source: trunk/dll/mainwnd.c@ 1409

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

Rename some container ini keys consolidate inline code in WriteDetailsSwitches, LoadDetailsSwitches and RemoveCnrSwitches (Ticket 343, 345, 347) Save changes to detail switches for compare directories (Ticket 346). Move additional messages to PCSZs (Ticket 6). Comments and minor code clean up.

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