source: trunk/dll/mainwnd.c@ 1104

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

Replace save_dir2(dir) with strcpy(dir, pFM2SaveDirectory)

  • 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 1104 2008-08-02 20:33:03Z 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;
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 WinQueryWindowRect(hwnd, &rcl);
2534 WinFillRect(hps, &rcl, lColor);
2535 WinEndPaint(hps);
2536 }
2537
2538 }
2539 break;
2540
2541 case WM_PRESPARAMCHANGED:
2542 PresParamChanged(hwnd, "ToolBar", mp1, mp2);
2543 WinInvalidateRect(hwnd, NULL, TRUE);
2544 break;
2545
2546 case UM_SETUP:
2547 {
2548 USHORT id;
2549 TOOL *tool;
2550
2551 id = SHORT1FROMMP(mp1);
2552 tool = find_tool(id);
2553 if (tool) {
2554 del_tool(tool);
2555 WinShowWindow(WinWindowFromID(hwnd, id), FALSE);
2556 if (fToolTitles)
2557 WinShowWindow(WinWindowFromID(hwnd, id + 25000), FALSE);
2558 ResizeTools(hwnd);
2559 }
2560 }
2561 return 0;
2562
2563 case WM_CHORD:
2564 {
2565 USHORT id;
2566
2567 id = (USHORT) WinDlgBox(HWND_DESKTOP,
2568 hwnd,
2569 AddToolProc,
2570 FM3ModHandle, ADDBTN_FRAME, MPVOID);
2571 if (id && id != (USHORT) - 1)
2572 WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2573 FID_CLIENT),
2574 WM_COMMAND,
2575 MPFROM2SHORT(IDM_CREATETOOL, 0), MPFROM2SHORT(id, 0));
2576 }
2577 break;
2578
2579 case WM_CONTEXTMENU:
2580 if (WinDlgBox(HWND_DESKTOP,
2581 hwnd, ToolIODlgProc, FM3ModHandle, SVBTN_FRAME, MPVOID))
2582 BuildTools(hwnd, TRUE);
2583 return MRFROMSHORT(TRUE);
2584
2585 case WM_CLOSE:
2586 WinDestroyWindow(hwnd);
2587 return 0;
2588
2589 case WM_DESTROY:
2590 break;
2591 }
2592 return WinDefWindowProc(hwnd, msg, mp1, mp2);
2593}
2594
2595static VOID AdjustSizeOfClient(PSWP pswp, PRECTL prectl)
2596{
2597 SWP swp;
2598 RECTL rectl;
2599
2600 if (fFreeTree)
2601 return;
2602 if (pswp) {
2603 if (WinQueryWindowPos(hwndTree, &swp) &&
2604 !(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE))) {
2605 pswp->x = swp.cx;
2606 pswp->cx -= swp.cx;
2607 }
2608 }
2609 if (prectl) {
2610 if (WinQueryWindowPos(hwndTree, &swp) &&
2611 !(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE)) &&
2612 WinQueryWindowRect(hwndTree, &rectl)) {
2613 prectl->xLeft = rectl.xRight;
2614 prectl->xRight -= rectl.xRight;
2615 }
2616 }
2617}
2618
2619VOID FillClient(HWND hwndClient, PSWP pswp, PRECTL prectl, BOOL avoidtree)
2620{
2621 ULONG adjust;
2622
2623 adjust = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
2624 if (pswp)
2625 WinQueryWindowPos(hwndClient, pswp);
2626 if (prectl)
2627 WinQueryWindowRect(hwndClient, prectl);
2628 if (avoidtree && !fFreeTree)
2629 AdjustSizeOfClient(pswp, prectl);
2630 if (prectl)
2631 prectl->yBottom += adjust;
2632 if (pswp) {
2633 if (!avoidtree || fFreeTree)
2634 pswp->x = 0;
2635 pswp->y = adjust;
2636 if (pswp->cy >= adjust)
2637 pswp->cy -= adjust;
2638 else
2639 pswp->cy = 0;
2640 }
2641}
2642
2643static VOID MoveChildrenAwayFromTree(HWND hwndClient)
2644{
2645 SWP swpC, swpT, swp;
2646 USHORT id;
2647 HWND hwndChild;
2648 HENUM henum;
2649
2650 if (fFreeTree)
2651 return;
2652 WinQueryWindowPos(hwndClient, &swpC);
2653 if (swpC.fl & (SWP_MINIMIZE | SWP_HIDE))
2654 return;
2655 WinQueryWindowPos(hwndTree, &swpT);
2656 henum = WinBeginEnumWindows(hwndClient);
2657 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2658 id = WinQueryWindowUShort(hwndChild, QWS_ID);
2659 if (!id || id == TREE_FRAME)
2660 continue;
2661 WinQueryWindowPos(hwndChild, &swp);
2662 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
2663 if (swp.x < swpT.cx) {
2664 swp.x = swpT.cx;
2665 if (swp.x + swp.cx > swpC.cx)
2666 swp.cx = swpC.cx - swp.x;
2667 if (swp.cx > 24)
2668 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
2669 SWP_SIZE | SWP_MOVE | SWP_SHOW);
2670 }
2671 }
2672 }
2673 WinEndEnumWindows(henum);
2674}
2675
2676static VOID ArrangeIcons(HWND hwndClient)
2677{
2678 HENUM henum;
2679 HWND hwndChild;
2680 SWP swp;
2681
2682 henum = WinBeginEnumWindows(hwndClient);
2683 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2684 WinQueryWindowPos(hwndChild, &swp);
2685 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
2686 WinSetWindowUShort(hwndChild, QWS_XMINIMIZE, (USHORT) - 1);
2687 WinSetWindowUShort(hwndChild, QWS_YMINIMIZE, (USHORT) - 1);
2688 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0,
2689 SWP_MOVE | SWP_SHOW | SWP_FOCUSDEACTIVATE);
2690 }
2691 }
2692 WinEndEnumWindows(henum);
2693}
2694
2695static VOID NextChild(HWND hwndClient, BOOL previous)
2696{
2697 HENUM henum;
2698 HWND hwndActive, hwndNext, hwndPrev = (HWND) 0;
2699 BOOL next = FALSE, once = FALSE;
2700
2701 previous = !previous;
2702
2703 hwndActive = WinQueryActiveWindow(hwndClient);
2704 if (!hwndActive)
2705 next = TRUE;
2706 henum = WinBeginEnumWindows(hwndClient);
2707 for (;;) {
2708 hwndNext = WinGetNextWindow(henum);
2709 if (hwndNext) {
2710 if (!WinQueryWindowUShort(hwndNext, QWS_ID))
2711 continue;
2712 if (next)
2713 break;
2714 if (hwndNext == hwndActive) {
2715 if (!previous && hwndPrev) {
2716 hwndNext = hwndPrev;
2717 break;
2718 }
2719 else if (previous)
2720 next = TRUE;
2721 }
2722 hwndPrev = hwndNext;
2723 }
2724 else {
2725 if ((!next && previous) || once)
2726 break;
2727 else if (!previous) {
2728 hwndNext = hwndPrev;
2729 break;
2730 }
2731 else
2732 once = next = TRUE;
2733 }
2734 }
2735 WinEndEnumWindows(henum);
2736
2737 if (hwndNext && hwndNext != hwndActive) {
2738 WinSetWindowPos(hwndNext, HWND_TOP, 0, 0, 0, 0,
2739 SWP_ZORDER | SWP_ACTIVATE);
2740 WinSetWindowPos(hwndActive, ((previous) ? HWND_BOTTOM : hwndNext), 0, 0,
2741 0, 0, SWP_ZORDER);
2742 }
2743}
2744
2745BOOL CloseChildren(HWND hwndClient)
2746{
2747 HENUM henum;
2748 HWND hwndChild;
2749 BOOL ret = FALSE;
2750
2751 fNoTileUpdate = TRUE;
2752 henum = WinBeginEnumWindows(hwndClient);
2753 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2754 if (hwndChild != hwndTree) {
2755 WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2756 WM_SAVEAPPLICATION, MPVOID, MPVOID);
2757 if (WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2758 WM_CLOSE, MPVOID, MPVOID)) {
2759 ret = TRUE;
2760 break;
2761 }
2762 }
2763 }
2764 WinEndEnumWindows(henum);
2765 fNoTileUpdate = FALSE;
2766 return ret;
2767}
2768
2769BOOL CloseDirCnrChildren(HWND hwndClient)
2770{
2771 /* returns TRUE if a directory container window was told to close */
2772
2773 HENUM henum;
2774 HWND hwndChild, hwndDir, hwndTemp;
2775 BOOL ret = FALSE;
2776
2777 fNoTileUpdate = TRUE;
2778 henum = WinBeginEnumWindows(hwndClient);
2779 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2780 if (hwndChild != hwndTree) {
2781 hwndTemp = WinWindowFromID(hwndChild, FID_CLIENT);
2782 if (hwndTemp) {
2783 hwndDir = WinWindowFromID(hwndTemp, DIR_CNR);
2784 if (hwndDir) {
2785 WinSendMsg(WinWindowFromID(hwndChild, FID_CLIENT),
2786 WM_CLOSE, MPVOID, MPVOID);
2787 ret = TRUE;
2788 }
2789 }
2790 }
2791 }
2792 WinEndEnumWindows(henum);
2793 fNoTileUpdate = FALSE;
2794 return ret;
2795}
2796
2797/** Save directory container state
2798 * @param hwndClient Client window handle
2799 * @param pszStateName State name to save, NULL to save global state
2800 * @returns Number of directory container windows that were saved or -1 if error
2801 * @seealso RestoreDirCnrState
2802 */
2803
2804#define STATE_NAME_MAX_BYTES 256
2805
2806INT SaveDirCnrState(HWND hwndClient, PSZ pszStateName)
2807{
2808 HENUM henum;
2809 HWND hwndChild, hwndDir, hwndC;
2810 ULONG numsaves = 0, flWindowAttr;
2811 ULONG previous_numsaves, ulTemp = sizeof(ULONG);
2812 CHAR szPrefix[STATE_NAME_MAX_BYTES + 1];
2813 CHAR szKey[STATE_NAME_MAX_BYTES + 80];
2814 CHAR szDir[CCHMAXPATH];
2815 SWP swp;
2816 DIRCNRDATA *dcd;
2817 BOOL fIsShutDownState;
2818
2819 if (!pszStateName || !*pszStateName) {
2820 Runtime_Error(pszSrcFile, __LINE__, "no data");
2821 return -1;
2822 }
2823 if (strlen(pszStateName) > sizeof(szPrefix) - 2) {
2824 Runtime_Error(pszSrcFile, __LINE__, "SaveDirCnrState");
2825 return -1;
2826 }
2827
2828 fIsShutDownState = strcmp(pszStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0;
2829 sprintf(szPrefix, "%s.", pszStateName);
2830
2831 henum = WinBeginEnumWindows(hwndClient);
2832 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2833 if (hwndChild != hwndTree) {
2834 hwndC = WinWindowFromID(hwndChild, FID_CLIENT);
2835 if (hwndC) {
2836 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
2837 if (hwndDir) {
2838 WinQueryWindowPos(hwndChild, &swp);
2839 *szDir = 0;
2840 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(szDir), MPVOID);
2841 if (*szDir) {
2842 // If saving shutdown state skip no prescan drives
2843 if (fIsShutDownState &&
2844 driveflags[toupper(*szDir) - 'A'] & DRIVE_NOPRESCAN) {
2845 continue;
2846 }
2847 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, numsaves);
2848 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp,
2849 sizeof(SWP));
2850 dcd =
2851 WinQueryWindowPtr(WinWindowFromID(hwndC, DIR_CNR), QWL_USER);
2852 if (dcd) {
2853 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, numsaves);
2854 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->sortFlags,
2855 sizeof(INT));
2856 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, numsaves);
2857 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->mask,
2858 sizeof(MASK));
2859 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, numsaves);
2860 flWindowAttr = dcd->flWindowAttr;
2861 if (!fLeaveTree && (flWindowAttr & CV_TREE)) {
2862 flWindowAttr &= (~(CV_TREE | CV_ICON | CV_DETAIL | CV_TEXT));
2863 if (dcd->lastattr) {
2864 if (dcd->lastattr & CV_TEXT)
2865 flWindowAttr |= CV_TEXT;
2866 else if (dcd->lastattr & CV_DETAIL)
2867 flWindowAttr |= CV_DETAIL;
2868 else if (dcd->lastattr & CV_ICON)
2869 flWindowAttr |= CV_ICON;
2870 else
2871 flWindowAttr |= CV_NAME;
2872 }
2873 else
2874 flWindowAttr |= CV_NAME;
2875 }
2876 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & flWindowAttr,
2877 sizeof(ULONG));
2878 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, numsaves);
2879 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslongname,
2880 sizeof(BOOL));
2881 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, numsaves);
2882 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailssubject,
2883 sizeof(BOOL));
2884 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, numsaves);
2885 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailssize,
2886 sizeof(BOOL));
2887 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, numsaves);
2888 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsea,
2889 sizeof(BOOL));
2890 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, numsaves);
2891 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsattr,
2892 sizeof(BOOL));
2893 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, numsaves);
2894 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsicon,
2895 sizeof(BOOL));
2896 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, numsaves);
2897 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslwdate,
2898 sizeof(BOOL));
2899 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, numsaves);
2900 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslwtime,
2901 sizeof(BOOL));
2902 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, numsaves);
2903 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailsladate,
2904 sizeof(BOOL));
2905 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, numsaves);
2906 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailslatime,
2907 sizeof(BOOL));
2908 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, numsaves);
2909 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailscrdate,
2910 sizeof(BOOL));
2911 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, numsaves);
2912 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & dcd->ds.detailscrtime,
2913 sizeof(BOOL));
2914 sprintf(szKey, "%sDirCnr.%lu", szPrefix, numsaves);
2915 SavePresParams(hwndDir, szKey);
2916 }
2917 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, numsaves++);
2918 PrfWriteProfileString(fmprof, FM3Str, szKey, szDir);
2919 }
2920 }
2921 }
2922 }
2923 } // while
2924 WinEndEnumWindows(henum);
2925
2926 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
2927 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &previous_numsaves, &ulTemp))
2928 for (ulTemp = numsaves; ulTemp < previous_numsaves; ulTemp++) {
2929 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, ulTemp);
2930 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(SWP));
2931 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, ulTemp);
2932 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(INT));
2933 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, ulTemp);
2934 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(MASK));
2935 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, ulTemp);
2936 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(ULONG));
2937 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, ulTemp);
2938 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2939 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, ulTemp);
2940 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2941 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, ulTemp);
2942 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2943 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, ulTemp);
2944 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2945 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, ulTemp);
2946 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2947 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, ulTemp);
2948 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2949 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, ulTemp);
2950 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2951 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, ulTemp);
2952 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2953 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, ulTemp);
2954 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2955 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, ulTemp);
2956 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2957 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, ulTemp);
2958 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2959 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, ulTemp);
2960 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, sizeof(BOOL));
2961 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, ulTemp);
2962 PrfWriteProfileString(fmprof, FM3Str, szKey, NULL);
2963 sprintf(szKey, "%sDirCnr.%lu.", szPrefix, ulTemp);
2964 DeletePresParams(szKey);
2965 }
2966 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
2967 if (numsaves) {
2968 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & numsaves, sizeof(ULONG));
2969 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swp);
2970 sprintf(szKey, "%sMySizeLastTime", szPrefix);
2971 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, sizeof(SWP));
2972 if (WinQueryWindowPos(hwndTree, &swp)) {
2973 sprintf(szKey, "%sLastTreePos", szPrefix);
2974 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, sizeof(SWP));
2975 }
2976 }
2977 else if (fIsShutDownState) {
2978 PrfWriteProfileData(fmprof, FM3Str, szKey, (PVOID) & numsaves, sizeof(ULONG));
2979 }
2980
2981 return numsaves;
2982}
2983
2984static VOID TransformSwp(PSWP pswp, double xtrans, double ytrans)
2985{
2986 SWP swp;
2987 HWND hwnd;
2988
2989 if ((LONG) pswp->x < 0L) {
2990 pswp->cx -= abs(pswp->x);
2991 pswp->x = 0;
2992 }
2993 if ((LONG) pswp->y < 0L) {
2994 pswp->cy -= abs(pswp->y);
2995 pswp->y = 0;
2996 }
2997 pswp->x = (LONG) (((double)pswp->x * 100.0) / xtrans);
2998 pswp->cx = (LONG) (((double)pswp->cx * 100.0) / xtrans);
2999 pswp->y = (LONG) (((double)pswp->y * 100.0) / ytrans);
3000 pswp->cy = (LONG) (((double)pswp->cy * 100.0) / ytrans);
3001 if (pswp->hwnd) {
3002 hwnd = WinQueryWindow(pswp->hwnd, QW_PARENT);
3003 if (hwnd) {
3004 if (WinQueryWindowPos(hwnd, &swp)) {
3005 if (pswp->x > swp.cx)
3006 pswp->x = (swp.cx > 24) ? swp.cx - 24 : swp.cx;
3007 if (pswp->y > swp.cy)
3008 pswp->y = (swp.cy > 24) ? swp.cy - 24 : swp.cy;
3009 if (pswp->x + pswp->cx > swp.cx)
3010 pswp->cx = swp.cx - pswp->x;
3011 if (pswp->y + pswp->cy > swp.cy)
3012 pswp->cy = swp.cy - pswp->y;
3013 }
3014 }
3015 }
3016}
3017
3018/** Restore directory container state
3019 * @param hwndClient Client window handle
3020 * @param pszStateName State name to restore, NULL to restore global state
3021 * @param noview request view state restore bypass
3022 * @returns TRUE if one or more directory containers were opened
3023 * @seealso SaveDirCnrState
3024 */
3025
3026static BOOL RestoreDirCnrState(HWND hwndClient, PSZ pszStateName, BOOL noview)
3027{
3028 CHAR szKey[STATE_NAME_MAX_BYTES + 80];
3029 CHAR szDir[CCHMAXPATH];
3030 CHAR szPrefix[STATE_NAME_MAX_BYTES + 2];
3031 HWND hwndDir, hwndC, hwndPPSave = NULLHANDLE;
3032 SWP swp, swpO, swpN;
3033 ULONG size, numsaves = 0;
3034 LONG x;
3035 double xtrans, ytrans;
3036 BOOL fRestored = FALSE;
3037 DIRCNRDATA localdcd, *dcd;
3038 BOOL fIsShutDownState;
3039 BOOL fDeleteState;
3040
3041 if (!pszStateName || !*pszStateName) {
3042 Runtime_Error(pszSrcFile, __LINE__, "no name");
3043 return fRestored;
3044 }
3045 if (strlen(pszStateName) > sizeof(szPrefix) - 2) {
3046 Runtime_Error(pszSrcFile, __LINE__, "name too long");
3047 return fRestored;
3048 }
3049
3050 sprintf(szPrefix, "%s.", pszStateName);
3051
3052 // If restoring shutdown state bypass no-prescan drives
3053 fIsShutDownState = strcmp(pszStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0;
3054 // Delete saved state if internally saved state
3055 fDeleteState = strcmp(pszStateName, GetPString(IDS_FM2TEMPTEXT)) == 0;
3056
3057 size = sizeof(SWP);
3058 sprintf(szKey, "%sMySizeLastTime", szPrefix);
3059 if (!PrfQueryProfileData(fmprof,
3060 FM3Str,
3061 szKey,
3062 (PVOID) & swpO,
3063 &size) ||
3064 size != sizeof(SWP) || !swp.cx || !swp.cy)
3065 {
3066 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swpO);
3067 }
3068 // If restoring internally saved state, forget info
3069 if (fDeleteState)
3070 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3071 WinQueryWindowPos(WinQueryWindow(hwndClient, QW_PARENT), &swpN);
3072 if (swpN.fl & (SWP_MINIMIZE | SWP_HIDE))
3073 swpN = swpO;
3074 xtrans = ((double)swpO.cx * 100.0) / (double)swpN.cx;
3075 ytrans = ((double)swpO.cy * 100.0) / (double)swpN.cy;
3076 size = sizeof(SWP);
3077 sprintf(szKey, "%sLastTreePos", szPrefix);
3078 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) & swp, &size)) {
3079 if (fDeleteState)
3080 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3081 swp.hwnd = hwndTree;
3082 TransformSwp(&swp, xtrans, ytrans);
3083 if (!fFreeTree) {
3084 WinQueryWindowPos(hwndClient, &swpN);
3085 swp.x = 0;
3086 swp.y = (swpN.cy - swp.cy);
3087 }
3088 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
3089 swp.fl &= (~SWP_ACTIVATE);
3090 WinSetWindowPos(hwndTree,
3091 HWND_TOP,
3092 swp.x,
3093 swp.y,
3094 swp.cx,
3095 swp.cy,
3096 swp.fl | SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
3097 }
3098 else {
3099 WinSetWindowPos(hwndTree,
3100 HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);
3101 WinSetWindowUShort(hwndTree, QWS_XRESTORE, (USHORT) swp.x);
3102 WinSetWindowUShort(hwndTree, QWS_CXRESTORE, (USHORT) swp.cx);
3103 WinSetWindowUShort(hwndTree, QWS_YRESTORE, (USHORT) swp.y);
3104 WinSetWindowUShort(hwndTree, QWS_CYRESTORE, (USHORT) swp.cy);
3105 }
3106 }
3107 size = sizeof(ULONG);
3108 sprintf(szKey, "%sNumDirsLastTime", szPrefix);
3109 if (PrfQueryProfileData(fmprof,
3110 FM3Str, szKey, (PVOID) & numsaves, &size)) {
3111 if (fDeleteState)
3112 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3113 for (x = numsaves - 1; x >= 0; x--) {
3114 sprintf(szKey, "%sDirCnrPos.%lu", szPrefix, x);
3115 size = sizeof(SWP);
3116 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &swp, &size)) {
3117 if (fDeleteState)
3118 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3119 sprintf(szKey, "%sDirCnrDir.%lu", szPrefix, x);
3120 size = sizeof(szDir);
3121 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) szDir, &size)) {
3122 // If restoring shutdown state and drive marked no prescan
3123 // bypass window restore
3124 if (fIsShutDownState &&
3125 driveflags[toupper(*szDir) - 'A'] & DRIVE_NOPRESCAN) {
3126 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3127 continue;
3128 }
3129 if (fDeleteState)
3130 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3131 localdcd.ds.detailslongname = dsDirCnrDefault.detailslongname; // Set default
3132 size = sizeof(BOOL);
3133 sprintf(szKey, "%sDirCnr.%lu.DetailsLongname", szPrefix, x);
3134 if (PrfQueryProfileData(fmprof,
3135 FM3Str,
3136 szKey,
3137 (PVOID)&localdcd.ds.detailslongname,
3138 &size) &&
3139 size == sizeof(BOOL))
3140 {
3141 if (fDeleteState)
3142 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3143 }
3144 localdcd.ds.detailssubject = dsDirCnrDefault.detailssubject; // Set default
3145 size = sizeof(BOOL);
3146 sprintf(szKey, "%sDirCnr.%lu.DetailsSubject", szPrefix, x);
3147 if (PrfQueryProfileData(fmprof,
3148 FM3Str,
3149 szKey,
3150 (PVOID)&localdcd.ds.detailssubject,
3151 &size) &&
3152 size == sizeof(BOOL))
3153 {
3154 if (fDeleteState)
3155 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3156 }
3157 localdcd.ds.detailsea = dsDirCnrDefault.detailsea; // Set default
3158 size = sizeof(BOOL);
3159 sprintf(szKey, "%sDirCnr.%lu.DetailsEA", szPrefix, x);
3160 if (PrfQueryProfileData(fmprof,
3161 FM3Str,
3162 szKey,
3163 (PVOID) & localdcd.ds.detailsea,
3164 &size) &&
3165 size == sizeof(BOOL))
3166 {
3167 if (fDeleteState)
3168 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3169 }
3170 localdcd.ds.detailssize = dsDirCnrDefault.detailssize; // Set default
3171 size = sizeof(BOOL);
3172 sprintf(szKey, "%sDirCnr.%lu.DetailsSize", szPrefix, x);
3173 if (PrfQueryProfileData(fmprof,
3174 FM3Str,
3175 szKey,
3176 (PVOID) & localdcd.ds.detailssize,
3177 &size) &&
3178 size == sizeof(BOOL))
3179 {
3180 if (fDeleteState)
3181 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3182 }
3183 localdcd.ds.detailsicon = dsDirCnrDefault.detailsicon; // Set default
3184 size = sizeof(BOOL);
3185 sprintf(szKey, "%sDirCnr.%lu.DetailsIcon", szPrefix, x);
3186 if (PrfQueryProfileData(fmprof,
3187 FM3Str,
3188 szKey,
3189 (PVOID) & localdcd.ds.detailsicon,
3190 &size) &&
3191 size == sizeof(BOOL))
3192 {
3193 if (fDeleteState)
3194 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3195 }
3196 localdcd.ds.detailsattr = dsDirCnrDefault.detailsattr; // Set default
3197 size = sizeof(BOOL);
3198 sprintf(szKey, "%sDirCnr.%lu.DetailsAttr", szPrefix, x);
3199 if (PrfQueryProfileData(fmprof,
3200 FM3Str,
3201 szKey,
3202 (PVOID)&localdcd.ds.detailsattr,
3203 &size) &&
3204 size == sizeof(BOOL))
3205 {
3206 if (fDeleteState)
3207 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3208 }
3209 localdcd.ds.detailscrdate = dsDirCnrDefault.detailscrdate; // Set default
3210 size = sizeof(BOOL);
3211 sprintf(szKey, "%sDirCnr.%lu.DetailsCRDate", szPrefix, x);
3212 if (PrfQueryProfileData(fmprof,
3213 FM3Str,
3214 szKey,
3215 (PVOID) & localdcd.ds.detailscrdate,
3216 &size) && size == sizeof(BOOL))
3217 {
3218 if (fDeleteState)
3219 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3220 }
3221 localdcd.ds.detailscrtime = dsDirCnrDefault.detailscrtime; // Set default
3222 size = sizeof(BOOL);
3223 sprintf(szKey, "%sDirCnr.%lu.DetailsCRTime", szPrefix, x);
3224 if (PrfQueryProfileData(fmprof,
3225 FM3Str,
3226 szKey,
3227 (PVOID)&localdcd.ds.detailscrtime,
3228 &size) &&
3229 size == sizeof(BOOL))
3230 {
3231 if (fDeleteState)
3232 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3233 }
3234 localdcd.ds.detailslwdate = dsDirCnrDefault.detailslwdate; // Set default
3235 size = sizeof(BOOL);
3236 sprintf(szKey, "%sDirCnr.%lu.DetailsLWDate", szPrefix, x);
3237 if (PrfQueryProfileData(fmprof,
3238 FM3Str,
3239 szKey,
3240 (PVOID) & localdcd.ds.detailslwdate,
3241 &size) &&
3242 size == sizeof(BOOL))
3243 {
3244 if (fDeleteState)
3245 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3246 }
3247 localdcd.ds.detailslwtime = dsDirCnrDefault.detailslwtime; // Set default
3248 size = sizeof(BOOL);
3249 sprintf(szKey, "%sDirCnr.%lu.DetailsLWTime", szPrefix, x);
3250 if (PrfQueryProfileData(fmprof,
3251 FM3Str,
3252 szKey,
3253 (PVOID) & localdcd.ds.detailslwtime,
3254 &size) &&
3255 size == sizeof(BOOL))
3256 {
3257 if (fDeleteState)
3258 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3259 }
3260 localdcd.ds.detailsladate = dsDirCnrDefault.detailsladate; // Set default
3261 size = sizeof(BOOL);
3262 sprintf(szKey, "%sDirCnr.%lu.DetailsLADate", szPrefix, x);
3263 if (PrfQueryProfileData(fmprof,
3264 FM3Str,
3265 szKey,
3266 (PVOID) & localdcd.ds.detailsladate,
3267 &size) &&
3268 size == sizeof(BOOL))
3269 {
3270 if (fDeleteState)
3271 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3272 }
3273 localdcd.ds.detailslatime = dsDirCnrDefault.detailslatime; // Set default
3274 size = sizeof(BOOL);
3275 sprintf(szKey, "%sDirCnr.%lu.DetailsLATime", szPrefix, x);
3276 if (PrfQueryProfileData(fmprof,
3277 FM3Str,
3278 szKey,
3279 (PVOID) & localdcd.ds.detailslatime,
3280 &size) &&
3281 size == sizeof(BOOL))
3282 {
3283 if (fDeleteState)
3284 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3285 }
3286 hwndDir = (HWND) WinSendMsg(hwndClient,
3287 UM_SETDIR,
3288 MPFROMP(szDir), MPFROMLONG(1));
3289 if (hwndDir) {
3290 hwndC = WinWindowFromID(hwndDir, FID_CLIENT);
3291 if (hwndC) {
3292 HWND hwndCnr = WinWindowFromID(hwndC, DIR_CNR);
3293 if (!hwndPPSave) {
3294 hwndPPSave = WinCreateWindow(hwndCnr, // Create a window (used to save default presparams)
3295 WC_CONTAINER,
3296 NULL,
3297 CCS_AUTOPOSITION | CCS_MINIICONS |
3298 CCS_MINIRECORDCORE | ulCnrType |
3299 WS_VISIBLE,
3300 0,
3301 0,
3302 0,
3303 0,
3304 hwndCnr,
3305 HWND_TOP, (ULONG) -1, NULL, NULL);
3306 CopyPresParams(hwndPPSave, hwndC);
3307 RestorePresParams(hwndPPSave, "DirCnr");
3308 }
3309 sprintf(szKey, "%sDirCnr.%lu", szPrefix, x);
3310 RestorePresParams(hwndCnr, szKey);
3311 dcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
3312 if (dcd) {
3313 dcd->ds.detailslongname = localdcd.ds.detailslongname;
3314 dcd->ds.detailssubject = localdcd.ds.detailssubject ;
3315 dcd->ds.detailsattr = localdcd.ds.detailsattr ;
3316 dcd->ds.detailsea = localdcd.ds.detailsea ;
3317 dcd->ds.detailssize = localdcd.ds.detailssize ;
3318 dcd->ds.detailsicon = localdcd.ds.detailsicon ;
3319 dcd->ds.detailscrdate = localdcd.ds.detailscrdate ;
3320 dcd->ds.detailscrtime = localdcd.ds.detailscrtime ;
3321 dcd->ds.detailsladate = localdcd.ds.detailsladate ;
3322 dcd->ds.detailslatime = localdcd.ds.detailslatime ;
3323 dcd->ds.detailslwdate = localdcd.ds.detailslwdate ;
3324 dcd->ds.detailslwtime = localdcd.ds.detailslwtime ;
3325 size = sizeof(INT);
3326 sprintf(szKey, "%sDirCnrSort.%lu", szPrefix, x);
3327 if (PrfQueryProfileData(fmprof,
3328 FM3Str,
3329 szKey,
3330 (PVOID) & dcd->sortFlags,
3331 &size) && size == sizeof(INT)) {
3332 if (!dcd->sortFlags)
3333 dcd->sortFlags = SORT_PATHNAME;
3334 }
3335 if (fDeleteState)
3336 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3337 size = sizeof(MASK);
3338 sprintf(szKey, "%sDirCnrFilter.%lu", szPrefix, x);
3339 if (PrfQueryProfileData(fmprof,
3340 FM3Str,
3341 szKey,
3342 (PVOID) & dcd->mask, &size) && size) {
3343 if (*dcd->mask.szMask)
3344 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3345 UM_FILTER, MPFROMP(dcd->mask.szMask), MPVOID);
3346 }
3347 *(dcd->mask.prompt) = 0;
3348 if (fDeleteState)
3349 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3350 size = sizeof(ULONG);
3351 sprintf(szKey, "%sDirCnrView.%lu", szPrefix, x);
3352 if (!noview) {
3353 if (PrfQueryProfileData(fmprof,
3354 FM3Str,
3355 szKey,
3356 (PVOID) & dcd->flWindowAttr,
3357 &size) && size == sizeof(ULONG)) {
3358
3359 CNRINFO cnri;
3360
3361 memset(&cnri, 0, sizeof(CNRINFO));
3362 cnri.cb = sizeof(CNRINFO);
3363 if (WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3364 CM_QUERYCNRINFO,
3365 MPFROMP(&cnri),
3366 MPFROMLONG(sizeof(CNRINFO)))) {
3367 cnri.flWindowAttr = dcd->flWindowAttr;
3368 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3369 CM_SETCNRINFO,
3370 MPFROMP(&cnri),
3371 MPFROMLONG(CMA_FLWINDOWATTR));
3372 }
3373 }
3374 }
3375 if (fDeleteState)
3376 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3377 if (!PostMsg(hwndCnr, UM_SETUP2, NULL, NULL))
3378 WinSendMsg(hwndCnr, UM_SETUP2, NULL, NULL);
3379 }
3380 }
3381 fRestored = TRUE;
3382 swp.hwnd = hwndDir;
3383 TransformSwp(&swp, xtrans, ytrans);
3384 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3385 WinSetWindowPos(hwndDir,
3386 HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);
3387 WinSetWindowUShort(hwndDir, QWS_XRESTORE, (USHORT) swp.x);
3388 WinSetWindowUShort(hwndDir, QWS_CXRESTORE, (USHORT) swp.cx);
3389 WinSetWindowUShort(hwndDir, QWS_YRESTORE, (USHORT) swp.y);
3390 WinSetWindowUShort(hwndDir, QWS_CYRESTORE, (USHORT) swp.cy);
3391 } else
3392 WinSetWindowPos(hwndDir,
3393 HWND_TOP,
3394 swp.x,
3395 swp.y,
3396 swp.cx,
3397 swp.cy,
3398 swp.fl | SWP_MOVE |
3399 SWP_SIZE | SWP_SHOW | SWP_ZORDER |
3400 SWP_ACTIVATE);
3401 }
3402 }
3403 }
3404 } // for
3405 if (hwndPPSave) {
3406 SavePresParams(hwndPPSave, "DirCnr");
3407 WinDestroyWindow(hwndPPSave);
3408 }
3409 }
3410 return fRestored;
3411}
3412
3413static ULONG CountChildren(HWND hwndClient, ULONG * ulNumMinChildren)
3414{
3415 HENUM henum;
3416 HWND hwndChild;
3417 SWP swp;
3418 register ULONG ulCnt = 0L;
3419 USHORT id;
3420
3421 if (ulNumMinChildren)
3422 *ulNumMinChildren = 0L;
3423 henum = WinBeginEnumWindows(hwndClient);
3424 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3425 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3426 if (!id || (!fFreeTree && id == TREE_FRAME))
3427 continue;
3428 ulCnt++;
3429 if (ulNumMinChildren) {
3430 if (WinQueryWindowPos(hwndChild, &swp) && (swp.fl & SWP_MINIMIZE))
3431 (*ulNumMinChildren)++;
3432 }
3433 }
3434 WinEndEnumWindows(henum);
3435 return ulCnt;
3436}
3437
3438VOID GetNextWindowPos(HWND hwndClient, PSWP pswp, ULONG * ulCntR,
3439 ULONG * ulNumMinChildrenR)
3440{
3441 register ULONG ulCnt;
3442 ULONG ulNumMinChildren;
3443 RECTL Rectl;
3444 register ULONG ulXDiff, ulYDiff, ulWindowsPerStack;
3445
3446 if (!ulCntR || !ulNumMinChildrenR)
3447 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3448 else {
3449 ulCnt = *ulCntR;
3450 ulNumMinChildren = *ulNumMinChildrenR;
3451 if (ulCnt == (ULONG) - 1) {
3452 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3453 /* return these values to the caller for later use */
3454 *ulCntR = ulCnt;
3455 *ulNumMinChildrenR = ulNumMinChildren;
3456 }
3457 }
3458 WinQueryWindowRect(hwndClient, &Rectl);
3459 AdjustSizeOfClient(NULL, &Rectl);
3460 if (!fFreeTree) {
3461
3462 SWP swp;
3463
3464 WinQueryWindowPos(hwndTree, &swp);
3465 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3466 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3467 }
3468 else if (ulNumMinChildren)
3469 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3470
3471 ulXDiff = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) +
3472 WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON) / 2;
3473 ulYDiff = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER) +
3474 WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
3475 ulWindowsPerStack = (Rectl.yTop - Rectl.yBottom) / (3 * ulYDiff);
3476 pswp->cx = Rectl.xRight - (ulWindowsPerStack * ulXDiff);
3477 pswp->cy = (Rectl.yTop - Rectl.yBottom) - (ulWindowsPerStack * ulYDiff);
3478 ulWindowsPerStack++;
3479 pswp->x = Rectl.xLeft + ((ulCnt % ulWindowsPerStack) * ulXDiff);
3480 pswp->y = (Rectl.yTop - pswp->cy - ((ulCnt % ulWindowsPerStack) * ulYDiff));
3481}
3482
3483static VOID CascadeChildren(HWND hwndClient)
3484{
3485 ULONG ulCnt = 0L, ulNumMinChildren;
3486 HWND hwndChild;
3487 HENUM henum;
3488 SWP swp;
3489 USHORT id;
3490 RECTL Rectl;
3491
3492 WinQueryWindowPos(hwndClient, &swp);
3493 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3494 return;
3495
3496 CountChildren(hwndClient, &ulNumMinChildren);
3497 if (!fFreeTree) {
3498 WinQueryWindowRect(hwndClient, &Rectl);
3499 AdjustSizeOfClient(NULL, &Rectl);
3500 WinQueryWindowPos(hwndTree, &swp);
3501 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3502 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3503 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3504 if (swp.x != 0)
3505 swp.x = 0;
3506 if (swp.y < 0)
3507 swp.y = 0;
3508 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3509 swp.cx = Rectl.xRight - Rectl.xLeft;
3510 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3511 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3512 }
3513 }
3514 henum = WinBeginEnumWindows(hwndClient);
3515 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3516 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3517 if (!id || (!fFreeTree && id == TREE_FRAME))
3518 continue;
3519 WinQueryWindowPos(hwndChild, &swp);
3520 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
3521 GetNextWindowPos(hwndClient, &swp, &ulCnt, &ulNumMinChildren);
3522 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3523 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
3524 SWP_ZORDER | SWP_ACTIVATE);
3525 ulCnt++;
3526 }
3527 }
3528 WinEndEnumWindows(henum);
3529}
3530
3531VOID TileChildren(HWND hwndClient, BOOL absolute)
3532{
3533 register ULONG ulChildCnt, ulSquare, ulNumRows, ulNumCols, ulExtraCols,
3534 ulWidth, ulHeight;
3535 ULONG ulNumMinChildren;
3536 RECTL Rectl;
3537 HWND hwndChild;
3538
3539 if (fNoTileUpdate || hwndClient == HWND_DESKTOP)
3540 return;
3541 {
3542 SWP swp;
3543
3544 WinQueryWindowPos(hwndClient, &swp);
3545 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3546 return;
3547 }
3548 ulChildCnt = CountChildren(hwndClient, &ulNumMinChildren);
3549 ulChildCnt -= ulNumMinChildren;
3550 if (!ulChildCnt)
3551 return;
3552
3553 fNoTileUpdate = TRUE;
3554
3555 for (ulSquare = 2; ulSquare * ulSquare <= ulChildCnt; ulSquare++) {
3556 ;
3557 }
3558 if (!fTileBackwards) {
3559 ulNumCols = ulSquare - 1;
3560 ulNumRows = ulChildCnt / ulNumCols;
3561 }
3562 else {
3563 ulNumRows = ulSquare - 1;
3564 ulNumCols = ulChildCnt / ulNumRows;
3565 }
3566 ulExtraCols = ulChildCnt % ulNumCols;
3567
3568 WinQueryWindowRect(hwndClient, &Rectl);
3569
3570 if (!fFreeTree) {
3571
3572 SWP swp;
3573
3574 WinQueryWindowPos(hwndTree, &swp);
3575 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3576 if (swp.y < 0)
3577 swp.y = 0;
3578 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3579 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3580 if (swp.x != 0)
3581 swp.x = 0;
3582 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3583 swp.cx = Rectl.xRight - Rectl.xLeft;
3584 WinSetWindowPos(hwndTree,
3585 HWND_TOP,
3586 swp.x,
3587 swp.y,
3588 swp.cx,
3589 swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3590 WinQueryWindowPos(hwndTree, &swp);
3591 }
3592 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3593 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3594 }
3595 else if (ulNumMinChildren)
3596 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3597
3598 AdjustSizeOfClient(NULL, &Rectl);
3599
3600 if (Rectl.xRight > 0L && (Rectl.yBottom < Rectl.yTop)) {
3601
3602 HENUM henum;
3603
3604 henum = WinBeginEnumWindows(hwndClient);
3605 if ((hwndChild = WinGetNextWindow(henum)) != (HWND) 0) {
3606
3607 ULONG ulCurRow, ulCurCol;
3608 SWP swp;
3609 USHORT id;
3610
3611 ulHeight = (Rectl.yTop - Rectl.yBottom) / ulNumRows;
3612
3613 for (ulCurRow = 0; ulCurRow < ulNumRows; ulCurRow++) {
3614 if ((ulNumRows - ulCurRow) <= ulExtraCols)
3615 ulNumCols++;
3616 for (ulCurCol = 0; ulCurCol < ulNumCols; ulCurCol++) {
3617 ulWidth = Rectl.xRight / ulNumCols;
3618
3619 while (hwndChild) {
3620 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3621 if (id && (id != TREE_FRAME || fFreeTree)) {
3622 WinQueryWindowPos(hwndChild, &swp);
3623 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3624 break;
3625 }
3626 hwndChild = WinGetNextWindow(henum);
3627 }
3628
3629 if (hwndChild) {
3630 if (!absolute && (swp.fl & SWP_MAXIMIZE)) {
3631 WinGetMaxPosition(hwndChild, &swp);
3632 WinSetWindowPos(hwndChild,
3633 HWND_TOP,
3634 swp.x,
3635 swp.y,
3636 swp.cx, swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
3637 WinSetWindowUShort(hwndChild,
3638 QWS_XRESTORE,
3639 (USHORT) (ulWidth * ulCurCol) + Rectl.xLeft);
3640 WinSetWindowUShort(hwndChild,
3641 QWS_YRESTORE,
3642 (USHORT) (Rectl.yTop -
3643 (ulHeight * (ulCurRow + 1))));
3644 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, (USHORT) ulWidth);
3645 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, (USHORT) ulHeight);
3646 }
3647 else
3648 WinSetWindowPos(hwndChild,
3649 HWND_TOP,
3650 (ulWidth * ulCurCol) + Rectl.xLeft,
3651 Rectl.yTop - (ulHeight * (ulCurRow + 1)),
3652 ulWidth,
3653 ulHeight,
3654 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3655 hwndChild = WinGetNextWindow(henum);
3656 }
3657 }
3658 if ((ulNumRows - ulCurRow) <= ulExtraCols) {
3659 ulNumCols--;
3660 ulExtraCols--;
3661 }
3662 }
3663 }
3664 WinEndEnumWindows(henum);
3665 }
3666
3667 fNoTileUpdate = FALSE;
3668}
3669
3670static VOID ResizeChildren(HWND hwndClient, SHORT oldcx, SHORT oldcy,
3671 SHORT newcx, SHORT newcy)
3672{
3673 /*
3674 * resize all children of the client to maintain their proportional
3675 * sizes and positions
3676 */
3677
3678 if (!newcx || !newcy || !oldcx || !oldcy)
3679 return;
3680 {
3681 HENUM henum;
3682 HWND hwndChild;
3683 register LONG x, y, cx, cy, ucx, ucy, ux, uy;
3684 SWP swp;
3685
3686 henum = WinBeginEnumWindows(hwndClient);
3687 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3688 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
3689 continue;
3690 if (WinQueryWindowPos(hwndChild, &swp)) {
3691 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
3692 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3693 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3694 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3695 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3696 }
3697 else if (swp.fl & SWP_MAXIMIZE) {
3698 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3699 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3700 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3701 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3702 }
3703 cx = (swp.cx) ? (LONG) (((double)oldcx * 100.0) / (double)swp.cx) : 0;
3704 cy = (swp.cy) ? (LONG) (((double)oldcy * 100.0) / (double)swp.cy) : 0;
3705 x = (swp.x) ? (LONG) (((double)oldcx * 100.0) / (double)swp.x) : 0;
3706 y = (swp.y) ? (LONG) (((double)oldcy * 100.0) / (double)swp.y) : 0;
3707 if (x < 0)
3708 x = 0;
3709 if (y < 0)
3710 y = 0;
3711 ux = (x) ? (LONG) (((double)newcx * 100.0) / (double)x) : 0;
3712 uy = (y) ? (LONG) (((double)newcy * 100.0) / (double)y) : 0;
3713 ucx = (cx) ? (LONG) (((double)newcx * 100.0) / (double)cx) : 0;
3714 ucy = (cy) ? (LONG) (((double)newcy * 100.0) / (double)cy) : 0;
3715 if (ux + ucx > newcx)
3716 ucx = newcx - ux;
3717 if (uy + ucy > newcy)
3718 ucy = newcy - uy;
3719
3720 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE)))
3721 WinSetWindowPos(hwndChild, HWND_TOP, ux, uy, ucx, ucy,
3722 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3723 else if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3724 WinSetWindowUShort(hwndChild, QWS_XMINIMIZE, (USHORT) - 1);
3725 WinSetWindowUShort(hwndChild, QWS_YMINIMIZE, (USHORT) - 1);
3726 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0,
3727 SWP_SIZE | SWP_MOVE | SWP_FOCUSDEACTIVATE);
3728 WinSetWindowUShort(hwndChild, QWS_XRESTORE, ux);
3729 WinSetWindowUShort(hwndChild, QWS_YRESTORE, uy);
3730 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, ucx);
3731 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, ucy);
3732 }
3733 else {
3734 WinGetMaxPosition(hwndChild, &swp);
3735 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3736 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3737 WinSetWindowUShort(hwndChild, QWS_XRESTORE, ux);
3738 WinSetWindowUShort(hwndChild, QWS_YRESTORE, uy);
3739 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, ucx);
3740 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, ucy);
3741 }
3742 }
3743 }
3744 WinEndEnumWindows(henum);
3745 }
3746 if (!fFreeTree) {
3747
3748 RECTL Rectl;
3749 SWP swp;
3750
3751 WinQueryWindowRect(hwndClient, &Rectl);
3752 AdjustSizeOfClient(NULL, &Rectl);
3753 WinQueryWindowPos(hwndTree, &swp);
3754 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3755
3756 if (!fNoTreeGap) {
3757 INT height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3758 if (swp.y < height)
3759 swp.y = height; // Force bottom to position
3760 }
3761 else
3762 swp.y = 0; // Force bottom to position
3763
3764 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3765 if (swp.cy < 0)
3766 swp.cy = 0;
3767
3768 if (swp.x != 0)
3769 swp.x = 0; // Left align
3770
3771 // AdjustSizeOfClient can return bogus xRight values - fixme someday
3772 if (Rectl.xRight >= Rectl.xLeft) {
3773 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3774 swp.cx = Rectl.xRight - Rectl.xLeft;
3775 }
3776 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3777 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3778 }
3779 }
3780}
3781
3782static VOID MinResChildren(HWND hwndClient, ULONG cmd)
3783{
3784 HENUM henum;
3785 HWND hwndChild;
3786
3787 {
3788 SWP swp;
3789
3790 WinQueryWindowPos(hwndClient, &swp);
3791 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3792 return;
3793 }
3794 henum = WinBeginEnumWindows(hwndClient);
3795 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3796 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
3797 continue;
3798 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0, cmd);
3799 }
3800}
3801
3802//=== ChildFrameButtonProc: subclass handler for WALKBUTTON and QUICKBUTTON windows ===
3803
3804static MRESULT EXPENTRY ChildFrameButtonProc(HWND hwnd,
3805 ULONG msg,
3806 MPARAM mp1, MPARAM mp2)
3807{
3808 USHORT id;
3809 static BOOL emphasized = FALSE;
3810
3811 switch (msg) {
3812 case WM_BUTTON1CLICK:
3813 case WM_CHORD:
3814 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3815 break;
3816
3817 case WM_MOUSEMOVE:
3818 if (fOtherHelp) {
3819 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
3820 && !WinQueryCapture(HWND_DESKTOP)) {
3821 id = WinQueryWindowUShort(hwnd, QWS_ID);
3822 switch (id) {
3823 case IDM_OPENWALK:
3824 MakeBubble(hwnd, FALSE, GetPString(IDS_WALKBUTTONHELP));
3825 break;
3826 case IDM_USERLIST:
3827 MakeBubble(hwnd, FALSE, GetPString(IDS_QUICKBUTTONHELP));
3828 break;
3829 }
3830 }
3831 }
3832 break;
3833
3834 case WM_BUTTON3CLICK:
3835 case WM_BUTTON2CLICK:
3836 {
3837 USHORT cmd = 0;
3838
3839 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3840 id = WinQueryWindowUShort(hwnd, QWS_ID);
3841 switch (id) {
3842 case IDM_OPENWALK:
3843 switch (msg) {
3844 case WM_BUTTON2CLICK:
3845 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
3846 (KC_ALT | KC_SHIFT | KC_CTRL))
3847 cmd = IDM_GREP;
3848 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
3849 CascadeChildren(hwndMain);
3850
3851#ifdef NEVER
3852 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
3853 cmd = IDM_SYSINFO;
3854#endif
3855
3856 else if (shiftstate & KC_SHIFT)
3857 cmd = IDM_WINDOWDLG;
3858 else if (shiftstate & KC_CTRL)
3859 cmd = IDM_SEEALL;
3860 else if (shiftstate & KC_ALT)
3861 TileChildren(hwndMain, TRUE);
3862 else
3863 cmd = IDM_WALKDIR;
3864 break;
3865 case WM_BUTTON3CLICK:
3866 TileChildren(hwndMain, TRUE);
3867 break;
3868 }
3869 break;
3870 case IDM_USERLIST:
3871 switch (msg) {
3872 case WM_BUTTON2CLICK:
3873 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
3874 (KC_ALT | KC_SHIFT | KC_CTRL))
3875 cmd = IDM_COLORPALETTE;
3876 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
3877 cmd = IDM_HIDEMENU;
3878 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
3879 cmd = IDM_NOTEBOOK;
3880 else if (shiftstate & KC_SHIFT)
3881 cmd = IDM_TOOLTITLES;
3882 else if (shiftstate & KC_CTRL)
3883 cmd = IDM_TEXTTOOLS;
3884 else if (shiftstate & KC_ALT)
3885 cmd = IDM_FONTPALETTE;
3886 else
3887 cmd = IDM_TOOLBAR;
3888 break;
3889 case WM_BUTTON3CLICK:
3890 cmd = IDM_DRIVEBAR;
3891 break;
3892 }
3893 break;
3894 } // switch id
3895
3896 if (cmd) {
3897 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_CLIENT),
3898 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
3899 }
3900 }
3901 break;
3902
3903 case DM_DRAGOVER:
3904 id = WinQueryWindowUShort(hwnd, QWS_ID);
3905 if (id == IDM_OPENWALK) {
3906 if (!emphasized) {
3907 emphasized = TRUE;
3908 DrawTargetEmphasis(hwnd, emphasized);
3909 }
3910 if (AcceptOneDrop(hwnd, mp1, mp2))
3911 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
3912 }
3913 return MRFROM2SHORT(DOR_NEVERDROP, 0);
3914
3915 case DM_DRAGLEAVE:
3916 if (emphasized) {
3917 emphasized = FALSE;
3918 DrawTargetEmphasis(hwnd, emphasized);
3919 }
3920 break;
3921
3922 case DM_DROPHELP:
3923 DropHelp(mp1, mp2, hwnd, GetPString(IDS_OPENDROPHELP));
3924 return 0;
3925
3926 case DM_DROP:
3927 {
3928 char szFrom[CCHMAXPATH + 2];
3929
3930 if (emphasized) {
3931 emphasized = FALSE;
3932 DrawTargetEmphasis(hwnd, emphasized);
3933 }
3934 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
3935 if (MakeValidDir(szFrom) && !FindDirCnrByName(szFrom, TRUE)) {
3936 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, szFrom);
3937 }
3938 }
3939 }
3940 return 0;
3941
3942 case WM_CLOSE:
3943 WinDestroyWindow(hwnd);
3944 return 0;
3945 }
3946 return PFNWPButton(hwnd, msg, mp1, mp2);
3947}
3948
3949static MRESULT EXPENTRY MainFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
3950 MPARAM mp2)
3951{
3952 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
3953 static ULONG aheight = 0L;
3954
3955 switch (msg) {
3956 case WM_ADJUSTWINDOWPOS:
3957 {
3958 SWP *pswp;
3959
3960 pswp = (SWP *) mp1;
3961 if (fDataMin && !fAmClosing) {
3962 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE)) {
3963
3964 SWP swp;
3965
3966 WinQueryWindowPos(hwnd, &swp);
3967 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(swp.fl), MPVOID);
3968 HideNote();
3969 }
3970 else if (pswp->fl & (SWP_SHOW | SWP_RESTORE)) {
3971 if (DataHwnd)
3972 PostMsg(DataHwnd, WM_CLOSE, MPVOID, MPVOID);
3973 }
3974 }
3975 if (!fAmClosing) {
3976 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE))
3977 HideNote();
3978 }
3979 }
3980 break;
3981
3982 case UM_FOCUSME:
3983 CreateDataBar(HWND_DESKTOP, (ULONG) mp1);
3984 return 0;
3985
3986 case WM_BUTTON1UP:
3987 case WM_BUTTON2UP:
3988 case WM_BUTTON3UP:
3989 case WM_MOUSEMOVE:
3990 case WM_CHORD:
3991 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
3992 break;
3993
3994 case WM_CHAR:
3995 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
3996 break;
3997
3998 case WM_CONTROL:
3999 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL, mp1,
4000 mp2);
4001
4002 case WM_COMMAND:
4003 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
4004
4005 case WM_CALCFRAMERECT:
4006 {
4007 MRESULT mr;
4008 PRECTL prectl;
4009 LONG sheight = 20, bheight = 20;
4010
4011 mr = oldproc(hwnd, msg, mp1, mp2);
4012
4013 /*
4014 * Calculate the position of the client rectangle.
4015 * Otherwise, we'll see a lot of redraw when we move the
4016 * client during WM_FORMATFRAME.
4017 */
4018
4019 if (mr && mp2) {
4020 prectl = (PRECTL) mp1;
4021 if (prectl->yBottom != prectl->yTop) {
4022 {
4023 HPS hps;
4024 POINTL aptl[TXTBOX_COUNT];
4025
4026 hps = WinGetPS(hwndStatus);
4027 if (hps) {
4028 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4029 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4030 WinReleasePS(hps);
4031 }
4032 }
4033 prectl->yBottom += (sheight + 4);
4034 prectl->yTop -= (sheight + 4);
4035 if (fMoreButtons) {
4036
4037 HPS hps;
4038 POINTL aptl[TXTBOX_COUNT];
4039
4040 hps = WinGetPS(hwndName);
4041 if (hps) {
4042 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4043 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4044 WinReleasePS(hps);
4045 }
4046 prectl->yBottom += (bheight + 4);
4047 prectl->yTop -= (bheight + 4);
4048 }
4049 if (fToolbar) {
4050 if (!fTextTools)
4051 prectl->yTop -= ((fToolTitles) ? 50 : 40);
4052 else
4053 prectl->yTop -= 32;
4054 }
4055 if (fDrivebar) {
4056 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES),
4057 ((prectl->xRight -
4058 (WinQuerySysValue(HWND_DESKTOP,
4059 SV_CYSIZEBORDER) * 2)) - 4));
4060 prectl->yTop -= (16 * (DriveLines * 18));
4061 }
4062 if (fUserComboBox) {
4063 if (!aheight) {
4064
4065 SWP swpTemp;
4066
4067 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4068 &swpTemp);
4069 aheight = swpTemp.cy;
4070 }
4071 prectl->yTop -= (aheight + 6L);
4072 }
4073 if (fAutoView) {
4074 AutoviewHeight = min(AutoviewHeight,
4075 (prectl->yTop - prectl->yBottom) - 116);
4076 AutoviewHeight = max(AutoviewHeight, 36);
4077 prectl->yBottom += (AutoviewHeight + 6);
4078 }
4079 }
4080 }
4081 return mr;
4082 }
4083
4084 case WM_FORMATFRAME:
4085 {
4086 SHORT sCount, soldCount;
4087 PSWP pswp, pswpClient, pswpNew;
4088 SWP swpClient;
4089 LONG theight = 48L, dheight = 20L, width, sheight = 20, bheight = 20;
4090
4091 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4092 soldCount = sCount;
4093
4094 /*
4095 * Reformat the frame to "squeeze" the client
4096 * and make room for status window sibling beneath
4097 * and toolbar above (if toolbar's on) and userlists
4098 * (if userlists are on).
4099 */
4100
4101 pswp = (PSWP) mp1;
4102 {
4103 SHORT x;
4104
4105 for (x = 0; x < soldCount; x++) {
4106 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
4107 pswpClient = pswp;
4108 break;
4109 }
4110 pswp++;
4111 }
4112 }
4113
4114 {
4115 HPS hps;
4116 POINTL aptl[TXTBOX_COUNT];
4117
4118 hps = WinGetPS(hwndStatus);
4119 if (hps) {
4120 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4121 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4122 WinReleasePS(hps);
4123 }
4124 if (fMoreButtons) {
4125 hps = WinGetPS(hwndName);
4126 if (hps) {
4127 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4128 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4129 WinReleasePS(hps);
4130 }
4131 }
4132 }
4133 pswpNew = (PSWP) mp1 + soldCount;
4134 *pswpNew = *pswpClient;
4135 swpClient = *pswpClient;
4136 pswpNew->hwnd = hwndStatus;
4137 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4138 pswpNew->x = swpClient.x + 3;
4139 pswpNew->y = swpClient.y + 2;
4140 if (!fSplitStatus)
4141 width = swpClient.cx - (16 + (sheight * 2) + 4);
4142 else
4143 width = (swpClient.cx - (16 + (sheight * 2) + 4)) / 2;
4144 width = max(width, 10);
4145 if (fSplitStatus)
4146 pswpNew->cx = width - 6;
4147 else
4148 pswpNew->cx = width - 8;
4149 pswpNew->cy = sheight;
4150 pswpClient->y = pswpNew->y + pswpNew->cy + 3;
4151 pswpClient->cy = (swpClient.cy - pswpNew->cy) - 3;
4152 sCount++;
4153
4154 if (fSplitStatus) {
4155 pswpNew = (PSWP) mp1 + (soldCount + 1);
4156 *pswpNew = *pswpClient;
4157 pswpNew->hwnd = hwndStatus2;
4158 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4159 pswpNew->x = width + 8;
4160 pswpNew->y = swpClient.y + 2;
4161 pswpNew->cx = width - 6;
4162 pswpNew->cy = sheight;
4163 sCount++;
4164 }
4165 else {
4166 WinShowWindow(hwndStatus2, FALSE);
4167 WinSetWindowText(hwndStatus2, NullStr);
4168 }
4169
4170 if (fToolbar) {
4171 if (fTextTools)
4172 theight = 32L;
4173 else if (!fToolTitles)
4174 theight = 40L;
4175 pswpNew = (PSWP) mp1 + (soldCount + 1 + (fSplitStatus != FALSE));
4176 *pswpNew = *pswpClient;
4177 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_TOOLS);
4178 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4179 pswpNew->x = swpClient.x + 2;
4180 pswpNew->y = (swpClient.y + swpClient.cy) - (theight - 2);
4181 pswpNew->cx = swpClient.cx - 4;
4182 pswpNew->cy = theight - 4;
4183 pswpClient->cy -= theight;
4184 sCount++;
4185 }
4186 else
4187 WinShowWindow(WinWindowFromID(hwnd, MAIN_TOOLS), FALSE);
4188
4189 if (fDrivebar) {
4190 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES), pswpClient->cx - 4);
4191 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4192 (fSplitStatus != FALSE) +
4193 (fToolbar != FALSE));
4194 *pswpNew = *pswpClient;
4195 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_DRIVES);
4196 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4197 pswpNew->x = swpClient.x + 2;
4198 dheight += ((dheight - 2) * DriveLines);
4199 pswpNew->y = (swpClient.y + swpClient.cy) - (dheight - 2);
4200 if (fToolbar)
4201 pswpNew->y -= theight;
4202 pswpNew->cx = swpClient.cx - 4;
4203 pswpNew->cy = dheight - 4;
4204 pswpClient->cy -= dheight;
4205 sCount++;
4206 }
4207 else
4208 WinShowWindow(WinWindowFromID(hwnd, MAIN_DRIVES), FALSE);
4209
4210 if (fAutoView) {
4211 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4212 (fToolbar != FALSE) +
4213 (fDrivebar != FALSE) +
4214 (fSplitStatus != FALSE));
4215 *pswpNew = *pswpClient;
4216 pswpNew->hwnd = (fComments) ? hwndAutoMLE : hwndAutoview;
4217 pswpNew->x = pswpClient->x + 3;
4218 pswpNew->y = pswpClient->y + 3;
4219 if (fMoreButtons)
4220 pswpNew->y += (bheight + 4);
4221 pswpNew->cx = pswpClient->cx - 6;
4222 AutoviewHeight = min(AutoviewHeight, pswpClient->cy - 116);
4223 AutoviewHeight = max(AutoviewHeight, 36);
4224 pswpNew->cy = AutoviewHeight;
4225 pswpClient->y += (AutoviewHeight + 6);
4226 pswpClient->cy -= (AutoviewHeight + 6);
4227 sCount++;
4228 WinShowWindow((fComments) ? hwndAutoview : hwndAutoMLE, FALSE);
4229 }
4230 else {
4231 WinShowWindow(hwndAutoview, FALSE);
4232 WinShowWindow(hwndAutoMLE, FALSE);
4233 }
4234
4235 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4236 (fToolbar != FALSE) +
4237 (fDrivebar != FALSE) +
4238 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4239 *pswpNew = *pswpClient;
4240 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_OPENWALK);
4241 pswpNew->x = swpClient.cx - ((sheight * 2) + 4);
4242 pswpNew->y = swpClient.y;
4243 pswpNew->cx = sheight + 4;
4244 pswpNew->cy = sheight + 4;
4245 sCount++;
4246 pswpNew = (PSWP) mp1 + (soldCount + 2 +
4247 (fToolbar != FALSE) +
4248 (fDrivebar != FALSE) +
4249 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4250 *pswpNew = *pswpClient;
4251 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_USERLIST);
4252 pswpNew->x = swpClient.cx - (sheight + 2);
4253 pswpNew->y = swpClient.y;
4254 pswpNew->cx = sheight + 4;
4255 pswpNew->cy = sheight + 4;
4256 sCount++;
4257 pswpNew = (PSWP) mp1 + (soldCount + 3 +
4258 (fToolbar != FALSE) +
4259 (fDrivebar != FALSE) +
4260 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4261 *pswpNew = *pswpClient;
4262 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LED);
4263 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4264 pswpNew->y = swpClient.y;
4265 pswpNew->cx = 12;
4266 pswpNew->cy = 12;
4267 sCount++;
4268 pswpNew = (PSWP) mp1 + (soldCount + 4 +
4269 (fToolbar != FALSE) +
4270 (fDrivebar != FALSE) +
4271 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4272 *pswpNew = *pswpClient;
4273 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LEDHDR);
4274 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4275 pswpNew->y = swpClient.y + 12;
4276 pswpNew->cx = 12;
4277 pswpNew->cy = sheight - 8;
4278 sCount++;
4279 if (fUserComboBox) {
4280 if (!aheight) {
4281
4282 SWP swpTemp;
4283
4284 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4285 &swpTemp);
4286 aheight = swpTemp.cy;
4287 }
4288 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4289 (fToolbar != FALSE) +
4290 (fSplitStatus != FALSE) +
4291 (fDrivebar != FALSE) + (fAutoView != FALSE));
4292 *pswpNew = *pswpClient;
4293 pswpNew->hwnd = hwndDrivelist;
4294 pswpNew->x = swpClient.x;
4295 pswpNew->cx = 48;
4296 pswpClient->cy -= (aheight + 6L);
4297 pswpNew->y = pswpClient->y;
4298 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4299 sCount++;
4300 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4301 (fToolbar != FALSE) +
4302 (fDrivebar != FALSE) +
4303 (fSplitStatus != FALSE) +
4304 (fAutoView != FALSE));
4305 *pswpNew = *pswpClient;
4306 pswpNew->hwnd = hwndStatelist;
4307 pswpNew->x = swpClient.x + 48;
4308 pswpNew->cx = (swpClient.cx - 48) / 7;
4309 pswpNew->y = pswpClient->y;
4310 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4311 sCount++;
4312 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4313 (fToolbar != FALSE) +
4314 (fDrivebar != FALSE) +
4315 (fSplitStatus != FALSE) +
4316 (fAutoView != FALSE));
4317 *pswpNew = *pswpClient;
4318 pswpNew->hwnd = hwndCmdlist;
4319 pswpNew->x = swpClient.x + 48 + ((swpClient.cx - 48) / 7);
4320 pswpNew->cx = (swpClient.cx - 48) / 5 +
4321 ((swpClient.cx - 48) / 5) - ((swpClient.cx - 48) / 7);
4322 pswpNew->y = pswpClient->y;
4323 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4324 sCount++;
4325 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4326 (fToolbar != FALSE) +
4327 (fDrivebar != FALSE) +
4328 (fSplitStatus != FALSE) +
4329 (fAutoView != FALSE));
4330 *pswpNew = *pswpClient;
4331 pswpNew->hwnd = hwndUserlist;
4332 pswpNew->x = swpClient.x + 48 + (((swpClient.cx - 48) / 5) * 2);
4333 pswpNew->cx = ((swpClient.x + swpClient.cx) - pswpNew->x) -
4334 ((fToolbar) ? ((swpClient.cx - 48) / 7) : 0);
4335 pswpNew->y = pswpClient->y;
4336 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4337 sCount++;
4338 if (fToolbar) {
4339 pswpNew = (PSWP) mp1 + (soldCount + 9 +
4340 (fToolbar != FALSE) +
4341 (fDrivebar != FALSE) +
4342 (fSplitStatus != FALSE) +
4343 (fAutoView != FALSE));
4344 *pswpNew = *pswpClient;
4345 pswpNew->hwnd = hwndButtonlist;
4346 pswpNew->x = swpClient.cx - ((swpClient.cx - 48) / 7) + 4;
4347 pswpNew->cx = (swpClient.x + swpClient.cx) - pswpNew->x;
4348 pswpNew->y = pswpClient->y;
4349 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4350 sCount++;
4351 }
4352 else
4353 WinShowWindow(hwndButtonlist, FALSE);
4354 }
4355 else {
4356 WinShowWindow(hwndUserlist, FALSE);
4357 WinShowWindow(hwndDrivelist, FALSE);
4358 WinShowWindow(hwndStatelist, FALSE);
4359 WinShowWindow(hwndButtonlist, FALSE);
4360 WinShowWindow(hwndCmdlist, FALSE);
4361 }
4362 {
4363 PSWP pswpTitlebar = (PSWP) 0, pswpMinbutton = (PSWP) 0;
4364 SHORT x;
4365
4366 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4367 (fToolbar != FALSE) +
4368 (fDrivebar != FALSE) +
4369 (fSplitStatus != FALSE) +
4370 (fAutoView != FALSE) +
4371 ((fUserComboBox != FALSE) * 4) +
4372 (fUserComboBox != FALSE &&
4373 fToolbar != FALSE));
4374 pswp = (PSWP) mp1;
4375 for (x = 0; x < soldCount; x++) {
4376 if (!pswpTitlebar &&
4377 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_TITLEBAR)
4378 pswpTitlebar = pswp;
4379 else if (!pswpMinbutton &&
4380 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_MINMAX)
4381 pswpMinbutton = pswp;
4382 if (pswpTitlebar && pswpMinbutton)
4383 break;
4384 pswp++;
4385 }
4386 if (pswpMinbutton && pswpTitlebar) {
4387 *pswpNew = *pswpMinbutton;
4388 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_IDEALSIZE);
4389 pswpNew->cy = pswpMinbutton->cy + 3;
4390 pswpNew->cx = min(pswpNew->cy, (pswpMinbutton->cx / 2) + 3);
4391 pswpTitlebar->cx -= (pswpNew->cx - 1);
4392 pswpNew->x = pswpTitlebar->x + (pswpTitlebar->cx);
4393 pswpNew->y = pswpMinbutton->y - 1;
4394 sCount++;
4395 }
4396 else
4397 WinShowWindow(WinWindowFromID(hwnd, IDM_IDEALSIZE), FALSE);
4398 }
4399
4400 if (fMoreButtons) {
4401
4402 LONG lastx;
4403
4404 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4405 (fToolbar != FALSE) +
4406 (fDrivebar != FALSE) +
4407 (fSplitStatus != FALSE) +
4408 (fAutoView != FALSE) +
4409 ((fUserComboBox != FALSE) * 4) +
4410 (fUserComboBox != FALSE &&
4411 fToolbar != FALSE));
4412 *pswpNew = *pswpClient;
4413 pswpNew->hwnd = hwndName;
4414 pswpNew->x = swpClient.x + 3;
4415 pswpNew->y = swpClient.y + (sheight + 6);
4416 pswpNew->cx = ((swpClient.cx / 2) + (swpClient.cx / 5)) - 3;
4417 lastx = pswpNew->x + pswpNew->cx;
4418 pswpNew->cy = bheight;
4419 pswpClient->y += (bheight + 4);
4420 pswpClient->cy -= (bheight + 4);
4421 sCount++;
4422 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4423 (fToolbar != FALSE) +
4424 (fDrivebar != FALSE) +
4425 (fSplitStatus != FALSE) +
4426 (fAutoView != FALSE) +
4427 ((fUserComboBox != FALSE) * 4) +
4428 (fUserComboBox != FALSE &&
4429 fToolbar != FALSE));
4430 *pswpNew = *pswpClient;
4431 pswpNew->hwnd = hwndDate;
4432 pswpNew->x = lastx + 3;
4433 pswpNew->y = swpClient.y + (sheight + 6);
4434 pswpNew->cx = (swpClient.cx / 6) + (swpClient.cx / 16) - 3;
4435 lastx = pswpNew->x + pswpNew->cx;
4436 pswpNew->cy = bheight;
4437 sCount++;
4438 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4439 (fToolbar != FALSE) +
4440 (fDrivebar != FALSE) +
4441 (fSplitStatus != FALSE) +
4442 (fAutoView != FALSE) +
4443 ((fUserComboBox != FALSE) * 4) +
4444 (fUserComboBox != FALSE &&
4445 fToolbar != FALSE));
4446 *pswpNew = *pswpClient;
4447 pswpNew->hwnd = hwndAttr;
4448 pswpNew->x = lastx + 3;
4449 pswpNew->y = swpClient.y + (sheight + 6);
4450 pswpNew->cx = (swpClient.cx - pswpNew->x) - 1;
4451 pswpNew->cy = bheight;
4452 sCount++;
4453 }
4454 else {
4455 WinShowWindow(hwndAttr, FALSE);
4456 WinShowWindow(hwndName, FALSE);
4457 WinShowWindow(hwndDate, FALSE);
4458 }
4459 return MRFROMSHORT(sCount);
4460 }
4461
4462 case WM_QUERYFRAMECTLCOUNT:
4463 {
4464 SHORT sCount;
4465
4466 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4467
4468 sCount += 6;
4469 if (fSplitStatus)
4470 sCount++;
4471 if (fToolbar)
4472 sCount++;
4473 if (fUserComboBox) {
4474 sCount += 4;
4475 if (fToolbar)
4476 sCount++;
4477 }
4478 if (fDrivebar)
4479 sCount++;
4480 if (fAutoView)
4481 sCount++;
4482 if (fMoreButtons)
4483 sCount += 3;
4484 return MRFROMSHORT(sCount);
4485 }
4486
4487 case WM_CLOSE:
4488 WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
4489 return 0;
4490 }
4491 return oldproc(hwnd, msg, mp1, mp2);
4492}
4493
4494MRESULT EXPENTRY MainWMCommand(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
4495{
4496 SetShiftState();
4497 switch (SHORT1FROMMP(mp1)) {
4498
4499 case IDM_CONTEXTMENU:
4500 {
4501 HWND hwnd = WinQueryFocus(HWND_DESKTOP);
4502 // DbgMsg(pszSrcFile, __LINE__, "IDM_CONTEXTMENU %x", hwnd);
4503 if (hwnd != NULLHANDLE) {
4504 HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
4505 USHORT id = WinQueryWindowUShort(hwndParent, QWS_ID);
4506 switch (id) {
4507 case MAIN_SETUPLIST:
4508 case MAIN_USERLIST:
4509 case MAIN_CMDLIST:
4510 // DbgMsg(pszSrcFile, __LINE__, "WM_CONTEXTMENU");
4511 WinPostMsg(hwnd, WM_CONTEXTMENU, 0, 0);
4512 }
4513 }
4514 }
4515 break;
4516
4517 case IDM_SETTARGET:
4518 SetTargetDir(hwnd, FALSE);
4519 break;
4520
4521 case IDM_TOAUTOMLE:
4522 if (fComments && fAutoView)
4523 WinSetFocus(HWND_DESKTOP, hwndAutoMLE);
4524 break;
4525
4526 case IDM_HIDENOTEWND:
4527 HideNote();
4528 break;
4529 case IDM_SHOWNOTEWND:
4530 ShowNote();
4531 break;
4532
4533 case IDM_COMPARE:
4534 {
4535 WALK2 wa;
4536 PCNRITEM pci;
4537
4538 memset(&wa, 0, sizeof(wa));
4539 wa.size = sizeof(wa);
4540 pci =
4541 (PCNRITEM)
4542 WinSendMsg(WinWindowFromID
4543 (WinWindowFromID(hwndTree, FID_CLIENT), TREE_CNR),
4544 CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
4545 MPFROMSHORT(CRA_CURSORED));
4546 if (pci && (INT) pci != -1) {
4547 strcpy(wa.szCurrentPath1, pci->pszFileName);
4548 MakeValidDir(wa.szCurrentPath1);
4549 }
4550 else
4551 strcpy(wa.szCurrentPath1, pFM2SaveDirectory);
4552 TopWindowName(hwndMain, (HWND) 0, wa.szCurrentPath2);
4553 if (!*wa.szCurrentPath2)
4554 strcpy(wa.szCurrentPath2, wa.szCurrentPath1);
4555 MakeValidDir(wa.szCurrentPath2);
4556 if (WinDlgBox(HWND_DESKTOP,
4557 hwnd,
4558 WalkTwoCmpDlgProc,
4559 FM3ModHandle,
4560 WALK2_FRAME,
4561 MPFROMP(&wa)) &&
4562 !IsFile(wa.szCurrentPath1) && !IsFile(wa.szCurrentPath2)) {
4563 if (!*dircompare) {
4564
4565 COMPARE *cmp;
4566
4567 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
4568 if (cmp) {
4569 cmp->size = sizeof(COMPARE);
4570 strcpy(cmp->leftdir, wa.szCurrentPath1);
4571 strcpy(cmp->rightdir, wa.szCurrentPath2);
4572 cmp->hwndParent = hwnd;
4573 cmp->dcd.hwndParent = hwnd;
4574 WinDlgBox(HWND_DESKTOP,
4575 HWND_DESKTOP,
4576 CompareDlgProc, FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
4577 }
4578 }
4579 else {
4580
4581 CHAR szPath1[CCHMAXPATH];
4582 CHAR szPath2[CCHMAXPATH];
4583 runemf2(SEPARATE,
4584 HWND_DESKTOP, pszSrcFile, __LINE__,
4585 NULL, NULL,
4586 "%s %s %s",
4587 dircompare,
4588 BldQuotedFileName(szPath1, wa.szCurrentPath1),
4589 BldQuotedFileName(szPath2, wa.szCurrentPath2));
4590 }
4591 }
4592 }
4593 break;
4594
4595 case IDM_EXIT:
4596 case IDM_KILLME:
4597 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
4598 break;
4599
4600 case IDM_CLI:
4601 if (fSplitStatus &&
4602 hwndStatus2 &&
4603 !WinIsWindow(WinQueryAnchorBlock(hwnd),
4604 WinWindowFromID(hwndStatus2, COMMAND_LINE)))
4605 PostMsg(hwndStatus2, UM_CLICKED, MPVOID, MPVOID);
4606 break;
4607
4608 case IDM_ADDTOUSERLIST:
4609 case IDM_DELETEFROMUSERLIST:
4610 {
4611 CHAR temp[CCHMAXPATH], path[CCHMAXPATH];
4612
4613 *temp = 0;
4614 WinQueryWindowText(hwndUserlist, CCHMAXPATH, temp);
4615 bstrip(temp);
4616 if (*temp &&
4617 !DosQueryPathInfo(temp, FIL_QUERYFULLNAME, path, sizeof(path))) {
4618 if (SHORT1FROMMP(mp1) == IDM_ADDTOUSERLIST) {
4619 add_udir(TRUE, path);
4620 if (fUdirsChanged)
4621 save_udirs();
4622 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4623 }
4624 else {
4625 if (!remove_udir(path))
4626 Runtime_Error(pszSrcFile, __LINE__, "remove_udir");
4627 else {
4628 if (fUdirsChanged)
4629 save_udirs();
4630 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4631 }
4632 }
4633 }
4634 }
4635 break;
4636
4637 case IDM_SAVEDIRCNRSTATE:
4638 case IDM_DELETEDIRCNRSTATE:
4639 {
4640 CHAR szStateName[STATE_NAME_MAX_BYTES + 1];
4641
4642 *szStateName = 0;
4643 WinQueryWindowText(hwndStatelist, STATE_NAME_MAX_BYTES, szStateName);
4644 bstrip(szStateName);
4645 // Complain if attempting to use reserved name
4646 if (stricmp(szStateName, GetPString(IDS_STATETEXT)) == 0 ||
4647 stricmp(szStateName, GetPString(IDS_FM2TEMPTEXT)) == 0)
4648 {
4649 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4650 GetPString(IDS_WARNINGTEXT),
4651 "\"%s\" is a reserved state name", szStateName);
4652 }
4653 // Ignore request if blank
4654 else if (*szStateName) {
4655 BOOL fAbortOperation = FALSE;
4656 if (!fNoSaveState && fSaveState && stricmp(szStateName, GetPString(IDS_SHUTDOWNSTATE)) == 0)
4657 {
4658 if (saymsg(MB_YESNO | MB_DEFBUTTON2 | MB_ICONASTERISK, hwnd,
4659 GetPString(IDS_WARNINGTEXT),
4660 GetPString(IDS_SHUTDOWNSTATE_WARNING), szStateName) == MBID_NO)
4661 fAbortOperation = TRUE;
4662 }
4663 if (!fAbortOperation) {
4664 if (SHORT1FROMMP(mp1) == IDM_SAVEDIRCNRSTATE) {
4665 // Save
4666 INT nSaved = SaveDirCnrState(hwnd, szStateName);
4667 if (nSaved >= 0) {
4668 INT ret = add_setup(szStateName);
4669 if (ret == 0) {
4670 WinSendMsg(hwndStatelist, LM_INSERTITEM,
4671 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(szStateName));
4672 save_setups();
4673 }
4674 else if (ret != 1) {
4675 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4676 GetPString(IDS_WARNINGTEXT),
4677 "\"%s\" state name add failed", szStateName); // 15 Apr 07 SHL failed
4678 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
4679 }
4680 }
4681 else {
4682 saymsg(MB_ENTER | MB_ICONASTERISK,
4683 hwnd,
4684 GetPString(IDS_WARNINGTEXT),
4685 "State data save failed");
4686 WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
4687 }
4688 }
4689 else {
4690 // Delete
4691 ULONG numsaves = 0, size, x;
4692 CHAR s[STATE_NAME_MAX_BYTES + 80];
4693
4694 INT ret = remove_setup(szStateName);
4695 if (ret == 1)
4696 save_setups();
4697 sprintf(s, "%s.NumDirsLastTime", szStateName);
4698 size = sizeof(ULONG);
4699 if (!PrfQueryProfileData(fmprof,
4700 FM3Str,
4701 s,
4702 (PVOID)&numsaves,
4703 &size)) {
4704 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4705 GetPString(IDS_WARNINGTEXT),
4706 GetPString(IDS_DOESNTEXISTTEXT), szStateName);
4707 }
4708 else if (!size)
4709 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
4710 else {
4711 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0L);
4712 for (x = 0; x < numsaves; x++) {
4713 sprintf(s, "%s.DirCnrPos.%lu", szStateName, x);
4714 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4715 sprintf(s, "%s.DirCnrDir.%lu", szStateName, x);
4716 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4717 sprintf(s, "%s.DirCnrSort.%lu", szStateName, x);
4718 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4719 sprintf(s, "%s.DirCnrFilter.%lu", szStateName, x);
4720 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4721 sprintf(s, "%s.DirCnrView.%lu", szStateName, x);
4722 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4723 sprintf(s, "%s.DirCnr.%lu.DetailsLongname", szStateName, x);
4724 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4725 sprintf(s, "%s.DirCnr.%lu.DetailsSubject", szStateName, x);
4726 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4727 sprintf(s, "%s.DirCnr.%lu.DetailsSize", szStateName, x);
4728 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4729 sprintf(s, "%s.DirCnr.%lu.DetailsEA", szStateName, x);
4730 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4731 sprintf(s, "%s.DirCnr.%lu.DetailsAttr", szStateName, x);
4732 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4733 sprintf(s, "%s.DirCnr.%lu.DetailsIcon", szStateName, x);
4734 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4735 sprintf(s, "%s.DirCnr.%lu.DetailsLWDate", szStateName, x);
4736 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4737 sprintf(s, "%s.DirCnr.%lu.DetailsLWTime", szStateName, x);
4738 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4739 sprintf(s, "%s.DirCnr.%lu.DetailsLADate", szStateName, x);
4740 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4741 sprintf(s, "%s.DirCnr.%lu.DetailsLATime", szStateName, x);
4742 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4743 sprintf(s, "%s.DirCnr.%lu.DetailsCRDate", szStateName, x);
4744 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4745 sprintf(s, "%s.DirCnr.%lu.DetailsCRTime", szStateName, x);
4746 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4747 sprintf(s, "%s.DirCnr.%lu.Backgroundcolor", szStateName, x);
4748 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4749 sprintf(s, "%s.DirCnr.%lu.Fontnamesize", szStateName, x);
4750 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4751 }
4752 sprintf(s, "%s.LastTreePos", szStateName);
4753 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4754 sprintf(s, "%s.MySizeLastTime", szStateName);
4755 PrfWriteProfileData(fmprof, FM3Str, s, NULL, 0);
4756 }
4757 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
4758 }
4759 }
4760 }
4761 }
4762 break;
4763
4764 case IDM_IDEALSIZE:
4765 {
4766 SWP swp, swpD;
4767 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
4768 ULONG bsz = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
4769
4770 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4771 if (swp.fl & SWP_MAXIMIZE) {
4772 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_SYSCOMMAND,
4773 MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
4774 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4775 }
4776 WinGetMaxPosition(WinQueryWindow(hwnd, QW_PARENT), &swpD);
4777 swpD.x += bsz;
4778 swpD.cx -= (bsz * 2);
4779 swpD.y += icz;
4780 swpD.cy -= (icz + bsz);
4781 if (swp.x == swpD.x && swp.y == swpD.y &&
4782 swp.cx == swpD.cx && swp.cy == swpD.cy &&
4783 // fixme to be #defined someday
4784 WinQueryWindowUShort(hwnd, QWL_USER + 10) &&
4785 WinQueryWindowUShort(hwnd, QWL_USER + 14)) {
4786 swpD.x = WinQueryWindowUShort(hwnd, QWL_USER + 8);
4787 swpD.cx = WinQueryWindowUShort(hwnd, QWL_USER + 10);
4788 swpD.y = WinQueryWindowUShort(hwnd, QWL_USER + 12);
4789 swpD.cy = WinQueryWindowUShort(hwnd, QWL_USER + 14);
4790 }
4791 else {
4792 WinSetWindowUShort(hwnd, QWL_USER + 8, (USHORT) swp.x);
4793 WinSetWindowUShort(hwnd, QWL_USER + 10, (USHORT) swp.cx);
4794 WinSetWindowUShort(hwnd, QWL_USER + 12, (USHORT) swp.y);
4795 WinSetWindowUShort(hwnd, QWL_USER + 14, (USHORT) swp.cy);
4796 }
4797 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP,
4798 swpD.x, swpD.y, swpD.cx, swpD.cy, SWP_MOVE | SWP_SIZE);
4799 }
4800 break;
4801
4802 case IDM_BLINK:
4803 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
4804 SWP_MINIMIZE);
4805 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
4806 SWP_RESTORE | SWP_ZORDER);
4807 break;
4808
4809 case DID_CANCEL:
4810 {
4811 HWND hwndTop = TopWindow(hwndMain, (HWND) 0);
4812
4813 if (hwndTop)
4814 WinSetFocus(HWND_DESKTOP, hwndTop);
4815 }
4816 break;
4817
4818 case IDM_NOTEBOOK:
4819 case IDM_DIRCNRSETTINGS:
4820 case IDM_DIRVIEWSETTINGS:
4821 case IDM_DIRSORTSETTINGS:
4822 case IDM_COLLECTORVIEWSETTINGS:
4823 case IDM_COLLECTORSORTSETTINGS:
4824 case IDM_ARCHIVERSETTINGS:
4825 case IDM_TREECNRVIEWSETTINGS:
4826 case IDM_TREECNRSORTSETTINGS:
4827 case IDM_VIEWERSETTINGS:
4828 case IDM_VIEWERSETTINGS2:
4829 case IDM_COMPARESETTINGS:
4830 case IDM_MONOLITHICSETTINGS:
4831 case IDM_GENERALSETTINGS:
4832 case IDM_SCANSETTINGS:
4833 case IDM_BUBBLESSETTINGS:
4834 case IDM_QUICKSETTINGS:
4835 WinDlgBox(HWND_DESKTOP,
4836 hwnd, CfgDlgProc, FM3ModHandle, CFG_FRAME, MPFROMLONG(mp1));
4837 break;
4838
4839 case IDM_VIEWHELPS:
4840 case IDM_VIEWINFS:
4841 WinDlgBox(HWND_DESKTOP,
4842 HWND_DESKTOP,
4843 ViewInfProc,
4844 FM3ModHandle,
4845 VINF_FRAME,
4846 ((SHORT1FROMMP(mp1) == IDM_VIEWHELPS) ?
4847 MPFROMP(NullStr) : MPVOID));
4848 break;
4849
4850 case IDM_OPENWALK:
4851 {
4852 char newpath[CCHMAXPATH];
4853
4854 *newpath = 0;
4855 TopWindowName(hwnd, (HWND) 0, newpath);
4856 if (WinDlgBox(HWND_DESKTOP,
4857 hwnd,
4858 WalkAllDlgProc,
4859 FM3ModHandle, WALK_FRAME, MPFROMP(newpath)) && *newpath)
4860 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, newpath);
4861 }
4862 break;
4863
4864 case IDM_WINDOWDLG:
4865 WindowList(hwnd);
4866 break;
4867
4868 case IDM_HELPMOUSE:
4869 case IDM_HELPCONTEXT:
4870 case IDM_HELPHINTS:
4871 case IDM_HELPPIX:
4872 case IDM_HELPTUTOR:
4873 case IDM_HELPUSERLIST:
4874 case IDM_HELP:
4875 case IDM_HELPCONTENTS:
4876 case IDM_HELPKEYS:
4877 case IDM_HELPGENERAL:
4878 if (hwndHelp) {
4879 if (SHORT1FROMMP(mp2) == CMDSRC_MENU) {
4880
4881 RECTL rcl;
4882 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
4883
4884 WinQueryWindowRect(HWND_DESKTOP, &rcl);
4885 rcl.yBottom += icz;
4886 rcl.yTop -= icz;
4887 rcl.xLeft += icz;
4888 rcl.xRight -= icz;
4889 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
4890 }
4891 else {
4892
4893 RECTL rcl;
4894
4895 WinQueryWindowRect(HWND_DESKTOP, &rcl);
4896 rcl.yBottom += 8;
4897 rcl.yTop = (rcl.yTop / 2) + (rcl.yTop / 7);
4898 rcl.xLeft = (rcl.xRight / 2) - (rcl.xRight / 7);
4899 rcl.xRight -= 8;
4900 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
4901 }
4902 switch (SHORT1FROMMP(mp1)) {
4903 case IDM_HELPCONTEXT:
4904 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4905 MPFROM2SHORT(HELP_CONTEXT, 0), MPFROMSHORT(HM_RESOURCEID));
4906 break;
4907
4908 case IDM_HELPMOUSE:
4909 if (hwndHelp)
4910 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4911 MPFROM2SHORT(HELP_MOUSE, 0), MPFROMSHORT(HM_RESOURCEID));
4912 break;
4913
4914 case IDM_HELPPIX:
4915 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4916 MPFROM2SHORT(HELP_BITMAP1, 0), MPFROMSHORT(HM_RESOURCEID));
4917 break;
4918
4919 case IDM_HELPTUTOR:
4920 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4921 MPFROM2SHORT(HELP_TUTORIAL, 0),
4922 MPFROMSHORT(HM_RESOURCEID));
4923 break;
4924
4925 case IDM_HELPHINTS:
4926 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4927 MPFROM2SHORT(HELP_HINTS, 0), MPFROMSHORT(HM_RESOURCEID));
4928 break;
4929
4930 case IDM_HELPGENERAL:
4931 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4932 MPFROM2SHORT(HELP_MAIN, 0), MPFROMSHORT(HM_RESOURCEID));
4933 break;
4934 case IDM_HELPKEYS:
4935 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4936 MPFROM2SHORT(HELP_KEYS, 0), MPFROMSHORT(HM_RESOURCEID));
4937 break;
4938
4939 case IDM_HELP:
4940 case IDM_HELPCONTENTS:
4941 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
4942 break;
4943
4944 case IDM_HELPUSERLIST:
4945 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4946 MPFROM2SHORT(HELP_USERLISTS, 0),
4947 MPFROMSHORT(HM_RESOURCEID));
4948 break;
4949 }
4950 }
4951 break;
4952
4953 case IDM_EDITANYARCHIVER:
4954 EditArchiverDefinition(hwnd);
4955 break;
4956
4957 case IDM_ABOUT:
4958 WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, FM3ModHandle,
4959 ABT_FRAME, MPVOID);
4960 break;
4961
4962 case IDM_FONTPALETTE:
4963 OpenObject("<WP_FNTPAL>", Default, hwnd);
4964 break;
4965
4966 case IDM_HICOLORPALETTE:
4967 case IDM_COLORPALETTE:
4968 {
4969 CHAR *palette = "<WP_CLRPAL>";
4970 ULONG version[2];
4971
4972 if (!DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
4973 (PVOID) & version, (ULONG) sizeof(version))) {
4974 if (version[0] > 20L || (version[0] == 20L && version[1] > 29L)) {
4975 if (SHORT1FROMMP(mp1) == IDM_HICOLORPALETTE)
4976 palette = "<WP_HIRESCLRPAL>";
4977 else
4978 palette = "<WP_LORESCLRPAL>";
4979 }
4980 }
4981 OpenObject(palette, Default, hwnd);
4982 }
4983 break;
4984
4985 case IDM_SYSTEMSETUP:
4986 OpenObject("<WP_CONFIG>", Default, hwnd);
4987 break;
4988
4989 case IDM_SCHEMEPALETTE:
4990 {
4991 HOBJECT hWPSObject;
4992
4993 hWPSObject = WinQueryObject("<WP_SCHPAL>");
4994 if (hWPSObject != NULLHANDLE)
4995 WinSetObjectData(hWPSObject, "SCHEMES=Winter:PM_Winter,"
4996 "Spring:PM_Spring,Summer:PM_Summer,"
4997 "System:PM_System,Windows:PM_Windows;"
4998 "OPEN=DEFAULT");
4999 }
5000 break;
5001
5002 case IDM_SYSTEMCLOCK:
5003 OpenObject("<WP_CLOCK>", Default, hwnd);
5004 break;
5005
5006#ifdef NEVER
5007 case IDM_SYSINFO:
5008 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, SysInfoDlgProc, FM3ModHandle,
5009 SYS_FRAME, NULL);
5010 break;
5011#endif
5012
5013 case IDM_INSTANT:
5014 {
5015 CHAR path[CCHMAXPATH];
5016 PCNRITEM pci = (PCNRITEM) 0;
5017
5018 if (hwndTree)
5019 pci = (PCNRITEM) WinSendMsg(hwndTree, CM_QUERYRECORDEMPHASIS,
5020 MPFROMLONG(CMA_FIRST),
5021 MPFROMSHORT(CRA_CURSORED));
5022 if (pci && (INT) pci != -1) {
5023 strcpy(path, pci->pszFileName);
5024 MakeValidDir(path);
5025 }
5026 else
5027 strcpy(path, pFM2SaveDirectory);
5028 WinDlgBox(HWND_DESKTOP, hwnd, InstantDlgProc, FM3ModHandle,
5029 BAT_FRAME, MPFROMP(path));
5030 }
5031 break;
5032
5033 case IDM_WINFULLSCREEN:
5034 case IDM_DOSCOMMANDLINE:
5035 case IDM_COMMANDLINE:
5036 {
5037 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
5038 INT type = SEPARATE | WINDOWED;
5039
5040 *path = 0;
5041 TopWindowName(hwnd, (HWND) 0, path);
5042 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
5043 env = GetCmdSpec(TRUE);
5044 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
5045 env = "WINOS2.COM";
5046 type = SEPARATE | FULLSCREEN;
5047 }
5048 runemf2(type, hwnd, pszSrcFile, __LINE__,
5049 path, NULL, "%s", env);
5050 }
5051 break;
5052
5053 case IDM_KILLPROC:
5054 WinDlgBox(HWND_DESKTOP, hwnd, KillDlgProc, FM3ModHandle,
5055 KILL_FRAME, NULL);
5056 break;
5057
5058 case IDM_AUTOVIEWCOMMENTS:
5059 case IDM_AUTOVIEWFILE:
5060 if (SHORT1FROMMP(mp1) == IDM_AUTOVIEWFILE)
5061 fComments = FALSE;
5062 else
5063 fComments = TRUE;
5064 PrfWriteProfileData(fmprof, FM3Str, "Comments", &fComments, sizeof(BOOL));
5065 WinSetWindowText((fComments) ? hwndAutoview : hwndAutoMLE, NullStr);
5066 goto AutoChange;
5067
5068 case IDM_AUTOVIEW:
5069 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5070 &fAutoView, TRUE, "AutoView");
5071 AutoChange:
5072 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5073 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5074 if (fAutoView) {
5075
5076 CHAR s[CCHMAXPATH];
5077 HWND hwndDir;
5078 PCNRITEM pci;
5079
5080 hwndDir = TopWindowName(hwnd, (HWND) 0, s);
5081 if (hwndDir) {
5082 hwndDir = WinWindowFromID(hwndDir, FID_CLIENT);
5083 if (hwndDir) {
5084 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
5085 if (hwndDir) {
5086 pci = (PCNRITEM) WinSendMsg(hwndDir, CM_QUERYRECORDEMPHASIS,
5087 MPFROMLONG(CMA_FIRST),
5088 MPFROMSHORT(CRA_CURSORED));
5089 if (pci && (INT) pci != -1 &&
5090 (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW)))
5091 WinSendMsg(hwnd,
5092 UM_LOADFILE,
5093 MPFROMP(pci->pszFileName),
5094 (SHORT1FROMMP(mp1) == IDM_AUTOVIEW) ?
5095 MPVOID : MPFROMLONG(1));
5096 }
5097 }
5098 }
5099 }
5100 break;
5101
5102 case IDM_TEXTTOOLS:
5103 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5104 &fTextTools, TRUE, "TextTools");
5105 BuildTools(hwndToolback, TRUE);
5106 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5107 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5108 break;
5109
5110 case IDM_TOOLTITLES:
5111 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5112 &fToolTitles, TRUE, "ToolTitles");
5113 BuildTools(hwndToolback, TRUE);
5114 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5115 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5116 break;
5117
5118 case IDM_HIDEMENU:
5119 {
5120 HWND hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
5121 MenuInvisible = MenuInvisible ? FALSE : TRUE;
5122 if (MenuInvisible) {
5123 WinSetParent(hwndMenu, HWND_OBJECT, FALSE);
5124 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5125 FID_SYSMENU), IDM_HIDEMENU,
5126 GetPString(IDS_UNHIDEMENUTEXT));
5127 }
5128 else {
5129 WinSetParent(hwndMenu, WinQueryWindow(hwnd, QW_PARENT), FALSE);
5130 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5131 FID_SYSMENU), IDM_HIDEMENU,
5132 GetPString(IDS_HIDEMENUTEXT));
5133 }
5134 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5135 MPFROMLONG(FCF_MENU), MPVOID);
5136 PrfWriteProfileData(fmprof, FM3Str, "MenuInvisible",
5137 &MenuInvisible, sizeof(BOOL));
5138 }
5139 break;
5140
5141 case IDM_SEEALL:
5142 case IDM_GREP:
5143 case IDM_COLLECTOR:
5144 {
5145 HWND hwndC;
5146 SWP swp;
5147 BOOL already = FALSE;
5148
5149 if (Collector)
5150 already = TRUE;
5151 if (!already && !fAutoTile && !fExternalCollector)
5152 GetNextWindowPos(hwnd, &swp, NULL, NULL);
5153 hwndC = StartCollector(fExternalCollector ? HWND_DESKTOP : hwnd, 4);
5154 if (hwndC) {
5155 if (!already && !fAutoTile && !fExternalCollector)
5156 WinSetWindowPos(hwndC, HWND_TOP,
5157 swp.x, swp.y, swp.cx, swp.cy,
5158 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
5159 else if (fAutoTile && !already)
5160 TileChildren(hwnd, TRUE);
5161 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE |
5162 SWP_ACTIVATE);
5163 if (SHORT1FROMMP(mp1) == IDM_GREP)
5164 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5165 MPFROM2SHORT(IDM_GREP, 0), MPVOID);
5166 if (SHORT1FROMMP(mp1) == IDM_SEEALL)
5167 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5168 MPFROM2SHORT(IDM_SEEALL, 0), MPVOID);
5169 }
5170 }
5171 break;
5172
5173 case IDM_TOOLLEFT:
5174 case IDM_TOOLRIGHT:
5175 {
5176 TOOL *tool;
5177
5178 if (!toolhead || !toolhead->next) {
5179 firsttool = (toolhead) ? toolhead->id : 0;
5180 break;
5181 }
5182 tool = find_tool(firsttool);
5183 if (!tool)
5184 tool = toolhead;
5185 if (SHORT1FROMMP(mp1) == IDM_TOOLRIGHT) {
5186 tool = prev_tool(tool, TRUE);
5187 firsttool = tool->id;
5188 }
5189 else {
5190 tool = next_tool(tool, TRUE);
5191 firsttool = tool->id;
5192 }
5193 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5194 MAIN_TOOLS));
5195 }
5196 break;
5197
5198 case IDM_CREATETOOL:
5199 BuildTools(hwndToolback, TRUE);
5200 break;
5201
5202 case IDM_TOOLBAR:
5203 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5204 IDM_TOOLSUBMENU, &fToolbar, TRUE, "Toolbar");
5205 BuildTools(hwndToolback, TRUE);
5206 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5207 MAIN_TOOLS), fToolbar);
5208 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
5209 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5210 if (fDrivebar)
5211 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5212 MAIN_DRIVES), NULL, TRUE);
5213 break;
5214
5215 case IDM_DRIVEBAR:
5216 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5217 IDM_DRIVEBAR, &fDrivebar, TRUE, "Drivebar");
5218 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5219 MAIN_DRIVES), fDrivebar);
5220 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5221 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5222 PostMsg(hwnd, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
5223 break;
5224
5225 case IDM_USERLIST:
5226 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5227 SHORT1FROMMP(mp1), &fUserComboBox, TRUE, "UserComboBox");
5228 WinShowWindow(hwndUserlist, fUserComboBox);
5229 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5230 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5231 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
5232 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
5233 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5234 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
5235 break;
5236
5237 case IDM_MOREBUTTONS:
5238 WinSetWindowText(hwndName, NullStr);
5239 WinSetWindowText(hwndDate, NullStr);
5240 WinSetWindowText(hwndAttr, NullStr);
5241 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5242 SHORT1FROMMP(mp1), &fMoreButtons, TRUE, "MoreButtons");
5243 if (fMoreButtons) {
5244
5245 HWND hwndTemp;
5246
5247 hwndTemp = TopWindow(hwnd, (HWND) 0);
5248
5249 if (hwndTemp) {
5250 WinSetFocus(HWND_DESKTOP, hwnd);
5251 WinSetFocus(HWND_DESKTOP, hwndTemp);
5252 }
5253 }
5254 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5255 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5256 break;
5257
5258 case IDM_TOGGLEDRAGDIALOG:
5259 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5260 IDM_TOGGLEDRAGDIALOG,
5261 &fDragndropDlg,
5262 TRUE,
5263 "Drag&DropDlg");
5264 break;
5265
5266 case IDM_SYNCUPDATES:
5267 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5268 IDM_SYNCUPDATES,
5269 &fSyncUpdates,
5270 TRUE,
5271 "SyncUpdates");
5272 break;
5273
5274 case IDM_FREETREE:
5275 if (fFreeTree) {
5276 SWP swp, swpT;
5277
5278 WinQueryWindowPos(hwndTree, &swpT);
5279 WinQueryWindowPos(hwnd, &swp);
5280 WinSetWindowPos(hwndTree, HWND_TOP, 0, swp.cy - swpT.cy, 0, 0,
5281 SWP_MOVE);
5282 }
5283 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5284 &fFreeTree, TRUE, "FreeTree");
5285 if (fAutoTile)
5286 TileChildren(hwnd, TRUE);
5287 break;
5288
5289 case IDM_AUTOTILE:
5290 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5291 SHORT1FROMMP(mp1), &fAutoTile, TRUE, "AutoTile");
5292 if (fAutoTile)
5293 TileChildren(hwnd, TRUE);
5294 break;
5295
5296 case IDM_TILEBACKWARDS:
5297 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5298 SHORT1FROMMP(mp1), &fTileBackwards, TRUE, "TileBackwards");
5299 if (fAutoTile)
5300 TileChildren(hwnd, TRUE);
5301 break;
5302
5303 case IDM_NEXTWINDOW:
5304 case IDM_PREVWINDOW:
5305 NextChild(hwnd, (SHORT1FROMMP(mp1) == IDM_PREVWINDOW));
5306 break;
5307
5308 case IDM_CASCADE:
5309 CascadeChildren(hwnd);
5310 break;
5311
5312 case IDM_TILE:
5313 TileChildren(hwnd, TRUE);
5314 break;
5315
5316 case IDM_RESTORE:
5317 MinResChildren(hwnd, SWP_RESTORE);
5318 break;
5319
5320 case IDM_MINIMIZE:
5321 MinResChildren(hwnd, SWP_MINIMIZE);
5322 break;
5323
5324 case IDM_ARRANGEICONS:
5325 ArrangeIcons(hwnd);
5326 break;
5327
5328 case IDM_INIVIEWER:
5329 StartIniEditor(hwnd, NULL, 4);
5330 break;
5331
5332 case IDM_EDITASSOC:
5333 EditAssociations(hwnd);
5334 break;
5335
5336 case IDM_EDITCOMMANDS:
5337 EditCommands(hwnd);
5338 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5339 break;
5340
5341 default:
5342 if (!SwitchCommand((HWND) WinQueryWindowULong(hwnd, QWL_USER),
5343 SHORT1FROMMP(mp1))) {
5344 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
5345 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
5346
5347 INT x;
5348 HWND hwndCnr;
5349
5350 if (!cmdloaded)
5351 load_commands();
5352 hwndCnr = TopWindow(hwnd, (HWND) 0);
5353 hwndCnr = (HWND) WinSendMsg(WinWindowFromID(hwndCnr, FID_CLIENT),
5354 UM_CONTAINERHWND, MPVOID, MPVOID);
5355 if (!hwndCnr) {
5356 Runtime_Error2(pszSrcFile, __LINE__, IDS_NOWINDOWTEXT);
5357 break;
5358 }
5359 x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
5360 if (x >= 0) {
5361 x++;
5362 RunCommand(hwndCnr, x);
5363 if (fUnHilite) {
5364
5365 PCNRITEM pci;
5366 DIRCNRDATA *dcd = NULL;
5367
5368 // 12 May 07 SHL fixme to understand? backwards maybe? looking for DIR_CNR?
5369 if (WinQueryWindowUShort(hwndCnr, QWS_ID) != TREE_CNR)
5370 dcd = INSTDATA(hwndCnr);
5371 pci = (PCNRITEM) WinSendMsg(hwndCnr,
5372 CM_QUERYRECORDEMPHASIS,
5373 MPFROMLONG(CMA_FIRST),
5374 MPFROMSHORT(CRA_CURSORED));
5375 if (pci && (INT) pci != -1 &&
5376 (pci->rc.flRecordAttr & CRA_SELECTED))
5377 {
5378 UnHilite(hwnd,
5379 TRUE,
5380 dcd ? &dcd->lastselection : NULL,
5381 dcd ? dcd ->ulItemsToUnHilite : 0);
5382 }
5383 }
5384 }
5385 }
5386 else if (SHORT1FROMMP(mp1) >= IDM_QUICKTOOLSTART &&
5387 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART + 50) {
5388 if (!qtloaded)
5389 load_quicktools();
5390 if (quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]) {
5391 if (fToolsChanged)
5392 save_tools(NULL);
5393 if (!load_tools(quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]))
5394 load_tools(NULL);
5395 else {
5396 strcpy(lasttoolbox,
5397 quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART]);
5398 PrfWriteProfileString(fmprof, FM3Str, "LastToolBox", lasttoolbox);
5399 }
5400 BuildTools(hwndToolback, TRUE);
5401 }
5402 }
5403 else {
5404
5405 HWND hwndActive;
5406
5407 hwndActive = TopWindow(hwnd, (HWND) 0);
5408 if (hwndActive)
5409 PostMsg(WinWindowFromID(hwndActive, FID_CLIENT),
5410 WM_COMMAND, mp1, mp2);
5411 }
5412 }
5413 break; // default
5414 } // switch mp1
5415 return 0;
5416}
5417
5418static MRESULT EXPENTRY MainWMOnce(HWND hwnd, ULONG msg, MPARAM mp1,
5419 MPARAM mp2)
5420{
5421 TID tid;
5422 SWP swp;
5423 PFNWP oldproc;
5424 HWND hwndTmp;
5425 HWND hwndFrame;
5426 HWND hwndSysMenu, hwndSysSubMenu, hwndMenu;
5427 USHORT idSysMenu;
5428 MENUITEM mi, mit;
5429 ULONG size;
5430 BOOL temp = FALSE;
5431
5432 switch (msg) {
5433 case WM_CREATE:
5434 WinQueryWindowProcess(hwnd, &mypid, &tid);
5435 hwndMain = hwnd;
5436 WinSetWindowUShort(hwnd, QWL_USER + 8, 0);
5437 WinSetWindowUShort(hwnd, QWL_USER + 10, 0);
5438 WinSetWindowUShort(hwnd, QWL_USER + 12, 0);
5439 WinSetWindowUShort(hwnd, QWL_USER + 16, 0);
5440 if (_beginthread(MakeMainObjWin, NULL, 245760, MPVOID) == -1) {
5441 Runtime_Error(pszSrcFile, __LINE__,
5442 GetPString(IDS_COULDNTSTARTTHREADTEXT));
5443 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
5444 return 0;
5445 }
5446 else
5447 DosSleep(32);//05 Aug 07 GKY 64
5448
5449 hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
5450
5451 /*
5452 * create frame children (not client children, frame children)
5453 */
5454 DosSleep(1);
5455 WinQueryWindowPos(hwndFrame, &swp);
5456 oldproc = WinSubclassWindow(hwndFrame, MainFrameWndProc);
5457 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
5458 CommonCreateMainChildren(hwnd, &swp);
5459
5460 if (!WinCreateWindow(hwndFrame,
5461 WC_BUTTON,
5462 "I",
5463 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
5464 ((swp.cx -
5465 WinQuerySysValue(HWND_DESKTOP,
5466 SV_CXMINMAXBUTTON)) -
5467 WinQuerySysValue(HWND_DESKTOP,
5468 SV_CXMINMAXBUTTON) / 2) -
5469 WinQuerySysValue(HWND_DESKTOP,
5470 SV_CXSIZEBORDER),
5471 (swp.cy - WinQuerySysValue(HWND_DESKTOP,
5472 SV_CYMINMAXBUTTON)) -
5473 WinQuerySysValue(HWND_DESKTOP,
5474 SV_CYSIZEBORDER),
5475 WinQuerySysValue(HWND_DESKTOP,
5476 SV_CXMINMAXBUTTON) / 2,
5477 WinQuerySysValue(HWND_DESKTOP,
5478 SV_CYMINMAXBUTTON),
5479 hwnd, HWND_TOP, IDM_IDEALSIZE, NULL, NULL)) {
5480 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5481 }
5482 else {
5483 WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_IDEALSIZE),
5484 IdealButtonProc);
5485 SetPresParams(WinWindowFromID(hwndFrame,
5486 IDM_IDEALSIZE),
5487 NULL, NULL, NULL, GetPString(IDS_10SYSTEMVIOTEXT));
5488 }
5489
5490 hwndTmp = WinCreateWindow(hwndFrame,
5491 WC_BUTTON,
5492 "#1019",
5493 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5494 BS_BITMAP,
5495 swp.cx - 46,
5496 swp.y + 2,
5497 24,
5498 22, hwnd, HWND_TOP, IDM_OPENWALK, NULL, NULL);
5499 if (!hwndTmp)
5500 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5501
5502 hwndTmp = WinCreateWindow(hwndFrame,
5503 WC_BUTTON,
5504 "#3062",
5505 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5506 BS_BITMAP,
5507 swp.cx - 22,
5508 swp.y + 2,
5509 24,
5510 22, hwnd, HWND_TOP, IDM_USERLIST, NULL, NULL);
5511 if (!hwndTmp)
5512 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5513
5514 hwndUserlist = WinCreateWindow(hwndFrame,
5515 WC_COMBOBOX,
5516 (PSZ) NULL,
5517 WS_VISIBLE | CBS_DROPDOWN |
5518 LS_HORZSCROLL,
5519 (swp.x +
5520 WinQuerySysValue(HWND_DESKTOP,
5521 SV_CXSIZEBORDER) + 48L),
5522 (swp.cy -
5523 WinQuerySysValue(HWND_DESKTOP,
5524 SV_CYSIZEBORDER)) - 60,
5525 ((swp.cx -
5526 (WinQuerySysValue(HWND_DESKTOP,
5527 SV_CXSIZEBORDER) *
5528 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5529 MAIN_USERLIST, NULL, NULL);
5530 if (!hwndUserlist)
5531 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5532 hwndCmdlist = WinCreateWindow(hwndFrame,
5533 WC_COMBOBOX,
5534 (PSZ) NULL,
5535 WS_VISIBLE | CBS_DROPDOWN |
5536 LS_HORZSCROLL,
5537 (swp.x +
5538 WinQuerySysValue(HWND_DESKTOP,
5539 SV_CXSIZEBORDER) + 48L),
5540 (swp.cy -
5541 WinQuerySysValue(HWND_DESKTOP,
5542 SV_CYSIZEBORDER)) - 60,
5543 ((swp.cx -
5544 (WinQuerySysValue(HWND_DESKTOP,
5545 SV_CXSIZEBORDER) * 2)) -
5546 64L), 60L, hwndFrame, HWND_TOP,
5547 MAIN_CMDLIST, NULL, NULL);
5548 if (!hwndCmdlist)
5549 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5550 WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
5551 hwndStatelist = WinCreateWindow(hwndFrame,
5552 WC_COMBOBOX,
5553 (PSZ) NULL,
5554 WS_VISIBLE | CBS_DROPDOWN |
5555 LS_HORZSCROLL,
5556 (swp.x +
5557 WinQuerySysValue(HWND_DESKTOP,
5558 SV_CXSIZEBORDER) + 48L),
5559 (swp.cy -
5560 WinQuerySysValue(HWND_DESKTOP,
5561 SV_CYSIZEBORDER)) - 60,
5562 ((swp.cx -
5563 (WinQuerySysValue(HWND_DESKTOP,
5564 SV_CXSIZEBORDER) *
5565 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5566 MAIN_SETUPLIST, NULL, NULL);
5567 if (!hwndStatelist)
5568 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5569
5570 hwndDrivelist = WinCreateWindow(hwndFrame,
5571 WC_COMBOBOX,
5572 (PSZ) NULL,
5573 WS_VISIBLE | CBS_DROPDOWN,
5574 (swp.x +
5575 WinQuerySysValue(HWND_DESKTOP,
5576 SV_CXSIZEBORDER)),
5577 (swp.cy -
5578 WinQuerySysValue(HWND_DESKTOP,
5579 SV_CYSIZEBORDER)) - 60,
5580 48L,
5581 60L,
5582 hwndFrame,
5583 HWND_TOP, MAIN_DRIVELIST, NULL, NULL);
5584 if (!hwndDrivelist)
5585 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5586 SetPresParams(hwndDrivelist,
5587 NULL, NULL, NULL, GetPString(IDS_10SYSTEMMONOTEXT));
5588 hwndButtonlist = WinCreateWindow(hwndFrame,
5589 WC_COMBOBOX,
5590 (PSZ) NULL,
5591 WS_VISIBLE | CBS_DROPDOWN |
5592 LS_HORZSCROLL,
5593 (swp.cx -
5594 WinQuerySysValue(HWND_DESKTOP,
5595 SV_CXSIZEBORDER)) -
5596 164L,
5597 (swp.cy -
5598 WinQuerySysValue(HWND_DESKTOP,
5599 SV_CYSIZEBORDER)) - 60,
5600 164L, 60L, hwndFrame, HWND_TOP,
5601 MAIN_BUTTONLIST, NULL, NULL);
5602 if (!hwndButtonlist)
5603 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
5604 WinSendMsg(WinWindowFromID(hwndUserlist, CBID_EDIT),
5605 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
5606 WinSendMsg(WinWindowFromID(hwndStatelist, CBID_EDIT),
5607 EM_SETTEXTLIMIT, MPFROM2SHORT(STATE_NAME_MAX_BYTES, 0), MPVOID);
5608 WinSendMsg(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5609 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5610 WinSendMsg(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5611 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5612 WinSendMsg(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5613 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5614
5615 oldproc = WinSubclassWindow(WinWindowFromID(hwndUserlist, CBID_EDIT),
5616 DropDownListProc);
5617 WinSetWindowPtr(WinWindowFromID(hwndUserlist, CBID_EDIT),
5618 QWL_USER, (PVOID) oldproc);
5619 oldproc = WinSubclassWindow(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5620 DropDownListProc);
5621 WinSetWindowPtr(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5622 QWL_USER, (PVOID) oldproc);
5623 oldproc = WinSubclassWindow(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5624 DropDownListProc);
5625 WinSetWindowPtr(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5626 QWL_USER, (PVOID) oldproc);
5627 oldproc = WinSubclassWindow(WinWindowFromID(hwndStatelist, CBID_EDIT),
5628 DropDownListProc);
5629 WinSetWindowPtr(WinWindowFromID(hwndStatelist, CBID_EDIT),
5630 QWL_USER, (PVOID) oldproc);
5631 oldproc = WinSubclassWindow(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5632 DropDownListProc);
5633 WinSetWindowPtr(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5634 QWL_USER, (PVOID) oldproc);
5635 oldproc = WinSubclassWindow(hwndUserlist, DropDownListProc);
5636 WinSetWindowPtr(hwndUserlist, QWL_USER, (PVOID) oldproc);
5637 oldproc = WinSubclassWindow(hwndCmdlist, DropDownListProc);
5638 WinSetWindowPtr(hwndCmdlist, QWL_USER, (PVOID) oldproc);
5639 oldproc = WinSubclassWindow(hwndStatelist, DropDownListProc);
5640 WinSetWindowPtr(hwndStatelist, QWL_USER, (PVOID) oldproc);
5641 oldproc = WinSubclassWindow(hwndDrivelist, DropDownListProc);
5642 WinSetWindowPtr(hwndDrivelist, QWL_USER, (PVOID) oldproc);
5643 oldproc = WinSubclassWindow(hwndButtonlist, DropDownListProc);
5644 WinSetWindowPtr(hwndButtonlist, QWL_USER, (PVOID) oldproc);
5645 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_USERLIST),
5646 ChildFrameButtonProc);
5647 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_USERLIST),
5648 QWL_USER, (PVOID) oldproc);
5649 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5650 ChildFrameButtonProc);
5651 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5652 QWL_USER, (PVOID) oldproc);
5653 hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
5654 WinSendMsg(hwnd, UM_ADDTOMENU, MPVOID, MPVOID);
5655 SetToggleChecks(hwndMenu);
5656 CfgMenuInit(hwndMenu, FALSE); // 14 Feb 08 SHL
5657 SetConditionalCascade(hwndMenu, IDM_COMMANDLINESUBMENU, IDM_COMMANDLINE);
5658 SetConditionalCascade(hwndMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
5659 SetConditionalCascade(hwndMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
5660 SetConditionalCascade(hwndMenu, IDM_TILEMENU, IDM_TILE);
5661 WinSetWindowULong(hwnd, QWL_USER, hwndMenu);
5662 memset(&mi, 0, sizeof(mi));
5663 memset(&mit, 0, sizeof(mit));
5664 hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
5665 idSysMenu = SHORT1FROMMR(WinSendMsg(hwndSysMenu,
5666 MM_ITEMIDFROMPOSITION,
5667 MPVOID, MPVOID));
5668 WinSendMsg(hwndSysMenu,
5669 MM_QUERYITEM, MPFROM2SHORT(idSysMenu, 0), MPFROMP(&mit));
5670 hwndSysSubMenu = mit.hwndSubMenu;
5671 mi.iPosition = MIT_END;
5672 mi.afStyle = MIS_SEPARATOR;
5673 mi.id = (USHORT) - 1;
5674 WinSendMsg(hwndSysSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(NULL));
5675 mi.afStyle = MIS_TEXT;
5676 mi.id = IDM_IDEALSIZE;
5677 WinSendMsg(hwndSysSubMenu,
5678 MM_INSERTITEM,
5679 MPFROMP(&mi), MPFROMP(GetPString(IDS_IDEALMENUTEXT)));
5680 mi.afStyle = MIS_TEXT;
5681 mi.id = IDM_HIDEMENU;
5682 WinSendMsg(hwndSysSubMenu,
5683 MM_INSERTITEM,
5684 MPFROMP(&mi), MPFROMP(GetPString(IDS_HIDEMENUTEXT)));
5685 SetSysMenu(hwndSysMenu);
5686
5687 size = sizeof(BOOL);
5688 if (PrfQueryProfileData(fmprof,
5689 FM3Str,
5690 "MenuInvisible", &temp, &size) && size && temp)
5691 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HIDEMENU, 0), MPVOID);
5692 size = sizeof(BOOL);
5693 if (PrfQueryProfileData(fmprof,
5694 FM3Str, "FreeTree", &temp, &size) && size && temp)
5695 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_FREETREE, 0), MPVOID);
5696 size = sizeof(BOOL);
5697 if (PrfQueryProfileData(fmprof,
5698 FM3Str,
5699 "AutoTile", &temp, &size) && size && !temp)
5700 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_AUTOTILE, 0), MPVOID);
5701 size = sizeof(BOOL);
5702 if (PrfQueryProfileData(fmprof,
5703 FM3Str, "Toolbar", &temp, &size) && size && !temp)
5704 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TOOLBAR, 0), MPVOID);
5705
5706 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR), "FM/2");
5707 FixSwitchList(hwndFrame, NULL);
5708 break; // WM_CREATE
5709
5710 case UM_SETUP:
5711 /*
5712 * start up some initial children
5713 */
5714 load_tools(NULL);
5715 BuildTools(hwndToolback, TRUE);
5716 WinShowWindow(WinQueryWindow(hwnd, QW_PARENT), TRUE);
5717 PostMsg(MainObjectHwnd, UM_SETUP2, mp1, mp2);
5718 return 0;
5719
5720 case UM_SETUP2:
5721 {
5722 SWP swp;
5723 ULONG size = sizeof(SWP);
5724
5725 WinQueryWindowPos(hwnd, &swp);
5726 hwndTree = StartTreeCnr(hwnd, 4);
5727 if (!hwndTree)
5728 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
5729 else {
5730 if (!fSaveState ||
5731 !PrfQueryProfileData(fmprof,
5732 FM3Str,
5733 "LastTreePos",
5734 &swp, &size) || size != sizeof(SWP)) {
5735
5736 INT ratio, height = 0;
5737
5738 if (!fNoTreeGap)
5739 height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
5740 size = sizeof(ratio);
5741 if (!PrfQueryProfileData(fmprof,
5742 FM3Str,
5743 "TreeWindowRatio",
5744 (PVOID) & ratio,
5745 &size) || size < sizeof(ratio))
5746 ratio = 400;
5747 WinSetWindowPos(hwndTree,
5748 HWND_TOP,
5749 0,
5750 height,
5751 (swp.cx * 100) / ratio,
5752 swp.cy - height,
5753 SWP_SHOW | SWP_SIZE | SWP_MOVE |
5754 SWP_ACTIVATE | SWP_ZORDER);
5755 }
5756 else
5757 WinSetWindowPos(hwndTree,
5758 HWND_TOP,
5759 swp.x,
5760 swp.y,
5761 swp.cx,
5762 swp.cy,
5763 swp.fl | SWP_MOVE | SWP_SIZE | SWP_SHOW |
5764 SWP_ZORDER | SWP_ACTIVATE);
5765 }
5766 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5767 MAIN_TOOLS));
5768 }
5769 PostMsg(MainObjectHwnd, UM_SETUP3, mp1, mp2);
5770 return 0;
5771
5772 case UM_SETUP3:
5773 /* start remaining child windows */
5774 if (!fNoSaveState && fSaveState) {
5775 PSZ pszStatename = GetPString(IDS_SHUTDOWNSTATE);
5776 PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszStatename), MPVOID);
5777 if (!add_setup(pszStatename))
5778 save_setups();
5779 }
5780 PostMsg(MainObjectHwnd, UM_SETUP4, mp1, mp2);
5781 return 0;
5782
5783 case UM_SETUP4:
5784 {
5785 INT argc = (INT) mp1, x;
5786 CHAR **argv = (CHAR **) mp2;
5787
5788 for (x = 1; x < argc; x++) {
5789 if (*argv[x] == '/' || *argv[x] == ';')
5790 continue;
5791 if (!IsFile(argv[x]) && !FindDirCnrByName(argv[x], FALSE))
5792 OpenDirCnr((HWND) 0, hwndMain, hwndTree, TRUE, argv[x]);
5793 }
5794 }
5795 PostMsg(MainObjectHwnd, UM_SETUP5, MPVOID, MPVOID);
5796 return 0;
5797
5798 case UM_SETUP5:
5799// if (fAutoTile)
5800// TileChildren(hwnd, TRUE);
5801 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
5802 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
5803 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5804 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
5805 {
5806 HWND hwndActive;
5807
5808 hwndActive = TopWindow(hwnd, hwndTree);
5809 if (hwndActive)
5810 WinSetWindowPos(hwndActive, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
5811 }
5812 if (fStartMinimized || fReminimize)
5813 PostMsg(hwndTree, UM_MINIMIZE, MPVOID, MPVOID);
5814 else if (fStartMaximized)
5815 PostMsg(hwndTree, UM_MAXIMIZE, MPVOID, MPVOID);
5816 fRunning = TRUE;
5817 if (fWantFirstTimeInit) {
5818 fWantFirstTimeInit = FALSE;
5819 PostMsg(hwnd, WM_COMMAND, MPFROMLONG(IDM_QUICKSETTINGS), MPVOID);
5820 }
5821 return 0;
5822 }
5823
5824 return WinDefWindowProc(hwnd, msg, mp1, mp2);
5825}
5826
5827MRESULT EXPENTRY MainWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
5828{
5829 switch (msg) {
5830 case WM_CREATE:
5831# ifdef FORTIFY
5832 Fortify_EnterScope();
5833# endif
5834 case UM_SETUP:
5835 case UM_SETUP2:
5836 case UM_SETUP3:
5837 case UM_SETUP4:
5838 case UM_SETUP5:
5839 return MainWMOnce(hwnd, msg, mp1, mp2);
5840
5841 case WM_CONTROLPOINTER:
5842 if (!fNoFinger &&
5843 (SHORT1FROMMP(mp1) == IDM_OPENWALK ||
5844 SHORT1FROMMP(mp1) == IDM_USERLIST))
5845 return MRFROMLONG(hptrFinger);
5846 break;
5847
5848 case UM_LOADFILE:
5849 case UM_THREADUSE:
5850 case UM_BUILDDRIVEBAR:
5851 return CommonMainWndProc(hwnd, msg, mp1, mp2);
5852
5853 case WM_BUTTON1UP:
5854 case WM_BUTTON2UP:
5855 case WM_BUTTON3UP:
5856 case WM_MOUSEMOVE:
5857 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
5858 break;
5859
5860 case WM_CHAR:
5861 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
5862 break;
5863
5864 case WM_MENUEND:
5865 if ((HWND) mp2 == MainPopupMenu) {
5866 WinDestroyWindow(MainPopupMenu);
5867 MainPopupMenu = (HWND) 0;
5868 }
5869 break;
5870
5871 case UM_CONTEXTMENU:
5872 case WM_CONTEXTMENU:
5873 if (CheckMenu(hwndMainMenu, &MainPopupMenu, MAIN_POPUP)) {
5874 SetToggleChecks(MainPopupMenu);
5875 PopupMenu(hwnd, hwnd, MainPopupMenu);
5876 }
5877 if (msg == UM_CONTEXTMENU)
5878 return 0;
5879 return MRFROMSHORT(TRUE);
5880
5881 case UM_SETUSERLISTNAME:
5882 if (mp1) {
5883 if (fUserComboBox)
5884 WinSetWindowText(WinWindowFromID(hwndUserlist, CBID_EDIT),
5885 (CHAR *)mp1);
5886 if (add_udir(FALSE, (CHAR *)mp1)) {
5887 if (fUserComboBox && fAutoAddDirs) {
5888 WinSendMsg(hwndUserlist, LM_INSERTITEM,
5889 MPFROM2SHORT(LIT_SORTASCENDING, 0),
5890 MPFROMP((CHAR *)mp1));
5891 }
5892 }
5893 }
5894 return 0;
5895
5896 case UM_ARRANGEICONS:
5897 ArrangeIcons(hwnd);
5898 return 0;
5899
5900 case WM_CHORD:
5901 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
5902 break;
5903
5904 case WM_SETFOCUS:
5905 if (mp2)
5906 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
5907 break;
5908
5909 case UM_FOCUSME:
5910 WinSetFocus(hwndTree, TRUE);
5911 return 0;
5912
5913 case UM_RESCAN:
5914 TileChildren(hwnd, TRUE);
5915 return 0;
5916
5917 case WM_SAVEAPPLICATION:
5918 {
5919 SWP swp;
5920
5921 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
5922 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
5923 WinStoreWindowPos(FM2Str,
5924 "MainWindowPos", WinQueryWindow(hwnd, QW_PARENT));
5925 if (!fNoSaveState && fSaveState)
5926 SaveDirCnrState(hwnd, GetPString(IDS_SHUTDOWNSTATE));
5927 }
5928 }
5929 break;
5930
5931 case MM_PORTHOLEINIT:
5932 switch (SHORT1FROMMP(mp1)) {
5933 case 0:
5934 case 1:
5935 {
5936 HWND hwndCurrent;
5937 ULONG wmsg;
5938
5939 wmsg = (SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU;
5940 hwndCurrent = TopWindow(hwnd, (HWND) 0);
5941 PortholeInit((HWND) WinSendMsg(WinWindowFromID(hwndCurrent,
5942 FID_CLIENT), wmsg,
5943 MPVOID, MPVOID), mp1, mp2);
5944 }
5945 break;
5946 }
5947 break;
5948
5949 case WM_INITMENU:
5950 switch (SHORT1FROMMP(mp1)) {
5951 case IDM_CONFIGMENU:
5952 SetToggleChecks((HWND) WinQueryWindowULong(hwnd, QWL_USER));
5953 break;
5954
5955 case IDM_WINDOWSMENU:
5956 /*
5957 * add child windows of client
5958 * and switchlist entries to end of pulldown menu
5959 */
5960 {
5961 HWND hwndMenu, hwndSubMenu;
5962 MENUITEM mi;
5963
5964 hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
5965 memset(&mi, 0, sizeof(mi));
5966 mi.iPosition = MIT_END;
5967 mi.afStyle = MIS_TEXT;
5968 if (!WinSendMsg(hwndMenu, MM_QUERYITEM,
5969 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
5970 break;
5971 hwndSubMenu = mi.hwndSubMenu;
5972 SetupWinList(hwndSubMenu, hwnd, WinQueryWindow(hwnd, QW_PARENT));
5973 }
5974 break;
5975
5976 default:
5977 {
5978 HWND hwndCurrent;
5979
5980 hwndCurrent = TopWindow(hwnd, (HWND) 0);
5981 if (hwndCurrent)
5982 WinSendMsg(hwndCurrent, UM_INITMENU, mp1, mp2);
5983 }
5984 break;
5985 }
5986 break;
5987
5988 case UM_ADDTOMENU:
5989 AddToMenu((CHAR *)mp1, WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5990 FID_MENU));
5991 return 0;
5992
5993 case UM_FILLCMDLIST:
5994 WinSendMsg(hwndCmdlist, LM_DELETEALL, MPVOID, MPVOID);
5995 if (!cmdloaded)
5996 load_commands();
5997 if (cmdhead) {
5998
5999 LINKCMDS *info;
6000
6001 info = cmdhead;
6002 while (info) {
6003 WinSendMsg(hwndCmdlist, LM_INSERTITEM,
6004 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->title));
6005 info = info->next;
6006 }
6007 }
6008 return 0;
6009
6010 case UM_FILLSETUPLIST:
6011 fill_setups_list();
6012 return 0;
6013
6014 case UM_FILLBUTTONLIST:
6015 WinSendMsg(hwndButtonlist, LM_DELETEALL, MPVOID, MPVOID);
6016 if (fUserComboBox) {
6017
6018 BOOL foundit = FALSE, thisone;
6019 ULONG ulSearchCount;
6020 SHORT sSelect;
6021 FILEFINDBUF3 findbuf;
6022 HDIR hDir;
6023 CHAR *p;
6024
6025 DosError(FERR_DISABLEHARDERR);
6026 hDir = HDIR_CREATE;
6027 ulSearchCount = 1;
6028 if (!DosFindFirst("*.TLS", &hDir, FILE_READONLY | FILE_ARCHIVED,
6029 &findbuf, sizeof(FILEFINDBUF3),
6030 &ulSearchCount, FIL_STANDARD)) {
6031 do {
6032 priority_bumped();
6033 if (!foundit) {
6034 thisone = FALSE;
6035 p = strrchr(lasttoolbox, '\\');
6036 if (!p)
6037 p = lasttoolbox;
6038 else
6039 p++;
6040 if (!stricmp(findbuf.achName, p))
6041 thisone = TRUE;
6042 }
6043 p = strrchr(findbuf.achName, '.');
6044 if (p)
6045 *p = 0;
6046 sSelect = (SHORT) WinSendMsg(hwndButtonlist, LM_INSERTITEM,
6047 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6048 MPFROMP(findbuf.achName));
6049 if (!foundit && thisone && sSelect >= 0) {
6050 WinSendMsg(hwndButtonlist, LM_SELECTITEM,
6051 MPFROM2SHORT(sSelect, 0), MPFROMLONG(TRUE));
6052 foundit = TRUE;
6053 }
6054 }
6055 while (!DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3),
6056 &ulSearchCount));
6057 DosFindClose(hDir);
6058 priority_bumped();
6059 }
6060 WinSetWindowText(hwndButtonlist, GetPString(IDS_TOOLBOXTEXT));
6061 }
6062 return 0;
6063
6064 case UM_FILLUSERLIST:
6065 WinSendMsg(hwndUserlist, LM_DELETEALL, MPVOID, MPVOID);
6066 if (fUserComboBox) {
6067 ULONG ulDriveNum;
6068 ULONG ulDriveMap;
6069 ULONG ulSearchCount;
6070 FILEFINDBUF3 findbuf;
6071 HDIR hDir;
6072 APIRET rc;
6073 LINKDIRS *info;
6074 LINKDIRS *temp;
6075
6076 if (!loadedudirs)
6077 load_udirs();
6078 DosError(FERR_DISABLEHARDERR);
6079 DosQCurDisk(&ulDriveNum, &ulDriveMap);
6080 info = udirhead;
6081 while (info) {
6082 if (IsFullName(info->path) &&
6083 !(driveflags[toupper(*info->path) - 'A'] &
6084 (DRIVE_IGNORE | DRIVE_INVALID))) {
6085 DosError(FERR_DISABLEHARDERR);
6086 hDir = HDIR_CREATE;
6087 ulSearchCount = 1;
6088 if (!IsRoot(info->path))
6089 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6090 MUST_HAVE_DIRECTORY | FILE_READONLY |
6091 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6092 &findbuf, sizeof(FILEFINDBUF3),
6093 &ulSearchCount, FIL_STANDARD);
6094 else {
6095 rc = 0;
6096 findbuf.attrFile = FILE_DIRECTORY;
6097 }
6098 priority_bumped();
6099 if (!rc) {
6100 if (!IsRoot(info->path))
6101 DosFindClose(hDir);
6102 if (findbuf.attrFile & FILE_DIRECTORY)
6103 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6104 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6105 MPFROMP(info->path));
6106 else {
6107 temp = info->next;
6108 remove_udir(info->path);
6109 info = temp;
6110 continue;
6111 }
6112 }
6113 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6114 temp = info->next;
6115 remove_udir(info->path);
6116 info = temp;
6117 continue;
6118 }
6119 }
6120 info = info->next;
6121 }
6122 info = ldirhead;
6123 while (info) {
6124 if (IsFullName(info->path) &&
6125 !(driveflags[toupper(*info->path) - 'A'] &
6126 (DRIVE_IGNORE | DRIVE_INVALID))) {
6127 DosError(FERR_DISABLEHARDERR);
6128 hDir = HDIR_CREATE;
6129 ulSearchCount = 1;
6130 if (!IsRoot(info->path))
6131 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6132 MUST_HAVE_DIRECTORY | FILE_READONLY |
6133 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6134 &findbuf, sizeof(FILEFINDBUF3),
6135 &ulSearchCount, FIL_STANDARD);
6136 else {
6137 rc = 0;
6138 findbuf.attrFile = FILE_DIRECTORY;
6139 }
6140 priority_bumped();
6141 if (!rc) {
6142 if (!IsRoot(info->path))
6143 DosFindClose(hDir);
6144 if (findbuf.attrFile & FILE_DIRECTORY)
6145 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6146 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6147 MPFROMP(info->path));
6148 else {
6149 temp = info->next;
6150 remove_udir(info->path);
6151 info = temp;
6152 continue;
6153 }
6154 }
6155 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6156 temp = info->next;
6157 remove_udir(info->path);
6158 info = temp;
6159 continue;
6160 }
6161 }
6162 info = info->next;
6163 }
6164 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6165 MPFROM2SHORT(0, 0),
6166 MPFROMP(GetPString(IDS_NEWDIRECTORYTEXT)));
6167 WinSetWindowText(hwndUserlist, GetPString(IDS_COMMONDIRTEXT));
6168 }
6169 return 0;
6170
6171 case UM_SIZE:
6172 if (fAutoTile)
6173 TileChildren(hwnd, FALSE);
6174 else
6175 MoveChildrenAwayFromTree(hwnd);
6176 return 0;
6177
6178 case WM_SIZE:
6179 ResizeChildren(hwnd, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),
6180 SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
6181 break;
6182
6183 case WM_ERASEBACKGROUND:
6184 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
6185 return 0;
6186
6187 case WM_PAINT:
6188 {
6189 HPS hps;
6190 RECTL rcl;
6191
6192 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
6193 if (hps) {
6194 WinQueryWindowRect(hwnd, &rcl);
6195 WinFillRect(hps, &rcl, CLR_PALEGRAY);
6196 WinEndPaint(hps);
6197 }
6198 }
6199 break;
6200
6201 case UM_CONTROL:
6202 switch (SHORT1FROMMP(mp1)) {
6203 case MAIN_CMDLIST:
6204 case MAIN_SETUPLIST:
6205 case MAIN_DRIVELIST:
6206 case MAIN_USERLIST:
6207 case MAIN_BUTTONLIST:
6208 switch (SHORT2FROMMP(mp1)) {
6209 case CBN_ENTER:
6210 {
6211 HWND hwndUL = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
6212 SHORT1FROMMP(mp1));
6213 CHAR path[CCHMAXPATH];
6214 ULONG ul;
6215
6216 switch (SHORT1FROMMP(mp1)) {
6217 case MAIN_USERLIST:
6218 ul = CCHMAXPATH;
6219 break;
6220 case MAIN_SETUPLIST:
6221 ul = STATE_NAME_MAX_BYTES;
6222 break;
6223 default:
6224 ul = 13; // fixme to not be hardcoded
6225 }
6226
6227 SetShiftState();
6228 WinQueryWindowText(WinWindowFromID(hwndUL, CBID_EDIT), ul, path);
6229 bstrip(path);
6230 if (*path) {
6231 if (SHORT1FROMMP(mp1) == MAIN_USERLIST) {
6232 if (!strcmp(path, GetPString(IDS_NEWDIRECTORYTEXT))) {
6233 if (!LastDir ||
6234 !WinSendMsg(WinQueryWindow(LastDir, QW_PARENT),
6235 UM_CONTAINERDIR, MPFROMP(path), MPVOID))
6236 strcpy(path, pFM2SaveDirectory);
6237 if (!PMMkDir(hwnd, path, TRUE)) {
6238 WinSetWindowText(hwndUL, GetPString(IDS_COMMONDIRTEXT));
6239 break;
6240 }
6241 }
6242 if (!IsFile(path) && !FindDirCnrByName(path, TRUE)) {
6243
6244 HWND hwndDir;
6245
6246 if ((fUserListSwitches &&
6247 !(shiftstate & KC_SHIFT)) ||
6248 (!fUserListSwitches && (shiftstate & KC_SHIFT))) {
6249 hwndDir = FindDirCnr(hwnd);
6250 if (hwndDir) {
6251 WinSendMsg(LastDir, UM_SETDIR, MPFROMP(path), MPVOID);
6252 break;
6253 }
6254 }
6255 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, path);
6256 }
6257 }
6258 else if (SHORT1FROMMP(mp1) == MAIN_DRIVELIST) {
6259 ShowTreeRec(WinWindowFromID(WinWindowFromID(hwndTree,
6260 FID_CLIENT),
6261 TREE_CNR), path, FALSE, TRUE);
6262 WinSetFocus(HWND_DESKTOP, hwndTree);
6263 }
6264 else if (SHORT1FROMMP(mp1) == MAIN_BUTTONLIST) {
6265 strcat(path, ".TLS");
6266 load_tools(path);
6267 PrfWriteProfileString(fmprof,
6268 FM3Str, "LastToolBox", lasttoolbox);
6269 BuildTools(hwndToolback, TRUE);
6270 WinSetWindowText(hwndButtonlist, GetPString(IDS_TOOLBOXTEXT));
6271 }
6272 else if (SHORT1FROMMP(mp1) == MAIN_SETUPLIST) {
6273 CHAR szKey[80];
6274 ULONG size, numsaves = 0;
6275
6276 SetShiftState();
6277 size = sizeof(ULONG);
6278 sprintf(szKey, "%s.NumDirsLastTime", path); // path is state name
6279 if (!PrfQueryProfileData(fmprof,
6280 FM3Str,
6281 szKey,
6282 (PVOID)&numsaves,
6283 &size))
6284 {
6285 if ((WinGetLastError(WinQueryAnchorBlock(hwnd)) & 0xffff) == PMERR_NOT_IN_IDX) {
6286 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
6287 GetPString(IDS_WARNINGTEXT),
6288 GetPString(IDS_DOESNTEXISTTEXT), path);
6289 }
6290 else {
6291 Win_Error2(hwnd, hwnd, __FILE__, __LINE__,
6292 IDS_PRFQUERYPROFILEDATA);
6293 }
6294 }
6295 else {
6296 char *pszStateName;
6297 if ((shiftstate & KC_SHIFT) == 0)
6298 PostMsg(MainObjectHwnd, UM_RESTORE, MPVOID, MPFROMLONG(2));
6299 pszStateName = xstrdup(path, pszSrcFile, __LINE__);
6300 if (!pszStateName) {
6301 // Fall back if out of memory - already complained
6302 if ((shiftstate & KC_SHIFT) != 0 || fAutoTile) {
6303 // Autotile requested or forced
6304 PostMsg(MainObjectHwnd,
6305 UM_RESTORE,
6306 MPVOID,
6307 MPFROMLONG(1)); // Autotile
6308 }
6309 }
6310 else if (!PostMsg(MainObjectHwnd,
6311 UM_RESTORE,
6312 MPFROMP(pszStateName),
6313 MPVOID)) {
6314 free(pszStateName);
6315 }
6316 }
6317 }
6318 else if (SHORT1FROMMP(mp1) == MAIN_CMDLIST) {
6319
6320 SHORT sSelect;
6321
6322 sSelect = (SHORT) WinSendMsg(hwndCmdlist,
6323 LM_QUERYSELECTION,
6324 MPFROMSHORT(LIT_FIRST), MPVOID);
6325 if (sSelect >= 0)
6326 WinPostMsg(hwnd,
6327 WM_COMMAND,
6328 MPFROM2SHORT(IDM_COMMANDSTART + sSelect, 0),
6329 MPVOID);
6330 WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
6331 }
6332 }
6333 }
6334 break;
6335
6336 default:
6337 break;
6338 }
6339 break;
6340
6341 default:
6342 break;
6343 }
6344 return 0;
6345
6346 case WM_HELP:
6347 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
6348 break;
6349
6350 case UM_COMMAND:
6351 case WM_COMMAND:
6352
6353 return MainWMCommand(hwnd, msg, mp1, mp2);
6354
6355 case WM_CLOSE:
6356 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6357 WM_SYSCOMMAND, MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
6358 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
6359 fAmClosing = TRUE;
6360 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6361 WM_SYSCOMMAND, MPFROM2SHORT(SC_MINIMIZE, 0), MPVOID);
6362 if (CloseChildren(hwnd)) {
6363 fAmClosing = FALSE;
6364 if (fAutoTile)
6365 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TILE, 0), MPVOID);
6366 return 0;
6367 }
6368 if (hwndTree) {
6369 if (!PostMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID))
6370 WinSendMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID);
6371 }
6372 DosSleep(1);
6373 return 0; // Hold off WM_QUIT
6374
6375 case UM_CLOSE:
6376 HideNote();
6377 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
6378 return 0;
6379
6380 case UM_RESTORE:
6381 {
6382 // Try to restore saved shutdown state
6383 char *pszDefaultStateName = xstrdup(GetPString(IDS_SHUTDOWNSTATE),
6384 pszSrcFile, __LINE__);
6385 if (pszDefaultStateName) {
6386 if (!PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszDefaultStateName), MPVOID))
6387 // 05 Feb 08 SHL fixme to complain?
6388 free(pszDefaultStateName);
6389 }
6390 }
6391 return 0;
6392
6393 case UM_SETDIR:
6394 /* mp1 == name of directory to open */
6395 if (mp1)
6396 return MRFROMLONG(OpenDirCnr((HWND) 0,
6397 hwndMain,
6398 hwndTree, (BOOL) mp2, (char *)mp1));
6399 return 0;
6400
6401 case WM_DESTROY:
6402 hwndMain = (HWND) 0;
6403 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
6404 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
6405# ifdef FORTIFY
6406 free_commands();
6407 free_associations();
6408 free_udirs();
6409 free_ldir();
6410 free_archivers();
6411 free_tools();
6412 free_setups();
6413 Fortify_LeaveScope();
6414# endif
6415 break;
6416 }
6417 return WinDefWindowProc(hwnd, msg, mp1, mp2);
6418}
6419
6420VOID DeletePresParams(CHAR * pchKeyroot)
6421// This code assumes that pchKeyroot points to a buffer large enough to
6422// hold the full INI key: The state name.dircnr-number.PPName. The
6423// PPNames are listed below.
6424{
6425 PSZ apszPPNames[] =
6426 {
6427 "Backgroundcolor",
6428 "Foregroundcolor",
6429 "Hilitebackgroundcolor",
6430 "Hiliteforegroundcolor",
6431 "Bordercolor",
6432 "Fontnamesize"
6433 };
6434
6435 ULONG ulSize, ulArraySize = sizeof(apszPPNames) / sizeof(PSZ), x;
6436 CHAR * eos = pchKeyroot + strlen(pchKeyroot);
6437
6438 for (x = 0; x < ulArraySize; x++)
6439 {
6440 strcpy(eos, apszPPNames[x]);
6441 if (PrfQueryProfileSize(fmprof, appname, pchKeyroot, &ulSize) && ulSize)
6442 {
6443 PrfWriteProfileData(fmprof, appname, pchKeyroot, NULL, ulSize);
6444 }
6445 }
6446}
6447
6448#pragma alloc_text(MISC8,SetToggleChecks,FindDirCnrByName,TopWindow)
6449#pragma alloc_text(MISC8,TopWindowName,CountDirCnrs)
6450#pragma alloc_text(MAINWND,AdjustSizeOfClient,FillClient,ChildButtonProc)
6451#pragma alloc_text(MAINWND,ToolBackProc,StatusProc)
6452#pragma alloc_text(MAINWND,MoveChildrenAwayFromTree,ArrangeIcons,NextChild)
6453#pragma alloc_text(MAINWND,ChildFrameButtonProc)
6454#pragma alloc_text(MAINWND2,CloseChildren,CountChildren,GetNextWindowPos)
6455#pragma alloc_text(MAINWND2,CascadeChildren,TileChildren,ResizeChildren)
6456#pragma alloc_text(MAINWND2,MinResChildren,MainFrameWndProc,MainWndProc)
6457#pragma alloc_text(MAINWND2,DropDownListProc)
6458#pragma alloc_text(MAINWND3,RestoreDirCnrState,SaveDirCnrState)
6459#pragma alloc_text(MAINWND3,CloseDirCnrChildren,TransformSwp)
6460#pragma alloc_text(MAINWND3,ResizeTools,BuildTools,CommandLineProc)
6461#pragma alloc_text(MAINWND4,DriveProc,DriveBackProc,BuildDriveBarButtons,ResizeDrives)
6462#pragma alloc_text(MAINWND4,LEDProc,IdealButtonProc)
6463#pragma alloc_text(MAINWND5,MainWMOnce)
6464#pragma alloc_text(MAINWND6,MainWMCommand)
6465#pragma alloc_text(BUBBLE,MakeBubble,BubbleProc,BubbleHelp)
6466#pragma alloc_text(MAINOBJ,MainObjectWndProc,MakeMainObjWin)
6467
Note: See TracBrowser for help on using the repository browser.