source: trunk/dll/mainwnd.c@ 1120

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

Set default color for toolbar when no presprams exist Ticket 258

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