source: trunk/dll/treecnr.c@ 1079

Last change on this file since 1079 was 1079, checked in by Steven Levine, 17 years ago

Avoid some more spurious leak reports

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