source: trunk/dll/treecnr.c@ 1063

Last change on this file since 1063 was 1063, checked in by Gregg Young, 17 years ago

Fortify ifdef reformat

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