source: trunk/dll/treecnr.c@ 1668

Last change on this file since 1668 was 1663, checked in by Gregg Young, 13 years ago

Fix trap reported by Ben

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