source: trunk/dll/treecnr.c@ 1037

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

Newview is used used when view is selected from menus in dircnrs, collector, arccnrs etc (ticket 244); Removed Fortify_Leavescope wrapper other minor fortify changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: treecnr.c 1037 2008-07-04 16:39:08Z 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 hwnd;
2174
2175 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2176 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2177 (CHAR *)mp2, dcd->hwndFrame);
2178 else
2179 hwnd = StartMLEEditor(dcd->hwndParent,
2180 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
2181 xfree((CHAR *)mp2, pszSrcFile, __LINE__);
2182 return MRFROMLONG(hwnd);
2183 }
2184 return 0;
2185
2186 case UM_FIXCNRMLE:
2187 case UM_FIXEDITNAME:
2188 return CommonCnrProc(hwnd, msg, mp1, mp2);
2189
2190 case UM_NOTIFY:
2191 if (mp2)
2192 Notify((CHAR *)mp2);
2193 return 0;
2194
2195 case UM_FILTER:
2196 if (dcd) {
2197
2198 BOOL tempsusp = dcd->suspendview;
2199
2200 if (mp1) {
2201 DosEnterCritSec();
2202 SetMask((CHAR *)mp1, &dcd->mask);
2203 DosExitCritSec();
2204 }
2205 dcd->suspendview = TRUE;
2206 dcd->mask.attrFile |= FILE_DIRECTORY;
2207 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2208 dcd->suspendview = tempsusp;
2209 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2210 }
2211 return 0;
2212
2213 case UM_DRIVECMD:
2214 if (mp1)
2215 ShowTreeRec(hwnd, (CHAR *)mp1, FALSE, TRUE);
2216 return 0;
2217
2218 case WM_APPTERMINATENOTIFY:
2219 {
2220 APPNOTIFY *info;
2221 PCNRITEM pci;
2222 CHAR s[] = " :\\";
2223
2224 if (!mp2) {
2225 if (hwndMain)
2226 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
2227 }
2228 info = apphead;
2229 while (info) {
2230 if (info->happ == (HAPP) mp1) {
2231 *s = info->device;
2232 pci = FindCnrRecord(hwnd, s, NULL, FALSE, FALSE, TRUE);
2233 if (pci && (INT) pci != -1) {
2234 driveserial[info->device - 'A'] = -1;
2235 DriveFlagsOne(info->device - 'A');
2236 if (driveflags[info->device - 'A'] &
2237 (DRIVE_INVALID | DRIVE_IGNORE))
2238 RemoveCnrItems(hwnd, pci, 1, CMA_FREE);
2239 else
2240 Flesh(hwnd, pci);
2241 }
2242 if (info->prev)
2243 info->prev->next = info->next;
2244 if (info->next)
2245 info->next->prev = info->prev;
2246 if (apphead == info)
2247 apphead = info->next;
2248 if (apptail == info)
2249 apptail = info->prev;
2250 xfree(info, pszSrcFile, __LINE__);
2251 break;
2252 }
2253 info = info->next;
2254 }
2255 }
2256 break;
2257
2258 case WM_COMMAND:
2259 DosError(FERR_DISABLEHARDERR);
2260 if (dcd) {
2261 if (SwitchCommand(dcd->hwndLastMenu, SHORT1FROMMP(mp1)))
2262 return 0;
2263 switch (SHORT1FROMMP(mp1)) {
2264 case IDM_SETTARGET:
2265 SetTargetDir(hwnd, FALSE);
2266 break;
2267
2268 case IDM_DETACH:
2269 {
2270 CHAR d[3] = " :";
2271 PCNRITEM pci;
2272 PROGDETAILS pgd;
2273 CHAR params[368], *p;
2274 HAPP happ;
2275
2276 pci = (PCNRITEM) CurrentRecord(hwnd);
2277 if (pci && (INT) pci != -1 && isalpha(*pci->pszFileName)) {
2278 *d = toupper(*pci->pszFileName);
2279 p = GetCmdSpec(FALSE);
2280 memset(&pgd, 0, sizeof(pgd));
2281 pgd.Length = sizeof(pgd);
2282 pgd.progt.progc = PROG_WINDOWABLEVIO;
2283 pgd.progt.fbVisible = SHE_VISIBLE;
2284 pgd.pszTitle = GetPString(IDS_DETACHREQUESTTEXT);
2285 pgd.pszExecutable = p;
2286 pgd.pszParameters = params;
2287 pgd.pszStartupDir = NULL;
2288 pgd.pszIcon = NULL;
2289 pgd.pszEnvironment = NULL;
2290 pgd.swpInitial.hwndInsertBehind = HWND_TOP;
2291 pgd.swpInitial.hwnd = hwnd;
2292 pgd.swpInitial.fl = SWP_SHOW | SWP_ACTIVATE;
2293 sprintf(params, "/C NET USE %s /D", d);
2294 happ = WinStartApp(hwnd, &pgd, pgd.pszParameters,
2295 NULL, SAF_MAXIMIZED);
2296 if (!happ) {
2297 saymsg(MB_CANCEL | MB_ICONEXCLAMATION, hwnd,
2298 GetPString(IDS_ERRORTEXT),
2299 GetPString(IDS_CANTSTARTTEXT), p, params);
2300 }
2301 else {
2302 APPNOTIFY *info;
2303
2304 info = xmallocz(sizeof(APPNOTIFY), pszSrcFile, __LINE__);
2305 if (info) {
2306 info->happ = happ;
2307 info->device = *d;
2308 if (!apphead)
2309 apphead = info;
2310 else {
2311 apptail->next = info;
2312 info->prev = apptail;
2313 }
2314 apptail = info;
2315 }
2316 }
2317 }
2318 }
2319 break;
2320
2321 case IDM_REMAP:
2322 WinDlgBox(HWND_DESKTOP, hwnd, RemapDlgProc,
2323 FM3ModHandle, MAP_FRAME, NULL);
2324 break;
2325
2326 case IDM_CONTEXTMENU:
2327 {
2328 PCNRITEM pci;
2329
2330 pci = (PCNRITEM) CurrentRecord(hwnd);
2331 PostMsg(hwnd, WM_CONTROL, MPFROM2SHORT(DIR_CNR, CN_CONTEXTMENU),
2332 MPFROMP(pci));
2333 }
2334 break;
2335
2336 case IDM_FINDINTREE:
2337 {
2338 CHAR dir[CCHMAXPATH];
2339 PCNRITEM pci;
2340
2341 pci = (PCNRITEM) CurrentRecord(hwnd);
2342 if (pci && (INT) pci != -1) {
2343 strcpy(dir, pci->pszFileName);
2344 MakeValidDir(dir);
2345 }
2346 else
2347 save_dir2(dir);
2348 if (WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
2349 WalkAllDlgProc,
2350 FM3ModHandle, WALK_FRAME, MPFROMP(dir)) && *dir)
2351 WinSendMsg(hwnd, UM_SHOWME, MPFROMP(dir), MPFROMLONG(1));
2352 }
2353 break;
2354
2355 case IDM_BEGINEDIT:
2356 OpenEdit(hwnd);
2357 break;
2358
2359 case IDM_ENDEDIT:
2360 WinSendMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
2361 break;
2362
2363 case IDM_FILTER:
2364 {
2365 BOOL empty = FALSE;
2366 PCNRITEM pci;
2367
2368 pci = (PCNRITEM) CurrentRecord(hwnd);
2369 if (!*dcd->mask.szMask)
2370 empty = TRUE;
2371 dcd->mask.fIsTree = TRUE;
2372 *dcd->mask.prompt = 0;
2373 if (pci && (INT) pci != -1)
2374 dcd->mask.fFilesIncluded =
2375 ((driveflags[toupper(*pci->pszFileName) - 'A'] &
2376 DRIVE_INCLUDEFILES) != 0);
2377 else
2378 dcd->mask.fFilesIncluded = FALSE;
2379 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2380 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask)))
2381 WinSendMsg(hwnd, UM_FILTER, MPVOID, MPVOID);
2382 else if (empty)
2383 *dcd->mask.szMask = 0;
2384 PrfWriteProfileData(fmprof, appname, "TreeFilter", &dcd->mask,
2385 sizeof(MASK));
2386 }
2387 break;
2388
2389 case IDM_SHOWSORT:
2390 QuickPopup(hwnd, dcd, CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP),
2391 IDM_SORTSUBMENU);
2392 break;
2393
2394 case IDM_SHOWSELECT:
2395 QuickPopup(hwnd, dcd, CheckMenu(hwndMainMenu, &TreeCnrMenu, TREECNR_POPUP),
2396 IDM_SELECTSUBMENU);
2397 break;
2398
2399 case IDM_TREECNRVIEWSETTINGS:
2400 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
2401 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_TREECNRVIEWSETTINGS), mp2);
2402 else {
2403 WinDlgBox(HWND_DESKTOP,
2404 hwnd,
2405 CfgDlgProc,
2406 FM3ModHandle,
2407 CFG_FRAME,
2408 MPFROMLONG(IDM_TREECNRVIEWSETTINGS));
2409 }
2410 break;
2411
2412 case IDM_WALKDIR:
2413 case IDM_OPENWALK:
2414 {
2415 CHAR newpath[CCHMAXPATH];
2416 PCNRITEM pci;
2417
2418 pci = (PCNRITEM) CurrentRecord(hwnd);
2419 if (pci && (INT) pci != -1) {
2420 strcpy(newpath, pci->pszFileName);
2421 MakeValidDir(newpath);
2422 }
2423 else
2424 save_dir2(newpath);
2425 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkAllDlgProc,
2426 FM3ModHandle, WALK_FRAME,
2427 MPFROMP(newpath)) || !*newpath)
2428 break;
2429 WinSendMsg(hwnd, UM_OPENWINDOWFORME, MPFROMP(newpath), MPVOID);
2430 }
2431 break;
2432
2433 case IDM_HELP:
2434 if (hwndHelp) {
2435 if (!ParentIsDesktop(dcd->hwndFrame, dcd->hwndParent))
2436 PostMsg(dcd->hwndParent, UM_COMMAND, mp1, mp2);
2437 else
2438 WinSendMsg(hwndHelp, HM_HELP_CONTENTS, MPVOID, MPVOID);
2439 }
2440 break;
2441
2442 case IDM_PARTITION:
2443 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2444 NULL, NULL,
2445 "%s", "MINILVM.EXE");
2446 break;
2447
2448 case IDM_PARTITIONDF:
2449 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2450 NULL, NULL,
2451 "%s", "DFSOS2.EXE");
2452 break;
2453
2454 case IDM_PARTITIONLVMG:
2455 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2456 NULL, NULL,
2457 "%s", "LVMGUI.CMD");
2458 break;
2459
2460 case IDM_PARTITIONFD:
2461 runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
2462 NULL, NULL,
2463 "%s", "FDISKPM.EXE");
2464 break;
2465
2466 case IDM_SORTNAME:
2467 case IDM_SORTFILENAME:
2468 case IDM_SORTSIZE:
2469 case IDM_SORTEASIZE:
2470 case IDM_SORTFIRST:
2471 case IDM_SORTLAST:
2472 case IDM_SORTLWDATE:
2473 case IDM_SORTLADATE:
2474 case IDM_SORTCRDATE:
2475 TreesortFlags &= (SORT_REVERSE | SORT_DIRSFIRST | SORT_DIRSLAST);
2476 case IDM_SORTDIRSFIRST:
2477 case IDM_SORTDIRSLAST:
2478 case IDM_SORTREVERSE:
2479 switch (SHORT1FROMMP(mp1)) {
2480 case IDM_SORTFILENAME:
2481 TreesortFlags |= SORT_FILENAME;
2482 break;
2483 case IDM_SORTSIZE:
2484 TreesortFlags |= SORT_SIZE;
2485 break;
2486 case IDM_SORTEASIZE:
2487 TreesortFlags |= SORT_EASIZE;
2488 break;
2489 case IDM_SORTFIRST:
2490 TreesortFlags |= SORT_FIRSTEXTENSION;
2491 break;
2492 case IDM_SORTLAST:
2493 TreesortFlags |= SORT_LASTEXTENSION;
2494 break;
2495 case IDM_SORTLWDATE:
2496 TreesortFlags |= SORT_LWDATE;
2497 break;
2498 case IDM_SORTLADATE:
2499 TreesortFlags |= SORT_LADATE;
2500 break;
2501 case IDM_SORTCRDATE:
2502 TreesortFlags |= SORT_CRDATE;
2503 break;
2504 case IDM_SORTDIRSFIRST:
2505 if (TreesortFlags & SORT_DIRSFIRST)
2506 TreesortFlags &= (~SORT_DIRSFIRST);
2507 else {
2508 TreesortFlags |= SORT_DIRSFIRST;
2509 TreesortFlags &= (~SORT_DIRSLAST);
2510 }
2511 break;
2512 case IDM_SORTDIRSLAST:
2513 if (TreesortFlags & SORT_DIRSLAST)
2514 TreesortFlags &= (~SORT_DIRSLAST);
2515 else {
2516 TreesortFlags |= SORT_DIRSLAST;
2517 TreesortFlags &= (~SORT_DIRSFIRST);
2518 }
2519 break;
2520 case IDM_SORTREVERSE:
2521 if (TreesortFlags & SORT_REVERSE)
2522 TreesortFlags &= (~SORT_REVERSE);
2523 else
2524 TreesortFlags |= SORT_REVERSE;
2525 break;
2526 }
2527 PrfWriteProfileData(fmprof, appname, "TreeSort", &TreesortFlags,
2528 sizeof(INT));
2529 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortTreeCnr), MPVOID);
2530 break;
2531
2532 case IDM_COLLECT:
2533 if (!Collector) {
2534
2535 HWND hwndC;
2536 SWP swp;
2537
2538 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
2539 !fAutoTile &&
2540 (!fExternalCollector && *(ULONG *) realappname == FM3UL))
2541 GetNextWindowPos(dcd->hwndParent, &swp, NULL, NULL);
2542 hwndC = StartCollector((fExternalCollector ||
2543 *(ULONG *) realappname != FM3UL) ?
2544 HWND_DESKTOP : dcd->hwndParent, 4);
2545 if (hwndC) {
2546 if (!ParentIsDesktop(hwnd,
2547 dcd->hwndParent) &&
2548 !fAutoTile &&
2549 (!fExternalCollector && *(ULONG *) realappname == FM3UL))
2550 WinSetWindowPos(hwndC,
2551 HWND_TOP,
2552 swp.x,
2553 swp.y,
2554 swp.cx,
2555 swp.cy,
2556 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
2557 else if (!ParentIsDesktop(hwnd,
2558 dcd->hwndParent) &&
2559 fAutoTile && *(ULONG *) realappname == FM3UL)
2560 TileChildren(dcd->hwndParent, TRUE);
2561 }
2562 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
2563 DosSleep(100);//05 Aug 07 GKY 250
2564 }
2565 else
2566 StartCollector(dcd->hwndParent, 4);
2567 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPVOID);
2568 break;
2569
2570 case IDM_COLLECTOR:
2571 DosSleep(32);//05 Aug 07 GKY 64
2572 {
2573 CHAR **list;
2574
2575 list = BuildList(hwnd);
2576 if (list) {
2577 if (Collector) {
2578 if (!PostMsg(Collector, WM_COMMAND,
2579 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
2580 FreeList(list);
2581 }
2582 else
2583 FreeList(list);
2584 }
2585 }
2586 break;
2587
2588 case IDM_COLLAPSEALL:
2589 WinSendMsg(hwnd, CM_COLLAPSETREE, MPVOID, MPVOID);
2590 break;
2591
2592 case IDM_COLLAPSE:
2593 case IDM_EXPAND:
2594 {
2595 PCNRITEM pci = NULL;
2596
2597 pci = (PCNRITEM) CurrentRecord(hwnd);
2598 if (pci && (INT) pci != -1) {
2599 if (pci->flags & RECFLAGS_UNDERENV)
2600 break;
2601 PostMsg(dcd->hwndObject, UM_EXPAND, mp1, MPFROMP(pci));
2602 }
2603 }
2604 break;
2605
2606 case IDM_UPDATE:
2607 {
2608 PCNRITEM pci = (PCNRITEM)CurrentRecord(hwnd);
2609 if (pci && (INT)pci != -1) {
2610 UINT driveflag = driveflags[toupper(*pci->pszFileName) - 'A'];
2611 if (pci->attrFile & FILE_DIRECTORY) {
2612 if (pci->flags & RECFLAGS_UNDERENV)
2613 break;
2614 UnFlesh(hwnd, pci);
2615 // Check if drive type might need update
2616 if ((driveflag & (DRIVE_INVALID | DRIVE_NOPRESCAN)) ||
2617 (~driveflag & DRIVE_NOPRESCAN && pci->rc.hptrIcon == hptrDunno))
2618 {
2619 driveflags[toupper(*pci->pszFileName) - 'A'] &=
2620 (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
2621 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | DRIVE_NOSTATS);
2622 DriveFlagsOne(toupper(*pci->pszFileName) - 'A');
2623 driveflag = driveflags[toupper(*pci->pszFileName) - 'A'];
2624 if (driveflag & DRIVE_INVALID)
2625 pci->rc.hptrIcon = hptrDunno;
2626 else {
2627 SelectDriveIcon(pci);
2628 }
2629 WinSendMsg(hwnd,
2630 CM_INVALIDATERECORD,
2631 MPFROMP(&pci),
2632 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2633 if (hwndMain)
2634 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
2635 }
2636 if (~driveflag & DRIVE_INVALID)
2637 Flesh(hwnd, pci);
2638 }
2639 }
2640 }
2641 break;
2642
2643 case IDM_RESCAN:
2644 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2645 break;
2646
2647 case IDM_RESORT:
2648 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortTreeCnr), MPVOID);
2649 break;
2650
2651 case IDM_TEXT:
2652 case IDM_MINIICONS:
2653 {
2654 CNRINFO cnri;
2655
2656 memset(&cnri, 0, sizeof(CNRINFO));
2657 cnri.cb = sizeof(CNRINFO);
2658 WinSendMsg(hwnd,
2659 CM_QUERYCNRINFO,
2660 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2661 if (SHORT1FROMMP(mp1) == IDM_MINIICONS) {
2662 if (cnri.flWindowAttr & CV_MINI)
2663 cnri.flWindowAttr &= (~CV_MINI);
2664 else
2665 cnri.flWindowAttr |= CV_MINI;
2666 }
2667 else {
2668 if (cnri.flWindowAttr & CV_TEXT) {
2669 cnri.flWindowAttr &= (~CV_TEXT);
2670 cnri.flWindowAttr |= CV_ICON;
2671 }
2672 else {
2673 cnri.flWindowAttr &= (~CV_ICON);
2674 cnri.flWindowAttr |= CV_TEXT;
2675 }
2676 }
2677 dcd->flWindowAttr = cnri.flWindowAttr;
2678 PrfWriteProfileData(fmprof,
2679 appname,
2680 "TreeflWindowAttr",
2681 &cnri.flWindowAttr, sizeof(ULONG));
2682 WinSendMsg(hwnd,
2683 CM_SETCNRINFO,
2684 MPFROMP(&cnri),
2685 MPFROMLONG(CMA_FLWINDOWATTR | CMA_TREEICON |
2686 CMA_SLTREEBITMAPORICON));
2687 }
2688 break;
2689
2690 case IDM_SIZES:
2691 case IDM_DRVFLAGS:
2692 case IDM_SHOWALLFILES:
2693 case IDM_UNDELETE:
2694 case IDM_OPTIMIZE:
2695 case IDM_CHKDSK:
2696 case IDM_FORMAT:
2697 case IDM_MKDIR:
2698 case IDM_LOCK:
2699 case IDM_UNLOCK:
2700 case IDM_EJECT:
2701 case IDM_CLOSETRAY:
2702 {
2703 PCNRITEM pci;
2704
2705 pci = (PCNRITEM) CurrentRecord(hwnd);
2706 if (pci && (INT) pci != -1)
2707 CommonDriveCmd(hwnd, pci->pszFileName, SHORT1FROMMP(mp1));
2708 }
2709 break;
2710
2711 case IDM_SAVETOLIST:
2712 WinDlgBox(HWND_DESKTOP,
2713 hwnd,
2714 SaveListDlgProc, FM3ModHandle, SAV_FRAME, MPFROMP(&hwnd));
2715 break;
2716
2717 case IDM_DELETE:
2718 case IDM_PERMDELETE:
2719 case IDM_MOVE:
2720 case IDM_WPSMOVE:
2721 case IDM_WILDMOVE:
2722 case IDM_RENAME:
2723 {
2724 PCNRITEM pci;
2725
2726 pci = (PCNRITEM) CurrentRecord(hwnd);
2727 if (pci && (INT) pci != -1) {
2728 if (pci->flags & RECFLAGS_UNDERENV)
2729 break;
2730 }
2731 }
2732 /* else intentional fallthru */
2733 case IDM_ATTRS:
2734 case IDM_INFO:
2735 case IDM_COPY:
2736 case IDM_WPSCOPY:
2737 case IDM_WILDCOPY:
2738 case IDM_DOITYOURSELF:
2739 case IDM_OPENWINDOW:
2740 case IDM_OPENSETTINGS:
2741 case IDM_OPENDEFAULT:
2742 case IDM_OPENICON:
2743 case IDM_OPENDETAILS:
2744 case IDM_OPENTREE:
2745 case IDM_SHADOW:
2746 case IDM_SHADOW2:
2747 case IDM_COMPARE:
2748 case IDM_VIEW:
2749 case IDM_VIEWTEXT:
2750 case IDM_VIEWBINARY:
2751 case IDM_EDIT:
2752 case IDM_EDITTEXT:
2753 case IDM_EDITBINARY:
2754 case IDM_EAS:
2755 case IDM_SUBJECT:
2756 case IDM_APPENDTOCLIP:
2757 case IDM_SAVETOCLIP:
2758 case IDM_ARCHIVE:
2759 case IDM_MCIPLAY:
2760 case IDM_UUDECODE:
2761 {
2762 LISTINFO *li;
2763 ULONG action = UM_ACTION;
2764# ifdef FORTIFY
2765 Fortify_EnterScope();
2766# endif
2767 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2768 if (li) {
2769 li->type = SHORT1FROMMP(mp1);
2770 li->hwnd = hwnd;
2771 li->list = BuildList(hwnd);
2772 if (!li->list || !li->list[0]) {
2773 xfree(li, pszSrcFile, __LINE__);
2774# ifdef FORTIFY
2775 Fortify_LeaveScope();
2776# endif
2777 break;
2778 }
2779 if (IsRoot(li->list[0])) {
2780 switch (SHORT1FROMMP(mp1)) {
2781 case IDM_MOVE:
2782 case IDM_COPY:
2783 case IDM_WILDCOPY:
2784 case IDM_WILDMOVE:
2785 case IDM_WPSMOVE:
2786 case IDM_WPSCOPY:
2787 case IDM_RENAME:
2788 case IDM_DELETE:
2789 case IDM_PERMDELETE:
2790 mp1 = MPFROM2SHORT(IDM_INFO, SHORT2FROMMP(mp1));
2791 li->type = IDM_INFO;
2792 break;
2793 }
2794 }
2795 switch (SHORT1FROMMP(mp1)) {
2796 case IDM_APPENDTOCLIP:
2797 case IDM_SAVETOCLIP:
2798 case IDM_ARCHIVE:
2799 case IDM_DELETE:
2800 case IDM_PERMDELETE:
2801 case IDM_ATTRS:
2802 case IDM_SHADOW:
2803 case IDM_SHADOW2:
2804 case IDM_DOITYOURSELF:
2805 case IDM_EAS:
2806 case IDM_VIEW:
2807 case IDM_VIEWTEXT:
2808 case IDM_VIEWBINARY:
2809 case IDM_EDIT:
2810 case IDM_EDITTEXT:
2811 case IDM_EDITBINARY:
2812 case IDM_MCIPLAY:
2813 action = UM_MASSACTION;
2814 break;
2815 }
2816 if (SHORT1FROMMP(mp1) == IDM_SHADOW ||
2817 SHORT1FROMMP(mp1) == IDM_SHADOW2)
2818 *li->targetpath = 0;
2819 if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID)) {
2820 Runtime_Error(pszSrcFile, __LINE__, "PostMsg");
2821 FreeListInfo(li);
2822 }
2823 }
2824 }
2825 break;
2826
2827 default:
2828 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
2829 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
2830
2831 INT x;
2832
2833 if (!cmdloaded)
2834 load_commands();
2835 x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
2836 if (x >= 0) {
2837 x++;
2838 RunCommand(hwnd, x);
2839 if (fUnHilite)
2840 UnHilite(hwnd, TRUE, &dcd->lastselection, 0);
2841 }
2842 }
2843 break;
2844 }
2845 }
2846 return 0;
2847
2848 case WM_SAVEAPPLICATION:
2849 if (dcd && !ParentIsDesktop(hwnd, dcd->hwndParent)) {
2850
2851 SWP swp, swpP;
2852 INT ratio;
2853
2854 WinQueryWindowPos(dcd->hwndFrame, &swp);
2855 if (!(swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE | SWP_HIDE))) {
2856 WinQueryWindowPos(dcd->hwndParent, &swpP);
2857 if (swp.cx) {
2858 ratio = (swpP.cx * 100) / swp.cx;
2859 if (ratio > 0)
2860 PrfWriteProfileData(fmprof, appname, "TreeWindowRatio",
2861 &ratio, sizeof(INT));
2862 }
2863 }
2864 }
2865 else if (dcd && ParentIsDesktop(hwnd, dcd->hwndParent)) {
2866
2867 SWP swp;
2868
2869 WinQueryWindowPos(dcd->hwndFrame, &swp);
2870 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
2871 WinStoreWindowPos(FM2Str, "VTreeWindowPos", dcd->hwndFrame);
2872 }
2873 break;
2874
2875 case UM_MINIMIZE:
2876 if (dcd && hwndMain) {
2877 fOkayMinimize = TRUE;
2878 if (dcd->hwndObject && !fDummy) {
2879 DosSleep(50);//05 Aug 07 GKY 100
2880 if (!fDummy) {
2881 fOkayMinimize = FALSE;
2882 WinSetWindowPos(((hwndMain) ? WinQueryWindow(hwndMain, QW_PARENT) :
2883 dcd->hwndFrame), HWND_TOP, 0, 0, 0, 0,
2884 SWP_MINIMIZE | SWP_DEACTIVATE);
2885 }
2886 }
2887 }
2888 return 0;
2889
2890 case UM_MAXIMIZE:
2891 if (dcd || hwndMain)
2892 WinSetWindowPos(((hwndMain) ? WinQueryWindow(hwndMain, QW_PARENT) :
2893 dcd->hwndFrame), HWND_TOP, 0, 0, 0, 0, SWP_MAXIMIZE |
2894 SWP_SHOW);
2895 return 0;
2896
2897 case UM_CLOSE:
2898 {
2899 HWND hwndParent = WinQueryWindow(WinQueryWindow(WinQueryWindow(hwnd,
2900 QW_PARENT),
2901 QW_PARENT), QW_PARENT);
2902
2903 if (!mp1) {
2904 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
2905 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
2906 if (hwndParent && !ParentIsDesktop(hwnd, hwndParent))
2907 WinDestroyWindow(hwndParent);
2908 }
2909 else
2910 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
2911 QW_PARENT));
2912 }
2913 return 0;
2914
2915 case WM_CLOSE:
2916 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
2917 if (dcd)
2918 dcd->stopflag++;
2919 if (dcd && dcd->hwndObject) {
2920 /* kill object window */
2921 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
2922 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
2923 }
2924 else
2925 WinSendMsg(hwnd, UM_CLOSE, MPFROMLONG(1), MPVOID);
2926 return 0;
2927
2928 case WM_DESTROY:
2929 if (TreeCnrMenu)
2930 WinDestroyWindow(TreeCnrMenu);
2931 if (DirMenu)
2932 WinDestroyWindow(DirMenu);
2933 if (FileMenu)
2934 WinDestroyWindow(FileMenu);
2935 TreeCnrMenu = FileMenu = DirMenu = (HWND) 0;
2936 EmptyCnr(hwnd);
2937 if (apphead) {
2938
2939 APPNOTIFY *info, *next;
2940
2941 info = apphead;
2942 while (info) {
2943 next = info->next;
2944 xfree(info, pszSrcFile, __LINE__);
2945 info = next;
2946 }
2947 apphead = apptail = NULL;
2948 }
2949 break;
2950 }
2951 if (dcd && dcd->oldproc){
2952 return dcd->oldproc(hwnd, msg, mp1, mp2);
2953 }
2954 else
2955 return PFNWPCnr(hwnd, msg, mp1, mp2);
2956}
2957
2958HWND StartTreeCnr(HWND hwndParent, ULONG flags)
2959{
2960 /* bitmapped flags:
2961 * 0x00000001 = don't close app when window closes
2962 * 0x00000002 = no frame controls
2963 * 0x00000004 = no close or move button
2964 */
2965
2966 HWND hwndFrame = NULLHANDLE;
2967 HWND hwndSysMenu = NULLHANDLE;
2968 HWND hwndClient;
2969 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
2970 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
2971 DIRCNRDATA *dcd;
2972
2973 if (!hwndParent)
2974 hwndParent = HWND_DESKTOP;
2975 if (ParentIsDesktop(hwndParent, hwndParent))
2976 FrameFlags |= (FCF_TASKLIST | FCF_MENU);
2977 if (flags & 2)
2978 FrameFlags &= (~(FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
2979 FCF_MINMAX | FCF_ICON));
2980 hwndFrame = WinCreateStdWindow(hwndParent,
2981 WS_VISIBLE,
2982 &FrameFlags,
2983 WC_TREECONTAINER,
2984 NULL,
2985 WS_VISIBLE | fwsAnimate,
2986 FM3ModHandle, TREE_FRAME, &hwndClient);
2987 if (hwndParent != HWND_DESKTOP) {
2988 hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
2989 if (hwndSysMenu != NULLHANDLE)
2990 WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
2991 MPFROM2SHORT(SC_CLOSE, TRUE),
2992 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
2993 if (!fFreeTree)
2994 WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
2995 MPFROM2SHORT(SC_MOVE, TRUE),
2996 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
2997 }
2998 if (hwndFrame && hwndClient) {
2999# ifdef FORTIFY
3000 Fortify_EnterScope();
3001# endif
3002 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3003 if (!dcd) {
3004 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
3005 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3006 hwndFrame = (HWND) 0;
3007 }
3008 else {
3009 SWP swp;
3010
3011 WinQueryWindowPos(hwndFrame, &swp);
3012 if (*(ULONG *) realappname == FM3UL) {
3013 if (!WinCreateWindow(hwndFrame,
3014 WC_TREEOPENBUTTON,
3015 "Op",
3016 WS_VISIBLE | BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
3017 ((swp.cx -
3018 WinQuerySysValue(HWND_DESKTOP,
3019 SV_CXMINMAXBUTTON)) -
3020 WinQuerySysValue(HWND_DESKTOP,
3021 SV_CXMINMAXBUTTON) / 2) -
3022 WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER),
3023 (swp.cy -
3024 WinQuerySysValue(HWND_DESKTOP,
3025 SV_CYMINMAXBUTTON)) -
3026 WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER),
3027 WinQuerySysValue(HWND_DESKTOP,
3028 SV_CXMINMAXBUTTON) / 2,
3029 WinQuerySysValue(HWND_DESKTOP,
3030 SV_CYMINMAXBUTTON), hwndFrame,
3031 HWND_TOP, IDM_OPENWINDOW, NULL, NULL)) {
3032 Win_Error2(hwndFrame, hwndParent, pszSrcFile, __LINE__,
3033 IDS_WINCREATEWINDOW);
3034 }
3035 }
3036 else {
3037 if (!WinCreateWindow(hwndFrame,
3038 WC_TREESTATUS,
3039 GetPString(IDS_YOUAREHERETEXT),
3040 WS_VISIBLE | SS_TEXT | DT_LEFT | DT_VCENTER,
3041 swp.x + 4 + WinQuerySysValue(HWND_DESKTOP,
3042 SV_CXSIZEBORDER),
3043 swp.cy - (22 + WinQuerySysValue(HWND_DESKTOP,
3044 SV_CYSIZEBORDER)),
3045 (swp.cx - 8) - (WinQuerySysValue(HWND_DESKTOP,
3046 SV_CXSIZEBORDER)
3047 * 2), 22, hwndFrame, HWND_TOP,
3048 MAIN_STATUS, NULL, NULL)) {
3049 Win_Error2(hwndFrame, hwndParent, pszSrcFile, __LINE__,
3050 IDS_WINCREATEWINDOW);
3051 }
3052 }
3053 memset(dcd, 0, sizeof(DIRCNRDATA));
3054 dcd->size = sizeof(DIRCNRDATA);
3055 dcd->type = TREE_FRAME;
3056 dcd->dontclose = ((flags & 1) != 0);
3057 dcd->hwndParent = (hwndParent) ? hwndParent : HWND_DESKTOP;
3058 dcd->hwndClient = hwndClient;
3059 dcd->hwndFrame = hwndFrame;
3060 {
3061 PFNWP oldproc;
3062
3063 oldproc = WinSubclassWindow(hwndFrame, TreeFrameWndProc);
3064 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3065 oldproc = WinSubclassWindow(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3066 (PFNWP) TreeTitleWndProc);
3067 WinSetWindowPtr(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3068 QWL_USER, (PVOID) oldproc);
3069 }
3070 dcd->hwndCnr = WinCreateWindow(hwndClient,
3071 WC_CONTAINER,
3072 NULL,
3073 CCS_AUTOPOSITION | CCS_MINIICONS |
3074 CCS_MINIRECORDCORE | WS_VISIBLE,
3075 0,
3076 0,
3077 0,
3078 0,
3079 hwndClient,
3080 HWND_TOP, (ULONG) TREE_CNR, NULL, NULL);
3081 if (!dcd->hwndCnr) {
3082 Win_Error2(hwndClient, hwndClient, pszSrcFile, __LINE__,
3083 IDS_WINCREATEWINDOW);
3084 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3085 xfree(dcd, pszSrcFile, __LINE__);
3086# ifdef FORTIFY
3087 Fortify_LeaveScope();
3088# endif
3089 hwndFrame = (HWND) 0;
3090 }
3091 else {
3092 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3093 if (ParentIsDesktop(hwndFrame, hwndParent)) {
3094 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR), "VTree");
3095 FixSwitchList(hwndFrame, "VTree");
3096 }
3097 else {
3098 WinSetWindowText(hwndFrame, GetPString(IDS_TREETEXT));
3099 WinSetWindowText(WinWindowFromID(hwndFrame, FID_TITLEBAR),
3100 GetPString(IDS_TREETEXT));
3101 }
3102 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr, TreeCnrWndProc);
3103 // DbgMsg(pszSrcFile, __LINE__, "oldproc subclass %X", dcd->oldproc); // 05 Jul 07 SHL
3104 // fixme to document 01 test?
3105 if (dcd->oldproc == 0)
3106 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
3107 "WinSubclassWindow");
3108 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3109 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3110 }
3111 }
3112 }
3113 return hwndFrame;
3114}
3115
3116#pragma alloc_text(TREECNR,TreeCnrWndProc,TreeObjWndProc,TreeClientWndProc)
3117#pragma alloc_text(TREECNR,TreeFrameWndProc,TreeTitleWndProc,ShowTreeRec)
3118#pragma alloc_text(TREECNR,TreeStatProc,OpenButtonProc)
3119#pragma alloc_text(STARTUP,StartTreeCnr)
Note: See TracBrowser for help on using the repository browser.