source: trunk/dll/mainwnd.c@ 1209

Last change on this file since 1209 was 1209, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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