source: trunk/dll/treecnr.c@ 1506

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

Fixed hang and drive tree rescan failure resulting from event sem not being posted.

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