source: trunk/dll/mainwnd.c@ 1121

Last change on this file since 1121 was 1121, checked in by Gregg Young, 17 years ago

Require unique ID plus text and help strings for all tools save toolbar on button delete. (Tickets 264, 266 & 272)

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