source: trunk/dll/mainwnd.c@ 1303

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

Last part of remove or replace with a mutex semaphore DosEnterCriSec where appropriate. (Ticket 308) Note the partial commits for this ticket won't build without this.

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