source: trunk/dll/treecnr.c@ 1771

Last change on this file since 1771 was 1771, checked in by Gregg Young, 11 years ago

Last change to try to speed up the initial drive scan. This delays making the tree container visible to hopefully reduce some screen write overhead. I am not convinced it does anything but it doesn't appear to cause any problems. Ticket [528]

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