source: trunk/dll/mainwnd.c@ 1224

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

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