source: trunk/dll/mainwnd.c@ 1066

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

Ticket 246: Allow saved directory container states to have no directory containers
(i.e. just a directory tree container).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 213.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: mainwnd.c 1066 2008-07-12 13:20:00Z jbs $
5
6 fm/2 main window
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2008 Steven H. Levine
10
11 11 Jun 02 SHL Drop obsolete xor code
12 16 Oct 02 SHL Handle large partitions
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 23 May 05 SHL Use datamin.h
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 26 May 05 SHL Comments and localize code
18 05 Jun 05 SHL Use QWL_USER
19 06 Jun 05 SHL Rework MainWMCommand for VAC3.65 compat
20 13 Aug 05 SHL Renames and comments
21 08 Dec 05 SHL DriveProc: disable menu items if drive not ready
22 17 Dec 05 SHL DriveProc: correct my stupid
23 29 May 06 SHL IDM_EDITANYARCHIVER: sanitize code
24 17 Jul 06 SHL Use Runtime_Error
25 17 Aug 06 SHL Complain nicer if state name does not exist
26 18 Feb 07 GKY More drive type and icon support
27 08 Mar 07 SHL SaveDirCnrState: do not save state of NOPRESCAN volumes
28 09 Mar 07 SHL RestoreDirCnrState/SaveDirCnrState: optimize and avoid overflows
29 30 Mar 07 GKY Remove GetPString for window class names
30 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
31 06 Apr 07 GKY Add some error checking in drag/drop
32 15 Apr 07 SHL mainwnd MAIN_SETUPLIST restore state not found reporting
33 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
34 20 Apr 07 SHL Avoid spurious add_udir error reports
35 12 May 07 SHL Use dcd->ulItemsToUnHilite
36 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
37 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
38 07 Aug 07 SHL Use BldQuotedFileName
39 16 Aug 07 SHL Update IDM_SAVEDIRCNRSTATE logic for ticket# 109
40 18 Aug 07 SHL Rework UM_FILLSETUPLIST for new setups storage
41 19 Aug 07 SHL Move #pragma alloc_text to end of file for OpenWatcom
42 19 Aug 07 SHL Rework SaveDirCnrState to return better error info
43 30 Aug 07 SHL Add accelerator support to quicklist windows
44 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
45 12 Jan 08 SHL Support drag&drop dialog toggle
46 16 Jan 08 SHL Add sync updates toggle
47 16 Jan 08 GKY Fix changing background color on toolbar
48 17 Jan 08 GKY Add presparam save & restore for individual directory containers
49 19 Jan 08 JBS Ticket 150: fix/improve save and restore of dir cnr state at FM/2 close/reopen
50 19 Jan 08 GKY Rework Utilities menu
51 05 Feb 08 SHL Restore no-prescan drives if restoring named state
52 14 Feb 08 SHL Rework to support settings menu conditional cascade
53 15 Feb 08 SHL Rework ResizeChildren to honor fNoTreeGap and resize drive tree better
54 19 Feb 08 JBS Stop deleting "State at last FM/2 Close" from INI file so it be accessed from States combo box.
55 22 Feb 08 JBS Ticket 230: Fix/improve various code related to state or presparam values in the INI file.
56 29 Feb 08 GKY Use xfree where appropriate
57 19 Jun 08 JBS Ticket 227: Allow temporary saving/deleting of the shutdown state of directory containers
58 22 Jun 08 GKY Use free_... functions for fortify checking
59 30 Jun 08 JBS Ticket 103: Fix restore of previous shutdown state when opening FM/2
60 07 Jul 08 JBS Ticket 242: Delete obsolete INI keys when re-saving a state
61 11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
62 all the details view settings (both the global variables and those in the
63 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
64 12 Jul 08 JBS Ticket 246: Allow saved directory container states to have no directory containers
65 (i.e. just a directory tree container).
66
67***********************************************************************/
68
69#include <stdlib.h>
70#include <string.h>
71#include <ctype.h>
72#include <process.h> // _beginthread
73
74#define INCL_DOS
75#define INCL_WIN
76#define INCL_SHLERRORS // PMERR_NOT_IN_IDX
77#define INCL_WINHELP
78#define INCL_GPI
79#define INCL_LONGLONG
80
81#include "fm3dlg.h"
82#include "fm3str.h"
83#include "tools.h"
84#include "comp.h"
85#include "datamin.h"
86#include "pathutil.h" // BldQuotedFileName
87#include "errutil.h" // Dos_Error...
88#include "strutil.h" // GetPString
89#include "notebook.h" // CfgDlgProc CfgMenuInit
90#include "command.h" // LINKCMDS
91#include "fm3dll.h"
92#include "avl.h" // free_archivers
93
94#include "fortify.h"
95
96#pragma data_seg(DATA1)
97
98static PSZ pszSrcFile = __FILE__;
99
100static USHORT firsttool = 0;
101
102static BOOL CloseDirCnrChildren(HWND hwndClient);
103static BOOL RestoreDirCnrState(HWND hwndClient, PSZ pszStateName, BOOL noview);
104static VOID DeletePresParams(PSZ pszKeyroot);
105
106static MRESULT EXPENTRY MainObjectWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
107 MPARAM mp2)
108{
109 switch (msg) {
110 case UM_SETUP:
111 case UM_SETUP2:
112 case UM_SETUP3:
113 case UM_SETUP4:
114 case UM_SETUP5:
115 /*
116 * feed setup messages to main window
117 */
118 PostMsg(hwndMain, msg, mp1, mp2);
119 return 0;
120
121 case UM_SETUP6:
122 /*
123 * handle bubble help requests from drive bar buttons
124 */
125 {
126 char dv[3], d;
127 HWND hwndB = (HWND) mp1;
128 USHORT id;
129
130 id = WinQueryWindowUShort(hwndB, QWS_ID);
131 *dv = 0;
132 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwndB, QW_PARENT),
133 id + 50), sizeof(dv), dv);
134 d = toupper(*dv);
135 if (isalpha(d) && d > 'B' &&
136 !(driveflags[d - 'A'] & (DRIVE_CDROM | DRIVE_INVALID |
137 DRIVE_SLOW)) &&
138 (!hwndBubble ||
139 WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
140 !WinQueryCapture(HWND_DESKTOP)) {
141
142 FSALLOCATE fsa;
143 CHAR s[90], szQty[38];
144 ULONG ulPctFree;
145 ULONGLONG ullFreeQty;
146
147 if (!DosQueryFSInfo((d - 'A') + 1,
148 FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
149 ullFreeQty = (ULONGLONG) fsa.cUnitAvail *
150 (fsa.cSectorUnit * fsa.cbSector);
151 ulPctFree = (fsa.cUnit && fsa.cUnitAvail) ?
152 (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
153 CommaFmtULL(szQty, sizeof(szQty), ullFreeQty, ' ');
154 sprintf(s, "%s (%lu%%) free", szQty, ulPctFree);
155 }
156 if ((!hwndBubble ||
157 WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
158 !WinQueryCapture(HWND_DESKTOP))
159 WinSendMsg(hwndB, UM_SETUP6, MPFROMP(s), MPVOID);
160 }
161 }
162 return 0;
163
164 case UM_SETDIR:
165 {
166 CHAR s[8] = " :\\OS2";
167 ULONG bd;
168
169 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
170 QSV_BOOT_DRIVE,
171 (PVOID) & bd, (ULONG) sizeof(ULONG)))
172 bd = 3L;
173 *s = (CHAR) bd + '@';
174 WinSendMsg(hwndMain, UM_SETDIR, MPFROMP(s), MPFROMLONG(1));
175 if (!mp1) {
176 s[3] = 0;
177 WinSendMsg(hwndMain, UM_SETDIR, MPFROMP(s), MPVOID);
178 }
179 PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMLONG(1), MPFROMLONG(1));
180 }
181 return 0;
182
183 case UM_RESTORE:
184 switch ((ULONG)mp2) {
185 case 1:
186 TileChildren(hwndMain, TRUE);
187 break;
188 case 2:
189 CloseDirCnrChildren(hwndMain);
190 break;
191 case 0:
192 fNoTileUpdate = TRUE;
193 WinEnableWindow(WinQueryWindow(hwndMain, QW_PARENT), FALSE);
194 RestoreDirCnrState(hwndMain, (char *)mp1, FALSE);
195 WinEnableWindow(WinQueryWindow(hwndMain, QW_PARENT), TRUE);
196 fNoTileUpdate = FALSE;
197 //xfree((char *)mp1, pszSrcFile, __LINE__);
198// if (fAutoTile)
199// TileChildren(hwndMain, TRUE);
200 break;
201 default:
202 Runtime_Error(pszSrcFile, __LINE__, "%u unexpected", mp2);
203 }
204 return 0;
205
206 case UM_NOTIFY:
207 /*
208 * bring up notify messages for various windows
209 */
210 if (mp1)
211 return MRFROMLONG(DoNotify((char *)mp1));
212 return 0;
213
214 case WM_DESTROY:
215 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
216 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
217# ifdef FORTIFY
218 Fortify_LeaveScope();
219# endif
220 break;
221 }
222 return WinDefWindowProc(hwnd, msg, mp1, mp2);
223}
224
225VOID MakeMainObjWin(VOID * args)
226{
227 HAB hab2;
228 HMQ hmq2;
229 QMSG qmsg2;
230
231 priority_bumped();
232 hab2 = WinInitialize(0);
233 if (hab2) {
234 hmq2 = WinCreateMsgQueue(hab2, 128);
235 if (hmq2) {
236 DosError(FERR_DISABLEHARDERR);
237 WinRegisterClass(hab2,
238 (PSZ) WC_OBJECTWINDOW,
239 MainObjectWndProc, 0, sizeof(PVOID));
240 MainObjectHwnd = WinCreateWindow(HWND_OBJECT,
241 WC_OBJECTWINDOW,
242 (PSZ) NULL,
243 0,
244 0L,
245 0L,
246 0L,
247 0L,
248 0L, HWND_TOP, OBJ_FRAME, NULL, NULL);
249 if (!MainObjectHwnd)
250 Win_Error2(HWND_OBJECT, HWND_DESKTOP, pszSrcFile, __LINE__,
251 IDS_WINCREATEWINDOW);
252 else {
253 WinSetWindowPtr(MainObjectHwnd, QWL_USER, args);
254 while (WinGetMsg(hab2, &qmsg2, (HWND) 0, 0, 0))
255 WinDispatchMsg(hab2, &qmsg2);
256 WinDestroyWindow(MainObjectHwnd);
257 }
258 WinDestroyMsgQueue(hmq2);
259 }
260 WinTerminate(hab2);
261 }
262}
263
264static MRESULT EXPENTRY IdealButtonProc(HWND hwnd, ULONG msg, MPARAM mp1,
265 MPARAM mp2)
266{
267 switch (msg) {
268 case WM_MOUSEMOVE:
269 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(IDS_IDEALBUTTONHELP));
270 break;
271 }
272 return PFNWPButton(hwnd, msg, mp1, mp2);
273}
274
275HWND TopWindow(HWND hwndParent, HWND exclude)
276{
277 HENUM henum;
278 HWND hwndC = (HWND) 0;
279 USHORT id;
280
281 if (hwndParent) {
282 henum = WinBeginEnumWindows(hwndMain);
283 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
284 if (hwndC != exclude) {
285 id = WinQueryWindowUShort(hwndC, QWS_ID);
286 if (id)
287 break;
288 }
289 }
290 WinEndEnumWindows(henum);
291 }
292 return hwndC;
293}
294
295HWND TopWindowName(HWND hwndParent, HWND exclude, CHAR * ret)
296{
297 HENUM henum;
298 HWND hwndC = (HWND) 0, hwndDir, hwndClient;
299 USHORT id;
300 PCNRITEM pci = NULL;
301
302 if (ret) {
303 *ret = 0;
304 if (hwndParent) {
305 henum = WinBeginEnumWindows(hwndMain);
306 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
307 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Tree = %lu\rExclude = %lu\rFound = %lu",hwndTree,exclude,hwndC);
308 if (hwndC != exclude && hwndC != hwndTree) {
309 id = WinQueryWindowUShort(hwndC, QWS_ID);
310 if (id) {
311 hwndClient = WinWindowFromID(hwndC, FID_CLIENT);
312 if (hwndClient) {
313 hwndDir = WinWindowFromID(hwndClient, DIR_CNR);
314 if (hwndDir) {
315 if (fLookInDir) {
316 pci = (PCNRITEM) WinSendMsg(hwndDir,
317 CM_QUERYRECORDEMPHASIS,
318 MPFROMLONG(CMA_FIRST),
319 MPFROMSHORT(CRA_CURSORED));
320 if (pci && (INT) pci != -1)
321 break;
322 }
323 if (WinSendMsg(hwndClient,
324 UM_CONTAINERDIR, MPFROMP(ret), MPVOID)) {
325 MakeValidDir(ret);
326 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Tree = %lu\rExclude = %lu\rFound = %lu\r\"%s\"",hwndTree,exclude,hwndC,ret);
327 WinEndEnumWindows(henum);
328 return hwndC;
329 }
330 }
331 }
332 }
333 }
334 }
335 WinEndEnumWindows(henum);
336 if (!pci || (INT) pci == -1) {
337 hwndC = hwndTree;
338 pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(hwndTree,
339 FID_CLIENT),
340 TREE_CNR),
341 CM_QUERYRECORDEMPHASIS,
342 MPFROMLONG(CMA_FIRST),
343 MPFROMSHORT(CRA_CURSORED));
344 }
345 if (pci && (INT) pci != -1) {
346 strcpy(ret, pci->pszFileName);
347 MakeValidDir(ret);
348 }
349 else
350 save_dir2(ret);
351 }
352 }
353 return hwndC;
354}
355
356ULONG CountDirCnrs(HWND hwndParent)
357{
358 HENUM henum;
359 HWND hwndF = (HWND) 0, hwndC, hwndDir;
360 ULONG ret = 0;
361
362 henum = WinBeginEnumWindows(hwndParent);
363 while ((hwndF = WinGetNextWindow(henum)) != NULLHANDLE) {
364 hwndC = WinWindowFromID(hwndF, FID_CLIENT);
365 if (hwndC) {
366 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
367 if (hwndDir)
368 ret++;
369 }
370 }
371 WinEndEnumWindows(henum);
372 return ret;
373}
374
375HWND FindDirCnrByName(CHAR * directory, BOOL restore)
376{
377 HENUM henum;
378 HWND hwndF = (HWND) 0, hwndC, hwndDir;
379 CHAR retstr[CCHMAXPATH];
380
381 if (hwndMain) {
382 henum = WinBeginEnumWindows(hwndMain);
383 while ((hwndF = WinGetNextWindow(henum)) != NULLHANDLE) {
384 hwndC = WinWindowFromID(hwndF, FID_CLIENT);
385 if (hwndC) {
386 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
387 if (hwndDir) {
388 *retstr = 0;
389 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
390 if (*retstr && !stricmp(retstr, directory)) {
391 if (restore)
392 WinSetWindowPos(hwndF,
393 HWND_TOP,
394 0,
395 0,
396 0,
397 0,
398 SWP_RESTORE | SWP_SHOW |
399 SWP_ACTIVATE | SWP_ZORDER);
400 break;
401 }
402 }
403 }
404 }
405 WinEndEnumWindows(henum);
406 }
407 return hwndF;
408}
409
410static VOID SetToggleChecks(HWND hwndMenu)
411{
412 WinCheckMenuItem(hwndMenu, IDM_TEXTTOOLS, fTextTools);
413 WinCheckMenuItem(hwndMenu, IDM_TOOLTITLES, fToolTitles);
414 WinCheckMenuItem(hwndMenu, IDM_USERLIST, fUserComboBox);
415 WinCheckMenuItem(hwndMenu, IDM_TOOLSUBMENU, fToolbar);
416 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWSUBMENU, fAutoView);
417 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWFILE, !fComments);
418 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWCOMMENTS, fComments);
419 WinCheckMenuItem(hwndMenu, IDM_MOREBUTTONS, fMoreButtons);
420 WinCheckMenuItem(hwndMenu, IDM_DRIVEBAR, fDrivebar);
421 WinCheckMenuItem(hwndMenu, IDM_AUTOTILE, fAutoTile);
422 WinCheckMenuItem(hwndMenu, IDM_TILEBACKWARDS, fTileBackwards);
423 WinCheckMenuItem(hwndMenu, IDM_TOGGLEDRAGDIALOG, fDragndropDlg);
424 WinCheckMenuItem(hwndMenu, IDM_SYNCUPDATES, fSyncUpdates);
425}
426
427static VOID ResizeTools(HWND hwnd)
428{
429 register ULONG butx = 18L;
430 INT attrib = SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER | SWP_NOREDRAW,
431 noattrib;
432 register TOOL *tool, *starttool;
433 SWP *swp;
434 register ULONG numtools, x;
435
436 if (!fToolbar)
437 return;
438 noattrib = attrib;
439 noattrib &= (~(SWP_SHOW | SWP_ZORDER));
440 noattrib |= SWP_HIDE;
441 /* count tools */
442 tool = toolhead;
443 for (numtools = 0L; tool; numtools++)
444 tool = tool->next;
445 /* allocate swp array for WinSetMultWindowPos */
446 swp = xmallocz(sizeof(SWP) * (numtools + 2), pszSrcFile, __LINE__);
447 if (swp) {
448 for (x = 0; x < numtools + 2L; x++) {
449 swp[x].hwndInsertBehind = HWND_TOP;
450 swp[x].fl = attrib;
451 swp[x].y = (fToolTitles) ? 14L : 3L;
452 swp[x].cx = 32L;
453 swp[x].cy = 32L;
454 }
455 swp[0].x = swp[1].x = 2L;
456 swp[0].y = (fTextTools) ? 14L : 18L;
457 swp[1].y = (fTextTools) ? 1L : 2L;
458 swp[0].cx = swp[1].cx = 14L;
459 swp[0].cy = swp[1].cy = 14L;
460 swp[0].hwnd = WinWindowFromID(hwnd, IDM_TOOLLEFT);
461 swp[1].hwnd = WinWindowFromID(hwnd, IDM_TOOLRIGHT);
462 x = 2L;
463 tool = find_tool(firsttool);
464 if (!tool)
465 tool = toolhead;
466 starttool = tool;
467 while (tool) {
468 if (!(tool->flags & T_INVISIBLE)) {
469 swp[x].x = butx;
470 if (fTextTools || (tool->flags & T_TEXT)) {
471 butx += 55L;
472 swp[x].cx = 54L;
473 swp[x].cy = 24L;
474 swp[x].y = 3L;
475 }
476 else
477 butx += 33L;
478 if (tool->flags & T_SEPARATOR)
479 butx += 12;
480 }
481 else
482 swp[x].fl = noattrib;
483 swp[x].hwnd = WinWindowFromID(hwnd, tool->id);
484 x++;
485 tool = tool->next;
486 }
487 tool = toolhead;
488 while (tool && tool != starttool) {
489 swp[x].x = butx;
490 if (!(tool->flags & T_INVISIBLE)) {
491 if (fTextTools || (tool->flags & T_TEXT)) {
492 butx += 55L;
493 swp[x].cx = 54L;
494 swp[x].cy = 24L;
495 swp[x].y = 3L;
496 }
497 else
498 butx += 33L;
499 if (tool->flags & T_SEPARATOR)
500 butx += 12;
501 }
502 else
503 swp[x].fl = noattrib;
504 swp[x].hwnd = WinWindowFromID(hwnd, tool->id);
505 x++;
506 tool = tool->next;
507 }
508 WinSetMultWindowPos(WinQueryAnchorBlock(hwnd), swp, numtools + 2L);
509 if (!fTextTools && fToolTitles) {
510 for (x = 2L; x < numtools + 2L; x++) {
511 if (fTextTools || !fToolTitles)
512 swp[x].fl = noattrib;
513 else {
514 tool = find_tool(WinQueryWindowUShort(swp[x].hwnd, QWS_ID));
515 if (tool && (tool->flags & T_TEXT))
516 swp[x].fl = noattrib;
517 else {
518 swp[x].hwndInsertBehind = HWND_TOP;
519 swp[x].y = 1L;
520 swp[x].cy = 10L;
521 }
522 }
523 swp[x].hwnd = WinWindowFromID(hwnd,
524 WinQueryWindowUShort(swp[x].hwnd,
525 QWS_ID) + 25000);
526 }
527 WinSetMultWindowPos(WinQueryAnchorBlock(hwnd), &swp[2], numtools);
528 }
529 free(swp);
530 }
531 WinInvalidateRect(hwnd, NULL, TRUE);
532}
533
534static MRESULT EXPENTRY DropDownListProc(HWND hwnd, ULONG msg, MPARAM mp1,
535 MPARAM mp2)
536{
537 PFNWP oldproc = (PFNWP) INSTDATA(hwnd);
538 USHORT id;
539
540 static HWND hwndMenu = (HWND)0;
541 static BOOL emphasized = FALSE;
542
543 switch (msg) {
544 case WM_MOUSEMOVE:
545 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
546 break;
547
548 case WM_CHAR:
549 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
550 break;
551
552 case WM_MENUEND:
553 if (hwndMenu == (HWND) mp2) {
554 WinDestroyWindow(hwndMenu);
555 hwndMenu = (HWND) 0;
556 }
557 break;
558
559 case WM_FOCUSCHANGE:
560 {
561 HAB hab = WinQueryAnchorBlock(hwnd);
562 HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
563 HWND hwndFrame = WinQueryWindow(hwndParent, QW_PARENT);
564 static HACCEL haccelSaved = NULLHANDLE;
565 static HACCEL haccelDriveList = NULLHANDLE;
566 static HACCEL haccelSetupList = NULLHANDLE;
567 static HACCEL haccelUserList = NULLHANDLE;
568 static HACCEL haccelCmdList = NULLHANDLE;
569 static HACCEL haccelButtonList = NULLHANDLE;
570 // DbgMsg(pszSrcFile, __LINE__, "WM_FOCUSCHANGE %u", SHORT1FROMMP(mp2));
571 id = WinQueryWindowUShort(hwndParent, QWS_ID);
572 if (SHORT1FROMMP(mp2)) {
573 // If getting focus 1st time - save original accelerator
574 if (haccelSaved == NULLHANDLE) {
575 haccelSaved = WinQueryAccelTable(hab, hwndFrame);
576 if (haccelSaved == NULLHANDLE)
577 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryAccelTable");
578 // else
579 // DbgMsg(pszSrcFile, __LINE__, "WinQueryAccelTable SAVED %x", haccelSaved);
580 }
581 if (haccelSaved != NULLHANDLE) {
582 switch (id) {
583 case MAIN_DRIVELIST:
584 if (haccelDriveList == NULLHANDLE) {
585 haccelDriveList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_DRIVELIST);
586 if (haccelDriveList == NULLHANDLE)
587 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinLoadAccelTable");
588 }
589 if (haccelDriveList != NULLHANDLE) {
590 if (!WinSetAccelTable(hab, haccelDriveList, hwndFrame))
591 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
592 // else
593 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable MAIN_DRIVELIST %x %x", hwndFrame, haccelDriveList);
594 }
595 break;
596 case MAIN_SETUPLIST:
597 if (haccelSetupList == NULLHANDLE) {
598 haccelSetupList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_SETUPLIST);
599 if (haccelSetupList == NULLHANDLE)
600 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinLoadAccelTable");
601 }
602 if (haccelSetupList != NULLHANDLE) {
603 if (!WinSetAccelTable(hab, haccelSetupList, hwndFrame))
604 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
605 // else
606 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable MAIN_SETUPLIST %x %x", hwndFrame, haccelSetupList);
607 }
608 break;
609 case MAIN_CMDLIST:
610 if (haccelCmdList == NULLHANDLE) {
611 haccelCmdList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_CMDLIST);
612 if (haccelCmdList == NULLHANDLE)
613 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinLoadAccelTable");
614 }
615 if (haccelCmdList != NULLHANDLE) {
616 if (!WinSetAccelTable(hab, haccelCmdList, hwndFrame))
617 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
618 // else
619 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable MAIN_CMDLIST %x %x", hwndFrame, haccelCmdList);
620 }
621 break;
622 case MAIN_USERLIST:
623 if (haccelUserList == NULLHANDLE) {
624 haccelUserList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_USERLIST);
625 if (haccelUserList == NULLHANDLE)
626 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinLoadAccelTable");
627 }
628 if (haccelUserList != NULLHANDLE) {
629 if (!WinSetAccelTable(hab, haccelUserList, hwndFrame))
630 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
631 // else
632 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable MAIN_USERLIST %x %x", hwndFrame, haccelUserList);
633 }
634 break;
635 case MAIN_BUTTONLIST:
636 if (haccelButtonList == NULLHANDLE) {
637 haccelButtonList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_BUTTONLIST);
638 if (haccelButtonList == NULLHANDLE)
639 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinLoadAccelTable");
640 }
641 if (haccelButtonList != NULLHANDLE) {
642 if (!WinSetAccelTable(hab, haccelButtonList, hwndFrame))
643 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
644 // else
645 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable MAIN_BUTTONLIST %x %x", hwndFrame, haccelButtonList);
646 }
647 break;
648 } // switch
649 }
650 }
651 else {
652 // Losing focus
653 switch (id) {
654 case MAIN_DRIVELIST:
655 case MAIN_SETUPLIST:
656 case MAIN_CMDLIST:
657 case MAIN_USERLIST:
658 case MAIN_BUTTONLIST:
659 if (haccelSaved != NULLHANDLE) {
660 if (!WinSetAccelTable(hab, haccelSaved, hwndFrame))
661 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, "WinSetAccelTable");
662 // else
663 // DbgMsg(pszSrcFile, __LINE__, "WinSetAccelTable SAVED %x %x", hwndFrame, haccelSaved);
664 }
665 break;
666 } // switch
667 }
668 }
669 break; // WM_FOCUSCHANGE
670
671 case WM_CONTEXTMENU:
672 {
673 MRESULT ret = MRFROMSHORT(TRUE);
674
675 if (hwndMenu)
676 WinDestroyWindow(hwndMenu);
677 hwndMenu = (HWND) 0;
678 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
679 switch (id) {
680 case MAIN_CMDLIST:
681 WinPostMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
682 QW_PARENT),
683 QW_PARENT),
684 FID_CLIENT),
685 WM_COMMAND, MPFROM2SHORT(IDM_EDITCOMMANDS, 0), MPVOID);
686 break;
687 case MAIN_USERLIST:
688 case MAIN_SETUPLIST:
689 hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
690 if (hwndMenu)
691 PopupMenu(hwnd,
692 WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
693 QW_PARENT),
694 QW_PARENT),
695 FID_CLIENT), hwndMenu);
696 break;
697 default:
698 ret = FALSE;
699 break;
700 } // switch
701 return ret;
702 }
703
704 case WM_CONTROL:
705 if (hwndStatus2) {
706 switch (SHORT1FROMMP(mp1)) {
707 case CBID_EDIT:
708 id = WinQueryWindowUShort(hwnd, QWS_ID);
709 switch (SHORT2FROMMP(mp1)) {
710 case EN_SETFOCUS:
711 switch (id) {
712 case MAIN_CMDLIST:
713 WinSetWindowText(hwndStatus2, GetPString(IDS_CMDLISTHELP));
714 break;
715 case MAIN_SETUPLIST:
716 WinSetWindowText(hwndStatus2, GetPString(IDS_SETUPLISTHELP));
717 break;
718 case MAIN_USERLIST:
719 WinSetWindowText(hwndStatus2, GetPString(IDS_USERLISTHELP));
720 break;
721 case MAIN_DRIVELIST:
722 WinSetWindowText(hwndStatus2, GetPString(IDS_DRIVELISTHELP));
723 break;
724 case MAIN_BUTTONLIST:
725 WinSetWindowText(hwndStatus2, GetPString(IDS_BUTTONLISTHELP));
726 break;
727 default:
728 break;
729 }
730 break;
731
732 default:
733 break;
734 }
735 }
736 break;
737
738 default:
739 break;
740 }
741 break;
742
743 case WM_BEGINDRAG:
744 id = WinQueryWindowUShort(hwnd, QWS_ID);
745 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"%u %s %u",id,(id == CBID_EDIT) ? "TRUE" : "FALSE",WinQueryWindowUShort(WinQueryWindow(hwnd,QW_PARENT),QWS_ID) == MAIN_USERLIST);
746 if (id == CBID_EDIT &&
747 WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID) ==
748 MAIN_USERLIST) {
749
750 CHAR path[CCHMAXPATH];
751
752 *path = 0;
753 WinQueryWindowText(hwnd, CCHMAXPATH, path);
754 bstrip(path);
755 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Dragging: %s",path);
756 if (*path && !IsRoot(path))
757 DragOne(hwnd, (HWND) 0, path, FALSE);
758 return 0;
759 }
760 break;
761
762 case DM_DRAGOVER:
763 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
764 if (id == MAIN_USERLIST) {
765 if (!emphasized) {
766 emphasized = TRUE;
767 DrawTargetEmphasis(hwnd, emphasized);
768 }
769 if (AcceptOneDrop(hwnd, mp1, mp2))
770 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
771 return MRFROM2SHORT(DOR_NEVERDROP, 0);
772 }
773 break;
774
775 case DM_DRAGLEAVE:
776 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
777 if (id == MAIN_USERLIST) {
778 if (emphasized) {
779 emphasized = FALSE;
780 DrawTargetEmphasis(hwnd, emphasized);
781 }
782 }
783 break;
784
785 case DM_DROPHELP:
786 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
787 if (id == MAIN_USERLIST) {
788 DropHelp(mp1, mp2, hwnd, GetPString(IDS_USERLISTDROPHELP));
789 return 0;
790 }
791 break;
792
793 case DM_DROP:
794 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
795 if (id == MAIN_USERLIST) {
796
797 char szFrom[CCHMAXPATH + 2];
798
799 if (emphasized) {
800 emphasized = FALSE;
801 DrawTargetEmphasis(hwnd, emphasized);
802 }
803 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
804 MakeValidDir(szFrom);
805 WinSetWindowText(hwnd, szFrom);
806 PostMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
807 QW_PARENT),
808 QW_PARENT),
809 FID_CLIENT),
810 UM_COMMAND, MPFROM2SHORT(IDM_ADDTOUSERLIST, 0), MPVOID);
811 return 0;
812 }
813 }
814 break;
815
816 case WM_DESTROY:
817 if (hwndMenu)
818 WinDestroyWindow(hwndMenu);
819 hwndMenu = (HWND) 0;
820 break;
821 }
822
823 return oldproc(hwnd, msg, mp1, mp2);
824}
825
826void BubbleHelp(HWND hwnd, BOOL other, BOOL drive, BOOL above, char *help)
827{
828 if (help && *help &&
829 ((drive && fDrivebarHelp) ||
830 (other && fOtherHelp) || (!other && !drive && fToolbarHelp))) {
831 if ((!hwndBubble ||
832 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
833 !WinQueryCapture(HWND_DESKTOP))
834 MakeBubble(hwnd, above, help);
835 }
836}
837
838VOID MakeBubble(HWND hwnd, BOOL above, CHAR * help)
839{
840 if (!hwnd || !help || !*help)
841 return;
842
843 if (hwndBubble)
844 WinDestroyWindow(hwndBubble);
845
846 {
847 HWND hwndActive;
848 char ucClassname[8];
849
850 hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
851 if (hwndActive) {
852 /* don't bring up help if window isn't active */
853 if (!WinIsChild(hwnd, hwndActive))
854 return;
855 }
856 hwndActive = WinQueryFocus(HWND_DESKTOP);
857 if (WinQueryClassName(hwndActive, sizeof(ucClassname), ucClassname)) {
858 /* don't bring up help if a menu is active */
859 if (!strcmp(ucClassname, "#4"))
860 return;
861 }
862 }
863
864 hwndBubble = WinCreateWindow(HWND_DESKTOP,
865 WC_BUBBLE,
866 help,
867 WS_CLIPSIBLINGS | SS_TEXT |
868 DT_CENTER | DT_VCENTER,
869 0,
870 0,
871 0,
872 0,
873 HWND_DESKTOP, HWND_TOP, MAIN_HELP, NULL, NULL);
874 if (!hwndBubble)
875 Win_Error2(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
876 IDS_WINCREATEWINDOW);
877 else {
878 HPS hps;
879 POINTL aptl[TXTBOX_COUNT], ptl, tptl;
880 LONG lxScreen, sx, sy, extra = 0, lyScreen;
881 char *p, *pp, *wp;
882 SWP swp;
883
884 WinQueryWindowPos(hwnd, &swp);
885 lyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
886 lxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
887 WinSetWindowULong(hwndBubble, QWL_USER, hwnd);
888 SetPresParams(hwndBubble, NULL, NULL, NULL, GetPString(IDS_8HELVTEXT));
889 hps = WinGetPS(hwndBubble);
890 p = help;
891 tptl.x = tptl.y = 0;
892 while (p && *p) {
893 wp = NULL;
894 pp = strchr(p, '\r');
895 if (pp) {
896 wp = pp;
897 *pp = 0;
898 pp++;
899 }
900 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
901 tptl.x = max(aptl[TXTBOX_TOPRIGHT].x, tptl.x);
902 if (tptl.y)
903 tptl.y += extra;
904 else
905 extra = aptl[TXTBOX_TOPLEFT].y / 4;
906 tptl.y += aptl[TXTBOX_TOPLEFT].y;
907 if (wp)
908 *wp = '\r';
909 p = pp;
910 }
911 WinSetWindowULong(hwndBubble, QWL_USER + 4, extra);
912 WinReleasePS(hps);
913 ptl.x = ptl.y = 0;
914 WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1);
915 if (above) {
916 sy = ptl.y + swp.cy + 4;
917 if (sy + tptl.y + 12 > lyScreen) {
918 above = FALSE;
919 sy = ptl.y - (tptl.y + 14);
920 }
921 }
922 else
923 sy = ptl.y - (tptl.y + 14);
924 if (ptl.x > (lxScreen / 2))
925 sx = (ptl.x - tptl.x) - 16;
926 else
927 sx = ptl.x + (54 * (above == FALSE)) + 2;
928 if (sx < 0)
929 sx = 0;
930 if (sx + tptl.x + 14 > lxScreen)
931 sx = lxScreen - (tptl.x + 14);
932 if (sy < 0) {
933 sy = ptl.y + swp.cy + 4;
934 if (sy + tptl.y + 12 > lyScreen)
935 sy = 0;
936 }
937 WinSetWindowPos(hwndBubble, HWND_TOP, sx, sy,
938 tptl.x + 14,
939 tptl.y + 12,
940 SWP_DEACTIVATE | SWP_SHOW | SWP_ZORDER |
941 SWP_MOVE | SWP_SIZE);
942 }
943}
944
945MRESULT EXPENTRY BubbleProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
946{
947 switch (msg) {
948 case WM_SETFOCUS:
949 if (mp2)
950 PostMsg(hwnd, UM_FOCUSME, mp1, MPVOID);
951 break;
952
953 case UM_FOCUSME:
954 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
955 return 0;
956
957 case WM_MOUSEMOVE:
958 WinShowWindow(hwnd, FALSE);
959 break;
960
961 case UM_TIMER:
962 {
963 POINTL ptl;
964
965 WinQueryPointerPos(HWND_DESKTOP, &ptl);
966 if (WinWindowFromPoint(HWND_DESKTOP, &ptl, TRUE) !=
967 WinQueryWindowULong(hwnd, QWL_USER) || !WinIsWindowVisible(hwnd))
968 WinDestroyWindow(hwnd);
969 }
970 return 0;
971
972 case WM_PAINT:
973 {
974 HPS hps;
975 SWP swp;
976 POINTL ptl, aptl[TXTBOX_COUNT];
977 CHAR *s, *p, *pp, *wp;
978 ULONG extra, tlen, y;
979
980 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
981 if (hps) {
982 WinQueryWindowPos(hwnd, &swp);
983 GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, 0);
984 GpiSetColor(hps, ((255 << 16) | (255 << 8) | 198));
985 GpiSetBackMix(hps, BM_LEAVEALONE);
986 GpiSetMix(hps, FM_OVERPAINT);
987 ptl.x = ptl.y = 0;
988 GpiMove(hps, &ptl);
989 ptl.x = swp.cx - 1;
990 ptl.y = swp.cy - 1;
991 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
992 tlen = WinQueryWindowTextLength(hwnd);
993 if (tlen) {
994 s = xmalloc(tlen + 2, pszSrcFile, __LINE__);
995 if (s) {
996 WinQueryWindowText(hwnd, tlen + 1, s);
997 if (*s) {
998 p = s;
999 y = swp.cy - 3;
1000 extra = WinQueryWindowULong(hwnd, QWL_USER + 4);
1001 GpiSetColor(hps, 0);
1002 GpiSetMix(hps, FM_OVERPAINT);
1003 while (p && *p) {
1004 wp = NULL;
1005 pp = strchr(p, '\r');
1006 if (pp) {
1007 wp = pp;
1008 *pp = 0;
1009 pp++;
1010 }
1011 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
1012 ptl.x = 7;
1013 y -= aptl[TXTBOX_TOPLEFT].y;
1014 if (p != s)
1015 y -= extra;
1016 ptl.y = y;
1017 GpiCharStringAt(hps, &ptl, strlen(p), p);
1018 if (wp)
1019 *wp = '\r';
1020 p = pp;
1021 }
1022 }
1023 free(s);
1024 }
1025 }
1026 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) && swp.cx > 6 && swp.cy > 6) {
1027 GpiSetColor(hps, CLR_WHITE);
1028 ptl.x = 1;
1029 ptl.y = 1;
1030 GpiMove(hps, &ptl);
1031 ptl.y = swp.cy - 2;
1032 GpiLine(hps, &ptl);
1033 ptl.x = swp.cx - 2;
1034 GpiLine(hps, &ptl);
1035 ptl.x = 2;
1036 ptl.y = 2;
1037 GpiMove(hps, &ptl);
1038 ptl.y = swp.cy - 3;
1039 GpiLine(hps, &ptl);
1040 ptl.x = swp.cx - 3;
1041 GpiLine(hps, &ptl);
1042 GpiSetColor(hps, CLR_BROWN);
1043 ptl.x = 1;
1044 ptl.y = 1;
1045 GpiMove(hps, &ptl);
1046 ptl.x = swp.cx - 2;
1047 GpiLine(hps, &ptl);
1048 ptl.y = swp.cy - 2;
1049 GpiLine(hps, &ptl);
1050 ptl.x = 2;
1051 ptl.y = 2;
1052 GpiMove(hps, &ptl);
1053 ptl.x = swp.cx - 3;
1054 GpiLine(hps, &ptl);
1055 ptl.y = swp.cy - 3;
1056 GpiLine(hps, &ptl);
1057 }
1058 WinEndPaint(hps);
1059 }
1060 }
1061 return 0;
1062
1063 case WM_CLOSE:
1064 WinDestroyWindow(hwnd);
1065 return 0;
1066
1067 case WM_DESTROY:
1068 hwndBubble = (HWND) 0;
1069 break;
1070 }
1071 return PFNWPStatic(hwnd, msg, mp1, mp2);
1072}
1073
1074MRESULT EXPENTRY LEDProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1075{
1076 switch (msg) {
1077 case WM_CREATE:
1078 {
1079 MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
1080 HBITMAP hbmold = (HBITMAP) 0;
1081 HPS hps = (HPS) 0;
1082
1083 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
1084 case MAIN_LED:
1085 hps = WinGetPS(hwnd);
1086 hbmold = (HBITMAP) WinSendMsg(hwnd, SM_QUERYHANDLE, MPVOID, MPVOID);
1087 if (!fBlueLED) {
1088 hbmLEDon = GpiLoadBitmap(hps, 0, LEDON_BMP, 12, 12);
1089 hbmLEDoff = GpiLoadBitmap(hps, 0, LEDOFF_BMP, 12, 12);
1090 }
1091 else {
1092 hbmLEDon = GpiLoadBitmap(hps, 0, LEDON2_BMP, 12, 12);
1093 hbmLEDoff = GpiLoadBitmap(hps, 0, LEDOFF2_BMP, 12, 12);
1094 }
1095 if (hbmLEDoff && hbmLEDon)
1096 WinSendMsg(hwnd, SM_SETHANDLE, MPFROMLONG(hbmLEDoff), MPVOID);
1097 else {
1098 if (hbmLEDoff)
1099 GpiDeleteBitmap(hbmLEDoff);
1100 if (hbmLEDon)
1101 GpiDeleteBitmap(hbmLEDon);
1102 }
1103 if (hbmold &&
1104 hbmLEDon &&
1105 hbmLEDoff && hbmold != hbmLEDon && hbmold != hbmLEDoff)
1106 GpiDeleteBitmap(hbmold);
1107 if (hps)
1108 WinReleasePS(hps);
1109 break;
1110 default:
1111 SetPresParams(hwnd,
1112 &RGBGREY,
1113 &RGBBLACK, &RGBGREY, GetPString(IDS_6HELVTEXT));
1114 break;
1115 }
1116 return mr;
1117 }
1118
1119 case WM_SETFOCUS:
1120 if (mp2)
1121 PostMsg(hwnd, UM_FOCUSME, mp1, MPVOID);
1122 break;
1123
1124 case UM_FOCUSME:
1125 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
1126 return 0;
1127
1128 case WM_MOUSEMOVE:
1129 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(IDS_LEDHELP));
1130 if (!fNoFinger) {
1131 WinSetPointer(HWND_DESKTOP, hptrFinger);
1132 return MRFROMLONG(TRUE);
1133 }
1134 break;
1135
1136 case WM_BUTTON1CLICK:
1137 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1138 WM_COMMAND, MPFROM2SHORT(IDM_SHOWNOTEWND, 0), MPVOID);
1139 break;
1140
1141 case WM_BUTTON2CLICK:
1142 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1143 WM_COMMAND, MPFROM2SHORT(IDM_HIDENOTEWND, 0), MPVOID);
1144 break;
1145
1146 case WM_CHORD:
1147 case WM_BUTTON3CLICK:
1148 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1149 WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
1150 break;
1151 }
1152 return PFNWPStatic(hwnd, msg, mp1, mp2);
1153}
1154
1155MRESULT EXPENTRY ChildButtonProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1156{
1157 USHORT id;
1158 TOOL *tool;
1159
1160 static HWND hwndMenu = (HWND) 0;
1161
1162 switch (msg) {
1163 case WM_BUTTON1DOWN:
1164 case WM_BUTTON2DOWN:
1165 case WM_BUTTON3DOWN:
1166 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
1167 break;
1168
1169 case WM_MOUSEMOVE:
1170 if (fToolbarHelp) {
1171 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
1172 && !WinQueryCapture(HWND_DESKTOP)) {
1173 id = WinQueryWindowUShort(hwnd, QWS_ID);
1174 tool = find_tool(id);
1175 if (tool && tool->help && *tool->help) {
1176
1177 char s[128];
1178
1179 strcpy(s, tool->help);
1180 if (tool->flags & T_DROPABLE)
1181 strcat(s, GetPString(IDS_DROPONMETEXT));
1182 MakeBubble(hwnd, FALSE, s);
1183 }
1184 }
1185 }
1186 break;
1187
1188 case WM_COMMAND:
1189 switch (SHORT1FROMMP(mp1)) {
1190 case IDM_HELP:
1191 if (hwndHelp)
1192 WinSendMsg(hwndHelp,
1193 HM_DISPLAY_HELP,
1194 MPFROM2SHORT(HELP_TOOLBAR, 0), MPFROMSHORT(HM_RESOURCEID));
1195 break;
1196
1197 case IDM_HIDEANYTOOL: /* hide any tool */
1198 case IDM_HIDETOOL: /* hide tool */
1199 if (SHORT1FROMMP(mp1) == IDM_HIDETOOL)
1200 id = WinQueryWindowUShort(hwnd, QWS_ID);
1201 else
1202 id = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd,
1203 PickToolProc, FM3ModHandle,
1204 PICKBTN_FRAME, GetPString(IDS_HIDETEXT));
1205 if (id) {
1206 tool = find_tool(id);
1207 if (tool) {
1208 tool->flags |= T_INVISIBLE;
1209 fToolsChanged = TRUE;
1210 }
1211 }
1212 break;
1213
1214 case IDM_SHOWTOOLS: /* show all tools */
1215 tool = toolhead;
1216 while (tool) {
1217 tool->flags &= (~T_INVISIBLE);
1218 tool = tool->next;
1219 fToolsChanged = TRUE;
1220 }
1221 break;
1222
1223 case IDM_DELETEANYTOOL: /* delete any button */
1224 case IDM_DELETETOOL: /* delete button */
1225 if (SHORT1FROMMP(mp1) == IDM_DELETETOOL)
1226 id = WinQueryWindowUShort(hwnd, QWS_ID);
1227 else
1228 id =
1229 (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, PickToolProc, FM3ModHandle,
1230 PICKBTN_FRAME, GetPString(IDS_DELETETEXT));
1231 if (id)
1232 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_SETUP,
1233 MPFROM2SHORT(id, 0), MPVOID);
1234 return 0;
1235
1236 case IDM_EDITANYTOOL: /* edit any button */
1237 case IDM_EDITTOOL: /* edit button */
1238 if (SHORT1FROMMP(mp1) == IDM_EDITTOOL)
1239 id = WinQueryWindowUShort(hwnd, QWS_ID);
1240 else
1241 id =
1242 (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, PickToolProc, FM3ModHandle,
1243 PICKBTN_FRAME, GetPString(IDS_EDITTEXT));
1244 if (id) {
1245 tool = find_tool(id);
1246 if (tool) {
1247 if (WinDlgBox(HWND_DESKTOP, hwnd, AddToolProc, FM3ModHandle,
1248 ADDBTN_FRAME, (PVOID) tool))
1249 WinSendMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
1250 QW_PARENT),
1251 QW_PARENT), FID_CLIENT),
1252 WM_COMMAND, MPFROM2SHORT(IDM_CREATETOOL, 0),
1253 MPFROM2SHORT(id, 0));
1254 }
1255 }
1256 break;
1257
1258 case IDM_ADDTOOL: /* add tool */
1259 id = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, AddToolProc, FM3ModHandle,
1260 ADDBTN_FRAME, MPVOID);
1261 if (id && id != (USHORT) - 1)
1262 WinSendMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
1263 QW_PARENT),
1264 QW_PARENT), FID_CLIENT),
1265 WM_COMMAND, MPFROM2SHORT(IDM_CREATETOOL, 0),
1266 MPFROM2SHORT(id, 0));
1267 break;
1268
1269 case IDM_REORDERTOOLS: /* reorder tools */
1270 WinDlgBox(HWND_DESKTOP,
1271 hwnd, ReOrderToolsProc, FM3ModHandle, RE_FRAME, MPVOID);
1272 break;
1273
1274 case IDM_SAVETOOLS:
1275 case IDM_LOADTOOLS:
1276 if (WinDlgBox(HWND_DESKTOP,
1277 hwnd,
1278 ToolIODlgProc,
1279 FM3ModHandle,
1280 SVBTN_FRAME,
1281 (PVOID) (SHORT1FROMMP(mp1) == IDM_SAVETOOLS) ?
1282 "TRUE" : NULL))
1283 BuildTools(hwndToolback, TRUE);
1284 break;
1285 }
1286 ResizeTools(WinQueryWindow(hwnd, QW_PARENT));
1287 return 0;
1288
1289 case WM_MENUEND:
1290 if (hwndMenu == (HWND) mp2) {
1291 WinDestroyWindow(hwndMenu);
1292 hwndMenu = (HWND) 0;
1293 }
1294 break;
1295
1296 case WM_CONTEXTMENU:
1297 DosEnterCritSec();
1298 if (!hwndMenu)
1299 hwndMenu = WinLoadMenu(hwnd, FM3ModHandle, ID_BUTTONMENU);
1300 DosExitCritSec();
1301 SetPresParams(hwndMenu, NULL, NULL, NULL, GetPString(IDS_10SYSPROTEXT));
1302 if (PopupMenu(hwnd, hwnd, hwndMenu))
1303 WinShowWindow(hwndMenu, TRUE);
1304 return MRFROMSHORT(TRUE);
1305
1306 case DM_DRAGOVER:
1307 {
1308 PDRAGINFO pDInfo; /* Pointer to DRAGINFO */
1309
1310 pDInfo = (PDRAGINFO) mp1; /* Get DRAGINFO pointer */
1311 DrgAccessDraginfo(pDInfo); /* Access DRAGINFO */
1312 id = WinQueryWindowUShort(hwnd, QWS_ID);
1313 tool = find_tool(id);
1314 if (!tool) {
1315 DrgFreeDraginfo(pDInfo);
1316 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); /* Drop not valid */
1317 }
1318 if (!(tool->flags & T_DROPABLE)) {
1319 DrgFreeDraginfo(pDInfo);
1320 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); /* Drop not valid */
1321 }
1322 {
1323 PDRAGITEM pDItem; /* Pointer to DRAGITEM */
1324
1325 pDItem = DrgQueryDragitemPtr(pDInfo, /* Access DRAGITEM */
1326 0); /* Index to DRAGITEM */
1327 if (DrgVerifyRMF(pDItem, /* Check valid rendering */
1328 DRM_OS2FILE, /* mechanisms and data */
1329 NULL)) { /* formats */
1330 if (!(tool->flags & T_EMPHASIZED)) {
1331 tool->flags |= T_EMPHASIZED;
1332 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1333 DrgFreeDraginfo(pDInfo);
1334 }
1335 return (MRFROM2SHORT(DOR_DROP, /* Return okay to drop */
1336 DO_MOVE)); /* Move operation valid */
1337 }
1338 DrgFreeDraginfo(pDInfo);
1339 }
1340 }
1341 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); /* Drop not valid */
1342
1343 case DM_DROPHELP:
1344 id = WinQueryWindowUShort(hwnd, QWS_ID);
1345 tool = find_tool(id);
1346 PFNWPButton(hwnd, msg, mp1, mp2);
1347 DropHelp(mp1, mp2, hwnd, GetPString(IDS_TOOLDROPHELP));
1348 return 0;
1349
1350 case DM_DRAGLEAVE:
1351 id = WinQueryWindowUShort(hwnd, QWS_ID);
1352 tool = find_tool(id);
1353 if (tool && (tool->flags & T_DROPABLE)) {
1354 if (tool->flags & T_EMPHASIZED) {
1355 tool->flags &= (~T_EMPHASIZED);
1356 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1357 }
1358 }
1359 break;
1360
1361 case DM_DROP:
1362 id = WinQueryWindowUShort(hwnd, QWS_ID);
1363 tool = find_tool(id);
1364 if (tool && (tool->flags & T_DROPABLE) != 0) {
1365 LISTINFO *li;
1366 CNRDRAGINFO cdi;
1367
1368 if (tool->flags & T_EMPHASIZED) {
1369 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1370 tool->flags &= (~T_EMPHASIZED);
1371 }
1372 memset(&cdi, 0, sizeof(cdi));
1373 cdi.pDragInfo = mp1;
1374 li = DoFileDrop(hwnd, NULL, FALSE, mp1, MPFROMP(&cdi));
1375 CheckPmDrgLimit(cdi.pDragInfo);
1376 if (li) {
1377 li->type = id;
1378 if (!li->list || !li->list[0])
1379 FreeListInfo(li);
1380 else {
1381 HWND hwndActive;
1382
1383 hwndActive = TopWindow(hwndMain, (HWND) 0);
1384 if (hwndActive) {
1385 if (!WinSendMsg(hwndActive, UM_COMMAND, MPFROMP(li), MPVOID))
1386 FreeListInfo(li);
1387 }
1388 else
1389 FreeListInfo(li);
1390 }
1391 }
1392 }
1393 return 0;
1394
1395 case WM_CLOSE:
1396 WinDestroyWindow(hwnd);
1397 return 0;
1398 }
1399 return PFNWPButton(hwnd, msg, mp1, mp2);
1400}
1401
1402VOID BuildTools(HWND hwndT, BOOL resize)
1403{
1404 TOOL *tool;
1405 ULONG ctrlxpos = 18L;
1406 CHAR s[33];
1407 HENUM henum;
1408 HWND hwndTool;
1409
1410 henum = WinBeginEnumWindows(hwndT);
1411 while ((hwndTool = WinGetNextWindow(henum)) != NULLHANDLE)
1412 WinDestroyWindow(hwndTool);
1413 WinEndEnumWindows(henum);
1414 if (!fToolbar) {
1415 load_quicktools();
1416 load_tools(NULL);
1417 return;
1418 }
1419 if (!toolhead)
1420 load_tools(NULL);
1421 tool = toolhead;
1422 while (tool) {
1423 sprintf(s, "#%u", tool->id);
1424 hwndTool = (HWND) 0;
1425 if (!fTextTools) {
1426 if (!(tool->flags & T_MYICON)) {
1427 hwndTool = WinCreateWindow(hwndT,
1428 WC_TOOLBUTTONS,
1429 s,
1430 BS_NOPOINTERFOCUS |
1431 BS_BITMAP | BS_PUSHBUTTON,
1432 ctrlxpos,
1433 14,
1434 32,
1435 32, hwndT, HWND_TOP, tool->id, NULL, NULL);
1436 }
1437 if (!hwndTool) {
1438 HBITMAP hbm = LoadBitmapFromFileNum(tool->id);
1439
1440 if (hbm) {
1441 BTNCDATA btc;
1442
1443 memset(&btc, 0, sizeof(btc));
1444 btc.cb = sizeof(btc);
1445 btc.hImage = hbm;
1446 hwndTool = WinCreateWindow(hwndT,
1447 WC_TOOLBUTTONS,
1448 NullStr,
1449 BS_NOPOINTERFOCUS |
1450 BS_BITMAP | BS_PUSHBUTTON,
1451 ctrlxpos,
1452 14,
1453 32,
1454 32,
1455 hwndT, HWND_TOP, tool->id, &btc, NULL);
1456 if (!hwndTool)
1457 GpiDeleteBitmap(hbm);
1458 }
1459 }
1460 if (hwndTool)
1461 tool->flags &= (~T_TEXT);
1462 }
1463 if (!hwndTool) {
1464 hwndTool = WinCreateWindow(hwndT,
1465 WC_TOOLBUTTONS,
1466 (!tool->text && tool->id >= IDM_COMMANDSTART
1467 && tool->id <
1468 IDM_QUICKTOOLSTART) ? command_title(tool->
1469 id -
1470 IDM_COMMANDSTART)
1471 : tool->text,
1472 BS_NOPOINTERFOCUS | BS_PUSHBUTTON, ctrlxpos,
1473 2, 54, 24, hwndT, HWND_TOP, tool->id, NULL,
1474 NULL);
1475 if (!hwndTool)
1476 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1477 IDS_WINCREATEWINDOW);
1478 tool->flags |= T_TEXT;
1479 }
1480 if (fToolTitles && !fTextTools) {
1481 hwndTool = WinCreateWindow(hwndT,
1482 WC_STATIC,
1483 tool->text,
1484 SS_TEXT | DT_LEFT | DT_VCENTER,
1485 ctrlxpos,
1486 1,
1487 32,
1488 10,
1489 hwndT,
1490 HWND_TOP, tool->id + 25000, NULL, NULL);
1491 if (!hwndTool)
1492 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1493 IDS_WINCREATEWINDOW);
1494 else {
1495 SetPresParams(hwndTool,
1496 &RGBGREY,
1497 &RGBBLACK, &RGBGREY, GetPString(IDS_2SYSTEMVIOTEXT));
1498 }
1499 }
1500 ctrlxpos += ((tool->flags & T_TEXT) ? 55L : 33L);
1501 SetPresParams(WinWindowFromID(hwndT, tool->id),
1502 NULL, NULL, NULL, GetPString(IDS_8HELVTEXT));
1503 tool = tool->next;
1504 } // while tool
1505
1506 hwndTool = WinCreateWindow(hwndT,
1507 WC_BUTTON,
1508 "#6010",
1509 BS_NOPOINTERFOCUS |
1510 BS_BITMAP | BS_PUSHBUTTON,
1511 1,
1512 19,
1513 14,
1514 13, hwndT, HWND_TOP, IDM_TOOLLEFT, NULL, NULL);
1515 if (!hwndTool)
1516 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1517 IDS_WINCREATEWINDOW);
1518 hwndTool =
1519 WinCreateWindow(hwndT, WC_BUTTON, "#6011",
1520 BS_NOPOINTERFOCUS | BS_BITMAP | BS_PUSHBUTTON, 1, 4, 14,
1521 13, hwndT, HWND_TOP, IDM_TOOLRIGHT, NULL, NULL);
1522 if (!hwndTool)
1523 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1524 IDS_WINCREATEWINDOW);
1525 if (resize)
1526 ResizeTools(hwndT);
1527}
1528
1529static MRESULT EXPENTRY CommandLineProc(HWND hwnd, ULONG msg, MPARAM mp1,
1530 MPARAM mp2)
1531{
1532 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1533 static BOOL lbup = FALSE;
1534
1535 switch (msg) {
1536 case UM_FOCUSME:
1537 WinSetFocus(HWND_DESKTOP, hwnd);
1538 return 0;
1539
1540 case WM_SETFOCUS:
1541 if (!mp2 && !lbup) {
1542
1543 PID pid;
1544 TID tid;
1545
1546 if (WinQueryWindowUShort((HWND) mp1, QWS_ID) == COMMAND_BUTTON)
1547 break;
1548 if (!WinQueryWindowProcess((HWND) mp1, &pid, &tid) || pid == mypid)
1549 WinDestroyWindow(hwnd);
1550 }
1551 break;
1552
1553 case UM_RESCAN:
1554 {
1555 PSZ pszCmdLine;
1556
1557 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1558 if (pszCmdLine) {
1559 lbup = TRUE;
1560 if (WinDlgBox(HWND_DESKTOP,
1561 hwnd,
1562 CmdLine2DlgProc,
1563 FM3ModHandle, EXEC2_FRAME, MPFROMP(pszCmdLine))) {
1564 lstrip(pszCmdLine);
1565 WinSetWindowText(hwnd, pszCmdLine);
1566 }
1567 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1568 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1569 free(pszCmdLine);
1570 }
1571 }
1572 return 0;
1573
1574 case UM_SETUP:
1575 lbup = FALSE;
1576 return 0;
1577
1578 case WM_BUTTON1DBLCLK:
1579 PostMsg(hwnd, UM_OPENWINDOWFORME, MPVOID, MPVOID);
1580 return 0;
1581
1582 case WM_COMMAND:
1583 switch (SHORT1FROMMP(mp1)) {
1584 case COMMAND_BUTTON:
1585 if (!lbup)
1586 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1587 break;
1588 }
1589 return 0;
1590
1591 case UM_OPENWINDOWFORME:
1592 {
1593 static char directory[CCHMAXPATH], cl[1000];
1594 char **list = NULL;
1595 ULONG len;
1596 HWND hwndCnr;
1597
1598 *directory = *cl = 0;
1599 strcpy(cl, GetCmdSpec(FALSE));
1600 strcat(cl, " /C ");
1601 len = strlen(cl);
1602 WinQueryWindowText(hwnd, 1000 - len, cl + len);
1603 bstrip(cl + len);
1604 if (strlen(cl) > len) {
1605 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
1606 UM_SETUP, MPFROMP(cl + len), MPVOID);
1607 WinQueryWindowText(hwndStatus, CCHMAXPATH, directory);
1608 bstrip(directory);
1609 if (*directory && (IsRoot(directory) || !IsFile(directory))) {
1610 if (!FM2Command(directory, cl + len)) {
1611 hwndCnr = TopWindow(hwndMain, (HWND) 0);
1612 if (hwndCnr) {
1613 hwndCnr = WinWindowFromID(hwndCnr, FID_CLIENT);
1614 if (hwndCnr) {
1615 hwndCnr = WinWindowFromID(hwndCnr, DIR_CNR);
1616 if (hwndCnr)
1617 list = BuildList(hwndCnr);
1618 }
1619 }
1620 WinSetActiveWindow(HWND_DESKTOP, hwndCnr);
1621 if (add_cmdline(cl + len, FALSE) && fSaveMiniCmds)
1622 save_cmdlines(FALSE);
1623 ExecOnList(hwndCnr,
1624 cl,
1625 WINDOWED | ((fKeepCmdLine) ?
1626 SEPARATEKEEP : SEPARATE),
1627 directory, list, NULL, pszSrcFile, __LINE__);
1628 xfree(list, pszSrcFile, __LINE__);
1629 WinDestroyWindow(hwnd);
1630 break;
1631 }
1632 }
1633 }
1634 WinSendMsg(hwnd, EM_SETSEL, MPFROM2SHORT(0, 1024), MPVOID);
1635 }
1636 return 0;
1637
1638 case WM_CHAR:
1639 if (!lbup && !(SHORT1FROMMP(mp1) & KC_KEYUP)) {
1640 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
1641 if ((SHORT1FROMMP(mp2) & 255) == '\r')
1642 PostMsg(hwnd, UM_OPENWINDOWFORME, MPVOID, MPVOID);
1643 else if ((SHORT1FROMMP(mp2) & 0xff) == 0x1b)
1644 WinDestroyWindow(hwnd);
1645 else if (SHORT2FROMMP(mp2) == VK_UP || SHORT2FROMMP(mp2) == VK_DOWN)
1646 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1647 }
1648 }
1649 else if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
1650 ((SHORT2FROMMP(mp2) == VK_UP ||
1651 SHORT2FROMMP(mp2) == VK_DOWN) ||
1652 (SHORT1FROMMP(mp2) == '\x1b') || (SHORT1FROMMP(mp2) == '\r')))
1653 return 0;
1654 break;
1655
1656 case WM_DESTROY:
1657 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_RESCAN, MPVOID, MPVOID);
1658 lbup = FALSE;
1659 break;
1660 }
1661 return oldproc(hwnd, msg, mp1, mp2);
1662}
1663
1664MRESULT EXPENTRY DriveBackProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1665{
1666 switch (msg) {
1667 case WM_CREATE:
1668 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1669 break;
1670
1671 case UM_SETUP:
1672 {
1673 RGB2 rgb;
1674
1675 memset(&rgb, 0, sizeof(rgb));
1676 rgb.bRed = (BYTE)128;
1677 SetPresParams(hwnd,
1678 &RGBGREY, &rgb, &RGBGREY, GetPString(IDS_8HELVTEXT));
1679 SetTargetDir(hwnd, TRUE);
1680 }
1681 return 0;
1682
1683 case WM_SETFOCUS:
1684 case UM_FOCUSME:
1685 case WM_BUTTON1DOWN:
1686 case WM_BUTTON1UP:
1687 case WM_BUTTON2DOWN:
1688 case WM_BUTTON2UP:
1689 case WM_BUTTON3DOWN:
1690 case WM_BUTTON3UP:
1691 return CommonTextButton(hwnd, msg, mp1, mp2);
1692
1693 case WM_MOUSEMOVE:
1694 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1695 break;
1696
1697 case UM_CLICKED:
1698 case UM_CLICKED3:
1699 PostMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_SETTARGET, 0), MPVOID);
1700 return 0;
1701
1702 case WM_CHAR:
1703 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1704 break;
1705
1706 case WM_CONTROLPOINTER:
1707 if (!fNoFinger &&
1708 (SHORT1FROMMP(mp1) >= IDM_DRIVEA &&
1709 SHORT1FROMMP(mp1) < IDM_DRIVEA + 26))
1710 return MRFROMLONG(hptrFinger);
1711 break;
1712
1713 case WM_COMMAND:
1714 {
1715 CHAR dv[4];
1716
1717 *dv = 0;
1718 WinQueryWindowText(WinWindowFromID(hwnd, SHORT1FROMMP(mp1) + 50),
1719 2, dv);
1720 if (isalpha(*dv)) {
1721
1722 HWND hwndActive;
1723
1724 dv[1] = ':';
1725 dv[2] = '\\';
1726 dv[3] = 0;
1727 hwndActive = TopWindow(hwnd, (HWND) 0);
1728 if (hwndActive)
1729 WinSendMsg(WinWindowFromID(hwndActive, FID_CLIENT),
1730 UM_DRIVECMD, MPFROMP(dv), MPVOID);
1731 }
1732 }
1733 return 0;
1734
1735 case WM_PAINT:
1736 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
1737 break;
1738
1739 case WM_CLOSE:
1740 WinDestroyWindow(hwnd);
1741 return 0;
1742 }
1743 return PFNWPStatic(hwnd, msg, mp1, mp2);
1744}
1745
1746MRESULT EXPENTRY DriveProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1747{
1748 USHORT id;
1749 CHAR szDrv[CCHMAXPATH];
1750
1751 static BOOL emphasized = FALSE;
1752 static HWND hwndMenu = NULLHANDLE;
1753 static USHORT helpid = 0;
1754
1755 switch (msg) {
1756 case WM_MOUSEMOVE:
1757 if (fDrivebarHelp &&
1758 (!hwndBubble ||
1759 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
1760 !WinQueryCapture(HWND_DESKTOP)) {
1761 id = WinQueryWindowUShort(hwnd, QWS_ID);
1762 if (helpid != id) {
1763 helpid = id;
1764 PostMsg(MainObjectHwnd, UM_SETUP6, MPFROMLONG((ULONG) hwnd), MPVOID);
1765 }
1766 else
1767 helpid = 0;
1768 }
1769 break;
1770
1771 case UM_SETUP6:
1772 if (helpid == WinQueryWindowUShort(hwnd, QWS_ID)) {
1773 if ((char *)mp1 &&
1774 (!hwndBubble ||
1775 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
1776 !WinQueryCapture(HWND_DESKTOP)) {
1777
1778 RECTL rcl;
1779 POINTL ptl;
1780
1781 WinQueryPointerPos(HWND_DESKTOP, &ptl);
1782 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1);
1783 WinQueryWindowRect(hwnd, &rcl);
1784 if (WinPtInRect(WinQueryAnchorBlock(hwnd), &rcl, &ptl))
1785 BubbleHelp(hwnd, FALSE, TRUE, FALSE, (char *)mp1);
1786 }
1787 }
1788 return 0;
1789
1790 case WM_MENUEND:
1791 if (hwndMenu == (HWND) mp2) {
1792 WinDestroyWindow(hwndMenu);
1793 hwndMenu = (HWND) 0;
1794 }
1795 break;
1796
1797 case WM_CONTEXTMENU:
1798 if (hwndMenu)
1799 WinDestroyWindow(hwndMenu);
1800 hwndMenu = (HWND) 0;
1801 id = WinQueryWindowUShort(hwnd, QWS_ID);
1802 *szDrv = 0;
1803 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1804 id + 50), sizeof(szDrv), szDrv);
1805 if (isalpha(*szDrv)) {
1806 hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, MAIN_DRIVES);
1807 if (hwndMenu) {
1808 BOOL rdy;
1809 CHAR chDrv = *szDrv;
1810 UINT iDrv;
1811
1812 strcpy(szDrv + 2, "\\");
1813 MakeValidDir(szDrv);
1814 // Disable menus if MakeValidDir changes drive letter fixme this section doesn't do anything see treecnt.c
1815 rdy = toupper(*szDrv) == toupper(chDrv);
1816 iDrv = toupper(*szDrv) - 'A';
1817 if (!rdy || ~driveflags[iDrv] & DRIVE_REMOTE)
1818 WinEnableMenuItem(hwndMenu, IDM_DETACH, FALSE);
1819
1820 if (!rdy || driveflags[iDrv] & DRIVE_NOTWRITEABLE) {
1821 WinEnableMenuItem(hwndMenu, IDM_MKDIR, FALSE);
1822 WinEnableMenuItem(hwndMenu, IDM_FORMAT, FALSE);
1823 WinEnableMenuItem(hwndMenu, IDM_OPTIMIZE, FALSE);
1824 WinEnableMenuItem(hwndMenu, IDM_UNDELETE, FALSE);
1825 }
1826 if (!rdy || ~driveflags[iDrv] & DRIVE_REMOVABLE) {
1827 WinEnableMenuItem(hwndMenu, IDM_EJECT, FALSE);
1828 WinEnableMenuItem(hwndMenu, IDM_LOCK, FALSE);
1829 WinEnableMenuItem(hwndMenu, IDM_UNLOCK, FALSE);
1830 }
1831 if (!rdy) {
1832 WinEnableMenuItem(hwndMenu, IDM_INFO, FALSE);
1833 WinEnableMenuItem(hwndMenu, IDM_ARCHIVE, FALSE);
1834 WinEnableMenuItem(hwndMenu, IDM_SIZES, FALSE);
1835 WinEnableMenuItem(hwndMenu, IDM_SHOWALLFILES, FALSE);
1836 WinEnableMenuItem(hwndMenu, IDM_CHKDSK, FALSE);
1837 }
1838 /* fixme to be gone?
1839 if (!rdy || ~driveflags[iDrv] & DRIVE_CDROM) {
1840 WinEnableMenuItem(hwndMenu, IDM_CLOSETRAY, FALSE);
1841 }
1842 */
1843 PopupMenu(hwnd, hwnd, hwndMenu);
1844 }
1845 }
1846 return MRFROMSHORT(TRUE);
1847
1848 case WM_BUTTON2CLICK:
1849 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
1850 if (!(shiftstate & KC_CTRL))
1851 break;
1852
1853 case WM_CHORD:
1854 case WM_BUTTON3CLICK:
1855 id = WinQueryWindowUShort(hwnd, QWS_ID);
1856 *szDrv = 0;
1857 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1858 id + 50), sizeof(szDrv), szDrv);
1859 if (isalpha(*szDrv)) {
1860 strcat(szDrv, "\\");
1861 if (!FindDirCnrByName(szDrv, TRUE))
1862 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, szDrv);
1863 }
1864 break;
1865
1866 case WM_COMMAND:
1867 PostMsg(hwnd, UM_COMMAND, mp1, mp2);
1868 return 0;
1869
1870 case UM_COMMAND:
1871 id = WinQueryWindowUShort(hwnd, QWS_ID);
1872 *szDrv = 0;
1873 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1874 id + 50), sizeof(szDrv), szDrv);
1875 if (isalpha(*szDrv)) {
1876 strcat(szDrv, "\\");
1877 CommonDriveCmd(hwnd, szDrv, SHORT1FROMMP(mp1));
1878 }
1879 return 0;
1880
1881 case DM_DRAGOVER:
1882 id = WinQueryWindowUShort(hwnd, QWS_ID);
1883 *szDrv = 0;
1884 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1885 id + 50), sizeof(szDrv), szDrv);
1886 if (isalpha(*szDrv) &&
1887 !(driveflags[toupper(*szDrv) - 'A'] & DRIVE_NOTWRITEABLE)) {
1888 if (!emphasized) {
1889 emphasized = TRUE;
1890 DrawTargetEmphasis(hwnd, emphasized);
1891 }
1892 if (AcceptOneDrop(hwnd, mp1, mp2))
1893 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1894 return MRFROM2SHORT(DOR_NEVERDROP, 0);
1895 }
1896 break;
1897
1898 case DM_DRAGLEAVE:
1899 id = WinQueryWindowUShort(hwnd, QWS_ID);
1900 *szDrv = 0;
1901 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1902 id + 50), sizeof(szDrv), szDrv);
1903 if (isalpha(*szDrv) &&
1904 !(driveflags[toupper(*szDrv) - 'A'] & DRIVE_NOTWRITEABLE)) {
1905 if (emphasized) {
1906 emphasized = FALSE;
1907 DrawTargetEmphasis(hwnd, emphasized);
1908 }
1909 }
1910 break;
1911
1912 case DM_DROPHELP:
1913 id = WinQueryWindowUShort(hwnd, QWS_ID);
1914 *szDrv = 0;
1915 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1916 id + 50), sizeof(szDrv), szDrv);
1917 if (isalpha(*szDrv) &&
1918 !(driveflags[toupper(*szDrv) - 'A'] & DRIVE_NOTWRITEABLE)) {
1919 DropHelp(mp1, mp2, hwnd, GetPString(IDS_DRIVEDROPHELP));
1920 return 0;
1921 }
1922 break;
1923
1924 case DM_DROP:
1925 id = WinQueryWindowUShort(hwnd, QWS_ID);
1926 *szDrv = 0;
1927 WinQueryWindowText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1928 id + 50), sizeof(szDrv), szDrv);
1929 if (isalpha(*szDrv) &&
1930 !(driveflags[toupper(*szDrv) - 'A'] & DRIVE_NOTWRITEABLE)) {
1931
1932 CNRDRAGINFO cnd;
1933 LISTINFO *li;
1934 ULONG action = UM_ACTION;
1935
1936 if (emphasized) {
1937 emphasized = FALSE;
1938 DrawTargetEmphasis(hwnd, emphasized);
1939 }
1940 memset(&cnd, 0, sizeof(cnd));
1941 cnd.pDragInfo = (PDRAGINFO) mp1;
1942 cnd.pRecord = NULL;
1943 li = DoFileDrop(hwnd,
1944 NULL,
1945 TRUE, MPFROM2SHORT(TREE_CNR, CN_DROP), MPFROMP(&cnd));
1946 CheckPmDrgLimit(cnd.pDragInfo);
1947 if (li) {
1948 strcpy(li->targetpath, szDrv);
1949 strcat(li->targetpath, "\\");
1950 if (li->list && li->list[0] && IsRoot(li->list[0]))
1951 li->type = DO_LINK;
1952 else if (fDragndropDlg && (!*li->arcname || !li->info)) {
1953
1954 CHECKLIST cl;
1955
1956 memset(&cl, 0, sizeof(cl));
1957 cl.size = sizeof(cl);
1958 cl.flags = li->type;
1959 cl.list = li->list;
1960 cl.cmd = li->type;
1961 cl.prompt = li->targetpath;
1962 li->type = WinDlgBox(HWND_DESKTOP,
1963 hwndMain,
1964 DropListProc,
1965 FM3ModHandle, DND_FRAME, MPFROMP(&cl));
1966 if (li->type == DID_ERROR)
1967 Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
1968 "Drag & Drop Dialog");
1969 if (!li->type) {
1970 FreeListInfo(li);
1971 return 0;
1972 }
1973 li->list = cl.list;
1974 if (!li->list || !li->list[0]) {
1975 FreeListInfo(li);
1976 return 0;
1977 }
1978 }
1979 else {
1980 if (!WinDlgBox(HWND_DESKTOP,
1981 hwndMain,
1982 WalkDlgProc,
1983 FM3ModHandle,
1984 WALK_FRAME,
1985 MPFROMP(li->targetpath)) || !*li->targetpath) {
1986 FreeListInfo(li);
1987 return 0;
1988 }
1989 }
1990 switch (li->type) {
1991 case DND_LAUNCH:
1992 strcat(li->targetpath, " %a");
1993 ExecOnList(hwndMain,
1994 li->targetpath, PROMPT | WINDOWED, NULL, li->list, NULL,
1995 pszSrcFile, __LINE__);
1996 FreeList(li->list);
1997 li->list = NULL;
1998 break;
1999 case DO_LINK:
2000 if (fLinkSetsIcon) {
2001 li->type = IDM_SETICON;
2002 action = UM_MASSACTION;
2003 }
2004 else
2005 li->type = IDM_COMPARE;
2006 break;
2007 case DND_EXTRACT:
2008 if (*li->targetpath && !IsFile(li->targetpath))
2009 li->type = IDM_EXTRACT;
2010 break;
2011 case DND_MOVE:
2012 li->type = IDM_MOVE;
2013 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2014 action = UM_MASSACTION;
2015 li->type = IDM_ARCHIVEM;
2016 }
2017 break;
2018 case DND_WILDMOVE:
2019 li->type = IDM_WILDMOVE;
2020 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2021 action = UM_MASSACTION;
2022 li->type = IDM_ARCHIVEM;
2023 }
2024 break;
2025 case DND_OBJECT:
2026 li->type = IDM_OBJECT;
2027 action = UM_MASSACTION;
2028 break;
2029 case DND_SHADOW:
2030 li->type = IDM_SHADOW;
2031 action = UM_MASSACTION;
2032 break;
2033 case DND_COMPARE:
2034 li->type = IDM_COMPARE;
2035 break;
2036 case DND_SETICON:
2037 action = UM_MASSACTION;
2038 li->type = IDM_SETICON;
2039 break;
2040 case DND_COPY:
2041 li->type = IDM_COPY;
2042 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2043 action = UM_MASSACTION;
2044 li->type = IDM_ARCHIVE;
2045 }
2046 break;
2047 case DND_WILDCOPY:
2048 li->type = IDM_WILDCOPY;
2049 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2050 action = UM_MASSACTION;
2051 li->type = IDM_ARCHIVE;
2052 }
2053 break;
2054 default:
2055 if (*li->arcname && li->info) {
2056 action = UM_MASSACTION;
2057 li->type = (li->type == DO_MOVE) ? IDM_FAKEEXTRACTM :
2058 IDM_FAKEEXTRACT;
2059 }
2060 else if (*li->targetpath && IsFile(li->targetpath) == 1) {
2061 action = UM_MASSACTION;
2062 li->type = (li->type == DO_MOVE) ? IDM_ARCHIVEM : IDM_ARCHIVE;
2063 }
2064 else
2065 li->type = (li->type == DO_MOVE) ? IDM_MOVE : IDM_COPY;
2066 break;
2067 }
2068 if (!li->list || !li->list[0])
2069 FreeListInfo(li);
2070 else
2071 WinSendMsg(hwndTree, UM_ACTION, MPFROMP(li), MPFROMLONG(action));
2072 }
2073 return 0;
2074 }
2075 break;
2076
2077 case WM_DESTROY:
2078 if (hwndMenu)
2079 WinDestroyWindow(hwndMenu);
2080 hwndMenu = (HWND) 0;
2081 break;
2082 }
2083 return PFNWPButton(hwnd, msg, mp1, mp2);
2084}
2085
2086VOID BuildDriveBarButtons(HWND hwndT)
2087{
2088 register ULONG x, y = 0;
2089 ULONG ulDriveNum, ulDriveMap, iconid;
2090 CHAR s[8];
2091 HENUM henum;
2092 HWND hwndB;
2093
2094 henum = WinBeginEnumWindows(hwndT);
2095
2096 while ((hwndB = WinGetNextWindow(henum)) != NULLHANDLE)
2097 WinDestroyWindow(hwndB);
2098
2099 WinEndEnumWindows(henum);
2100 if (fDrivebar) {
2101 DosError(FERR_DISABLEHARDERR);
2102 DosQCurDisk(&ulDriveNum, &ulDriveMap);
2103 for (x = 0; x < 26; x++) {
2104 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
2105 if (x > 1) {
2106 if (driveflags[x] & DRIVE_CDROM)
2107 iconid = CDROM_ICON;
2108 else
2109 iconid = (driveflags[x] & DRIVE_REMOVABLE) ?
2110 REMOVABLE_ICON :
2111 (driveflags[x] & DRIVE_VIRTUAL) ?
2112 VIRTUAL_ICON :
2113 (driveflags[x] & DRIVE_REMOTE) ?
2114 REMOTE_ICON :
2115 (driveflags[x] & DRIVE_RAMDISK) ?
2116 RAMDISK_ICON :
2117 (driveflags[x] & DRIVE_ZIPSTREAM) ?
2118 ZIPSTREAM_ICON :DRIVE_ICON;
2119 }
2120 else
2121 iconid = FLOPPY_ICON;
2122 sprintf(s, "#%lu", iconid);
2123 hwndB = WinCreateWindow(hwndT,
2124 WC_DRIVEBUTTONS,
2125 s,
2126 BS_NOPOINTERFOCUS | BS_BITMAP | BS_PUSHBUTTON,
2127 0,
2128 0,
2129 28,
2130 18,
2131 hwndT, HWND_TOP, y + IDM_DRIVEA, NULL, NULL);
2132 if (!hwndB)
2133 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
2134 IDS_WINCREATEWINDOW);
2135 else {
2136 WinSetWindowPos(hwndB, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
2137 sprintf(s, "%c:", (CHAR) x + 'A');
2138 hwndB = WinCreateWindow(hwndT,
2139 WC_STATIC,
2140 s,
2141 SS_TEXT | DT_LEFT | DT_VCENTER,
2142 0,
2143 0,
2144 10,
2145 18,
2146 hwndT,
2147 HWND_TOP, y + IDM_DRIVEATEXT, NULL, NULL);
2148 if (!hwndB)
2149 Win_Error2(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
2150 IDS_WINCREATEWINDOW);
2151 else {
2152 SetPresParams(hwndB,
2153 &RGBGREY,
2154 &RGBBLACK, &RGBGREY, GetPString(IDS_6HELVTEXT));
2155 WinSetWindowPos(hwndB, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
2156 }
2157 y++;
2158 }
2159 }
2160 } // for
2161 } // if drivebar
2162 PostMsg(WinQueryWindow(hwndT, QW_PARENT),
2163 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
2164}
2165
2166VOID ResizeDrives(HWND hwndT, long xwidth)
2167{
2168 register ULONG ctrlxpos = 2, ctrlypos = 0, ctrlxsize;
2169 HENUM henum;
2170 HWND hwndB;
2171 RECTL rcl;
2172
2173 DriveLines = 0;
2174 if (!fDrivebar)
2175 return;
2176 if (!xwidth) {
2177 WinQueryWindowRect(hwndT, &rcl);
2178 xwidth = rcl.xRight - ((WinQuerySysValue(HWND_DESKTOP,
2179 SV_CYSIZEBORDER) * 2) + 2);
2180 }
2181 henum = WinBeginEnumWindows(hwndT);
2182 while ((hwndB = WinGetNextWindow(henum)) != NULLHANDLE) {
2183 if (WinQueryWindowUShort(hwndB, QWS_ID) > IDM_DRIVEA + 27)
2184 ctrlxsize = 10;
2185 else
2186 ctrlxsize = 28;
2187 WinSetWindowPos(hwndB,
2188 HWND_TOP,
2189 ctrlxpos, ctrlypos, ctrlxsize, 18, SWP_MOVE | SWP_SHOW);
2190 ctrlxpos += (ctrlxsize + 2);
2191 if (ctrlxsize == 10) {
2192 if (ctrlxpos + (42 + ((fShowTarget && DriveLines == 0) ?
2193 256 : 0)) > xwidth) {
2194 ctrlxpos = 2;
2195 ctrlypos += 18;
2196 DriveLines++;
2197 }
2198 }
2199 }
2200 if (ctrlxpos == 2 && DriveLines)
2201 DriveLines--;
2202}
2203
2204MRESULT EXPENTRY StatusProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2205{
2206 static HWND hwndE = (HWND) 0, hwndB = (HWND) 0;
2207 static CHAR lastcmd[1024] = "";
2208
2209 switch (msg) {
2210 case WM_CREATE:
2211 {
2212 MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
2213
2214 SetPresParams(hwnd,
2215 &RGBGREY,
2216 &RGBBLACK, &RGBGREY, GetPString(IDS_8HELVBOLDTEXT));
2217 return mr;
2218 }
2219
2220 case WM_PRESPARAMCHANGED:
2221 if (fRunning) {
2222
2223 ULONG AttrFound, AttrValue[64], cbRetLen;
2224
2225 cbRetLen = WinQueryPresParam(hwnd,
2226 (ULONG) mp1,
2227 0,
2228 &AttrFound,
2229 (ULONG) sizeof(AttrValue), &AttrValue, 0);
2230 if (cbRetLen) {
2231 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
2232 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
2233 }
2234 }
2235 break;
2236
2237 case WM_CONTEXTMENU:
2238 PostMsg(hwndMain, UM_CONTEXTMENU, MPVOID, MPVOID);
2239 return MRFROMSHORT(TRUE);
2240
2241 case WM_BEGINDRAG:
2242 if (hwndTree) {
2243
2244 SWP swp;
2245 ULONG fl = SWP_ACTIVATE | SWP_SHOW | SWP_ZORDER;
2246
2247 WinQueryWindowPos(hwndTree, &swp);
2248 if (!(swp.fl & SWP_MAXIMIZE))
2249 fl |= SWP_RESTORE;
2250 WinSetWindowPos(hwndTree, HWND_TOP, 0, 0, 0, 0, fl);
2251 }
2252 break;
2253
2254 case UM_SETUP:
2255 if (mp1)
2256 strcpy(lastcmd, (CHAR *)mp1);
2257 return 0;
2258
2259 case UM_RESCAN:
2260 if (hwndE && WinIsWindow(WinQueryAnchorBlock(hwnd), hwndE))
2261 WinDestroyWindow(hwndE);
2262 if (hwndB && WinIsWindow(WinQueryAnchorBlock(hwnd), hwndB))
2263 WinDestroyWindow(hwndB);
2264 hwndE = hwndB = (HWND) 0;
2265 return 0;
2266
2267 case WM_COMMAND:
2268 switch (SHORT1FROMMP(mp1)) {
2269 case COMMAND_BUTTON:
2270 PostMsg(hwndE, msg, mp1, mp2);
2271 break;
2272 }
2273 return 0;
2274
2275 case WM_MOUSEMOVE:
2276 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
2277 {
2278 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
2279 char *s = NULL;
2280
2281 if (fOtherHelp) {
2282 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
2283 && !WinQueryCapture(HWND_DESKTOP)) {
2284 switch (id) {
2285 case IDM_ATTRS:
2286 if (WinQueryWindowTextLength(hwnd))
2287 s = GetPString(IDS_ATTRSBUTTONHELP);
2288 break;
2289 case IDM_INFO:
2290 if (WinQueryWindowTextLength(hwnd))
2291 s = GetPString(IDS_INFOBUTTONHELP);
2292 break;
2293 case IDM_RENAME:
2294 if (WinQueryWindowTextLength(hwnd))
2295 s = GetPString(IDS_NAMEBUTTONHELP);
2296 break;
2297 case MAIN_STATUS2:
2298 if (!hwndE)
2299 s = GetPString(IDS_STATUS2HELP);
2300 break;
2301 default:
2302 break;
2303 }
2304 if (s)
2305 MakeBubble(hwnd, FALSE, s);
2306 else if (hwndBubble)
2307 WinDestroyWindow(hwndBubble);
2308 }
2309 }
2310 switch (id) {
2311 case IDM_ATTRS:
2312 case IDM_INFO:
2313 case IDM_RENAME:
2314 case MAIN_STATUS2:
2315 return CommonTextProc(hwnd, msg, mp1, mp2);
2316 default:
2317 break;
2318 }
2319 }
2320 break;
2321
2322 case WM_BUTTON2DOWN:
2323 case WM_BUTTON2UP:
2324 case UM_FOCUSME:
2325 return CommonTextButton(hwnd, msg, mp1, mp2);
2326
2327 case WM_BUTTON1DOWN:
2328 case WM_BUTTON1UP:
2329 case WM_BUTTON3DOWN:
2330 case WM_BUTTON3UP:
2331 {
2332 USHORT id;
2333
2334 id = WinQueryWindowUShort(hwnd, QWS_ID);
2335 switch (id) {
2336 case IDM_ATTRS:
2337 case IDM_INFO:
2338 case IDM_RENAME:
2339 case MAIN_STATUS2:
2340 return CommonTextButton(hwnd, msg, mp1, mp2);
2341 default:
2342 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
2343 break;
2344 }
2345 }
2346 break;
2347
2348 case WM_SETFOCUS:
2349 if (mp2) {
2350
2351 USHORT id;
2352
2353 id = WinQueryWindowUShort(hwnd, QWS_ID);
2354 if (id == MAIN_STATUS2 && hwndE)
2355 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2356 else
2357 return CommonTextButton(hwnd, msg, mp1, mp2);
2358 }
2359 break;
2360
2361 case WM_BUTTON1CLICK:
2362 {
2363 USHORT id;
2364
2365 id = WinQueryWindowUShort(hwnd, QWS_ID);
2366 if (id == MAIN_STATUS) {
2367 if (SHORT2FROMMP(mp2) & KC_CTRL)
2368 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2369 FID_CLIENT),
2370 WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
2371 else if (hwndTree)
2372 PostMsg(hwndTree, UM_TIMER, MPVOID, MPVOID);
2373 }
2374 }
2375 break;
2376
2377 case UM_CLICKED:
2378 case UM_CLICKED3:
2379 {
2380 USHORT id;
2381
2382 id = WinQueryWindowUShort(hwnd, QWS_ID);
2383 if (id == MAIN_STATUS2 && !hwndE) {
2384
2385 SWP swp;
2386 CHAR directory[CCHMAXPATH];
2387 PFNWP oldproce;
2388
2389 *directory = 0;
2390 TopWindowName(hwndMain, (HWND) 0, directory);
2391 WinQueryWindowPos(hwnd, &swp);
2392 hwndB = WinCreateWindow(hwnd,
2393 WC_BUTTON,
2394 "+",
2395 WS_VISIBLE | BS_PUSHBUTTON |
2396 BS_NOPOINTERFOCUS,
2397 swp.cx - swp.cy,
2398 0,
2399 swp.cy,
2400 swp.cy,
2401 hwnd, HWND_TOP, COMMAND_BUTTON, NULL, NULL);
2402 if (!hwndB)
2403 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
2404 hwndE = WinCreateWindow(hwnd,
2405 WC_ENTRYFIELD,
2406 NULL,
2407 WS_VISIBLE | ES_AUTOSCROLL,
2408 0,
2409 0,
2410 swp.cx - swp.cy,
2411 swp.cy,
2412 hwnd, HWND_TOP, COMMAND_LINE, NULL, NULL);
2413 if (!hwndE)
2414 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
2415 if (!hwndE || !hwndB) {
2416 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2417 return 0;
2418 }
2419 WinSendMsg(hwndE, EM_SETTEXTLIMIT, MPFROM2SHORT(1024, 0), MPVOID);
2420 WinSetWindowText(hwndStatus, directory);
2421 if (*lastcmd)
2422 WinSetWindowText(hwndE, lastcmd);
2423 else
2424 WinSetWindowText(hwndE, GetPString(IDS_HELPCMDTEXT));
2425 oldproce = WinSubclassWindow(hwndE, (PFNWP) CommandLineProc);
2426 if (oldproce)
2427 WinSetWindowPtr(hwndE, QWL_USER, (PVOID) oldproce);
2428 PostMsg(hwndE, UM_FOCUSME, MPVOID, MPVOID);
2429 PostMsg(hwndE, EM_SETSEL, MPFROM2SHORT(0, 1024), MPVOID);
2430 return 0;
2431 }
2432 if (msg == UM_CLICKED3 || (SHORT2FROMMP(mp2) & KC_CTRL)) {
2433 switch (id) {
2434 case IDM_ATTRS:
2435 id = IDM_SORTSIZE;
2436 break;
2437 case IDM_INFO:
2438 id = IDM_SORTLWDATE;
2439 break;
2440 case IDM_RENAME:
2441 id = IDM_SORTFILENAME;
2442 break;
2443 }
2444 }
2445 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
2446 WM_COMMAND, MPFROM2SHORT(id, 0), MPVOID);
2447 }
2448 return 0;
2449
2450 case WM_PAINT:
2451 {
2452 USHORT id;
2453
2454 id = WinQueryWindowUShort(hwnd, QWS_ID);
2455 switch (id) {
2456 case IDM_ATTRS:
2457 case IDM_INFO:
2458 case IDM_RENAME:
2459 case MAIN_STATUS2:
2460 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
2461 break;
2462 default:
2463 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, TRUE);
2464 break;
2465 }
2466 if (id == IDM_RENAME) {
2467
2468 HPS hps;
2469
2470 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
2471 if (hps) {
2472 PaintSTextWindow(hwnd, hps);
2473 WinEndPaint(hps);
2474 }
2475 return 0;
2476 }
2477 }
2478 break;
2479
2480 }
2481 return PFNWPStatic(hwnd, msg, mp1, mp2);
2482}
2483
2484MRESULT EXPENTRY ToolBackProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2485{
2486 switch (msg) {
2487 case WM_CREATE:
2488 hwndToolback = hwnd;
2489 RestorePresParams(hwnd, "ToolBar");
2490 break;
2491
2492 case WM_MOUSEMOVE:
2493 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
2494 break;
2495
2496 case WM_CONTROLPOINTER:
2497 if (!fNoFinger && SHORT1FROMMP(mp1) < 25000)
2498 return MRFROMLONG(hptrFinger);
2499 break;
2500
2501 case WM_CHAR:
2502 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2503 break;
2504
2505 case WM_COMMAND:
2506 case UM_COMMAND:
2507 return WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2508 FID_CLIENT), msg, mp1, mp2);
2509
2510 case WM_PAINT:
2511
2512 PaintRecessedWindow(hwnd, (HPS)0, TRUE, FALSE);
2513
2514 {
2515 HPS hps;
2516 RECTL rcl;
2517 ULONG lColor;
2518
2519 hps = WinBeginPaint(hwnd, (HPS)0, NULL);
2520 if (hps) {
2521 GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
2522 WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, NULL,
2523 sizeof(lColor), &lColor, 0);
2524 WinQueryWindowRect(hwnd, &rcl);
2525 WinFillRect(hps, &rcl, lColor);
2526 WinEndPaint(hps);
2527 }
2528
2529 }
2530 break;
2531
2532 case WM_PRESPARAMCHANGED:
2533 PresParamChanged(hwnd, "ToolBar", mp1, mp2);
2534 WinInvalidateRect(hwnd, NULL, TRUE);
2535 break;
2536
2537 case UM_SETUP:
2538 {
2539 USHORT id;
2540 TOOL *tool;
2541
2542 id = SHORT1FROMMP(mp1);
2543 tool = find_tool(id);
2544 if (tool) {
2545 del_tool(tool);
2546 WinShowWindow(WinWindowFromID(hwnd, id), FALSE);
2547 if (fToolTitles)
2548 WinShowWindow(WinWindowFromID(hwnd, id + 25000), FALSE);
2549 ResizeTools(hwnd);
2550 }
2551 }
2552 return 0;
2553
2554 case WM_CHORD:
2555 {
2556 USHORT id;
2557
2558 id = (USHORT) WinDlgBox(HWND_DESKTOP,
2559 hwnd,
2560 AddToolProc,
2561 FM3ModHandle, ADDBTN_FRAME, MPVOID);
2562 if (id && id != (USHORT) - 1)
2563 WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2564 FID_CLIENT),
2565 WM_COMMAND,
2566 MPFROM2SHORT(IDM_CREATETOOL, 0), MPFROM2SHORT(id, 0));
2567 }
2568 break;
2569
2570 case WM_CONTEXTMENU:
2571 if (WinDlgBox(HWND_DESKTOP,
2572 hwnd, ToolIODlgProc, FM3ModHandle, SVBTN_FRAME, MPVOID))
2573 BuildTools(hwnd, TRUE);
2574 return MRFROMSHORT(TRUE);
2575
2576 case WM_CLOSE:
2577 WinDestroyWindow(hwnd);
2578 return 0;
2579
2580 case WM_DESTROY:
2581 break;
2582 }
2583 return WinDefWindowProc(hwnd, msg, mp1, mp2);
2584}
2585
2586static VOID AdjustSizeOfClient(PSWP pswp, PRECTL prectl)
2587{
2588 SWP swp;
2589 RECTL rectl;
2590
2591 if (fFreeTree)
2592 return;
2593 if (pswp) {
2594 if (WinQueryWindowPos(hwndTree, &swp) &&
2595 !(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE))) {
2596 pswp->x = swp.cx;
2597 pswp->cx -= swp.cx;
2598 }
2599 }
2600 if (prectl) {
2601 if (WinQueryWindowPos(hwndTree, &swp) &&
2602 !(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE)) &&
2603 WinQueryWindowRect(hwndTree, &rectl)) {
2604 prectl->xLeft = rectl.xRight;
2605 prectl->xRight -= rectl.xRight;
2606 }
2607 }
2608}
2609
2610VOID FillClient(HWND hwndClient, PSWP pswp, PRECTL prectl, BOOL avoidtree)
2611{
2612 ULONG adjust;
2613
2614 adjust = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
2615 if (pswp)
2616 WinQueryWindowPos(hwndClient, pswp);
2617 if (prectl)
2618 WinQueryWindowRect(hwndClient, prectl);
2619 if (avoidtree && !fFreeTree)
2620 AdjustSizeOfClient(pswp, prectl);
2621 if (prectl)
2622 prectl->yBottom += adjust;
2623 if (pswp) {
2624 if (!avoidtree || fFreeTree)
2625 pswp->x = 0;
2626 pswp->y = adjust;
2627 if (pswp->cy >= adjust)
2628 pswp->cy -= adjust;
2629 else
2630 pswp->cy = 0;
2631 }
2632}
2633
2634static VOID MoveChildrenAwayFromTree(HWND hwndClient)
2635{
2636 SWP swpC, swpT, swp;
2637 USHORT id;
2638 HWND hwndChild;
2639 HENUM henum;
2640
2641 if (fFreeTree)
2642 return;
2643 WinQueryWindowPos(hwndClient, &swpC);
2644 if (swpC.fl & (SWP_MINIMIZE | SWP_HIDE))
2645 return;
2646 WinQueryWindowPos(hwndTree, &swpT);
2647 henum = WinBeginEnumWindows(hwndClient);
2648 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2649 id = WinQueryWindowUShort(hwndChild, QWS_ID);
2650 if (!id || id == TREE_FRAME)
2651 continue;
2652 WinQueryWindowPos(hwndChild, &swp);
2653 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
2654 if (swp.x < swpT.cx) {
2655 swp.x = swpT.cx;
2656 if (swp.x + swp.cx > swpC.cx)
2657 swp.cx = swpC.cx - swp.x;
2658 if (swp.cx > 24)
2659 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
2660 SWP_SIZE | SWP_MOVE | SWP_SHOW);
2661 }
2662 }
2663 }
2664 WinEndEnumWindows(henum);
2665}
2666
2667static VOID ArrangeIcons(HWND hwndClient)
2668{
2669 HENUM henum;
2670 HWND hwndChild;
2671 SWP swp;
2672
2673 henum = WinBeginEnumWindows(hwndClient);
2674 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2675 WinQueryWindowPos(hwndChild, &swp);
2676 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
2677 WinSetWindowUShort(hwndChild, QWS_XMINIMIZE, (USHORT) - 1);
2678 WinSetWindowUShort(hwndChild, QWS_YMINIMIZE, (USHORT) - 1);
2679 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0,
2680 SWP_MOVE | SWP_SHOW | SWP_FOCUSDEACTIVATE);
2681 }
2682 }
2683 WinEndEnumWindows(henum);
2684}
2685
2686static VOID NextChild(HWND hwndClient, BOOL previous)
2687{
2688 HENUM henum;
2689 HWND hwndActive, hwndNext, hwndPrev = (HWND) 0;
2690 BOOL next = FALSE, once = FALSE;
2691
2692 previous = !previous;
2693
2694 hwndActive = WinQueryActiveWindow(hwndClient);
2695 if (!hwndActive)
2696 next = TRUE;
2697 henum = WinBeginEnumWindows(hwndClient);
2698 for (;;) {
2699 hwndNext = WinGetNextWindow(henum);
2700 if (hwndNext) {
2701 if (!WinQueryWindowUShort(hwndNext, QWS_ID))
2702 continue;
2703 if (next)
2704 break;
2705 if (hwndNext == hwndActive) {
2706 if (!previous && hwndPrev) {
2707 hwndNext = hwndPrev;
2708 break;
2709 }
2710 else if (previous)
2711 next = TRUE;
2712 }
2713 hwndPrev = hwndNext;
2714 }
2715 else {
2716 if ((!next && previous) || once)
2717 break;
2718 else if (!previous) {
2719 hwndNext = hwndPrev;
2720 break;
2721 }
2722 else
2723 once = next = TRUE;
2724 }
2725 }
2726 WinEndEnumWindows(henum);
2727
2728 if (hwndNext && hwndNext != hwndActive) {
2729 WinSetWindowPos(hwndNext, HWND_TOP, 0, 0, 0, 0,
2730 SWP_ZORDER | SWP_ACTIVATE);
2731 WinSetWindowPos(hwndActive, ((previous) ? HWND_BOTTOM : hwndNext), 0, 0,
2732 0, 0, SWP_ZORDER);
2733 }
2734}
2735
2736BOOL CloseChildren(HWND hwndClient)
2737{
2738 HENUM henum;
2739 HWND hwndChild;
2740 BOOL ret = FALSE;
2741
2742 fNoTileUpdate = TRUE;
2743 henum = WinBeginEnumWindows(hwndClient);
2744 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2745 if (hwndChild != hwndTree) {
2746 WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2747 WM_SAVEAPPLICATION, MPVOID, MPVOID);
2748 if (WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2749 WM_CLOSE, MPVOID, MPVOID)) {
2750 ret = TRUE;
2751 break;
2752 }
2753 }
2754 }
2755 WinEndEnumWindows(henum);
2756 fNoTileUpdate = FALSE;
2757 return ret;
2758}
2759
2760BOOL CloseDirCnrChildren(HWND hwndClient)
2761{
2762 /* returns TRUE if a directory container window was told to close */
2763
2764 HENUM henum;
2765 HWND hwndChild, hwndDir, hwndTemp;
2766 BOOL ret = FALSE;
2767
2768 fNoTileUpdate = TRUE;
2769 henum = WinBeginEnumWindows(hwndClient);
2770 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2771 if (hwndChild != hwndTree) {
2772 hwndTemp = WinWindowFromID(hwndChild, FID_CLIENT);
2773 if (hwndTemp) {
2774 hwndDir = WinWindowFromID(hwndTemp, DIR_CNR);
2775 if (hwndDir) {
2776 WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2777 WM_CLOSE, MPVOID, MPVOID);
2778 ret = TRUE;
2779 }
2780 }
2781 }
2782 }
2783 WinEndEnumWindows(henum);
2784 fNoTileUpdate = FALSE;
2785 return ret;
2786}
2787
2788/** Save directory container state
2789 * @param hwndClient Client window handle
2790 * @param pszStateName State name to save, NULL to save global state
2791 * @returns Number of directory container windows that were saved or -1 if error
2792 * @seealso RestoreDirCnrState
2793 */
2794
2795#define STATE_NAME_MAX_BYTES 256
2796
2797INT SaveDirCnrState(HWND hwndClient, PSZ pszStateName)
2798{
2799 HENUM henum;
2800 HWND hwndChild, hwndDir, hwndC;
2801 ULONG numsaves = 0, flWindowAttr;
2802 ULONG previous_numsaves, ulTemp = sizeof(ULONG);
2803 CHAR szPrefix[STATE_NAME_MAX_BYTES + 1];
2804 CHAR szKey[STATE_NAME_MAX_BYTES + 80];
2805 CHAR szDir[CCHMAXPATH];
2806 SWP swp;
2807 DIRCNRDATA *dcd;
2808 BOOL fIsShutDownState;
2809
2810 if (!pszStateName || !*pszStateName) {
2811 Runtime_Error(pszSrcFile, __LINE__, "no data");
2812 return -1;
2813 }
2814 if (strlen(pszStateName) > sizeof(szPrefix) - 2) {
2815 Runtime_Error(pszSrcFile, __LINE__, "SaveDirCnrState");
2816 return -1;
2817 }
2818
2819 fIsShutDownState = strcmp(pszStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0;
2820 sprintf(szPrefix, "%s.", pszStateName);
2821
2822 henum = WinBeginEnumWindows(hwndClient);
2823 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2824 if (hwndChild != hwndTree) {
2825 hwndC = WinWindowFromID(hwndChild, FID_CLIENT);
2826 if (hwndC) {
2827 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
2828 if (hwndDir) {
2829 WinQueryWindowPos(hwndChild, &swp);
2830 *szDir = 0;
2831 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(szDir), MPVOID);
2832 if (*szDir) {
2833 // If saving shutdown state skip no prescan drives
2834 if (fIsShutDownState &&
2835 driveflags[toupper(*szDir) - 'A'] & DRIVE_NOPRESCAN) {
2836 continue;
2837 }
2838 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, numsaves);
2839 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp,
2840 sizeof(SWP));
2841 dcd =
2842 WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
2843 if (dcd) {
2844 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, numsaves);
2845 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->sortFlags,
2846 sizeof(INT));
2847 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, numsaves);
2848 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->mask,
2849 sizeof(MASK));
2850 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, numsaves);
2851 flWindowAttr = dcd->flWindowAttr;
2852 if (!fLeaveTree && (flWindowAttr & CV_TREE)) {
2853 flWindowAttr &= (~(CV_TREE | CV_ICON | CV_DETAIL | CV_TEXT));
2854 if (dcd->lastattr) {
2855 if (dcd->lastattr & CV_TEXT)
2856 flWindowAttr |= CV_TEXT;
2857 else if (dcd->lastattr & CV_DETAIL)
2858 flWindowAttr |= CV_DETAIL;
2859 else if (dcd->lastattr & CV_ICON)
2860 flWindowAttr |= CV_ICON;
2861 else
2862 flWindowAttr |= CV_NAME;
2863 }
2864 else
2865 flWindowAttr |= CV_NAME;
2866 }
2867 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & flWindowAttr,
2868 sizeof(ULONG));
2869 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, numsaves);
2870 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslongname,
2871 sizeof(BOOL));
2872 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, numsaves);
2873 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailssubject,
2874 sizeof(BOOL));
2875 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, numsaves);
2876 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailssize,
2877 sizeof(BOOL));
2878 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, numsaves);
2879 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsea,
2880 sizeof(BOOL));
2881 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, numsaves);
2882 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsattr,
2883 sizeof(BOOL));
2884 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, numsaves);
2885 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsicon,
2886 sizeof(BOOL));
2887 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, numsaves);
2888 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslwdate,
2889 sizeof(BOOL));
2890 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, numsaves);
2891 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslwtime,
2892 sizeof(BOOL));
2893 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, numsaves);
2894 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsladate,
2895 sizeof(BOOL));
2896 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, numsaves);
2897 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslatime,
2898 sizeof(BOOL));
2899 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, numsaves);
2900 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailscrdate,
2901 sizeof(BOOL));
2902 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, numsaves);
2903 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailscrtime,
2904 sizeof(BOOL));
2905 sprintf(szKey, "%sDirCnr.%lu", szPrefix, numsaves);
2906 SavePresParams(hwndDir, szKey);
2907 }
2908 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, numsaves++);
2909 PrfWriteProfileString(fmprof, FM3Str, szKey, szDir);
2910 }
2911 }
2912 }
2913 }
2914 } // while
2915 WinEndEnumWindows(henum);
2916
2917 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
2918 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &previous_numsaves, &ulTemp))
2919 for (ulTemp = numsaves; ulTemp < previous_numsaves; ulTemp++) {
2920 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, ulTemp);
2921 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(SWP));
2922 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, ulTemp);
2923 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(INT));
2924 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, ulTemp);
2925 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(MASK));
2926 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, ulTemp);
2927 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(ULONG));
2928 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, ulTemp);
2929 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2930 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, ulTemp);
2931 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2932 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, ulTemp);
2933 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2934 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, ulTemp);
2935 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2936 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, ulTemp);
2937 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2938 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, ulTemp);
2939 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2940 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, ulTemp);
2941 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2942 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, ulTemp);
2943 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2944 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, ulTemp);
2945 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2946 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, ulTemp);
2947 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2948 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, ulTemp);
2949 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2950 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, ulTemp);
2951 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2952 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, ulTemp);
2953 PrfWriteProfileString(fmprof, FM3Str, szKey, NULL);
2954 sprintf(szKey, "%sDirCnr.%lu.", szPrefix, ulTemp);
2955 DeletePresParams(szKey);
2956 }
2957 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
2958 if (numsaves) {
2959 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & numsaves, sizeof(ULONG));
2960 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swp);
2961 sprintf(szKey, "%sMySizeLastTime", szPrefix);
2962 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, sizeof(SWP));
2963 if (WinQueryWindowPos(hwndTree, &swp)) {
2964 sprintf(szKey, "%sLastTreePos", szPrefix);
2965 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, sizeof(SWP));
2966 }
2967 }
2968 else if (fIsShutDownState) {
2969 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & numsaves, sizeof(ULONG));
2970 }
2971
2972 return numsaves;
2973}
2974
2975static VOID TransformSwp(PSWP pswp, double xtrans, double ytrans)
2976{
2977 SWP swp;
2978 HWND hwnd;
2979
2980 if ((LONG) pswp->x < 0L) {
2981 pswp->cx -= abs(pswp->x);
2982 pswp->x = 0;
2983 }
2984 if ((LONG) pswp->y < 0L) {
2985 pswp->cy -= abs(pswp->y);
2986 pswp->y = 0;
2987 }
2988 pswp->x = (LONG) (((double)pswp->x * 100.0) / xtrans);
2989 pswp->cx = (LONG) (((double)pswp->cx * 100.0) / xtrans);
2990 pswp->y = (LONG) (((double)pswp->y * 100.0) / ytrans);
2991 pswp->cy = (LONG) (((double)pswp->cy * 100.0) / ytrans);
2992 if (pswp->hwnd) {
2993 hwnd = WinQueryWindow(pswp->hwnd, QW_PARENT);
2994 if (hwnd) {
2995 if (WinQueryWindowPos(hwnd, &swp)) {
2996 if (pswp->x > swp.cx)
2997 pswp->x = (swp.cx > 24) ? swp.cx - 24 : swp.cx;
2998 if (pswp->y > swp.cy)
2999 pswp->y = (swp.cy > 24) ? swp.cy - 24 : swp.cy;
3000 if (pswp->x + pswp->cx > swp.cx)
3001 pswp->cx = swp.cx - pswp->x;
3002 if (pswp->y + pswp->cy > swp.cy)
3003 pswp->cy = swp.cy - pswp->y;
3004 }
3005 }
3006 }
3007}
3008
3009/** Restore directory container state
3010 * @param hwndClient Client window handle
3011 * @param pszStateName State name to restore, NULL to restore global state
3012 * @param noview request view state restore bypass
3013 * @returns TRUE if one or more directory containers were opened
3014 * @seealso SaveDirCnrState
3015 */
3016
3017static BOOL RestoreDirCnrState(HWND hwndClient, PSZ pszStateName, BOOL noview)
3018{
3019 CHAR szKey[STATE_NAME_MAX_BYTES + 80];
3020 CHAR szDir[CCHMAXPATH];
3021 CHAR szPrefix[STATE_NAME_MAX_BYTES + 2];
3022 HWND hwndDir, hwndC, hwndPPSave = NULLHANDLE;
3023 SWP swp, swpO, swpN;
3024 ULONG size, numsaves = 0;
3025 LONG x;
3026 double xtrans, ytrans;
3027 BOOL fRestored = FALSE;
3028 DIRCNRDATA localdcd, *dcd;
3029 BOOL fIsShutDownState;
3030 BOOL fDeleteState;
3031
3032 if (!pszStateName || !*pszStateName) {
3033 Runtime_Error(pszSrcFile, __LINE__, "no name");
3034 return fRestored;
3035 }
3036 if (strlen(pszStateName) > sizeof(szPrefix) - 2) {
3037 Runtime_Error(pszSrcFile, __LINE__, "name too long");
3038 return fRestored;
3039 }
3040
3041 sprintf(szPrefix, "%s.", pszStateName);
3042
3043 // If restoring shutdown state bypass no-prescan drives
3044 fIsShutDownState = strcmp(pszStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0;
3045 // Delete saved state if internally saved state
3046 fDeleteState = strcmp(pszStateName, GetPString(IDS_FM2TEMPTEXT)) == 0;
3047
3048 size = sizeof(SWP);
3049 sprintf(szKey, "%sMySizeLastTime", szPrefix);
3050 if (!PrfQueryProfileData(fmprof,
3051 FM3Str,
3052 szKey,
3053 (PVOID) & swpO,
3054 &size) ||
3055 size != sizeof(SWP) || !swp.cx || !swp.cy)
3056 {
3057 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swpO);
3058 }
3059 // If restoring internally saved state, forget info
3060 if (fDeleteState)
3061 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3062 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swpN);
3063 if (swpN.fl & (SWP_MINIMIZE | SWP_HIDE))
3064 swpN = swpO;
3065 xtrans = ((double)swpO.cx * 100.0) / (double)swpN.cx;
3066 ytrans = ((double)swpO.cy * 100.0) / (double)swpN.cy;
3067 size = sizeof(SWP);
3068 sprintf(szKey, "%sLastTreePos", szPrefix);
3069 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, &size)) {
3070 if (fDeleteState)
3071 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3072 swp.hwnd = hwndTree;
3073 TransformSwp(&swp, xtrans, ytrans);
3074 if (!fFreeTree) {
3075 WinQueryWindowPos(hwndClient, &swpN);
3076 swp.x = 0;
3077 swp.y = (swpN.cy - swp.cy);
3078 }
3079 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
3080 swp.fl &= (~SWP_ACTIVATE);
3081 WinSetWindowPos(hwndTree,
3082 HWND_TOP,
3083 swp.x,
3084 swp.y,
3085 swp.cx,
3086 swp.cy,
3087 swp.fl | SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
3088 }
3089 else {
3090 WinSetWindowPos(hwndTree,
3091 HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);
3092 WinSetWindowUShort(hwndTree, QWS_XRESTORE, (USHORT) swp.x);
3093 WinSetWindowUShort(hwndTree, QWS_CXRESTORE, (USHORT) swp.cx);
3094 WinSetWindowUShort(hwndTree, QWS_YRESTORE, (USHORT) swp.y);
3095 WinSetWindowUShort(hwndTree, QWS_CYRESTORE, (USHORT) swp.cy);
3096 }
3097 }
3098 size = sizeof(ULONG);
3099 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
3100 if (PrfQueryProfileData(fmprof,
3101 FM3Str, szKey, (PVOID) & numsaves, &size)) {
3102 if (fDeleteState)
3103 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3104 for (x = numsaves - 1; x >= 0; x--) {
3105 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, x);
3106 size = sizeof(SWP);
3107 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &swp, &size)) {
3108 if (fDeleteState)
3109 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3110 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, x);
3111 size = sizeof(szDir);
3112 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) szDir, &size)) {
3113 // If restoring shutdown state and drive marked no prescan
3114 // bypass window restore
3115 if (fIsShutDownState &&
3116 driveflags[toupper(*szDir) - 'A'] & DRIVE_NOPRESCAN) {
3117 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3118 continue;
3119 }
3120 if (fDeleteState)
3121 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3122 localdcd.ds.detailslongname = dsDirCnrDefault.detailslongname; // Set default
3123 size = sizeof(BOOL);
3124 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, x);
3125 if (PrfQueryProfileData(fmprof,
3126 FM3Str,
3127 szKey,
3128 (PVOID)&localdcd.ds.detailslongname,
3129 &size) &&
3130 size == sizeof(BOOL))
3131 {
3132 if (fDeleteState)
3133 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3134 }
3135 localdcd.ds.detailssubject = dsDirCnrDefault.detailssubject; // Set default
3136 size = sizeof(BOOL);
3137 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, x);
3138 if (PrfQueryProfileData(fmprof,
3139 FM3Str,
3140 szKey,
3141 (PVOID)&localdcd.ds.detailssubject,
3142 &size) &&
3143 size == sizeof(BOOL))
3144 {
3145 if (fDeleteState)
3146 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3147 }
3148 localdcd.ds.detailsea = dsDirCnrDefault.detailsea; // Set default
3149 size = sizeof(BOOL);
3150 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, x);
3151 if (PrfQueryProfileData(fmprof,
3152 FM3Str,
3153 szKey,
3154 (PVOID) & localdcd.ds.detailsea,
3155 &size) &&
3156 size == sizeof(BOOL))
3157 {
3158 if (fDeleteState)
3159 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3160 }
3161 localdcd.ds.detailssize = dsDirCnrDefault.detailssize; // Set default
3162 size = sizeof(BOOL);
3163 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, x);
3164 if (PrfQueryProfileData(fmprof,
3165 FM3Str,
3166 szKey,
3167 (PVOID) & localdcd.ds.detailssize,
3168 &size) &&
3169 size == sizeof(BOOL))
3170 {
3171 if (fDeleteState)
3172 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3173 }
3174 localdcd.ds.detailsicon = dsDirCnrDefault.detailsicon; // Set default
3175 size = sizeof(BOOL);
3176 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, x);
3177 if (PrfQueryProfileData(fmprof,
3178 FM3Str,
3179 szKey,
3180 (PVOID) & localdcd.ds.detailsicon,
3181 &size) &&
3182 size == sizeof(BOOL))
3183 {
3184 if (fDeleteState)
3185 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3186 }
3187 localdcd.ds.detailsattr = dsDirCnrDefault.detailsattr; // Set default
3188 size = sizeof(BOOL);
3189 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, x);
3190 if (PrfQueryProfileData(fmprof,
3191 FM3Str,
3192 szKey,
3193 (PVOID)&localdcd.ds.detailsattr,
3194 &size) &&
3195 size == sizeof(BOOL))
3196 {
3197 if (fDeleteState)
3198 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3199 }
3200 localdcd.ds.detailscrdate = dsDirCnrDefault.detailscrdate; // Set default
3201 size = sizeof(BOOL);
3202 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, x);
3203 if (PrfQueryProfileData(fmprof,
3204 FM3Str,
3205 szKey,
3206 (PVOID) & localdcd.ds.detailscrdate,
3207 &size) && size == sizeof(BOOL))
3208 {
3209 if (fDeleteState)
3210 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3211 }
3212 localdcd.ds.detailscrtime = dsDirCnrDefault.detailscrtime; // Set default
3213 size = sizeof(BOOL);
3214 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, x);
3215 if (PrfQueryProfileData(fmprof,
3216 FM3Str,
3217 szKey,
3218 (PVOID)&localdcd.ds.detailscrtime,
3219 &size) &&
3220 size == sizeof(BOOL))
3221 {
3222 if (fDeleteState)
3223 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3224 }
3225 localdcd.ds.detailslwdate = dsDirCnrDefault.detailslwdate; // Set default
3226 size = sizeof(BOOL);
3227 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, x);
3228 if (PrfQueryProfileData(fmprof,
3229 FM3Str,
3230 szKey,
3231 (PVOID) & localdcd.ds.detailslwdate,
3232 &size) &&
3233 size == sizeof(BOOL))
3234 {
3235 if (fDeleteState)
3236 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3237 }
3238 localdcd.ds.detailslwtime = dsDirCnrDefault.detailslwtime; // Set default
3239 size = sizeof(BOOL);
3240 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, x);
3241 if (PrfQueryProfileData(fmprof,
3242 FM3Str,
3243 szKey,
3244 (PVOID) & localdcd.ds.detailslwtime,
3245 &size) &&
3246 size == sizeof(BOOL))
3247 {
3248 if (fDeleteState)
3249 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3250 }
3251 localdcd.ds.detailsladate = dsDirCnrDefault.detailsladate; // Set default
3252 size = sizeof(BOOL);
3253 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, x);
3254 if (PrfQueryProfileData(fmprof,
3255 FM3Str,
3256 szKey,
3257 (PVOID) & localdcd.ds.detailsladate,
3258 &size) &&
3259 size == sizeof(BOOL))
3260 {
3261 if (fDeleteState)
3262 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3263 }
3264 localdcd.ds.detailslatime = dsDirCnrDefault.detailslatime; // Set default
3265 size = sizeof(BOOL);
3266 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, x);
3267 if (PrfQueryProfileData(fmprof,
3268 FM3Str,
3269 szKey,
3270 (PVOID) & localdcd.ds.detailslatime,
3271 &size) &&
3272 size == sizeof(BOOL))
3273 {
3274 if (fDeleteState)
3275 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3276 }
3277 hwndDir = (HWND) WinSendMsg(hwndClient,
3278 UM_SETDIR,
3279 MPFROMP(szDir), MPFROMLONG(1));
3280 if (hwndDir) {
3281 hwndC = WinWindowFromID(hwndDir, FID_CLIENT);
3282 if (hwndC) {
3283 HWND hwndCnr = WinWindowFromID(hwndC, DIR_CNR);
3284 if (!hwndPPSave) {
3285 hwndPPSave = WinCreateWindow(hwndCnr, // Create a window (used to save default presparams)
3286 WC_CONTAINER,
3287 NULL,
3288 CCS_AUTOPOSITION | CCS_MINIICONS |
3289 CCS_MINIRECORDCORE | ulCnrType |
3290 WS_VISIBLE,
3291 0,
3292 0,
3293 0,
3294 0,
3295 hwndCnr,
3296 HWND_TOP, (ULONG) -1, NULL, NULL);
3297 CopyPresParams(hwndPPSave, hwndC);
3298 RestorePresParams(hwndPPSave, "DirCnr");
3299 }
3300 sprintf(szKey, "%sDirCnr.%lu", szPrefix, x);
3301 RestorePresParams(hwndCnr, szKey);
3302 dcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
3303 if (dcd) {
3304 dcd->ds.detailslongname = localdcd.ds.detailslongname;
3305 dcd->ds.detailssubject = localdcd.ds.detailssubject ;
3306 dcd->ds.detailsattr = localdcd.ds.detailsattr ;
3307 dcd->ds.detailsea = localdcd.ds.detailsea ;
3308 dcd->ds.detailssize = localdcd.ds.detailssize ;
3309 dcd->ds.detailsicon = localdcd.ds.detailsicon ;
3310 dcd->ds.detailscrdate = localdcd.ds.detailscrdate ;
3311 dcd->ds.detailscrtime = localdcd.ds.detailscrtime ;
3312 dcd->ds.detailsladate = localdcd.ds.detailsladate ;
3313 dcd->ds.detailslatime = localdcd.ds.detailslatime ;
3314 dcd->ds.detailslwdate = localdcd.ds.detailslwdate ;
3315 dcd->ds.detailslwtime = localdcd.ds.detailslwtime ;
3316 size = sizeof(INT);
3317 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, x);
3318 if (PrfQueryProfileData(fmprof,
3319 FM3Str,
3320 szKey,
3321 (PVOID) & dcd->sortFlags,
3322 &size) && size == sizeof(INT)) {
3323 if (!dcd->sortFlags)
3324 dcd->sortFlags = SORT_PATHNAME;
3325 }
3326 if (fDeleteState)
3327 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3328 size = sizeof(MASK);
3329 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, x);
3330 if (PrfQueryProfileData(fmprof,
3331 FM3Str,
3332 szKey,
3333 (PVOID) & dcd->mask, &size) && size) {
3334 if (*dcd->mask.szMask)
3335 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3336 UM_FILTER, MPFROMP(dcd->mask.szMask), MPVOID);
3337 }
3338 *(dcd->mask.prompt) = 0;
3339 if (fDeleteState)
3340 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3341 size = sizeof(ULONG);
3342 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, x);
3343 if (!noview) {
3344 if (PrfQueryProfileData(fmprof,
3345 FM3Str,
3346 szKey,
3347 (PVOID) & dcd->flWindowAttr,
3348 &size) && size == sizeof(ULONG)) {
3349
3350 CNRINFO cnri;
3351
3352 memset(&cnri, 0, sizeof(CNRINFO));
3353 cnri.cb = sizeof(CNRINFO);
3354 if (WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3355 CM_QUERYCNRINFO,
3356 MPFROMP(&cnri),
3357 MPFROMLONG(sizeof(CNRINFO)))) {
3358 cnri.flWindowAttr = dcd->flWindowAttr;
3359 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3360 CM_SETCNRINFO,
3361 MPFROMP(&cnri),
3362 MPFROMLONG(CMA_FLWINDOWATTR));
3363 }
3364 }
3365 }
3366 if (fDeleteState)
3367 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3368 if (!PostMsg(hwndCnr, UM_SETUP2, NULL, NULL))
3369 WinSendMsg(hwndCnr, UM_SETUP2, NULL, NULL);
3370 }
3371 }
3372 fRestored = TRUE;
3373 swp.hwnd = hwndDir;
3374 TransformSwp(&swp, xtrans, ytrans);
3375 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3376 WinSetWindowPos(hwndDir,
3377 HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);
3378 WinSetWindowUShort(hwndDir, QWS_XRESTORE, (USHORT) swp.x);
3379 WinSetWindowUShort(hwndDir, QWS_CXRESTORE, (USHORT) swp.cx);
3380 WinSetWindowUShort(hwndDir, QWS_YRESTORE, (USHORT) swp.y);
3381 WinSetWindowUShort(hwndDir, QWS_CYRESTORE, (USHORT) swp.cy);
3382 } else
3383 WinSetWindowPos(hwndDir,
3384 HWND_TOP,
3385 swp.x,
3386 swp.y,
3387 swp.cx,
3388 swp.cy,
3389 swp.fl | SWP_MOVE |
3390 SWP_SIZE | SWP_SHOW | SWP_ZORDER |
3391 SWP_ACTIVATE);
3392 }
3393 }
3394 }
3395 } // for
3396 if (hwndPPSave) {
3397 SavePresParams(hwndPPSave, "DirCnr");
3398 WinDestroyWindow(hwndPPSave);
3399 }
3400 }
3401 return fRestored;
3402}
3403
3404static ULONG CountChildren(HWND hwndClient, ULONG * ulNumMinChildren)
3405{
3406 HENUM henum;
3407 HWND hwndChild;
3408 SWP swp;
3409 register ULONG ulCnt = 0L;
3410 USHORT id;
3411
3412 if (ulNumMinChildren)
3413 *ulNumMinChildren = 0L;
3414 henum = WinBeginEnumWindows(hwndClient);
3415 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3416 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3417 if (!id || (!fFreeTree && id == TREE_FRAME))
3418 continue;
3419 ulCnt++;
3420 if (ulNumMinChildren) {
3421 if (WinQueryWindowPos(hwndChild, &swp) && (swp.fl & SWP_MINIMIZE))
3422 (*ulNumMinChildren)++;
3423 }
3424 }
3425 WinEndEnumWindows(henum);
3426 return ulCnt;
3427}
3428
3429VOID GetNextWindowPos(HWND hwndClient, PSWP pswp, ULONG * ulCntR,
3430 ULONG * ulNumMinChildrenR)
3431{
3432 register ULONG ulCnt;
3433 ULONG ulNumMinChildren;
3434 RECTL Rectl;
3435 register ULONG ulXDiff, ulYDiff, ulWindowsPerStack;
3436
3437 if (!ulCntR || !ulNumMinChildrenR)
3438 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3439 else {
3440 ulCnt = *ulCntR;
3441 ulNumMinChildren = *ulNumMinChildrenR;
3442 if (ulCnt == (ULONG) - 1) {
3443 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3444 /* return these values to the caller for later use */
3445 *ulCntR = ulCnt;
3446 *ulNumMinChildrenR = ulNumMinChildren;
3447 }
3448 }
3449 WinQueryWindowRect(hwndClient, &Rectl);
3450 AdjustSizeOfClient(NULL, &Rectl);
3451 if (!fFreeTree) {
3452
3453 SWP swp;
3454
3455 WinQueryWindowPos(hwndTree, &swp);
3456 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3457 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3458 }
3459 else if (ulNumMinChildren)
3460 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3461
3462 ulXDiff = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) +
3463 WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON) / 2;
3464 ulYDiff = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER) +
3465 WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
3466 ulWindowsPerStack = (Rectl.yTop - Rectl.yBottom) / (3 * ulYDiff);
3467 pswp->cx = Rectl.xRight - (ulWindowsPerStack * ulXDiff);
3468 pswp->cy = (Rectl.yTop - Rectl.yBottom) - (ulWindowsPerStack * ulYDiff);
3469 ulWindowsPerStack++;
3470 pswp->x = Rectl.xLeft + ((ulCnt % ulWindowsPerStack) * ulXDiff);
3471 pswp->y = (Rectl.yTop - pswp->cy - ((ulCnt % ulWindowsPerStack) * ulYDiff));
3472}
3473
3474static VOID CascadeChildren(HWND hwndClient)
3475{
3476 ULONG ulCnt = 0L, ulNumMinChildren;
3477 HWND hwndChild;
3478 HENUM henum;
3479 SWP swp;
3480 USHORT id;
3481 RECTL Rectl;
3482
3483 WinQueryWindowPos(hwndClient, &swp);
3484 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3485 return;
3486
3487 CountChildren(hwndClient, &ulNumMinChildren);
3488 if (!fFreeTree) {
3489 WinQueryWindowRect(hwndClient, &Rectl);
3490 AdjustSizeOfClient(NULL, &Rectl);
3491 WinQueryWindowPos(hwndTree, &swp);
3492 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3493 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3494 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3495 if (swp.x != 0)
3496 swp.x = 0;
3497 if (swp.y < 0)
3498 swp.y = 0;
3499 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3500 swp.cx = Rectl.xRight - Rectl.xLeft;
3501 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3502 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3503 }
3504 }
3505 henum = WinBeginEnumWindows(hwndClient);
3506 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3507 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3508 if (!id || (!fFreeTree && id == TREE_FRAME))
3509 continue;
3510 WinQueryWindowPos(hwndChild, &swp);
3511 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
3512 GetNextWindowPos(hwndClient, &swp, &ulCnt, &ulNumMinChildren);
3513 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3514 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
3515 SWP_ZORDER | SWP_ACTIVATE);
3516 ulCnt++;
3517 }
3518 }
3519 WinEndEnumWindows(henum);
3520}
3521
3522VOID TileChildren(HWND hwndClient, BOOL absolute)
3523{
3524 register ULONG ulChildCnt, ulSquare, ulNumRows, ulNumCols, ulExtraCols,
3525 ulWidth, ulHeight;
3526 ULONG ulNumMinChildren;
3527 RECTL Rectl;
3528 HWND hwndChild;
3529
3530 if (fNoTileUpdate || hwndClient == HWND_DESKTOP)
3531 return;
3532 {
3533 SWP swp;
3534
3535 WinQueryWindowPos(hwndClient, &swp);
3536 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3537 return;
3538 }
3539 ulChildCnt = CountChildren(hwndClient, &ulNumMinChildren);
3540 ulChildCnt -= ulNumMinChildren;
3541 if (!ulChildCnt)
3542 return;
3543
3544 fNoTileUpdate = TRUE;
3545
3546 for (ulSquare = 2; ulSquare * ulSquare <= ulChildCnt; ulSquare++) {
3547 ;
3548 }
3549 if (!fTileBackwards) {
3550 ulNumCols = ulSquare - 1;
3551 ulNumRows = ulChildCnt / ulNumCols;
3552 }
3553 else {
3554 ulNumRows = ulSquare - 1;
3555 ulNumCols = ulChildCnt / ulNumRows;
3556 }
3557 ulExtraCols = ulChildCnt % ulNumCols;
3558
3559 WinQueryWindowRect(hwndClient, &Rectl);
3560
3561 if (!fFreeTree) {
3562
3563 SWP swp;
3564
3565 WinQueryWindowPos(hwndTree, &swp);
3566 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3567 if (swp.y < 0)
3568 swp.y = 0;
3569 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3570 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3571 if (swp.x != 0)
3572 swp.x = 0;
3573 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3574 swp.cx = Rectl.xRight - Rectl.xLeft;
3575 WinSetWindowPos(hwndTree,
3576 HWND_TOP,
3577 swp.x,
3578 swp.y,
3579 swp.cx,
3580 swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3581 WinQueryWindowPos(hwndTree, &swp);
3582 }
3583 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3584 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3585 }
3586 else if (ulNumMinChildren)
3587 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3588
3589 AdjustSizeOfClient(NULL, &Rectl);
3590
3591 if (Rectl.xRight > 0L && (Rectl.yBottom < Rectl.yTop)) {
3592
3593 HENUM henum;
3594
3595 henum = WinBeginEnumWindows(hwndClient);
3596 if ((hwndChild = WinGetNextWindow(henum)) != (HWND) 0) {
3597
3598 ULONG ulCurRow, ulCurCol;
3599 SWP swp;
3600 USHORT id;
3601
3602 ulHeight = (Rectl.yTop - Rectl.yBottom) / ulNumRows;
3603
3604 for (ulCurRow = 0; ulCurRow < ulNumRows; ulCurRow++) {
3605 if ((ulNumRows - ulCurRow) <= ulExtraCols)
3606 ulNumCols++;
3607 for (ulCurCol = 0; ulCurCol < ulNumCols; ulCurCol++) {
3608 ulWidth = Rectl.xRight / ulNumCols;
3609
3610 while (hwndChild) {
3611 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3612 if (id && (id != TREE_FRAME || fFreeTree)) {
3613 WinQueryWindowPos(hwndChild, &swp);
3614 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3615 break;
3616 }
3617 hwndChild = WinGetNextWindow(henum);
3618 }
3619
3620 if (hwndChild) {
3621 if (!absolute && (swp.fl & SWP_MAXIMIZE)) {
3622 WinGetMaxPosition(hwndChild, &swp);
3623 WinSetWindowPos(hwndChild,
3624 HWND_TOP,
3625 swp.x,
3626 swp.y,
3627 swp.cx, swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
3628 WinSetWindowUShort(hwndChild,
3629 QWS_XRESTORE,
3630 (USHORT) (ulWidth * ulCurCol) + Rectl.xLeft);
3631 WinSetWindowUShort(hwndChild,
3632 QWS_YRESTORE,
3633 (USHORT) (Rectl.yTop -
3634 (ulHeight * (ulCurRow + 1))));
3635 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, (USHORT) ulWidth);
3636 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, (USHORT) ulHeight);
3637 }
3638 else
3639 WinSetWindowPos(hwndChild,
3640 HWND_TOP,
3641 (ulWidth * ulCurCol) + Rectl.xLeft,
3642 Rectl.yTop - (ulHeight * (ulCurRow + 1)),
3643 ulWidth,
3644 ulHeight,
3645 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3646 hwndChild = WinGetNextWindow(henum);
3647 }
3648 }
3649 if ((ulNumRows - ulCurRow) <= ulExtraCols) {
3650 ulNumCols--;
3651 ulExtraCols--;
3652 }
3653 }
3654 }
3655 WinEndEnumWindows(henum);
3656 }
3657
3658 fNoTileUpdate = FALSE;
3659}
3660
3661static VOID ResizeChildren(HWND hwndClient, SHORT oldcx, SHORT oldcy,
3662 SHORT newcx, SHORT newcy)
3663{
3664 /*
3665 * resize all children of the client to maintain their proportional
3666 * sizes and positions
3667 */
3668
3669 if (!newcx || !newcy || !oldcx || !oldcy)
3670 return;
3671 {
3672 HENUM henum;
3673 HWND hwndChild;
3674 register LONG x, y, cx, cy, ucx, ucy, ux, uy;
3675 SWP swp;
3676
3677 henum = WinBeginEnumWindows(hwndClient);
3678 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3679 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
3680 continue;
3681 if (WinQueryWindowPos(hwndChild, &swp)) {
3682 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
3683 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3684 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3685 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3686 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3687 }
3688 else if (swp.fl & SWP_MAXIMIZE) {
3689 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3690 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3691 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3692 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3693 }
3694 cx = (swp.cx) ? (LONG) (((double)oldcx * 100.0) / (double)swp.cx) : 0;
3695 cy = (swp.cy) ? (LONG) (((double)oldcy * 100.0) / (double)swp.cy) : 0;
3696 x = (swp.x) ? (LONG) (((double)oldcx * 100.0) / (double)swp.x) : 0;
3697 y = (swp.y) ? (LONG) (((double)oldcy * 100.0) / (double)swp.y) : 0;
3698 if (x < 0)
3699 x = 0;
3700 if (y < 0)
3701 y = 0;
3702 ux = (x) ? (LONG) (((double)newcx * 100.0) / (double)x) : 0;
3703 uy = (y) ? (LONG) (((double)newcy * 100.0) / (double)y) : 0;
3704 ucx = (cx) ? (LONG) (((double)newcx * 100.0) / (double)cx) : 0;
3705 ucy = (cy) ? (LONG) (((double)newcy * 100.0) / (double)cy) : 0;
3706 if (ux + ucx > newcx)
3707 ucx = newcx - ux;
3708 if (uy + ucy > newcy)
3709 ucy = newcy - uy;
3710
3711 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE)))
3712 WinSetWindowPos(hwndChild, HWND_TOP, ux, uy, ucx, ucy,
3713 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3714 else if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3715 WinSetWindowUShort(hwndChild, QWS_XMINIMIZE, (USHORT) - 1);
3716 WinSetWindowUShort(hwndChild, QWS_YMINIMIZE, (USHORT) - 1);
3717 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0,
3718 SWP_SIZE | SWP_MOVE | SWP_FOCUSDEACTIVATE);
3719 WinSetWindowUShort(hwndChild, QWS_XRESTORE, ux);
3720 WinSetWindowUShort(hwndChild, QWS_YRESTORE, uy);
3721 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, ucx);
3722 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, ucy);
3723 }
3724 else {
3725 WinGetMaxPosition(hwndChild, &swp);
3726 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3727 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3728 WinSetWindowUShort(hwndChild, QWS_XRESTORE, ux);
3729 WinSetWindowUShort(hwndChild, QWS_YRESTORE, uy);
3730 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, ucx);
3731 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, ucy);
3732 }
3733 }
3734 }
3735 WinEndEnumWindows(henum);
3736 }
3737 if (!fFreeTree) {
3738
3739 RECTL Rectl;
3740 SWP swp;
3741
3742 WinQueryWindowRect(hwndClient, &Rectl);
3743 AdjustSizeOfClient(NULL, &Rectl);
3744 WinQueryWindowPos(hwndTree, &swp);
3745 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3746
3747 if (!fNoTreeGap) {
3748 INT height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3749 if (swp.y < height)
3750 swp.y = height; // Force bottom to position
3751 }
3752 else
3753 swp.y = 0; // Force bottom to position
3754
3755 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3756 if (swp.cy < 0)
3757 swp.cy = 0;
3758
3759 if (swp.x != 0)
3760 swp.x = 0; // Left align
3761
3762 // AdjustSizeOfClient can return bogus xRight values - fixme someday
3763 if (Rectl.xRight >= Rectl.xLeft) {
3764 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3765 swp.cx = Rectl.xRight - Rectl.xLeft;
3766 }
3767 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3768 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3769 }
3770 }
3771}
3772
3773static VOID MinResChildren(HWND hwndClient, ULONG cmd)
3774{
3775 HENUM henum;
3776 HWND hwndChild;
3777
3778 {
3779 SWP swp;
3780
3781 WinQueryWindowPos(hwndClient, &swp);
3782 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3783 return;
3784 }
3785 henum = WinBeginEnumWindows(hwndClient);
3786 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3787 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
3788 continue;
3789 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0, cmd);
3790 }
3791}
3792
3793//=== ChildFrameButtonProc: subclass handler for WALKBUTTON and QUICKBUTTON windows ===
3794
3795static MRESULT EXPENTRY ChildFrameButtonProc(HWND hwnd,
3796 ULONG msg,
3797 MPARAM mp1, MPARAM mp2)
3798{
3799 USHORT id;
3800 static BOOL emphasized = FALSE;
3801
3802 switch (msg) {
3803 case WM_BUTTON1CLICK:
3804 case WM_CHORD:
3805 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3806 break;
3807
3808 case WM_MOUSEMOVE:
3809 if (fOtherHelp) {
3810 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
3811 && !WinQueryCapture(HWND_DESKTOP)) {
3812 id = WinQueryWindowUShort(hwnd, QWS_ID);
3813 switch (id) {
3814 case IDM_OPENWALK:
3815 MakeBubble(hwnd, FALSE, GetPString(IDS_WALKBUTTONHELP));
3816 break;
3817 case IDM_USERLIST:
3818 MakeBubble(hwnd, FALSE, GetPString(IDS_QUICKBUTTONHELP));
3819 break;
3820 }
3821 }
3822 }
3823 break;
3824
3825 case WM_BUTTON3CLICK:
3826 case WM_BUTTON2CLICK:
3827 {
3828 USHORT cmd = 0;
3829
3830 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3831 id = WinQueryWindowUShort(hwnd, QWS_ID);
3832 switch (id) {
3833 case IDM_OPENWALK:
3834 switch (msg) {
3835 case WM_BUTTON2CLICK:
3836 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
3837 (KC_ALT | KC_SHIFT | KC_CTRL))
3838 cmd = IDM_GREP;
3839 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
3840 CascadeChildren(hwndMain);
3841
3842#ifdef NEVER
3843 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
3844 cmd = IDM_SYSINFO;
3845#endif
3846
3847 else if (shiftstate & KC_SHIFT)
3848 cmd = IDM_WINDOWDLG;
3849 else if (shiftstate & KC_CTRL)
3850 cmd = IDM_SEEALL;
3851 else if (shiftstate & KC_ALT)
3852 TileChildren(hwndMain, TRUE);
3853 else
3854 cmd = IDM_WALKDIR;
3855 break;
3856 case WM_BUTTON3CLICK:
3857 TileChildren(hwndMain, TRUE);
3858 break;
3859 }
3860 break;
3861 case IDM_USERLIST:
3862 switch (msg) {
3863 case WM_BUTTON2CLICK:
3864 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
3865 (KC_ALT | KC_SHIFT | KC_CTRL))
3866 cmd = IDM_COLORPALETTE;
3867 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
3868 cmd = IDM_HIDEMENU;
3869 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
3870 cmd = IDM_NOTEBOOK;
3871 else if (shiftstate & KC_SHIFT)
3872 cmd = IDM_TOOLTITLES;
3873 else if (shiftstate & KC_CTRL)
3874 cmd = IDM_TEXTTOOLS;
3875 else if (shiftstate & KC_ALT)
3876 cmd = IDM_FONTPALETTE;
3877 else
3878 cmd = IDM_TOOLBAR;
3879 break;
3880 case WM_BUTTON3CLICK:
3881 cmd = IDM_DRIVEBAR;
3882 break;
3883 }
3884 break;
3885 } // switch id
3886
3887 if (cmd) {
3888 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_CLIENT),
3889 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
3890 }
3891 }
3892 break;
3893
3894 case DM_DRAGOVER:
3895 id = WinQueryWindowUShort(hwnd, QWS_ID);
3896 if (id == IDM_OPENWALK) {
3897 if (!emphasized) {
3898 emphasized = TRUE;
3899 DrawTargetEmphasis(hwnd, emphasized);
3900 }
3901 if (AcceptOneDrop(hwnd, mp1, mp2))
3902 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
3903 }
3904 return MRFROM2SHORT(DOR_NEVERDROP, 0);
3905
3906 case DM_DRAGLEAVE:
3907 if (emphasized) {
3908 emphasized = FALSE;
3909 DrawTargetEmphasis(hwnd, emphasized);
3910 }
3911 break;
3912
3913 case DM_DROPHELP:
3914 DropHelp(mp1, mp2, hwnd, GetPString(IDS_OPENDROPHELP));
3915 return 0;
3916
3917 case DM_DROP:
3918 {
3919 char szFrom[CCHMAXPATH + 2];
3920
3921 if (emphasized) {
3922 emphasized = FALSE;
3923 DrawTargetEmphasis(hwnd, emphasized);
3924 }
3925 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
3926 if (MakeValidDir(szFrom) && !FindDirCnrByName(szFrom, TRUE)) {
3927 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, szFrom);
3928 }
3929 }
3930 }
3931 return 0;
3932
3933 case WM_CLOSE:
3934 WinDestroyWindow(hwnd);
3935 return 0;
3936 }
3937 return PFNWPButton(hwnd, msg, mp1, mp2);
3938}
3939
3940static MRESULT EXPENTRY MainFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
3941 MPARAM mp2)
3942{
3943 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
3944 static ULONG aheight = 0L;
3945
3946 switch (msg) {
3947 case WM_ADJUSTWINDOWPOS:
3948 {
3949 SWP *pswp;
3950
3951 pswp = (SWP *) mp1;
3952 if (fDataMin && !fAmClosing) {
3953 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE)) {
3954
3955 SWP swp;
3956
3957 WinQueryWindowPos(hwnd, &swp);
3958 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(swp.fl), MPVOID);
3959 HideNote();
3960 }
3961 else if (pswp->fl & (SWP_SHOW | SWP_RESTORE)) {
3962 if (DataHwnd)
3963 PostMsg(DataHwnd, WM_CLOSE, MPVOID, MPVOID);
3964 }
3965 }
3966 if (!fAmClosing) {
3967 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE))
3968 HideNote();
3969 }
3970 }
3971 break;
3972
3973 case UM_FOCUSME:
3974 CreateDataBar(HWND_DESKTOP, (ULONG) mp1);
3975 return 0;
3976
3977 case WM_BUTTON1UP:
3978 case WM_BUTTON2UP:
3979 case WM_BUTTON3UP:
3980 case WM_MOUSEMOVE:
3981 case WM_CHORD:
3982 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3983 break;
3984
3985 case WM_CHAR:
3986 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
3987 break;
3988
3989 case WM_CONTROL:
3990 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL, mp1,
3991 mp2);
3992
3993 case WM_COMMAND:
3994 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
3995
3996 case WM_CALCFRAMERECT:
3997 {
3998 MRESULT mr;
3999 PRECTL prectl;
4000 LONG sheight = 20, bheight = 20;
4001
4002 mr = oldproc(hwnd, msg, mp1, mp2);
4003
4004 /*
4005 * Calculate the position of the client rectangle.
4006 * Otherwise, we'll see a lot of redraw when we move the
4007 * client during WM_FORMATFRAME.
4008 */
4009
4010 if (mr && mp2) {
4011 prectl = (PRECTL) mp1;
4012 if (prectl->yBottom != prectl->yTop) {
4013 {
4014 HPS hps;
4015 POINTL aptl[TXTBOX_COUNT];
4016
4017 hps = WinGetPS(hwndStatus);
4018 if (hps) {
4019 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4020 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4021 WinReleasePS(hps);
4022 }
4023 }
4024 prectl->yBottom += (sheight + 4);
4025 prectl->yTop -= (sheight + 4);
4026 if (fMoreButtons) {
4027
4028 HPS hps;
4029 POINTL aptl[TXTBOX_COUNT];
4030
4031 hps = WinGetPS(hwndName);
4032 if (hps) {
4033 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4034 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4035 WinReleasePS(hps);
4036 }
4037 prectl->yBottom += (bheight + 4);
4038 prectl->yTop -= (bheight + 4);
4039 }
4040 if (fToolbar) {
4041 if (!fTextTools)
4042 prectl->yTop -= ((fToolTitles) ? 50 : 40);
4043 else
4044 prectl->yTop -= 32;
4045 }
4046 if (fDrivebar) {
4047 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES),
4048 ((prectl->xRight -
4049 (WinQuerySysValue(HWND_DESKTOP,
4050 SV_CYSIZEBORDER) * 2)) - 4));
4051 prectl->yTop -= (16 * (DriveLines * 18));
4052 }
4053 if (fUserComboBox) {
4054 if (!aheight) {
4055
4056 SWP swpTemp;
4057
4058 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4059 &swpTemp);
4060 aheight = swpTemp.cy;
4061 }
4062 prectl->yTop -= (aheight + 6L);
4063 }
4064 if (fAutoView) {
4065 AutoviewHeight = min(AutoviewHeight,
4066 (prectl->yTop - prectl->yBottom) - 116);
4067 AutoviewHeight = max(AutoviewHeight, 36);
4068 prectl->yBottom += (AutoviewHeight + 6);
4069 }
4070 }
4071 }
4072 return mr;
4073 }
4074
4075 case WM_FORMATFRAME:
4076 {
4077 SHORT sCount, soldCount;
4078 PSWP pswp, pswpClient, pswpNew;
4079 SWP swpClient;
4080 LONG theight = 48L, dheight = 20L, width, sheight = 20, bheight = 20;
4081
4082 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4083 soldCount = sCount;
4084
4085 /*
4086 * Reformat the frame to "squeeze" the client
4087 * and make room for status window sibling beneath
4088 * and toolbar above (if toolbar's on) and userlists
4089 * (if userlists are on).
4090 */
4091
4092 pswp = (PSWP) mp1;
4093 {
4094 SHORT x;
4095
4096 for (x = 0; x < soldCount; x++) {
4097 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
4098 pswpClient = pswp;
4099 break;
4100 }
4101 pswp++;
4102 }
4103 }
4104
4105 {
4106 HPS hps;
4107 POINTL aptl[TXTBOX_COUNT];
4108
4109 hps = WinGetPS(hwndStatus);
4110 if (hps) {
4111 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4112 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4113 WinReleasePS(hps);
4114 }
4115 if (fMoreButtons) {
4116 hps = WinGetPS(hwndName);
4117 if (hps) {
4118 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4119 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4120 WinReleasePS(hps);
4121 }
4122 }
4123 }
4124 pswpNew = (PSWP) mp1 + soldCount;
4125 *pswpNew = *pswpClient;
4126 swpClient = *pswpClient;
4127 pswpNew->hwnd = hwndStatus;
4128 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4129 pswpNew->x = swpClient.x + 3;
4130 pswpNew->y = swpClient.y + 2;
4131 if (!fSplitStatus)
4132 width = swpClient.cx - (16 + (sheight * 2) + 4);
4133 else
4134 width = (swpClient.cx - (16 + (sheight * 2) + 4)) / 2;
4135 width = max(width, 10);
4136 if (fSplitStatus)
4137 pswpNew->cx = width - 6;
4138 else
4139 pswpNew->cx = width - 8;
4140 pswpNew->cy = sheight;
4141 pswpClient->y = pswpNew->y + pswpNew->cy + 3;
4142 pswpClient->cy = (swpClient.cy - pswpNew->cy) - 3;
4143 sCount++;
4144
4145 if (fSplitStatus) {
4146 pswpNew = (PSWP) mp1 + (soldCount + 1);
4147 *pswpNew = *pswpClient;
4148 pswpNew->hwnd = hwndStatus2;
4149 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4150 pswpNew->x = width + 8;
4151 pswpNew->y = swpClient.y + 2;
4152 pswpNew->cx = width - 6;
4153 pswpNew->cy = sheight;
4154 sCount++;
4155 }
4156 else {
4157 WinShowWindow(hwndStatus2, FALSE);
4158 WinSetWindowText(hwndStatus2, NullStr);
4159 }
4160
4161 if (fToolbar) {
4162 if (fTextTools)
4163 theight = 32L;
4164 else if (!fToolTitles)
4165 theight = 40L;
4166 pswpNew = (PSWP) mp1 + (soldCount + 1 + (fSplitStatus != FALSE));
4167 *pswpNew = *pswpClient;
4168 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_TOOLS);
4169 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4170 pswpNew->x = swpClient.x + 2;
4171 pswpNew->y = (swpClient.y + swpClient.cy) - (theight - 2);
4172 pswpNew->cx = swpClient.cx - 4;
4173 pswpNew->cy = theight - 4;
4174 pswpClient->cy -= theight;
4175 sCount++;
4176 }
4177 else
4178 WinShowWindow(WinWindowFromID(hwnd, MAIN_TOOLS), FALSE);
4179
4180 if (fDrivebar) {
4181 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES), pswpClient->cx - 4);
4182 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4183 (fSplitStatus != FALSE) +
4184 (fToolbar != FALSE));
4185 *pswpNew = *pswpClient;
4186 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_DRIVES);
4187 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4188 pswpNew->x = swpClient.x + 2;
4189 dheight += ((dheight - 2) * DriveLines);
4190 pswpNew->y = (swpClient.y + swpClient.cy) - (dheight - 2);
4191 if (fToolbar)
4192 pswpNew->y -= theight;
4193 pswpNew->cx = swpClient.cx - 4;
4194 pswpNew->cy = dheight - 4;
4195 pswpClient->cy -= dheight;
4196 sCount++;
4197 }
4198 else
4199 WinShowWindow(WinWindowFromID(hwnd, MAIN_DRIVES), FALSE);
4200
4201 if (fAutoView) {
4202 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4203 (fToolbar != FALSE) +
4204 (fDrivebar != FALSE) +
4205 (fSplitStatus != FALSE));
4206 *pswpNew = *pswpClient;
4207 pswpNew->hwnd = (fComments) ? hwndAutoMLE : hwndAutoview;
4208 pswpNew->x = pswpClient->x + 3;
4209 pswpNew->y = pswpClient->y + 3;
4210 if (fMoreButtons)
4211 pswpNew->y += (bheight + 4);
4212 pswpNew->cx = pswpClient->cx - 6;
4213 AutoviewHeight = min(AutoviewHeight, pswpClient->cy - 116);
4214 AutoviewHeight = max(AutoviewHeight, 36);
4215 pswpNew->cy = AutoviewHeight;
4216 pswpClient->y += (AutoviewHeight + 6);
4217 pswpClient->cy -= (AutoviewHeight + 6);
4218 sCount++;
4219 WinShowWindow((fComments) ? hwndAutoview : hwndAutoMLE, FALSE);
4220 }
4221 else {
4222 WinShowWindow(hwndAutoview, FALSE);
4223 WinShowWindow(hwndAutoMLE, FALSE);
4224 }
4225
4226 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4227 (fToolbar != FALSE) +
4228 (fDrivebar != FALSE) +
4229 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4230 *pswpNew = *pswpClient;
4231 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_OPENWALK);
4232 pswpNew->x = swpClient.cx - ((sheight * 2) + 4);
4233 pswpNew->y = swpClient.y;
4234 pswpNew->cx = sheight + 4;
4235 pswpNew->cy = sheight + 4;
4236 sCount++;
4237 pswpNew = (PSWP) mp1 + (soldCount + 2 +
4238 (fToolbar != FALSE) +
4239 (fDrivebar != FALSE) +
4240 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4241 *pswpNew = *pswpClient;
4242 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_USERLIST);
4243 pswpNew->x = swpClient.cx - (sheight + 2);
4244 pswpNew->y = swpClient.y;
4245 pswpNew->cx = sheight + 4;
4246 pswpNew->cy = sheight + 4;
4247 sCount++;
4248 pswpNew = (PSWP) mp1 + (soldCount + 3 +
4249 (fToolbar != FALSE) +
4250 (fDrivebar != FALSE) +
4251 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4252 *pswpNew = *pswpClient;
4253 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LED);
4254 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4255 pswpNew->y = swpClient.y;
4256 pswpNew->cx = 12;
4257 pswpNew->cy = 12;
4258 sCount++;
4259 pswpNew = (PSWP) mp1 + (soldCount + 4 +
4260 (fToolbar != FALSE) +
4261 (fDrivebar != FALSE) +
4262 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4263 *pswpNew = *pswpClient;
4264 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LEDHDR);
4265 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4266 pswpNew->y = swpClient.y + 12;
4267 pswpNew->cx = 12;
4268 pswpNew->cy = sheight - 8;
4269 sCount++;
4270 if (fUserComboBox) {
4271 if (!aheight) {
4272
4273 SWP swpTemp;
4274
4275 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4276 &swpTemp);
4277 aheight = swpTemp.cy;
4278 }
4279 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4280 (fToolbar != FALSE) +
4281 (fSplitStatus != FALSE) +
4282 (fDrivebar != FALSE) + (fAutoView != FALSE));
4283 *pswpNew = *pswpClient;
4284 pswpNew->hwnd = hwndDrivelist;
4285 pswpNew->x = swpClient.x;
4286 pswpNew->cx = 48;
4287 pswpClient->cy -= (aheight + 6L);
4288 pswpNew->y = pswpClient->y;
4289 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4290 sCount++;
4291 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4292 (fToolbar != FALSE) +
4293 (fDrivebar != FALSE) +
4294 (fSplitStatus != FALSE) +
4295 (fAutoView != FALSE));
4296 *pswpNew = *pswpClient;
4297 pswpNew->hwnd = hwndStatelist;
4298 pswpNew->x = swpClient.x + 48;
4299 pswpNew->cx = (swpClient.cx - 48) / 7;
4300 pswpNew->y = pswpClient->y;
4301 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4302 sCount++;
4303 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4304 (fToolbar != FALSE) +
4305 (fDrivebar != FALSE) +
4306 (fSplitStatus != FALSE) +
4307 (fAutoView != FALSE));
4308 *pswpNew = *pswpClient;
4309 pswpNew->hwnd = hwndCmdlist;
4310 pswpNew->x = swpClient.x + 48 + ((swpClient.cx - 48) / 7);
4311 pswpNew->cx = (swpClient.cx - 48) / 5 +
4312 ((swpClient.cx - 48) / 5) - ((swpClient.cx - 48) / 7);
4313 pswpNew->y = pswpClient->y;
4314 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4315 sCount++;
4316 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4317 (fToolbar != FALSE) +
4318 (fDrivebar != FALSE) +
4319 (fSplitStatus != FALSE) +
4320 (fAutoView != FALSE));
4321 *pswpNew = *pswpClient;
4322 pswpNew->hwnd = hwndUserlist;
4323 pswpNew->x = swpClient.x + 48 + (((swpClient.cx - 48) / 5) * 2);
4324 pswpNew->cx = ((swpClient.x + swpClient.cx) - pswpNew->x) -
4325 ((fToolbar) ? ((swpClient.cx - 48) / 7) : 0);
4326 pswpNew->y = pswpClient->y;
4327 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4328 sCount++;
4329 if (fToolbar) {
4330 pswpNew = (PSWP) mp1 + (soldCount + 9 +
4331 (fToolbar != FALSE) +
4332 (fDrivebar != FALSE) +
4333 (fSplitStatus != FALSE) +
4334 (fAutoView != FALSE));
4335 *pswpNew = *pswpClient;
4336 pswpNew->hwnd = hwndButtonlist;
4337 pswpNew->x = swpClient.cx - ((swpClient.cx - 48) / 7) + 4;
4338 pswpNew->cx = (swpClient.x + swpClient.cx) - pswpNew->x;
4339 pswpNew->y = pswpClient->y;
4340 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4341 sCount++;
4342 }
4343 else
4344 WinShowWindow(hwndButtonlist, FALSE);
4345 }
4346 else {
4347 WinShowWindow(hwndUserlist, FALSE);
4348 WinShowWindow(hwndDrivelist, FALSE);
4349 WinShowWindow(hwndStatelist, FALSE);
4350 WinShowWindow(hwndButtonlist, FALSE);
4351 WinShowWindow(hwndCmdlist, FALSE);
4352 }
4353 {
4354 PSWP pswpTitlebar = (PSWP) 0, pswpMinbutton = (PSWP) 0;
4355 SHORT x;
4356
4357 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4358 (fToolbar != FALSE) +
4359 (fDrivebar != FALSE) +
4360 (fSplitStatus != FALSE) +
4361 (fAutoView != FALSE) +
4362 ((fUserComboBox != FALSE) * 4) +
4363 (fUserComboBox != FALSE &&
4364 fToolbar != FALSE));
4365 pswp = (PSWP) mp1;
4366 for (x = 0; x < soldCount; x++) {
4367 if (!pswpTitlebar &&
4368 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_TITLEBAR)
4369 pswpTitlebar = pswp;
4370 else if (!pswpMinbutton &&
4371 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_MINMAX)
4372 pswpMinbutton = pswp;
4373 if (pswpTitlebar && pswpMinbutton)
4374 break;
4375 pswp++;
4376 }
4377 if (pswpMinbutton && pswpTitlebar) {
4378 *pswpNew = *pswpMinbutton;
4379 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_IDEALSIZE);
4380 pswpNew->cy = pswpMinbutton->cy + 3;
4381 pswpNew->cx = min(pswpNew->cy, (pswpMinbutton->cx / 2) + 3);
4382 pswpTitlebar->cx -= (pswpNew->cx - 1);
4383 pswpNew->x = pswpTitlebar->x + (pswpTitlebar->cx);
4384 pswpNew->y = pswpMinbutton->y - 1;
4385 sCount++;
4386 }
4387 else
4388 WinShowWindow(WinWindowFromID(hwnd, IDM_IDEALSIZE), FALSE);
4389 }
4390
4391 if (fMoreButtons) {
4392
4393 LONG lastx;
4394
4395 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4396 (fToolbar != FALSE) +
4397 (fDrivebar != FALSE) +
4398 (fSplitStatus != FALSE) +
4399 (fAutoView != FALSE) +
4400 ((fUserComboBox != FALSE) * 4) +
4401 (fUserComboBox != FALSE &&
4402 fToolbar != FALSE));
4403 *pswpNew = *pswpClient;
4404 pswpNew->hwnd = hwndName;
4405 pswpNew->x = swpClient.x + 3;
4406 pswpNew->y = swpClient.y + (sheight + 6);
4407 pswpNew->cx = ((swpClient.cx / 2) + (swpClient.cx / 5)) - 3;
4408 lastx = pswpNew->x + pswpNew->cx;
4409 pswpNew->cy = bheight;
4410 pswpClient->y += (bheight + 4);
4411 pswpClient->cy -= (bheight + 4);
4412 sCount++;
4413 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4414 (fToolbar != FALSE) +
4415 (fDrivebar != FALSE) +
4416 (fSplitStatus != FALSE) +
4417 (fAutoView != FALSE) +
4418 ((fUserComboBox != FALSE) * 4) +
4419 (fUserComboBox != FALSE &&
4420 fToolbar != FALSE));
4421 *pswpNew = *pswpClient;
4422 pswpNew->hwnd = hwndDate;
4423 pswpNew->x = lastx + 3;
4424 pswpNew->y = swpClient.y + (sheight + 6);
4425 pswpNew->cx = (swpClient.cx / 6) + (swpClient.cx / 16) - 3;
4426 lastx = pswpNew->x + pswpNew->cx;
4427 pswpNew->cy = bheight;
4428 sCount++;
4429 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4430 (fToolbar != FALSE) +
4431 (fDrivebar != FALSE) +
4432 (fSplitStatus != FALSE) +
4433 (fAutoView != FALSE) +
4434 ((fUserComboBox != FALSE) * 4) +
4435 (fUserComboBox != FALSE &&
4436 fToolbar != FALSE));
4437 *pswpNew = *pswpClient;
4438 pswpNew->hwnd = hwndAttr;
4439 pswpNew->x = lastx + 3;
4440 pswpNew->y = swpClient.y + (sheight + 6);
4441 pswpNew->cx = (swpClient.cx - pswpNew->x) - 1;
4442 pswpNew->cy = bheight;
4443 sCount++;
4444 }
4445 else {
4446 WinShowWindow(hwndAttr, FALSE);
4447 WinShowWindow(hwndName, FALSE);
4448 WinShowWindow(hwndDate, FALSE);
4449 }
4450 return MRFROMSHORT(sCount);
4451 }
4452
4453 case WM_QUERYFRAMECTLCOUNT:
4454 {
4455 SHORT sCount;
4456
4457 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4458
4459 sCount += 6;
4460 if (fSplitStatus)
4461 sCount++;
4462 if (fToolbar)
4463 sCount++;
4464 if (fUserComboBox) {
4465 sCount += 4;
4466 if (fToolbar)
4467 sCount++;
4468 }
4469 if (fDrivebar)
4470 sCount++;
4471 if (fAutoView)
4472 sCount++;
4473 if (fMoreButtons)
4474 sCount += 3;
4475 return MRFROMSHORT(sCount);
4476 }
4477
4478 case WM_CLOSE:
4479 WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
4480 return 0;
4481 }
4482 return oldproc(hwnd, msg, mp1, mp2);
4483}
4484
4485MRESULT EXPENTRY MainWMCommand(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
4486{
4487 SetShiftState();
4488 switch (SHORT1FROMMP(mp1)) {
4489
4490 case IDM_CONTEXTMENU:
4491 {
4492 HWND hwnd = WinQueryFocus(HWND_DESKTOP);
4493 // DbgMsg(pszSrcFile, __LINE__, "IDM_CONTEXTMENU %x", hwnd);
4494 if (hwnd != NULLHANDLE) {
4495 HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
4496 USHORT id = WinQueryWindowUShort(hwndParent, QWS_ID);
4497 switch (id) {
4498 case MAIN_SETUPLIST:
4499 case MAIN_USERLIST:
4500 case MAIN_CMDLIST:
4501 // DbgMsg(pszSrcFile, __LINE__, "WM_CONTEXTMENU");
4502 WinPostMsg(hwnd, WM_CONTEXTMENU, 0, 0);
4503 }
4504 }
4505 }
4506 break;
4507
4508 case IDM_SETTARGET:
4509 SetTargetDir(hwnd, FALSE);
4510 break;
4511
4512 case IDM_TOAUTOMLE:
4513 if (fComments && fAutoView)
4514 WinSetFocus(HWND_DESKTOP, hwndAutoMLE);
4515 break;
4516
4517 case IDM_HIDENOTEWND:
4518 HideNote();
4519 break;
4520 case IDM_SHOWNOTEWND:
4521 ShowNote();
4522 break;
4523
4524 case IDM_COMPARE:
4525 {
4526 WALK2 wa;
4527 PCNRITEM pci;
4528
4529 memset(&wa, 0, sizeof(wa));
4530 wa.size = sizeof(wa);
4531 pci =
4532 (PCNRITEM)
4533 WinSendMsg(WinWindowFromID
4534 (WinWindowFromID(hwndTree, FID_CLIENT), TREE_CNR),
4535 CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
4536 MPFROMSHORT(CRA_CURSORED));
4537 if (pci && (INT) pci != -1) {
4538 strcpy(wa.szCurrentPath1, pci->pszFileName);
4539 MakeValidDir(wa.szCurrentPath1);
4540 }
4541 else
4542 save_dir2(wa.szCurrentPath1);
4543 TopWindowName(hwndMain, (HWND) 0, wa.szCurrentPath2);
4544 if (!*wa.szCurrentPath2)
4545 strcpy(wa.szCurrentPath2, wa.szCurrentPath1);
4546 MakeValidDir(wa.szCurrentPath2);
4547 if (WinDlgBox(HWND_DESKTOP,
4548 hwnd,
4549 WalkTwoCmpDlgProc,
4550 FM3ModHandle,
4551 WALK2_FRAME,
4552 MPFROMP(&wa)) &&
4553 !IsFile(wa.szCurrentPath1) && !IsFile(wa.szCurrentPath2)) {
4554 if (!*dircompare) {
4555
4556 COMPARE *cmp;
4557
4558 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
4559 if (cmp) {
4560 cmp->size = sizeof(COMPARE);
4561 strcpy(cmp->leftdir, wa.szCurrentPath1);
4562 strcpy(cmp->rightdir, wa.szCurrentPath2);
4563 cmp->hwndParent = hwnd;
4564 cmp->dcd.hwndParent = hwnd;
4565 WinDlgBox(HWND_DESKTOP,
4566 HWND_DESKTOP,
4567 CompareDlgProc, FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
4568 }
4569 }
4570 else {
4571
4572 CHAR szPath1[CCHMAXPATH];
4573 CHAR szPath2[CCHMAXPATH];
4574 runemf2(SEPARATE,
4575 HWND_DESKTOP, pszSrcFile, __LINE__,
4576 NULL, NULL,
4577 "%s %s %s",
4578 dircompare,
4579 BldQuotedFileName(szPath1, wa.szCurrentPath1),
4580 BldQuotedFileName(szPath2, wa.szCurrentPath2));
4581 }
4582 }
4583 }
4584 break;
4585
4586 case IDM_EXIT:
4587 case IDM_KILLME:
4588 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
4589 break;
4590
4591 case IDM_CLI:
4592 if (fSplitStatus &&
4593 hwndStatus2 &&
4594 !WinIsWindow(WinQueryAnchorBlock(hwnd),
4595 WinWindowFromID(hwndStatus2, COMMAND_LINE)))
4596 PostMsg(hwndStatus2, UM_CLICKED, MPVOID, MPVOID);
4597 break;
4598
4599 case IDM_ADDTOUSERLIST:
4600 case IDM_DELETEFROMUSERLIST:
4601 {
4602 CHAR temp[CCHMAXPATH], path[CCHMAXPATH];
4603
4604 *temp = 0;
4605 WinQueryWindowText(hwndUserlist, CCHMAXPATH, temp);
4606 bstrip(temp);
4607 if (*temp &&
4608 !DosQueryPathInfo(temp, FIL_QUERYFULLNAME, path, sizeof(path))) {
4609 if (SHORT1FROMMP(mp1) == IDM_ADDTOUSERLIST) {
4610 add_udir(TRUE, path);
4611 if (fUdirsChanged)
4612 save_udirs();
4613 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4614 }
4615 else {
4616 if (!remove_udir(path))
4617 Runtime_Error(pszSrcFile, __LINE__, "remove_udir");
4618 else {
4619 if (fUdirsChanged)
4620 save_udirs();
4621 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4622 }
4623 }
4624 }
4625 }
4626 break;
4627
4628 case IDM_SAVEDIRCNRSTATE:
4629 case IDM_DELETEDIRCNRSTATE:
4630 {
4631 CHAR szStateName[STATE_NAME_MAX_BYTES + 1];
4632
4633 *szStateName = 0;
4634 WinQueryWindowText(hwndStatelist, STATE_NAME_MAX_BYTES, szStateName);
4635 bstrip(szStateName);
4636 // Complain if attempting to use reserved name
4637 if (stricmp(szStateName, GetPString(IDS_STATETEXT)) == 0 ||
4638 stricmp(szStateName, GetPString(IDS_FM2TEMPTEXT)) == 0)
4639 {
4640 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4641 GetPString(IDS_WARNINGTEXT),
4642 "\"%s\" is a reserved state name", szStateName);
4643 }
4644 // Ignore request if blank
4645 else if (*szStateName) {
4646 BOOL fAbortOperation = FALSE;
4647 if (!fNoSaveState && fSaveState && stricmp(szStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0)
4648 {
4649 if (saymsg(MB_YESNO | MB_DEFBUTTON2 | MB_ICONASTERISK, hwnd,
4650 GetPString(IDS_WARNINGTEXT),
4651 GetPString(IDS_SHUTDOWNSTATE_WARNING), szStateName) == MBID_NO)
4652 fAbortOperation = TRUE;
4653 }
4654 if (!fAbortOperation) {
4655 if (SHORT1FROMMP(mp1) == IDM_SAVEDIRCNRSTATE) {
4656 // Save
4657 INT nSaved = SaveDirCnrState(hwnd, szStateName);
4658 if (nSaved >= 0) {
4659 INT ret = add_setup(szStateName);
4660 if (ret == 0) {
4661 WinSendMsg(hwndStatelist, LM_INSERTITEM,
4662 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(szStateName));
4663 save_setups();
4664 }
4665 else if (ret != 1) {
4666 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4667 GetPString(IDS_WARNINGTEXT),
4668 "\"%s\" state name add failed", szStateName); // 15 Apr 07 SHL failed
4669 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
4670 }
4671 }
4672 else {
4673 saymsg(MB_ENTER | MB_ICONASTERISK,
4674 hwnd,
4675 GetPString(IDS_WARNINGTEXT),
4676 "State data save failed");
4677 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
4678 }
4679 }
4680 else {
4681 // Delete
4682 ULONG numsaves = 0, size, x;
4683 CHAR s[STATE_NAME_MAX_BYTES + 80];
4684
4685 INT ret = remove_setup(szStateName);
4686 if (ret == 1)
4687 save_setups();
4688 sprintf(s, "%s.NumDirsLastTime", szStateName);
4689 size = sizeof(ULONG);
4690 if (!PrfQueryProfileData(fmprof,
4691 FM3Str,
4692 s,
4693 (PVOID)&numsaves,
4694 &size)) {
4695 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4696 GetPString(IDS_WARNINGTEXT),
4697 GetPString(IDS_DOESNTEXISTTEXT), szStateName);
4698 }
4699 else if (!size)
4700 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
4701 else {
4702 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0L);
4703 for (x = 0; x < numsaves; x++) {
4704 sprintf(s, "%s.DirCnrPos.%lu", szStateName, x);
4705 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4706 sprintf(s, "%s.DirCnrDir.%lu", szStateName, x);
4707 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4708 sprintf(s, "%s.DirCnrSort.%lu", szStateName, x);
4709 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4710 sprintf(s, "%s.DirCnrFilter.%lu", szStateName, x);
4711 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4712 sprintf(s, "%s.DirCnrView.%lu", szStateName, x);
4713 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4714 sprintf(s, "%s.DirCnr.%lu.DetailsLongname", szStateName, x);
4715 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4716 sprintf(s, "%s.DirCnr.%lu.DetailsSubject", szStateName, x);
4717 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4718 sprintf(s, "%s.DirCnr.%lu.DetailsSize", szStateName, x);
4719 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4720 sprintf(s, "%s.DirCnr.%lu.DetailsEA", szStateName, x);
4721 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4722 sprintf(s, "%s.DirCnr.%lu.DetailsAttr", szStateName, x);
4723 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4724 sprintf(s, "%s.DirCnr.%lu.DetailsIcon", szStateName, x);
4725 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4726 sprintf(s, "%s.DirCnr.%lu.DetailsLWDate", szStateName, x);
4727 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4728 sprintf(s, "%s.DirCnr.%lu.DetailsLWTime", szStateName, x);
4729 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4730 sprintf(s, "%s.DirCnr.%lu.DetailsLADate", szStateName, x);
4731 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4732 sprintf(s, "%s.DirCnr.%lu.DetailsLATime", szStateName, x);
4733 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4734 sprintf(s, "%s.DirCnr.%lu.DetailsCRDate", szStateName, x);
4735 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4736 sprintf(s, "%s.DirCnr.%lu.DetailsCRTime", szStateName, x);
4737 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4738 sprintf(s, "%s.DirCnr.%lu.Backgroundcolor", szStateName, x);
4739 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4740 sprintf(s, "%s.DirCnr.%lu.Fontnamesize", szStateName, x);
4741 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4742 }
4743 sprintf(s, "%s.LastTreePos", szStateName);
4744 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4745 sprintf(s, "%s.MySizeLastTime", szStateName);
4746 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4747 }
4748 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
4749 }
4750 }
4751 }
4752 }
4753 break;
4754
4755 case IDM_IDEALSIZE:
4756 {
4757 SWP swp, swpD;
4758 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
4759 ULONG bsz = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
4760
4761 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4762 if (swp.fl & SWP_MAXIMIZE) {
4763 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_SYSCOMMAND,
4764 MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
4765 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4766 }
4767 WinGetMaxPosition(WinQueryWindow(hwnd, QW_PARENT), &swpD);
4768 swpD.x += bsz;
4769 swpD.cx -= (bsz * 2);
4770 swpD.y += icz;
4771 swpD.cy -= (icz + bsz);
4772 if (swp.x == swpD.x && swp.y == swpD.y &&
4773 swp.cx == swpD.cx && swp.cy == swpD.cy &&
4774 // fixme to be #defined someday
4775 WinQueryWindowUShort(hwnd, QWL_USER + 10) &&
4776 WinQueryWindowUShort(hwnd, QWL_USER + 14)) {
4777 swpD.x = WinQueryWindowUShort(hwnd, QWL_USER + 8);
4778 swpD.cx = WinQueryWindowUShort(hwnd, QWL_USER + 10);
4779 swpD.y = WinQueryWindowUShort(hwnd, QWL_USER + 12);
4780 swpD.cy = WinQueryWindowUShort(hwnd, QWL_USER + 14);
4781 }
4782 else {
4783 WinSetWindowUShort(hwnd, QWL_USER + 8, (USHORT) swp.x);
4784 WinSetWindowUShort(hwnd, QWL_USER + 10, (USHORT) swp.cx);
4785 WinSetWindowUShort(hwnd, QWL_USER + 12, (USHORT) swp.y);
4786 WinSetWindowUShort(hwnd, QWL_USER + 14, (USHORT) swp.cy);
4787 }
4788 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP,
4789 swpD.x, swpD.y, swpD.cx, swpD.cy, SWP_MOVE | SWP_SIZE);
4790 }
4791 break;
4792
4793 case IDM_BLINK:
4794 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
4795 SWP_MINIMIZE);
4796 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
4797 SWP_RESTORE | SWP_ZORDER);
4798 break;
4799
4800 case DID_CANCEL:
4801 {
4802 HWND hwndTop = TopWindow(hwndMain, (HWND) 0);
4803
4804 if (hwndTop)
4805 WinSetFocus(HWND_DESKTOP, hwndTop);
4806 }
4807 break;
4808
4809 case IDM_NOTEBOOK:
4810 case IDM_DIRCNRSETTINGS:
4811 case IDM_DIRVIEWSETTINGS:
4812 case IDM_DIRSORTSETTINGS:
4813 case IDM_COLLECTORVIEWSETTINGS:
4814 case IDM_COLLECTORSORTSETTINGS:
4815 case IDM_ARCHIVERSETTINGS:
4816 case IDM_TREECNRVIEWSETTINGS:
4817 case IDM_TREECNRSORTSETTINGS:
4818 case IDM_VIEWERSETTINGS:
4819 case IDM_VIEWERSETTINGS2:
4820 case IDM_COMPARESETTINGS:
4821 case IDM_MONOLITHICSETTINGS:
4822 case IDM_GENERALSETTINGS:
4823 case IDM_SCANSETTINGS:
4824 case IDM_BUBBLESSETTINGS:
4825 case IDM_QUICKSETTINGS:
4826 WinDlgBox(HWND_DESKTOP,
4827 hwnd, CfgDlgProc, FM3ModHandle, CFG_FRAME, MPFROMLONG(mp1));
4828 break;
4829
4830 case IDM_VIEWHELPS:
4831 case IDM_VIEWINFS:
4832 WinDlgBox(HWND_DESKTOP,
4833 HWND_DESKTOP,
4834 ViewInfProc,
4835 FM3ModHandle,
4836 VINF_FRAME,
4837 ((SHORT1FROMMP(mp1) == IDM_VIEWHELPS) ?
4838 MPFROMP(NullStr) : MPVOID));
4839 break;
4840
4841 case IDM_OPENWALK:
4842 {
4843 char newpath[CCHMAXPATH];
4844
4845 *newpath = 0;
4846 TopWindowName(hwnd, (HWND) 0, newpath);
4847 if (WinDlgBox(HWND_DESKTOP,
4848 hwnd,
4849 WalkAllDlgProc,
4850 FM3ModHandle, WALK_FRAME, MPFROMP(newpath)) && *newpath)
4851 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, newpath);
4852 }
4853 break;
4854
4855 case IDM_WINDOWDLG:
4856 WindowList(hwnd);
4857 break;
4858
4859 case IDM_HELPMOUSE:
4860 case IDM_HELPCONTEXT:
4861 case IDM_HELPHINTS:
4862 case IDM_HELPPIX:
4863 case IDM_HELPTUTOR:
4864 case IDM_HELPUSERLIST:
4865 case IDM_HELP:
4866 case IDM_HELPCONTENTS:
4867 case IDM_HELPKEYS:
4868 case IDM_HELPGENERAL:
4869 if (hwndHelp) {
4870 if (SHORT1FROMMP(mp2) == CMDSRC_MENU) {
4871
4872 RECTL rcl;
4873 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
4874
4875 WinQueryWindowRect(HWND_DESKTOP, &rcl);
4876 rcl.yBottom += icz;
4877 rcl.yTop -= icz;
4878 rcl.xLeft += icz;
4879 rcl.xRight -= icz;
4880 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
4881 }
4882 else {
4883
4884 RECTL rcl;
4885
4886 WinQueryWindowRect(HWND_DESKTOP, &rcl);
4887 rcl.yBottom += 8;
4888 rcl.yTop = (rcl.yTop / 2) + (rcl.yTop / 7);
4889 rcl.xLeft = (rcl.xRight / 2) - (rcl.xRight / 7);
4890 rcl.xRight -= 8;
4891 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
4892 }
4893 switch (SHORT1FROMMP(mp1)) {
4894 case IDM_HELPCONTEXT:
4895 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4896 MPFROM2SHORT(HELP_CONTEXT, 0), MPFROMSHORT(HM_RESOURCEID));
4897 break;
4898
4899 case IDM_HELPMOUSE:
4900 if (hwndHelp)
4901 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4902 MPFROM2SHORT(HELP_MOUSE, 0), MPFROMSHORT(HM_RESOURCEID));
4903 break;
4904
4905 case IDM_HELPPIX:
4906 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4907 MPFROM2SHORT(HELP_BITMAP1, 0), MPFROMSHORT(HM_RESOURCEID));
4908 break;
4909
4910 case IDM_HELPTUTOR:
4911 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4912 MPFROM2SHORT(HELP_TUTORIAL, 0),
4913 MPFROMSHORT(HM_RESOURCEID));
4914 break;
4915
4916 case IDM_HELPHINTS:
4917 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4918 MPFROM2SHORT(HELP_HINTS, 0), MPFROMSHORT(HM_RESOURCEID));
4919 break;
4920
4921 case IDM_HELPGENERAL:
4922 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4923 MPFROM2SHORT(HELP_MAIN, 0), MPFROMSHORT(HM_RESOURCEID));
4924 break;
4925 case IDM_HELPKEYS:
4926 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4927 MPFROM2SHORT(HELP_KEYS, 0), MPFROMSHORT(HM_RESOURCEID));
4928 break;
4929
4930 case IDM_HELP:
4931 case IDM_HELPCONTENTS:
4932 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
4933 break;
4934
4935 case IDM_HELPUSERLIST:
4936 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4937 MPFROM2SHORT(HELP_USERLISTS, 0),
4938 MPFROMSHORT(HM_RESOURCEID));
4939 break;
4940 }
4941 }
4942 break;
4943
4944 case IDM_EDITANYARCHIVER:
4945 EditArchiverDefinition(hwnd);
4946 break;
4947
4948 case IDM_ABOUT:
4949 WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, FM3ModHandle,
4950 ABT_FRAME, MPVOID);
4951 break;
4952
4953 case IDM_FONTPALETTE:
4954 OpenObject("<WP_FNTPAL>", Default, hwnd);
4955 break;
4956
4957 case IDM_HICOLORPALETTE:
4958 case IDM_COLORPALETTE:
4959 {
4960 CHAR *palette = "<WP_CLRPAL>";
4961 ULONG version[2];
4962
4963 if (!DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
4964 (PVOID) & version, (ULONG) sizeof(version))) {
4965 if (version[0] > 20L || (version[0] == 20L && version[1] > 29L)) {
4966 if (SHORT1FROMMP(mp1) == IDM_HICOLORPALETTE)
4967 palette = "<WP_HIRESCLRPAL>";
4968 else
4969 palette = "<WP_LORESCLRPAL>";
4970 }
4971 }
4972 OpenObject(palette, Default, hwnd);
4973 }
4974 break;
4975
4976 case IDM_SYSTEMSETUP:
4977 OpenObject("<WP_CONFIG>", Default, hwnd);
4978 break;
4979
4980 case IDM_SCHEMEPALETTE:
4981 {
4982 HOBJECT hWPSObject;
4983
4984 hWPSObject = WinQueryObject("<WP_SCHPAL>");
4985 if (hWPSObject != NULLHANDLE)
4986 WinSetObjectData(hWPSObject, "SCHEMES=Winter:PM_Winter,"
4987 "Spring:PM_Spring,Summer:PM_Summer,"
4988 "System:PM_System,Windows:PM_Windows;"
4989 "OPEN=DEFAULT");
4990 }
4991 break;
4992
4993 case IDM_SYSTEMCLOCK:
4994 OpenObject("<WP_CLOCK>", Default, hwnd);
4995 break;
4996
4997#ifdef NEVER
4998 case IDM_SYSINFO:
4999 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, SysInfoDlgProc, FM3ModHandle,
5000 SYS_FRAME, NULL);
5001 break;
5002#endif
5003
5004 case IDM_INSTANT:
5005 {
5006 CHAR path[CCHMAXPATH];
5007 PCNRITEM pci = (PCNRITEM) 0;
5008
5009 if (hwndTree)
5010 pci = (PCNRITEM) WinSendMsg(hwndTree, CM_QUERYRECORDEMPHASIS,
5011 MPFROMLONG(CMA_FIRST),
5012 MPFROMSHORT(CRA_CURSORED));
5013 if (pci && (INT) pci != -1) {
5014 strcpy(path, pci->pszFileName);
5015 MakeValidDir(path);
5016 }
5017 else
5018 save_dir2(path);
5019 WinDlgBox(HWND_DESKTOP, hwnd, InstantDlgProc, FM3ModHandle,
5020 BAT_FRAME, MPFROMP(path));
5021 }
5022 break;
5023
5024 case IDM_WINFULLSCREEN:
5025 case IDM_DOSCOMMANDLINE:
5026 case IDM_COMMANDLINE:
5027 {
5028 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
5029 INT type = SEPARATE | WINDOWED;
5030
5031 *path = 0;
5032 TopWindowName(hwnd, (HWND) 0, path);
5033 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
5034 env = GetCmdSpec(TRUE);
5035 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
5036 env = "WINOS2.COM";
5037 type = SEPARATE | FULLSCREEN;
5038 }
5039 runemf2(type, hwnd, pszSrcFile, __LINE__,
5040 path, NULL, "%s", env);
5041 }
5042 break;
5043
5044 case IDM_KILLPROC:
5045 WinDlgBox(HWND_DESKTOP, hwnd, KillDlgProc, FM3ModHandle,
5046 KILL_FRAME, NULL);
5047 break;
5048
5049 case IDM_AUTOVIEWCOMMENTS:
5050 case IDM_AUTOVIEWFILE:
5051 if (SHORT1FROMMP(mp1) == IDM_AUTOVIEWFILE)
5052 fComments = FALSE;
5053 else
5054 fComments = TRUE;
5055 PrfWriteProfileData(fmprof, FM3Str, "Comments", &fComments, sizeof(BOOL));
5056 WinSetWindowText((fComments) ? hwndAutoview : hwndAutoMLE, NullStr);
5057 goto AutoChange;
5058
5059 case IDM_AUTOVIEW:
5060 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5061 &fAutoView, TRUE, "AutoView");
5062 AutoChange:
5063 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5064 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5065 if (fAutoView) {
5066
5067 CHAR s[CCHMAXPATH];
5068 HWND hwndDir;
5069 PCNRITEM pci;
5070
5071 hwndDir = TopWindowName(hwnd, (HWND) 0, s);
5072 if (hwndDir) {
5073 hwndDir = WinWindowFromID(hwndDir, FID_CLIENT);
5074 if (hwndDir) {
5075 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
5076 if (hwndDir) {
5077 pci = (PCNRITEM) WinSendMsg(hwndDir, CM_QUERYRECORDEMPHASIS,
5078 MPFROMLONG(CMA_FIRST),
5079 MPFROMSHORT(CRA_CURSORED));
5080 if (pci && (INT) pci != -1 &&
5081 (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW)))
5082 WinSendMsg(hwnd,
5083 UM_LOADFILE,
5084 MPFROMP(pci->pszFileName),
5085 (SHORT1FROMMP(mp1) == IDM_AUTOVIEW) ?
5086 MPVOID : MPFROMLONG(1));
5087 }
5088 }
5089 }
5090 }
5091 break;
5092
5093 case IDM_TEXTTOOLS:
5094 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5095 &fTextTools, TRUE, "TextTools");
5096 BuildTools(hwndToolback, TRUE);
5097 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5098 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5099 break;
5100
5101 case IDM_TOOLTITLES:
5102 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5103 &fToolTitles, TRUE, "ToolTitles");
5104 BuildTools(hwndToolback, TRUE);
5105 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5106 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5107 break;
5108
5109 case IDM_HIDEMENU:
5110 {
5111 HWND hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
5112 MenuInvisible = MenuInvisible ? FALSE : TRUE;
5113 if (MenuInvisible) {
5114 WinSetParent(hwndMenu, HWND_OBJECT, FALSE);
5115 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5116 FID_SYSMENU), IDM_HIDEMENU,
5117 GetPString(IDS_UNHIDEMENUTEXT));
5118 }
5119 else {
5120 WinSetParent(hwndMenu, WinQueryWindow(hwnd, QW_PARENT), FALSE);
5121 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5122 FID_SYSMENU), IDM_HIDEMENU,
5123 GetPString(IDS_HIDEMENUTEXT));
5124 }
5125 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5126 MPFROMLONG(FCF_MENU), MPVOID);
5127 PrfWriteProfileData(fmprof, FM3Str, "MenuInvisible",
5128 &MenuInvisible, sizeof(BOOL));
5129 }
5130 break;
5131
5132 case IDM_SEEALL:
5133 case IDM_GREP:
5134 case IDM_COLLECTOR:
5135 {
5136 HWND hwndC;
5137 SWP swp;
5138 BOOL already = FALSE;
5139
5140 if (Collector)
5141 already = TRUE;
5142 if (!already && !fAutoTile && !fExternalCollector)
5143 GetNextWindowPos(hwnd, &swp, NULL, NULL);
5144 hwndC = StartCollector(fExternalCollector ? HWND_DESKTOP : hwnd, 4);
5145 if (hwndC) {
5146 if (!already && !fAutoTile && !fExternalCollector)
5147 WinSetWindowPos(hwndC, HWND_TOP,
5148 swp.x, swp.y, swp.cx, swp.cy,
5149 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
5150 else if (fAutoTile && !already)
5151 TileChildren(hwnd, TRUE);
5152 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE |
5153 SWP_ACTIVATE);
5154 if (SHORT1FROMMP(mp1) == IDM_GREP)
5155 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5156 MPFROM2SHORT(IDM_GREP, 0), MPVOID);
5157 if (SHORT1FROMMP(mp1) == IDM_SEEALL)
5158 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5159 MPFROM2SHORT(IDM_SEEALL, 0), MPVOID);
5160 }
5161 }
5162 break;
5163
5164 case IDM_TOOLLEFT:
5165 case IDM_TOOLRIGHT:
5166 {
5167 TOOL *tool;
5168
5169 if (!toolhead || !toolhead->next) {
5170 firsttool = (toolhead) ? toolhead->id : 0;
5171 break;
5172 }
5173 tool = find_tool(firsttool);
5174 if (!tool)
5175 tool = toolhead;
5176 if (SHORT1FROMMP(mp1) == IDM_TOOLRIGHT) {
5177 tool = prev_tool(tool, TRUE);
5178 firsttool = tool->id;
5179 }
5180 else {
5181 tool = next_tool(tool, TRUE);
5182 firsttool = tool->id;
5183 }
5184 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5185 MAIN_TOOLS));
5186 }
5187 break;
5188
5189 case IDM_CREATETOOL:
5190 BuildTools(hwndToolback, TRUE);
5191 break;
5192
5193 case IDM_TOOLBAR:
5194 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5195 IDM_TOOLSUBMENU, &fToolbar, TRUE, "Toolbar");
5196 BuildTools(hwndToolback, TRUE);
5197 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5198 MAIN_TOOLS), fToolbar);
5199 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
5200 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5201 if (fDrivebar)
5202 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5203 MAIN_DRIVES), NULL, TRUE);
5204 break;
5205
5206 case IDM_DRIVEBAR:
5207 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5208 IDM_DRIVEBAR, &fDrivebar, TRUE, "Drivebar");
5209 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5210 MAIN_DRIVES), fDrivebar);
5211 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5212 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5213 PostMsg(hwnd, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
5214 break;
5215
5216 case IDM_USERLIST:
5217 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5218 SHORT1FROMMP(mp1), &fUserComboBox, TRUE, "UserComboBox");
5219 WinShowWindow(hwndUserlist, fUserComboBox);
5220 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5221 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5222 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
5223 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
5224 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5225 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
5226 break;
5227
5228 case IDM_MOREBUTTONS:
5229 WinSetWindowText(hwndName, NullStr);
5230 WinSetWindowText(hwndDate, NullStr);
5231 WinSetWindowText(hwndAttr, NullStr);
5232 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5233 SHORT1FROMMP(mp1), &fMoreButtons, TRUE, "MoreButtons");
5234 if (fMoreButtons) {
5235
5236 HWND hwndTemp;
5237
5238 hwndTemp = TopWindow(hwnd, (HWND) 0);
5239
5240 if (hwndTemp) {
5241 WinSetFocus(HWND_DESKTOP, hwnd);
5242 WinSetFocus(HWND_DESKTOP, hwndTemp);
5243 }
5244 }
5245 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5246 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5247 break;
5248
5249 case IDM_TOGGLEDRAGDIALOG:
5250 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5251 IDM_TOGGLEDRAGDIALOG,
5252 &fDragndropDlg,
5253 TRUE,
5254 "Drag&DropDlg");
5255 break;
5256
5257 case IDM_SYNCUPDATES:
5258 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5259 IDM_SYNCUPDATES,
5260 &fSyncUpdates,
5261 TRUE,
5262 "SyncUpdates");
5263 break;
5264
5265 case IDM_FREETREE:
5266 if (fFreeTree) {
5267 SWP swp, swpT;
5268
5269 WinQueryWindowPos(hwndTree, &swpT);
5270 WinQueryWindowPos(hwnd, &swp);
5271 WinSetWindowPos(hwndTree, HWND_TOP, 0, swp.cy - swpT.cy, 0, 0,
5272 SWP_MOVE);
5273 }
5274 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5275 &fFreeTree, TRUE, "FreeTree");
5276 if (fAutoTile)
5277 TileChildren(hwnd, TRUE);
5278 break;
5279
5280 case IDM_AUTOTILE:
5281 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5282 SHORT1FROMMP(mp1), &fAutoTile, TRUE, "AutoTile");
5283 if (fAutoTile)
5284 TileChildren(hwnd, TRUE);
5285 break;
5286
5287 case IDM_TILEBACKWARDS:
5288 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5289 SHORT1FROMMP(mp1), &fTileBackwards, TRUE, "TileBackwards");
5290 if (fAutoTile)
5291 TileChildren(hwnd, TRUE);
5292 break;
5293
5294 case IDM_NEXTWINDOW:
5295 case IDM_PREVWINDOW:
5296 NextChild(hwnd, (SHORT1FROMMP(mp1) == IDM_PREVWINDOW));
5297 break;
5298
5299 case IDM_CASCADE:
5300 CascadeChildren(hwnd);
5301 break;
5302
5303 case IDM_TILE:
5304 TileChildren(hwnd, TRUE);
5305 break;
5306
5307 case IDM_RESTORE:
5308 MinResChildren(hwnd, SWP_RESTORE);
5309 break;
5310
5311 case IDM_MINIMIZE:
5312 MinResChildren(hwnd, SWP_MINIMIZE);
5313 break;
5314
5315 case IDM_ARRANGEICONS:
5316 ArrangeIcons(hwnd);
5317 break;
5318
5319 case IDM_INIVIEWER:
5320 StartIniEditor(hwnd, NULL, 4);
5321 break;
5322
5323 case IDM_EDITASSOC:
5324 EditAssociations(hwnd);
5325 break;
5326
5327 case IDM_EDITCOMMANDS:
5328 EditCommands(hwnd);
5329 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5330 break;
5331
5332 default:
5333 if (!SwitchCommand((HWND) WinQueryWindowULong(hwnd, QWL_USER),
5334 SHORT1FROMMP(mp1))) {
5335 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
5336 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
5337
5338 INT x;
5339 HWND hwndCnr;
5340
5341 if (!cmdloaded)
5342 load_commands();
5343 hwndCnr = TopWindow(hwnd, (HWND) 0);
5344 hwndCnr = (HWND) WinSendMsg(WinWindowFromID(hwndCnr, FID_CLIENT),
5345 UM_CONTAINERHWND, MPVOID, MPVOID);
5346 if (!hwndCnr) {
5347 Runtime_Error2(pszSrcFile, __LINE__, IDS_NOWINDOWTEXT);
5348 break;
5349 }
5350 x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
5351 if (x >= 0) {
5352 x++;
5353 RunCommand(hwndCnr, x);
5354 if (fUnHilite) {
5355
5356 PCNRITEM pci;
5357 DIRCNRDATA *dcd = NULL;
5358
5359 // 12 May 07 SHL fixme to understand? backwards maybe? looking for DIR_CNR?
5360 if (WinQueryWindowUShort(hwndCnr, QWS_ID) != TREE_CNR)
5361 dcd = INSTDATA(hwndCnr);
5362 pci = (PCNRITEM) WinSendMsg(hwndCnr,
5363 CM_QUERYRECORDEMPHASIS,
5364 MPFROMLONG(CMA_FIRST),
5365 MPFROMSHORT(CRA_CURSORED));
5366 if (pci && (INT) pci != -1 &&
5367 (pci->rc.flRecordAttr & CRA_SELECTED))
5368 {
5369 UnHilite(hwnd,
5370 TRUE,
5371 dcd ? &dcd->lastselection : NULL,
5372 dcd ? dcd ->ulItemsToUnHilite : 0);
5373 }
5374 }
5375 }
5376 }
5377 else if (SHORT1FROMMP(mp1) >= IDM_QUICKTOOLSTART &&
5378 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART + 50) {
5379 if (!qtloaded)
5380 load_quicktools();
5381 if (quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]) {
5382 if (fToolsChanged)
5383 save_tools(NULL);
5384 if (!load_tools(quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]))
5385 load_tools(NULL);
5386 else {
5387 strcpy(lasttoolbox,
5388 quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]);
5389 PrfWriteProfileString(fmprof, FM3Str, "LastToolBox", lasttoolbox);
5390 }
5391 BuildTools(hwndToolback, TRUE);
5392 }
5393 }
5394 else {
5395
5396 HWND hwndActive;
5397
5398 hwndActive = TopWindow(hwnd, (HWND) 0);
5399 if (hwndActive)
5400 PostMsg(WinWindowFromID(hwndActive, FID_CLIENT),
5401 WM_COMMAND, mp1, mp2);
5402 }
5403 }
5404 break; // default
5405 } // switch mp1
5406 return 0;
5407}
5408
5409static MRESULT EXPENTRY MainWMOnce(HWND hwnd, ULONG msg, MPARAM mp1,
5410 MPARAM mp2)
5411{
5412 TID tid;
5413 SWP swp;
5414 PFNWP oldproc;
5415 HWND hwndTmp;
5416 HWND hwndFrame;
5417 HWND hwndSysMenu, hwndSysSubMenu, hwndMenu;
5418 USHORT idSysMenu;
5419 MENUITEM mi, mit;
5420 ULONG size;
5421 BOOL temp = FALSE;
5422
5423 switch (msg) {
5424 case WM_CREATE:
5425 WinQueryWindowProcess(hwnd, &mypid, &tid);
5426 hwndMain = hwnd;
5427 WinSetWindowUShort(hwnd, QWL_USER + 8, 0);
5428 WinSetWindowUShort(hwnd, QWL_USER + 10, 0);
5429 WinSetWindowUShort(hwnd, QWL_USER + 12, 0);
5430 WinSetWindowUShort(hwnd, QWL_USER + 16, 0);
5431 if (_beginthread(MakeMainObjWin, NULL, 245760, MPVOID) == -1) {
5432 Runtime_Error(pszSrcFile, __LINE__,
5433 GetPString(IDS_COULDNTSTARTTHREADTEXT));
5434 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
5435 return 0;
5436 }
5437 else
5438 DosSleep(32);//05 Aug 07 GKY 64
5439
5440 hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
5441
5442 /*
5443 * create frame children (not client children, frame children)
5444 */
5445 DosSleep(1);
5446 WinQueryWindowPos(hwndFrame, &swp);
5447 oldproc = WinSubclassWindow(hwndFrame, MainFrameWndProc);
5448 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
5449 CommonCreateMainChildren(hwnd, &swp);
5450
5451 if (!WinCreateWindow(hwndFrame,
5452 WC_BUTTON,
5453 "I",
5454 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
5455 ((swp.cx -
5456 WinQuerySysValue(HWND_DESKTOP,
5457 SV_CXMINMAXBUTTON)) -
5458 WinQuerySysValue(HWND_DESKTOP,
5459 SV_CXMINMAXBUTTON) / 2) -
5460 WinQuerySysValue(HWND_DESKTOP,
5461 SV_CXSIZEBORDER),
5462 (swp.cy - WinQuerySysValue(HWND_DESKTOP,
5463 SV_CYMINMAXBUTTON)) -
5464 WinQuerySysValue(HWND_DESKTOP,
5465 SV_CYSIZEBORDER),
5466 WinQuerySysValue(HWND_DESKTOP,
5467 SV_CXMINMAXBUTTON) / 2,
5468 WinQuerySysValue(HWND_DESKTOP,
5469 SV_CYMINMAXBUTTON),
5470 hwnd, HWND_TOP, IDM_IDEALSIZE, NULL, NULL)) {
5471 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5472 }
5473 else {
5474 WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_IDEALSIZE),
5475 IdealButtonProc);
5476 SetPresParams(WinWindowFromID(hwndFrame,
5477 IDM_IDEALSIZE),
5478 NULL, NULL, NULL, GetPString(IDS_10SYSTEMVIOTEXT));
5479 }
5480
5481 hwndTmp = WinCreateWindow(hwndFrame,
5482 WC_BUTTON,
5483 "#1019",
5484 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5485 BS_BITMAP,
5486 swp.cx - 46,
5487 swp.y + 2,
5488 24,
5489 22, hwnd, HWND_TOP, IDM_OPENWALK, NULL, NULL);
5490 if (!hwndTmp)
5491 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5492
5493 hwndTmp = WinCreateWindow(hwndFrame,
5494 WC_BUTTON,
5495 "#3062",
5496 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5497 BS_BITMAP,
5498 swp.cx - 22,
5499 swp.y + 2,
5500 24,
5501 22, hwnd, HWND_TOP, IDM_USERLIST, NULL, NULL);
5502 if (!hwndTmp)
5503 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5504
5505 hwndUserlist = WinCreateWindow(hwndFrame,
5506 WC_COMBOBOX,
5507 (PSZ) NULL,
5508 WS_VISIBLE | CBS_DROPDOWN |
5509 LS_HORZSCROLL,
5510 (swp.x +
5511 WinQuerySysValue(HWND_DESKTOP,
5512 SV_CXSIZEBORDER) + 48L),
5513 (swp.cy -
5514 WinQuerySysValue(HWND_DESKTOP,
5515 SV_CYSIZEBORDER)) - 60,
5516 ((swp.cx -
5517 (WinQuerySysValue(HWND_DESKTOP,
5518 SV_CXSIZEBORDER) *
5519 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5520 MAIN_USERLIST, NULL, NULL);
5521 if (!hwndUserlist)
5522 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5523 hwndCmdlist = WinCreateWindow(hwndFrame,
5524 WC_COMBOBOX,
5525 (PSZ) NULL,
5526 WS_VISIBLE | CBS_DROPDOWN |
5527 LS_HORZSCROLL,
5528 (swp.x +
5529 WinQuerySysValue(HWND_DESKTOP,
5530 SV_CXSIZEBORDER) + 48L),
5531 (swp.cy -
5532 WinQuerySysValue(HWND_DESKTOP,
5533 SV_CYSIZEBORDER)) - 60,
5534 ((swp.cx -
5535 (WinQuerySysValue(HWND_DESKTOP,
5536 SV_CXSIZEBORDER) * 2)) -
5537 64L), 60L, hwndFrame, HWND_TOP,
5538 MAIN_CMDLIST, NULL, NULL);
5539 if (!hwndCmdlist)
5540 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5541 WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
5542 hwndStatelist = WinCreateWindow(hwndFrame,
5543 WC_COMBOBOX,
5544 (PSZ) NULL,
5545 WS_VISIBLE | CBS_DROPDOWN |
5546 LS_HORZSCROLL,
5547 (swp.x +
5548 WinQuerySysValue(HWND_DESKTOP,
5549 SV_CXSIZEBORDER) + 48L),
5550 (swp.cy -
5551 WinQuerySysValue(HWND_DESKTOP,
5552 SV_CYSIZEBORDER)) - 60,
5553 ((swp.cx -
5554 (WinQuerySysValue(HWND_DESKTOP,
5555 SV_CXSIZEBORDER) *
5556 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5557 MAIN_SETUPLIST, NULL, NULL);
5558 if (!hwndStatelist)
5559 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5560
5561 hwndDrivelist = WinCreateWindow(hwndFrame,
5562 WC_COMBOBOX,
5563 (PSZ) NULL,
5564 WS_VISIBLE | CBS_DROPDOWN,
5565 (swp.x +
5566 WinQuerySysValue(HWND_DESKTOP,
5567 SV_CXSIZEBORDER)),
5568 (swp.cy -
5569 WinQuerySysValue(HWND_DESKTOP,
5570 SV_CYSIZEBORDER)) - 60,
5571 48L,
5572 60L,
5573 hwndFrame,
5574 HWND_TOP, MAIN_DRIVELIST, NULL, NULL);
5575 if (!hwndDrivelist)
5576 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5577 SetPresParams(hwndDrivelist,
5578 NULL, NULL, NULL, GetPString(IDS_10SYSTEMMONOTEXT));
5579 hwndButtonlist = WinCreateWindow(hwndFrame,
5580 WC_COMBOBOX,
5581 (PSZ) NULL,
5582 WS_VISIBLE | CBS_DROPDOWN |
5583 LS_HORZSCROLL,
5584 (swp.cx -
5585 WinQuerySysValue(HWND_DESKTOP,
5586 SV_CXSIZEBORDER)) -
5587 164L,
5588 (swp.cy -
5589 WinQuerySysValue(HWND_DESKTOP,
5590 SV_CYSIZEBORDER)) - 60,
5591 164L, 60L, hwndFrame, HWND_TOP,
5592 MAIN_BUTTONLIST, NULL, NULL);
5593 if (!hwndButtonlist)
5594 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5595 WinSendMsg(WinWindowFromID(hwndUserlist, CBID_EDIT),
5596 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
5597 WinSendMsg(WinWindowFromID(hwndStatelist, CBID_EDIT),
5598 EM_SETTEXTLIMIT, MPFROM2SHORT(STATE_NAME_MAX_BYTES, 0), MPVOID);
5599 WinSendMsg(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5600 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5601 WinSendMsg(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5602 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5603 WinSendMsg(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5604 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5605
5606 oldproc = WinSubclassWindow(WinWindowFromID(hwndUserlist, CBID_EDIT),
5607 DropDownListProc);
5608 WinSetWindowPtr(WinWindowFromID(hwndUserlist, CBID_EDIT),
5609 QWL_USER, (PVOID) oldproc);
5610 oldproc = WinSubclassWindow(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5611 DropDownListProc);
5612 WinSetWindowPtr(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5613 QWL_USER, (PVOID) oldproc);
5614 oldproc = WinSubclassWindow(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5615 DropDownListProc);
5616 WinSetWindowPtr(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5617 QWL_USER, (PVOID) oldproc);
5618 oldproc = WinSubclassWindow(WinWindowFromID(hwndStatelist, CBID_EDIT),
5619 DropDownListProc);
5620 WinSetWindowPtr(WinWindowFromID(hwndStatelist, CBID_EDIT),
5621 QWL_USER, (PVOID) oldproc);
5622 oldproc = WinSubclassWindow(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5623 DropDownListProc);
5624 WinSetWindowPtr(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5625 QWL_USER, (PVOID) oldproc);
5626 oldproc = WinSubclassWindow(hwndUserlist, DropDownListProc);
5627 WinSetWindowPtr(hwndUserlist, QWL_USER, (PVOID) oldproc);
5628 oldproc = WinSubclassWindow(hwndCmdlist, DropDownListProc);
5629 WinSetWindowPtr(hwndCmdlist, QWL_USER, (PVOID) oldproc);
5630 oldproc = WinSubclassWindow(hwndStatelist, DropDownListProc);
5631 WinSetWindowPtr(hwndStatelist, QWL_USER, (PVOID) oldproc);
5632 oldproc = WinSubclassWindow(hwndDrivelist, DropDownListProc);
5633 WinSetWindowPtr(hwndDrivelist, QWL_USER, (PVOID) oldproc);
5634 oldproc = WinSubclassWindow(hwndButtonlist, DropDownListProc);
5635 WinSetWindowPtr(hwndButtonlist, QWL_USER, (PVOID) oldproc);
5636 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_USERLIST),
5637 ChildFrameButtonProc);
5638 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_USERLIST),
5639 QWL_USER, (PVOID) oldproc);
5640 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5641 ChildFrameButtonProc);
5642 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5643 QWL_USER, (PVOID) oldproc);
5644 hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
5645 WinSendMsg(hwnd, UM_ADDTOMENU, MPVOID, MPVOID);
5646 SetToggleChecks(hwndMenu);
5647 CfgMenuInit(hwndMenu, FALSE); // 14 Feb 08 SHL
5648 SetConditionalCascade(hwndMenu, IDM_COMMANDLINESUBMENU, IDM_COMMANDLINE);
5649 SetConditionalCascade(hwndMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
5650 SetConditionalCascade(hwndMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
5651 SetConditionalCascade(hwndMenu, IDM_TILEMENU, IDM_TILE);
5652 WinSetWindowULong(hwnd, QWL_USER, hwndMenu);
5653 memset(&mi, 0, sizeof(mi));
5654 memset(&mit, 0, sizeof(mit));
5655 hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
5656 idSysMenu = SHORT1FROMMR(WinSendMsg(hwndSysMenu,
5657 MM_ITEMIDFROMPOSITION,
5658 MPVOID, MPVOID));
5659 WinSendMsg(hwndSysMenu,
5660 MM_QUERYITEM, MPFROM2SHORT(idSysMenu, 0), MPFROMP(&mit));
5661 hwndSysSubMenu = mit.hwndSubMenu;
5662 mi.iPosition = MIT_END;
5663 mi.afStyle = MIS_SEPARATOR;
5664 mi.id = (USHORT) - 1;
5665 WinSendMsg(hwndSysSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(NULL));
5666 mi.afStyle = MIS_TEXT;
5667 mi.id = IDM_IDEALSIZE;
5668 WinSendMsg(hwndSysSubMenu,
5669 MM_INSERTITEM,
5670 MPFROMP(&mi), MPFROMP(GetPString(IDS_IDEALMENUTEXT)));
5671 mi.afStyle = MIS_TEXT;
5672 mi.id = IDM_HIDEMENU;
5673 WinSendMsg(hwndSysSubMenu,
5674 MM_INSERTITEM,
5675 MPFROMP(&mi), MPFROMP(GetPString(IDS_HIDEMENUTEXT)));
5676 SetSysMenu(hwndSysMenu);
5677
5678 size = sizeof(BOOL);
5679 if (PrfQueryProfileData(fmprof,
5680 FM3Str,
5681 "MenuInvisible", &temp, &size) && size && temp)
5682 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HIDEMENU, 0), MPVOID);
5683 size = sizeof(BOOL);
5684 if (PrfQueryProfileData(fmprof,
5685 FM3Str, "FreeTree", &temp, &size) && size && temp)
5686 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_FREETREE, 0), MPVOID);
5687 size = sizeof(BOOL);
5688 if (PrfQueryProfileData(fmprof,
5689 FM3Str,
5690 "AutoTile", &temp, &size) && size && !temp)
5691 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_AUTOTILE, 0), MPVOID);
5692 size = sizeof(BOOL);
5693 if (PrfQueryProfileData(fmprof,
5694 FM3Str, "Toolbar", &temp, &size) && size && !temp)
5695 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TOOLBAR, 0), MPVOID);
5696
5697 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR), "FM/2");
5698 FixSwitchList(hwndFrame, NULL);
5699 break; // WM_CREATE
5700
5701 case UM_SETUP:
5702 /*
5703 * start up some initial children
5704 */
5705 load_tools(NULL);
5706 BuildTools(hwndToolback, TRUE);
5707 WinShowWindow(WinQueryWindow(hwnd, QW_PARENT), TRUE);
5708 PostMsg(MainObjectHwnd, UM_SETUP2, mp1, mp2);
5709 return 0;
5710
5711 case UM_SETUP2:
5712 {
5713 SWP swp;
5714 ULONG size = sizeof(SWP);
5715
5716 WinQueryWindowPos(hwnd, &swp);
5717 hwndTree = StartTreeCnr(hwnd, 4);
5718 if (!hwndTree)
5719 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
5720 else {
5721 if (!fSaveState ||
5722 !PrfQueryProfileData(fmprof,
5723 FM3Str,
5724 "LastTreePos",
5725 &swp, &size) || size != sizeof(SWP)) {
5726
5727 INT ratio, height = 0;
5728
5729 if (!fNoTreeGap)
5730 height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
5731 size = sizeof(ratio);
5732 if (!PrfQueryProfileData(fmprof,
5733 FM3Str,
5734 "TreeWindowRatio",
5735 (PVOID) & ratio,
5736 &size) || size < sizeof(ratio))
5737 ratio = 400;
5738 WinSetWindowPos(hwndTree,
5739 HWND_TOP,
5740 0,
5741 height,
5742 (swp.cx * 100) / ratio,
5743 swp.cy - height,
5744 SWP_SHOW | SWP_SIZE | SWP_MOVE |
5745 SWP_ACTIVATE | SWP_ZORDER);
5746 }
5747 else
5748 WinSetWindowPos(hwndTree,
5749 HWND_TOP,
5750 swp.x,
5751 swp.y,
5752 swp.cx,
5753 swp.cy,
5754 swp.fl | SWP_MOVE | SWP_SIZE | SWP_SHOW |
5755 SWP_ZORDER | SWP_ACTIVATE);
5756 }
5757 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5758 MAIN_TOOLS));
5759 }
5760 PostMsg(MainObjectHwnd, UM_SETUP3, mp1, mp2);
5761 return 0;
5762
5763 case UM_SETUP3:
5764 /* start remaining child windows */
5765 if (!fNoSaveState && fSaveState) {
5766 PSZ pszStatename = GetPString(IDS_SHUTDOWNSTATE);
5767 PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszStatename), MPVOID);
5768 if (!add_setup(pszStatename))
5769 save_setups();
5770 }
5771 PostMsg(MainObjectHwnd, UM_SETUP4, mp1, mp2);
5772 return 0;
5773
5774 case UM_SETUP4:
5775 {
5776 INT argc = (INT) mp1, x;
5777 CHAR **argv = (CHAR **) mp2;
5778
5779 for (x = 1; x < argc; x++) {
5780 if (*argv[x] == '/' || *argv[x] == ';')
5781 continue;
5782 if (!IsFile(argv[x]) && !FindDirCnrByName(argv[x], FALSE))
5783 OpenDirCnr((HWND) 0, hwndMain, hwndTree, TRUE, argv[x]);
5784 }
5785 }
5786 PostMsg(MainObjectHwnd, UM_SETUP5, MPVOID, MPVOID);
5787 return 0;
5788
5789 case UM_SETUP5:
5790// if (fAutoTile)
5791// TileChildren(hwnd, TRUE);
5792 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
5793 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
5794 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5795 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
5796 {
5797 HWND hwndActive;
5798
5799 hwndActive = TopWindow(hwnd, hwndTree);
5800 if (hwndActive)
5801 WinSetWindowPos(hwndActive, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
5802 }
5803 if (fStartMinimized || fReminimize)
5804 PostMsg(hwndTree, UM_MINIMIZE, MPVOID, MPVOID);
5805 else if (fStartMaximized)
5806 PostMsg(hwndTree, UM_MAXIMIZE, MPVOID, MPVOID);
5807 fRunning = TRUE;
5808 if (fWantFirstTimeInit) {
5809 fWantFirstTimeInit = FALSE;
5810 PostMsg(hwnd, WM_COMMAND, MPFROMLONG(IDM_QUICKSETTINGS), MPVOID);
5811 }
5812# ifdef FORTIFY
5813 Fortify_EnterScope();
5814# endif
5815 return 0;
5816 }
5817
5818 return WinDefWindowProc(hwnd, msg, mp1, mp2);
5819}
5820
5821MRESULT EXPENTRY MainWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
5822{
5823 switch (msg) {
5824 case WM_CREATE:
5825 case UM_SETUP:
5826 case UM_SETUP2:
5827 case UM_SETUP3:
5828 case UM_SETUP4:
5829 case UM_SETUP5:
5830 return MainWMOnce(hwnd, msg, mp1, mp2);
5831
5832 case WM_CONTROLPOINTER:
5833 if (!fNoFinger &&
5834 (SHORT1FROMMP(mp1) == IDM_OPENWALK ||
5835 SHORT1FROMMP(mp1) == IDM_USERLIST))
5836 return MRFROMLONG(hptrFinger);
5837 break;
5838
5839 case UM_LOADFILE:
5840 case UM_THREADUSE:
5841 case UM_BUILDDRIVEBAR:
5842 return CommonMainWndProc(hwnd, msg, mp1, mp2);
5843
5844 case WM_BUTTON1UP:
5845 case WM_BUTTON2UP:
5846 case WM_BUTTON3UP:
5847 case WM_MOUSEMOVE:
5848 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
5849 break;
5850
5851 case WM_CHAR:
5852 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
5853 break;
5854
5855 case WM_MENUEND:
5856 if ((HWND) mp2 == MainPopupMenu) {
5857 WinDestroyWindow(MainPopupMenu);
5858 MainPopupMenu = (HWND) 0;
5859 }
5860 break;
5861
5862 case UM_CONTEXTMENU:
5863 case WM_CONTEXTMENU:
5864 if (CheckMenu(hwndMainMenu, &MainPopupMenu, MAIN_POPUP)) {
5865 SetToggleChecks(MainPopupMenu);
5866 PopupMenu(hwnd, hwnd, MainPopupMenu);
5867 }
5868 if (msg == UM_CONTEXTMENU)
5869 return 0;
5870 return MRFROMSHORT(TRUE);
5871
5872 case UM_SETUSERLISTNAME:
5873 if (mp1) {
5874 if (fUserComboBox)
5875 WinSetWindowText(WinWindowFromID(hwndUserlist, CBID_EDIT),
5876 (CHAR *)mp1);
5877 if (add_udir(FALSE, (CHAR *)mp1)) {
5878 if (fUserComboBox && fAutoAddDirs) {
5879 WinSendMsg(hwndUserlist, LM_INSERTITEM,
5880 MPFROM2SHORT(LIT_SORTASCENDING, 0),
5881 MPFROMP((CHAR *)mp1));
5882 }
5883 }
5884 }
5885 return 0;
5886
5887 case UM_ARRANGEICONS:
5888 ArrangeIcons(hwnd);
5889 return 0;
5890
5891 case WM_CHORD:
5892 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
5893 break;
5894
5895 case WM_SETFOCUS:
5896 if (mp2)
5897 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
5898 break;
5899
5900 case UM_FOCUSME:
5901 WinSetFocus(hwndTree, TRUE);
5902 return 0;
5903
5904 case UM_RESCAN:
5905 TileChildren(hwnd, TRUE);
5906 return 0;
5907
5908 case WM_SAVEAPPLICATION:
5909 {
5910 SWP swp;
5911
5912 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
5913 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
5914 WinStoreWindowPos(FM2Str,
5915 "MainWindowPos", WinQueryWindow(hwnd, QW_PARENT));
5916 if (!fNoSaveState && fSaveState)
5917 SaveDirCnrState(hwnd, GetPString(IDS_SHUTDOWNSTATE));
5918 }
5919 }
5920 break;
5921
5922 case MM_PORTHOLEINIT:
5923 switch (SHORT1FROMMP(mp1)) {
5924 case 0:
5925 case 1:
5926 {
5927 HWND hwndCurrent;
5928 ULONG wmsg;
5929
5930 wmsg = (SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU;
5931 hwndCurrent = TopWindow(hwnd, (HWND) 0);
5932 PortholeInit((HWND) WinSendMsg(WinWindowFromID(hwndCurrent,
5933 FID_CLIENT), wmsg,
5934 MPVOID, MPVOID), mp1, mp2);
5935 }
5936 break;
5937 }
5938 break;
5939
5940 case WM_INITMENU:
5941 switch (SHORT1FROMMP(mp1)) {
5942 case IDM_CONFIGMENU:
5943 SetToggleChecks((HWND) WinQueryWindowULong(hwnd, QWL_USER));
5944 break;
5945
5946 case IDM_WINDOWSMENU:
5947 /*
5948 * add child windows of client
5949 * and switchlist entries to end of pulldown menu
5950 */
5951 {
5952 HWND hwndMenu, hwndSubMenu;
5953 MENUITEM mi;
5954
5955 hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
5956 memset(&mi, 0, sizeof(mi));
5957 mi.iPosition = MIT_END;
5958 mi.afStyle = MIS_TEXT;
5959 if (!WinSendMsg(hwndMenu, MM_QUERYITEM,
5960 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
5961 break;
5962 hwndSubMenu = mi.hwndSubMenu;
5963 SetupWinList(hwndSubMenu, hwnd, WinQueryWindow(hwnd, QW_PARENT));
5964 }
5965 break;
5966
5967 default:
5968 {
5969 HWND hwndCurrent;
5970
5971 hwndCurrent = TopWindow(hwnd, (HWND) 0);
5972 if (hwndCurrent)
5973 WinSendMsg(hwndCurrent, UM_INITMENU, mp1, mp2);
5974 }
5975 break;
5976 }
5977 break;
5978
5979 case UM_ADDTOMENU:
5980 AddToMenu((CHAR *)mp1, WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5981 FID_MENU));
5982 return 0;
5983
5984 case UM_FILLCMDLIST:
5985 WinSendMsg(hwndCmdlist, LM_DELETEALL, MPVOID, MPVOID);
5986 if (!cmdloaded)
5987 load_commands();
5988 if (cmdhead) {
5989
5990 LINKCMDS *info;
5991
5992 info = cmdhead;
5993 while (info) {
5994 WinSendMsg(hwndCmdlist, LM_INSERTITEM,
5995 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->title));
5996 info = info->next;
5997 }
5998 }
5999 return 0;
6000
6001 case UM_FILLSETUPLIST:
6002 fill_setups_list();
6003 return 0;
6004
6005 case UM_FILLBUTTONLIST:
6006 WinSendMsg(hwndButtonlist, LM_DELETEALL, MPVOID, MPVOID);
6007 if (fUserComboBox) {
6008
6009 BOOL foundit = FALSE, thisone;
6010 ULONG ulSearchCount;
6011 SHORT sSelect;
6012 FILEFINDBUF3 findbuf;
6013 HDIR hDir;
6014 CHAR *p;
6015
6016 DosError(FERR_DISABLEHARDERR);
6017 hDir = HDIR_CREATE;
6018 ulSearchCount = 1;
6019 if (!DosFindFirst("*.TLS", &hDir, FILE_READONLY | FILE_ARCHIVED,
6020 &findbuf, sizeof(FILEFINDBUF3),
6021 &ulSearchCount, FIL_STANDARD)) {
6022 do {
6023 priority_bumped();
6024 if (!foundit) {
6025 thisone = FALSE;
6026 p = strrchr(lasttoolbox, '\\');
6027 if (!p)
6028 p = lasttoolbox;
6029 else
6030 p++;
6031 if (!stricmp(findbuf.achName, p))
6032 thisone = TRUE;
6033 }
6034 p = strrchr(findbuf.achName, '.');
6035 if (p)
6036 *p = 0;
6037 sSelect = (SHORT) WinSendMsg(hwndButtonlist, LM_INSERTITEM,
6038 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6039 MPFROMP(findbuf.achName));
6040 if (!foundit && thisone && sSelect >= 0) {
6041 WinSendMsg(hwndButtonlist, LM_SELECTITEM,
6042 MPFROM2SHORT(sSelect, 0), MPFROMLONG(TRUE));
6043 foundit = TRUE;
6044 }
6045 }
6046 while (!DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3),
6047 &ulSearchCount));
6048 DosFindClose(hDir);
6049 priority_bumped();
6050 }
6051 WinSetWindowText(hwndButtonlist, GetPString(IDS_TOOLBOXTEXT));
6052 }
6053 return 0;
6054
6055 case UM_FILLUSERLIST:
6056 WinSendMsg(hwndUserlist, LM_DELETEALL, MPVOID, MPVOID);
6057 if (fUserComboBox) {
6058 ULONG ulDriveNum;
6059 ULONG ulDriveMap;
6060 ULONG ulSearchCount;
6061 FILEFINDBUF3 findbuf;
6062 HDIR hDir;
6063 APIRET rc;
6064 LINKDIRS *info;
6065 LINKDIRS *temp;
6066
6067 if (!loadedudirs)
6068 load_udirs();
6069 DosError(FERR_DISABLEHARDERR);
6070 DosQCurDisk(&ulDriveNum, &ulDriveMap);
6071 info = udirhead;
6072 while (info) {
6073 if (IsFullName(info->path) &&
6074 !(driveflags[toupper(*info->path) - 'A'] &
6075 (DRIVE_IGNORE | DRIVE_INVALID))) {
6076 DosError(FERR_DISABLEHARDERR);
6077 hDir = HDIR_CREATE;
6078 ulSearchCount = 1;
6079 if (!IsRoot(info->path))
6080 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6081 MUST_HAVE_DIRECTORY | FILE_READONLY |
6082 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6083 &findbuf, sizeof(FILEFINDBUF3),
6084 &ulSearchCount, FIL_STANDARD);
6085 else {
6086 rc = 0;
6087 findbuf.attrFile = FILE_DIRECTORY;
6088 }
6089 priority_bumped();
6090 if (!rc) {
6091 if (!IsRoot(info->path))
6092 DosFindClose(hDir);
6093 if (findbuf.attrFile & FILE_DIRECTORY)
6094 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6095 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6096 MPFROMP(info->path));
6097 else {
6098 temp = info->next;
6099 remove_udir(info->path);
6100 info = temp;
6101 continue;
6102 }
6103 }
6104 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6105 temp = info->next;
6106 remove_udir(info->path);
6107 info = temp;
6108 continue;
6109 }
6110 }
6111 info = info->next;
6112 }
6113 info = ldirhead;
6114 while (info) {
6115 if (IsFullName(info->path) &&
6116 !(driveflags[toupper(*info->path) - 'A'] &
6117 (DRIVE_IGNORE | DRIVE_INVALID))) {
6118 DosError(FERR_DISABLEHARDERR);
6119 hDir = HDIR_CREATE;
6120 ulSearchCount = 1;
6121 if (!IsRoot(info->path))
6122 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6123 MUST_HAVE_DIRECTORY | FILE_READONLY |
6124 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6125 &findbuf, sizeof(FILEFINDBUF3),
6126 &ulSearchCount, FIL_STANDARD);
6127 else {
6128 rc = 0;
6129 findbuf.attrFile = FILE_DIRECTORY;
6130 }
6131 priority_bumped();
6132 if (!rc) {
6133 if (!IsRoot(info->path))
6134 DosFindClose(hDir);
6135 if (findbuf.attrFile & FILE_DIRECTORY)
6136 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6137 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6138 MPFROMP(info->path));
6139 else {
6140 temp = info->next;
6141 remove_udir(info->path);
6142 info = temp;
6143 continue;
6144 }
6145 }
6146 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6147 temp = info->next;
6148 remove_udir(info->path);
6149 info = temp;
6150 continue;
6151 }
6152 }
6153 info = info->next;
6154 }
6155 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6156 MPFROM2SHORT(0, 0),
6157 MPFROMP(GetPString(IDS_NEWDIRECTORYTEXT)));
6158 WinSetWindowText(hwndUserlist, GetPString(IDS_COMMONDIRTEXT));
6159 }
6160 return 0;
6161
6162 case UM_SIZE:
6163 if (fAutoTile)
6164 TileChildren(hwnd, FALSE);
6165 else
6166 MoveChildrenAwayFromTree(hwnd);
6167 return 0;
6168
6169 case WM_SIZE:
6170 ResizeChildren(hwnd, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),
6171 SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
6172 break;
6173
6174 case WM_ERASEBACKGROUND:
6175 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
6176 return 0;
6177
6178 case WM_PAINT:
6179 {
6180 HPS hps;
6181 RECTL rcl;
6182
6183 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
6184 if (hps) {
6185 WinQueryWindowRect(hwnd, &rcl);
6186 WinFillRect(hps, &rcl, CLR_PALEGRAY);
6187 WinEndPaint(hps);
6188 }
6189 }
6190 break;
6191
6192 case UM_CONTROL:
6193 switch (SHORT1FROMMP(mp1)) {
6194 case MAIN_CMDLIST:
6195 case MAIN_SETUPLIST:
6196 case MAIN_DRIVELIST:
6197 case MAIN_USERLIST:
6198 case MAIN_BUTTONLIST:
6199 switch (SHORT2FROMMP(mp1)) {
6200 case CBN_ENTER:
6201 {
6202 HWND hwndUL = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
6203 SHORT1FROMMP(mp1));
6204 CHAR path[CCHMAXPATH];
6205 ULONG ul;
6206
6207 switch (SHORT1FROMMP(mp1)) {
6208 case MAIN_USERLIST:
6209 ul = CCHMAXPATH;
6210 break;
6211 case MAIN_SETUPLIST:
6212 ul = STATE_NAME_MAX_BYTES;
6213 break;
6214 default:
6215 ul = 13; // fixme to not be hardcoded
6216 }
6217
6218 SetShiftState();
6219 WinQueryWindowText(WinWindowFromID(hwndUL, CBID_EDIT), ul, path);
6220 bstrip(path);
6221 if (*path) {
6222 if (SHORT1FROMMP(mp1) == MAIN_USERLIST) {
6223 if (!strcmp(path, GetPString(IDS_NEWDIRECTORYTEXT))) {
6224 if (!LastDir ||
6225 !WinSendMsg(WinQueryWindow(LastDir, QW_PARENT),
6226 UM_CONTAINERDIR, MPFROMP(path), MPVOID))
6227 save_dir2(path);
6228 if (!PMMkDir(hwnd, path, TRUE)) {
6229 WinSetWindowText(hwndUL, GetPString(IDS_COMMONDIRTEXT));
6230 break;
6231 }
6232 }
6233 if (!IsFile(path) && !FindDirCnrByName(path, TRUE)) {
6234
6235 HWND hwndDir;
6236
6237 if ((fUserListSwitches &&
6238 !(shiftstate & KC_SHIFT)) ||
6239 (!fUserListSwitches && (shiftstate & KC_SHIFT))) {
6240 hwndDir = FindDirCnr(hwnd);
6241 if (hwndDir) {
6242 WinSendMsg(LastDir, UM_SETDIR, MPFROMP(path), MPVOID);
6243 break;
6244 }
6245 }
6246 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, path);
6247 }
6248 }
6249 else if (SHORT1FROMMP(mp1) == MAIN_DRIVELIST) {
6250 ShowTreeRec(WinWindowFromID(WinWindowFromID(hwndTree,
6251 FID_CLIENT),
6252 TREE_CNR), path, FALSE, TRUE);
6253 WinSetFocus(HWND_DESKTOP, hwndTree);
6254 }
6255 else if (SHORT1FROMMP(mp1) == MAIN_BUTTONLIST) {
6256 strcat(path, ".TLS");
6257 load_tools(path);
6258 PrfWriteProfileString(fmprof,
6259 FM3Str, "LastToolBox", lasttoolbox);
6260 BuildTools(hwndToolback, TRUE);
6261 WinSetWindowText(hwndButtonlist, GetPString(IDS_TOOLBOXTEXT));
6262 }
6263 else if (SHORT1FROMMP(mp1) == MAIN_SETUPLIST) {
6264 CHAR szKey[80];
6265 ULONG size, numsaves = 0;
6266
6267 SetShiftState();
6268 size = sizeof(ULONG);
6269 sprintf(szKey, "%s.NumDirsLastTime", path); // path is state name
6270 if (!PrfQueryProfileData(fmprof,
6271 FM3Str,
6272 szKey,
6273 (PVOID)&numsaves,
6274 &size))
6275 {
6276 if ((WinGetLastError(WinQueryAnchorBlock(hwnd)) & 0xffff) == PMERR_NOT_IN_IDX) {
6277 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
6278 GetPString(IDS_WARNINGTEXT),
6279 GetPString(IDS_DOESNTEXISTTEXT), path);
6280 }
6281 else {
6282 Win_Error2(hwnd, hwnd, __FILE__, __LINE__,
6283 IDS_PRFQUERYPROFILEDATA);
6284 }
6285 }
6286 else {
6287 char *pszStateName;
6288 if ((shiftstate & KC_SHIFT) == 0)
6289 PostMsg(MainObjectHwnd, UM_RESTORE, MPVOID, MPFROMLONG(2));
6290 pszStateName = xstrdup(path, pszSrcFile, __LINE__);
6291 if (!pszStateName) {
6292 // Fall back if out of memory - already complained
6293 if ((shiftstate & KC_SHIFT) != 0 || fAutoTile) {
6294 // Autotile requested or forced
6295 PostMsg(MainObjectHwnd,
6296 UM_RESTORE,
6297 MPVOID,
6298 MPFROMLONG(1)); // Autotile
6299 }
6300 }
6301 else if (!PostMsg(MainObjectHwnd,
6302 UM_RESTORE,
6303 MPFROMP(pszStateName),
6304 MPVOID)) {
6305 free(pszStateName);
6306 }
6307 }
6308 }
6309 else if (SHORT1FROMMP(mp1) == MAIN_CMDLIST) {
6310
6311 SHORT sSelect;
6312
6313 sSelect = (SHORT) WinSendMsg(hwndCmdlist,
6314 LM_QUERYSELECTION,
6315 MPFROMSHORT(LIT_FIRST), MPVOID);
6316 if (sSelect >= 0)
6317 WinPostMsg(hwnd,
6318 WM_COMMAND,
6319 MPFROM2SHORT(IDM_COMMANDSTART + sSelect, 0),
6320 MPVOID);
6321 WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
6322 }
6323 }
6324 }
6325 break;
6326
6327 default:
6328 break;
6329 }
6330 break;
6331
6332 default:
6333 break;
6334 }
6335 return 0;
6336
6337 case WM_HELP:
6338 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
6339 break;
6340
6341 case UM_COMMAND:
6342 case WM_COMMAND:
6343
6344 return MainWMCommand(hwnd, msg, mp1, mp2);
6345
6346 case WM_CLOSE:
6347 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6348 WM_SYSCOMMAND, MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
6349 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
6350 fAmClosing = TRUE;
6351 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6352 WM_SYSCOMMAND, MPFROM2SHORT(SC_MINIMIZE, 0), MPVOID);
6353 if (CloseChildren(hwnd)) {
6354 fAmClosing = FALSE;
6355 if (fAutoTile)
6356 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TILE, 0), MPVOID);
6357 return 0;
6358 }
6359 if (hwndTree) {
6360 if (!PostMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID))
6361 WinSendMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID);
6362 }
6363 DosSleep(1);
6364 return 0; // Hold off WM_QUIT
6365
6366 case UM_CLOSE:
6367 HideNote();
6368 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
6369 return 0;
6370
6371 case UM_RESTORE:
6372 {
6373 // Try to restore saved shutdown state
6374 char *pszDefaultStateName = xstrdup(GetPString(IDS_SHUTDOWNSTATE),
6375 pszSrcFile, __LINE__);
6376 if (pszDefaultStateName) {
6377 if (!PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszDefaultStateName), MPVOID))
6378 // 05 Feb 08 SHL fixme to complain?
6379 free(pszDefaultStateName);
6380 }
6381 }
6382 return 0;
6383
6384 case UM_SETDIR:
6385 /* mp1 == name of directory to open */
6386 if (mp1)
6387 return MRFROMLONG(OpenDirCnr((HWND) 0,
6388 hwndMain,
6389 hwndTree, (BOOL) mp2, (char *)mp1));
6390 return 0;
6391
6392 case WM_DESTROY:
6393 hwndMain = (HWND) 0;
6394 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
6395 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
6396# ifdef FORTIFY
6397 free_commands();
6398 free_associations();
6399 free_udirs();
6400 free_ldir();
6401 free_archivers();
6402 free_tools();
6403 Fortify_LeaveScope();
6404# endif
6405 break;
6406 }
6407 return WinDefWindowProc(hwnd, msg, mp1, mp2);
6408}
6409
6410VOID DeletePresParams(CHAR * pchKeyroot)
6411// This code assumes that pchKeyroot points to a buffer large enough to
6412// hold the full INI key: The state name.dircnr-number.PPName. The
6413// PPNames are listed below.
6414{
6415 PSZ apszPPNames[] =
6416 {
6417 "Backgroundcolor",
6418 "Foregroundcolor",
6419 "Hilitebackgroundcolor",
6420 "Hiliteforegroundcolor",
6421 "Bordercolor",
6422 "Fontnamesize"
6423 };
6424
6425 ULONG ulSize, ulArraySize = sizeof(apszPPNames) / sizeof(PSZ), x;
6426 CHAR * eos = pchKeyroot + strlen(pchKeyroot);
6427
6428 for (x = 0; x < ulArraySize; x++)
6429 {
6430 strcpy(eos, apszPPNames[x]);
6431 if (PrfQueryProfileSize(fmprof, appname, pchKeyroot, &ulSize) && ulSize)
6432 {
6433 PrfWriteProfileData(fmprof, appname, pchKeyroot, NULL, ulSize);
6434 }
6435 }
6436}
6437
6438#pragma alloc_text(MISC8,SetToggleChecks,FindDirCnrByName,TopWindow)
6439#pragma alloc_text(MISC8,TopWindowName,CountDirCnrs)
6440#pragma alloc_text(MAINWND,AdjustSizeOfClient,FillClient,ChildButtonProc)
6441#pragma alloc_text(MAINWND,ToolBackProc,StatusProc)
6442#pragma alloc_text(MAINWND,MoveChildrenAwayFromTree,ArrangeIcons,NextChild)
6443#pragma alloc_text(MAINWND,ChildFrameButtonProc)
6444#pragma alloc_text(MAINWND2,CloseChildren,CountChildren,GetNextWindowPos)
6445#pragma alloc_text(MAINWND2,CascadeChildren,TileChildren,ResizeChildren)
6446#pragma alloc_text(MAINWND2,MinResChildren,MainFrameWndProc,MainWndProc)
6447#pragma alloc_text(MAINWND2,DropDownListProc)
6448#pragma alloc_text(MAINWND3,RestoreDirCnrState,SaveDirCnrState)
6449#pragma alloc_text(MAINWND3,CloseDirCnrChildren,TransformSwp)
6450#pragma alloc_text(MAINWND3,ResizeTools,BuildTools,CommandLineProc)
6451#pragma alloc_text(MAINWND4,DriveProc,DriveBackProc,BuildDriveBarButtons,ResizeDrives)
6452#pragma alloc_text(MAINWND4,LEDProc,IdealButtonProc)
6453#pragma alloc_text(MAINWND5,MainWMOnce)
6454#pragma alloc_text(MAINWND6,MainWMCommand)
6455#pragma alloc_text(BUBBLE,MakeBubble,BubbleProc,BubbleHelp)
6456#pragma alloc_text(MAINOBJ,MainObjectWndProc,MakeMainObjWin)
6457
Note: See TracBrowser for help on using the repository browser.