source: trunk/dll/mainwnd.c@ 1077

Last change on this file since 1077 was 1077, checked in by Steven Levine, 17 years ago

Enhance Fortify infrastructure
Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT support
Add more fm/2 Fortify tooling and rework existing tooling for correct nesting
Still lots to do for cross-thread allocations
Add misc.h
Add walkem.h

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