source: trunk/dll/mainwnd.c@ 1878

Last change on this file since 1878 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

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