source: trunk/dll/mainwnd.c@ 1060

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

Ticket 242: Ensure that obsolete INI keys are deleted when re-saving
a directory container state with fewer open windows than those in the
previous state.

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