source: trunk/dll/winlist.c@ 1194

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

Ticket 187: Draft 2: Move remaining function declarations

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