source: trunk/dll/treecnr.c@ 1803

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

Changes to allow a JAVA executable object to be created using "Real object" menu item on a jar file. (Ticket [37]) Eliminate redundant prompts and error messages when telling FM/2 not to delete a R/O file. (Ticket [548]) Limit attempts to unlock files to exes and dlls. (Ticket [549])

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