source: trunk/dll/mainwnd.c@ 1315

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

Improve multithread treecnr scan to prevent scan of "last" directory container prior to tree scan completion; prevents duplicate directory names in tree.

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