source: trunk/dll/treecnr.c@ 1549

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

This "fixes" the double entries in the tree container (Ticket 363); it also means the tree ignores the fSwitchTree* variables on startup. The only remaining problem is on the first focus changes between 2 directory containers the directory doesn't always get placed at the top of the tree container after the first switch to each it seems to work fine.

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