source: trunk/dll/mainwnd.c@ 1063

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

Fortify ifdef reformat

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