source: trunk/dll/winlist.c@ 1330

Last change on this file since 1330 was 1228, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: winlist.c 1228 2008-09-13 23:13:40Z jbs $
5
6 Window List Dialog
7
8 Copyright (c) 1993-97 M. Kimes
9 Copyright (c) 2005, 2006 Steven H.Levine
10
11 23 May 05 SHL Use QWL_USER
12 22 Jul 06 SHL Check more run time errors
13 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
14
15***********************************************************************/
16
17#include <stdlib.h>
18#include <string.h>
19
20#define INCL_DOS
21#define INCL_WIN
22
23#include "fm3dll.h"
24#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
25#include "killproc.h" // Data declaration(s)
26#include "init.h" // Data declaration(s)
27#include "newview.h" // Data declaration(s)
28#include "notebook.h" // Data declaration(s)
29#include "fm3dlg.h"
30#include "mainwnd.h" // GetNextWindowPos
31#include "winlist.h"
32#include "wrappers.h" // xmalloc
33#include "misc.h" // PostMsg
34#include "fortify.h"
35
36#pragma data_seg(DATA1)
37
38static PSZ pszSrcFile = __FILE__;
39
40
41MRESULT EXPENTRY WinListDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
42{
43 SHORT sSelect;
44
45 static HWND Me = (HWND) 0;
46
47 switch (msg) {
48 case WM_INITDLG:
49 if (Me || !mp2) {
50 if (Me)
51 PostMsg(Me, UM_FOCUSME, MPVOID, MPVOID);
52 WinDismissDlg(hwnd, 0);
53 }
54 else {
55
56 HENUM henum;
57 HWND hwndChild;
58 USHORT id;
59 CHAR wtext[CCHMAXPATH + 1];
60
61 Me = hwnd;
62 WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2);
63 henum = WinBeginEnumWindows(*(HWND *) mp2);
64 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
65 id = WinQueryWindowUShort(hwndChild, QWS_ID);
66 if (!id)
67 continue;
68 *wtext = ' ';
69 WinQueryWindowText(hwndChild, CCHMAXPATH, wtext + 1);
70 wtext[CCHMAXPATH] = 0;
71 sSelect =
72 (SHORT) WinSendDlgItemMsg(hwnd, WLIST_LISTBOX, LM_INSERTITEM,
73 MPFROM2SHORT(LIT_SORTASCENDING, 0),
74 MPFROMP(wtext));
75 if (sSelect >= 0)
76 WinSendDlgItemMsg(hwnd, WLIST_LISTBOX, LM_SETITEMHANDLE,
77 MPFROM2SHORT(sSelect, 0),
78 MPFROMLONG((ULONG) hwndChild));
79 }
80 WinEndEnumWindows(henum);
81
82 {
83 PSWBLOCK pswb;
84 ULONG ulSize, ulcEntries;
85 register INT i, y;
86
87 /* Get the switch list information */
88 ulcEntries = WinQuerySwitchList(0, NULL, 0);
89 ulSize = sizeof(SWBLOCK) + sizeof(HSWITCH) + (ulcEntries + 4) *
90 (LONG) sizeof(SWENTRY);
91 /* Allocate memory for list */
92 pswb = xmalloc((unsigned)ulSize, pszSrcFile, __LINE__);
93 if (pswb) {
94 /* Put the info in the list */
95 ulcEntries = WinQuerySwitchList(0, pswb, ulSize - sizeof(SWENTRY));
96 /* do the dirty deed */
97 y = 0;
98 for (i = 0; i < pswb->cswentry; i++) {
99 if (pswb->aswentry[i].swctl.uchVisibility == SWL_VISIBLE &&
100 pswb->aswentry[i].swctl.fbJump == SWL_JUMPABLE &&
101 ((pswb->aswentry[i].swctl.idProcess == mypid &&
102 (strnicmp(pswb->aswentry[i].swctl.szSwtitle,
103 "FM/2", 4))) ||
104 !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "AV/2", 4) ||
105 !stricmp(pswb->aswentry[i].swctl.szSwtitle, "File Manager/2")
106 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "Collector")
107 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VTree", 5)
108 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VDir", 4)
109 || (!strnicmp(pswb->aswentry[i].swctl.szSwtitle, FM2Str, 4)
110 && strnicmp(pswb->aswentry[i].swctl.szSwtitle, "FM/2",
111 4)))) {
112 *wtext = '*';
113 wtext[1] = 0;
114 strcat(wtext, pswb->aswentry[i].swctl.szSwtitle);
115 wtext[CCHMAXPATH] = 0;
116 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
117 WLIST_LISTBOX,
118 LM_INSERTITEM,
119 MPFROM2SHORT
120 (LIT_SORTASCENDING, 0),
121 MPFROMP(wtext));
122 if (sSelect >= 0)
123 WinSendDlgItemMsg(hwnd,
124 WLIST_LISTBOX,
125 LM_SETITEMHANDLE,
126 MPFROM2SHORT(sSelect, 0),
127 MPFROMLONG(pswb->aswentry[i].swctl.hwnd));
128 }
129 y++;
130 }
131 free(pswb);
132 DosPostEventSem(CompactSem);
133 }
134 }
135
136 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
137 WLIST_LISTBOX,
138 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
139 if (sSelect <= 0)
140 WinDismissDlg(hwnd, 0);
141 }
142 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
143 break;
144
145 case UM_FOCUSME:
146 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
147 return 0;
148
149 case UM_SETUP:
150 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
151 return 0;
152
153 case UM_SETUP2:
154 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
155 return 0;
156
157 case UM_SETUP3:
158 WinSetActiveWindow(HWND_DESKTOP, hwnd);
159 return 0;
160
161 case WM_CONTROL:
162 switch (SHORT1FROMMP(mp1)) {
163 case WLIST_LISTBOX:
164 switch (SHORT2FROMMP(mp1)) {
165 case LN_ENTER:
166 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
167 break;
168 }
169 break;
170 }
171 return 0;
172
173 case WM_COMMAND:
174 switch (SHORT1FROMMP(mp1)) {
175 case WLIST_MINIMIZE:
176 case WLIST_CLOSE:
177 case DID_OK:
178 {
179 HWND hwndActive = (HWND) WinQueryWindowULong(hwnd, QWL_USER);
180
181 hwndActive = WinQueryActiveWindow(hwndActive);
182 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
183 WLIST_LISTBOX,
184 LM_QUERYSELECTION,
185 MPFROM2SHORT(LIT_FIRST, 0),
186 MPVOID);
187 while (sSelect >= 0) {
188
189 HWND HwndC;
190
191 HwndC = (HWND) WinSendDlgItemMsg(hwnd,
192 WLIST_LISTBOX,
193 LM_QUERYITEMHANDLE,
194 MPFROM2SHORT(sSelect, 0), MPVOID);
195 if (HwndC) {
196
197 SWP swp;
198
199 WinQueryWindowPos(HwndC, &swp);
200 if (SHORT1FROMMP(mp1) == DID_OK) {
201 if (!(swp.fl & SWP_MINIMIZE) && (swp.cx == 0 || swp.cy == 0)) {
202 GetNextWindowPos((HWND) WinQueryWindowULong(hwnd, QWL_USER),
203 &swp, NULL, NULL);
204 WinSetWindowPos(HwndC, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
205 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER |
206 SWP_ACTIVATE | SWP_FOCUSACTIVATE);
207 }
208 else
209 WinSetWindowPos(HwndC, HWND_TOP, 0, 0, 0, 0,
210 SWP_RESTORE | SWP_SHOW | SWP_ZORDER |
211 SWP_ACTIVATE | SWP_FOCUSACTIVATE);
212 }
213 else if (SHORT1FROMMP(mp1) == WLIST_MINIMIZE) {
214 WinSetWindowPos(HwndC, HWND_BOTTOM, 0, 0, 0, 0,
215 SWP_MINIMIZE | SWP_DEACTIVATE |
216 SWP_FOCUSDEACTIVATE | SWP_ZORDER);
217 if (hwndActive == HwndC) {
218 WinSetWindowPos(WinWindowFromID(WinQueryWindow(hwndActive,
219 QW_PARENT),
220 TREE_FRAME), HWND_TOP, 0, 0,
221 0, 0,
222 SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE |
223 SWP_FOCUSACTIVATE | SWP_ZORDER);
224 hwndActive = (HWND) 0;
225 }
226 }
227 else if (WinQueryWindowUShort(HwndC, QWS_ID) != TREE_FRAME)
228 PostMsg(HwndC, WM_CLOSE, MPVOID, MPVOID);
229 }
230 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, WLIST_LISTBOX,
231 LM_QUERYSELECTION,
232 MPFROM2SHORT(sSelect, 0),
233 MPVOID);
234 }
235 }
236 WinDismissDlg(hwnd, 0);
237 break;
238
239 case IDM_HELP:
240 if (hwndHelp)
241 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
242 MPFROM2SHORT(HELP_WINLIST, 0), MPFROMSHORT(HM_RESOURCEID));
243 break;
244
245 case DID_CANCEL:
246 WinDismissDlg(hwnd, 0);
247 break;
248 }
249 return 0;
250
251 case WM_DESTROY:
252 if (Me == hwnd)
253 Me = (HWND) 0;
254 else
255 WinSetWindowPos(Me, HWND_TOP, 0, 0, 0, 0,
256 SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
257 break;
258 }
259 return WinDefDlgProc(hwnd, msg, mp1, mp2);
260}
261
262VOID WindowList(HWND hwnd)
263{
264 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, WinListDlgProc, FM3ModHandle,
265 WLIST_FRAME, MPFROMP(&hwnd));
266}
267
268#pragma alloc_text(WINLIST,WindowList,WinListDlgProc)
Note: See TracBrowser for help on using the repository browser.