source: trunk/dll/winlist.c@ 1214

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

Ticket 187: Move data declarations/definitions out of fm3dll.h

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