source: trunk/dll/mainwnd.c@ 1362

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

Add databar to utilities menu (Ticket 280)

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