source: trunk/dll/treecnr.c@ 1553

Last change on this file since 1553 was 1553, checked in by Gregg Young, 15 years ago

Rework scanning code to remove redundant scans, prevent double directory entries in the tree container, fix related semaphore performance using combination of event and mutex semaphores

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