source: trunk/dll/treecnr.c@ 1799

Last change on this file since 1799 was 1799, checked in by Gregg Young, 10 years ago

Add fix for trap on close while filtered dir container was still populating to collector, arc container and tree container after collector experienced the same trap. Ticket [535]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 91.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: treecnr.c 1799 2015-03-16 22:26:04Z gyoung $
5
6 Tree containers
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001-2012 Steven H. Levine
10
11 16 Oct 02 SHL Handle large partitions
12 11 Jun 03 SHL Add JFS and FAT32 support
13 25 May 05 SHL Rename comnam to szCommonName and fix typo
14 25 May 05 SHL Use ULONGLONG and CommaFmtULL
15 26 May 05 SHL More large file formatting updates
16 05 Jun 05 SHL Use QWL_USER
17 06 Aug 05 SHL Renames
18 08 Dec 05 SHL TreeCnrWndProc: disable menu items if drive not ready
19 17 Jul 06 SHL Use Runtime_Error
20 15 Aug 06 SHL Rework SetMask args
21 31 Aug 06 JS Add more partitioning menu items
22 22 Oct 06 GKY Add NDFS32 support
23 29 Dec 06 GKY Fixed menu gray out for remote drives (added variable "remote")
24 29 Dec 06 GKY Enabled edit of drive flags on "not ready" drives
25 18 Feb 07 GKY More drive type and icon support
26 08 Mar 07 SHL Ensure drive icon updates after drive flags change
27 09 Mar 07 GKY Use SelectDriveIcon
28 30 Mar 07 GKY Remove GetPString for window class names
29 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
30 06 Apr 07 GKY Add some error checking in drag/drop
31 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
32 19 Apr 07 SHL Add more drag/drop error checking
33 12 May 07 SHL Use dcd->ulItemsToUnHilite; sync with UnHilite arg mods
34 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
35 10 Jun 07 GKY Mouse button 3 white space click to fail silently
36 05 Jul 07 SHL Disable leftover debug code
37 02 Aug 07 SHL Sync with CNRITEM mods
38 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
39 14 Aug 07 SHL Revert ShowTreeRec DosSleep to 0
40 14 Aug 07 SHL Optimze ShowTreeRec collapse - was really slow
41 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
42 22 Aug 07 SHL Disable DbgMsgs shipped with 3.0.8beta1
43 26 Aug 07 SHL Revert to DosSleep(0)
44 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
45 10 Jan 08 SHL Sync with CfgDlgProc mods
46 15 Feb 08 SHL Sync with settings menu rework
47 15 Feb 08 SHL Avoid death if tree container 0 width
48 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
49 02 Aug 08 GKY Always pass temp variable point to UM_SHOWME to avoid freeing pci->pszFileName early
50 19 Oct 08 GKY Fixed logic for greying menu items (Format etc) on remote and virtual drives (it was reversed)
51 19 Oct 08 GKY Fixed context menu to be "drives" menu on unformatted drives
52 28 Nov 08 GKY Remove unneeded DosEnterCriSec calls
53 10 Dec 08 SHL Integrate exception handler support
54 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
55 26 Dec 08 GKY Implemented DROPHELP for the tree container
56 27 Dec 08 GKY Add refresh removable media to tree container menus
57 28 Dec 08 GKY Rework partition submenu to gray out unavailable items (check for existence of files)
58 and have no default choice.
59 01 Jan 09 GKY Add Seek and Scan to drives & directory context menus pass drive/dir as search root
60 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
61 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
62 07 Feb 09 GKY Add *DateFormat functions to format dates based on locale
63 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
64 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
65 08 Mar 09 GKY Additional strings move to PCSZs in init.c
66 12 Mar 09 SHL Use common SearchContainer
67 14 Mar 09 GKY Prevent execution of UM_SHOWME while drive scan is occuring
68 06 Jun 09 GKY Add option to show file system type or drive label in tree
69 06 Jun 09 GKY Status line to show file sys/label not shown in tree; shortened to fit split status
70 07 Jun 09 GKY Fixed double names in tree container when collapsed tree is accessed
71 before recursive scan
72 12 Jul 09 GKY Add option to show file system type or drive label in tree
73 (get NOPRESCAN drives working)
74 22 Jul 09 GKY Code changes to use semaphores to serialize drive scanning
75 22 Jul 09 GKY Consolidated driveflag setting code in DriveFlagsOne
76 22 Jul 09 GKY Streamline scanning code for faster Tree rescans
77 14 Sep 09 SHL Drop experimental code
78 15 Sep 09 SHL Use UM_GREP when passing pathname
79 15 Nov 09 GKY Add semaphore to fix double names in tree container caused by UM_SHOWME
80 before scan completes
81 22 Nov 09 GKY Add LVM.EXE to partition submenu
82 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast
83 CHAR CONSTANT * as CHAR *.
84 11 Apr 10 GKY Fix drive tree rescan failure and program hang caused by event sem
85 never being posted
86 20 Nov 10 GKY Rework scanning code to remove redundant scans, prevent double directory
87 entries in the tree container, fix related semaphore performance using
88 combination of event and mutex semaphores
89 04 Aug 12 GKY Fix trap reported by Ben
90 30 Dec 12 GKY Changed refresh removable media to query LVM directly to call Rediscover_PRMs (Ticket 472);
91 Also added a tree rescan following volume detach.
92 22 Feb 14 GKY Fix warn readonly yes don't ask to work when recursing directories.
93 07 Sep 14 GKY Fix tree container mis-draws (stacked icons with RWS) The problem was magnified
94 by RWS but I think the occasional extra blank directory or duplicating
95 directories is related.
96 16 Mar 15 GKY Add semaphore hmtxFiltering to prevent freeing dcd while filtering. Prevents
97 a trap when FM2 is shutdown or the container is closed while tree
98 container is still populating
99
100***********************************************************************/
101
102#include <stdlib.h>
103#include <string.h>
104#include <ctype.h>
105// #include <process.h> // _beginthread
106
107#define INCL_DOS
108#define INCL_WIN
109#define INCL_LONGLONG
110#define INCL_DOSERRORS
111
112#include "fm3dll.h"
113#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
114#include "treecnr.h"
115#include "mainwnd2.h" // Data declaration(s)
116#include "grep.h" // Data declaration(s)
117#include "dircnrs.h" // Data declaration(s)
118#include "info.h" // Data declaration(s)
119#include "fm3dlg.h"
120#include "fm3str.h"
121#include "mle.h"
122#include "comp.h" // COMPARE
123#include "filldir.h" // RemoveCnrItems...
124#include "errutil.h" // Dos_Error...
125#include "strutil.h" // GetPString
126#include "notebook.h" // CfgDlgProc
127#include "command.h" // RunCommand
128#include "worker.h" // Action, MassAction
129#include "mainwnd.h" // BubbleHelp, FindDirCnrByName, GetNextWindowPos
130#include "misc.h" // CnrDirectEdit, EmphasizeButton, FindDirCnr
131 // FindDirCnr, FixSwitchList, OpenEdit, QuickPopup
132 // SetSortChecks, SwitchCommand, CheckMenu
133 // CurrentRecord, IsFm2Window
134#include "common.h" // CommonCnrProc, CommonDriveCmd, CommonFrameWndProc
135 // CommonTextProc
136#include "valid.h" // CheckDrive, DriveFlagsOne, IsValidDrive
137#include "chklist.h" // DropListProc
138#include "select.h" // ExpandAll
139#include "findrec.h" // FindCnrRecord, FindParentRecord, ShowCnrRecord
140#include "flesh.h" // Flesh, UnFlesh
141#include "notify.h" // HideNote
142#include "objwin.h" // MakeObjWin
143#include "notify.h" // NotifyError
144#include "remap.h" // RemapDlgProc
145#include "saveclip.h" // SaveListDlgProc
146#include "update.h" // SelectDriveIcon, UpdateCnrList, UpdateCnrRecord
147#include "sortcnr.h" // SortTreeCnr
148#include "droplist.h" // AcceptOneDrop, CheckPmDrgLimit, DropHelp, GetOneDrop
149#include "presparm.h" // CopyPresParams
150#include "defview.h" // DefaultViewKeys
151#include "draglist.h" // DoFileDrag
152#include "filter.h" // Filter
153#include "shadow.h" // OpenObject
154#include "mkdir.h" // PMMkDir
155#include "collect.h" // StartCollector
156#include "viewer.h" // StartMLEEditor
157#include "newview.h" // StartViewer
158#include "walkem.h" // WalkAllDlgProc
159#include "i18nutil.h" // CommaFmtULL
160#include "wrappers.h" // xDosFindFirst
161#include "systemf.h" // runemf2
162#include "dirs.h" // save_dir2
163#include "fortify.h"
164#include "init.h" // GetTidForWindow
165#include "excputil.h" // xbeginthread
166#include "copyf.h" // ignorereadonly
167
168// Data definitions
169
170#pragma data_seg(GLOBAL1)
171HWND LastDir;
172HWND TreeCnrMenu;
173INT driveserial[26];
174BOOL fDCOpens;
175BOOL fDummy;
176BOOL fFollowTree;
177BOOL fTopDir;
178BOOL fLVMGui;
179BOOL fDFSee;
180BOOL fFDisk;
181BOOL fMiniLVM;
182BOOL fLVM;
183HPOINTER hptrDunno;
184HWND hwndMainMenu;
185
186#pragma data_seg(GLOBAL2)
187ULONG FM3UL;
188INT TreesortFlags;
189
190#pragma data_seg(DATA1)
191
192static PSZ pszSrcFile = __FILE__;
193static BOOL fOkayMinimize;
194
195APIRET16 APIENTRY16 Dos16MemAvail(PULONG pulAvailMem);
196
197typedef struct APPNOTIFY
198{
199 HAPP happ;
200 CHAR device;
201 struct APPNOTIFY *next;
202 struct APPNOTIFY *prev;
203}
204APPNOTIFY;
205
206MRESULT EXPENTRY OpenButtonProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
207{
208 static BOOL emphasized = FALSE;
209
210 switch (msg) {
211 case WM_CREATE:
212 {
213 MRESULT rc;
214
215 rc = PFNWPButton(hwnd, msg, mp1, mp2);
216 //fixme to allow user to change presparams 1-10-09 GKY
217 WinSetPresParam(hwnd, PP_FONTNAMESIZE,
218 strlen(FNT_8TIMESNEWROMAN) + 1,
219 (PVOID) FNT_8TIMESNEWROMAN);
220 return rc;
221 }
222
223 case WM_MOUSEMOVE:
224 BubbleHelp(hwnd, TRUE, FALSE, TRUE, GetPString(IDS_OPENBUTTONHELP));
225 break;
226
227 case WM_CONTEXTMENU:
228 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
229 WM_COMMAND, MPFROM2SHORT(IDM_OPENWALK, 0), MPVOID);
230 return 0;
231
232 case DM_DRAGOVER:
233 if (!emphasized) {
234 emphasized = TRUE;
235 EmphasizeButton(hwnd, emphasized);
236 }
237 if (AcceptOneDrop(hwnd, mp1, mp2))
238 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
239 return MRFROM2SHORT(DOR_NEVERDROP, 0);
240
241 case DM_DRAGLEAVE:
242 if (emphasized) {
243 emphasized = FALSE;
244 EmphasizeButton(hwnd, emphasized);
245 }
246 break;
247
248 case DM_DROPHELP:
249 DropHelp(mp1, mp2, hwnd, GetPString(IDS_OPENDROPHELP));
250 return 0;
251
252 case DM_DROP:
253 {
254 char szFrom[CCHMAXPATH + 2];
255
256 if (emphasized) {
257 emphasized = FALSE;
258 EmphasizeButton(hwnd, emphasized);
259 }
260 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
261 MakeValidDir(szFrom);
262 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
263 UM_OPENWINDOWFORME, MPFROMP(szFrom), MPVOID);
264 }
265 }
266 return 0;
267
268 }
269 return PFNWPButton(hwnd, msg, mp1, mp2);
270}
271
272VOID ShowTreeRec(HWND hwndCnr,
273 CHAR *dirname,
274 BOOL collapsefirst,
275 BOOL maketop)
276{
277 /**
278 * Find a record in tree view, move it so it shows in container and
279 * make it the current record
280 */
281
282 PCNRITEM pci, pciToSelect, pciP;
283 BOOL quickbail = FALSE;
284 CHAR szDir[CCHMAXPATH], *p;
285
286 // already positioned to requested record?
287 pci = WinSendMsg(hwndCnr,
288 CM_QUERYRECORDEMPHASIS,
289 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
290 if (pci && (INT) pci != -1 && !stricmp(pci->pszFileName, dirname)) {
291 quickbail = TRUE; // Bypass repositioning
292 goto MakeTop;
293 }
294 WinEnableWindowUpdate(hwndCnr, FALSE);
295 pci = FindCnrRecord(hwndCnr, dirname, NULL, TRUE, FALSE, TRUE);
296 if (!pci || (INT) pci == -1) {
297 *szDir = *dirname;
298 szDir[1] = ':';
299 szDir[2] = '\\';
300 szDir[3] = 0;
301 p = szDir + 3; // Point after root backslash
302 for (;;) {
303 pciP = FindCnrRecord(hwndCnr, szDir, NULL, TRUE, FALSE, TRUE);
304 if (pciP && (INT) pciP != -1) {
305 if (!stricmp(dirname, pciP->pszFileName))
306 break; // Found it
307 if (~pciP->rc.flRecordAttr & CRA_EXPANDED)
308 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciP), MPVOID);
309 strcpy(szDir, dirname);
310 if (p - szDir >= strlen(szDir))
311 break; // Not root dir
312 p = strchr(p, '\\');
313 if (p) {
314 *p = 0; // fixme?
315 p++;
316 }
317 else
318 break;
319 }
320 else
321 break;
322 DosSleep(0);
323 } // for
324 pci = FindCnrRecord(hwndCnr, dirname, NULL, TRUE, FALSE, TRUE);
325 }
326 if (pci && (INT) pci != -1) {
327 if (~pci->rc.flRecordAttr & CRA_CURSORED) {
328 if (collapsefirst) {
329 pciP = WinSendMsg(hwndCnr,
330 CM_QUERYRECORD,
331 MPVOID, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
332 while (pciP && (INT) pciP != -1) {
333#if 1 // 05 Jan 08 SHL fixme to be sure this is correct code
334 if (pciP->rc.flRecordAttr & CRA_EXPANDED) {
335 // collapse top level of all branches
336 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciP), MPVOID);
337 }
338#else // fixme to be gone
339 if (toupper(*pciP->pszFileName) == toupper(*dirname)) {
340 // collapse all levels if branch is our drive
341 if (pciP->rc.flRecordAttr & CRA_EXPANDED)
342 ExpandAll(hwndCnr, FALSE, pciP);
343 }
344 else if (pciP->rc.flRecordAttr & CRA_EXPANDED) {
345 // collapse top level of all branches
346 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciP), MPVOID);
347 }
348#endif
349 pciP = WinSendMsg(hwndCnr,
350 CM_QUERYRECORD,
351 MPFROMP(pciP),
352 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
353 } // while
354 }
355 // expand all parent branches
356 pciToSelect = pci;
357 for (;;) {
358 pciP = WinSendMsg(hwndCnr,
359 CM_QUERYRECORD,
360 MPFROMP(pciToSelect),
361 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
362 if (pciP && (INT) pciP != -1) {
363 if (!(pciP->rc.flRecordAttr & CRA_EXPANDED))
364 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciP), MPVOID);
365 pciToSelect = pciP;
366 }
367 else
368 break;
369 DosSleep(0); // Let GUI update
370 } // for
371 }
372 // make record visible
373 MakeTop:
374 pciToSelect = pci;
375 if (pciToSelect && (INT) pciToSelect != -1) {
376 //DbgMsg(pszSrcFile, __LINE__, "TOP %i %i", fTopDir, maketop);
377 if (fSwitchTreeExpand && ~pciToSelect->rc.flRecordAttr & CRA_EXPANDED)
378 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciToSelect), MPVOID);
379 if (fTopDir || maketop) {
380 ShowCnrRecord(hwndCnr, (PMINIRECORDCORE) pciToSelect);
381 }
382 if (!quickbail) {
383 WinSendMsg(hwndCnr,
384 CM_SETRECORDEMPHASIS,
385 MPFROMP(pciToSelect),
386 MPFROM2SHORT(TRUE, CRA_SELECTED | CRA_CURSORED));
387 }
388 }
389 }
390 WinEnableWindowUpdate(hwndCnr, TRUE);
391}
392
393MRESULT EXPENTRY TreeTitleWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
394 MPARAM mp2)
395{
396 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
397
398 switch (msg) {
399 case WM_CONTEXTMENU:
400 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
401 UM_CONTEXTMENU, mp1, mp2);
402 }
403 return oldproc(hwnd, msg, mp1, mp2);
404}
405
406MRESULT EXPENTRY TreeStatProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
407{
408 switch (msg) {
409 case WM_CREATE:
410 return CommonTextProc(hwnd, msg, mp1, mp2);
411
412 case WM_CONTEXTMENU:
413 PostMsg(WinQueryWindow(hwnd, QW_PARENT), msg, mp1, mp2);
414 return 0;
415
416 case WM_PAINT:
417 {
418 MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
419
420 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
421 return mr;
422 }
423
424 case WM_SETFOCUS:
425 if (mp2)
426 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
427 break;
428
429 case UM_FOCUSME:
430 WinSetFocus(HWND_DESKTOP, WinQueryWindow(hwnd, QW_PARENT));
431 return 0;
432 }
433 return PFNWPStatic(hwnd, msg, mp1, mp2);
434}
435
436MRESULT EXPENTRY TreeFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
437 MPARAM mp2)
438{
439 switch (msg) {
440 case UM_RESCAN:
441 PostMsg(WinQueryWindow(hwnd, QW_PARENT), msg, mp1, mp2);
442 return 0;
443
444 case WM_ADJUSTWINDOWPOS:
445 {
446 SWP *pswp;
447
448 pswp = (SWP *) mp1;
449 if (ParentIsDesktop(hwnd, (HWND) 0)) {
450 if (pswp->fl & (SWP_HIDE | SWP_MINIMIZE))
451 HideNote();
452 }
453 }
454 break;
455
456 case WM_TRACKFRAME:
457 if (!fFreeTree && !ParentIsDesktop(hwnd, (HWND) 0)) {
458 switch (SHORT1FROMMP(mp1) & TF_MOVE) {
459 case TF_MOVE:
460 case TF_LEFT:
461 case TF_TOP:
462 case (TF_LEFT | TF_BOTTOM):
463 case (TF_LEFT | TF_TOP):
464 {
465 SWP swp;
466
467 WinQueryWindowPos(hwnd, &swp);
468 if (!(swp.fl & SWP_ACTIVATE))
469 WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
470 SWP_ZORDER | SWP_ACTIVATE);
471 }
472 return 0;
473 }
474 }
475 break;
476
477 case WM_CALCFRAMERECT:
478 if (*(ULONG *) realappname != FM3UL) {
479
480 MRESULT mr;
481 PRECTL prectl;
482
483 mr = CommonFrameWndProc(TREE_CNR, hwnd, msg, mp1, mp2);
484
485 /**
486 * Calculate the position of the client rectangle.
487 * Otherwise, we'll see a lot of redraw when we move the
488 * client during WM_FORMATFRAME.
489 */
490
491 if (mr && mp2) {
492 prectl = (PRECTL) mp1;
493 prectl->yTop -= 22;
494 }
495 return mr;
496 }
497 break;
498
499 case WM_FORMATFRAME:
500 {
501 SHORT sCount;
502 PSWP pswp, pswpClient, pswpNew;
503
504 sCount = (SHORT) CommonFrameWndProc(TREE_CNR, hwnd, msg, mp1, mp2);
505
506 // Reformat the frame to "squeeze" the client
507
508 pswp = (PSWP) mp1;
509 {
510 SHORT x;
511
512 for (x = 0; x < sCount; x++) {
513 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
514 pswpClient = pswp;
515 break;
516 }
517 pswp++;
518 }
519 }
520 pswpNew = (PSWP) mp1 + sCount;
521 *pswpNew = *pswpClient;
522 pswpNew->hwnd = WinWindowFromID(hwnd, MAIN_STATUS);
523 if (*(ULONG *) realappname == FM3UL) {
524
525 PSWP pswpTitlebar = (PSWP) 0, pswpMinbutton = (PSWP) 0;
526 SHORT x;
527
528 pswpNew->hwnd = WinWindowFromID(hwnd, IDM_OPENWINDOW);
529 pswp = (PSWP) mp1;
530 for (x = 0; x < sCount; x++) {
531 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_TITLEBAR)
532 pswpTitlebar = pswp;
533 else if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_MINMAX)
534 pswpMinbutton = pswp;
535 if (pswpTitlebar && pswpMinbutton)
536 break;
537 pswp++;
538 }
539 pswpNew->cy = pswpMinbutton->cy + 3;
540 pswpNew->cx = min(pswpNew->cy, (pswpMinbutton->cx / 2) + 3);
541 pswpTitlebar->cx -= (pswpNew->cx + 1);
542 pswpNew->x = pswpTitlebar->x + pswpTitlebar->cx;
543 pswpNew->y = pswpMinbutton->y - 1;
544 }
545 else {
546 pswpNew->x = pswpClient->x + 3;
547 pswpNew->y = (pswpClient->y + pswpClient->cy) - 20;
548 pswpNew->cx = pswpClient->cx - 6;
549 pswpNew->cy = 18;
550 pswpClient->cy -= 22;
551 }
552 sCount++;
553 return MRFROMSHORT(sCount);
554 }
555
556 case WM_QUERYFRAMECTLCOUNT:
557 {
558 SHORT sCount;
559
560 sCount = (SHORT) CommonFrameWndProc(TREE_CNR, hwnd, msg, mp1, mp2);
561 sCount++;
562 return MRFROMSHORT(sCount);
563 }
564 }
565 return CommonFrameWndProc(TREE_CNR, hwnd, msg, mp1, mp2);
566}
567
568MRESULT EXPENTRY TreeClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
569 MPARAM mp2)
570{
571 switch (msg) {
572 case UM_CONTAINERHWND:
573 return MRFROMLONG(WinWindowFromID(hwnd, TREE_CNR));
574
575 case UM_VIEWSMENU:
576 return MRFROMLONG(CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP));
577
578 case UM_TIMER:
579 case UM_ACTION:
580 case UM_SHOWME:
581 case UM_OPENWINDOWFORME:
582 case UM_MINIMIZE:
583 case UM_MAXIMIZE:
584 case WM_INITMENU:
585 case UM_INITMENU:
586 case UM_FILTER:
587 case UM_FILESMENU:
588 case UM_UPDATERECORD:
589 case UM_UPDATERECORDLIST:
590 case MM_PORTHOLEINIT:
591 case UM_DRIVECMD:
592 case WM_CLOSE:
593 case WM_CONTROL:
594 case UM_COMMAND:
595 case WM_COMMAND:
596 return WinSendMsg(WinWindowFromID(hwnd, TREE_CNR), msg, mp1, mp2);
597
598 case WM_PSETFOCUS:
599 case WM_SETFOCUS:
600 if (mp2)
601 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
602 break;
603
604 case UM_FOCUSME:
605 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, TREE_CNR));
606 break;
607
608 case WM_ERASEBACKGROUND:
609 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
610 return 0;
611
612 case WM_PAINT:
613 {
614 HPS hps;
615 RECTL rcl;
616
617 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
618 if (hps) {
619 WinQueryWindowRect(hwnd, &rcl);
620 WinFillRect(hps, &rcl, CLR_PALEGRAY);
621 PaintRecessedWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
622 MAIN_STATUS), hps, FALSE, FALSE);
623 WinEndPaint(hps);
624 }
625 }
626 break;
627
628 case WM_SIZE:
629 WinSetWindowPos(WinWindowFromID(hwnd, TREE_CNR),
630 HWND_TOP,
631 0,
632 0,
633 SHORT1FROMMP(mp2),
634 SHORT2FROMMP(mp2), SWP_SHOW | SWP_MOVE | SWP_SIZE);
635 if (hwndMain)
636 PostMsg(hwndMain, UM_SIZE, MPVOID, MPVOID);
637 break;
638
639 case WM_CONTEXTMENU:
640 case UM_CONTEXTMENU:
641 PostMsg(WinWindowFromID(hwnd, TREE_CNR),
642 WM_CONTROL, MPFROM2SHORT(TREE_CNR, CN_CONTEXTMENU), MPVOID);
643 return 0;
644 }
645 return WinDefWindowProc(hwnd, msg, mp1, mp2);
646}
647
648MRESULT EXPENTRY TreeObjWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
649{
650 DIRCNRDATA *dcd;
651
652 switch (msg) {
653 case UM_SHOWME:
654 if (mp1) {
655# ifdef FORTIFY
656 Fortify_BecomeOwner(mp1);
657# endif
658 dcd = INSTDATA(hwnd);
659 if (dcd) {
660 BOOL tempsusp, tempfollow, temptop;
661
662 DosWaitEventSem(hevTreeCnrScanComplete, SEM_INDEFINITE_WAIT);
663 tempsusp = dcd->suspendview;
664 dcd->suspendview = TRUE;
665 tempfollow = fFollowTree;
666 fFollowTree = FALSE;
667 if (mp2) {
668 temptop = fTopDir;
669 fTopDir = TRUE;
670 }
671 ShowTreeRec(dcd->hwndCnr, (CHAR *)mp1, fCollapseFirst, TRUE);
672 PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_UPDATE, 0), MPVOID);
673 dcd->suspendview = (USHORT) tempsusp;
674 fFollowTree = tempfollow;
675 if (mp2)
676 fTopDir = temptop;
677 }
678 free((CHAR *)mp1);
679 }
680 return 0;
681
682 case DM_PRINTOBJECT:
683 return MRFROMLONG(DRR_TARGET);
684
685 case DM_DISCARDOBJECT:
686 dcd = INSTDATA(hwnd);
687 if (fFM2Deletes && dcd) {
688
689 LISTINFO *li;
690 CNRDRAGINFO cni;
691
692 cni.pRecord = NULL;
693 cni.pDragInfo = (PDRAGINFO) mp1;
694 li = DoFileDrop(dcd->hwndCnr,
695 dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
696 CheckPmDrgLimit(cni.pDragInfo);
697 if (li) {
698 li->type = ((fDefaultDeletePerm) ? IDM_PERMDELETE : IDM_DELETE);
699 if (!PostMsg(hwnd, UM_MASSACTION, MPFROMP(li), MPVOID))
700 FreeListInfo(li);
701 else
702 return MRFROMLONG(DRR_SOURCE);
703 }
704 }
705 return MRFROMLONG(DRR_TARGET);
706
707 case UM_EXPAND:
708 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
709 if (!dcd)
710 Runtime_Error(pszSrcFile, __LINE__, NULL);
711 else {
712 BOOL tempsusp = dcd->suspendview;
713
714 dcd->suspendview = TRUE;
715 ExpandAll(dcd->hwndCnr,
716 (SHORT1FROMMP(mp1) == IDM_EXPAND), (PCNRITEM) mp2);
717 DosSleep(1); // Fixes tree epansion (dir text and icons all placed on
718 // the same line as the drive) failure on startup using RWS
719 dcd->suspendview = (USHORT) tempsusp;
720 PostMsg(dcd->hwndCnr, UM_FILTER, MPVOID, MPVOID);
721 }
722 return 0;
723
724 case UM_UPDATERECORDLIST:
725 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
726 if (!dcd || !mp1)
727 Runtime_Error(pszSrcFile, __LINE__, NULL);
728 else {
729 INT numentries = 0;
730 CHAR **list = (CHAR **) mp1;
731
732 while (list[numentries])
733 numentries++;
734 if (numentries)
735 UpdateCnrList(dcd->hwndCnr, list, numentries, TRUE, dcd);
736 }
737 return 0;
738
739 case UM_SETUP:
740# ifdef FORTIFY
741 Fortify_EnterScope();
742# endif
743 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
744 if (!dcd)
745 Runtime_Error(pszSrcFile, __LINE__, NULL);
746 else {
747# ifdef FORTIFY
748 Fortify_BecomeOwner(dcd);
749# endif
750 dcd->hwndObject = hwnd;
751 if (ParentIsDesktop(hwnd, dcd->hwndParent))
752 DosSleep(100); //05 Aug 07 GKY 250
753 }
754 return 0;
755
756 case UM_RESCAN2:
757 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
758 if (!dcd)
759 Runtime_Error(pszSrcFile, __LINE__, NULL);
760 // Bypass if not running integrated (i.e if vtree)
761 else if (hwndStatus &&
762 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
763 CHAR s[CCHMAXPATH * 2];
764 PCNRITEM pci = (PCNRITEM) mp1;
765 FSALLOCATE fsa;
766 struct
767 {
768 ULONG serial;
769 CHAR volumelength;
770 CHAR volumelabel[CCHMAXPATH];
771 }
772 volser;
773 CHAR tb[64];
774 CHAR szFree[64];
775 CNRINFO cnri;
776 CHAR FileSystem[CCHMAXPATH * 2];
777 CHAR szTmpLabel[CCHMAXPATH];
778 ULONG type;
779
780 strcpy(s, GetPString(IDS_TREETEXT));
781 memset(&cnri, 0, sizeof(CNRINFO));
782 cnri.cb = sizeof(CNRINFO);
783 WinSendMsg(dcd->hwndCnr,
784 CM_QUERYCNRINFO,
785 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
786 if (cnri.cRecords) {
787 sprintf(s, GetPString(IDS_NUMDRIVESTEXT), cnri.cRecords);
788 if (pci && (INT) pci != -1 && pci->pszFileName) { //fixme? will try checking pci->pszFileName instead of the pointer
789 if (!(driveflags[toupper(*pci->pszFileName) - 'A'] &
790 DRIVE_REMOVABLE) ||
791 driveserial[toupper(*pci->pszFileName) - 'A'] != -1) {
792 memset(&volser, 0, sizeof(volser));
793 DosError(FERR_DISABLEHARDERR);
794 if (!DosQueryFSInfo(toupper(*pci->pszFileName) - '@',
795 FSIL_VOLSER,
796 &volser,
797 (ULONG) sizeof(volser)) &&
798 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
799 DosError(FERR_DISABLEHARDERR);
800 if (!DosQueryFSInfo(toupper(*pci->pszFileName) - '@',
801 FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
802 CommaFmtULL(tb, sizeof(tb),
803 (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit *
804 fsa.cbSector), 'M');
805 sprintf(szFree, " %s %s", tb, GetPString(IDS_FREETEXT));
806 }
807 else
808 *szFree = 0;
809 //Show information on status line not shown in the tree container
810 driveserial[toupper(*pci->pszFileName) - 'A'] = volser.serial;
811 if (CheckDrive(toupper(*pci->pszFileName), FileSystem, &type) == -1 ||
812 fShowFSTypeInTree)
813 strcpy(FileSystem, NullStr);
814 if (fShowDriveLabelInTree)
815 strcpy(szTmpLabel, NullStr);
816 else
817 strcpy(szTmpLabel, volser.volumelabel);
818 if (fSplitStatus) {
819 CHAR temp[CCHMAXPATH] = " [";
820
821 strcat(temp, s);
822 strcat(temp, "]");
823 sprintf(s,
824 GetPString(fShowFSTypeInTree ? IDS_TREESTATUSSTART1TEXT :
825 fShowDriveLabelInTree ? IDS_TREESTATUSSTART2TEXT :
826 IDS_TREESTATUSSTARTTEXT), toupper(*pci->pszFileName),
827 FileSystem, szTmpLabel, volser.serial, szFree);
828 strcat(s, temp);
829 }
830 else {
831 strcat(s, " [");
832 sprintf(&s[strlen(s)],
833 GetPString(fShowFSTypeInTree ? IDS_TREESTATUSSTART1TEXT :
834 fShowDriveLabelInTree ? IDS_TREESTATUSSTART2TEXT :
835 IDS_TREESTATUSSTARTTEXT), toupper(*pci->pszFileName),
836 FileSystem, szTmpLabel, volser.serial, szFree);
837 strcat(s, "]");
838 }
839 if (!fMoreButtons) {
840 if (*dcd->mask.szMask ||
841 (dcd->mask.attrFile != ALLATTRS ||
842 ((fFilesInTree ||
843 (driveflags[toupper(*pci->pszFileName)] &
844 DRIVE_INCLUDEFILES)) ?
845 dcd->mask.antiattr :
846 (dcd->mask.antiattr &&
847 dcd->mask.antiattr != FILE_DIRECTORY)))) {
848 sprintf(&s[strlen(s)],
849 " (%s)",
850 (*dcd->mask.szMask) ?
851 dcd->mask.szMask : GetPString(IDS_ATTRTEXT));
852 }
853 }
854 }
855 }
856 else {
857 // find root record and strip it
858 pci = FindParentRecord(dcd->hwndCnr, pci);
859 driveserial[toupper(*pci->pszFileName) - 'A'] = -1;
860 UnFlesh(dcd->hwndCnr, pci);
861 }
862 }
863 }
864 // 21 Sep 09 SHL fixme to know why checking again - focus change?
865 if (dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent))
866 WinSetWindowText(hwndStatus, s);
867 }
868 return 0;
869
870 case UM_RESCAN:
871 // populate container
872 DosWaitEventSem(hevTreeCnrScanComplete, SEM_INDEFINITE_WAIT);
873 DosResetEventSem(hevTreeCnrScanComplete, &ulScanPostCnt);
874 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
875 if (!dcd)
876 Runtime_Error(pszSrcFile, __LINE__, NULL);
877 else {
878 RemoveCnrItems(dcd->hwndCnr, NULL, 0, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
879 WinSendMsg(dcd->hwndCnr,
880 CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(-1));
881 WinSendMsg(dcd->hwndCnr,
882 CM_SCROLLWINDOW,
883 MPFROMSHORT(CMA_HORIZONTAL), MPFROMLONG(-1));
884 FillTreeCnr(dcd->hwndCnr, dcd->hwndParent);
885 if (fOkayMinimize) {
886 PostMsg(dcd->hwndCnr, UM_MINIMIZE, MPVOID, MPVOID);
887 fOkayMinimize = FALSE;
888 }
889 WinSendMsg(dcd->hwndCnr,
890 CM_INVALIDATERECORD,
891 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
892 PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
893 }
894 return 0;
895
896 case UM_COMMAND:
897 if (mp1) {
898
899 LISTINFO *li = (LISTINFO *) mp1;
900
901 switch (li->type) {
902 case IDM_DOITYOURSELF:
903 case IDM_APPENDTOCLIP:
904 case IDM_SAVETOCLIP:
905 case IDM_ARCHIVE:
906 case IDM_VIEW:
907 case IDM_EDIT:
908 case IDM_OBJECT:
909 case IDM_SHADOW:
910 case IDM_SHADOW2:
911 case IDM_PRINT:
912 case IDM_ATTRS:
913 case IDM_DELETE:
914 case IDM_PERMDELETE:
915 if (li->type == IDM_DELETE)
916 ignorereadonly = FALSE;
917 if (PostMsg(hwnd, UM_MASSACTION, mp1, mp2))
918 return (MRESULT) TRUE;
919 default:
920 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
921 return (MRESULT) TRUE;
922 }
923 }
924 return 0;
925
926 case UM_MASSACTION:
927 if (mp1) {
928
929 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
930 if (!dcd)
931 Runtime_Error(pszSrcFile, __LINE__, NULL);
932 else {
933 WORKER *wk;
934# ifdef FORTIFY
935 Fortify_EnterScope();
936# endif
937 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
938 if (!wk)
939 FreeListInfo((LISTINFO *) mp1);
940 else {
941 wk->size = sizeof(WORKER);
942 wk->hwndCnr = dcd->hwndCnr;
943 wk->hwndParent = dcd->hwndParent;
944 wk->hwndFrame = dcd->hwndFrame;
945 wk->hwndClient = dcd->hwndClient;
946 wk->li = (LISTINFO *) mp1;
947 strcpy(wk->directory, dcd->directory);
948 if (xbeginthread(MassAction,
949 122880,
950 wk,
951 pszSrcFile,
952 __LINE__) == -1)
953 {
954 free(wk);
955 FreeListInfo((LISTINFO *) mp1);
956 }
957 }
958# ifdef FORTIFY
959 Fortify_LeaveScope();
960# endif
961 }
962 }
963 return 0;
964
965 case UM_ACTION:
966# ifdef FORTIFY
967 Fortify_EnterScope();
968# endif
969 if (mp1) {
970# ifdef FORTIFY
971 Fortify_BecomeOwner(mp1);
972# endif
973 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
974 if (!dcd)
975 Runtime_Error(pszSrcFile, __LINE__, NULL);
976 else {
977 WORKER *wk;
978 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
979 if (!wk)
980 FreeListInfo((LISTINFO *) mp1);
981 else {
982 wk->size = sizeof(WORKER);
983 wk->hwndCnr = dcd->hwndCnr;
984 wk->hwndParent = dcd->hwndParent;
985 wk->hwndFrame = dcd->hwndFrame;
986 wk->hwndClient = dcd->hwndClient;
987 wk->li = (LISTINFO *) mp1;
988 strcpy(wk->directory, dcd->directory);
989 if (xbeginthread(Action,
990 122880,
991 wk,
992 pszSrcFile,
993 __LINE__) == -1)
994 {
995 free(wk);
996 FreeListInfo((LISTINFO *) mp1);
997 }
998 }
999 }
1000 }
1001# ifdef FORTIFY
1002 Fortify_LeaveScope();
1003# endif
1004 return 0;
1005
1006 case WM_CLOSE:
1007 WinDestroyWindow(hwnd);
1008 break;
1009
1010 case WM_DESTROY:
1011 hwndTree = (HWND) 0;
1012 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1013 if (dcd) {
1014 WinSendMsg(dcd->hwndCnr,
1015 UM_CLOSE, MPFROMLONG(dcd->dontclose != FALSE), MPVOID);
1016 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); // 13 Apr 10 SHL Set NULL before freeing dcd
1017 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
1018 free(dcd);
1019 DosReleaseMutexSem(hmtxFiltering);
1020# ifdef FORTIFY
1021 Fortify_LeaveScope();
1022# endif
1023 }
1024 DosPostEventSem(CompactSem);
1025 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
1026 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
1027 break;
1028 }
1029 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1030}
1031
1032MRESULT EXPENTRY TreeCnrWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1033{
1034 static APPNOTIFY *apphead = NULL, *apptail = NULL;
1035 DIRCNRDATA *dcd = INSTDATA(hwnd);
1036 PCNRITEM pci;
1037
1038 switch (msg) {
1039 case DM_PRINTOBJECT:
1040 return MRFROMLONG(DRR_TARGET);
1041
1042 case DM_DISCARDOBJECT:
1043 if (dcd)
1044 return WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1045 else
1046 return MRFROMLONG(DRR_TARGET);
1047
1048 case WM_CHAR:
1049 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1050 if (SHORT1FROMMP(mp1) & KC_KEYUP)
1051 return (MRESULT) TRUE;
1052 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
1053 switch (SHORT2FROMMP(mp2)) {
1054 case VK_INSERT:
1055 if ((shiftstate & KC_CTRL) == KC_CTRL)
1056 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_MKDIR, 0), MPVOID);
1057 break;
1058 case VK_DELETE:
1059 if ((shiftstate & KC_CTRL) == KC_CTRL)
1060 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_PERMDELETE, 0), MPVOID);
1061 else if ((shiftstate & KC_SHIFT) == KC_SHIFT)
1062 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_SAVETOCLIP, 0), MPVOID);
1063 else
1064 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
1065 break;
1066 } // switch
1067 }
1068
1069 if (SearchContainer(hwnd, msg, mp1, mp2))
1070 return (MRESULT)TRUE; // Avoid default handler
1071
1072 break; // Let default handler see key
1073
1074 case WM_MOUSEMOVE:
1075 case WM_BUTTON1UP:
1076 case WM_BUTTON2UP:
1077 case WM_BUTTON3UP:
1078 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1079 break;
1080
1081 case UM_TIMER:
1082 if (dcd && dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent) &&
1083 hwndStatus2) {
1084 FILEFINDBUF3L ffb;
1085 ULONG nm = 1;
1086 HDIR hdir = HDIR_CREATE;
1087
1088 if (*SwapperDat) {
1089 if (!xDosFindFirst(SwapperDat,
1090 &hdir,
1091 FILE_NORMAL | FILE_HIDDEN |
1092 FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
1093 &ffb, sizeof(ffb), &nm, FIL_STANDARDL)) {
1094 CHAR tb[39], tm[39], tpm[39], s[163];
1095 ULONG amem;
1096
1097 priority_bumped();
1098 DosFindClose(hdir);
1099 if (!DosQuerySysInfo(QSV_TOTAVAILMEM,
1100 QSV_TOTAVAILMEM,
1101 (PVOID) & amem, sizeof(amem))) {
1102 CommaFmtULL(tpm, sizeof(tpm), amem, 'M');
1103 }
1104 else
1105 *tpm = 0;
1106 if (!Dos16MemAvail(&amem))
1107 CommaFmtULL(tm, sizeof(tm), amem, 'M');
1108 else
1109 *tm = 0;
1110 CommaFmtULL(tb, sizeof(tb), ffb.cbFile, 'M');
1111 sprintf(s, " %s %s%s%s%s%s",
1112 GetPString(IDS_SWAPFILETEXT),
1113 tb,
1114 *tm ? GetPString(IDS_TREEMEMTEXT) : NullStr,
1115 tm, *tpm ? "/" : NullStr, tpm);
1116 WinSetWindowText(hwndStatus2, s);
1117 }
1118 else
1119 WinSetWindowText(hwndStatus2, NullStr);
1120 }
1121 else
1122 WinSetWindowText(hwndStatus2, NullStr);
1123 }
1124 // 13 Jul 09 SHL fixme to make sense
1125 if (msg == UM_TIMER)
1126 return 0;
1127 break;
1128
1129 case WM_PRESPARAMCHANGED:
1130 PresParamChanged(hwnd, PCSZ_TREECNR, mp1, mp2);
1131 break;
1132
1133 case UM_FILESMENU:
1134 {
1135 HWND menuHwnd = (HWND) 0;
1136 FSALLOCATE fsa;
1137
1138 pci = (PCNRITEM) CurrentRecord(hwnd);
1139 if (pci && (INT) pci != -1) {
1140 if (IsRoot(pci->pszFileName) || !DosQueryFSInfo(toupper(*pci->pszFileName) - '@',
1141 FSIL_ALLOC, &fsa,
1142 sizeof(FSALLOCATE)))
1143 menuHwnd = CheckMenu(hwndMainMenu, &TreeMenu, TREE_POPUP);
1144 else {
1145 menuHwnd = CheckMenu(hwndMainMenu, &DirMenu, DIR_POPUP);
1146// WinEnableMenuItem(DirMenu,
1147// IDM_TREE,
1148// FALSE);
1149 }
1150 if (!(pci->attrFile & FILE_DIRECTORY))
1151 menuHwnd = CheckMenu(hwndMainMenu, &FileMenu, FILE_POPUP);
1152 }
1153 return MRFROMLONG(menuHwnd);
1154 }
1155
1156 case UM_COMPARE:
1157 if (dcd && mp1 && mp2) {
1158
1159 COMPARE *cmp;
1160 CHAR *leftdir = (CHAR *)mp1, *rightdir = (CHAR *)mp2;
1161
1162 if (!IsFile(leftdir) && !IsFile(rightdir)) {
1163 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
1164 if (cmp) {
1165 cmp->size = sizeof(COMPARE);
1166 strcpy(cmp->leftdir, leftdir);
1167 strcpy(cmp->rightdir, rightdir);
1168 cmp->hwndParent = dcd->hwndParent;
1169 cmp->dcd.hwndParent = dcd->hwndParent;
1170 WinDlgBox(HWND_DESKTOP,
1171 HWND_DESKTOP,
1172 CompareDlgProc, FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
1173 }
1174 }
1175 }
1176 return 0;
1177
1178 case UM_UPDATERECORDLIST:
1179 if (dcd && mp1)
1180 WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1181 return 0;
1182
1183 case UM_UPDATERECORD:
1184 if (dcd && mp1) {
1185 CHAR *filename;
1186 filename = mp1;
1187 if (filename) {
1188 UpdateCnrRecord(hwnd, filename, TRUE, dcd);
1189 }
1190 }
1191 return 0;
1192
1193 case WM_SETFOCUS:
1194 if (dcd && hwndStatus && mp2) {
1195 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1196 if (hwndMain)
1197 PostMsg(hwndMain, UM_ADVISEFOCUS, MPFROMLONG(dcd->hwndFrame), MPVOID);
1198 }
1199 break;
1200
1201 case UM_RESCAN:
1202
1203 if (dcd && dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
1204 // put name of our window on status line
1205
1206 PCNRITEM pci = NULL;
1207 CHAR str[CCHMAXPATH + 6];
1208
1209 if (fAutoView && hwndMain) {
1210 pci = WinSendMsg(hwnd,
1211 CM_QUERYRECORDEMPHASIS,
1212 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1213 if (pci && (INT) pci != -1 && fComments &&
1214 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW))
1215 WinSendMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName), MPVOID);
1216 else
1217 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1218 }
1219 if (!fAutoView || !hwndMain)
1220 pci = (PCNRITEM) WinSendMsg(hwnd,
1221 CM_QUERYRECORDEMPHASIS,
1222 MPFROMLONG(CMA_FIRST),
1223 MPFROMSHORT(CRA_CURSORED));
1224 if ((INT) pci == -1)
1225 pci = NULL;
1226 if (pci) {
1227 if (*(ULONG *) realappname == FM3UL) {
1228 sprintf(str, "%s %s", GetPString(IDS_DTTEXT), pci->pszFileName);
1229 WinSetWindowText(dcd->hwndFrame, str);
1230 WinSetWindowText(WinWindowFromID(dcd->hwndFrame, FID_TITLEBAR),
1231 str);
1232 }
1233 else
1234 WinSetWindowText(WinWindowFromID(dcd->hwndFrame,
1235 MAIN_STATUS), pci->pszFileName);
1236 if (fMoreButtons && hwndName) {
1237 CHAR szDate[DATE_BUF_BYTES];
1238
1239 DateFormat(szDate, pci->date);
1240 WinSetWindowText(hwndName, pci->pszFileName);
1241 sprintf(str, "%s %02u%s%02u%s%02u", szDate,
1242 pci->time.hours, TimeSeparator,
1243 pci->time.minutes, TimeSeparator, pci->time.seconds);
1244 WinSetWindowText(hwndDate, str);
1245 WinSetWindowText(hwndAttr, pci->pszDispAttr);
1246 }
1247 }
1248 PostMsg(dcd->hwndObject, UM_RESCAN2, MPFROMP(pci), MPVOID);
1249 if (hwndStatus2)
1250 PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID);
1251 }
1252 return 0;
1253
1254 case UM_SETUP2:
1255 {
1256 PCNRITEM pci = (PCNRITEM) mp1;
1257
1258 if (pci)
1259 NotifyError(pci->pszFileName, (ULONG) mp2);
1260 }
1261 return 0;
1262
1263 case UM_SETUP:
1264# ifdef FORTIFY
1265 // Balance WM_DESTROY
1266 Fortify_EnterScope();
1267# endif
1268
1269 if (!dcd) {
1270 Runtime_Error(pszSrcFile, __LINE__, NULL);
1271 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1272 return 0;
1273 }
1274 else {
1275 if (!dcd->hwndObject) {
1276 // first time through -- set things up
1277 CNRINFO cnri;
1278
1279# ifdef FORTIFY
1280 Fortify_EnterScope();
1281# endif
1282
1283 RestorePresParams(hwnd, PCSZ_TREECNR);
1284 memset(&cnri, 0, sizeof(CNRINFO));
1285 cnri.cb = sizeof(CNRINFO);
1286 WinSendMsg(hwnd,
1287 CM_QUERYCNRINFO,
1288 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1289 cnri.cyLineSpacing = 0;
1290 cnri.cxTreeIndent = 12;
1291 cnri.pSortRecord = (PVOID) SortTreeCnr;
1292 cnri.flWindowAttr &= (~(CV_NAME | CV_DETAIL | CV_TEXT));
1293 cnri.flWindowAttr |= (CV_TREE | CA_TREELINE | CV_ICON | CV_MINI);
1294 {
1295 ULONG size = sizeof(ULONG);
1296
1297 PrfQueryProfileData(fmprof,
1298 appname,
1299 "TreeflWindowAttr",
1300 (PVOID) & cnri.flWindowAttr, &size);
1301 size = sizeof(MASK);
1302 *dcd->mask.prompt = 0;
1303 if (!*dcd->mask.szMask && !dcd->mask.attrFile) {
1304 if (PrfQueryProfileSize(fmprof,
1305 appname, "TreeFilter", &size) && size) {
1306 PrfQueryProfileData(fmprof,
1307 appname, "TreeFilter", &dcd->mask, &size);
1308 SetMask(NULL, &dcd->mask);
1309 }
1310 else
1311 dcd->mask.attrFile = (FILE_READONLY | FILE_NORMAL |
1312 FILE_ARCHIVED | FILE_DIRECTORY |
1313 FILE_HIDDEN | FILE_SYSTEM);
1314 }
1315 dcd->mask.attrFile |= FILE_DIRECTORY;
1316 }
1317 cnri.flWindowAttr &= (~(CA_MIXEDTARGETEMPH | CA_ORDEREDTARGETEMPH));
1318 cnri.flWindowAttr |= CV_FLOW;
1319 dcd->flWindowAttr = cnri.flWindowAttr;
1320 WinSendMsg(hwnd,
1321 CM_SETCNRINFO,
1322 MPFROMP(&cnri),
1323 MPFROMLONG(CMA_FLWINDOWATTR | CMA_LINESPACING |
1324 CMA_CXTREEINDENT | CMA_PSORTRECORD));
1325 if (xbeginthread(MakeObjWin,
1326 327680,
1327 dcd,
1328 pszSrcFile,
1329 __LINE__) == -1)
1330 {
1331 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1332 }
1333 else
1334 DosSleep(1);
1335# ifdef FORTIFY
1336 Fortify_LeaveScope();
1337# endif
1338 }
1339 }
1340 return 0;
1341
1342 case WM_BUTTON3CLICK:
1343 case WM_CHORD:
1344 {
1345 PCNRITEM pci = NULL;
1346 QUERYRECFROMRECT pqr;
1347 NOTIFYRECORDENTER nr;
1348 BOOL tbool = fDCOpens;
1349 RECTL rectl;
1350 POINTL ptl;
1351
1352 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1353 if (msg == WM_CHORD) {
1354 if (!WinQueryPointerPos(HWND_DESKTOP, &ptl))
1355 break;
1356 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1);
1357 }
1358 else {
1359 ptl.x = SHORT1FROMMP(mp1);
1360 ptl.y = SHORT2FROMMP(mp1);
1361 }
1362 memset(&rectl, 0, sizeof(rectl));
1363 memset(&pqr, 0, sizeof(pqr));
1364 pqr.cb = sizeof(pqr);
1365 pqr.rect.xLeft = ptl.x - 1;
1366 pqr.rect.xRight = ptl.x + 1;
1367 pqr.rect.yTop = ptl.y + 1;
1368 pqr.rect.yBottom = ptl.y - 1;
1369 pqr.fsSearch = CMA_PARTIAL;
1370 pci = (PCNRITEM) WinSendMsg(hwnd,
1371 CM_QUERYRECORDFROMRECT,
1372 MPFROMLONG(CMA_FIRST), MPFROMP(&pqr));
1373 if (!pci || (INT) pci == -1)
1374 break; //Probable B3 click on white space
1375 else {
1376 memset(&nr, 0, sizeof(nr));
1377 nr.hwndCnr = hwnd;
1378 nr.pRecord = (PRECORDCORE) pci;
1379 fDCOpens = TRUE;
1380 WinSendMsg(hwnd,
1381 WM_CONTROL,
1382 MPFROM2SHORT(WinQueryWindowUShort(hwnd,
1383 QWS_ID),
1384 CN_ENTER), MPFROMP(&nr));
1385 PostMsg(hwnd, UM_RESTOREDC, MPFROMLONG(tbool), MPVOID);
1386 }
1387 }
1388 break;
1389
1390 case UM_RESTOREDC:
1391 fDCOpens = (BOOL) mp1;
1392 return 0;
1393
1394 case WM_CONTROL:
1395 DosError(FERR_DISABLEHARDERR);
1396 if (dcd) {
1397 switch (SHORT2FROMMP(mp1)) {
1398 case CN_BEGINEDIT:
1399 case CN_REALLOCPSZ:
1400 case CN_ENDEDIT:
1401 {
1402 MRESULT mre;
1403
1404 mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
1405 if (mre != (MRESULT) - 1)
1406 return mre;
1407 }
1408 break;
1409
1410 case CN_DRAGLEAVE:
1411 if (mp2) {
1412
1413 PDRAGINFO pDInfo;
1414
1415 // fixme to know why - seems superfluous
1416 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
1417 DrgAccessDraginfo(pDInfo);
1418 DrgFreeDraginfo(pDInfo);
1419 }
1420 return 0;
1421
1422 case CN_DROPHELP:
1423 if (mp2) {
1424
1425 PDRAGINFO pDInfo;
1426 PCNRITEM pci;
1427 ULONG numitems;
1428 USHORT usOperation;
1429
1430 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
1431 pDInfo = (PDRAGINFO) ((PCNRDRAGINFO) mp2)->pDragInfo;
1432 if (!DrgAccessDraginfo(pDInfo)) {
1433 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
1434 GetPString(IDS_DROPERRORTEXT));
1435 }
1436 else {
1437 numitems = DrgQueryDragitemCount(pDInfo);
1438 usOperation = pDInfo->usOperation;
1439 if (usOperation == DO_DEFAULT)
1440 usOperation = fCopyDefault ? DO_COPY : DO_MOVE;
1441 FreeDragInfoData(hwnd, pDInfo);
1442 saymsg(MB_ENTER | MB_ICONASTERISK,
1443 hwnd,
1444 GetPString(IDS_DROPHELPHDRTEXT),
1445 GetPString(IDS_DROPHELPTEXT),
1446 numitems,
1447 &"s"[numitems == 1L],
1448 pci ? NullStr : GetPString(IDS_NOTEXT),
1449 pci ? NullStr : " ",
1450 pci ? pci->pszFileName : NullStr,
1451 pci ? " " : NullStr,
1452 GetPString((usOperation == DO_MOVE) ?
1453 IDS_MOVETEXT :
1454 (usOperation == DO_LINK) ?
1455 IDS_LINKTEXT : IDS_COPYTEXT));
1456 }
1457 }
1458 return 0;
1459
1460 case CN_DRAGAFTER:
1461 case CN_DRAGOVER:
1462 if (mp2) {
1463
1464 PDRAGITEM pDItem;
1465 PDRAGINFO pDInfo;
1466 PCNRITEM pci;
1467 USHORT uso;
1468
1469 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
1470 if (!DrgAccessDraginfo(pDInfo)) {
1471 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
1472 PCSZ_DRGACCESSDRAGINFO);
1473 return (MRFROM2SHORT(DOR_NODROP, 0)); // Drop not valid
1474 }
1475 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
1476 if ((INT) pci == -1)
1477 pci = NULL;
1478 if (pci && (pci->flags & (RECFLAGS_ENV | RECFLAGS_NODROP))) {
1479 DrgFreeDraginfo(pDInfo);
1480 return MRFROM2SHORT(DOR_NODROP, 0);
1481 }
1482 if (!WinIsWindowEnabled(dcd->hwndFrame)) {
1483 DrgFreeDraginfo(pDInfo);
1484 return MRFROM2SHORT(DOR_NODROP, 0);
1485 }
1486 if (pci) {
1487 uso = pDInfo->usOperation;
1488 if (uso == DO_DEFAULT)
1489 uso = (fCopyDefault) ? DO_COPY : DO_MOVE;
1490 if (!(pci->attrFile & FILE_DIRECTORY)) {
1491 if (uso != DO_LINK && uso != DO_COPY && uso != DO_MOVE) {
1492 DrgFreeDraginfo(pDInfo);
1493 return (MRFROM2SHORT(DOR_NODROP, 0));
1494 }
1495 if (uso != DO_LINK &&
1496 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
1497 DRIVE_NOTWRITEABLE)) {
1498
1499 ARC_TYPE *info;
1500
1501 if (!fQuickArcFind &&
1502 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
1503 DRIVE_SLOW))
1504 info = find_type(pci->pszFileName, NULL);
1505 else
1506 info = quick_find_type(pci->pszFileName, NULL);
1507 if (!info || ((uso == DO_MOVE && !info->move) ||
1508 (uso == DO_COPY && !info->create))) {
1509 DrgFreeDraginfo(pDInfo);
1510 return (MRFROM2SHORT(DOR_NODROP, 0));
1511 }
1512 }
1513 }
1514 }
1515 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
1516 0); // Index to DRAGITEM
1517 if (DrgVerifyRMF(pDItem, // Check valid rendering
1518 (CHAR *) DRM_OS2FILE, // mechanisms and data
1519 NULL) || DrgVerifyRMF(pDItem,
1520 (CHAR *) DRM_FM2ARCMEMBER,
1521 (CHAR *) DRF_FM2ARCHIVE)) { // formats
1522 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
1523 if (!pci || (INT) pci == -1)
1524 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1525 if (driveflags[toupper(*pci->pszFileName) - 'A'] &
1526 DRIVE_NOTWRITEABLE)
1527 return MRFROM2SHORT(DOR_DROP, DO_LINK);
1528 if (toupper(*pci->pszFileName) < 'C')
1529 return MRFROM2SHORT(DOR_DROP, DO_COPY);
1530 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
1531 ((fCopyDefault) ? DO_COPY : DO_MOVE));
1532 }
1533 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
1534 }
1535 return MRFROM2SHORT(DOR_NODROP, 0); // Drop not valid
1536
1537 case CN_INITDRAG:
1538 {
1539 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
1540 PCNRITEM pci;
1541
1542 if (!pcd) {
1543 Runtime_Error(pszSrcFile, __LINE__, NULL);
1544 break;
1545 }
1546 else {
1547 pci = (PCNRITEM) pcd->pRecord;
1548 if (!pci || (INT) pci == -1) {
1549 Runtime_Error(pszSrcFile, __LINE__, NULL);
1550 break;
1551 }
1552 if (pci->flags & (RECFLAGS_ENV | RECFLAGS_NODRAG)) {
1553 Runtime_Error(pszSrcFile, __LINE__, "drag not allowed");
1554 break;
1555 }
1556 if (hwndStatus2) {
1557 WinSetWindowText(hwndStatus2, (IsRoot(pci->pszFileName)) ?
1558 (CHAR *) GetPString(IDS_DRAGROOTTEXT) :
1559 (pci->attrFile & FILE_DIRECTORY) ?
1560 (CHAR *) GetPString(IDS_DRAGDIRTEXT) :
1561 (CHAR *) GetPString(IDS_DRAGFILETEXT));
1562 }
1563 DoFileDrag(hwnd, dcd->hwndObject, mp2, NULL, NULL, TRUE);
1564 if (hwndStatus2) {
1565 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1566 }
1567 }
1568 }
1569 return 0;
1570
1571 case CN_DROP:
1572 {
1573 LISTINFO *li;
1574 ULONG action = UM_ACTION;
1575
1576 li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
1577 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
1578 if (li) {
1579 if (!*li->targetpath) {
1580 if (li->list[0])
1581 PMMkDir(dcd->hwndParent, li->list[0], FALSE);
1582 FreeListInfo(li);
1583 return 0;
1584 }
1585 if (li->list && li->list[0] && IsRoot(li->list[0]))
1586 li->type = DO_LINK;
1587 else if (fDragndropDlg && (!*li->arcname || !li->info)) {
1588
1589 CHECKLIST cl;
1590
1591 memset(&cl, 0, sizeof(cl));
1592 cl.size = sizeof(cl);
1593 cl.flags = li->type;
1594 cl.list = li->list;
1595 cl.cmd = li->type;
1596 cl.prompt = li->targetpath;
1597 li->type = WinDlgBox(HWND_DESKTOP,
1598 dcd->hwndParent,
1599 DropListProc,
1600 FM3ModHandle, DND_FRAME, MPFROMP(&cl));
1601 if (li->type == DID_ERROR)
1602 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,
1603 GetPString(IDS_DRAGDROPDIALOGTEXT));
1604 if (!li->type) {
1605 FreeListInfo(li);
1606 return 0;
1607 }
1608 li->list = cl.list;
1609 if (!li->list || !li->list[0]) {
1610 FreeListInfo(li);
1611 return 0;
1612 }
1613 }
1614 switch (li->type) {
1615 case DO_LINK:
1616 if (fLinkSetsIcon) {
1617 li->type = IDM_SETICON;
1618 action = UM_MASSACTION;
1619 }
1620 else
1621 li->type = IDM_COMPARE;
1622 break;
1623 case DND_EXTRACT:
1624 if (*li->targetpath && !IsFile(li->targetpath))
1625 li->type = IDM_EXTRACT;
1626 break;
1627 case DND_MOVE:
1628 li->type = IDM_MOVE;
1629 if (*li->targetpath && IsFile(li->targetpath) == 1) {
1630 action = UM_MASSACTION;
1631 li->type = IDM_ARCHIVEM;
1632 }
1633 break;
1634 case DND_WILDMOVE:
1635 li->type = IDM_WILDMOVE;
1636 if (*li->targetpath && IsFile(li->targetpath) == 1) {
1637 action = UM_MASSACTION;
1638 li->type = IDM_ARCHIVEM;
1639 }
1640 break;
1641 case DND_OBJECT:
1642 li->type = IDM_OBJECT;
1643 action = UM_MASSACTION;
1644 break;
1645 case DND_SHADOW:
1646 li->type = IDM_SHADOW;
1647 action = UM_MASSACTION;
1648 break;
1649 case DND_COMPARE:
1650 li->type = IDM_COMPARE;
1651 break;
1652 case DND_SETICON:
1653 action = UM_MASSACTION;
1654 li->type = IDM_SETICON;
1655 break;
1656 case DND_COPY:
1657 li->type = IDM_COPY;
1658 if (*li->targetpath && IsFile(li->targetpath) == 1) {
1659 action = UM_MASSACTION;
1660 li->type = IDM_ARCHIVE;
1661 }
1662 break;
1663 case DND_WILDCOPY:
1664 li->type = IDM_WILDCOPY;
1665 if (*li->targetpath && IsFile(li->targetpath) == 1) {
1666 action = UM_MASSACTION;
1667 li->type = IDM_ARCHIVE;
1668 }
1669 break;
1670 default:
1671 if (*li->arcname && li->info) {
1672 action = UM_MASSACTION;
1673 li->type = (li->type == DO_MOVE) ?
1674 IDM_FAKEEXTRACTM : IDM_FAKEEXTRACT;
1675 }
1676 else if (*li->targetpath && IsFile(li->targetpath) == 1) {
1677 action = UM_MASSACTION;
1678 li->type = (li->type == DO_MOVE) ? IDM_ARCHIVEM : IDM_ARCHIVE;
1679 }
1680 else
1681 li->type = (li->type == DO_MOVE) ? IDM_MOVE : IDM_COPY;
1682 break;
1683 }
1684 if (!li->list || !li->list[0])
1685 FreeListInfo(li);
1686 else if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID))
1687 FreeListInfo(li);
1688 else {
1689
1690 USHORT usop = 0;
1691
1692 switch (li->type) {
1693 case IDM_COPY:
1694 case IDM_WILDCOPY:
1695 usop = DO_COPY;
1696 break;
1697 case IDM_MOVE:
1698 case IDM_WILDMOVE:
1699 case IDM_ARCHIVEM:
1700 usop = DO_MOVE;
1701 break;
1702 }
1703 if (usop)
1704 return MRFROM2SHORT(DOR_DROP, usop);
1705 }
1706 }
1707 }
1708 return 0;
1709
1710 case CN_EMPHASIS:
1711 if (!fDummy) {
1712
1713 PNOTIFYRECORDEMPHASIS pre = mp2;
1714
1715 if (pre->fEmphasisMask & CRA_SELECTED) {
1716 if (pre->pRecord->flRecordAttr & CRA_SELECTED) {
1717 if (((PCNRITEM) (pre->pRecord))->attrFile & FILE_DIRECTORY) {
1718 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1719 if (fFollowTree &&
1720 !(driveflags
1721 [toupper(*((PCNRITEM) pre->pRecord)->pszFileName) -
1722 'A'] & DRIVE_INVALID)) {
1723 if (!LastDir && !ParentIsDesktop(hwnd, dcd->hwndParent))
1724 LastDir = FindDirCnr(dcd->hwndParent);
1725 if (LastDir) {
1726
1727 NOTIFYRECORDENTER pri;
1728 BOOL tbool = fDCOpens;
1729
1730 fDCOpens = FALSE;
1731 memset(&pri, 0, sizeof(pri));
1732 pri.hwndCnr = hwnd;
1733 pri.fKey = FALSE;
1734 pri.pRecord = pre->pRecord;
1735 WinSendMsg(hwnd,
1736 WM_CONTROL,
1737 MPFROM2SHORT(SHORT1FROMMP(mp1),
1738 CN_ENTER), MPFROMP(&pri));
1739 fDCOpens = tbool;
1740 }
1741 }
1742 if (*(ULONG *) realappname != FM3UL)
1743 WinSetWindowText(WinWindowFromID(dcd->hwndFrame,
1744 MAIN_STATUS),
1745 ((PCNRITEM) (pre->pRecord))->pszFileName);
1746 }
1747 }
1748 }
1749 }
1750 break;
1751
1752 case CN_CONTEXTMENU:
1753 {
1754 PCNRITEM pci = (PCNRITEM) mp2;
1755 BOOL wasFollowing;
1756
1757 //DosEnterCritSec(); //GKY 11-28-08
1758 wasFollowing = fFollowTree;
1759 fFollowTree = FALSE;
1760 //DosExitCritSec();
1761 if (pci && (INT) pci != -1 && !(pci->flags & RECFLAGS_ENV)) {
1762 WinSendMsg(hwnd,
1763 CM_SETRECORDEMPHASIS,
1764 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
1765 MarkAll(hwnd, FALSE, FALSE, TRUE);
1766 if (!(pci->attrFile & FILE_DIRECTORY))
1767 dcd->hwndLastMenu = CheckMenu(hwndMainMenu, &FileMenu, FILE_POPUP);
1768 else if (!IsRoot(pci->pszFileName))
1769 dcd->hwndLastMenu = CheckMenu(hwndMainMenu, &DirMenu, DIR_POPUP);
1770 else
1771 dcd->hwndLastMenu = CheckMenu(hwndMainMenu, &TreeMenu, TREE_POPUP);
1772 }
1773 else {
1774 dcd->hwndLastMenu = CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP);
1775 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
1776 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1777 MPFROM2SHORT(TRUE, CRA_SOURCE));
1778 dcd->cnremphasized = TRUE;
1779 }
1780 }
1781 if (dcd->hwndLastMenu) {
1782 if (dcd->hwndLastMenu == DirMenu)
1783 WinEnableMenuItem(DirMenu, IDM_TREE, FALSE);
1784 if (dcd->hwndLastMenu == TreeCnrMenu) {
1785 if (dcd->flWindowAttr & CV_MINI)
1786 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
1787 }
1788 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
1789 if (dcd->cnremphasized) {
1790 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1791 MPFROM2SHORT(FALSE, CRA_SOURCE));
1792 dcd->cnremphasized = FALSE;
1793 }
1794 if (dcd->hwndLastMenu != TreeCnrMenu)
1795 MarkAll(hwnd, TRUE, FALSE, TRUE);
1796 }
1797 }
1798 //DosEnterCritSec(); //GKY 11-28-08
1799 fFollowTree = wasFollowing;
1800 //DosExitCritSec();
1801 }
1802 break;
1803
1804 case CN_ENTER:
1805 if (mp2) {
1806 PCNRITEM pci = (PCNRITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
1807
1808 PostMsg(hwnd, UM_ENTER, MPFROMP(pci), MPVOID);
1809 }
1810 break;
1811
1812 case CN_COLLAPSETREE:
1813 case CN_EXPANDTREE:
1814 {
1815 PCNRITEM pci = (PCNRITEM) mp2;
1816
1817 if (pci && (INT) pci != -1 && !(pci->flags & RECFLAGS_ENV)) {
1818 if (driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_REMOVABLE) {
1819
1820 struct
1821 {
1822 ULONG serial;
1823 CHAR volumelength;
1824 CHAR volumelabel[CCHMAXPATH];
1825 }
1826 volser;
1827
1828 memset(&volser, 0, sizeof(volser));
1829 DosError(FERR_DISABLEHARDERR);
1830 if (!DosQueryFSInfo(toupper(*pci->pszFileName) - '@',
1831 FSIL_VOLSER, &volser,
1832 (ULONG) sizeof(volser))) {
1833 if (SHORT2FROMMP(mp1) == CN_COLLAPSETREE &&
1834 !volser.serial ||
1835 driveserial[toupper(*pci->pszFileName) - 'A'] !=
1836 volser.serial)
1837 UnFlesh(hwnd, pci);
1838 if (SHORT2FROMMP(mp1) != CN_COLLAPSETREE ||
1839 (!volser.serial ||
1840 driveserial[toupper(*pci->pszFileName) - 'A'] !=
1841 volser.serial)) {
1842 if (SHORT2FROMMP(mp1) == CN_EXPANDTREE && Flesh(hwnd, pci)
1843 &&!dcd->suspendview && fTopDir) {
1844 PostMsg(hwnd, UM_TOPDIR, MPFROMP(pci), MPVOID);
1845 //DbgMsg(pszSrcFile, __LINE__, "UM_TOPDIR %p pci %p", hwnd, pci);
1846 }
1847 }
1848 driveserial[toupper(*pci->pszFileName) - 'A'] = volser.serial;
1849 }
1850 else {
1851 driveserial[toupper(*pci->pszFileName) - 'A'] = -1;
1852 UnFlesh(hwnd, pci);
1853 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1854 if (!fAlertBeepOff)
1855 DosBeep(250, 100);
1856 }
1857 }
1858 else if (SHORT2FROMMP(mp1) == CN_EXPANDTREE) {
1859 if (Flesh(hwnd, pci) && !dcd->suspendview && fTopDir){
1860 PostMsg(hwnd, UM_TOPDIR, MPFROMP(pci), MPVOID);
1861 //DbgMsg(pszSrcFile, __LINE__, "UM_TOPDIR %p pci %p", hwnd, pci);
1862 }
1863 }
1864 if (SHORT2FROMMP(mp1) == CN_EXPANDTREE && !dcd->suspendview){
1865 WinSendMsg(hwnd, UM_FILTER, MPVOID, MPVOID);
1866 //DbgMsg(pszSrcFile, __LINE__, "UM_FILTER %p pci %p", hwnd, pci);
1867 }
1868 }
1869 }
1870 break;
1871 } // switch WM_CONTROL
1872 }
1873 return 0;
1874
1875 case UM_ACTION:
1876 if (mp1) {
1877
1878 LISTINFO *li = mp1;
1879 ULONG action = (ULONG) mp2;
1880
1881 if (!li->list || !li->list[0] ||
1882 !PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID))
1883 FreeListInfo(li);
1884 }
1885 return 0;
1886
1887 case UM_SHOWME:
1888 if (mp1 && dcd) {
1889 CHAR *dir = xstrdup((CHAR *)mp1, pszSrcFile, __LINE__);
1890
1891 if (dir) {
1892 if (!PostMsg(dcd->hwndObject, UM_SHOWME, MPFROMP(dir), MPVOID))
1893 free(dir);
1894 }
1895 }
1896 return 0;
1897
1898 case UM_TOPDIR:
1899 if (mp1) {
1900
1901 PCNRITEM pci = (PCNRITEM) mp1;
1902
1903 ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
1904 }
1905 return 0;
1906
1907 case UM_ENTER:
1908 {
1909 FILEFINDBUF3 ffb;
1910 HDIR hDir = HDIR_CREATE;
1911 ULONG nm = 1;
1912 APIRET status;
1913 BOOL IsOk = FALSE;
1914 ULONG ulDriveNum, ulDriveMap;
1915 PCNRITEM pciP, pciL, pci;
1916 ULONG fl = SWP_ACTIVATE;
1917 INT x;
1918
1919 DosRequestMutexSem(hmtxScanning, SEM_INDEFINITE_WAIT);
1920 DosQueryEventSem(hevTreeCnrScanComplete, &ulScanPostCnt);
1921 if (ulScanPostCnt < 1)
1922 return 0;
1923 DosResetEventSem(hevTreeCnrScanComplete, &ulScanPostCnt);
1924 if (fFollowTree)
1925 fl = 0;
1926 SetShiftState();
1927 pci = (PCNRITEM) mp1;
1928 if (pci &&
1929 (INT) pci != -1 &&
1930 !(pci->rc.flRecordAttr & CRA_INUSE) &&
1931 !(pci->flags & RECFLAGS_ENV) && IsFullName(pci->pszFileName)) {
1932 x = (INT) (toupper(*pci->pszFileName) - 'A');
1933 if (driveflags[x] & DRIVE_INVALID) {
1934 if (!fAlertBeepOff)
1935 DosBeep(50, 100);
1936 if (hwndStatus)
1937 WinSetWindowText(hwndStatus, (CHAR *) GetPString(IDS_RESCANSUGTEXT));
1938 DosPostEventSem(hevTreeCnrScanComplete);
1939 return 0;
1940 }
1941 DosError(FERR_DISABLEHARDERR);
1942 if (!DosQCurDisk(&ulDriveNum, &ulDriveMap)) {
1943 if (!(ulDriveMap & 1 << x)) {
1944 pciL = pciP = pci;
1945 for (;;) {
1946 pciP = WinSendMsg(hwnd,
1947 CM_QUERYRECORD,
1948 MPFROMP(pciL),
1949 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
1950 if (pciP && (INT) pciP != -1)
1951 pciL = pciP;
1952 else {
1953 pciP = pciL;
1954 break;
1955 }
1956 } // for
1957 RemoveCnrItems(hwnd, pciP, 1, CMA_FREE | CMA_INVALIDATE);
1958 DosPostEventSem(hevTreeCnrScanComplete);
1959 return 0;
1960 }
1961 }
1962 if (driveflags[x] & (DRIVE_REMOVABLE | DRIVE_NOPRESCAN)) {
1963
1964 struct
1965 {
1966 ULONG serial;
1967 CHAR volumelength;
1968 CHAR volumelabel[CCHMAXPATH];
1969 }
1970 volser;
1971 CHAR FileSystem[CCHMAXPATH];
1972 CHAR szBuf[CCHMAXPATH];
1973
1974 pciL = pciP = pci;
1975 for (;;) {
1976 pciP = WinSendMsg(hwnd,
1977 CM_QUERYRECORD,
1978 MPFROMP(pciL),
1979 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
1980 if (pciP && (INT) pciP != -1)
1981 pciL = pciP;
1982 else {
1983 pciP = pciL;
1984 break;
1985 }
1986 }
1987 if ((driveflags[x] & DRIVE_NOPRESCAN) || (toupper(*pci->pszFileName) > 'B' &&
1988 !(driveflags[x] & DRIVE_CDROM))) {
1989 DriveFlagsOne(x, FileSystem, &volser);
1990 SelectDriveIcon(pciP);
1991 if (hwndMain)
1992 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1993 }
1994 memset(&volser, 0, sizeof(volser));
1995 DosError(FERR_DISABLEHARDERR);
1996 status = DosQueryFSInfo(toupper(*pci->pszFileName) - '@',
1997 FSIL_VOLSER, &volser,
1998 (ULONG) sizeof(volser));
1999 if (!status) {
2000 if (!volser.serial || driveserial[x] != volser.serial) {
2001 Flesh(hwnd, pciP);
2002 driveserial[x] = volser.serial;
2003 }
2004 pciL = WinSendMsg(hwnd,
2005 CM_QUERYRECORD,
2006 MPFROMP(pciP),
2007 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
2008 if (!pciL) {
2009 Flesh(hwnd, pciP);
2010 }
2011 if ((fShowFSTypeInTree || fShowDriveLabelInTree) &&
2012 strlen(pciP->pszFileName) < 4) {
2013 strcpy(szBuf, pciP->pszFileName);
2014 strcat(szBuf, " [");
2015 strcat(szBuf, fShowFSTypeInTree ? FileSystem : volser.volumelabel);
2016 strcat(szBuf, "]");
2017 pciP->pszDisplayName = xstrdup(szBuf, pszSrcFile, __LINE__);
2018 pciP->rc.pszIcon = pciP->pszDisplayName;
2019 }
2020 WinSendMsg(hwnd,
2021 CM_INVALIDATERECORD,
2022 MPFROMP(&pciP),
2023 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2024 }
2025 else {
2026 driveserial[x] = -1;
2027 UnFlesh(hwnd, pci);
2028 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2029 PostMsg(hwnd, UM_SETUP2, MPFROMP(pci), MPFROMLONG(status));
2030 DosPostEventSem(hevTreeCnrScanComplete);
2031 return 0;
2032 }
2033 }
2034 status = 0;
2035 IsOk = (IsRoot(pci->pszFileName) &&
2036 IsValidDrive(toupper(*pci->pszFileName)));
2037 if (!IsOk) {
2038 DosError(FERR_DISABLEHARDERR);
2039 status = DosFindFirst(pci->pszFileName, &hDir,
2040 FILE_NORMAL | FILE_DIRECTORY |
2041 FILE_ARCHIVED | FILE_READONLY |
2042 FILE_HIDDEN | FILE_SYSTEM,
2043 &ffb, sizeof(ffb), &nm, FIL_STANDARD);
2044 priority_bumped();
2045 }
2046 if (!status) {
2047 if (!IsOk)
2048 DosFindClose(hDir);
2049 if (IsOk || (ffb.attrFile & FILE_DIRECTORY)) {
2050 if ((shiftstate & (KC_CTRL | KC_ALT)) == (KC_CTRL | KC_ALT)) {
2051 PostMsg(hwnd,
2052 WM_COMMAND, MPFROM2SHORT(IDM_SHOWALLFILES, 0), MPVOID);
2053 DosPostEventSem(hevTreeCnrScanComplete);
2054 return 0;
2055 }
2056 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT)) {
2057 OpenObject(pci->pszFileName, Settings, dcd->hwndFrame);
2058 DosPostEventSem(hevTreeCnrScanComplete);
2059 return 0;
2060 }
2061 if (!(shiftstate & (KC_CTRL | KC_SHIFT))) {
2062 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
2063 if (FindDirCnrByName(pci->pszFileName, TRUE)) {
2064 DosPostEventSem(hevTreeCnrScanComplete);
2065 return 0;
2066 }
2067 }
2068 }
2069 if ((shiftstate & KC_CTRL) ||
2070 (!(shiftstate & KC_SHIFT) &&
2071 ParentIsDesktop(hwnd, dcd->hwndParent) && fVTreeOpensWPS)) {
2072
2073 ULONG size = sizeof(ULONG), flWindowAttr = CV_ICON;
2074 CHAR s[33];
2075
2076 strcpy(s, PCSZ_ICON);
2077 PrfQueryProfileData(fmprof,
2078 appname,
2079 "DirflWindowAttr",
2080 (PVOID) & flWindowAttr, &size);
2081 if (flWindowAttr & CV_DETAIL) {
2082 if (IsRoot(pci->pszFileName))
2083 strcpy(s, PCSZ_TREE);
2084 else
2085 strcpy(s, Details);
2086 }
2087 OpenObject(pci->pszFileName, s, dcd->hwndFrame);
2088 DosPostEventSem(hevTreeCnrScanComplete);
2089 return 0;
2090 }
2091 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
2092 !fDCOpens && !LastDir && !(shiftstate & KC_SHIFT))
2093 LastDir = FindDirCnr(dcd->hwndParent);
2094 if (LastDir && !fDCOpens && !(shiftstate & KC_SHIFT)) {
2095 WinSendMsg(LastDir,
2096 UM_SETDIR, MPFROMP(pci->pszFileName), MPVOID);
2097 WinSetWindowPos(WinQueryWindow(WinQueryWindow(LastDir,
2098 QW_PARENT),
2099 QW_PARENT),
2100 HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | fl);
2101 }
2102 else
2103 OpenDirCnr(hwnd,
2104 dcd->hwndParent,
2105 dcd->hwndFrame, FALSE, pci->pszFileName);
2106 }
2107 else {
2108 if (!(driveflags[x] & DRIVE_INCLUDEFILES))
2109 RemoveCnrItems(hwnd, pci, 1, CMA_FREE | CMA_INVALIDATE);
2110 else {
2111
2112 SWP swp;
2113
2114 WinQueryWindowPos(dcd->hwndFrame, &swp);
2115 DefaultViewKeys(hwnd,
2116 dcd->hwndFrame,
2117 dcd->hwndParent, &swp, pci->pszFileName);
2118 }
2119 }
2120 }
2121 else {
2122 if (!IsRoot(pci->pszFileName)) {
2123 NotifyError(pci->pszFileName, status);
2124 RemoveCnrItems(hwnd, pci, 1, CMA_FREE | CMA_INVALIDATE);
2125 }
2126 }
2127 }
2128 else if (!pci)
2129 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_MKDIR, 0), MPVOID);
2130 if (fFollowTree)
2131 WinSetFocus(HWND_DESKTOP, hwnd);
2132 DosPostEventSem(hevTreeCnrScanComplete);
2133 }
2134 return 0;
2135
2136 case WM_MENUEND:
2137 if (dcd) {
2138
2139 HWND hwndMenu = (HWND) mp2;
2140
2141 if (hwndMenu == TreeCnrMenu || hwndMenu == TreeMenu ||
2142 hwndMenu == DirMenu) {
2143 MarkAll(hwnd, TRUE, FALSE, TRUE);
2144 if (dcd->cnremphasized) {
2145 WinSendMsg(hwnd,
2146 CM_SETRECORDEMPHASIS,
2147 MPVOID, MPFROM2SHORT(FALSE, CRA_SOURCE));
2148 dcd->cnremphasized = FALSE;
2149 }
2150 }
2151 }
2152 break;
2153
2154 case UM_OPENWINDOWFORME:
2155 if (dcd) {
2156 if (mp1 && !IsFile((CHAR *)mp1))
2157 OpenDirCnr(hwnd, dcd->hwndParent, dcd->hwndFrame, FALSE, (char *)mp1);
2158 }
2159 return 0;
2160
2161 case MM_PORTHOLEINIT:
2162 if (dcd) {
2163 switch (SHORT1FROMMP(mp1)) {
2164 case 0:
2165 case 1:
2166 {
2167 ULONG wmsg;
2168
2169 wmsg = ((SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU);
2170 PortholeInit((HWND) WinSendMsg(dcd->hwndClient,
2171 wmsg, MPVOID, MPVOID), mp1, mp2);
2172 }
2173 break;
2174 }
2175 }
2176 break;
2177
2178 case UM_INITMENU:
2179 case WM_INITMENU:
2180 if (dcd) {
2181
2182 switch (SHORT1FROMMP(mp1)) {
2183 case IDM_FILESMENU:
2184 {
2185 PCNRITEM pci;
2186
2187 pci = (PCNRITEM) CurrentRecord(hwnd);
2188 if (pci && (INT) pci != -1) {
2189 BOOL rdy;
2190 BOOL writeable;
2191 BOOL removable;
2192 BOOL local;
2193 BOOL underenv;
2194 CHAR chDrvU;
2195 CHAR szDrv[CCHMAXPATH];
2196
2197 strcpy(szDrv, pci->pszFileName);
2198 chDrvU = *pci->pszFileName;
2199 chDrvU = toupper(chDrvU);
2200 MakeValidDir(szDrv);
2201 rdy = *szDrv == chDrvU; // Drive not ready if MakeValidDir changes drive letter
2202 removable = rdy
2203 && (driveflags[chDrvU - 'A'] & DRIVE_REMOVABLE) != 0;
2204 writeable = rdy
2205 && !(driveflags[chDrvU - 'A'] & DRIVE_NOTWRITEABLE);
2206 local = rdy && (!(driveflags[chDrvU - 'A'] & (DRIVE_REMOTE | DRIVE_VIRTUAL)));
2207 underenv = (pci->flags & RECFLAGS_UNDERENV) != 0;
2208
2209 CopyPresParams((HWND) mp2, hwndMainMenu);
2210 WinEnableMenuItem((HWND) mp2, IDM_INFO, rdy);
2211
2212 WinEnableMenuItem((HWND) mp2, IDM_ATTRS, writeable);
2213 WinEnableMenuItem((HWND) mp2, IDM_EAS, writeable);
2214 WinEnableMenuItem((HWND) mp2, IDM_SUBJECT, writeable);
2215 WinEnableMenuItem((HWND) mp2, IDM_DRVFLAGS, 1); // fixme to allow if not ready
2216
2217 WinEnableMenuItem((HWND) mp2, IDM_ARCHIVE, rdy);
2218
2219 WinEnableMenuItem((HWND) mp2, IDM_UPDATE, !underenv);
2220 WinEnableMenuItem((HWND) mp2, IDM_EXPANDSUBMENU, !underenv);
2221 WinEnableMenuItem((HWND) mp2, IDM_EXPAND, !underenv);
2222 WinEnableMenuItem((HWND) mp2, IDM_COLLAPSE, !underenv);
2223
2224 WinEnableMenuItem((HWND) mp2, IDM_SIZES, rdy);
2225 WinEnableMenuItem((HWND) mp2, IDM_MKDIR, writeable);
2226 WinEnableMenuItem((HWND) mp2, IDM_SHOWALLFILES, rdy);
2227 WinEnableMenuItem((HWND) mp2, IDM_UNDELETE, writeable);
2228
2229 WinEnableMenuItem((HWND) mp2, IDM_CHKDSK, writeable && local);
2230 WinEnableMenuItem((HWND) mp2, IDM_FORMAT, writeable && local);
2231 WinEnableMenuItem((HWND) mp2, IDM_OPTIMIZE, writeable && local);
2232 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONSMENU, local);
2233 WinEnableMenuItem((HWND) mp2, IDM_PARTITION, fMiniLVM);
2234 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONDF, fDFSee);
2235 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONLVMG, fLVMGui);
2236 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONLVM, fLVM);
2237 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONFD, fFDisk);
2238
2239 WinEnableMenuItem((HWND) mp2, IDM_DETACH, !local);
2240
2241 WinEnableMenuItem((HWND) mp2, IDM_EJECT, removable);
2242
2243 WinEnableMenuItem((HWND) mp2, IDM_LOCK, removable);
2244 WinEnableMenuItem((HWND) mp2, IDM_UNLOCK, removable);
2245
2246 WinEnableMenuItem((HWND) mp2, IDM_DELETE, !underenv && writeable);
2247 WinEnableMenuItem((HWND) mp2, IDM_PERMDELETE, !underenv
2248 && writeable);
2249 WinEnableMenuItem((HWND) mp2, IDM_DELETESUBMENU, !underenv
2250 && writeable);
2251 WinEnableMenuItem((HWND) mp2, IDM_MOVEMENU, !underenv
2252 && writeable);
2253 WinEnableMenuItem((HWND) mp2, IDM_RENAME, !underenv && writeable);
2254
2255 }
2256 }
2257 break;
2258
2259 case IDM_VIEWSMENU:
2260 WinCheckMenuItem((HWND) mp2,
2261 IDM_MINIICONS, ((dcd->flWindowAttr & CV_MINI) != 0));
2262 CopyPresParams((HWND) mp2, hwndMainMenu);
2263 WinEnableMenuItem((HWND) mp2, IDM_RESELECT, FALSE);
2264 WinEnableMenuItem((HWND) mp2, IDM_PARTITION, fMiniLVM);
2265 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONDF, fDFSee);
2266 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONLVMG, fLVMGui);
2267 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONLVM, fLVM);
2268 WinEnableMenuItem((HWND) mp2, IDM_PARTITIONFD, fFDisk);
2269 break;
2270
2271 case IDM_COMMANDSMENU:
2272 SetupCommandMenu((HWND) mp2, hwnd);
2273 CopyPresParams((HWND) mp2, hwndMainMenu);
2274 break;
2275
2276 case IDM_SORTSUBMENU:
2277 SetSortChecks((HWND) mp2, TreesortFlags);
2278 CopyPresParams((HWND) mp2, hwndMainMenu);
2279 break;
2280
2281 case IDM_WINDOWSMENU:
2282 SetupWinList((HWND) mp2,
2283 (hwndMain) ? hwndMain : (HWND) 0, dcd->hwndFrame);
2284 CopyPresParams((HWND) mp2, hwndMainMenu);
2285 break;
2286 }
2287 dcd->hwndLastMenu = (HWND) mp2;
2288 }
2289 if (msg == WM_INITMENU)
2290 break;
2291 return 0;
2292
2293 case UM_COMMAND:
2294 if (!mp1)
2295 Runtime_Error(pszSrcFile, __LINE__, NULL);
2296 else {
2297 if (!dcd) {
2298 Runtime_Error(pszSrcFile, __LINE__, NULL);
2299 FreeListInfo((LISTINFO *) mp1);
2300 }
2301 else {
2302 if (!PostMsg(dcd->hwndObject, UM_COMMAND, mp1, mp2)) {
2303 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
2304 FreeListInfo((LISTINFO *) mp1);
2305 }
2306 else
2307 return (MRESULT) TRUE;
2308 }
2309 }
2310 return 0;
2311
2312 case UM_LOADFILE:
2313 if (dcd && mp2) {
2314
2315 HWND hwnd;
2316
2317 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2318 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2319 (CHAR *)mp2, dcd->hwndFrame);
2320 else
2321 hwnd = StartMLEEditor(dcd->hwndParent,
2322 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
2323 free((CHAR *)mp2);
2324 return MRFROMLONG(hwnd);
2325 }
2326 return 0;
2327
2328 case UM_FIXCNRMLE:
2329 case UM_FIXEDITNAME:
2330 return CommonCnrProc(hwnd, msg, mp1, mp2);
2331
2332 case UM_NOTIFY:
2333 if (mp2)
2334 Notify((CHAR *)mp2);
2335 return 0;
2336
2337 case UM_FILTER:
2338 if (dcd) {
2339
2340 BOOL tempsusp = dcd->suspendview;
2341
2342 if (mp1)
2343 SetMask((CHAR *)mp1, &dcd->mask);
2344
2345 dcd->suspendview = TRUE;
2346 dcd->mask.attrFile |= FILE_DIRECTORY;
2347 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2348 dcd->suspendview = (USHORT) tempsusp;
2349 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2350 //DbgMsg(pszSrcFile, __LINE__, "UM_RESCAN %p pci %s", hwnd, (CHAR *) mp1);
2351 }
2352 return 0;
2353
2354 case UM_DRIVECMD:
2355 if (mp1) {
2356 ShowTreeRec(hwnd, (CHAR *)mp1, FALSE, TRUE);
2357 PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_UPDATE, 0), MPVOID);
2358 }
2359 return 0;
2360
2361 case WM_APPTERMINATENOTIFY:
2362 {
2363 APPNOTIFY *info;
2364 PCNRITEM pci;
2365 CHAR s[] = " :\\";
2366
2367 if (!mp2) {
2368 if (hwndMain)
2369 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
2370 }
2371 info = apphead;
2372 while (info) {
2373 if (info->happ == (HAPP) mp1) {
2374 *s = info->device;
2375 pci = FindCnrRecord(hwnd, s, NULL, FALSE, FALSE, TRUE);
2376 if (pci && (INT) pci != -1) {
2377 INT x = info->device - 'A';
2378 CHAR FileSystem[CCHMAXPATH];
2379
2380 driveserial[x] = -1;
2381 DriveFlagsOne(x, FileSystem, NULL);
2382 if (driveflags[x] &
2383 (DRIVE_INVALID | DRIVE_IGNORE))
2384 RemoveCnrItems(hwnd, pci, 1, CMA_FREE);
2385 else
2386 Flesh(hwnd, pci);
2387 }
2388 if (info->prev)
2389 info->prev->next = info->next;
2390 if (info->next)
2391 info->next->prev = info->prev;
2392 if (apphead == info)
2393 apphead = info->next;
2394 if (apptail == info)
2395 apptail = info->prev;
2396 free(info);
2397 break;
2398 }
2399 info = info->next;
2400 }
2401 }
2402 break;
2403
2404 case WM_COMMAND:
2405 DosError(FERR_DISABLEHARDERR);
2406 if (dcd) {
2407 if (SwitchCommand(dcd->hwndLastMenu, SHORT1FROMMP(mp1)))
2408 return 0;
2409 switch (SHORT1FROMMP(mp1)) {
2410 case IDM_SETTARGET:
2411 SetTargetDir(hwnd, FALSE, NULL);
2412 break;
2413
2414 case IDM_DETACH:
2415 {
2416 CHAR d[3] = " :";
2417 PCNRITEM pci;
2418 PROGDETAILS pgd;
2419 CHAR params[368], *p;
2420 HAPP happ;
2421
2422 pci = (PCNRITEM) CurrentRecord(hwnd);
2423 if (pci && (INT) pci != -1 && isalpha(*pci->pszFileName)) {
2424 *d = toupper(*pci->pszFileName);
2425 p = GetCmdSpec(FALSE);
2426 memset(&pgd, 0, sizeof(pgd));
2427 pgd.Length = sizeof(pgd);
2428 pgd.progt.progc = PROG_WINDOWABLEVIO;
2429 pgd.progt.fbVisible = SHE_VISIBLE;
2430 pgd.pszTitle = (PSZ)GetPString(IDS_DETACHREQUESTTEXT);
2431 pgd.pszExecutable = p;
2432 pgd.pszParameters = params;
2433 pgd.pszStartupDir = NULL;
2434 pgd.pszIcon = NULL;
2435 pgd.pszEnvironment = NULL;
2436 pgd.swpInitial.hwndInsertBehind = HWND_TOP;
2437 pgd.swpInitial.hwnd = hwnd;
2438 pgd.swpInitial.fl = SWP_SHOW | SWP_ACTIVATE;
2439 sprintf(params, "/C NET USE %s /D", d);
2440 happ = WinStartApp(hwnd, &pgd, pgd.pszParameters,
2441 NULL, SAF_MAXIMIZED);
2442 if (!happ) {
2443 saymsg(MB_CANCEL | MB_ICONEXCLAMATION, hwnd,
2444 GetPString(IDS_ERRORTEXT),
2445 GetPString(IDS_CANTSTARTTEXT), p, params);
2446 }
2447 else {
2448 APPNOTIFY *info;
2449
2450 info = xmallocz(sizeof(APPNOTIFY), pszSrcFile, __LINE__);
2451 if (info) {
2452 info->happ = happ;
2453 info->device = *d;
2454 if (!apphead)
2455 apphead = info;
2456 else {
2457 apptail->next = info;
2458 info->prev = apptail;
2459 }
2460 apptail = info;
2461 }
2462 PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
2463 }
2464 }
2465 }
2466 break;
2467
2468 case IDM_REMAP:
2469 WinDlgBox(HWND_DESKTOP, hwnd, RemapDlgProc,
2470 FM3ModHandle, MAP_FRAME, NULL);
2471 break;
2472
2473 case IDM_CONTEXTMENU:
2474 {
2475 PCNRITEM pci;
2476
2477 pci = (PCNRITEM) CurrentRecord(hwnd);
2478 PostMsg(hwnd, WM_CONTROL, MPFROM2SHORT(DIR_CNR, CN_CONTEXTMENU),
2479 MPFROMP(pci));
2480 }
2481 break;
2482
2483 case IDM_FINDINTREE:
2484 {
2485 PSZ pszTempDir;
2486 PCNRITEM pci;
2487
2488 pci = (PCNRITEM) CurrentRecord(hwnd);
2489 if (pci && (INT) pci != -1) {
2490 pszTempDir = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
2491 if (pszTempDir)
2492 MakeValidDir(pszTempDir);
2493 }
2494 else
2495 pszTempDir = xstrdup(pFM2SaveDirectory, pszSrcFile, __LINE__);
2496 if (pszTempDir) {
2497 if (WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
2498 WalkAllDlgProc,
2499 FM3ModHandle, WALK_FRAME, MPFROMP(pszTempDir))) {
2500 if (!WinSendMsg(hwnd, UM_SHOWME, MPFROMP(pszTempDir), MPFROMLONG(1)))
2501 free(pszTempDir);
2502 }
2503 else
2504 free(pszTempDir);
2505 }
2506 }
2507 break;
2508
2509 case IDM_BEGINEDIT:
2510 OpenEdit(hwnd);
2511 break;
2512
2513 case IDM_ENDEDIT:
2514 WinSendMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
2515 break;
2516
2517 case IDM_FILTER:
2518 {
2519 BOOL empty = FALSE;
2520 PCNRITEM pci;
2521
2522 pci = (PCNRITEM) CurrentRecord(hwnd);
2523 if (!*dcd->mask.szMask)
2524 empty = TRUE;
2525 dcd->mask.fIsTree = TRUE;
2526 *dcd->mask.prompt = 0;
2527 if (pci && (INT) pci != -1)
2528 dcd->mask.fFilesIncluded =
2529 ((driveflags[toupper(*pci->pszFileName) - 'A'] &
2530 DRIVE_INCLUDEFILES) != 0);
2531 else
2532 dcd->mask.fFilesIncluded = FALSE;
2533 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2534 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask)))
2535 WinSendMsg(hwnd, UM_FILTER, MPVOID, MPVOID);
2536 else if (empty)
2537 *dcd->mask.szMask = 0;
2538 PrfWriteProfileData(fmprof, appname, "TreeFilter", &dcd->mask,
2539 sizeof(MASK));
2540 }
2541 break;
2542
2543 case IDM_SHOWSORT:
2544 QuickPopup(hwnd, dcd, CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP),
2545 IDM_SORTSUBMENU);
2546 break;
2547
2548 case IDM_SHOWSELECT:
2549 QuickPopup(hwnd, dcd, CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP),
2550 IDM_SELECTSUBMENU);
2551 break;
2552
2553 case IDM_TREECNRVIEWSETTINGS:
2554 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
2555 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_TREECNRVIEWSETTINGS), mp2);
2556 else {
2557 WinDlgBox(HWND_DESKTOP,
2558 hwnd,
2559 CfgDlgProc,
2560 FM3ModHandle,
2561 CFG_FRAME,
2562 MPFROMLONG(IDM_TREECNRVIEWSETTINGS));
2563 }
2564 break;
2565
2566 case IDM_WALKDIR:
2567 case IDM_OPENWALK:
2568 {
2569 CHAR newpath[CCHMAXPATH];
2570 PCNRITEM pci;
2571
2572 pci = (PCNRITEM) CurrentRecord(hwnd);
2573 if (pci && (INT) pci != -1) {
2574 strcpy(newpath, pci->pszFileName);
2575 MakeValidDir(newpath);
2576 }
2577 else
2578 strcpy(newpath, pFM2SaveDirectory);
2579 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkAllDlgProc,
2580 FM3ModHandle, WALK_FRAME,
2581 MPFROMP(newpath)) || !*newpath)
2582 break;
2583 WinSendMsg(hwnd, UM_OPENWINDOWFORME, MPFROMP(newpath), MPVOID);
2584 }
2585 break;
2586
2587 case IDM_HELP:
2588 if (hwndHelp) {
2589 if (!ParentIsDesktop(dcd->hwndFrame, dcd->hwndParent))
2590 PostMsg(dcd->hwndParent, UM_COMMAND, mp1, mp2);
2591 else
2592 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
2593 }
2594 break;
2595
2596 case IDM_PARTITION:
2597 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2598 NULL, NULL,
2599 "%s", PCSZ_MINILVMEXE);
2600 break;
2601
2602 case IDM_PARTITIONDF:
2603 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2604 NULL, NULL,
2605 "%s", PCSZ_DFSOS2EXE);
2606 break;
2607
2608 case IDM_PARTITIONLVMG:
2609 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2610 NULL, NULL,
2611 "%s", PCSZ_LVMGUICMD);
2612 break;
2613
2614 case IDM_PARTITIONLVM:
2615 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2616 NULL, NULL,
2617 "%s", PCSZ_LVMEXE);
2618 break;
2619
2620 case IDM_PARTITIONFD:
2621 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2622 NULL, NULL,
2623 "%s", PCSZ_FDISKPMEXE);
2624 break;
2625
2626 case IDM_REFRESHREMOVABLES:
2627 {
2628 PFN Rediscover_PRMs;
2629 HMODULE hmod = 0;
2630 APIRET rc;
2631 CHAR objerr[CCHMAXPATH];
2632
2633 rc = DosLoadModule(objerr, sizeof(objerr), "LVM", &hmod);
2634 if (!rc) {
2635 rc = DosQueryProcAddr(hmod, 70, NULL, &Rediscover_PRMs);
2636 if (!rc)
2637 Rediscover_PRMs(&rc);
2638 DosFreeModule(hmod);
2639 }
2640 if (!rc)
2641 PostMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
2642 break;
2643 }
2644
2645 case IDM_SORTNAME:
2646 case IDM_SORTFILENAME:
2647 case IDM_SORTSIZE:
2648 case IDM_SORTEASIZE:
2649 case IDM_SORTFIRST:
2650 case IDM_SORTLAST:
2651 case IDM_SORTLWDATE:
2652 case IDM_SORTLADATE:
2653 case IDM_SORTCRDATE:
2654 TreesortFlags &= (SORT_REVERSE | SORT_DIRSFIRST | SORT_DIRSLAST);
2655 case IDM_SORTDIRSFIRST:
2656 case IDM_SORTDIRSLAST:
2657 case IDM_SORTREVERSE:
2658 switch (SHORT1FROMMP(mp1)) {
2659 case IDM_SORTFILENAME:
2660 TreesortFlags |= SORT_FILENAME;
2661 break;
2662 case IDM_SORTSIZE:
2663 TreesortFlags |= SORT_SIZE;
2664 break;
2665 case IDM_SORTEASIZE:
2666 TreesortFlags |= SORT_EASIZE;
2667 break;
2668 case IDM_SORTFIRST:
2669 TreesortFlags |= SORT_FIRSTEXTENSION;
2670 break;
2671 case IDM_SORTLAST:
2672 TreesortFlags |= SORT_LASTEXTENSION;
2673 break;
2674 case IDM_SORTLWDATE:
2675 TreesortFlags |= SORT_LWDATE;
2676 break;
2677 case IDM_SORTLADATE:
2678 TreesortFlags |= SORT_LADATE;
2679 break;
2680 case IDM_SORTCRDATE:
2681 TreesortFlags |= SORT_CRDATE;
2682 break;
2683 case IDM_SORTDIRSFIRST:
2684 if (TreesortFlags & SORT_DIRSFIRST)
2685 TreesortFlags &= (~SORT_DIRSFIRST);
2686 else {
2687 TreesortFlags |= SORT_DIRSFIRST;
2688 TreesortFlags &= (~SORT_DIRSLAST);
2689 }
2690 break;
2691 case IDM_SORTDIRSLAST:
2692 if (TreesortFlags & SORT_DIRSLAST)
2693 TreesortFlags &= (~SORT_DIRSLAST);
2694 else {
2695 TreesortFlags |= SORT_DIRSLAST;
2696 TreesortFlags &= (~SORT_DIRSFIRST);
2697 }
2698 break;
2699 case IDM_SORTREVERSE:
2700 if (TreesortFlags & SORT_REVERSE)
2701 TreesortFlags &= (~SORT_REVERSE);
2702 else
2703 TreesortFlags |= SORT_REVERSE;
2704 break;
2705 }
2706 PrfWriteProfileData(fmprof, appname, "TreeSort", &TreesortFlags,
2707 sizeof(INT));
2708 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortTreeCnr), MPVOID);
2709 break;
2710
2711 case IDM_COLLECT:
2712 case IDM_GREP:
2713 if (!Collector) {
2714
2715 HWND hwndC;
2716 SWP swp;
2717
2718 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
2719 !fAutoTile &&
2720 (!fExternalCollector && *(ULONG *) realappname == FM3UL))
2721 GetNextWindowPos(dcd->hwndParent, &swp, NULL, NULL);
2722 hwndC = StartCollector((fExternalCollector ||
2723 *(ULONG *) realappname != FM3UL) ?
2724 HWND_DESKTOP : dcd->hwndParent, 4);
2725 if (hwndC) {
2726 if (!ParentIsDesktop(hwnd,
2727 dcd->hwndParent) &&
2728 !fAutoTile &&
2729 (!fExternalCollector && *(ULONG *) realappname == FM3UL))
2730 WinSetWindowPos(hwndC,
2731 HWND_TOP,
2732 swp.x,
2733 swp.y,
2734 swp.cx,
2735 swp.cy,
2736 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
2737 else if (!ParentIsDesktop(hwnd,
2738 dcd->hwndParent) &&
2739 fAutoTile && *(ULONG *) realappname == FM3UL)
2740 TileChildren(dcd->hwndParent, TRUE);
2741 }
2742 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
2743 DosSleep(100);//05 Aug 07 GKY 250
2744 }
2745 else
2746 StartCollector(dcd->hwndParent, 4);
2747 if (SHORT1FROMMP(mp1) == IDM_GREP) {
2748 PCNRITEM pci = NULL;
2749
2750 pci = WinSendMsg(hwnd,
2751 CM_QUERYRECORDEMPHASIS,
2752 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
2753 if (pci && (INT) pci != -1)
2754 PostMsg(Collector, WM_COMMAND,
2755 MPFROM2SHORT(UM_GREP, 0), MPFROMP(pci->pszFileName));
2756 else
2757 PostMsg(Collector, WM_COMMAND,
2758 MPFROM2SHORT(IDM_GREP, 0), MPVOID);
2759 }
2760 else
2761 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPVOID);
2762 break;
2763
2764 case IDM_COLLECTOR:
2765 DosSleep(32);//05 Aug 07 GKY 64
2766 {
2767 CHAR **list;
2768
2769 list = BuildList(hwnd);
2770 if (list) {
2771 if (Collector) {
2772 if (!PostMsg(Collector, WM_COMMAND,
2773 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
2774 FreeList(list);
2775 }
2776 else
2777 FreeList(list);
2778 }
2779 }
2780 break;
2781
2782 case IDM_COLLAPSEALL:
2783 WinSendMsg(hwnd, CM_COLLAPSETREE, MPVOID, MPVOID);
2784 break;
2785
2786 case IDM_COLLAPSE:
2787 case IDM_EXPAND:
2788 {
2789 PCNRITEM pci = NULL;
2790
2791 pci = (PCNRITEM) CurrentRecord(hwnd);
2792 if (pci && (INT) pci != -1) {
2793 if (pci->flags & RECFLAGS_UNDERENV)
2794 break;
2795 PostMsg(dcd->hwndObject, UM_EXPAND, mp1, MPFROMP(pci));
2796 }
2797 }
2798 break;
2799
2800 case IDM_UPDATE:
2801 {
2802 PCNRITEM pci = (PCNRITEM)CurrentRecord(hwnd);
2803 if (pci && (INT)pci != -1) {
2804 struct
2805 {
2806 ULONG serial;
2807 CHAR volumelength;
2808 CHAR volumelabel[CCHMAXPATH];
2809 }
2810 volser;
2811 INT x = toupper(*pci->pszFileName) - 'A';
2812 CHAR FileSystem[CCHMAXPATH], szBuf[CCHMAXPATH];
2813
2814 UINT driveflag = driveflags[x];
2815 if (pci->attrFile & FILE_DIRECTORY) {
2816 if (pci->flags & RECFLAGS_UNDERENV)
2817 break;
2818 DosRequestMutexSem(hmtxScanning, SEM_INDEFINITE_WAIT);
2819 DosResetEventSem(hevTreeCnrScanComplete, &ulScanPostCnt);
2820 UnFlesh(hwnd, pci);
2821 // Check if drive type might need update
2822 if ((driveflag & (DRIVE_INVALID | DRIVE_NOPRESCAN)) ||
2823 (~driveflag & DRIVE_NOPRESCAN && pci->rc.hptrIcon == hptrDunno)) {
2824 DriveFlagsOne(x, FileSystem, &volser);
2825 driveflag = driveflags[x];
2826 if (driveflag & DRIVE_INVALID)
2827 pci->rc.hptrIcon = hptrDunno;
2828 else if (strlen(pci->pszFileName) < 4) {
2829 SelectDriveIcon(pci);
2830 if (fShowFSTypeInTree || fShowDriveLabelInTree) {
2831 strcpy(szBuf, pci->pszFileName);
2832 strcat(szBuf, " [");
2833 strcat(szBuf, fShowFSTypeInTree ? FileSystem : volser.volumelabel);
2834 strcat(szBuf, "]");
2835 pci->pszDisplayName = xstrdup(szBuf, pszSrcFile, __LINE__);
2836 pci->rc.pszIcon = pci->pszDisplayName;
2837 }
2838 }
2839 WinSendMsg(hwnd,
2840 CM_INVALIDATERECORD,
2841 MPFROMP(&pci),
2842 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2843 if (hwndMain)
2844 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
2845 }
2846 if (~driveflag & DRIVE_INVALID)
2847 Flesh(hwnd, pci);
2848 DosPostEventSem(hevTreeCnrScanComplete);
2849 }
2850 }
2851 }
2852 break;
2853
2854 case IDM_RESCAN:
2855 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2856 break;
2857
2858 case IDM_RESORT:
2859 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortTreeCnr), MPVOID);
2860 break;
2861
2862 case IDM_TEXT:
2863 case IDM_MINIICONS:
2864 {
2865 CNRINFO cnri;
2866
2867 memset(&cnri, 0, sizeof(CNRINFO));
2868 cnri.cb = sizeof(CNRINFO);
2869 WinSendMsg(hwnd,
2870 CM_QUERYCNRINFO,
2871 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2872 if (SHORT1FROMMP(mp1) == IDM_MINIICONS) {
2873 if (cnri.flWindowAttr & CV_MINI)
2874 cnri.flWindowAttr &= (~CV_MINI);
2875 else
2876 cnri.flWindowAttr |= CV_MINI;
2877 }
2878 else {
2879 if (cnri.flWindowAttr & CV_TEXT) {
2880 cnri.flWindowAttr &= (~CV_TEXT);
2881 cnri.flWindowAttr |= CV_ICON;
2882 }
2883 else {
2884 cnri.flWindowAttr &= (~CV_ICON);
2885 cnri.flWindowAttr |= CV_TEXT;
2886 }
2887 }
2888 dcd->flWindowAttr = cnri.flWindowAttr;
2889 PrfWriteProfileData(fmprof,
2890 appname,
2891 "TreeflWindowAttr",
2892 &cnri.flWindowAttr, sizeof(ULONG));
2893 WinSendMsg(hwnd,
2894 CM_SETCNRINFO,
2895 MPFROMP(&cnri),
2896 MPFROMLONG(CMA_FLWINDOWATTR | CMA_TREEICON |
2897 CMA_SLTREEBITMAPORICON));
2898 }
2899 break;
2900
2901 case IDM_SIZES:
2902 case IDM_DRVFLAGS:
2903 case IDM_SHOWALLFILES:
2904 case IDM_UNDELETE:
2905 case IDM_OPTIMIZE:
2906 case IDM_CHKDSK:
2907 case IDM_FORMAT:
2908 case IDM_MKDIR:
2909 case IDM_LOCK:
2910 case IDM_UNLOCK:
2911 case IDM_EJECT:
2912 case IDM_CLOSETRAY:
2913 {
2914 PCNRITEM pci;
2915
2916 pci = (PCNRITEM) CurrentRecord(hwnd);
2917 if (pci && (INT) pci != -1)
2918 CommonDriveCmd(hwnd, pci->pszFileName, SHORT1FROMMP(mp1));
2919 }
2920 break;
2921
2922 case IDM_SAVETOLIST:
2923 WinDlgBox(HWND_DESKTOP,
2924 hwnd,
2925 SaveListDlgProc, FM3ModHandle, SAV_FRAME, MPFROMP(&hwnd));
2926 break;
2927
2928 case IDM_DELETE:
2929 case IDM_PERMDELETE:
2930 case IDM_MOVE:
2931 case IDM_WPSMOVE:
2932 case IDM_WILDMOVE:
2933 case IDM_RENAME:
2934 {
2935 PCNRITEM pci;
2936
2937 pci = (PCNRITEM) CurrentRecord(hwnd);
2938 if (pci && (INT) pci != -1) {
2939 if (pci->flags & RECFLAGS_UNDERENV)
2940 break;
2941 }
2942 }
2943 // else intentional fallthru
2944 case IDM_ATTRS:
2945 case IDM_INFO:
2946 case IDM_COPY:
2947 case IDM_WPSCOPY:
2948 case IDM_WILDCOPY:
2949 case IDM_DOITYOURSELF:
2950 case IDM_OPENWINDOW:
2951 case IDM_OPENSETTINGS:
2952 case IDM_OPENDEFAULT:
2953 case IDM_OPENICON:
2954 case IDM_OPENDETAILS:
2955 case IDM_OPENTREE:
2956 case IDM_SHADOW:
2957 case IDM_SHADOW2:
2958 case IDM_COMPARE:
2959 case IDM_VIEW:
2960 case IDM_VIEWTEXT:
2961 case IDM_VIEWBINARY:
2962 case IDM_EDIT:
2963 case IDM_EDITTEXT:
2964 case IDM_EDITBINARY:
2965 case IDM_EAS:
2966 case IDM_SUBJECT:
2967 case IDM_APPENDTOCLIP:
2968 case IDM_SAVETOCLIP:
2969 case IDM_ARCHIVE:
2970 case IDM_MCIPLAY:
2971 case IDM_UUDECODE:
2972 {
2973 LISTINFO *li;
2974 ULONG action = UM_ACTION;
2975# ifdef FORTIFY
2976 Fortify_EnterScope();
2977# endif
2978 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2979 if (li) {
2980 li->type = SHORT1FROMMP(mp1);
2981 li->hwnd = hwnd;
2982 li->list = BuildList(hwnd);
2983 if (!li->list || !li->list[0]) {
2984 free(li);
2985 break;
2986 }
2987 if (IsRoot(li->list[0])) {
2988 switch (SHORT1FROMMP(mp1)) {
2989 case IDM_MOVE:
2990 case IDM_COPY:
2991 case IDM_WILDCOPY:
2992 case IDM_WILDMOVE:
2993 case IDM_WPSMOVE:
2994 case IDM_WPSCOPY:
2995 case IDM_RENAME:
2996 case IDM_DELETE:
2997 case IDM_PERMDELETE:
2998 mp1 = MPFROM2SHORT(IDM_INFO, SHORT2FROMMP(mp1));
2999 li->type = IDM_INFO;
3000 }
3001 }
3002 switch (SHORT1FROMMP(mp1)) {
3003 case IDM_APPENDTOCLIP:
3004 case IDM_SAVETOCLIP:
3005 case IDM_ARCHIVE:
3006 case IDM_DELETE:
3007 case IDM_PERMDELETE:
3008 case IDM_ATTRS:
3009 case IDM_SHADOW:
3010 case IDM_SHADOW2:
3011 case IDM_DOITYOURSELF:
3012 case IDM_EAS:
3013 case IDM_VIEW:
3014 case IDM_VIEWTEXT:
3015 case IDM_VIEWBINARY:
3016 case IDM_EDIT:
3017 case IDM_EDITTEXT:
3018 case IDM_EDITBINARY:
3019 case IDM_MCIPLAY:
3020 action = UM_MASSACTION;
3021 }
3022 if (li->type == IDM_DELETE)
3023 ignorereadonly = FALSE;
3024 if (SHORT1FROMMP(mp1) == IDM_SHADOW ||
3025 SHORT1FROMMP(mp1) == IDM_SHADOW2)
3026 *li->targetpath = 0;
3027 if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID)) {
3028 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
3029 FreeListInfo(li);
3030 }
3031 }
3032# ifdef FORTIFY
3033 Fortify_LeaveScope();
3034# endif
3035 }
3036 break;
3037
3038 default:
3039 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
3040 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
3041
3042 INT x;
3043
3044 if (!cmdloaded)
3045 load_commands();
3046 x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
3047 if (x >= 0) {
3048 //x++;
3049 RunCommand(hwnd, x);
3050 if (fUnHilite)
3051 UnHilite(hwnd, TRUE, &dcd->lastselection, 0);
3052 }
3053 }
3054 break;
3055 }
3056 }
3057 return 0;
3058
3059 case WM_SAVEAPPLICATION:
3060 if (dcd && !ParentIsDesktop(hwnd, dcd->hwndParent)) {
3061
3062 SWP swp, swpP;
3063 INT ratio;
3064
3065 WinQueryWindowPos(dcd->hwndFrame, &swp);
3066 if (!(swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE | SWP_HIDE))) {
3067 WinQueryWindowPos(dcd->hwndParent, &swpP);
3068 if (swp.cx) {
3069 ratio = (swpP.cx * 100) / swp.cx;
3070 if (ratio > 0)
3071 PrfWriteProfileData(fmprof, appname, "TreeWindowRatio",
3072 &ratio, sizeof(INT));
3073 }
3074 }
3075 }
3076 else if (dcd && ParentIsDesktop(hwnd, dcd->hwndParent)) {
3077
3078 SWP swp;
3079
3080 WinQueryWindowPos(dcd->hwndFrame, &swp);
3081 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3082 WinStoreWindowPos((CHAR *) FM2Str, "VTreeWindowPos", dcd->hwndFrame);
3083 }
3084 break;
3085
3086 case UM_MINIMIZE:
3087 if (dcd && hwndMain) {
3088 fOkayMinimize = TRUE;
3089 if (dcd->hwndObject && !fDummy) {
3090 DosSleep(50);//05 Aug 07 GKY 100
3091 if (!fDummy) {
3092 fOkayMinimize = FALSE;
3093 WinSetWindowPos(((hwndMain) ? WinQueryWindow(hwndMain, QW_PARENT) :
3094 dcd->hwndFrame), HWND_TOP, 0, 0, 0, 0,
3095 SWP_MINIMIZE | SWP_DEACTIVATE);
3096 }
3097 }
3098 }
3099 return 0;
3100
3101 case UM_MAXIMIZE:
3102 if (dcd || hwndMain)
3103 WinSetWindowPos(((hwndMain) ? WinQueryWindow(hwndMain, QW_PARENT) :
3104 dcd->hwndFrame), HWND_TOP, 0, 0, 0, 0, SWP_MAXIMIZE |
3105 SWP_SHOW);
3106 return 0;
3107
3108 case UM_CLOSE:
3109 {
3110 HWND hwndParent = WinQueryWindow(WinQueryWindow(WinQueryWindow(hwnd,
3111 QW_PARENT),
3112 QW_PARENT), QW_PARENT);
3113
3114 if (!mp1) {
3115 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3116 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
3117 if (hwndParent && !ParentIsDesktop(hwnd, hwndParent))
3118 WinDestroyWindow(hwndParent);
3119 }
3120 else
3121 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
3122 QW_PARENT));
3123 }
3124 return 0;
3125
3126 case WM_CLOSE:
3127 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3128 if (dcd)
3129 dcd->stopflag++;
3130 if (dcd && dcd->hwndObject) {
3131 // kill object window
3132 if (WinIsWindow((HAB) 0, dcd->hwndObject)) {
3133 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3134 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3135 }
3136 }
3137 else
3138 WinSendMsg(hwnd, UM_CLOSE, MPFROMLONG(1), MPVOID);
3139 return 0;
3140
3141 case WM_DESTROY:
3142# ifdef FORTIFY
3143 DbgMsg(pszSrcFile, __LINE__, "WM_DESTROY hwnd %p TID %u", hwnd, GetTidForThread()); // 18 Jul 08 SHL fixme
3144# endif
3145 if (TreeCnrMenu)
3146 WinDestroyWindow(TreeCnrMenu);
3147 if (DirMenu)
3148 WinDestroyWindow(DirMenu);
3149 if (FileMenu)
3150 WinDestroyWindow(FileMenu);
3151 TreeCnrMenu = FileMenu = DirMenu = (HWND) 0;
3152 EmptyCnr(hwnd);
3153 if (apphead) {
3154 APPNOTIFY *info, *next;
3155
3156 info = apphead;
3157 while (info) {
3158 next = info->next;
3159 free(info);
3160 info = next;
3161 }
3162 apphead = apptail = NULL;
3163 }
3164# ifdef FORTIFY
3165 Fortify_LeaveScope();
3166# endif
3167 break; // WM_DESTROY
3168 } // switch
3169 if (dcd && dcd->oldproc){
3170 return dcd->oldproc(hwnd, msg, mp1, mp2);
3171 }
3172 else
3173 return PFNWPCnr(hwnd, msg, mp1, mp2);
3174}
3175
3176/**
3177 * Start drive tree container
3178 * @returns tree handle or NULLHANDLE
3179 */
3180
3181HWND StartTreeCnr(HWND hwndParent, ULONG flags)
3182{
3183 /**
3184 * bitmapped flags:
3185 * 0x00000001 = don't close app when window closes
3186 * 0x00000002 = no frame controls
3187 * 0x00000004 = no close or move button
3188 */
3189
3190 HWND hwndFrame = NULLHANDLE;
3191 HWND hwndSysMenu = NULLHANDLE;
3192 HWND hwndClient;
3193 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3194 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3195 DIRCNRDATA *dcd;
3196
3197 if (!hwndParent)
3198 hwndParent = HWND_DESKTOP;
3199 if (ParentIsDesktop(hwndParent, hwndParent))
3200 FrameFlags |= (FCF_TASKLIST | FCF_MENU);
3201 if (flags & 2)
3202 FrameFlags &= (~(FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
3203 FCF_MINMAX | FCF_ICON));
3204 hwndFrame = WinCreateStdWindow(hwndParent,
3205 WS_VISIBLE,
3206 &FrameFlags,
3207 (CHAR *) WC_TREECONTAINER,
3208 NULL,
3209 WS_VISIBLE | fwsAnimate,
3210 FM3ModHandle, TREE_FRAME, &hwndClient);
3211 if (hwndParent != HWND_DESKTOP) {
3212 hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
3213 if (hwndSysMenu != NULLHANDLE)
3214 WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
3215 MPFROM2SHORT(SC_CLOSE, TRUE),
3216 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
3217 if (!fFreeTree)
3218 WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
3219 MPFROM2SHORT(SC_MOVE, TRUE),
3220 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
3221 }
3222 if (hwndFrame && hwndClient) {
3223# ifdef FORTIFY
3224 Fortify_EnterScope();
3225# endif
3226 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3227 if (!dcd) {
3228 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
3229 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3230 hwndFrame = (HWND) 0;
3231 }
3232 else {
3233 SWP swp;
3234 WinQueryWindowPos(hwndFrame, &swp);
3235 if (*(ULONG *) realappname == FM3UL) {
3236 if (!WinCreateWindow(hwndFrame,
3237 (CHAR *) WC_TREEOPENBUTTON,
3238 "#303",
3239 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS | BS_BITMAP,
3240 ((swp.cx -
3241 WinQuerySysValue(HWND_DESKTOP,
3242 SV_CXMINMAXBUTTON)) -
3243 WinQuerySysValue(HWND_DESKTOP,
3244 SV_CXMINMAXBUTTON) / 2) -
3245 WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER),
3246 (swp.cy -
3247 WinQuerySysValue(HWND_DESKTOP,
3248 SV_CYMINMAXBUTTON)) -
3249 WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER),
3250 WinQuerySysValue(HWND_DESKTOP,
3251 SV_CXMINMAXBUTTON) / 2,
3252 WinQuerySysValue(HWND_DESKTOP,
3253 SV_CYMINMAXBUTTON), hwndFrame,
3254 HWND_TOP, IDM_OPENWINDOW, NULL, NULL)) {
3255 Win_Error(hwndFrame, hwndParent, pszSrcFile, __LINE__,
3256 PCSZ_WINCREATEWINDOW);
3257 }
3258 }
3259 else {
3260 if (!WinCreateWindow(hwndFrame,
3261 (CHAR *) WC_TREESTATUS,
3262 (CHAR *) GetPString(IDS_YOUAREHERETEXT),
3263 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_VCENTER,
3264 swp.x + 4 + WinQuerySysValue(HWND_DESKTOP,
3265 SV_CXSIZEBORDER),
3266 swp.cy - (22 + WinQuerySysValue(HWND_DESKTOP,
3267 SV_CYSIZEBORDER)),
3268 (swp.cx - 8) - (WinQuerySysValue(HWND_DESKTOP,
3269 SV_CXSIZEBORDER)
3270 * 2), 22, hwndFrame, HWND_TOP,
3271 MAIN_STATUS, NULL, NULL)) {
3272 Win_Error(hwndFrame, hwndParent, pszSrcFile, __LINE__,
3273 PCSZ_WINCREATEWINDOW);
3274 }
3275 }
3276 memset(dcd, 0, sizeof(DIRCNRDATA));
3277 dcd->size = sizeof(DIRCNRDATA);
3278 dcd->type = TREE_FRAME;
3279 dcd->dontclose = (flags & 1) != 0;
3280 dcd->hwndParent = hwndParent ? hwndParent : HWND_DESKTOP;
3281 dcd->hwndClient = hwndClient;
3282 dcd->hwndFrame = hwndFrame;
3283 {
3284 PFNWP oldproc;
3285
3286 oldproc = WinSubclassWindow(hwndFrame, TreeFrameWndProc);
3287 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3288 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3289 (PFNWP) TreeTitleWndProc);
3290 WinSetWindowPtr(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3291 QWL_USER, (PVOID) oldproc);
3292 }
3293 dcd->hwndCnr = WinCreateWindow(hwndClient,
3294 WC_CONTAINER,
3295 NULL,
3296 CCS_AUTOPOSITION | CCS_MINIICONS |
3297 CCS_MINIRECORDCORE,
3298 0,
3299 0,
3300 0,
3301 0,
3302 hwndClient,
3303 HWND_TOP, (ULONG) TREE_CNR, NULL, NULL);
3304 if (!dcd->hwndCnr) {
3305 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3306 PCSZ_WINCREATEWINDOW);
3307 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3308 free(dcd);
3309 dcd = 0;
3310 hwndFrame = (HWND) 0;
3311 }
3312 else {
3313 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3314 if (ParentIsDesktop(hwndFrame, hwndParent)) {
3315 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR), "VTree");
3316 FixSwitchList(hwndFrame, "VTree");
3317 }
3318 else {
3319 WinSetWindowText(hwndFrame, (CHAR *) GetPString(IDS_TREETEXT));
3320 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3321 (CHAR *) GetPString(IDS_TREETEXT));
3322 }
3323 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr, TreeCnrWndProc);
3324 // fixme to document 01 test?
3325 if (dcd->oldproc == 0)
3326 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
3327 "WinSubclassWindow");
3328 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3329 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3330 }
3331 }
3332# ifdef FORTIFY
3333 if (dcd)
3334 Fortify_ChangeScope(dcd, -1);
3335 Fortify_LeaveScope();
3336 if (dcd)
3337 Fortify_ChangeScope(dcd, +1);
3338# endif
3339 }
3340 WinShowWindow(hwndFrame, FALSE);
3341 return hwndFrame;
3342}
3343
3344#pragma alloc_text(TREECNR,TreeCnrWndProc,TreeObjWndProc,TreeClientWndProc)
3345#pragma alloc_text(TREECNR,TreeFrameWndProc,TreeTitleWndProc,ShowTreeRec)
3346#pragma alloc_text(TREECNR,TreeStatProc,OpenButtonProc)
3347#pragma alloc_text(STARTUP,StartTreeCnr)
Note: See TracBrowser for help on using the repository browser.