source: trunk/dll/mainwnd.c@ 1844

Last change on this file since 1844 was 1844, checked in by Steven Levine, 10 years ago

Add RESTORE_STATE_... definitions and use

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 186.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: mainwnd.c 1844 2015-08-12 05:37:37Z stevenhl $
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 09 Aug 15 SHL Use RESTORE_STATE_...
120
121***********************************************************************/
122
123#include <stdlib.h>
124#include <string.h>
125#include <ctype.h>
126
127#define INCL_DOS
128#define INCL_WIN
129#define INCL_SHLERRORS // PMERR_NOT_IN_IDX
130#define INCL_WINHELP
131#define INCL_GPI
132#define INCL_LONGLONG
133
134#include "fm3dll.h"
135#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
136#include "grep.h" // Data declaration(s)
137#include "autoview.h" // Data declaration(s)
138#include "dircnrs.h" // Data declaration(s)
139#include "info.h" // Data declaration(s)
140#include "defview.h" // Data declaration(s)
141#include "init.h" // Data declaration(s)
142#include "fm3dlg.h"
143#include "fm3str.h"
144#include "tools.h"
145#include "comp.h"
146#include "datamin.h"
147#include "pathutil.h" // BldQuotedFileName
148#include "errutil.h" // Dos_Error...
149#include "strutil.h" // GetPString
150#include "notebook.h" // CfgDlgProc CfgMenuInit
151#include "command.h" // LINKCMDS
152#include "avl.h" // free_archivers
153#include "walkem.h" // free_setups...
154#include "key.h" // AboutDlgProc
155#include "menu.h" // AddToMenu
156#include "mainwnd.h"
157#include "cmdline.h" // CmdLine2DlgProc, save_cmdlines
158#include "common.h" // CommonCreateMainChildren, CommonDriveCmd, CommonMainWndProc
159 // CommonTextButton
160#include "notify.h" // DoNotify, HideNote, ShowNote
161#include "draglist.h" // DragOne
162#include "chklist.h" // DropListProc
163#include "avv.h" // EditArchiverDefinition
164#include "assoc.h" // EditAssociations
165#include "fm2cmd.h" // FM2Command
166#include "misc.h" // FindDirCnr, FixSwitchList, PaintSTextWindow,
167 // SetConditionalCascade, SetMenuCheck, SetSysMenu
168 // SwitchCommand, CheckMenu, DrawTargetEmphasis
169 // IsFm2Window
170#include "instant.h" // InstantDlgProc
171#include "killproc.h" // KillDlgProc
172#include "loadbmp.h" // LoadBitmapFromFileNum
173#include "presparm.h" // SavePresParams
174#include "treecnr.h" // ShowTreeRec, StartTreeCnr
175#include "inis.h" // StartIniEditor
176#include "sysinfo.h" // SysInfoDlgProc
177#include "viewinf.h" // ViewInfProc
178#include "walkem.h" // WalkDlgProc, WalkTwoCmpDlgProc, add_setup, add_udir
179 // fill_setups_list, free_ldir, free_udirs, load_udirs
180 // remove_setup, remove_udir, save_setups, save_udirs
181#include "winlist.h" // WindowList
182#include "cmdline.h" // add_cmdline
183#include "assoc.h" // free_associations
184#include "droplist.h" // AcceptOneDrop, CheckPmDrgLimit, DropHelp, GetOneDrop
185#include "common.h" // CommonTextProc
186#include "presparm.h" // CopyPresParams
187#include "systemf.h" // ExecOnList
188#include "shadow.h" // OpenObject
189#include "mkdir.h" // PMMkDir
190#include "collect.h" // StartCollector
191#include "select.h" // UnHilite
192#include "strips.h" // bstrip
193#include "i18nutil.h" // CommaFmtULL
194#include "valid.h" // IsFullName
195#include "dirs.h" // save_dir2
196#include "wrappers.h" // xfree
197#include "fortify.h"
198#include "excputil.h" // xbeginthread
199
200#define DRIVEBAR_FONT_LCID 10
201
202static BOOL CloseDirCnrChildren(HWND hwndClient);
203static BOOL RestoreDirCnrState(HWND hwndClient, PSZ pszStateName, BOOL noview);
204static VOID BuildTools(HWND hwndT, BOOL resize);
205
206// Data definitions
207#pragma data_seg(GLOBAL1)
208ULONG DriveLines;
209HWND MainObjectHwnd;
210HWND MainPopupMenu;
211BOOL MenuInvisible;
212PFNWP PFNWPButton;
213PFNWP PFNWPStatic;
214BOOL fAmClosing;
215BOOL fAutoTile;
216BOOL fAutoView;
217BOOL fComments;
218BOOL fDrivebar;
219BOOL fFreeTree;
220BOOL fMoreButtons;
221BOOL fNoFinger;
222BOOL fNoSaveState;
223BOOL fNoTileUpdate;
224BOOL fRunning;
225BOOL fSplitStatus;
226BOOL fTextTools;
227BOOL fToolTitles;
228BOOL fToolbar;
229BOOL fUserComboBox;
230HBITMAP hbmLEDoff;
231HBITMAP hbmLEDon;
232HPOINTER hptrFinger;
233HWND hwndAutoview;
234HWND hwndBubble;
235HWND hwndName;
236HWND hwndStatelist;
237HWND hwndToolback;
238HWND hwndTree;
239USHORT shiftstate;
240
241#pragma data_seg(GLOBAL2)
242HMODULE FM3ModHandle;
243PCSZ FM3Str = "FM/3";
244RGB2 RGBGREY;
245PSZ pszFocusDir;
246
247#pragma data_seg(DATA1)
248
249static PSZ pszSrcFile = __FILE__;
250static USHORT firsttool = 0;
251static HWND hwndButtonlist;
252static HWND hwndCmdlist;
253static HWND hwndDrivelist;
254static HWND hwndUserlist;
255
256
257static MRESULT EXPENTRY MainObjectWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
258 MPARAM mp2)
259{
260 switch (msg) {
261 case WM_CREATE:
262 break;
263
264 case UM_SETUP:
265 case UM_SETUP2:
266 case UM_SETUP3:
267 case UM_SETUP4:
268 case UM_SETUP5:
269 // feed setup messages to main window
270 PostMsg(hwndMain, msg, mp1, mp2);
271 return 0;
272
273 case UM_SETUP6:
274 // handle bubble help requests from drive bar buttons
275 {
276 char dv[3], d;
277 HWND hwndB = (HWND) mp1;
278 USHORT id;
279 CHAR s[90]= {0};
280
281 id = WinQueryWindowUShort(hwndB, QWS_ID);
282 switch (id) {
283 case IDM_RESCAN:
284 strcpy(s, GetPString(IDS_RESCANALLDRIVESTEXT));
285 break;
286
287 case IDM_REFRESHREMOVABLES:
288 strcpy(s, GetPString(IDS_REFRESHREMOVABLESTEXT));
289 break;
290
291 default:
292 *dv = 0;
293 *dv = id - IDM_DRIVEA + 'A';
294 strcpy(dv + 1, ":");
295 d = toupper(*dv);
296 if (isalpha(d) && d > 'B' &&
297 !(driveflags[d - 'A'] & (DRIVE_CDROM | DRIVE_INVALID |
298 DRIVE_SLOW)) &&
299 (!hwndBubble ||
300 WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
301 !WinQueryCapture(HWND_DESKTOP)) {
302
303 FSALLOCATE fsa;
304 CHAR szQty[38];
305 ULONG ulPctFree;
306 ULONGLONG ullFreeQty;
307
308 if (!DosQueryFSInfo((d - 'A') + 1,
309 FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
310 ullFreeQty = (ULONGLONG) fsa.cUnitAvail *
311 (fsa.cSectorUnit * fsa.cbSector);
312 ulPctFree = (fsa.cUnit && fsa.cUnitAvail) ?
313 (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
314 CommaFmtULL(szQty, sizeof(szQty), ullFreeQty, ' ');
315 sprintf(s, "%s %s (%lu%%) %s", dv, szQty, ulPctFree, GetPString(IDS_FREETEXT));
316 }
317 else
318 sprintf(s, "%s ", dv);
319 }
320 }
321 if ((!hwndBubble ||
322 WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
323 !WinQueryCapture(HWND_DESKTOP))
324 WinSendMsg(hwndB, UM_SETUP6, MPFROMP(s), MPVOID);
325 }
326 return 0;
327
328 case UM_SETDIR:
329 {
330 CHAR s[8] = " :\\OS2";
331 ULONG bd;
332
333 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
334 QSV_BOOT_DRIVE,
335 (PVOID) & bd, (ULONG) sizeof(ULONG)))
336 bd = 3L;
337 *s = (CHAR) bd + '@';
338 WinSendMsg(hwndMain, UM_SETDIR, MPFROMP(s), MPFROMLONG(1));
339 if (!mp1) {
340 s[3] = 0;
341 WinSendMsg(hwndMain, UM_SETDIR, MPFROMP(s), MPVOID);
342 }
343 PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMLONG(1), MPFROMLONG(RESTORE_STATE_TILE_CHILDREN));
344 }
345 return 0;
346
347 case UM_RESTORE:
348 switch ((ULONG)mp2) {
349 case RESTORE_STATE_TILE_CHILDREN:
350 TileChildren(hwndMain, TRUE);
351 break;
352 case RESTORE_STATE_CLOSE_CHILDREN:
353 CloseDirCnrChildren(hwndMain);
354 break;
355 case RESTORE_STATE_RESTORE:
356 fNoTileUpdate = TRUE;
357 WinEnableWindow(WinQueryWindow(hwndMain, QW_PARENT), FALSE);
358 RestoreDirCnrState(hwndMain, (CHAR *)mp1, FALSE);
359 WinEnableWindow(WinQueryWindow(hwndMain, QW_PARENT), TRUE);
360 fNoTileUpdate = FALSE; ;
361 break;
362 default:
363 Runtime_Error(pszSrcFile, __LINE__, "%u unexpected", mp2);
364 }
365 return 0;
366
367 case UM_NOTIFY:
368 // bring up notify messages for various windows
369 if (mp1)
370 return MRFROMLONG(DoNotify((char *)mp1));
371 return 0;
372
373 case WM_DESTROY:
374 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
375 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
376 break;
377 }
378 return WinDefWindowProc(hwnd, msg, mp1, mp2);
379}
380
381VOID MakeMainObjWin(VOID * args)
382{
383 HAB hab2;
384 HMQ hmq2;
385 QMSG qmsg2;
386
387 priority_bumped();
388 hab2 = WinInitialize(0);
389 if (hab2) {
390 hmq2 = WinCreateMsgQueue(hab2, 128);
391 if (hmq2) {
392 DosError(FERR_DISABLEHARDERR);
393 WinRegisterClass(hab2,
394 (PSZ) WC_OBJECTWINDOW,
395 MainObjectWndProc, 0, sizeof(PVOID));
396 MainObjectHwnd = WinCreateWindow(HWND_OBJECT,
397 (CHAR *) WC_OBJECTWINDOW,
398 (PSZ) NULL,
399 0,
400 0L,
401 0L,
402 0L,
403 0L,
404 0L, HWND_TOP, OBJ_FRAME, NULL, NULL);
405 if (!MainObjectHwnd)
406 Win_Error(HWND_OBJECT, HWND_DESKTOP, pszSrcFile, __LINE__,
407 PCSZ_WINCREATEWINDOW);
408 else {
409 WinSetWindowPtr(MainObjectHwnd, QWL_USER, args);
410# ifdef FORTIFY
411 Fortify_EnterScope();
412# endif
413 while (WinGetMsg(hab2, &qmsg2, (HWND) 0, 0, 0))
414 WinDispatchMsg(hab2, &qmsg2);
415 WinDestroyWindow(MainObjectHwnd);
416# ifdef FORTIFY
417 Fortify_LeaveScope();
418# endif
419 }
420 WinDestroyMsgQueue(hmq2);
421 }
422 WinTerminate(hab2);
423 }
424}
425
426static MRESULT EXPENTRY IdealButtonProc(HWND hwnd, ULONG msg, MPARAM mp1,
427 MPARAM mp2)
428{
429 switch (msg) {
430 case WM_MOUSEMOVE:
431 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(IDS_IDEALBUTTONHELP));
432 break;
433 }
434 return PFNWPButton(hwnd, msg, mp1, mp2);
435}
436
437HWND TopWindow(HWND hwndParent, HWND exclude)
438{
439 HENUM henum;
440 HWND hwndC = (HWND) 0;
441 USHORT id;
442
443 if (hwndParent) {
444 henum = WinBeginEnumWindows(hwndMain);
445 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
446 if (hwndC != exclude) {
447 id = WinQueryWindowUShort(hwndC, QWS_ID);
448 if (id)
449 break;
450 }
451 }
452 WinEndEnumWindows(henum);
453 }
454 return hwndC;
455}
456
457HWND TopWindowName(HWND hwndParent, HWND exclude, CHAR * ret)
458{
459 HENUM henum;
460 HWND hwndC = (HWND) 0, hwndDir, hwndClient;
461 USHORT id;
462 PCNRITEM pci = NULL;
463
464 if (ret) {
465 *ret = 0;
466 if (hwndParent) {
467 henum = WinBeginEnumWindows(hwndMain);
468 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
469 if (hwndC != exclude && hwndC != hwndTree) {
470 id = WinQueryWindowUShort(hwndC, QWS_ID);
471 if (id) {
472 hwndClient = WinWindowFromID(hwndC, FID_CLIENT);
473 if (hwndClient) {
474 hwndDir = WinWindowFromID(hwndClient, DIR_CNR);
475 if (hwndDir) {
476 if (fLookInDir) {
477 pci = (PCNRITEM) WinSendMsg(hwndDir,
478 CM_QUERYRECORDEMPHASIS,
479 MPFROMLONG(CMA_FIRST),
480 MPFROMSHORT(CRA_CURSORED));
481 if (pci && (INT) pci != -1)
482 break;
483 }
484 if (WinSendMsg(hwndClient,
485 UM_CONTAINERDIR, MPFROMP(ret), MPVOID)) {
486 MakeValidDir(ret);
487 WinEndEnumWindows(henum);
488 return hwndC;
489 }
490 }
491 }
492 }
493 }
494 }
495 WinEndEnumWindows(henum);
496 if (!pci || (INT) pci == -1) {
497 hwndC = hwndTree;
498 pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(hwndTree,
499 FID_CLIENT),
500 TREE_CNR),
501 CM_QUERYRECORDEMPHASIS,
502 MPFROMLONG(CMA_FIRST),
503 MPFROMSHORT(CRA_CURSORED));
504 }
505 if (pci && (INT) pci != -1) {
506 strcpy(ret, pci->pszFileName);
507 MakeValidDir(ret);
508 }
509 else
510 strcpy(ret, pFM2SaveDirectory);
511 }
512 }
513 return hwndC;
514}
515
516ULONG CountDirCnrs(HWND hwndParent)
517{
518 HENUM henum;
519 HWND hwndF = (HWND) 0, hwndC, hwndDir;
520 ULONG ret = 0;
521
522 henum = WinBeginEnumWindows(hwndParent);
523 while ((hwndF = WinGetNextWindow(henum)) != NULLHANDLE) {
524 hwndC = WinWindowFromID(hwndF, FID_CLIENT);
525 if (hwndC) {
526 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
527 if (hwndDir)
528 ret++;
529 }
530 }
531 WinEndEnumWindows(henum);
532 return ret;
533}
534
535HWND FindDirCnrByName(CHAR * directory, BOOL restore)
536{
537 HENUM henum;
538 HWND hwndF = (HWND) 0, hwndC, hwndDir;
539 CHAR retstr[CCHMAXPATH];
540
541 if (hwndMain) {
542 henum = WinBeginEnumWindows(hwndMain);
543 while ((hwndF = WinGetNextWindow(henum)) != NULLHANDLE) {
544 hwndC = WinWindowFromID(hwndF, FID_CLIENT);
545 if (hwndC) {
546 hwndDir = WinWindowFromID(hwndC, DIR_CNR);
547 if (hwndDir) {
548 *retstr = 0;
549 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
550 if (*retstr && !stricmp(retstr, directory)) {
551 if (restore)
552 WinSetWindowPos(hwndF,
553 HWND_TOP,
554 0,
555 0,
556 0,
557 0,
558 SWP_RESTORE | SWP_SHOW |
559 SWP_ACTIVATE | SWP_ZORDER);
560 break;
561 }
562 }
563 }
564 }
565 WinEndEnumWindows(henum);
566 }
567 return hwndF;
568}
569
570/**
571 * Sync menu item checkmarks to match globals
572 * Called before submenu or context menu opened
573 * Does more work than really needed, but makes code easier to maintain
574 */
575
576static VOID SetToggleChecks(HWND hwndMenu)
577{
578 WinCheckMenuItem(hwndMenu, IDM_TEXTTOOLS, fTextTools);
579 WinCheckMenuItem(hwndMenu, IDM_TOOLTITLES, fToolTitles);
580 WinCheckMenuItem(hwndMenu, IDM_USERLIST, fUserComboBox);
581 WinCheckMenuItem(hwndMenu, IDM_TOOLSUBMENU, fToolbar);
582 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWSUBMENU, fAutoView);
583 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWFILE, !fComments);
584 WinCheckMenuItem(hwndMenu, IDM_AUTOVIEWCOMMENTS, fComments);
585 WinCheckMenuItem(hwndMenu, IDM_MOREBUTTONS, fMoreButtons);
586 WinCheckMenuItem(hwndMenu, IDM_DRIVEBAR, fDrivebar);
587 WinCheckMenuItem(hwndMenu, IDM_AUTOTILE, fAutoTile);
588 WinCheckMenuItem(hwndMenu, IDM_TILEBACKWARDS, fTileBackwards);
589 WinCheckMenuItem(hwndMenu, IDM_CONFIRMDELETE, fConfirmDelete); // 2014-05-17 SHL
590 WinCheckMenuItem(hwndMenu, IDM_TOGGLEDRAGDIALOG, fDragndropDlg);
591 WinCheckMenuItem(hwndMenu, IDM_SYNCUPDATES, fSyncUpdates);
592}
593
594static VOID ResizeTools(HWND hwnd)
595{
596 register ULONG butx = 18L;
597 INT attrib = SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER | SWP_NOREDRAW,
598 noattrib;
599 register TOOL *tool, *starttool;
600 SWP *swp;
601 register ULONG numtools, x;
602
603 if (!fToolbar)
604 return;
605 noattrib = attrib;
606 noattrib &= (~(SWP_SHOW | SWP_ZORDER));
607 noattrib |= SWP_HIDE;
608 // count tools
609 tool = toolhead;
610 for (numtools = 0L; tool; numtools++)
611 tool = tool->next;
612 // allocate swp array for WinSetMultWindowPos
613 swp = xmallocz(sizeof(SWP) * (numtools + 2), pszSrcFile, __LINE__);
614 if (swp) {
615 for (x = 0; x < numtools + 2L; x++) {
616 swp[x].hwndInsertBehind = HWND_TOP;
617 swp[x].fl = attrib;
618 swp[x].y = (fToolTitles) ? 14L : 3L;
619 swp[x].cx = 32L;
620 swp[x].cy = 32L;
621 }
622 swp[0].x = swp[1].x = 2L;
623 swp[0].y = (fTextTools) ? 14L : 18L;
624 swp[1].y = (fTextTools) ? 1L : 2L;
625 swp[0].cx = swp[1].cx = 14L;
626 swp[0].cy = swp[1].cy = 14L;
627 swp[0].hwnd = WinWindowFromID(hwnd, IDM_TOOLLEFT);
628 swp[1].hwnd = WinWindowFromID(hwnd, IDM_TOOLRIGHT);
629 x = 2L;
630 tool = find_tool(firsttool);
631 if (!tool)
632 tool = toolhead;
633 starttool = tool;
634 while (tool) {
635 if (!(tool->flags & T_INVISIBLE)) {
636 swp[x].x = butx;
637 if (fTextTools || (tool->flags & T_TEXT)) {
638 butx += 55L;
639 swp[x].cx = 54L;
640 swp[x].cy = 24L;
641 swp[x].y = 3L;
642 }
643 else
644 butx += 33L;
645 if (tool->flags & T_SEPARATOR)
646 butx += 12;
647 }
648 else
649 swp[x].fl = noattrib;
650 swp[x].hwnd = WinWindowFromID(hwnd, tool->id);
651 x++;
652 tool = tool->next;
653 }
654 tool = toolhead;
655 while (tool && tool != starttool) {
656 swp[x].x = butx;
657 if (!(tool->flags & T_INVISIBLE)) {
658 if (fTextTools || (tool->flags & T_TEXT)) {
659 butx += 55L;
660 swp[x].cx = 54L;
661 swp[x].cy = 24L;
662 swp[x].y = 3L;
663 }
664 else
665 butx += 33L;
666 if (tool->flags & T_SEPARATOR)
667 butx += 12;
668 }
669 else
670 swp[x].fl = noattrib;
671 swp[x].hwnd = WinWindowFromID(hwnd, tool->id);
672 x++;
673 tool = tool->next;
674 }
675 WinSetMultWindowPos(WinQueryAnchorBlock(hwnd), swp, numtools + 2L);
676 if (!fTextTools && fToolTitles) {
677 for (x = 2L; x < numtools + 2L; x++) {
678 if (fTextTools || !fToolTitles)
679 swp[x].fl = noattrib;
680 else {
681 tool = find_tool(WinQueryWindowUShort(swp[x].hwnd, QWS_ID));
682 if (tool && (tool->flags & T_TEXT))
683 swp[x].fl = noattrib;
684 else {
685 swp[x].hwndInsertBehind = HWND_TOP;
686 swp[x].y = 1L;
687 swp[x].cy = 10L;
688 }
689 }
690 swp[x].hwnd = WinWindowFromID(hwnd,
691 WinQueryWindowUShort(swp[x].hwnd,
692 QWS_ID) + 25000);
693 }
694 WinSetMultWindowPos(WinQueryAnchorBlock(hwnd), &swp[2], numtools);
695 }
696 free(swp);
697 }
698 WinInvalidateRect(hwnd, NULL, TRUE);
699}
700
701static MRESULT EXPENTRY DropDownListProc(HWND hwnd, ULONG msg, MPARAM mp1,
702 MPARAM mp2)
703{
704 PFNWP oldproc = (PFNWP) INSTDATA(hwnd);
705 USHORT id;
706
707 static HWND hwndMenu = (HWND)0;
708 static BOOL emphasized = FALSE;
709
710 switch (msg) {
711 case WM_MOUSEMOVE:
712 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
713 break;
714
715 case WM_CHAR:
716 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
717 break;
718
719 case WM_MENUEND:
720 if (hwndMenu == (HWND) mp2) {
721 WinDestroyWindow(hwndMenu);
722 hwndMenu = (HWND) 0;
723 }
724 break;
725
726 case WM_FOCUSCHANGE:
727 {
728 HAB hab = WinQueryAnchorBlock(hwnd);
729 HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
730 HWND hwndFrame = WinQueryWindow(hwndParent, QW_PARENT);
731 static HACCEL haccelSaved = NULLHANDLE;
732 static HACCEL haccelDriveList = NULLHANDLE;
733 static HACCEL haccelSetupList = NULLHANDLE;
734 static HACCEL haccelUserList = NULLHANDLE;
735 static HACCEL haccelCmdList = NULLHANDLE;
736 static HACCEL haccelButtonList = NULLHANDLE;
737 // DbgMsg(pszSrcFile, __LINE__, "WM_FOCUSCHANGE %u", SHORT1FROMMP(mp2));
738 id = WinQueryWindowUShort(hwndParent, QWS_ID);
739 if (SHORT1FROMMP(mp2)) {
740 // If getting focus 1st time - save original accelerator
741 if (haccelSaved == NULLHANDLE) {
742 haccelSaved = WinQueryAccelTable(hab, hwndFrame);
743 if (haccelSaved == NULLHANDLE)
744 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryAccelTable");
745 }
746 if (haccelSaved != NULLHANDLE) {
747 switch (id) {
748 case MAIN_DRIVELIST:
749 if (haccelDriveList == NULLHANDLE) {
750 haccelDriveList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_DRIVELIST);
751 if (haccelDriveList == NULLHANDLE)
752 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINLOADACCELTABLE);
753 }
754 if (haccelDriveList != NULLHANDLE) {
755 if (!WinSetAccelTable(hab, haccelDriveList, hwndFrame))
756 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
757 }
758 break;
759 case MAIN_SETUPLIST:
760 if (haccelSetupList == NULLHANDLE) {
761 haccelSetupList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_SETUPLIST);
762 if (haccelSetupList == NULLHANDLE)
763 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINLOADACCELTABLE);
764 }
765 if (haccelSetupList != NULLHANDLE) {
766 if (!WinSetAccelTable(hab, haccelSetupList, hwndFrame))
767 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
768 }
769 break;
770 case MAIN_CMDLIST:
771 if (haccelCmdList == NULLHANDLE) {
772 haccelCmdList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_CMDLIST);
773 if (haccelCmdList == NULLHANDLE)
774 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINLOADACCELTABLE);
775 }
776 if (haccelCmdList != NULLHANDLE) {
777 if (!WinSetAccelTable(hab, haccelCmdList, hwndFrame))
778 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
779 }
780 break;
781 case MAIN_USERLIST:
782 if (haccelUserList == NULLHANDLE) {
783 haccelUserList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_USERLIST);
784 if (haccelUserList == NULLHANDLE)
785 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINLOADACCELTABLE);
786 }
787 if (haccelUserList != NULLHANDLE) {
788 if (!WinSetAccelTable(hab, haccelUserList, hwndFrame))
789 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
790 }
791 break;
792 case MAIN_BUTTONLIST:
793 if (haccelButtonList == NULLHANDLE) {
794 haccelButtonList = WinLoadAccelTable(hab, FM3ModHandle, MAIN_BUTTONLIST);
795 if (haccelButtonList == NULLHANDLE)
796 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINLOADACCELTABLE);
797 }
798 if (haccelButtonList != NULLHANDLE) {
799 if (!WinSetAccelTable(hab, haccelButtonList, hwndFrame))
800 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
801 }
802 break;
803 } // switch
804 }
805 }
806 else {
807 // Losing focus
808 switch (id) {
809 case MAIN_DRIVELIST:
810 case MAIN_SETUPLIST:
811 case MAIN_CMDLIST:
812 case MAIN_USERLIST:
813 case MAIN_BUTTONLIST:
814 if (haccelSaved != NULLHANDLE) {
815 if (!WinSetAccelTable(hab, haccelSaved, hwndFrame))
816 Win_Error(hwndFrame, HWND_DESKTOP, pszSrcFile, __LINE__, PCSZ_WINSETACCELTABLE);
817 }
818 break;
819 } // switch
820 }
821 }
822 break; // WM_FOCUSCHANGE
823
824 case WM_CONTEXTMENU:
825 {
826 MRESULT ret = MRFROMSHORT(TRUE);
827
828 if (hwndMenu)
829 WinDestroyWindow(hwndMenu);
830 hwndMenu = (HWND) 0;
831 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
832 switch (id) {
833 case MAIN_CMDLIST:
834 WinPostMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
835 QW_PARENT),
836 QW_PARENT),
837 FID_CLIENT),
838 WM_COMMAND, MPFROM2SHORT(IDM_EDITCOMMANDS, 0), MPVOID);
839 break;
840 case MAIN_USERLIST:
841 case MAIN_SETUPLIST:
842 hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
843 if (hwndMenu)
844 PopupMenu(hwnd,
845 WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
846 QW_PARENT),
847 QW_PARENT),
848 FID_CLIENT), hwndMenu);
849 break;
850 default:
851 ret = FALSE;
852 break;
853 } // switch
854 return ret;
855 }
856
857 case WM_CONTROL:
858 if (hwndStatus2) {
859 switch (SHORT1FROMMP(mp1)) {
860 case CBID_EDIT:
861 id = WinQueryWindowUShort(hwnd, QWS_ID);
862 switch (SHORT2FROMMP(mp1)) {
863 case EN_SETFOCUS:
864 switch (id) {
865 case MAIN_CMDLIST:
866 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_CMDLISTHELP));
867 break;
868 case MAIN_SETUPLIST:
869 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_SETUPLISTHELP));
870 break;
871 case MAIN_USERLIST:
872 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_USERLISTHELP));
873 break;
874 case MAIN_DRIVELIST:
875 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_DRIVELISTHELP));
876 break;
877 case MAIN_BUTTONLIST:
878 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_BUTTONLISTHELP));
879 break;
880 default:
881 break;
882 }
883 break;
884
885 default:
886 break;
887 }
888 }
889 break;
890
891 default:
892 break;
893 }
894 break;
895
896 case WM_BEGINDRAG:
897 id = WinQueryWindowUShort(hwnd, QWS_ID);
898 if (id == CBID_EDIT &&
899 WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID) ==
900 MAIN_USERLIST) {
901
902 CHAR path[CCHMAXPATH];
903
904 *path = 0;
905 WinQueryWindowText(hwnd, CCHMAXPATH, path);
906 bstrip(path);
907 if (*path && !IsRoot(path))
908 DragOne(hwnd, (HWND) 0, path, FALSE);
909 return 0;
910 }
911 break;
912
913 case DM_DRAGOVER:
914 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
915 if (id == MAIN_USERLIST) {
916 if (!emphasized) {
917 emphasized = TRUE;
918 DrawTargetEmphasis(hwnd, emphasized);
919 }
920 if (AcceptOneDrop(hwnd, mp1, mp2))
921 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
922 return MRFROM2SHORT(DOR_NEVERDROP, 0);
923 }
924 break;
925
926 case DM_DRAGLEAVE:
927 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
928 if (id == MAIN_USERLIST) {
929 if (emphasized) {
930 emphasized = FALSE;
931 DrawTargetEmphasis(hwnd, emphasized);
932 }
933 }
934 break;
935
936 case DM_DROPHELP:
937 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
938 if (id == MAIN_USERLIST) {
939 DropHelp(mp1, mp2, hwnd, GetPString(IDS_USERLISTDROPHELP));
940 return 0;
941 }
942 break;
943
944 case DM_DROP:
945 id = WinQueryWindowUShort(WinQueryWindow(hwnd, QW_PARENT), QWS_ID);
946 if (id == MAIN_USERLIST) {
947
948 char szFrom[CCHMAXPATH + 2];
949
950 if (emphasized) {
951 emphasized = FALSE;
952 DrawTargetEmphasis(hwnd, emphasized);
953 }
954 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
955 MakeValidDir(szFrom);
956 WinSetWindowText(hwnd, szFrom);
957 PostMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
958 QW_PARENT),
959 QW_PARENT),
960 FID_CLIENT),
961 UM_COMMAND, MPFROM2SHORT(IDM_ADDTOUSERLIST, 0), MPVOID);
962 return 0;
963 }
964 }
965 break;
966
967 case WM_DESTROY:
968 if (hwndMenu)
969 WinDestroyWindow(hwndMenu);
970 hwndMenu = (HWND) 0;
971 break;
972 }
973
974 return oldproc(hwnd, msg, mp1, mp2);
975}
976
977void BubbleHelp(HWND hwnd, BOOL other, BOOL drive, BOOL above, PCSZ help)
978{
979 if (help && *help &&
980 ((drive && fDrivebarHelp) ||
981 (other && fOtherHelp) || (!other && !drive && fToolbarHelp))) {
982 if ((!hwndBubble ||
983 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
984 !WinQueryCapture(HWND_DESKTOP))
985 MakeBubble(hwnd, above, help);
986 }
987}
988
989VOID MakeBubble(HWND hwnd, BOOL above, PCSZ help)
990{
991 if (!hwnd || !help || !*help)
992 return;
993
994 if (hwndBubble)
995 WinDestroyWindow(hwndBubble);
996
997 {
998 HWND hwndActive;
999 char ucClassname[8];
1000
1001 hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
1002 if (hwndActive) {
1003 // don't bring up help if window isn't active
1004 if (!WinIsChild(hwnd, hwndActive))
1005 return;
1006 }
1007 hwndActive = WinQueryFocus(HWND_DESKTOP);
1008 if (WinQueryClassName(hwndActive, sizeof(ucClassname), ucClassname)) {
1009 // don't bring up help if a menu is active
1010 if (!strcmp(ucClassname, "#4"))
1011 return;
1012 }
1013 }
1014
1015 hwndBubble = WinCreateWindow(HWND_DESKTOP,
1016 (CHAR *) WC_BUBBLE,
1017 (CHAR *) help,
1018 WS_CLIPSIBLINGS | SS_TEXT |
1019 DT_CENTER | DT_VCENTER,
1020 0,
1021 0,
1022 0,
1023 0,
1024 HWND_DESKTOP, HWND_TOP, MAIN_HELP, NULL, NULL);
1025 if (!hwndBubble)
1026 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
1027 PCSZ_WINCREATEWINDOW);
1028 else {
1029 HPS hps;
1030 POINTL aptl[TXTBOX_COUNT], ptl, tptl;
1031 LONG lxScreen, sx, sy, extra = 0, lyScreen;
1032 CHAR *p, *pp, *wp;
1033 SWP swp;
1034
1035 WinQueryWindowPos(hwnd, &swp);
1036 lyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
1037 lxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
1038 WinSetWindowULong(hwndBubble, QWL_USER, hwnd);
1039 //fixme to allow user to change presparams 1-10-09 GKY
1040 SetPresParams(hwndBubble, NULL, NULL, NULL, FNT_8HELVETICA);
1041 hps = WinGetPS(hwndBubble);
1042 // 03 Feb 09 SHL fixme to not overwrite?
1043 p = (PSZ)help;
1044 tptl.x = tptl.y = 0;
1045 while (p && *p) {
1046 wp = NULL;
1047 pp = strchr(p, '\r');
1048 if (pp) {
1049 wp = pp;
1050 *pp = 0;
1051 pp++;
1052 }
1053 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
1054 tptl.x = max(aptl[TXTBOX_TOPRIGHT].x, tptl.x);
1055 if (tptl.y)
1056 tptl.y += extra;
1057 else
1058 extra = aptl[TXTBOX_TOPLEFT].y / 4;
1059 tptl.y += aptl[TXTBOX_TOPLEFT].y;
1060 if (wp)
1061 *wp = '\r';
1062 p = pp;
1063 }
1064 WinSetWindowULong(hwndBubble, QWL_USER + 4, extra);
1065 WinReleasePS(hps);
1066 ptl.x = ptl.y = 0;
1067 WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1);
1068 if (above) {
1069 sy = ptl.y + swp.cy + 4;
1070 if (sy + tptl.y + 12 > lyScreen) {
1071 above = FALSE;
1072 sy = ptl.y - (tptl.y + 14);
1073 }
1074 }
1075 else
1076 sy = ptl.y - (tptl.y + 14);
1077 if (ptl.x > (lxScreen / 2))
1078 sx = (ptl.x - tptl.x) - 16;
1079 else
1080 sx = ptl.x + (54 * (above == FALSE)) + 2;
1081 if (sx < 0)
1082 sx = 0;
1083 if (sx + tptl.x + 14 > lxScreen)
1084 sx = lxScreen - (tptl.x + 14);
1085 if (sy < 0) {
1086 sy = ptl.y + swp.cy + 4;
1087 if (sy + tptl.y + 12 > lyScreen)
1088 sy = 0;
1089 }
1090 WinSetWindowPos(hwndBubble, HWND_TOP, sx, sy,
1091 tptl.x + 14,
1092 tptl.y + 12,
1093 SWP_DEACTIVATE | SWP_SHOW | SWP_ZORDER |
1094 SWP_MOVE | SWP_SIZE);
1095 }
1096}
1097
1098MRESULT EXPENTRY BubbleProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1099{
1100 switch (msg) {
1101 case WM_SETFOCUS:
1102 if (mp2)
1103 PostMsg(hwnd, UM_FOCUSME, mp1, MPVOID);
1104 break;
1105
1106 case UM_FOCUSME:
1107 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
1108 return 0;
1109
1110 case WM_MOUSEMOVE:
1111 WinShowWindow(hwnd, FALSE);
1112 break;
1113
1114 case UM_TIMER:
1115 {
1116 POINTL ptl;
1117
1118 WinQueryPointerPos(HWND_DESKTOP, &ptl);
1119 if (WinWindowFromPoint(HWND_DESKTOP, &ptl, TRUE) !=
1120 WinQueryWindowULong(hwnd, QWL_USER) || !WinIsWindowVisible(hwnd))
1121 WinDestroyWindow(hwnd);
1122 }
1123 return 0;
1124
1125 case WM_PAINT:
1126 {
1127 HPS hps;
1128 SWP swp;
1129 POINTL ptl, aptl[TXTBOX_COUNT];
1130 CHAR *s, *p, *pp, *wp;
1131 ULONG extra, tlen, y;
1132
1133 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
1134 if (hps) {
1135 WinQueryWindowPos(hwnd, &swp);
1136 GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, 0);
1137 GpiSetColor(hps, ((255 << 16) | (255 << 8) | 198));
1138 GpiSetBackMix(hps, BM_LEAVEALONE);
1139 GpiSetMix(hps, FM_OVERPAINT);
1140 ptl.x = ptl.y = 0;
1141 GpiMove(hps, &ptl);
1142 ptl.x = swp.cx - 1;
1143 ptl.y = swp.cy - 1;
1144 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
1145 tlen = WinQueryWindowTextLength(hwnd);
1146 if (tlen) {
1147 s = xmalloc(tlen + 2, pszSrcFile, __LINE__);
1148 if (s) {
1149 WinQueryWindowText(hwnd, tlen + 1, s);
1150 if (*s) {
1151 p = s;
1152 y = swp.cy - 3;
1153 extra = WinQueryWindowULong(hwnd, QWL_USER + 4);
1154 GpiSetColor(hps, 0);
1155 GpiSetMix(hps, FM_OVERPAINT);
1156 while (p && *p) {
1157 wp = NULL;
1158 pp = strchr(p, '\r');
1159 if (pp) {
1160 wp = pp;
1161 *pp = 0;
1162 pp++;
1163 }
1164 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
1165 ptl.x = 7;
1166 y -= aptl[TXTBOX_TOPLEFT].y;
1167 if (p != s)
1168 y -= extra;
1169 ptl.y = y;
1170 GpiCharStringAt(hps, &ptl, strlen(p), p);
1171 if (wp)
1172 *wp = '\r';
1173 p = pp;
1174 }
1175 }
1176 free(s);
1177 }
1178 }
1179 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) && swp.cx > 6 && swp.cy > 6) {
1180 GpiSetColor(hps, CLR_WHITE);
1181 ptl.x = 1;
1182 ptl.y = 1;
1183 GpiMove(hps, &ptl);
1184 ptl.y = swp.cy - 2;
1185 GpiLine(hps, &ptl);
1186 ptl.x = swp.cx - 2;
1187 GpiLine(hps, &ptl);
1188 ptl.x = 2;
1189 ptl.y = 2;
1190 GpiMove(hps, &ptl);
1191 ptl.y = swp.cy - 3;
1192 GpiLine(hps, &ptl);
1193 ptl.x = swp.cx - 3;
1194 GpiLine(hps, &ptl);
1195 GpiSetColor(hps, CLR_BROWN);
1196 ptl.x = 1;
1197 ptl.y = 1;
1198 GpiMove(hps, &ptl);
1199 ptl.x = swp.cx - 2;
1200 GpiLine(hps, &ptl);
1201 ptl.y = swp.cy - 2;
1202 GpiLine(hps, &ptl);
1203 ptl.x = 2;
1204 ptl.y = 2;
1205 GpiMove(hps, &ptl);
1206 ptl.x = swp.cx - 3;
1207 GpiLine(hps, &ptl);
1208 ptl.y = swp.cy - 3;
1209 GpiLine(hps, &ptl);
1210 }
1211 WinEndPaint(hps);
1212 }
1213 }
1214 return 0;
1215
1216 case WM_CLOSE:
1217 WinDestroyWindow(hwnd);
1218 return 0;
1219
1220 case WM_DESTROY:
1221 hwndBubble = (HWND) 0;
1222 break;
1223 }
1224 return PFNWPStatic(hwnd, msg, mp1, mp2);
1225}
1226
1227MRESULT EXPENTRY LEDProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1228{
1229 switch (msg) {
1230 case WM_CREATE:
1231 {
1232 MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
1233
1234 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
1235 case MAIN_LED:
1236 {
1237 HPS hps = WinGetPS(hwnd);
1238 HBITMAP hbmold = (HBITMAP)WinSendMsg(hwnd, SM_QUERYHANDLE, MPVOID, MPVOID);
1239 if (!fBlueLED) {
1240 hbmLEDon = GpiLoadBitmap(hps, 0, LEDON_BMP, 12, 12);
1241 hbmLEDoff = GpiLoadBitmap(hps, 0, LEDOFF_BMP, 12, 12);
1242 }
1243 else {
1244 hbmLEDon = GpiLoadBitmap(hps, 0, LEDON2_BMP, 12, 12);
1245 hbmLEDoff = GpiLoadBitmap(hps, 0, LEDOFF2_BMP, 12, 12);
1246 }
1247 if (hbmLEDoff && hbmLEDon)
1248 WinSendMsg(hwnd, SM_SETHANDLE, MPFROMLONG(hbmLEDoff), MPVOID);
1249 else {
1250 if (hbmLEDoff)
1251 GpiDeleteBitmap(hbmLEDoff);
1252 if (hbmLEDon)
1253 GpiDeleteBitmap(hbmLEDon);
1254 }
1255 if (hbmold &&
1256 hbmLEDon &&
1257 hbmLEDoff && hbmold != hbmLEDon && hbmold != hbmLEDoff)
1258 GpiDeleteBitmap(hbmold);
1259 if (hps)
1260 WinReleasePS(hps);
1261 }
1262 break;
1263 default:
1264 //fixme to allow user to change presparams 1-10-09 GKY
1265 SetPresParams(hwnd,
1266 &RGBGREY,
1267 &RGBBLACK, &RGBGREY, FNT_6HELVETICA );
1268 break;
1269 }
1270 return mr;
1271 }
1272
1273 case WM_SETFOCUS:
1274 if (mp2)
1275 PostMsg(hwnd, UM_FOCUSME, mp1, MPVOID);
1276 break;
1277
1278 case UM_FOCUSME:
1279 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
1280 return 0;
1281
1282 case WM_MOUSEMOVE:
1283 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(IDS_LEDHELP));
1284 if (!fNoFinger) {
1285 WinSetPointer(HWND_DESKTOP, hptrFinger);
1286 return MRFROMLONG(TRUE);
1287 }
1288 break;
1289
1290 case WM_BUTTON1CLICK:
1291 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1292 WM_COMMAND, MPFROM2SHORT(IDM_SHOWNOTEWND, 0), MPVOID);
1293 break;
1294
1295 case WM_BUTTON2CLICK:
1296 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1297 WM_COMMAND, MPFROM2SHORT(IDM_HIDENOTEWND, 0), MPVOID);
1298 break;
1299
1300 case WM_CHORD:
1301 case WM_BUTTON3CLICK:
1302 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
1303 WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
1304 break;
1305 }
1306 return PFNWPStatic(hwnd, msg, mp1, mp2);
1307}
1308
1309MRESULT EXPENTRY ChildButtonProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1310{
1311 USHORT id;
1312 TOOL *tool;
1313
1314 static HWND hwndMenu = (HWND) 0;
1315
1316 switch (msg) {
1317 case WM_BUTTON1DOWN:
1318 case WM_BUTTON2DOWN:
1319 case WM_BUTTON3DOWN:
1320 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
1321 break;
1322
1323 case WM_MOUSEMOVE:
1324 if (fToolbarHelp) {
1325 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
1326 && !WinQueryCapture(HWND_DESKTOP)) {
1327 id = WinQueryWindowUShort(hwnd, QWS_ID);
1328 tool = find_tool(id);
1329 if (tool && tool->help && *tool->help) {
1330
1331 char s[128];
1332
1333 strcpy(s, tool->help);
1334 if (tool->flags & T_DROPABLE)
1335 strcat(s, GetPString(IDS_DROPONMETEXT));
1336 MakeBubble(hwnd, FALSE, s);
1337 }
1338 }
1339 }
1340 break;
1341
1342 case WM_COMMAND:
1343 switch (SHORT1FROMMP(mp1)) {
1344 case IDM_HELP:
1345 if (hwndHelp)
1346 WinSendMsg(hwndHelp,
1347 HM_DISPLAY_HELP,
1348 MPFROM2SHORT(HELP_TOOLBAR, 0), MPFROMSHORT(HM_RESOURCEID));
1349 break;
1350
1351 case IDM_HIDEANYTOOL: // hide any tool
1352 case IDM_HIDETOOL: // hide tool
1353 if (SHORT1FROMMP(mp1) == IDM_HIDETOOL)
1354 id = WinQueryWindowUShort(hwnd, QWS_ID);
1355 else
1356 id = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd,
1357 PickToolProc, FM3ModHandle,
1358 PICKBTN_FRAME, (PSZ)GetPString(IDS_HIDETEXT));
1359 if (id) {
1360 tool = find_tool(id);
1361 if (tool) {
1362 tool->flags |= T_INVISIBLE;
1363 save_tools(NULL);
1364 }
1365 }
1366 break;
1367
1368 case IDM_SHOWTOOLS: // show all tools
1369 tool = toolhead;
1370 while (tool) {
1371 tool->flags &= (~T_INVISIBLE);
1372 tool = tool->next;
1373 }
1374 save_tools(NULL);
1375 break;
1376
1377 case IDM_DELETEANYTOOL: // delete any button
1378 case IDM_DELETETOOL: // delete button
1379 if (SHORT1FROMMP(mp1) == IDM_DELETETOOL)
1380 id = WinQueryWindowUShort(hwnd, QWS_ID);
1381 else
1382 id =
1383 (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, PickToolProc, FM3ModHandle,
1384 PICKBTN_FRAME, (PSZ)GetPString(IDS_DELETETEXT));
1385 if (id)
1386 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_SETUP,
1387 MPFROM2SHORT(id, 0), MPVOID);
1388 return 0;
1389
1390 case IDM_EDITANYTOOL: // edit any button
1391 case IDM_EDITTOOL: // edit button
1392 if (SHORT1FROMMP(mp1) == IDM_EDITTOOL)
1393 id = WinQueryWindowUShort(hwnd, QWS_ID);
1394 else
1395 id =
1396 (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, PickToolProc, FM3ModHandle,
1397 PICKBTN_FRAME, (PSZ)GetPString(IDS_EDITTEXT));
1398 if (id) {
1399 tool = find_tool(id);
1400 if (tool) {
1401 if (WinDlgBox(HWND_DESKTOP, hwnd, AddToolProc, FM3ModHandle,
1402 ADDBTN_FRAME, (PVOID) tool))
1403 WinSendMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
1404 QW_PARENT),
1405 QW_PARENT), FID_CLIENT),
1406 WM_COMMAND, MPFROM2SHORT(IDM_CREATETOOL, 0),
1407 MPFROM2SHORT(id, 0));
1408 }
1409 }
1410 break;
1411
1412 case IDM_ADDTOOL: // add tool
1413 id = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, AddToolProc, FM3ModHandle,
1414 ADDBTN_FRAME, MPVOID);
1415 if (id && id != (USHORT) - 1)
1416 WinSendMsg(WinWindowFromID(WinQueryWindow(WinQueryWindow(hwnd,
1417 QW_PARENT),
1418 QW_PARENT), FID_CLIENT),
1419 WM_COMMAND, MPFROM2SHORT(IDM_CREATETOOL, 0),
1420 MPFROM2SHORT(id, 0));
1421 break;
1422
1423 case IDM_REORDERTOOLS: // reorder tools
1424 WinDlgBox(HWND_DESKTOP,
1425 hwnd, ReOrderToolsProc, FM3ModHandle, RE_FRAME, MPVOID);
1426 break;
1427
1428 case IDM_SAVETOOLS:
1429 case IDM_LOADTOOLS:
1430 if (WinDlgBox(HWND_DESKTOP,
1431 hwnd,
1432 ToolIODlgProc,
1433 FM3ModHandle,
1434 SVBTN_FRAME,
1435 (PVOID) (SHORT1FROMMP(mp1) == IDM_SAVETOOLS) ?
1436 "TRUE" : NULL))
1437 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
1438 break;
1439 }
1440 ResizeTools(WinQueryWindow(hwnd, QW_PARENT));
1441 return 0;
1442
1443 case WM_MENUEND:
1444 if (hwndMenu == (HWND) mp2) {
1445 WinDestroyWindow(hwndMenu);
1446 hwndMenu = (HWND) 0;
1447 }
1448 break;
1449
1450 case WM_CONTEXTMENU:
1451 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
1452 if (!hwndMenu)
1453 hwndMenu = WinLoadMenu(hwnd, FM3ModHandle, ID_BUTTONMENU);
1454 DosReleaseMutexSem(hmtxFM2Globals);
1455 //fixme to allow user to change font 1-10-09 GKY
1456 SetPresParams(hwndMenu, NULL, NULL, NULL, FNT_10SYSTEMPROPORT);
1457 if (PopupMenu(hwnd, hwnd, hwndMenu))
1458 WinShowWindow(hwndMenu, TRUE);
1459 return MRFROMSHORT(TRUE);
1460
1461 case DM_DRAGOVER:
1462 {
1463 PDRAGINFO pDInfo; // Pointer to DRAGINFO
1464
1465 pDInfo = (PDRAGINFO) mp1; // Get DRAGINFO pointer
1466 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
1467 id = WinQueryWindowUShort(hwnd, QWS_ID);
1468 tool = find_tool(id);
1469 if (!tool) {
1470 DrgFreeDraginfo(pDInfo);
1471 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); // Drop not valid
1472 }
1473 if (!(tool->flags & T_DROPABLE)) {
1474 DrgFreeDraginfo(pDInfo);
1475 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); // Drop not valid
1476 }
1477 {
1478 PDRAGITEM pDItem; // Pointer to DRAGITEM
1479
1480 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
1481 0); // Index to DRAGITEM
1482 if (DrgVerifyRMF(pDItem, // Check valid rendering
1483 (CHAR *) DRM_OS2FILE, // mechanisms and data
1484 NULL)) { // formats
1485 if (!(tool->flags & T_EMPHASIZED)) {
1486 tool->flags |= T_EMPHASIZED;
1487 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1488 DrgFreeDraginfo(pDInfo);
1489 }
1490 return (MRFROM2SHORT(DOR_DROP, // Return okay to drop
1491 DO_MOVE)); // Move operation valid
1492 }
1493 DrgFreeDraginfo(pDInfo);
1494 }
1495 }
1496 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); // Drop not valid
1497
1498 case DM_DROPHELP:
1499 id = WinQueryWindowUShort(hwnd, QWS_ID);
1500 tool = find_tool(id);
1501 PFNWPButton(hwnd, msg, mp1, mp2);
1502 DropHelp(mp1, mp2, hwnd, GetPString(IDS_TOOLDROPHELP));
1503 return 0;
1504
1505 case DM_DRAGLEAVE:
1506 id = WinQueryWindowUShort(hwnd, QWS_ID);
1507 tool = find_tool(id);
1508 if (tool && (tool->flags & T_DROPABLE)) {
1509 if (tool->flags & T_EMPHASIZED) {
1510 tool->flags &= (~T_EMPHASIZED);
1511 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1512 }
1513 }
1514 break;
1515
1516 case DM_DROP:
1517 id = WinQueryWindowUShort(hwnd, QWS_ID);
1518 tool = find_tool(id);
1519 if (tool && (tool->flags & T_DROPABLE) != 0) {
1520 LISTINFO *li;
1521 CNRDRAGINFO cdi;
1522
1523 if (tool->flags & T_EMPHASIZED) {
1524 DrawTargetEmphasis(hwnd, ((tool->flags & T_EMPHASIZED) != 0));
1525 tool->flags &= (~T_EMPHASIZED);
1526 }
1527 memset(&cdi, 0, sizeof(cdi));
1528 cdi.pDragInfo = mp1;
1529 li = DoFileDrop(hwnd, NULL, FALSE, mp1, MPFROMP(&cdi));
1530 CheckPmDrgLimit(cdi.pDragInfo);
1531 if (li) {
1532 li->type = id;
1533 if (!li->list || !li->list[0])
1534 FreeListInfo(li);
1535 else {
1536 HWND hwndActive;
1537
1538 hwndActive = TopWindow(hwndMain, (HWND) 0);
1539 if (hwndActive) {
1540 if (!WinSendMsg(hwndActive, UM_COMMAND, MPFROMP(li), MPVOID))
1541 FreeListInfo(li);
1542 }
1543 else
1544 FreeListInfo(li);
1545 }
1546 }
1547 }
1548 return 0;
1549
1550 case WM_CLOSE:
1551 WinDestroyWindow(hwnd);
1552 return 0;
1553 }
1554 return PFNWPButton(hwnd, msg, mp1, mp2);
1555}
1556
1557static VOID BuildTools(HWND hwndT, BOOL resize)
1558{
1559 TOOL *tool;
1560 ULONG ctrlxpos = 18L;
1561 CHAR s[33];
1562 HENUM henum;
1563 HWND hwndTool;
1564
1565 henum = WinBeginEnumWindows(hwndT);
1566 while ((hwndTool = WinGetNextWindow(henum)) != NULLHANDLE)
1567 if (!WinDestroyWindow(hwndTool))
1568 Runtime_Error(pszSrcFile, __LINE__, "Unable to destroy toolbar button");
1569 WinEndEnumWindows(henum);
1570 if (!fToolbar) {
1571 load_quicktools();
1572 load_tools(NULL);
1573 return;
1574 }
1575 if (!toolhead)
1576 load_tools(NULL);
1577 tool = toolhead;
1578 while (tool) {
1579 sprintf(s, "#%u", tool->id);
1580 hwndTool = (HWND) 0;
1581 if (!fTextTools) {
1582 if (!(tool->flags & T_MYICON)) {
1583 hwndTool = WinCreateWindow(hwndT,
1584 (CHAR *) WC_TOOLBUTTONS,
1585 s,
1586 BS_NOPOINTERFOCUS |
1587 BS_BITMAP | BS_PUSHBUTTON,
1588 ctrlxpos,
1589 14,
1590 32,
1591 32, hwndT, HWND_TOP, tool->id, NULL, NULL);
1592 }
1593 if (!hwndTool) {
1594 HBITMAP hbm = LoadBitmapFromFileIdentifier(tool->id, tool->text);
1595
1596 if (hbm) {
1597 BTNCDATA btc;
1598
1599 memset(&btc, 0, sizeof(btc));
1600 btc.cb = sizeof(btc);
1601 btc.hImage = hbm;
1602 hwndTool = WinCreateWindow(hwndT,
1603 (CHAR *) WC_TOOLBUTTONS,
1604 NullStr,
1605 BS_NOPOINTERFOCUS |
1606 BS_BITMAP | BS_PUSHBUTTON,
1607 ctrlxpos,
1608 14,
1609 32,
1610 32,
1611 hwndT, HWND_TOP, tool->id, &btc, NULL);
1612 if (!hwndTool)
1613 GpiDeleteBitmap(hbm);
1614 }
1615 }
1616 if (hwndTool)
1617 tool->flags &= (~T_TEXT);
1618 }
1619 if (!hwndTool) {
1620 hwndTool = WinCreateWindow(hwndT,
1621 (CHAR *) WC_TOOLBUTTONS,
1622 (!tool->text && tool->id >= IDM_COMMANDSTART
1623 && tool->id <
1624 IDM_QUICKTOOLSTART) ? command_title(tool->id -
1625 IDM_COMMANDSTART)
1626 : tool->text,
1627 BS_NOPOINTERFOCUS | BS_PUSHBUTTON, ctrlxpos,
1628 2, 54, 24, hwndT, HWND_TOP, tool->id, NULL,
1629 NULL);
1630 if (!hwndTool)
1631 Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1632 PCSZ_WINCREATEWINDOW);
1633 tool->flags |= T_TEXT;
1634 }
1635 if (fToolTitles && !fTextTools) {
1636 hwndTool = WinCreateWindow(hwndT,
1637 (CHAR *) WC_STATIC,
1638 tool->text,
1639 SS_TEXT | DT_LEFT | DT_VCENTER,
1640 ctrlxpos,
1641 1,
1642 32,
1643 10,
1644 hwndT,
1645 HWND_TOP, tool->id + 25000, NULL, NULL);
1646 if (!hwndTool)
1647 Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1648 PCSZ_WINCREATEWINDOW);
1649 else {
1650 SetPresParams(hwndTool,
1651 &RGBGREY,
1652 &RGBBLACK, &RGBGREY, FNT_2SYSTEMVIO);
1653 }
1654 }
1655 ctrlxpos += ((tool->flags & T_TEXT) ? 55L : 33L);
1656 //fixme to allow user to change presparams 1-10-09 GKY
1657 SetPresParams(WinWindowFromID(hwndT, tool->id),
1658 NULL, NULL, NULL, FNT_8HELVETICA);
1659 tool = tool->next;
1660 } // while tool
1661
1662 hwndTool = WinCreateWindow(hwndT,
1663 (CHAR *) WC_BUTTON,
1664 "#6010",
1665 BS_NOPOINTERFOCUS |
1666 BS_BITMAP | BS_PUSHBUTTON,
1667 1,
1668 19,
1669 14,
1670 13, hwndT, HWND_TOP, IDM_TOOLLEFT, NULL, NULL);
1671 if (!hwndTool)
1672 Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1673 PCSZ_WINCREATEWINDOW);
1674 hwndTool =
1675 WinCreateWindow(hwndT, (CHAR *) WC_BUTTON, "#6011",
1676 BS_NOPOINTERFOCUS | BS_BITMAP | BS_PUSHBUTTON, 1, 4, 14,
1677 13, hwndT, HWND_TOP, IDM_TOOLRIGHT, NULL, NULL);
1678 if (!hwndTool)
1679 Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
1680 PCSZ_WINCREATEWINDOW);
1681 if (resize)
1682 ResizeTools(hwndT);
1683}
1684
1685static MRESULT EXPENTRY CommandLineProc(HWND hwnd, ULONG msg, MPARAM mp1,
1686 MPARAM mp2)
1687{
1688 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1689 static BOOL lbup = FALSE;
1690
1691 switch (msg) {
1692 case UM_FOCUSME:
1693 WinSetFocus(HWND_DESKTOP, hwnd);
1694 return 0;
1695
1696 case WM_SETFOCUS:
1697 if (!mp2 && !lbup) {
1698
1699 PID pid;
1700 TID tid;
1701
1702 if (WinQueryWindowUShort((HWND) mp1, QWS_ID) == COMMAND_BUTTON)
1703 break;
1704 if (!WinQueryWindowProcess((HWND) mp1, &pid, &tid) || pid == mypid)
1705 WinDestroyWindow(hwnd);
1706 }
1707 break;
1708
1709 case UM_RESCAN:
1710 {
1711 PSZ pszCmdLine;
1712
1713 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1714 if (pszCmdLine) {
1715 lbup = TRUE;
1716 if (WinDlgBox(HWND_DESKTOP,
1717 hwnd,
1718 CmdLine2DlgProc,
1719 FM3ModHandle, EXEC2_FRAME, MPFROMP(pszCmdLine))) {
1720 lstrip(pszCmdLine);
1721 WinSetWindowText(hwnd, pszCmdLine);
1722 }
1723 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1724 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1725 free(pszCmdLine);
1726 }
1727 }
1728 return 0;
1729
1730 case UM_SETUP:
1731 lbup = FALSE;
1732 return 0;
1733
1734 case WM_BUTTON1DBLCLK:
1735 PostMsg(hwnd, UM_OPENWINDOWFORME, MPVOID, MPVOID);
1736 return 0;
1737
1738 case WM_COMMAND:
1739 switch (SHORT1FROMMP(mp1)) {
1740 case COMMAND_BUTTON:
1741 if (!lbup)
1742 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1743 break;
1744 }
1745 return 0;
1746
1747 case UM_OPENWINDOWFORME:
1748 {
1749 static char directory[CCHMAXPATH], cl[1000];
1750 char **list = NULL;
1751 ULONG len;
1752 HWND hwndCnr;
1753
1754 *directory = *cl = 0;
1755 strcpy(cl, GetCmdSpec(FALSE));
1756 strcat(cl, " /C ");
1757 len = strlen(cl);
1758 WinQueryWindowText(hwnd, 1000 - len, cl + len);
1759 bstrip(cl + len);
1760 if (strlen(cl) > len) {
1761 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
1762 UM_SETUP, MPFROMP(cl + len), MPVOID);
1763 WinQueryWindowText(hwndStatus, CCHMAXPATH, directory);
1764 bstrip(directory);
1765 if (*directory && (IsRoot(directory) || !IsFile(directory))) {
1766 if (!FM2Command(directory, cl + len)) {
1767 hwndCnr = TopWindow(hwndMain, (HWND) 0);
1768 if (hwndCnr) {
1769 hwndCnr = WinWindowFromID(hwndCnr, FID_CLIENT);
1770 if (hwndCnr) {
1771 hwndCnr = WinWindowFromID(hwndCnr, DIR_CNR);
1772 if (hwndCnr)
1773 list = BuildList(hwndCnr);
1774 }
1775 }
1776 WinSetActiveWindow(HWND_DESKTOP, hwndCnr);
1777 if (add_cmdline(cl + len, FALSE) && fSaveMiniCmds)
1778 save_cmdlines(FALSE);
1779 ExecOnList(hwndCnr,
1780 cl,
1781 WINDOWED | ((fKeepCmdLine) ?
1782 SEPARATEKEEP : SEPARATE),
1783 directory, NULL, list, NULL, pszSrcFile, __LINE__);
1784 xfree(list, pszSrcFile, __LINE__);
1785 WinDestroyWindow(hwnd);
1786 break;
1787 }
1788 }
1789 }
1790 WinSendMsg(hwnd, EM_SETSEL, MPFROM2SHORT(0, 1024), MPVOID);
1791 }
1792 return 0;
1793
1794 case WM_CHAR:
1795 if (!lbup && !(SHORT1FROMMP(mp1) & KC_KEYUP)) {
1796 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
1797 if ((SHORT1FROMMP(mp2) & 255) == '\r')
1798 PostMsg(hwnd, UM_OPENWINDOWFORME, MPVOID, MPVOID);
1799 else if ((SHORT1FROMMP(mp2) & 0xff) == 0x1b)
1800 WinDestroyWindow(hwnd);
1801 else if (SHORT2FROMMP(mp2) == VK_UP || SHORT2FROMMP(mp2) == VK_DOWN)
1802 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1803 }
1804 }
1805 else if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
1806 ((SHORT2FROMMP(mp2) == VK_UP ||
1807 SHORT2FROMMP(mp2) == VK_DOWN) ||
1808 (SHORT1FROMMP(mp2) == '\x1b') || (SHORT1FROMMP(mp2) == '\r')))
1809 return 0;
1810 break;
1811
1812 case WM_DESTROY:
1813 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_RESCAN, MPVOID, MPVOID);
1814 lbup = FALSE;
1815 break;
1816 }
1817 return oldproc(hwnd, msg, mp1, mp2);
1818}
1819
1820MRESULT EXPENTRY DriveBackProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1821{
1822 APIRET rc;
1823
1824 static BOOL emphasized;
1825
1826 switch (msg) {
1827 case WM_CREATE:
1828 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1829 break;
1830
1831 case UM_SETUP:
1832 {
1833 RGB2 rgb;
1834
1835 memset(&rgb, 0, sizeof(rgb));
1836 rgb.bRed = (BYTE)128;
1837 //fixme to allow user to change presparams 1-10-09 GKY
1838 SetPresParams(hwnd,
1839 &RGBGREY, &rgb, &RGBGREY, FNT_8HELVETICA);
1840 SetTargetDir(hwnd, TRUE, NULL);
1841 }
1842 return 0;
1843
1844 case WM_SETFOCUS:
1845 case UM_FOCUSME:
1846 case WM_BUTTON1DOWN:
1847 case WM_BUTTON1UP:
1848 case WM_BUTTON2DOWN:
1849 case WM_BUTTON2UP:
1850 case WM_BUTTON3DOWN:
1851 case WM_BUTTON3UP:
1852 return CommonTextButton(hwnd, msg, mp1, mp2);
1853
1854 case WM_MOUSEMOVE:
1855 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1856 break;
1857
1858 case UM_CLICKED:
1859 case UM_CLICKED3:
1860 PostMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_SETTARGET, 0), MPVOID);
1861 return 0;
1862
1863 case DM_DRAGOVER:
1864 if (!emphasized) {
1865 emphasized = TRUE;
1866 DrawTargetEmphasis(hwnd, emphasized);
1867 }
1868 if (AcceptOneDrop(hwnd, mp1, mp2))
1869 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1870 return MRFROM2SHORT(DOR_NEVERDROP, 0);
1871
1872 case DM_DRAGLEAVE:
1873 if (emphasized) {
1874 emphasized = FALSE;
1875 DrawTargetEmphasis(hwnd, emphasized);
1876 }
1877 break;
1878
1879 case DM_DROPHELP:
1880 if (mp1) {
1881
1882 CNRDRAGINFO cnd;
1883 ULONG numitems;
1884 USHORT usOperation;
1885
1886 cnd.pDragInfo = (PDRAGINFO) mp1;
1887 if (!DrgAccessDraginfo((PDRAGINFO) cnd.pDragInfo)) {
1888 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
1889 PCSZ_DRGACCESSDRAGINFO);
1890 return 0;
1891 }
1892 numitems = DrgQueryDragitemCount((PDRAGINFO) cnd.pDragInfo);
1893 usOperation = cnd.pDragInfo->usOperation;
1894 if (usOperation == DO_DEFAULT)
1895 usOperation = fCopyDefault ? DO_COPY : DO_MOVE;
1896 saymsg(MB_ENTER | MB_ICONASTERISK,
1897 hwnd,
1898 GetPString(IDS_DROPHELPHDRTEXT),
1899 GetPString(IDS_DROPHELPTEXT),
1900 numitems,
1901 &"s"[numitems == 1L],
1902 NullStr,
1903 NullStr,
1904 targetdir,
1905 " ",
1906 GetPString((usOperation == DO_MOVE) ?
1907 IDS_MOVETEXT :
1908 (usOperation == DO_LINK) ?
1909 IDS_LINKTEXT : IDS_COPYTEXT));
1910 }
1911 return 0;
1912
1913
1914 case DM_DROP:
1915 if (targetdir && strlen(targetdir) > 2) {
1916 CNRDRAGINFO cnd;
1917 LISTINFO *li;
1918 ULONG action = UM_ACTION, ret;
1919
1920 if (emphasized) {
1921 emphasized = FALSE;
1922 DrawTargetEmphasis(hwnd, emphasized);
1923 }
1924 memset(&cnd, 0, sizeof(cnd));
1925 cnd.pDragInfo = (PDRAGINFO) mp1;
1926 cnd.pRecord = NULL;
1927 li = DoFileDrop(hwnd,
1928 NULL,
1929 TRUE, MPFROM2SHORT(TREE_CNR, CN_DROP), MPFROMP(&cnd));
1930 CheckPmDrgLimit(cnd.pDragInfo);
1931 if (li) {
1932 if (!li->list[1] && !IsFile(li->list[0])) {
1933 ret = saymsg(MB_YESNO,
1934 HWND_DESKTOP,
1935 NullStr,
1936 GetPString(IDS_DROPSETSTARGET));
1937 if (ret == MBID_YES) {
1938 SetTargetDir(hwnd, TRUE, li->list[0]);
1939 break;
1940 }
1941 }
1942 strcpy(li->targetpath, targetdir);
1943 strcat(li->targetpath, PCSZ_BACKSLASH);
1944 if (li->list && li->list[0] && IsRoot(li->list[0]))
1945 li->type = DO_LINK;
1946 else if (fDragndropDlg && (!*li->arcname || !li->info)) {
1947
1948 CHECKLIST cl;
1949
1950 memset(&cl, 0, sizeof(cl));
1951 cl.size = sizeof(cl);
1952 cl.flags = li->type;
1953 cl.list = li->list;
1954 cl.cmd = li->type;
1955 cl.prompt = li->targetpath;
1956 li->type = WinDlgBox(HWND_DESKTOP,
1957 hwndMain,
1958 DropListProc,
1959 FM3ModHandle, DND_FRAME, MPFROMP(&cl));
1960 if (li->type == DID_ERROR)
1961 Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
1962 GetPString(IDS_DRAGDROPDIALOGTEXT));
1963 if (!li->type) {
1964 FreeListInfo(li);
1965 return 0;
1966 }
1967 li->list = cl.list;
1968 if (!li->list || !li->list[0]) {
1969 FreeListInfo(li);
1970 return 0;
1971 }
1972 }
1973 else {
1974 FreeListInfo(li);
1975 return 0;
1976 }
1977 }
1978 switch (li->type) {
1979 case DND_LAUNCH:
1980 strcat(li->targetpath, " %a");
1981 ExecOnList(hwndMain,
1982 li->targetpath, PROMPT | WINDOWED, NULL, NULL, li->list, NULL,
1983 pszSrcFile, __LINE__);
1984 FreeList(li->list);
1985 li->list = NULL;
1986 break;
1987 case DO_LINK:
1988 if (fLinkSetsIcon) {
1989 li->type = IDM_SETICON;
1990 action = UM_MASSACTION;
1991 }
1992 else
1993 li->type = IDM_COMPARE;
1994 break;
1995 case DND_EXTRACT:
1996 if (*li->targetpath && !IsFile(li->targetpath))
1997 li->type = IDM_EXTRACT;
1998 break;
1999 case DND_MOVE:
2000 li->type = IDM_MOVE;
2001 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2002 action = UM_MASSACTION;
2003 li->type = IDM_ARCHIVEM;
2004 }
2005 break;
2006 case DND_WILDMOVE:
2007 li->type = IDM_WILDMOVE;
2008 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2009 action = UM_MASSACTION;
2010 li->type = IDM_ARCHIVEM;
2011 }
2012 break;
2013 case DND_OBJECT:
2014 li->type = IDM_OBJECT;
2015 action = UM_MASSACTION;
2016 break;
2017 case DND_SHADOW:
2018 li->type = IDM_SHADOW;
2019 action = UM_MASSACTION;
2020 break;
2021 case DND_COMPARE:
2022 li->type = IDM_COMPARE;
2023 break;
2024 case DND_SETICON:
2025 action = UM_MASSACTION;
2026 li->type = IDM_SETICON;
2027 break;
2028 case DND_COPY:
2029 li->type = IDM_COPY;
2030 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2031 action = UM_MASSACTION;
2032 li->type = IDM_ARCHIVE;
2033 }
2034 break;
2035 case DND_WILDCOPY:
2036 li->type = IDM_WILDCOPY;
2037 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2038 action = UM_MASSACTION;
2039 li->type = IDM_ARCHIVE;
2040 }
2041 break;
2042 default:
2043 if (*li->arcname && li->info) {
2044 action = UM_MASSACTION;
2045 li->type = (li->type == DO_MOVE) ? IDM_FAKEEXTRACTM :
2046 IDM_FAKEEXTRACT;
2047 }
2048 else if (*li->targetpath && IsFile(li->targetpath) == 1) {
2049 action = UM_MASSACTION;
2050 li->type = (li->type == DO_MOVE) ? IDM_ARCHIVEM : IDM_ARCHIVE;
2051 }
2052 else
2053 li->type = (li->type == DO_MOVE) ? IDM_MOVE : IDM_COPY;
2054 break;
2055 }
2056 if (!li->list || !li->list[0])
2057 FreeListInfo(li);
2058 else
2059 WinSendMsg(hwndTree, UM_ACTION, MPFROMP(li), MPFROMLONG(action));
2060 }
2061 else {
2062 CNRDRAGINFO cnd;
2063 LISTINFO *li;
2064
2065 if (emphasized) {
2066 emphasized = FALSE;
2067 DrawTargetEmphasis(hwnd, emphasized);
2068 }
2069 memset(&cnd, 0, sizeof(cnd));
2070 cnd.pDragInfo = (PDRAGINFO) mp1;
2071 cnd.pRecord = NULL;
2072 li = DoFileDrop(hwnd,
2073 NULL,
2074 TRUE, MPFROM2SHORT(TREE_CNR, CN_DROP), MPFROMP(&cnd));
2075 CheckPmDrgLimit(cnd.pDragInfo);
2076 if (li && !li->list[1] && !IsFile(li->list[0]))
2077 SetTargetDir(hwnd, TRUE, li->list[0]);
2078 else
2079 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
2080 GetPString(IDS_WARNINGTEXT),
2081 GetPString(IDS_NOTARGETSET));
2082 }
2083 break;
2084
2085 case WM_CHAR:
2086 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2087 break;
2088
2089 case WM_CONTROLPOINTER:
2090 if (!fNoFinger &&
2091 (SHORT1FROMMP(mp1) >= IDM_DRIVEA &&
2092 SHORT1FROMMP(mp1) < IDM_DRIVEA + 26))
2093 return MRFROMLONG(hptrFinger);
2094 break;
2095
2096 case WM_COMMAND:
2097 rc = DosWaitEventSem(hevTreeCnrScanComplete, SEM_INDEFINITE_WAIT);
2098 if (rc)
2099 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, "DosWaitEventSem");
2100
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, numsaves = 0;
3449 LONG x;
3450 double xtrans, ytrans;
3451 BOOL fRestored = FALSE;
3452 DIRCNRDATA localdcd, *dcd;
3453 BOOL fIsShutDownState;
3454 BOOL fDeleteState;
3455
3456 if (!pszStateName || !*pszStateName) {
3457 Runtime_Error(pszSrcFile, __LINE__, "no name");
3458 return fRestored;
3459 }
3460 if (strlen(pszStateName) > sizeof(szPrefix) - 2) {
3461 Runtime_Error(pszSrcFile, __LINE__, "name too long");
3462 return fRestored;
3463 }
3464
3465 sprintf(szPrefix, "%s.", pszStateName);
3466
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 if (fDeleteState)
3536 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
3537 for (x = numsaves - 1; x >= 0; x--) {
3538 CHAR *eos = szKey;
3539
3540 sprintf(szKeyBase, "%sDirCnr.%lu", szPrefix, x);
3541 strcpy(szKey, szKeyBase);
3542 strcat(szKey, ".");
3543 eos = &szKey[strlen(szKey)];
3544 strcpy(eos, "Pos");
3545 size = sizeof(SWP);
3546 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &swp, &size)) {
3547 strcpy(eos, "Dir"); ;
3548 size = sizeof(szDir);
3549 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) szDir, &size)) {
3550 // If restoring shutdown state and drive marked no prescan
3551 // bypass window restore
3552 if (fIsShutDownState &&
3553 driveflags[toupper(*szDir) - 'A'] & DRIVE_NOPRESCAN) {
3554 RemoveCnrSwitches(szKeyBase, NULL);
3555 RemoveOldCnrSwitches(szPrefix, x);
3556 continue;
3557 }
3558 LoadDetailsSwitches(szKeyBase, &localdcd.ds, TRUE);
3559 hwndDir = (HWND) WinSendMsg(hwndClient,
3560 UM_SETDIR,
3561 MPFROMP(szDir), MPFROMLONG(1));
3562 if (hwndDir) {
3563 hwndC = WinWindowFromID(hwndDir, FID_CLIENT);
3564 if (hwndC) {
3565 HWND hwndCnr = WinWindowFromID(hwndC, DIR_CNR);
3566 if (!hwndPPSave) {
3567 hwndPPSave = WinCreateWindow(hwndCnr, // Create a window (used to save default presparams)
3568 (CHAR *) WC_CONTAINER,
3569 NULL,
3570 CCS_AUTOPOSITION | CCS_MINIICONS |
3571 CCS_MINIRECORDCORE | ulCnrType,
3572 0,
3573 0,
3574 0,
3575 0,
3576 hwndCnr,
3577 HWND_TOP, (ULONG) -1, NULL, NULL);
3578 CopyPresParams(hwndPPSave, hwndC);
3579 RestorePresParams(hwndPPSave, PCSZ_DIRCNR);
3580 }
3581 RestorePresParams(hwndCnr, szKeyBase);
3582 dcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
3583 if (dcd) {
3584 dcd->ds.detailslongname = localdcd.ds.detailslongname;
3585 dcd->ds.detailssubject = localdcd.ds.detailssubject ;
3586 dcd->ds.detailsattr = localdcd.ds.detailsattr ;
3587 dcd->ds.detailsea = localdcd.ds.detailsea ;
3588 dcd->ds.detailssize = localdcd.ds.detailssize ;
3589 dcd->ds.detailsicon = localdcd.ds.detailsicon ;
3590 dcd->ds.detailscrdate = localdcd.ds.detailscrdate ;
3591 dcd->ds.detailscrtime = localdcd.ds.detailscrtime ;
3592 dcd->ds.detailsladate = localdcd.ds.detailsladate ;
3593 dcd->ds.detailslatime = localdcd.ds.detailslatime ;
3594 dcd->ds.detailslwdate = localdcd.ds.detailslwdate ;
3595 dcd->ds.detailslwtime = localdcd.ds.detailslwtime ;
3596 strcpy(eos, "Sort");
3597 size = sizeof(INT);
3598 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &dcd->sortFlags,
3599 &size)) {
3600 if (!dcd->sortFlags)
3601 dcd->sortFlags = SORT_PATHNAME;
3602 }
3603 size = sizeof(MASK);
3604 strcpy(eos, "Filter");
3605 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &dcd->mask, &size)) {
3606 if (*dcd->mask.szMask)
3607 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3608 UM_FILTER, MPFROMP(dcd->mask.szMask), MPVOID);
3609 }
3610 *(dcd->mask.prompt) = 0;
3611 strcpy(eos, "View");
3612 if (!noview) {
3613 size = sizeof(ULONG);
3614 if (PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &dcd->flWindowAttr,
3615 &size)) {
3616
3617 CNRINFO cnri;
3618
3619 memset(&cnri, 0, sizeof(CNRINFO));
3620 cnri.cb = sizeof(CNRINFO);
3621 if (WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3622 CM_QUERYCNRINFO,
3623 MPFROMP(&cnri),
3624 MPFROMLONG(sizeof(CNRINFO)))) {
3625 cnri.flWindowAttr = dcd->flWindowAttr;
3626 WinSendMsg(WinWindowFromID(hwndC, DIR_CNR),
3627 CM_SETCNRINFO,
3628 MPFROMP(&cnri),
3629 MPFROMLONG(CMA_FLWINDOWATTR));
3630 }
3631 }
3632 }
3633 if (!PostMsg(hwndCnr, UM_SETUP2, NULL, NULL))
3634 WinSendMsg(hwndCnr, UM_SETUP2, NULL, NULL);
3635 }
3636 }
3637 fRestored = TRUE;
3638 swp.hwnd = hwndDir;
3639 TransformSwp(&swp, xtrans, ytrans);
3640 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3641 WinSetWindowPos(hwndDir,
3642 HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);
3643 WinSetWindowUShort(hwndDir, QWS_XRESTORE, (USHORT) swp.x);
3644 WinSetWindowUShort(hwndDir, QWS_CXRESTORE, (USHORT) swp.cx);
3645 WinSetWindowUShort(hwndDir, QWS_YRESTORE, (USHORT) swp.y);
3646 WinSetWindowUShort(hwndDir, QWS_CYRESTORE, (USHORT) swp.cy);
3647 } else
3648 WinSetWindowPos(hwndDir,
3649 HWND_TOP,
3650 swp.x,
3651 swp.y,
3652 swp.cx,
3653 swp.cy,
3654 swp.fl | SWP_MOVE |
3655 SWP_SIZE | SWP_SHOW | SWP_ZORDER |
3656 SWP_ACTIVATE);
3657 }
3658 if (fDeleteState)
3659 RemoveCnrSwitches(szKeyBase, pszStateName);
3660 }
3661 }
3662 } // for
3663 if (hwndPPSave) {
3664 SavePresParams(hwndPPSave, PCSZ_DIRCNR);
3665 WinDestroyWindow(hwndPPSave);
3666 }
3667 }
3668 return fRestored;
3669}
3670
3671static ULONG CountChildren(HWND hwndClient, ULONG * ulNumMinChildren)
3672{
3673 HENUM henum;
3674 HWND hwndChild;
3675 SWP swp;
3676 register ULONG ulCnt = 0L;
3677 USHORT id;
3678
3679 if (ulNumMinChildren)
3680 *ulNumMinChildren = 0L;
3681 henum = WinBeginEnumWindows(hwndClient);
3682 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3683 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3684 if (!id || (!fFreeTree && id == TREE_FRAME))
3685 continue;
3686 ulCnt++;
3687 if (ulNumMinChildren) {
3688 if (WinQueryWindowPos(hwndChild, &swp) && (swp.fl & SWP_MINIMIZE))
3689 (*ulNumMinChildren)++;
3690 }
3691 }
3692 WinEndEnumWindows(henum);
3693 return ulCnt;
3694}
3695
3696VOID GetNextWindowPos(HWND hwndClient, PSWP pswp, ULONG * ulCntR,
3697 ULONG * ulNumMinChildrenR)
3698{
3699 register ULONG ulCnt;
3700 ULONG ulNumMinChildren;
3701 RECTL Rectl;
3702 register ULONG ulXDiff, ulYDiff, ulWindowsPerStack;
3703
3704 if (!ulCntR || !ulNumMinChildrenR)
3705 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3706 else {
3707 ulCnt = *ulCntR;
3708 ulNumMinChildren = *ulNumMinChildrenR;
3709 if (ulCnt == (ULONG) - 1) {
3710 ulCnt = CountChildren(hwndClient, &ulNumMinChildren);
3711 // return these values to the caller for later use
3712 *ulCntR = ulCnt;
3713 *ulNumMinChildrenR = ulNumMinChildren;
3714 }
3715 }
3716 WinQueryWindowRect(hwndClient, &Rectl);
3717 AdjustSizeOfClient(NULL, &Rectl);
3718 if (!fFreeTree) {
3719
3720 SWP swp;
3721
3722 WinQueryWindowPos(hwndTree, &swp);
3723 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3724 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3725 }
3726 else if (ulNumMinChildren)
3727 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3728
3729 ulXDiff = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) +
3730 WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON) / 2;
3731 ulYDiff = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER) +
3732 WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
3733 ulWindowsPerStack = (Rectl.yTop - Rectl.yBottom) / (3 * ulYDiff);
3734 pswp->cx = Rectl.xRight - (ulWindowsPerStack * ulXDiff);
3735 pswp->cy = (Rectl.yTop - Rectl.yBottom) - (ulWindowsPerStack * ulYDiff);
3736 ulWindowsPerStack++;
3737 pswp->x = Rectl.xLeft + ((ulCnt % ulWindowsPerStack) * ulXDiff);
3738 pswp->y = (Rectl.yTop - pswp->cy - ((ulCnt % ulWindowsPerStack) * ulYDiff));
3739}
3740
3741static VOID CascadeChildren(HWND hwndClient)
3742{
3743 ULONG ulCnt = 0L, ulNumMinChildren;
3744 HWND hwndChild;
3745 HENUM henum;
3746 SWP swp;
3747 USHORT id;
3748 RECTL Rectl;
3749
3750 WinQueryWindowPos(hwndClient, &swp);
3751 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3752 return;
3753
3754 CountChildren(hwndClient, &ulNumMinChildren);
3755 if (!fFreeTree) {
3756 WinQueryWindowRect(hwndClient, &Rectl);
3757 AdjustSizeOfClient(NULL, &Rectl);
3758 WinQueryWindowPos(hwndTree, &swp);
3759 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3760 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3761 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3762 if (swp.x != 0)
3763 swp.x = 0;
3764 if (swp.y < 0)
3765 swp.y = 0;
3766 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3767 swp.cx = Rectl.xRight - Rectl.xLeft;
3768 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3769 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3770 }
3771 }
3772 henum = WinBeginEnumWindows(hwndClient);
3773 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3774 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3775 if (!id || (!fFreeTree && id == TREE_FRAME))
3776 continue;
3777 WinQueryWindowPos(hwndChild, &swp);
3778 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
3779 GetNextWindowPos(hwndClient, &swp, &ulCnt, &ulNumMinChildren);
3780 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3781 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
3782 SWP_ZORDER | SWP_ACTIVATE);
3783 ulCnt++;
3784 }
3785 }
3786 WinEndEnumWindows(henum);
3787}
3788
3789VOID TileChildren(HWND hwndClient, BOOL absolute)
3790{
3791 register ULONG ulChildCnt, ulSquare, ulNumRows, ulNumCols, ulExtraCols,
3792 ulWidth, ulHeight;
3793 ULONG ulNumMinChildren;
3794 RECTL Rectl;
3795 HWND hwndChild;
3796 SWP swp;
3797
3798 if (fNoTileUpdate || hwndClient == HWND_DESKTOP)
3799 return;
3800
3801 WinQueryWindowPos(hwndClient, &swp);
3802 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
3803 return;
3804
3805 ulChildCnt = CountChildren(hwndClient, &ulNumMinChildren);
3806 ulChildCnt -= ulNumMinChildren;
3807 if (!ulChildCnt)
3808 return;
3809
3810 fNoTileUpdate = TRUE;
3811
3812 for (ulSquare = 2; ulSquare * ulSquare <= ulChildCnt; ulSquare++) {
3813 ;
3814 }
3815 if (!fTileBackwards) {
3816 ulNumCols = ulSquare - 1;
3817 ulNumRows = ulChildCnt / ulNumCols;
3818 }
3819 else {
3820 ulNumRows = ulSquare - 1;
3821 ulNumCols = ulChildCnt / ulNumRows;
3822 }
3823 ulExtraCols = ulChildCnt % ulNumCols;
3824
3825 WinQueryWindowRect(hwndClient, &Rectl);
3826
3827 if (!fFreeTree) {
3828 WinQueryWindowPos(hwndTree, &swp);
3829 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
3830 if (swp.y < 0)
3831 swp.y = 0;
3832 if (swp.y + swp.cy < Rectl.yTop - Rectl.yBottom)
3833 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
3834 if (swp.x != 0)
3835 swp.x = 0;
3836 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
3837 swp.cx = Rectl.xRight - Rectl.xLeft;
3838 WinSetWindowPos(hwndTree,
3839 HWND_TOP,
3840 swp.x,
3841 swp.y,
3842 swp.cx,
3843 swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3844 WinQueryWindowPos(hwndTree, &swp);
3845 }
3846 if (ulNumMinChildren || (swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3847 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3848 }
3849 else if (ulNumMinChildren)
3850 Rectl.yBottom += WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
3851
3852 AdjustSizeOfClient(NULL, &Rectl);
3853
3854 if (Rectl.xRight > 0L && (Rectl.yBottom < Rectl.yTop)) {
3855
3856 HENUM henum;
3857
3858 henum = WinBeginEnumWindows(hwndClient);
3859 if ((hwndChild = WinGetNextWindow(henum)) != (HWND) 0) {
3860
3861 ULONG ulCurRow, ulCurCol;
3862 SWP swp;
3863 USHORT id;
3864
3865 ulHeight = (Rectl.yTop - Rectl.yBottom) / ulNumRows;
3866
3867 for (ulCurRow = 0; ulCurRow < ulNumRows; ulCurRow++) {
3868 if ((ulNumRows - ulCurRow) <= ulExtraCols)
3869 ulNumCols++;
3870 for (ulCurCol = 0; ulCurCol < ulNumCols; ulCurCol++) {
3871 ulWidth = Rectl.xRight / ulNumCols;
3872
3873 while (hwndChild) {
3874 id = WinQueryWindowUShort(hwndChild, QWS_ID);
3875 if (id && (id != TREE_FRAME || fFreeTree)) {
3876 WinQueryWindowPos(hwndChild, &swp);
3877 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
3878 break;
3879 }
3880 hwndChild = WinGetNextWindow(henum);
3881 }
3882
3883 if (hwndChild) {
3884 if (!absolute && (swp.fl & SWP_MAXIMIZE)) {
3885 WinGetMaxPosition(hwndChild, &swp);
3886 WinSetWindowPos(hwndChild,
3887 HWND_TOP,
3888 swp.x,
3889 swp.y,
3890 swp.cx, swp.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);
3891 WinSetWindowUShort(hwndChild,
3892 QWS_XRESTORE,
3893 (USHORT) ((USHORT) ulWidth * (USHORT) ulCurCol)
3894 + (USHORT) Rectl.xLeft);
3895 WinSetWindowUShort(hwndChild,
3896 QWS_YRESTORE,
3897 (USHORT) (Rectl.yTop -
3898 (ulHeight * (ulCurRow + 1))));
3899 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, (USHORT) ulWidth);
3900 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, (USHORT) ulHeight);
3901 }
3902 else
3903 WinSetWindowPos(hwndChild,
3904 HWND_TOP,
3905 (ulWidth * ulCurCol) + Rectl.xLeft,
3906 Rectl.yTop - (ulHeight * (ulCurRow + 1)),
3907 ulWidth,
3908 ulHeight,
3909 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
3910 hwndChild = WinGetNextWindow(henum);
3911 }
3912 }
3913 if ((ulNumRows - ulCurRow) <= ulExtraCols) {
3914 ulNumCols--;
3915 ulExtraCols--;
3916 }
3917 }
3918 }
3919 WinEndEnumWindows(henum);
3920 }
3921
3922 fNoTileUpdate = FALSE;
3923}
3924
3925static VOID ResizeChildren(HWND hwndClient, SHORT oldcx, SHORT oldcy,
3926 SHORT newcx, SHORT newcy)
3927{
3928 /**
3929 * resize all children of the client to maintain their proportional
3930 * sizes and positions
3931 */
3932
3933 if (!newcx || !newcy || !oldcx || !oldcy)
3934 return;
3935 {
3936 HENUM henum;
3937 HWND hwndChild;
3938 register LONG x, y, cx, cy, ucx, ucy, ux, uy;
3939 SWP swp;
3940
3941 henum = WinBeginEnumWindows(hwndClient);
3942 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
3943 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
3944 continue;
3945 if (WinQueryWindowPos(hwndChild, &swp)) {
3946 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
3947 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3948 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3949 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3950 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3951 }
3952 else if (swp.fl & SWP_MAXIMIZE) {
3953 swp.x = WinQueryWindowUShort(hwndChild, QWS_XRESTORE);
3954 swp.y = WinQueryWindowUShort(hwndChild, QWS_YRESTORE);
3955 swp.cx = WinQueryWindowUShort(hwndChild, QWS_CXRESTORE);
3956 swp.cy = WinQueryWindowUShort(hwndChild, QWS_CYRESTORE);
3957 }
3958 cx = (swp.cx) ? (LONG) (((double)oldcx * 100.0) / (double)swp.cx) : 0;
3959 cy = (swp.cy) ? (LONG) (((double)oldcy * 100.0) / (double)swp.cy) : 0;
3960 x = (swp.x) ? (LONG) (((double)oldcx * 100.0) / (double)swp.x) : 0;
3961 y = (swp.y) ? (LONG) (((double)oldcy * 100.0) / (double)swp.y) : 0;
3962 if (x < 0)
3963 x = 0;
3964 if (y < 0)
3965 y = 0;
3966 ux = (x) ? (LONG) (((double)newcx * 100.0) / (double)x) : 0;
3967 uy = (y) ? (LONG) (((double)newcy * 100.0) / (double)y) : 0;
3968 ucx = (cx) ? (LONG) (((double)newcx * 100.0) / (double)cx) : 0;
3969 ucy = (cy) ? (LONG) (((double)newcy * 100.0) / (double)cy) : 0;
3970 if (ux + ucx > newcx)
3971 ucx = newcx - ux;
3972 if (uy + ucy > newcy)
3973 ucy = newcy - uy;
3974
3975 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE | SWP_MAXIMIZE)))
3976 WinSetWindowPos(hwndChild, HWND_TOP, ux, uy, ucx, ucy,
3977 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3978 else if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
3979 WinSetWindowUShort(hwndChild, QWS_XMINIMIZE, (USHORT) - 1);
3980 WinSetWindowUShort(hwndChild, QWS_YMINIMIZE, (USHORT) - 1);
3981 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0,
3982 SWP_SIZE | SWP_MOVE | SWP_FOCUSDEACTIVATE);
3983 WinSetWindowUShort(hwndChild, QWS_XRESTORE, (USHORT) ux);
3984 WinSetWindowUShort(hwndChild, QWS_YRESTORE, (USHORT) uy);
3985 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, (USHORT) ucx);
3986 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, (USHORT) ucy);
3987 }
3988 else {
3989 WinGetMaxPosition(hwndChild, &swp);
3990 WinSetWindowPos(hwndChild, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
3991 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3992 WinSetWindowUShort(hwndChild, QWS_XRESTORE, (USHORT) ux);
3993 WinSetWindowUShort(hwndChild, QWS_YRESTORE, (USHORT) uy);
3994 WinSetWindowUShort(hwndChild, QWS_CXRESTORE, (USHORT) ucx);
3995 WinSetWindowUShort(hwndChild, QWS_CYRESTORE, (USHORT) ucy);
3996 }
3997 }
3998 }
3999 WinEndEnumWindows(henum);
4000 }
4001 if (!fFreeTree) {
4002
4003 RECTL Rectl;
4004 SWP swp;
4005
4006 WinQueryWindowRect(hwndClient, &Rectl);
4007 AdjustSizeOfClient(NULL, &Rectl);
4008 WinQueryWindowPos(hwndTree, &swp);
4009 if (!(swp.fl & (SWP_MAXIMIZE | SWP_HIDE | SWP_MINIMIZE))) {
4010
4011 if (!fNoTreeGap) {
4012 INT height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
4013 if (swp.y < height)
4014 swp.y = height; // Force bottom to position
4015 }
4016 else
4017 swp.y = 0; // Force bottom to position
4018
4019 swp.cy = (Rectl.yTop - Rectl.yBottom) - swp.y;
4020 if (swp.cy < 0)
4021 swp.cy = 0;
4022
4023 if (swp.x != 0)
4024 swp.x = 0; // Left align
4025
4026 // AdjustSizeOfClient can return bogus xRight values - fixme someday
4027 if (Rectl.xRight >= Rectl.xLeft) {
4028 if (swp.x + swp.cx > Rectl.xRight - Rectl.xLeft)
4029 swp.cx = Rectl.xRight - Rectl.xLeft;
4030 }
4031 WinSetWindowPos(hwndTree, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4032 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_RESTORE);
4033 }
4034 }
4035}
4036
4037static VOID MinResChildren(HWND hwndClient, ULONG cmd)
4038{
4039 HENUM henum;
4040 HWND hwndChild;
4041
4042 {
4043 SWP swp;
4044
4045 WinQueryWindowPos(hwndClient, &swp);
4046 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE))
4047 return;
4048 }
4049 henum = WinBeginEnumWindows(hwndClient);
4050 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
4051 if (!WinQueryWindowUShort(hwndChild, QWS_ID))
4052 continue;
4053 WinSetWindowPos(hwndChild, HWND_TOP, 0, 0, 0, 0, cmd);
4054 }
4055}
4056
4057//=== ChildFrameButtonProc: subclass handler for WALKBUTTON and QUICKBUTTON windows ===
4058
4059static MRESULT EXPENTRY ChildFrameButtonProc(HWND hwnd,
4060 ULONG msg,
4061 MPARAM mp1, MPARAM mp2)
4062{
4063 USHORT id;
4064 static BOOL emphasized = FALSE;
4065
4066 switch (msg) {
4067 case WM_BUTTON1CLICK:
4068 case WM_CHORD:
4069 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
4070 break;
4071
4072 case WM_MOUSEMOVE:
4073 if (fOtherHelp) {
4074 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
4075 && !WinQueryCapture(HWND_DESKTOP)) {
4076 id = WinQueryWindowUShort(hwnd, QWS_ID);
4077 switch (id) {
4078 case IDM_OPENWALK:
4079 MakeBubble(hwnd, FALSE, GetPString(IDS_WALKBUTTONHELP));
4080 break;
4081 case IDM_USERLIST:
4082 MakeBubble(hwnd, FALSE, GetPString(IDS_QUICKBUTTONHELP));
4083 break;
4084 }
4085 }
4086 }
4087 break;
4088
4089 case WM_BUTTON3CLICK:
4090 case WM_BUTTON2CLICK:
4091 {
4092 USHORT cmd = 0;
4093
4094 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
4095 id = WinQueryWindowUShort(hwnd, QWS_ID);
4096 switch (id) {
4097 case IDM_OPENWALK:
4098 switch (msg) {
4099 case WM_BUTTON2CLICK:
4100 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
4101 (KC_ALT | KC_SHIFT | KC_CTRL))
4102 cmd = IDM_GREP;
4103 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
4104 CascadeChildren(hwndMain);
4105
4106#ifdef NEVER
4107 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
4108 cmd = IDM_SYSINFO;
4109#endif
4110
4111 else if (shiftstate & KC_SHIFT)
4112 cmd = IDM_WINDOWDLG;
4113 else if (shiftstate & KC_CTRL)
4114 cmd = IDM_SEEALL;
4115 else if (shiftstate & KC_ALT)
4116 TileChildren(hwndMain, TRUE);
4117 else
4118 cmd = IDM_WALKDIR;
4119 break;
4120 case WM_BUTTON3CLICK:
4121 TileChildren(hwndMain, TRUE);
4122 break;
4123 }
4124 break;
4125 case IDM_USERLIST:
4126 switch (msg) {
4127 case WM_BUTTON2CLICK:
4128 if ((shiftstate & (KC_ALT | KC_SHIFT | KC_CTRL)) ==
4129 (KC_ALT | KC_SHIFT | KC_CTRL))
4130 cmd = IDM_COLORPALETTE;
4131 else if ((shiftstate & (KC_ALT | KC_CTRL)) == (KC_ALT | KC_CTRL))
4132 cmd = IDM_HIDEMENU;
4133 else if ((shiftstate & (KC_ALT | KC_SHIFT)) == (KC_ALT | KC_SHIFT))
4134 cmd = IDM_NOTEBOOK;
4135 else if (shiftstate & KC_SHIFT)
4136 cmd = IDM_TOOLTITLES;
4137 else if (shiftstate & KC_CTRL)
4138 cmd = IDM_TEXTTOOLS;
4139 else if (shiftstate & KC_ALT)
4140 cmd = IDM_FONTPALETTE;
4141 else
4142 cmd = IDM_TOOLBAR;
4143 break;
4144 case WM_BUTTON3CLICK:
4145 cmd = IDM_DRIVEBAR;
4146 break;
4147 }
4148 break;
4149 } // switch id
4150
4151 if (cmd) {
4152 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_CLIENT),
4153 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
4154 }
4155 }
4156 break;
4157
4158 case DM_DRAGOVER:
4159 id = WinQueryWindowUShort(hwnd, QWS_ID);
4160 if (id == IDM_OPENWALK) {
4161 if (!emphasized) {
4162 emphasized = TRUE;
4163 DrawTargetEmphasis(hwnd, emphasized);
4164 }
4165 if (AcceptOneDrop(hwnd, mp1, mp2))
4166 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
4167 }
4168 return MRFROM2SHORT(DOR_NEVERDROP, 0);
4169
4170 case DM_DRAGLEAVE:
4171 if (emphasized) {
4172 emphasized = FALSE;
4173 DrawTargetEmphasis(hwnd, emphasized);
4174 }
4175 break;
4176
4177 case DM_DROPHELP:
4178 DropHelp(mp1, mp2, hwnd, GetPString(IDS_OPENDROPHELP));
4179 return 0;
4180
4181 case DM_DROP:
4182 {
4183 char szFrom[CCHMAXPATH + 2];
4184
4185 if (emphasized) {
4186 emphasized = FALSE;
4187 DrawTargetEmphasis(hwnd, emphasized);
4188 }
4189 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
4190 if (MakeValidDir(szFrom) && !FindDirCnrByName(szFrom, TRUE)) {
4191 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, szFrom);
4192 }
4193 }
4194 }
4195 return 0;
4196
4197 case WM_CLOSE:
4198 WinDestroyWindow(hwnd);
4199 return 0;
4200 }
4201 return PFNWPButton(hwnd, msg, mp1, mp2);
4202}
4203
4204static MRESULT EXPENTRY MainFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
4205 MPARAM mp2)
4206{
4207 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
4208 static ULONG aheight = 0L;
4209
4210 switch (msg) {
4211 case WM_ADJUSTWINDOWPOS:
4212 {
4213 SWP *pswp;
4214
4215 pswp = (SWP *) mp1;
4216 if (fDataMin && !fAmClosing) {
4217 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE)) {
4218
4219 SWP swp;
4220
4221 WinQueryWindowPos(hwnd, &swp);
4222 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(swp.fl), MPVOID);
4223 HideNote();
4224 }
4225 else if (pswp->fl & (SWP_SHOW | SWP_RESTORE)) {
4226 if (DataHwnd)
4227 PostMsg(DataHwnd, WM_CLOSE, MPVOID, MPVOID);
4228 }
4229 }
4230 if (!fAmClosing) {
4231 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE))
4232 HideNote();
4233 }
4234 }
4235 break;
4236
4237 case UM_FOCUSME:
4238 CreateDataBar(HWND_DESKTOP, (ULONG) mp1);
4239 return 0;
4240
4241 case WM_BUTTON1UP:
4242 case WM_BUTTON2UP:
4243 case WM_BUTTON3UP:
4244 case WM_MOUSEMOVE:
4245 case WM_CHORD:
4246 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
4247 break;
4248
4249 case WM_CHAR:
4250 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
4251 break;
4252
4253 case WM_CONTROL:
4254 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL, mp1,
4255 mp2);
4256
4257 case WM_COMMAND:
4258 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
4259
4260 case WM_CALCFRAMERECT:
4261 {
4262 MRESULT mr;
4263 PRECTL prectl;
4264 LONG sheight = 20, bheight = 20;
4265
4266 mr = oldproc(hwnd, msg, mp1, mp2);
4267
4268 /**
4269 * Calculate the position of the client rectangle.
4270 * Otherwise, we'll see a lot of redraw when we move the
4271 * client during WM_FORMATFRAME.
4272 */
4273
4274 if (mr && mp2) {
4275 prectl = (PRECTL) mp1;
4276 if (prectl->yBottom != prectl->yTop) {
4277 {
4278 HPS hps;
4279 POINTL aptl[TXTBOX_COUNT];
4280
4281 hps = WinGetPS(hwndStatus);
4282 if (hps) {
4283 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4284 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4285 WinReleasePS(hps);
4286 }
4287 }
4288 prectl->yBottom += (sheight + 4);
4289 prectl->yTop -= (sheight + 4);
4290 if (fMoreButtons) {
4291
4292 HPS hps;
4293 POINTL aptl[TXTBOX_COUNT];
4294
4295 hps = WinGetPS(hwndName);
4296 if (hps) {
4297 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4298 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4299 WinReleasePS(hps);
4300 }
4301 prectl->yBottom += (bheight + 4);
4302 prectl->yTop -= (bheight + 4);
4303 }
4304 if (fToolbar) {
4305 if (!fTextTools)
4306 prectl->yTop -= ((fToolTitles) ? 50 : 40);
4307 else
4308 prectl->yTop -= 32;
4309 }
4310 if (fDrivebar) {
4311 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES),
4312 ((prectl->xRight -
4313 (WinQuerySysValue(HWND_DESKTOP,
4314 SV_CYSIZEBORDER) * 2)) - 4));
4315 prectl->yTop -= (16 * (DriveLines * DRIVE_BUTTON_HEIGHT));
4316 }
4317 if (fUserComboBox) {
4318 if (!aheight) {
4319 SWP swpTemp;
4320 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4321 &swpTemp);
4322 aheight = swpTemp.cy;
4323 }
4324 prectl->yTop -= (aheight + 6L);
4325 }
4326 if (fAutoView) {
4327 AutoviewHeight = min(AutoviewHeight,
4328 (prectl->yTop - prectl->yBottom) - 116);
4329 AutoviewHeight = max(AutoviewHeight, 36);
4330 prectl->yBottom += (AutoviewHeight + 6);
4331 }
4332 }
4333 }
4334 return mr;
4335 }
4336
4337 case WM_FORMATFRAME:
4338 {
4339 SHORT sCount, soldCount;
4340 PSWP pswp, pswpClient, pswpNew;
4341 SWP swpClient;
4342 LONG theight = 48L, dheight = DRIVE_BUTTON_HEIGHT, width, sheight = 20, bheight = 20;
4343
4344 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4345 soldCount = sCount;
4346
4347 /**
4348 * Reformat the frame to "squeeze" the client
4349 * and make room for status window sibling beneath
4350 * and toolbar above (if toolbar's on) and userlists
4351 * (if userlists are on).
4352 */
4353
4354 pswp = (PSWP) mp1;
4355 {
4356 SHORT x;
4357
4358 for (x = 0; x < soldCount; x++) {
4359 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
4360 pswpClient = pswp;
4361 break;
4362 }
4363 pswp++;
4364 }
4365 }
4366
4367 {
4368 HPS hps;
4369 POINTL aptl[TXTBOX_COUNT];
4370
4371 hps = WinGetPS(hwndStatus);
4372 if (hps) {
4373 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4374 bheight = sheight = aptl[TXTBOX_TOPLEFT].y + 6;
4375 WinReleasePS(hps);
4376 }
4377 if (fMoreButtons) {
4378 hps = WinGetPS(hwndName);
4379 if (hps) {
4380 GpiQueryTextBox(hps, 6, "$`WjgT", TXTBOX_COUNT, aptl);
4381 bheight = aptl[TXTBOX_TOPLEFT].y + 6;
4382 WinReleasePS(hps);
4383 }
4384 }
4385 }
4386 pswpNew = (PSWP) mp1 + soldCount;
4387 *pswpNew = *pswpClient;
4388 swpClient = *pswpClient;
4389 pswpNew->hwnd = hwndStatus;
4390 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4391 pswpNew->x = swpClient.x + 3;
4392 pswpNew->y = swpClient.y + 2;
4393 if (!fSplitStatus)
4394 width = swpClient.cx - (16 + (sheight * 2) + 4);
4395 else
4396 width = (swpClient.cx - (16 + (sheight * 2) + 4)) / 2;
4397 width = max(width, 10);
4398 if (fSplitStatus)
4399 pswpNew->cx = width - 6;
4400 else
4401 pswpNew->cx = width - 8;
4402 pswpNew->cy = sheight;
4403 pswpClient->y = pswpNew->y + pswpNew->cy + 3;
4404 pswpClient->cy = (swpClient.cy - pswpNew->cy) - 3;
4405 sCount++;
4406
4407 if (fSplitStatus) {
4408 pswpNew = (PSWP) mp1 + (soldCount + 1);
4409 *pswpNew = *pswpClient;
4410 pswpNew->hwnd = hwndStatus2;
4411 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4412 pswpNew->x = width + 8;
4413 pswpNew->y = swpClient.y + 2;
4414 pswpNew->cx = width - 6;
4415 pswpNew->cy = sheight;
4416 sCount++;
4417 }
4418 else {
4419 WinShowWindow(hwndStatus2, FALSE);
4420 WinSetWindowText(hwndStatus2, NullStr);
4421 }
4422
4423 if (fToolbar) {
4424 if (fTextTools)
4425 theight = 32L;
4426 else if (!fToolTitles)
4427 theight = 40L;
4428 pswpNew = (PSWP) mp1 + (soldCount + 1 + (fSplitStatus != FALSE));
4429 *pswpNew = *pswpClient;
4430 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_TOOLS);
4431 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4432 pswpNew->x = swpClient.x + 2;
4433 pswpNew->y = (swpClient.y + swpClient.cy) - (theight - 2);
4434 pswpNew->cx = swpClient.cx - 4;
4435 pswpNew->cy = theight - 4;
4436 pswpClient->cy -= theight;
4437 sCount++;
4438 }
4439 else
4440 WinShowWindow(WinWindowFromID(hwnd, MAIN_TOOLS), FALSE);
4441
4442 if (fDrivebar) {
4443 ResizeDrives(WinWindowFromID(hwnd, MAIN_DRIVES), pswpClient->cx - 4);
4444 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4445 (fSplitStatus != FALSE) +
4446 (fToolbar != FALSE));
4447 *pswpNew = *pswpClient;
4448 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_DRIVES);
4449 pswpNew->hwndInsertBehind = HWND_BOTTOM;
4450 pswpNew->x = swpClient.x + 2;
4451 dheight += ((dheight) * DriveLines);
4452 pswpNew->y = (swpClient.y + swpClient.cy) - (dheight);
4453 if (fToolbar)
4454 pswpNew->y -= theight;
4455 pswpNew->cx = swpClient.cx - 4;
4456 pswpNew->cy = dheight;
4457 pswpClient->cy -= dheight;
4458 sCount++;
4459 }
4460 else
4461 WinShowWindow(WinWindowFromID(hwnd, MAIN_DRIVES), FALSE);
4462
4463 if (fAutoView) {
4464 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4465 (fToolbar != FALSE) +
4466 (fDrivebar != FALSE) +
4467 (fSplitStatus != FALSE));
4468 *pswpNew = *pswpClient;
4469 pswpNew->hwnd = (fComments) ? hwndAutoMLE : hwndAutoview;
4470 pswpNew->x = pswpClient->x + 3;
4471 pswpNew->y = pswpClient->y + 3;
4472 if (fMoreButtons)
4473 pswpNew->y += (bheight + 4);
4474 pswpNew->cx = pswpClient->cx - 6;
4475 AutoviewHeight = min(AutoviewHeight, pswpClient->cy - 116);
4476 AutoviewHeight = max(AutoviewHeight, 40);
4477 pswpNew->cy = AutoviewHeight;
4478 pswpClient->y += (AutoviewHeight + 6);
4479 pswpClient->cy -= (AutoviewHeight + 6);
4480 sCount++;
4481 WinShowWindow((fComments) ? hwndAutoview : hwndAutoMLE, FALSE);
4482 }
4483 else {
4484 WinShowWindow(hwndAutoview, FALSE);
4485 WinShowWindow(hwndAutoMLE, FALSE);
4486 }
4487
4488 pswpNew = (PSWP) mp1 + (soldCount + 1 +
4489 (fToolbar != FALSE) +
4490 (fDrivebar != FALSE) +
4491 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4492 *pswpNew = *pswpClient;
4493 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_OPENWALK);
4494 pswpNew->x = swpClient.cx - ((sheight * 2) + 4);
4495 pswpNew->y = swpClient.y;
4496 pswpNew->cx = sheight + 4;
4497 pswpNew->cy = sheight + 4;
4498 sCount++;
4499 pswpNew = (PSWP) mp1 + (soldCount + 2 +
4500 (fToolbar != FALSE) +
4501 (fDrivebar != FALSE) +
4502 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4503 *pswpNew = *pswpClient;
4504 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_USERLIST);
4505 pswpNew->x = swpClient.cx - (sheight + 2);
4506 pswpNew->y = swpClient.y;
4507 pswpNew->cx = sheight + 4;
4508 pswpNew->cy = sheight + 4;
4509 sCount++;
4510 pswpNew = (PSWP) mp1 + (soldCount + 3 +
4511 (fToolbar != FALSE) +
4512 (fDrivebar != FALSE) +
4513 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4514 *pswpNew = *pswpClient;
4515 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LED);
4516 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4517 pswpNew->y = swpClient.y;
4518 pswpNew->cx = 12;
4519 pswpNew->cy = 12;
4520 sCount++;
4521 pswpNew = (PSWP) mp1 + (soldCount + 4 +
4522 (fToolbar != FALSE) +
4523 (fDrivebar != FALSE) +
4524 (fSplitStatus != FALSE) + (fAutoView != FALSE));
4525 *pswpNew = *pswpClient;
4526 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_LEDHDR);
4527 pswpNew->x = swpClient.cx - ((sheight * 2) + 16);
4528 pswpNew->y = swpClient.y + 12;
4529 pswpNew->cx = 12;
4530 pswpNew->cy = sheight - 8;
4531 sCount++;
4532 if (fUserComboBox) {
4533 if (!aheight) {
4534 SWP swpTemp;
4535 WinQueryWindowPos(WinWindowFromID(hwndDrivelist, CBID_EDIT),
4536 &swpTemp);
4537 aheight = swpTemp.cy;
4538 }
4539 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4540 (fToolbar != FALSE) +
4541 (fSplitStatus != FALSE) +
4542 (fDrivebar != FALSE) + (fAutoView != FALSE));
4543 *pswpNew = *pswpClient;
4544 pswpNew->hwnd = hwndDrivelist;
4545 pswpNew->x = swpClient.x;
4546 pswpNew->cx = 48;
4547 pswpClient->cy -= (aheight + 6L);
4548 pswpNew->y = pswpClient->y;
4549 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4550 sCount++;
4551 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4552 (fToolbar != FALSE) +
4553 (fDrivebar != FALSE) +
4554 (fSplitStatus != FALSE) +
4555 (fAutoView != FALSE));
4556 *pswpNew = *pswpClient;
4557 pswpNew->hwnd = hwndStatelist;
4558 pswpNew->x = swpClient.x + 48;
4559 pswpNew->cx = (swpClient.cx - 48) / 7;
4560 pswpNew->y = pswpClient->y;
4561 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4562 sCount++;
4563 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4564 (fToolbar != FALSE) +
4565 (fDrivebar != FALSE) +
4566 (fSplitStatus != FALSE) +
4567 (fAutoView != FALSE));
4568 *pswpNew = *pswpClient;
4569 pswpNew->hwnd = hwndCmdlist;
4570 pswpNew->x = swpClient.x + 48 + ((swpClient.cx - 48) / 7);
4571 pswpNew->cx = (swpClient.cx - 48) / 5 +
4572 ((swpClient.cx - 48) / 5) - ((swpClient.cx - 48) / 7);
4573 pswpNew->y = pswpClient->y;
4574 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4575 sCount++;
4576 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4577 (fToolbar != FALSE) +
4578 (fDrivebar != FALSE) +
4579 (fSplitStatus != FALSE) +
4580 (fAutoView != FALSE));
4581 *pswpNew = *pswpClient;
4582 pswpNew->hwnd = hwndUserlist;
4583 pswpNew->x = swpClient.x + 48 + (((swpClient.cx - 48) / 5) * 2);
4584 pswpNew->cx = ((swpClient.x + swpClient.cx) - pswpNew->x) -
4585 ((fToolbar) ? ((swpClient.cx - 48) / 7) : 0);
4586 pswpNew->y = pswpClient->y;
4587 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4588 sCount++;
4589 if (fToolbar) {
4590 pswpNew = (PSWP) mp1 + (soldCount + 9 +
4591 (fToolbar != FALSE) +
4592 (fDrivebar != FALSE) +
4593 (fSplitStatus != FALSE) +
4594 (fAutoView != FALSE));
4595 *pswpNew = *pswpClient;
4596 pswpNew->hwnd = hwndButtonlist;
4597 pswpNew->x = swpClient.cx - ((swpClient.cx - 48) / 7) + 4;
4598 pswpNew->cx = (swpClient.x + swpClient.cx) - pswpNew->x;
4599 pswpNew->y = pswpClient->y;
4600 pswpNew->cy = pswpClient->cy + (aheight + 5L);
4601 sCount++;
4602 }
4603 else
4604 WinShowWindow(hwndButtonlist, FALSE);
4605 }
4606 else {
4607 WinShowWindow(hwndUserlist, FALSE);
4608 WinShowWindow(hwndDrivelist, FALSE);
4609 WinShowWindow(hwndStatelist, FALSE);
4610 WinShowWindow(hwndButtonlist, FALSE);
4611 WinShowWindow(hwndCmdlist, FALSE);
4612 }
4613 {
4614 PSWP pswpTitlebar = (PSWP) 0, pswpMinbutton = (PSWP) 0;
4615 SHORT x;
4616
4617 pswpNew = (PSWP) mp1 + (soldCount + 5 +
4618 (fToolbar != FALSE) +
4619 (fDrivebar != FALSE) +
4620 (fSplitStatus != FALSE) +
4621 (fAutoView != FALSE) +
4622 ((fUserComboBox != FALSE) * 4) +
4623 (fUserComboBox != FALSE &&
4624 fToolbar != FALSE));
4625 pswp = (PSWP) mp1;
4626 for (x = 0; x < soldCount; x++) {
4627 if (!pswpTitlebar &&
4628 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_TITLEBAR)
4629 pswpTitlebar = pswp;
4630 else if (!pswpMinbutton &&
4631 WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_MINMAX)
4632 pswpMinbutton = pswp;
4633 if (pswpTitlebar && pswpMinbutton)
4634 break;
4635 pswp++;
4636 }
4637 if (pswpMinbutton && pswpTitlebar) {
4638 *pswpNew = *pswpMinbutton;
4639 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_IDEALSIZE);
4640 pswpNew->cy = pswpMinbutton->cy + 3;
4641 pswpNew->cx = min(pswpNew->cy, (pswpMinbutton->cx / 2) + 3);
4642 pswpTitlebar->cx -= (pswpNew->cx - 1);
4643 pswpNew->x = pswpTitlebar->x + (pswpTitlebar->cx);
4644 pswpNew->y = pswpMinbutton->y - 1;
4645 sCount++;
4646 }
4647 else
4648 WinShowWindow(WinWindowFromID(hwnd, IDM_IDEALSIZE), FALSE);
4649 }
4650
4651 if (fMoreButtons) {
4652
4653 LONG lastx;
4654
4655 pswpNew = (PSWP) mp1 + (soldCount + 6 +
4656 (fToolbar != FALSE) +
4657 (fDrivebar != FALSE) +
4658 (fSplitStatus != FALSE) +
4659 (fAutoView != FALSE) +
4660 ((fUserComboBox != FALSE) * 4) +
4661 (fUserComboBox != FALSE &&
4662 fToolbar != FALSE));
4663 *pswpNew = *pswpClient;
4664 pswpNew->hwnd = hwndName;
4665 pswpNew->x = swpClient.x + 3;
4666 pswpNew->y = swpClient.y + (sheight + 6);
4667 pswpNew->cx = ((swpClient.cx / 2) + (swpClient.cx / 5)) - 3;
4668 lastx = pswpNew->x + pswpNew->cx;
4669 pswpNew->cy = bheight;
4670 pswpClient->y += (bheight + 4);
4671 pswpClient->cy -= (bheight + 4);
4672 sCount++;
4673 pswpNew = (PSWP) mp1 + (soldCount + 7 +
4674 (fToolbar != FALSE) +
4675 (fDrivebar != FALSE) +
4676 (fSplitStatus != FALSE) +
4677 (fAutoView != FALSE) +
4678 ((fUserComboBox != FALSE) * 4) +
4679 (fUserComboBox != FALSE &&
4680 fToolbar != FALSE));
4681 *pswpNew = *pswpClient;
4682 pswpNew->hwnd = hwndDate;
4683 pswpNew->x = lastx + 3;
4684 pswpNew->y = swpClient.y + (sheight + 6);
4685 pswpNew->cx = (swpClient.cx / 6) + (swpClient.cx / 16) - 3;
4686 lastx = pswpNew->x + pswpNew->cx;
4687 pswpNew->cy = bheight;
4688 sCount++;
4689 pswpNew = (PSWP) mp1 + (soldCount + 8 +
4690 (fToolbar != FALSE) +
4691 (fDrivebar != FALSE) +
4692 (fSplitStatus != FALSE) +
4693 (fAutoView != FALSE) +
4694 ((fUserComboBox != FALSE) * 4) +
4695 (fUserComboBox != FALSE &&
4696 fToolbar != FALSE));
4697 *pswpNew = *pswpClient;
4698 pswpNew->hwnd = hwndAttr;
4699 pswpNew->x = lastx + 3;
4700 pswpNew->y = swpClient.y + (sheight + 6);
4701 pswpNew->cx = (swpClient.cx - pswpNew->x) - 1;
4702 pswpNew->cy = bheight;
4703 sCount++;
4704 }
4705 else {
4706 WinShowWindow(hwndAttr, FALSE);
4707 WinShowWindow(hwndName, FALSE);
4708 WinShowWindow(hwndDate, FALSE);
4709 }
4710 return MRFROMSHORT(sCount);
4711 }
4712
4713 case WM_QUERYFRAMECTLCOUNT:
4714 {
4715 SHORT sCount;
4716
4717 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
4718
4719 sCount += 6;
4720 if (fSplitStatus)
4721 sCount++;
4722 if (fToolbar)
4723 sCount++;
4724 if (fUserComboBox) {
4725 sCount += 4;
4726 if (fToolbar)
4727 sCount++;
4728 }
4729 if (fDrivebar)
4730 sCount++;
4731 if (fAutoView)
4732 sCount++;
4733 if (fMoreButtons)
4734 sCount += 3;
4735 return MRFROMSHORT(sCount);
4736 }
4737
4738 case WM_CLOSE:
4739 WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), msg, mp1, mp2);
4740 return 0;
4741 }
4742 return oldproc(hwnd, msg, mp1, mp2);
4743}
4744
4745MRESULT EXPENTRY MainWMCommand(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
4746{
4747 SetShiftState();
4748 switch (SHORT1FROMMP(mp1)) {
4749
4750 case IDM_CONTEXTMENU:
4751 {
4752 HWND hwnd = WinQueryFocus(HWND_DESKTOP);
4753 // DbgMsg(pszSrcFile, __LINE__, "IDM_CONTEXTMENU %x", hwnd);
4754 if (hwnd != NULLHANDLE) {
4755 HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
4756 USHORT id = WinQueryWindowUShort(hwndParent, QWS_ID);
4757 switch (id) {
4758 case MAIN_SETUPLIST:
4759 case MAIN_USERLIST:
4760 case MAIN_CMDLIST:
4761 // DbgMsg(pszSrcFile, __LINE__, "WM_CONTEXTMENU");
4762 WinPostMsg(hwnd, WM_CONTEXTMENU, 0, 0);
4763 }
4764 }
4765 }
4766 break;
4767
4768 case IDM_SETTARGET:
4769 SetTargetDir(hwnd, FALSE, NULL);
4770 break;
4771
4772 case IDM_TOAUTOMLE:
4773 if (fComments && fAutoView)
4774 WinSetFocus(HWND_DESKTOP, hwndAutoMLE);
4775 break;
4776
4777 case IDM_HIDENOTEWND:
4778 HideNote();
4779 break;
4780 case IDM_SHOWNOTEWND:
4781 ShowNote();
4782 break;
4783
4784 case IDM_COMPARE:
4785 {
4786 WALK2 wa;
4787 PCNRITEM pci;
4788
4789 memset(&wa, 0, sizeof(wa));
4790 wa.size = sizeof(wa);
4791 pci =
4792 (PCNRITEM)
4793 WinSendMsg(WinWindowFromID
4794 (WinWindowFromID(hwndTree, FID_CLIENT), TREE_CNR),
4795 CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
4796 MPFROMSHORT(CRA_CURSORED));
4797 if (pci && (INT) pci != -1) {
4798 strcpy(wa.szCurrentPath1, pci->pszFileName);
4799 MakeValidDir(wa.szCurrentPath1);
4800 }
4801 else
4802 strcpy(wa.szCurrentPath1, pFM2SaveDirectory);
4803 TopWindowName(hwndMain, (HWND) 0, wa.szCurrentPath2);
4804 if (!*wa.szCurrentPath2)
4805 strcpy(wa.szCurrentPath2, wa.szCurrentPath1);
4806 MakeValidDir(wa.szCurrentPath2);
4807 if (WinDlgBox(HWND_DESKTOP,
4808 hwnd,
4809 WalkTwoCmpDlgProc,
4810 FM3ModHandle,
4811 WALK2_FRAME,
4812 MPFROMP(&wa)) &&
4813 !IsFile(wa.szCurrentPath1) && !IsFile(wa.szCurrentPath2)) {
4814 if (!*dircompare) {
4815
4816 COMPARE *cmp;
4817
4818 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
4819 if (cmp) {
4820 cmp->size = sizeof(COMPARE);
4821 strcpy(cmp->leftdir, wa.szCurrentPath1);
4822 strcpy(cmp->rightdir, wa.szCurrentPath2);
4823 cmp->listfile = wa.listfile;
4824 cmp->includesubdirs = wa.includesubdirs;
4825 cmp->hwndParent = hwnd;
4826 cmp->dcd.hwndParent = hwnd;
4827 WinDlgBox(HWND_DESKTOP,
4828 HWND_DESKTOP,
4829 CompareDlgProc, FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
4830 }
4831 }
4832 else {
4833
4834 CHAR szPath1[CCHMAXPATH];
4835 CHAR szPath2[CCHMAXPATH];
4836 runemf2(SEPARATE,
4837 HWND_DESKTOP, pszSrcFile, __LINE__,
4838 NULL, NULL,
4839 "%s %s %s",
4840 dircompare,
4841 BldQuotedFileName(szPath1, wa.szCurrentPath1),
4842 BldQuotedFileName(szPath2, wa.szCurrentPath2));
4843 }
4844 }
4845 }
4846 break;
4847
4848 case IDM_EXIT:
4849 case IDM_KILLME:
4850 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
4851 break;
4852
4853 case IDM_CLI:
4854 if (fSplitStatus &&
4855 hwndStatus2 &&
4856 !WinIsWindow(WinQueryAnchorBlock(hwnd),
4857 WinWindowFromID(hwndStatus2, COMMAND_LINE)))
4858 PostMsg(hwndStatus2, UM_CLICKED, MPVOID, MPVOID);
4859 break;
4860
4861 case IDM_ADDTOUSERLIST:
4862 case IDM_DELETEFROMUSERLIST:
4863 {
4864 CHAR temp[CCHMAXPATH], path[CCHMAXPATH];
4865
4866 *temp = 0;
4867 WinQueryWindowText(hwndUserlist, CCHMAXPATH, temp);
4868 bstrip(temp);
4869 if (*temp &&
4870 !DosQueryPathInfo(temp, FIL_QUERYFULLNAME, path, sizeof(path))) {
4871 if (SHORT1FROMMP(mp1) == IDM_ADDTOUSERLIST) {
4872 add_udir(TRUE, path);
4873 if (fUdirsChanged)
4874 save_udirs();
4875 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4876 }
4877 else {
4878 if (!remove_udir(path))
4879 Runtime_Error(pszSrcFile, __LINE__, "remove_udir");
4880 else {
4881 if (fUdirsChanged)
4882 save_udirs();
4883 WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
4884 }
4885 }
4886 }
4887 }
4888 break;
4889
4890 case IDM_SAVEDIRCNRSTATE:
4891 case IDM_DELETEDIRCNRSTATE:
4892 {
4893 CHAR szStateName[STATE_NAME_MAX_BYTES + 1], szKeyBase[STATE_NAME_MAX_BYTES + 1];
4894
4895 *szStateName = 0;
4896 WinQueryWindowText(hwndStatelist, STATE_NAME_MAX_BYTES, szStateName);
4897 bstrip(szStateName);
4898 // Complain if attempting to use reserved name
4899 if (stricmp(szStateName, GetPString(IDS_STATETEXT)) == 0 ||
4900 stricmp(szStateName, PCSZ_FM2TEMPTEXT) == 0)
4901 {
4902 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4903 GetPString(IDS_WARNINGTEXT),
4904 GetPString(IDS_STATERESERVENAMETEXT), szStateName);
4905 }
4906 // Ignore request if blank
4907 else if (*szStateName) {
4908 BOOL fAbortOperation = FALSE;
4909 if (!fNoSaveState && fSaveState && stricmp(szStateName, PCSZ_SHUTDOWNSTATE) == 0)
4910 {
4911 if (saymsg(MB_YESNO | MB_DEFBUTTON2 | MB_ICONASTERISK, hwnd,
4912 GetPString(IDS_WARNINGTEXT),
4913 GetPString(IDS_SHUTDOWNSTATE_WARNING), szStateName) == MBID_NO)
4914 fAbortOperation = TRUE;
4915 }
4916 if (!fAbortOperation) {
4917 if (SHORT1FROMMP(mp1) == IDM_SAVEDIRCNRSTATE) {
4918 // Save
4919 INT nSaved = SaveDirCnrState(hwnd, szStateName);
4920 if (nSaved >= 0) {
4921 INT ret = add_setup(szStateName);
4922 if (ret == 0) {
4923 WinSendMsg(hwndStatelist, LM_INSERTITEM,
4924 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(szStateName));
4925 save_setups();
4926 }
4927 else if (ret != 1) {
4928 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4929 GetPString(IDS_WARNINGTEXT),
4930 GetPString(IDS_STATEADDFAILEDTEXT), szStateName); // 15 Apr 07 SHL failed
4931 WinSetWindowText(hwndStatelist, (CHAR *) GetPString(IDS_STATETEXT));
4932 }
4933 }
4934 else {
4935 saymsg(MB_ENTER | MB_ICONASTERISK,
4936 hwnd,
4937 GetPString(IDS_WARNINGTEXT),
4938 GetPString(IDS_STATEDATASAVEFAILED));
4939 WinSetWindowText(hwndStatelist, (CHAR *) GetPString(IDS_STATETEXT));
4940 }
4941 }
4942 else {
4943 // Delete
4944 ULONG numsaves = 0, size, x;
4945 CHAR szKey[STATE_NAME_MAX_BYTES + 80];
4946
4947 INT ret = remove_setup(szStateName);
4948 if (ret == 1)
4949 save_setups();
4950 sprintf(szKey, "%s.NumDirsLastTime", szStateName);
4951 size = sizeof(ULONG);
4952 if (!PrfQueryProfileData(fmprof, FM3Str, szKey, (PVOID) &numsaves, &size)) {
4953 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
4954 GetPString(IDS_WARNINGTEXT),
4955 GetPString(IDS_DOESNTEXISTTEXT), szStateName);
4956 }
4957 else if (!size)
4958 Runtime_Error(pszSrcFile, __LINE__, NULL);
4959 else {
4960 PrfWriteProfileData(fmprof, FM3Str, szKey, NULL, 0L);
4961 for (x = 0; x < numsaves; x++) {
4962 sprintf(szKeyBase, "%s.DirCnr.%lu", szStateName, x);
4963 RemoveCnrSwitches(szKeyBase, szStateName);
4964 size = 0;
4965 sprintf(szKey, "%sVersion", szStateName);
4966 if (PrfQueryProfileSize(fmprof, FM3Str, szKey, &size) && size)
4967 RemoveOldCnrSwitches(szStateName, x);
4968 }
4969 }
4970 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
4971 }
4972 }
4973 }
4974 }
4975 break;
4976
4977 case IDM_IDEALSIZE:
4978 {
4979 SWP swp, swpD;
4980 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
4981 ULONG bsz = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
4982
4983 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4984 if (swp.fl & SWP_MAXIMIZE) {
4985 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_SYSCOMMAND,
4986 MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
4987 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
4988 }
4989 WinGetMaxPosition(WinQueryWindow(hwnd, QW_PARENT), &swpD);
4990 swpD.x += bsz;
4991 swpD.cx -= (bsz * 2);
4992 swpD.y += icz;
4993 swpD.cy -= (icz + bsz);
4994 if (swp.x == swpD.x && swp.y == swpD.y &&
4995 swp.cx == swpD.cx && swp.cy == swpD.cy &&
4996 // fixme to be #defined someday
4997 WinQueryWindowUShort(hwnd, QWL_USER + 10) &&
4998 WinQueryWindowUShort(hwnd, QWL_USER + 14)) {
4999 swpD.x = WinQueryWindowUShort(hwnd, QWL_USER + 8);
5000 swpD.cx = WinQueryWindowUShort(hwnd, QWL_USER + 10);
5001 swpD.y = WinQueryWindowUShort(hwnd, QWL_USER + 12);
5002 swpD.cy = WinQueryWindowUShort(hwnd, QWL_USER + 14);
5003 }
5004 else {
5005 WinSetWindowUShort(hwnd, QWL_USER + 8, (USHORT) swp.x);
5006 WinSetWindowUShort(hwnd, QWL_USER + 10, (USHORT) swp.cx);
5007 WinSetWindowUShort(hwnd, QWL_USER + 12, (USHORT) swp.y);
5008 WinSetWindowUShort(hwnd, QWL_USER + 14, (USHORT) swp.cy);
5009 }
5010 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP,
5011 swpD.x, swpD.y, swpD.cx, swpD.cy, SWP_MOVE | SWP_SIZE);
5012 }
5013 break;
5014
5015 case IDM_BLINK:
5016 {
5017 BOOL changed = FALSE;
5018
5019 if (fDataMin) {
5020 fDataMin = FALSE;
5021 changed = TRUE;
5022 }
5023 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
5024 SWP_MINIMIZE);
5025 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
5026 SWP_RESTORE | SWP_ZORDER);
5027 if (changed)
5028 fDataMin = TRUE;
5029 break;
5030 }
5031
5032 case DID_CANCEL:
5033 {
5034 HWND hwndTop = TopWindow(hwndMain, (HWND) 0);
5035
5036 if (hwndTop)
5037 WinSetFocus(HWND_DESKTOP, hwndTop);
5038 }
5039 break;
5040
5041 case IDM_NOTEBOOK:
5042 case IDM_DIRCNRSETTINGS:
5043 case IDM_DIRVIEWSETTINGS:
5044 case IDM_DIRSORTSETTINGS:
5045 case IDM_COLLECTORVIEWSETTINGS:
5046 case IDM_COLLECTORSORTSETTINGS:
5047 case IDM_ARCHIVERSETTINGS:
5048 case IDM_TREECNRVIEWSETTINGS:
5049 case IDM_TREECNRSORTSETTINGS:
5050 case IDM_VIEWERSETTINGS:
5051 case IDM_VIEWERSETTINGS2:
5052 case IDM_COMPARESETTINGS:
5053 case IDM_MONOLITHICSETTINGS:
5054 case IDM_GENERALSETTINGS:
5055 case IDM_SCANSETTINGS:
5056 case IDM_BUBBLESSETTINGS:
5057 case IDM_QUICKSETTINGS:
5058 WinDlgBox(HWND_DESKTOP,
5059 hwnd, CfgDlgProc, FM3ModHandle, CFG_FRAME, MPFROMLONG(mp1));
5060 break;
5061
5062 case IDM_VIEWHELPS:
5063 case IDM_VIEWINFS:
5064 WinDlgBox(HWND_DESKTOP,
5065 HWND_DESKTOP,
5066 ViewInfProc,
5067 FM3ModHandle,
5068 VINF_FRAME,
5069 ((SHORT1FROMMP(mp1) == IDM_VIEWHELPS) ?
5070 MPFROMP(NullStr) : MPVOID));
5071 break;
5072
5073 case IDM_OPENWALK:
5074 {
5075 char newpath[CCHMAXPATH];
5076
5077 *newpath = 0;
5078 TopWindowName(hwnd, (HWND) 0, newpath);
5079 if (WinDlgBox(HWND_DESKTOP,
5080 hwnd,
5081 WalkAllDlgProc,
5082 FM3ModHandle, WALK_FRAME, MPFROMP(newpath)) && *newpath)
5083 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, newpath);
5084 }
5085 break;
5086
5087 case IDM_WINDOWDLG:
5088 WindowList(hwnd);
5089 break;
5090
5091 case IDM_HELPMOUSE:
5092 case IDM_HELPCONTEXT:
5093 case IDM_HELPHINTS:
5094 case IDM_HELPPIX:
5095 case IDM_HELPTUTOR:
5096 case IDM_HELPUSERLIST:
5097 case IDM_HELP:
5098 case IDM_HELPCONTENTS:
5099 case IDM_HELPKEYS:
5100 case IDM_HELPGENERAL:
5101 if (hwndHelp) {
5102 if (SHORT1FROMMP(mp2) == CMDSRC_MENU) {
5103
5104 RECTL rcl;
5105 ULONG icz = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2L;
5106
5107 WinQueryWindowRect(HWND_DESKTOP, &rcl);
5108 rcl.yBottom += icz;
5109 rcl.yTop -= icz;
5110 rcl.xLeft += icz;
5111 rcl.xRight -= icz;
5112 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
5113 }
5114 else {
5115
5116 RECTL rcl;
5117
5118 WinQueryWindowRect(HWND_DESKTOP, &rcl);
5119 rcl.yBottom += 8;
5120 rcl.yTop = (rcl.yTop / 2) + (rcl.yTop / 7);
5121 rcl.xLeft = (rcl.xRight / 2) - (rcl.xRight / 7);
5122 rcl.xRight -= 8;
5123 WinSendMsg(hwndHelp, HM_SET_COVERPAGE_SIZE, MPFROMP(&rcl), MPVOID);
5124 }
5125 switch (SHORT1FROMMP(mp1)) {
5126 case IDM_HELPCONTEXT:
5127 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5128 MPFROM2SHORT(HELP_CONTEXT, 0), MPFROMSHORT(HM_RESOURCEID));
5129 break;
5130
5131 case IDM_HELPMOUSE:
5132 if (hwndHelp)
5133 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5134 MPFROM2SHORT(HELP_MOUSE, 0), MPFROMSHORT(HM_RESOURCEID));
5135 break;
5136
5137 case IDM_HELPPIX:
5138 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5139 MPFROM2SHORT(HELP_BITMAP1, 0), MPFROMSHORT(HM_RESOURCEID));
5140 break;
5141
5142 case IDM_HELPTUTOR:
5143 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5144 MPFROM2SHORT(HELP_TUTORIAL, 0),
5145 MPFROMSHORT(HM_RESOURCEID));
5146 break;
5147
5148 case IDM_HELPHINTS:
5149 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5150 MPFROM2SHORT(HELP_HINTS, 0), MPFROMSHORT(HM_RESOURCEID));
5151 break;
5152
5153 case IDM_HELPGENERAL:
5154 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5155 MPFROM2SHORT(HELP_MAIN, 0), MPFROMSHORT(HM_RESOURCEID));
5156 break;
5157 case IDM_HELPKEYS:
5158 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5159 MPFROM2SHORT(HELP_KEYS, 0), MPFROMSHORT(HM_RESOURCEID));
5160 break;
5161
5162 case IDM_HELP:
5163 case IDM_HELPCONTENTS:
5164 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
5165 break;
5166
5167 case IDM_HELPUSERLIST:
5168 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
5169 MPFROM2SHORT(HELP_USERLISTS, 0),
5170 MPFROMSHORT(HM_RESOURCEID));
5171 break;
5172 }
5173 }
5174 break;
5175
5176 case IDM_EDITANYARCHIVER:
5177 EditArchiverDefinition(hwnd);
5178 break;
5179
5180 case IDM_ABOUT:
5181 WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, FM3ModHandle,
5182 ABT_FRAME, MPVOID);
5183 break;
5184
5185 case IDM_FONTPALETTE:
5186 OpenObject("<WP_FNTPAL>", Default, hwnd);
5187 break;
5188
5189 case IDM_HICOLORPALETTE:
5190 case IDM_COLORPALETTE:
5191 {
5192 CHAR *palette = "<WP_CLRPAL>";
5193 ULONG version[2];
5194
5195 if (!DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
5196 (PVOID) & version, (ULONG) sizeof(version))) {
5197 if (version[0] > 20L || (version[0] == 20L && version[1] > 29L)) {
5198 if (SHORT1FROMMP(mp1) == IDM_HICOLORPALETTE)
5199 palette = "<WP_HIRESCLRPAL>";
5200 else
5201 palette = "<WP_LORESCLRPAL>";
5202 }
5203 }
5204 OpenObject(palette, Default, hwnd);
5205 }
5206 break;
5207
5208 case IDM_SYSTEMSETUP:
5209 OpenObject("<WP_CONFIG>", Default, hwnd);
5210 break;
5211
5212 case IDM_SCHEMEPALETTE:
5213 {
5214 HOBJECT hWPSObject;
5215
5216 hWPSObject = WinQueryObject("<WP_SCHPAL>");
5217 if (hWPSObject != NULLHANDLE)
5218 WinSetObjectData(hWPSObject, "SCHEMES=Winter:PM_Winter,"
5219 "Spring:PM_Spring,Summer:PM_Summer,"
5220 "System:PM_System,Windows:PM_Windows;"
5221 "OPEN=DEFAULT");
5222 }
5223 break;
5224
5225 case IDM_SYSTEMCLOCK:
5226 OpenObject("<WP_CLOCK>", Default, hwnd);
5227 break;
5228
5229#ifdef NEVER
5230 case IDM_SYSINFO:
5231 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, SysInfoDlgProc, FM3ModHandle,
5232 SYS_FRAME, NULL);
5233 break;
5234#endif
5235
5236 case IDM_INSTANT:
5237 {
5238 CHAR path[CCHMAXPATH];
5239 PCNRITEM pci = (PCNRITEM) 0;
5240
5241 if (hwndTree)
5242 pci = (PCNRITEM) WinSendMsg(hwndTree, CM_QUERYRECORDEMPHASIS,
5243 MPFROMLONG(CMA_FIRST),
5244 MPFROMSHORT(CRA_CURSORED));
5245 if (pci && (INT) pci != -1) {
5246 strcpy(path, pci->pszFileName);
5247 MakeValidDir(path);
5248 }
5249 else
5250 strcpy(path, pFM2SaveDirectory);
5251 WinDlgBox(HWND_DESKTOP, hwnd, InstantDlgProc, FM3ModHandle,
5252 BAT_FRAME, MPFROMP(path));
5253 }
5254 break;
5255
5256 case IDM_WINFULLSCREEN:
5257 case IDM_DOSCOMMANDLINE:
5258 case IDM_COMMANDLINE:
5259 {
5260 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
5261 INT type = SEPARATE | WINDOWED;
5262
5263 *path = 0;
5264 TopWindowName(hwnd, (HWND) 0, path);
5265 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
5266 env = GetCmdSpec(TRUE);
5267 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
5268 env = "WINOS2.COM";
5269 type = SEPARATE | FULLSCREEN;
5270 }
5271 runemf2(type, hwnd, pszSrcFile, __LINE__,
5272 path, NULL, "%s", env);
5273 }
5274 break;
5275
5276 case IDM_KILLPROC:
5277 WinDlgBox(HWND_DESKTOP, hwnd, KillDlgProc, FM3ModHandle,
5278 KILL_FRAME, NULL);
5279 break;
5280
5281 case IDM_AUTOVIEWCOMMENTS:
5282 case IDM_AUTOVIEWFILE:
5283 if (SHORT1FROMMP(mp1) == IDM_AUTOVIEWFILE)
5284 fComments = FALSE;
5285 else
5286 fComments = TRUE;
5287 PrfWriteProfileData(fmprof, FM3Str, "Comments", &fComments, sizeof(BOOL));
5288 WinSetWindowText((fComments) ? hwndAutoview : hwndAutoMLE, NullStr);
5289 goto AutoChange;
5290
5291 case IDM_AUTOVIEW:
5292 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5293 &fAutoView, TRUE, "AutoView");
5294 AutoChange:
5295 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5296 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5297 if (fAutoView) {
5298
5299 CHAR s[CCHMAXPATH];
5300 HWND hwndDir;
5301 PCNRITEM pci;
5302
5303 hwndDir = TopWindowName(hwnd, (HWND) 0, s);
5304 if (hwndDir) {
5305 hwndDir = WinWindowFromID(hwndDir, FID_CLIENT);
5306 if (hwndDir) {
5307 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
5308 if (hwndDir) {
5309 pci = (PCNRITEM) WinSendMsg(hwndDir, CM_QUERYRECORDEMPHASIS,
5310 MPFROMLONG(CMA_FIRST),
5311 MPFROMSHORT(CRA_CURSORED));
5312 if (pci && (INT) pci != -1 &&
5313 (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW)))
5314 WinSendMsg(hwnd,
5315 UM_LOADFILE,
5316 MPFROMP(pci->pszFileName),
5317 (SHORT1FROMMP(mp1) == IDM_AUTOVIEW) ?
5318 MPVOID : MPFROMLONG(1));
5319 }
5320 }
5321 }
5322 }
5323 break;
5324
5325 case IDM_TEXTTOOLS:
5326 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5327 &fTextTools, TRUE, "TextTools");
5328 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
5329 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5330 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5331 break;
5332
5333 case IDM_TOOLTITLES:
5334 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5335 &fToolTitles, TRUE, "ToolTitles");
5336 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
5337 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5338 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5339 break;
5340
5341 case IDM_HIDEMENU:
5342 {
5343 HWND hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
5344 MenuInvisible = MenuInvisible ? FALSE : TRUE;
5345 if (MenuInvisible) {
5346 WinSetParent(hwndMenu, HWND_OBJECT, FALSE);
5347 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5348 FID_SYSMENU), IDM_HIDEMENU,
5349 GetPString(IDS_UNHIDEMENUTEXT));
5350 }
5351 else {
5352 WinSetParent(hwndMenu, WinQueryWindow(hwnd, QW_PARENT), FALSE);
5353 WinSetMenuItemText(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5354 FID_SYSMENU), IDM_HIDEMENU,
5355 GetPString(IDS_HIDEMENUTEXT));
5356 }
5357 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_UPDATEFRAME,
5358 MPFROMLONG(FCF_MENU), MPVOID);
5359 PrfWriteProfileData(fmprof, FM3Str, "MenuInvisible",
5360 &MenuInvisible, sizeof(BOOL));
5361 }
5362 break;
5363
5364 case IDM_SEEALL:
5365 case IDM_GREP:
5366 case IDM_COLLECTOR:
5367 {
5368 HWND hwndC;
5369 SWP swp;
5370 BOOL already = FALSE;
5371
5372 if (Collector)
5373 already = TRUE;
5374 if (!already && !fAutoTile && !fExternalCollector)
5375 GetNextWindowPos(hwnd, &swp, NULL, NULL);
5376 hwndC = StartCollector(fExternalCollector ? HWND_DESKTOP : hwnd, 4);
5377 if (hwndC) {
5378 if (!already && !fAutoTile && !fExternalCollector)
5379 WinSetWindowPos(hwndC, HWND_TOP,
5380 swp.x, swp.y, swp.cx, swp.cy,
5381 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
5382 else if (fAutoTile && !already)
5383 TileChildren(hwnd, TRUE);
5384 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE |
5385 SWP_ACTIVATE);
5386 if (SHORT1FROMMP(mp1) == IDM_GREP)
5387 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5388 MPFROM2SHORT(IDM_GREP, 0), MPVOID);
5389 if (SHORT1FROMMP(mp1) == IDM_SEEALL)
5390 PostMsg(WinWindowFromID(hwndC, FID_CLIENT), WM_COMMAND,
5391 MPFROM2SHORT(IDM_SEEALL, 0), MPVOID);
5392 }
5393 }
5394 break;
5395
5396 case IDM_DATABAR:
5397 CreateDataBar(HWND_DESKTOP, 0);
5398 break;
5399
5400 case IDM_TOOLLEFT:
5401 case IDM_TOOLRIGHT:
5402 {
5403 TOOL *tool;
5404
5405 if (!toolhead || !toolhead->next) {
5406 firsttool = (toolhead) ? toolhead->id : 0;
5407 break;
5408 }
5409 tool = find_tool(firsttool);
5410 if (!tool)
5411 tool = toolhead;
5412 if (SHORT1FROMMP(mp1) == IDM_TOOLRIGHT) {
5413 tool = prev_tool(tool, TRUE);
5414 firsttool = tool->id;
5415 }
5416 else {
5417 tool = next_tool(tool, TRUE);
5418 firsttool = tool->id;
5419 }
5420 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5421 MAIN_TOOLS));
5422 }
5423 break;
5424
5425 case IDM_CREATETOOL:
5426 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
5427 break;
5428
5429 case IDM_TOOLBAR:
5430 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5431 IDM_TOOLSUBMENU, &fToolbar, TRUE, "Toolbar");
5432 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
5433 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5434 MAIN_TOOLS), fToolbar);
5435 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
5436 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5437 if (fDrivebar)
5438 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5439 MAIN_DRIVES), NULL, TRUE);
5440 break;
5441
5442 case IDM_DRIVEBAR:
5443 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5444 IDM_DRIVEBAR, &fDrivebar, TRUE, "Drivebar");
5445 WinShowWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
5446 MAIN_DRIVES), fDrivebar);
5447 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5448 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5449 PostMsg(hwnd, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
5450 break;
5451
5452 case IDM_USERLIST:
5453 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5454 SHORT1FROMMP(mp1), &fUserComboBox, TRUE, "UserComboBox");
5455 WinShowWindow(hwndUserlist, fUserComboBox);
5456 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5457 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5458 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
5459 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
5460 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5461 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
5462 break;
5463
5464 case IDM_MOREBUTTONS:
5465 WinSetWindowText(hwndName, NullStr);
5466 WinSetWindowText(hwndDate, NullStr);
5467 WinSetWindowText(hwndAttr, NullStr);
5468 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5469 SHORT1FROMMP(mp1), &fMoreButtons, TRUE, "MoreButtons");
5470 if (fMoreButtons) {
5471
5472 HWND hwndTemp;
5473
5474 hwndTemp = TopWindow(hwnd, (HWND) 0);
5475
5476 if (hwndTemp) {
5477 WinSetFocus(HWND_DESKTOP, hwnd);
5478 WinSetFocus(HWND_DESKTOP, hwndTemp);
5479 }
5480 }
5481 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
5482 WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
5483 break;
5484
5485 // 2014-05-17 SHL
5486 case IDM_CONFIRMDELETE:
5487 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5488 IDM_CONFIRMDELETE,
5489 &fConfirmDelete,
5490 TRUE,
5491 "ConfirmDelete");
5492 break;
5493
5494 case IDM_TOGGLEDRAGDIALOG:
5495 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5496 IDM_TOGGLEDRAGDIALOG,
5497 &fDragndropDlg,
5498 TRUE,
5499 "Drag&DropDlg");
5500 break;
5501
5502 case IDM_SYNCUPDATES:
5503 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5504 IDM_SYNCUPDATES,
5505 &fSyncUpdates,
5506 TRUE,
5507 "SyncUpdates");
5508 break;
5509
5510 case IDM_FREETREE:
5511 if (fFreeTree) {
5512 SWP swp, swpT;
5513
5514 WinQueryWindowPos(hwndTree, &swpT);
5515 WinQueryWindowPos(hwnd, &swp);
5516 WinSetWindowPos(hwndTree, HWND_TOP, 0, swp.cy - swpT.cy, 0, 0,
5517 SWP_MOVE);
5518 }
5519 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER), SHORT1FROMMP(mp1),
5520 &fFreeTree, TRUE, "FreeTree");
5521 if (fAutoTile)
5522 TileChildren(hwnd, TRUE);
5523 break;
5524
5525 case IDM_AUTOTILE:
5526 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5527 SHORT1FROMMP(mp1), &fAutoTile, TRUE, "AutoTile");
5528 if (fAutoTile)
5529 TileChildren(hwnd, TRUE);
5530 break;
5531
5532 case IDM_TILEBACKWARDS:
5533 SetMenuCheck(WinQueryWindowULong(hwnd, QWL_USER),
5534 SHORT1FROMMP(mp1), &fTileBackwards, TRUE, "TileBackwards");
5535 if (fAutoTile)
5536 TileChildren(hwnd, TRUE);
5537 break;
5538
5539 case IDM_NEXTWINDOW:
5540 case IDM_PREVWINDOW:
5541 NextChild(hwnd, (SHORT1FROMMP(mp1) == IDM_PREVWINDOW));
5542 break;
5543
5544 case IDM_CASCADE:
5545 CascadeChildren(hwnd);
5546 break;
5547
5548 case IDM_TILE:
5549 TileChildren(hwnd, TRUE);
5550 break;
5551
5552 case IDM_RESTORE:
5553 MinResChildren(hwnd, SWP_RESTORE);
5554 break;
5555
5556 case IDM_MINIMIZE:
5557 MinResChildren(hwnd, SWP_MINIMIZE);
5558 break;
5559
5560 case IDM_ARRANGEICONS:
5561 ArrangeIcons(hwnd);
5562 break;
5563
5564 case IDM_INIVIEWER:
5565 StartIniEditor(hwnd, NULL, 4);
5566 break;
5567
5568 case IDM_INIVIEWERSYS:
5569 StartIniEditor(hwnd, "SYS", 4);
5570 break;
5571
5572 case IDM_INIVIEWERFM2:
5573 StartIniEditor(hwnd, profile, 4);
5574 break;
5575
5576 case IDM_EDITASSOC:
5577 EditAssociations(hwnd);
5578 break;
5579
5580 case IDM_EDITCOMMANDS:
5581 EditCommands(hwnd);
5582 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
5583 break;
5584
5585 default:
5586 if (!SwitchCommand((HWND) WinQueryWindowULong(hwnd, QWL_USER),
5587 SHORT1FROMMP(mp1))) {
5588 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
5589 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
5590
5591 INT x;
5592 HWND hwndCnr;
5593
5594 if (!cmdloaded)
5595 load_commands();
5596 hwndCnr = TopWindow(hwnd, (HWND) 0);
5597 hwndCnr = (HWND) WinSendMsg(WinWindowFromID(hwndCnr, FID_CLIENT),
5598 UM_CONTAINERHWND, MPVOID, MPVOID);
5599 if (!hwndCnr) {
5600 Runtime_Error(pszSrcFile, __LINE__, NULL);
5601 break;
5602 }
5603 x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
5604 if (x >= 0) {
5605 //x++;
5606 RunCommand(hwndCnr, x);
5607 if (fUnHilite) {
5608
5609 PCNRITEM pci;
5610 DIRCNRDATA *dcd = NULL;
5611
5612 // 12 May 07 SHL fixme to understand? backwards maybe? looking for DIR_CNR?
5613 if (WinQueryWindowUShort(hwndCnr, QWS_ID) != TREE_CNR)
5614 dcd = INSTDATA(hwndCnr);
5615 pci = (PCNRITEM) WinSendMsg(hwndCnr,
5616 CM_QUERYRECORDEMPHASIS,
5617 MPFROMLONG(CMA_FIRST),
5618 MPFROMSHORT(CRA_CURSORED));
5619 if (pci && (INT) pci != -1 &&
5620 (pci->rc.flRecordAttr & CRA_SELECTED))
5621 {
5622 UnHilite(hwnd,
5623 TRUE,
5624 dcd ? &dcd->lastselection : NULL,
5625 dcd ? dcd ->ulItemsToUnHilite : 0);
5626 }
5627 }
5628 }
5629 }
5630 else if (SHORT1FROMMP(mp1) >= IDM_QUICKTOOLSTART &&
5631 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART + 51) {
5632 if (!qtloaded)
5633 load_quicktools();
5634 if (quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART - 1]) {
5635 if (fToolsChanged)
5636 save_tools(NULL);
5637 if (!load_tools(quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART - 1]))
5638 load_tools(NULL);
5639 else {
5640 strcpy(lasttoolbar,
5641 quicktool[SHORT1FROMMP(mp1) - IDM_QUICKTOOLSTART - 1]);
5642 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", lasttoolbar);
5643 }
5644 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
5645 }
5646 }
5647 else {
5648
5649 HWND hwndActive;
5650
5651 hwndActive = TopWindow(hwnd, (HWND) 0);
5652 if (hwndActive)
5653 PostMsg(WinWindowFromID(hwndActive, FID_CLIENT),
5654 WM_COMMAND, mp1, mp2);
5655 }
5656 }
5657 break; // default
5658 } // switch mp1
5659 return 0;
5660}
5661
5662static MRESULT EXPENTRY MainWMOnce(HWND hwnd, ULONG msg, MPARAM mp1,
5663 MPARAM mp2)
5664{
5665 TID tid;
5666 SWP swp;
5667 PFNWP oldproc;
5668 HWND hwndTmp;
5669 HWND hwndFrame;
5670 HWND hwndSysMenu, hwndSysSubMenu, hwndMenu;
5671 USHORT idSysMenu;
5672 MENUITEM mi, mit;
5673 ULONG size;
5674 BOOL temp;
5675
5676 static BOOL needTile;
5677
5678 switch (msg) {
5679 case WM_CREATE:
5680 WinQueryWindowProcess(hwnd, &mypid, &tid);
5681 hwndMain = hwnd;
5682 WinSetWindowUShort(hwnd, QWL_USER + 8, 0);
5683 WinSetWindowUShort(hwnd, QWL_USER + 10, 0);
5684 WinSetWindowUShort(hwnd, QWL_USER + 12, 0);
5685 WinSetWindowUShort(hwnd, QWL_USER + 16, 0);
5686 if (xbeginthread(MakeMainObjWin,
5687 245760,
5688 MPVOID,
5689 pszSrcFile,
5690 __LINE__) == -1)
5691 {
5692 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
5693 return 0;
5694 }
5695 else
5696 DosSleep(32);//05 Aug 07 GKY 64
5697
5698 hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
5699
5700 // create frame children (not client children, frame children)
5701 DosSleep(1);
5702 WinQueryWindowPos(hwndFrame, &swp);
5703 oldproc = WinSubclassWindow(hwndFrame, MainFrameWndProc);
5704 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
5705 CommonCreateMainChildren(hwnd, &swp);
5706
5707 if (!WinCreateWindow(hwndFrame,
5708 (CHAR *) WC_BUTTON,
5709 "I",
5710 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
5711 ((swp.cx -
5712 WinQuerySysValue(HWND_DESKTOP,
5713 SV_CXMINMAXBUTTON)) -
5714 WinQuerySysValue(HWND_DESKTOP,
5715 SV_CXMINMAXBUTTON) / 2) -
5716 WinQuerySysValue(HWND_DESKTOP,
5717 SV_CXSIZEBORDER),
5718 (swp.cy - WinQuerySysValue(HWND_DESKTOP,
5719 SV_CYMINMAXBUTTON)) -
5720 WinQuerySysValue(HWND_DESKTOP,
5721 SV_CYSIZEBORDER),
5722 WinQuerySysValue(HWND_DESKTOP,
5723 SV_CXMINMAXBUTTON) / 2,
5724 WinQuerySysValue(HWND_DESKTOP,
5725 SV_CYMINMAXBUTTON),
5726 hwnd, HWND_TOP, IDM_IDEALSIZE, NULL, NULL)) {
5727 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5728 PCSZ_WINCREATEWINDOW);
5729 }
5730 else {
5731 WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_IDEALSIZE),
5732 IdealButtonProc);
5733 //fixme to allow user to change presparams 1-10-09 GKY
5734 SetPresParams(WinWindowFromID(hwndFrame,
5735 IDM_IDEALSIZE),
5736 NULL, NULL, NULL, FNT_10SYSTEMVIO);
5737 }
5738
5739 hwndTmp = WinCreateWindow(hwndFrame,
5740 (CHAR *) WC_BUTTON,
5741 "#1019",
5742 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5743 BS_BITMAP,
5744 swp.cx - 46,
5745 swp.y + 2,
5746 24,
5747 22, hwnd, HWND_TOP, IDM_OPENWALK, NULL, NULL);
5748 if (!hwndTmp)
5749 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5750 PCSZ_WINCREATEWINDOW);
5751
5752 hwndTmp = WinCreateWindow(hwndFrame,
5753 (CHAR *) WC_BUTTON,
5754 "#3062",
5755 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS |
5756 BS_BITMAP,
5757 swp.cx - 22,
5758 swp.y + 2,
5759 24,
5760 22, hwnd, HWND_TOP, IDM_USERLIST, NULL, NULL);
5761 if (!hwndTmp)
5762 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5763 PCSZ_WINCREATEWINDOW);
5764
5765 hwndUserlist = WinCreateWindow(hwndFrame,
5766 (CHAR *) WC_COMBOBOX,
5767 (PSZ) NULL,
5768 WS_VISIBLE | CBS_DROPDOWN |
5769 LS_HORZSCROLL,
5770 (swp.x +
5771 WinQuerySysValue(HWND_DESKTOP,
5772 SV_CXSIZEBORDER) + 48L),
5773 (swp.cy -
5774 WinQuerySysValue(HWND_DESKTOP,
5775 SV_CYSIZEBORDER)) - 60,
5776 ((swp.cx -
5777 (WinQuerySysValue(HWND_DESKTOP,
5778 SV_CXSIZEBORDER) *
5779 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5780 MAIN_USERLIST, NULL, NULL);
5781 if (!hwndUserlist)
5782 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5783 PCSZ_WINCREATEWINDOW);
5784 hwndCmdlist = WinCreateWindow(hwndFrame,
5785 (CHAR *) WC_COMBOBOX,
5786 (PSZ) NULL,
5787 WS_VISIBLE | CBS_DROPDOWN |
5788 LS_HORZSCROLL,
5789 (swp.x +
5790 WinQuerySysValue(HWND_DESKTOP,
5791 SV_CXSIZEBORDER) + 48L),
5792 (swp.cy -
5793 WinQuerySysValue(HWND_DESKTOP,
5794 SV_CYSIZEBORDER)) - 60,
5795 ((swp.cx -
5796 (WinQuerySysValue(HWND_DESKTOP,
5797 SV_CXSIZEBORDER) * 2)) -
5798 64L), 60L, hwndFrame, HWND_TOP,
5799 MAIN_CMDLIST, NULL, NULL);
5800 if (!hwndCmdlist)
5801 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5802 PCSZ_WINCREATEWINDOW);
5803 WinSetWindowText(hwndCmdlist, (CHAR *) GetPString(IDS_COMMANDSTEXT));
5804 hwndStatelist = WinCreateWindow(hwndFrame,
5805 (CHAR *) WC_COMBOBOX,
5806 (PSZ) NULL,
5807 WS_VISIBLE | CBS_DROPDOWN |
5808 LS_HORZSCROLL,
5809 (swp.x +
5810 WinQuerySysValue(HWND_DESKTOP,
5811 SV_CXSIZEBORDER) + 48L),
5812 (swp.cy -
5813 WinQuerySysValue(HWND_DESKTOP,
5814 SV_CYSIZEBORDER)) - 60,
5815 ((swp.cx -
5816 (WinQuerySysValue(HWND_DESKTOP,
5817 SV_CXSIZEBORDER) *
5818 2)) - 64L), 60L, hwndFrame, HWND_TOP,
5819 MAIN_SETUPLIST, NULL, NULL);
5820 if (!hwndStatelist)
5821 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5822 PCSZ_WINCREATEWINDOW);
5823
5824 hwndDrivelist = WinCreateWindow(hwndFrame,
5825 (CHAR *) WC_COMBOBOX,
5826 (PSZ) NULL,
5827 //WS_VISIBLE |
5828 CBS_DROPDOWN,
5829 (swp.x +
5830 WinQuerySysValue(HWND_DESKTOP,
5831 SV_CXSIZEBORDER)),
5832 (swp.cy -
5833 WinQuerySysValue(HWND_DESKTOP,
5834 SV_CYSIZEBORDER)) - 60,
5835 48L,
5836 60L,
5837 hwndFrame,
5838 HWND_TOP, MAIN_DRIVELIST, NULL, NULL);
5839 if (!hwndDrivelist)
5840 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5841 PCSZ_WINCREATEWINDOW);
5842 //fixme to allow user to change presparams 1-10-09 GKY
5843 SetPresParams(hwndDrivelist,
5844 NULL, NULL, NULL, FNT_10SYSTEMMONOTEXT);
5845 hwndButtonlist = WinCreateWindow(hwndFrame,
5846 (CHAR *) WC_COMBOBOX,
5847 (PSZ) NULL,
5848 WS_VISIBLE | CBS_DROPDOWN |
5849 LS_HORZSCROLL,
5850 (swp.cx -
5851 WinQuerySysValue(HWND_DESKTOP,
5852 SV_CXSIZEBORDER)) -
5853 164L,
5854 (swp.cy -
5855 WinQuerySysValue(HWND_DESKTOP,
5856 SV_CYSIZEBORDER)) - 60,
5857 164L, 60L, hwndFrame, HWND_TOP,
5858 MAIN_BUTTONLIST, NULL, NULL);
5859 if (!hwndButtonlist)
5860 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
5861 PCSZ_WINCREATEWINDOW);
5862 WinSendMsg(WinWindowFromID(hwndUserlist, CBID_EDIT),
5863 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
5864 WinSendMsg(WinWindowFromID(hwndStatelist, CBID_EDIT),
5865 EM_SETTEXTLIMIT, MPFROM2SHORT(STATE_NAME_MAX_BYTES, 0), MPVOID);
5866 WinSendMsg(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5867 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5868 WinSendMsg(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5869 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5870 WinSendMsg(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5871 EM_SETREADONLY, MPFROM2SHORT(TRUE, 0), MPVOID);
5872
5873 oldproc = WinSubclassWindow(WinWindowFromID(hwndUserlist, CBID_EDIT),
5874 DropDownListProc);
5875 WinSetWindowPtr(WinWindowFromID(hwndUserlist, CBID_EDIT),
5876 QWL_USER, (PVOID) oldproc);
5877 oldproc = WinSubclassWindow(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5878 DropDownListProc);
5879 WinSetWindowPtr(WinWindowFromID(hwndCmdlist, CBID_EDIT),
5880 QWL_USER, (PVOID) oldproc);
5881 oldproc = WinSubclassWindow(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5882 DropDownListProc);
5883 WinSetWindowPtr(WinWindowFromID(hwndButtonlist, CBID_EDIT),
5884 QWL_USER, (PVOID) oldproc);
5885 oldproc = WinSubclassWindow(WinWindowFromID(hwndStatelist, CBID_EDIT),
5886 DropDownListProc);
5887 WinSetWindowPtr(WinWindowFromID(hwndStatelist, CBID_EDIT),
5888 QWL_USER, (PVOID) oldproc);
5889 oldproc = WinSubclassWindow(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5890 DropDownListProc);
5891 WinSetWindowPtr(WinWindowFromID(hwndDrivelist, CBID_EDIT),
5892 QWL_USER, (PVOID) oldproc);
5893 oldproc = WinSubclassWindow(hwndUserlist, DropDownListProc);
5894 WinSetWindowPtr(hwndUserlist, QWL_USER, (PVOID) oldproc);
5895 oldproc = WinSubclassWindow(hwndCmdlist, DropDownListProc);
5896 WinSetWindowPtr(hwndCmdlist, QWL_USER, (PVOID) oldproc);
5897 oldproc = WinSubclassWindow(hwndStatelist, DropDownListProc);
5898 WinSetWindowPtr(hwndStatelist, QWL_USER, (PVOID) oldproc);
5899 oldproc = WinSubclassWindow(hwndDrivelist, DropDownListProc);
5900 WinSetWindowPtr(hwndDrivelist, QWL_USER, (PVOID) oldproc);
5901 oldproc = WinSubclassWindow(hwndButtonlist, DropDownListProc);
5902 WinSetWindowPtr(hwndButtonlist, QWL_USER, (PVOID) oldproc);
5903 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_USERLIST),
5904 ChildFrameButtonProc);
5905 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_USERLIST),
5906 QWL_USER, (PVOID) oldproc);
5907 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5908 ChildFrameButtonProc);
5909 WinSetWindowPtr(WinWindowFromID(hwndFrame, IDM_OPENWALK),
5910 QWL_USER, (PVOID) oldproc);
5911 hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
5912 WinSendMsg(hwnd, UM_ADDTOMENU, MPVOID, MPVOID);
5913 SetToggleChecks(hwndMenu);
5914 CfgMenuInit(hwndMenu, FALSE); // 14 Feb 08 SHL
5915 SetConditionalCascade(hwndMenu, IDM_COMMANDLINESUBMENU, IDM_COMMANDLINE);
5916 if (fProtectOnly) {
5917 WinEnableMenuItem(hwndMenu, IDM_DOSCOMMANDLINE, FALSE);
5918 WinEnableMenuItem(hwndMenu, IDM_WINFULLSCREEN, FALSE);
5919 }
5920 SetConditionalCascade(hwndMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
5921 SetConditionalCascade(hwndMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
5922 SetConditionalCascade(hwndMenu, IDM_TILEMENU, IDM_TILE);
5923 WinSetWindowULong(hwnd, QWL_USER, hwndMenu);
5924 memset(&mi, 0, sizeof(mi));
5925 memset(&mit, 0, sizeof(mit));
5926 hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
5927 idSysMenu = SHORT1FROMMR(WinSendMsg(hwndSysMenu,
5928 MM_ITEMIDFROMPOSITION,
5929 MPVOID, MPVOID));
5930 WinSendMsg(hwndSysMenu,
5931 MM_QUERYITEM, MPFROM2SHORT(idSysMenu, 0), MPFROMP(&mit));
5932 hwndSysSubMenu = mit.hwndSubMenu;
5933 mi.iPosition = MIT_END;
5934 mi.afStyle = MIS_SEPARATOR;
5935 mi.id = (USHORT) - 1;
5936 WinSendMsg(hwndSysSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(NULL));
5937 mi.afStyle = MIS_TEXT;
5938 mi.id = IDM_IDEALSIZE;
5939 WinSendMsg(hwndSysSubMenu,
5940 MM_INSERTITEM,
5941 MPFROMP(&mi), MPFROMP(GetPString(IDS_IDEALMENUTEXT)));
5942 mi.afStyle = MIS_TEXT;
5943 mi.id = IDM_HIDEMENU;
5944 WinSendMsg(hwndSysSubMenu,
5945 MM_INSERTITEM,
5946 MPFROMP(&mi), MPFROMP(GetPString(IDS_HIDEMENUTEXT)));
5947 SetSysMenu(hwndSysMenu);
5948
5949 size = sizeof(BOOL);
5950 if (PrfQueryProfileData(fmprof, FM3Str, "MenuInvisible", &temp, &size) &&
5951 size && temp)
5952 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HIDEMENU, 0), MPVOID);
5953 size = sizeof(BOOL);
5954 if (PrfQueryProfileData(fmprof, FM3Str, "FreeTree", &temp, &size) &&
5955 size && temp)
5956 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_FREETREE, 0), MPVOID);
5957 size = sizeof(BOOL);
5958 if (PrfQueryProfileData(fmprof, FM3Str, "AutoTile", &temp, &size) &&
5959 size && !temp)
5960 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_AUTOTILE, 0), MPVOID);
5961 size = sizeof(BOOL);
5962 if (PrfQueryProfileData(fmprof, appname, "Toolbar", &temp, &size) && size && !temp)
5963 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TOOLBAR, 0), MPVOID);
5964
5965 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR), "FM/2");
5966 FixSwitchList(hwndFrame, NULL);
5967 break; // WM_CREATE
5968
5969 case UM_SETUP:
5970 // start up some initial children
5971 WinShowWindow(WinQueryWindow(hwnd, QW_PARENT), TRUE);
5972 PostMsg(MainObjectHwnd, UM_SETUP2, mp1, mp2);
5973 return 0;
5974
5975 case UM_SETUP2:
5976 {
5977 SWP swp;
5978 ULONG size = sizeof(SWP);
5979
5980 WinQueryWindowPos(hwnd, &swp);
5981 hwndTree = StartTreeCnr(hwnd, 4);
5982 if (!hwndTree)
5983 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
5984 else {
5985 if (!fSaveState ||
5986 !PrfQueryProfileData(fmprof,
5987 FM3Str,
5988 "LastTreePos",
5989 &swp, &size) || size != sizeof(SWP)) {
5990
5991 INT ratio, height = 0;
5992
5993 if (!fNoTreeGap)
5994 height = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) * 2;
5995 size = sizeof(ratio);
5996 if (!PrfQueryProfileData(fmprof,
5997 FM3Str,
5998 "TreeWindowRatio",
5999 (PVOID) & ratio,
6000 &size) || size < sizeof(ratio))
6001 ratio = 400;
6002 WinSetWindowPos(hwndTree,
6003 HWND_TOP,
6004 0,
6005 height,
6006 (swp.cx * 100) / ratio,
6007 swp.cy - height,
6008 SWP_SHOW | SWP_SIZE | SWP_MOVE |
6009 SWP_ACTIVATE | SWP_ZORDER);
6010 }
6011 else
6012 WinSetWindowPos(hwndTree,
6013 HWND_TOP,
6014 swp.x,
6015 swp.y,
6016 swp.cx,
6017 swp.cy,
6018 swp.fl | SWP_MOVE | SWP_SIZE | SWP_SHOW |
6019 SWP_ZORDER | SWP_ACTIVATE);
6020 }
6021# if 0
6022 ResizeTools(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
6023 MAIN_TOOLS));
6024# endif
6025 }
6026 PostMsg(MainObjectHwnd, UM_SETUP3, mp1, mp2);
6027 return 0;
6028
6029 case UM_SETUP3:
6030 // start remaining child windows
6031 if (!fNoSaveState && fSaveState) {
6032 PCSZ pszStatename = PCSZ_SHUTDOWNSTATE;
6033 PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszStatename), MPFROMLONG(RESTORE_STATE_RESTORE));
6034 if (!add_setup(pszStatename))
6035 save_setups();
6036 }
6037 else {
6038 load_tools(NULL);
6039 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
6040 }
6041 PostMsg(MainObjectHwnd, UM_SETUP4, mp1, mp2);
6042 return 0;
6043
6044 case UM_SETUP4:
6045 {
6046 INT argc = (INT) mp1, x;
6047 CHAR **argv = (CHAR **) mp2;
6048
6049 for (x = 1; x < argc; x++) {
6050 if (*argv[x] == '/' || *argv[x] == ';')
6051 continue;
6052 if (IsFile(argv[x]) == 0 && !FindDirCnrByName(argv[x], FALSE)) {
6053 OpenDirCnr((HWND) 0, hwndMain, hwndTree, TRUE, argv[x]);
6054 needTile = TRUE; // 2011-10-03 SHL
6055 }
6056 }
6057 }
6058 PostMsg(MainObjectHwnd, UM_SETUP5, MPVOID, MPVOID);
6059 return 0;
6060
6061 case UM_SETUP5:
6062# if 0
6063 if (fAutoTile)
6064 TileChildren(hwnd, TRUE);
6065# endif
6066 PostMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
6067 PostMsg(hwnd, UM_FILLSETUPLIST, MPVOID, MPVOID);
6068 PostMsg(hwnd, UM_FILLCMDLIST, MPVOID, MPVOID);
6069 PostMsg(hwnd, UM_FILLBUTTONLIST, MPVOID, MPVOID);
6070 {
6071 HWND hwndActive;
6072
6073 hwndActive = TopWindow(hwnd, hwndTree);
6074 if (hwndActive)
6075 WinSetWindowPos(hwndActive, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
6076 }
6077 if (fStartMinimized || fReminimize)
6078 PostMsg(hwndTree, UM_MINIMIZE, MPVOID, MPVOID);
6079 else if (fStartMaximized)
6080 PostMsg(hwndTree, UM_MAXIMIZE, MPVOID, MPVOID);
6081 else if (needTile)
6082 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID); // 2011-10-03 SHL
6083
6084 fRunning = TRUE; // Allow status window PRESPARM updates
6085
6086 if (fWantFirstTimeInit) {
6087 fWantFirstTimeInit = FALSE;
6088 PostMsg(hwnd, WM_COMMAND, MPFROMLONG(IDM_QUICKSETTINGS), MPVOID);
6089 }
6090 return 0;
6091 } // switch
6092
6093 return WinDefWindowProc(hwnd, msg, mp1, mp2);
6094}
6095
6096MRESULT EXPENTRY MainWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
6097{
6098 switch (msg) {
6099 case WM_CREATE:
6100# ifdef FORTIFY
6101 Fortify_EnterScope();
6102# endif
6103 case UM_SETUP:
6104 case UM_SETUP2:
6105 case UM_SETUP3:
6106 case UM_SETUP4:
6107 case UM_SETUP5:
6108 return MainWMOnce(hwnd, msg, mp1, mp2);
6109
6110 case WM_CONTROLPOINTER:
6111 if (!fNoFinger &&
6112 (SHORT1FROMMP(mp1) == IDM_OPENWALK ||
6113 SHORT1FROMMP(mp1) == IDM_USERLIST))
6114 return MRFROMLONG(hptrFinger);
6115 break;
6116
6117 case UM_LOADFILE:
6118 case UM_THREADUSE:
6119 case UM_BUILDDRIVEBAR:
6120 case WM_TIMER:
6121 return CommonMainWndProc(hwnd, msg, mp1, mp2);
6122
6123 case WM_BUTTON1UP:
6124 case WM_BUTTON2UP:
6125 case WM_BUTTON3UP:
6126 case WM_MOUSEMOVE:
6127 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
6128 break;
6129
6130 case WM_CHAR:
6131 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
6132 break;
6133
6134 case WM_MENUEND:
6135 if ((HWND) mp2 == MainPopupMenu) {
6136 WinDestroyWindow(MainPopupMenu);
6137 MainPopupMenu = (HWND) 0;
6138 }
6139 break;
6140
6141 case UM_CONTEXTMENU:
6142 case WM_CONTEXTMENU:
6143 if (CheckMenu(hwndMainMenu, &MainPopupMenu, MAIN_POPUP)) {
6144 SetToggleChecks(MainPopupMenu);
6145 PopupMenu(hwnd, hwnd, MainPopupMenu);
6146 }
6147 if (msg == UM_CONTEXTMENU)
6148 return 0;
6149 return MRFROMSHORT(TRUE);
6150
6151 case UM_SETUSERLISTNAME:
6152 if (mp1) {
6153 if (fUserComboBox)
6154 WinSetWindowText(WinWindowFromID(hwndUserlist, CBID_EDIT),
6155 (CHAR *)mp1);
6156 if (add_udir(FALSE, (CHAR *)mp1)) {
6157 if (fUserComboBox && fAutoAddDirs) {
6158 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6159 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6160 MPFROMP((CHAR *)mp1));
6161 }
6162 }
6163 }
6164 return 0;
6165
6166 case UM_ARRANGEICONS:
6167 ArrangeIcons(hwnd);
6168 return 0;
6169
6170 case WM_CHORD:
6171 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
6172 break;
6173
6174 case WM_SETFOCUS:
6175 if (mp2)
6176 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
6177 break;
6178
6179 case UM_FOCUSME:
6180 WinSetFocus(hwndTree, TRUE);
6181 return 0;
6182
6183 case UM_RESCAN:
6184 TileChildren(hwnd, TRUE);
6185 return 0;
6186
6187 case WM_SAVEAPPLICATION:
6188 {
6189 SWP swp;
6190
6191 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
6192 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
6193 WinStoreWindowPos((CHAR *) FM2Str,
6194 "MainWindowPos", WinQueryWindow(hwnd, QW_PARENT));
6195 if (!fNoSaveState && fSaveState)
6196 SaveDirCnrState(hwnd, PCSZ_SHUTDOWNSTATE);
6197 }
6198 }
6199 break;
6200
6201 case MM_PORTHOLEINIT:
6202 switch (SHORT1FROMMP(mp1)) {
6203 case 0:
6204 case 1:
6205 {
6206 HWND hwndCurrent;
6207 ULONG wmsg;
6208
6209 wmsg = (SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU;
6210 hwndCurrent = TopWindow(hwnd, (HWND) 0);
6211 PortholeInit((HWND) WinSendMsg(WinWindowFromID(hwndCurrent,
6212 FID_CLIENT), wmsg,
6213 MPVOID, MPVOID), mp1, mp2);
6214 }
6215 break;
6216 }
6217 break;
6218
6219 case WM_INITMENU:
6220 switch (SHORT1FROMMP(mp1)) {
6221 case IDM_CONFIGMENU:
6222 SetToggleChecks((HWND) WinQueryWindowULong(hwnd, QWL_USER));
6223 break;
6224
6225 case IDM_WINDOWSMENU:
6226 /**
6227 * add child windows of client
6228 * and switchlist entries to end of pulldown menu
6229 */
6230 {
6231 HWND hwndMenu, hwndSubMenu;
6232 MENUITEM mi;
6233
6234 hwndMenu = WinQueryWindowULong(hwnd, QWL_USER);
6235 memset(&mi, 0, sizeof(mi));
6236 mi.iPosition = MIT_END;
6237 mi.afStyle = MIS_TEXT;
6238 if (!WinSendMsg(hwndMenu, MM_QUERYITEM,
6239 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
6240 break;
6241 hwndSubMenu = mi.hwndSubMenu;
6242 SetupWinList(hwndSubMenu, hwnd, WinQueryWindow(hwnd, QW_PARENT));
6243 }
6244 break;
6245
6246 default:
6247 {
6248 HWND hwndCurrent;
6249
6250 hwndCurrent = TopWindow(hwnd, (HWND) 0);
6251 if (hwndCurrent)
6252 WinSendMsg(hwndCurrent, UM_INITMENU, mp1, mp2);
6253 }
6254 break;
6255 }
6256 break;
6257
6258 case UM_ADDTOMENU:
6259 AddToMenu((
6260 CHAR *)mp1, WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
6261 FID_MENU));
6262 return 0;
6263
6264 case UM_FILLCMDLIST:
6265 WinSendMsg(hwndCmdlist, LM_DELETEALL, MPVOID, MPVOID);
6266 if (!cmdloaded)
6267 load_commands();
6268 if (cmdhead) {
6269
6270 LINKCMDS *info;
6271 CHAR s[120];
6272
6273 info = cmdhead;
6274 while (info) {
6275 sprintf(s, "%s {%i}", info->title, info->ID);
6276 WinSendMsg(hwndCmdlist, LM_INSERTITEM,
6277 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
6278 info = info->next;
6279 }
6280 }
6281 return 0;
6282
6283 case UM_FILLSETUPLIST:
6284 fill_setups_list();
6285 return 0;
6286
6287 case UM_FILLBUTTONLIST:
6288 WinSendMsg(hwndButtonlist, LM_DELETEALL, MPVOID, MPVOID);
6289 if (fUserComboBox) {
6290
6291 BOOL foundit = FALSE, thisone;
6292 ULONG ulSearchCount;
6293 SHORT sSelect;
6294 FILEFINDBUF3 findbuf;
6295 HDIR hDir;
6296 CHAR *p;
6297
6298 DosError(FERR_DISABLEHARDERR);
6299 hDir = HDIR_CREATE;
6300 ulSearchCount = 1;
6301 if (!DosFindFirst("*.TLS", &hDir, FILE_READONLY | FILE_ARCHIVED,
6302 &findbuf, sizeof(FILEFINDBUF3),
6303 &ulSearchCount, FIL_STANDARD)) {
6304 do {
6305 priority_bumped();
6306 if (!foundit) {
6307 thisone = FALSE;
6308 p = strrchr(lasttoolbar, '\\');
6309 if (!p)
6310 p = lasttoolbar;
6311 else
6312 p++;
6313 if (!stricmp(findbuf.achName, p))
6314 thisone = TRUE;
6315 }
6316 p = strrchr(findbuf.achName, '.');
6317 if (p)
6318 *p = 0;
6319 sSelect = (SHORT) WinSendMsg(hwndButtonlist, LM_INSERTITEM,
6320 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6321 MPFROMP(findbuf.achName));
6322 if (!foundit && thisone && sSelect >= 0) {
6323 WinSendMsg(hwndButtonlist, LM_SELECTITEM,
6324 MPFROM2SHORT(sSelect, 0), MPFROMLONG(TRUE));
6325 foundit = TRUE;
6326 }
6327 }
6328 while (!DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3),
6329 &ulSearchCount));
6330 DosFindClose(hDir);
6331 priority_bumped();
6332 }
6333 WinSetWindowText(hwndButtonlist, (CHAR *) GetPString(IDS_TOOLBARTEXT));
6334 }
6335 return 0;
6336
6337 case UM_FILLUSERLIST:
6338 WinSendMsg(hwndUserlist, LM_DELETEALL, MPVOID, MPVOID);
6339 if (fUserComboBox) {
6340 ULONG ulDriveNum;
6341 ULONG ulDriveMap;
6342 ULONG ulSearchCount;
6343 FILEFINDBUF3 findbuf;
6344 HDIR hDir;
6345 APIRET rc;
6346 LINKDIRS *info;
6347 LINKDIRS *temp;
6348
6349 if (!loadedudirs)
6350 load_udirs();
6351 DosError(FERR_DISABLEHARDERR);
6352 DosQCurDisk(&ulDriveNum, &ulDriveMap);
6353 info = udirhead;
6354 while (info) {
6355 if (IsFullName(info->path) &&
6356 !(driveflags[toupper(*info->path) - 'A'] &
6357 (DRIVE_IGNORE | DRIVE_INVALID))) {
6358 DosError(FERR_DISABLEHARDERR);
6359 hDir = HDIR_CREATE;
6360 ulSearchCount = 1;
6361 if (!IsRoot(info->path))
6362 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6363 MUST_HAVE_DIRECTORY | FILE_READONLY |
6364 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6365 &findbuf, sizeof(FILEFINDBUF3),
6366 &ulSearchCount, FIL_STANDARD);
6367 else {
6368 rc = 0;
6369 findbuf.attrFile = FILE_DIRECTORY;
6370 }
6371 priority_bumped();
6372 if (!rc) {
6373 if (!IsRoot(info->path))
6374 DosFindClose(hDir);
6375 if (findbuf.attrFile & FILE_DIRECTORY)
6376 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6377 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6378 MPFROMP(info->path));
6379 else {
6380 temp = info->next;
6381 remove_udir(info->path);
6382 info = temp;
6383 continue;
6384 }
6385 }
6386 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6387 temp = info->next;
6388 remove_udir(info->path);
6389 info = temp;
6390 continue;
6391 }
6392 }
6393 info = info->next;
6394 }
6395 info = ldirhead;
6396 while (info) {
6397 if (IsFullName(info->path) &&
6398 !(driveflags[toupper(*info->path) - 'A'] &
6399 (DRIVE_IGNORE | DRIVE_INVALID))) {
6400 DosError(FERR_DISABLEHARDERR);
6401 hDir = HDIR_CREATE;
6402 ulSearchCount = 1;
6403 if (!IsRoot(info->path))
6404 rc = DosFindFirst(info->path, &hDir, FILE_DIRECTORY |
6405 MUST_HAVE_DIRECTORY | FILE_READONLY |
6406 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
6407 &findbuf, sizeof(FILEFINDBUF3),
6408 &ulSearchCount, FIL_STANDARD);
6409 else {
6410 rc = 0;
6411 findbuf.attrFile = FILE_DIRECTORY;
6412 }
6413 priority_bumped();
6414 if (!rc) {
6415 if (!IsRoot(info->path))
6416 DosFindClose(hDir);
6417 if (findbuf.attrFile & FILE_DIRECTORY)
6418 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6419 MPFROM2SHORT(LIT_SORTASCENDING, 0),
6420 MPFROMP(info->path));
6421 else {
6422 temp = info->next;
6423 remove_udir(info->path);
6424 info = temp;
6425 continue;
6426 }
6427 }
6428 else if (!(ulDriveMap & (1 << (toupper(*info->path) - 'A')))) {
6429 temp = info->next;
6430 remove_udir(info->path);
6431 info = temp;
6432 continue;
6433 }
6434 }
6435 info = info->next;
6436 }
6437 WinSendMsg(hwndUserlist, LM_INSERTITEM,
6438 MPFROM2SHORT(0, 0),
6439 MPFROMP(GetPString(IDS_NEWDIRECTORYTEXT)));
6440 WinSetWindowText(hwndUserlist, (CHAR *) GetPString(IDS_COMMONDIRTEXT));
6441 }
6442 return 0;
6443
6444 case UM_SIZE:
6445 if (fAutoTile)
6446 TileChildren(hwnd, FALSE);
6447 else
6448 MoveChildrenAwayFromTree(hwnd);
6449 return 0;
6450
6451 case WM_SIZE:
6452 ResizeChildren(hwnd, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),
6453 SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
6454 break;
6455
6456 case WM_ERASEBACKGROUND:
6457 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
6458 return 0;
6459
6460 case WM_PAINT:
6461 {
6462 HPS hps;
6463 RECTL rcl;
6464
6465 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
6466 if (hps) {
6467 WinQueryWindowRect(hwnd, &rcl);
6468 WinFillRect(hps, &rcl, CLR_PALEGRAY);
6469 WinEndPaint(hps);
6470 }
6471 }
6472 break;
6473
6474 case UM_CONTROL:
6475 switch (SHORT1FROMMP(mp1)) {
6476 case MAIN_CMDLIST:
6477 case MAIN_SETUPLIST:
6478 case MAIN_DRIVELIST:
6479 case MAIN_USERLIST:
6480 case MAIN_BUTTONLIST:
6481 switch (SHORT2FROMMP(mp1)) {
6482 case CBN_ENTER:
6483 {
6484 HWND hwndUL = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
6485 SHORT1FROMMP(mp1));
6486 CHAR path[CCHMAXPATH];
6487 ULONG ul;
6488
6489 switch (SHORT1FROMMP(mp1)) {
6490 case MAIN_USERLIST:
6491 ul = CCHMAXPATH;
6492 break;
6493 case MAIN_SETUPLIST:
6494 ul = STATE_NAME_MAX_BYTES;
6495 break;
6496 default:
6497 ul = 13; // fixme to not be hardcoded
6498 }
6499
6500 SetShiftState();
6501 WinQueryWindowText(WinWindowFromID(hwndUL, CBID_EDIT), ul, path);
6502 bstrip(path);
6503 if (*path) {
6504 if (SHORT1FROMMP(mp1) == MAIN_USERLIST) {
6505 // 06 Oct 09 SHL Ctrl-select selects, but suppresses open
6506 if ((shiftstate & (KC_CTRL | KC_SHIFT | KC_ALT)) == KC_CTRL)
6507 break;
6508 if (!strcmp(path, GetPString(IDS_NEWDIRECTORYTEXT))) {
6509 if (!LastDir ||
6510 !WinSendMsg(WinQueryWindow(LastDir, QW_PARENT),
6511 UM_CONTAINERDIR, MPFROMP(path), MPVOID))
6512 strcpy(path, pFM2SaveDirectory);
6513 if (!PMMkDir(hwnd, path, TRUE)) {
6514 WinSetWindowText(hwndUL, (CHAR *) GetPString(IDS_COMMONDIRTEXT));
6515 break;
6516 }
6517 }
6518 if (!IsFile(path) && !FindDirCnrByName(path, TRUE)) {
6519
6520 HWND hwndDir;
6521
6522 if ((fUserListSwitches &&
6523 !(shiftstate & KC_SHIFT)) ||
6524 (!fUserListSwitches && (shiftstate & KC_SHIFT))) {
6525 hwndDir = FindDirCnr(hwnd);
6526 if (hwndDir) {
6527 WinSendMsg(LastDir, UM_SETDIR, MPFROMP(path), MPVOID);
6528 break;
6529 }
6530 }
6531 OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, path);
6532 }
6533 }
6534 else if (SHORT1FROMMP(mp1) == MAIN_DRIVELIST) {
6535 ShowTreeRec(WinWindowFromID(WinWindowFromID(hwndTree,
6536 FID_CLIENT),
6537 TREE_CNR), path, FALSE, TRUE);
6538 WinSetFocus(HWND_DESKTOP, hwndTree);
6539 }
6540 else if (SHORT1FROMMP(mp1) == MAIN_BUTTONLIST) {
6541 strcat(path, PCSZ_DOTTLS);
6542 load_tools(path);
6543 PrfWriteProfileString(fmprof,
6544 FM3Str, "LastToolbar", lasttoolbar);
6545 PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
6546 WinSetWindowText(hwndButtonlist, (CHAR *) GetPString(IDS_TOOLBARTEXT));
6547 }
6548 else if (SHORT1FROMMP(mp1) == MAIN_SETUPLIST) {
6549 // State name list
6550 CHAR szKey[80];
6551 ULONG numsaves = 0;
6552 ULONG size = sizeof(ULONG);
6553 // Ctrl-select selects, but suppresses open
6554 if ((shiftstate & (KC_CTRL | KC_SHIFT | KC_ALT)) == KC_CTRL)
6555 break;
6556 sprintf(szKey, "%s.NumDirsLastTime", path); // path is state name
6557 if (!PrfQueryProfileData(fmprof,
6558 FM3Str,
6559 szKey,
6560 (PVOID)&numsaves,
6561 &size))
6562 {
6563 // Name not found
6564 if ((WinGetLastError(WinQueryAnchorBlock(hwnd)) & 0xffff) == PMERR_NOT_IN_IDX) {
6565 saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
6566 GetPString(IDS_WARNINGTEXT),
6567 GetPString(IDS_DOESNTEXISTTEXT), path);
6568 }
6569 else {
6570 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
6571 PCSZ_INIQUERYPRFTEXT);
6572 }
6573 }
6574 else {
6575 // Name exists
6576 char *pszStateName;
6577 // If shift key, add state to existing state - FIXME to doc better
6578 if ((shiftstate & KC_SHIFT) == 0)
6579 PostMsg(MainObjectHwnd, UM_RESTORE, MPVOID, MPFROMLONG(RESTORE_STATE_CLOSE_CHILDREN));
6580 pszStateName = xstrdup(path, pszSrcFile, __LINE__);
6581 if (!pszStateName) {
6582 // Fall back if out of memory - already complained
6583 if ((shiftstate & KC_SHIFT) != 0 || fAutoTile) {
6584 // Autotile requested or forced
6585 PostMsg(MainObjectHwnd,
6586 UM_RESTORE,
6587 MPVOID,
6588 MPFROMLONG(1)); // Autotile
6589 }
6590 }
6591 // Request restore
6592 else if (!PostMsg(MainObjectHwnd,
6593 UM_RESTORE,
6594 MPFROMP(pszStateName),
6595 MPVOID)) {
6596 free(pszStateName);
6597 }
6598 }
6599 } // if MAIN_SETUPLIST
6600 else if (SHORT1FROMMP(mp1) == MAIN_CMDLIST) {
6601
6602 SHORT sSelect = (SHORT) WinSendMsg(hwndCmdlist,
6603 LM_QUERYSELECTION,
6604 MPFROMSHORT(LIT_FIRST), MPVOID);
6605 if (sSelect >= 0) {
6606 CHAR s[CCHMAXPATH];
6607 CHAR *p;
6608
6609 WinSendMsg(hwndCmdlist, LM_QUERYITEMTEXT,
6610 MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
6611 p = strrchr(s, '}');
6612 p = 0;
6613 p = strrchr(s, '{');
6614 p++;
6615 WinPostMsg(hwnd,
6616 WM_COMMAND,
6617 MPFROM2SHORT(atol(p), 0), //fixme GKY this traps in atol the {} probably don't exist
6618 //IDM_COMMANDSTART + sSelect, 0),
6619 MPVOID);
6620 }
6621 WinSetWindowText(hwndCmdlist, (CHAR *) GetPString(IDS_COMMANDSTEXT));
6622 }
6623 }
6624 } // CBN_ENTER
6625 break;
6626
6627 default:
6628 break;
6629 }
6630 break;
6631
6632 default:
6633 break;
6634 }
6635 return 0;
6636
6637 case WM_HELP:
6638 if (hwndHelp)
6639 PostMsg(hwndHelp, HM_DISPLAY_HELP, MPFROMSHORT(1), MPFROMSHORT(HM_RESOURCEID));
6640 break;
6641
6642 case UM_COMMAND:
6643 case WM_COMMAND:
6644
6645 return MainWMCommand(hwnd, msg, mp1, mp2);
6646
6647 case WM_CLOSE:
6648 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6649 WM_SYSCOMMAND, MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
6650 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
6651 fAmClosing = TRUE;
6652 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
6653 WM_SYSCOMMAND, MPFROM2SHORT(SC_MINIMIZE, 0), MPVOID);
6654 if (CloseChildren(hwnd)) {
6655 fAmClosing = FALSE;
6656 if (fAutoTile)
6657 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_TILE, 0), MPVOID);
6658 return 0;
6659 }
6660 if (hwndTree) {
6661 if (!PostMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID))
6662 WinSendMsg(hwndTree, WM_CLOSE, MPVOID, MPVOID);
6663 }
6664 DosSleep(1);
6665 DbgMsg(pszSrcFile, __LINE__, "MainWndProc WM_CLOSE returning");
6666
6667 return 0; // Suppress WinDefWindowProc WM_QUIT message generation
6668
6669 case UM_CLOSE:
6670 HideNote();
6671 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
6672 return 0;
6673
6674 case UM_RESTORE:
6675 {
6676 // Try to restore saved shutdown state
6677 char *pszDefaultStateName = xstrdup(PCSZ_SHUTDOWNSTATE, pszSrcFile, __LINE__);
6678 if (pszDefaultStateName) {
6679 if (!PostMsg(MainObjectHwnd, UM_RESTORE, MPFROMP(pszDefaultStateName), MPFROMLONG(RESTORE_STATE_RESTORE)))
6680 // 05 Feb 08 SHL fixme to complain?
6681 free(pszDefaultStateName);
6682 }
6683 }
6684 return 0;
6685
6686 case UM_SETDIR:
6687 // mp1 == name of directory to open
6688 if (mp1)
6689 return MRFROMLONG(OpenDirCnr((HWND) 0,
6690 hwndMain,
6691 hwndTree, (BOOL) mp2, (char *)mp1));
6692 return 0;
6693
6694 case WM_DESTROY:
6695 hwndMain = (HWND)0;
6696 if (!PostMsg((HWND)0, WM_QUIT, MPVOID, MPVOID))
6697 WinSendMsg((HWND)0, WM_QUIT, MPVOID, MPVOID);
6698# ifdef FORTIFY
6699 free_commands();
6700 free_associations();
6701 free_udirs();
6702 free_ldir();
6703 free_archivers();
6704 free_tools();
6705 free_setups();
6706 Fortify_LeaveScope();
6707# endif
6708 break;
6709 }
6710 return WinDefWindowProc(hwnd, msg, mp1, mp2);
6711}
6712
6713#pragma alloc_text(MISC8,SetToggleChecks,FindDirCnrByName,TopWindow)
6714#pragma alloc_text(MISC8,TopWindowName,CountDirCnrs)
6715#pragma alloc_text(MAINWND,AdjustSizeOfClient,FillClient,ChildButtonProc)
6716#pragma alloc_text(MAINWND,ToolBackProc,StatusProc)
6717#pragma alloc_text(MAINWND,MoveChildrenAwayFromTree,ArrangeIcons,NextChild)
6718#pragma alloc_text(MAINWND,ChildFrameButtonProc)
6719#pragma alloc_text(MAINWND2,CloseChildren,CountChildren,GetNextWindowPos)
6720#pragma alloc_text(MAINWND2,CascadeChildren,TileChildren,ResizeChildren)
6721#pragma alloc_text(MAINWND2,MinResChildren,MainFrameWndProc,MainWndProc)
6722#pragma alloc_text(MAINWND2,DropDownListProc)
6723#pragma alloc_text(MAINWND3,RestoreDirCnrState,SaveDirCnrState)
6724#pragma alloc_text(MAINWND3,CloseDirCnrChildren,TransformSwp)
6725#pragma alloc_text(MAINWND3,ResizeTools,BuildTools,CommandLineProc)
6726#pragma alloc_text(MAINWND4,DriveProc,DriveBackProc,BuildDriveBarButtons,ResizeDrives)
6727#pragma alloc_text(MAINWND4,LEDProc,IdealButtonProc)
6728#pragma alloc_text(MAINWND5,MainWMOnce)
6729#pragma alloc_text(MAINWND6,MainWMCommand)
6730#pragma alloc_text(BUBBLE,MakeBubble,BubbleProc,BubbleHelp)
6731#pragma alloc_text(MAINOBJ,MainObjectWndProc,MakeMainObjWin)
6732
Note: See TracBrowser for help on using the repository browser.