source: trunk/dll/treecnr.c@ 1036

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

Additional fortify scopes mostly for "lists"

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