source: trunk/dll/collect.c@ 1741

Last change on this file since 1741 was 1741, checked in by Gregg Young, 12 years ago

Fix warn readonly yes don't ask to work when recursing directories.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 87.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: collect.c 1741 2014-02-22 23:32:04Z gyoung $
5
6 Collector
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2003, 2012 Steven H. Levine
10
11 15 Oct 02 MK Baseline
12 10 Jan 04 SHL Avoid -1L byte counts
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 24 May 05 SHL Rework Win_Error usage
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 25 May 05 SHL Rework for FillInRecordFromFFB
18 05 Jun 05 SHL Use QWL_USER
19 06 Jun 05 SHL Indent -i2
20 06 Jun 05 SHL Make savedSortFlags static to avoid referencing garbage
21 24 Oct 05 SHL Sanitize handle references
22 24 Oct 05 SHL CollectorCnrWndProc: avoid excess writes to Status2 window
23 10 Nov 05 SHL CollectorCnrWndProc: correct missing button window updates
24 14 Jul 06 SHL Use Runtime_Error
25 27 Jul 06 SHL Avoid shutdown hang - pre3 typo
26 29 Jul 06 SHL Use xfgets_bstripcr
27 15 Aug 06 SHL Don't write garbage to CollectorFilter INI entry
28 15 Aug 06 SHL Rework SetMask args
29 18 Aug 06 SHL CollectorCnrWndProc: avoid freeing NULL pointer
30 31 Aug 06 SHL Disable Utilities->Seek and scan menu while busy
31 31 Aug 06 SHL Correct stop scan context menu enable/disable
32 30 Mar 07 GKY Remove GetPString for window class names
33 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
34 06 Apr 07 GKY Add some error checking in drag/drop
35 19 Apr 07 SHL Use FreeDragInfoData. Add more drag/drop error checks.
36 12 May 07 SHL Use dcd->ulItemsToUnHilite
37 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
38 05 Jul 07 SHL CollectorCnrWndProc: just warn if busy
39 02 Aug 07 SHL Sync with CNRITEM mods
40 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
41 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
42 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
43 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
44 10 Jan 08 SHL Sync with CfgDlgProc mods
45 10 Feb 08 GKY Implement bubble help for bitmap menu items
46 15 Feb 08 SHL Sync with settings menu rework
47 15 Feb 08 GKY Fix attempt to free container items that were never inserted
48 15 Feb 08 GKY Fix "collect" so it updates recollected files and unhides them if needed
49 29 Feb 08 GKY Use xfree where appropriate
50 06 Jul 08 GKY Update delete/undelete to include move to and open XWP trashcan
51 11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
52 all the details view settings (both the global variables and those in the
53 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
54 20 Jul 08 GKY Add save/append filename to clipboard.
55 Change menu wording to make these easier to find
56 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
57 less than 10 KiB (It hangs and can't be closed)
58 10 Dec 08 SHL Integrate exception handler support
59 26 Dec 08 GKY Fixed DROPHELP to check for copy as default is action is DO_DEFAULT
60 01 Jan 09 GKY Add Seek and Scan to drives & directory context menus pass drive/dir as search root
61 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
62 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
63 07 Feb 09 GKY Add *DateFormat functions to format dates based on locale
64 07 Feb 09 GKY Move repeated strings to PCSZs.
65 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
66 08 Mar 09 GKY Additional strings move to PCSZs in init.c
67 06 Jun 09 GKY Add option to show file system type or drive label in tree
68 12 Jul 09 GKY Add szFSType to FillInRecordFromFSA use to bypass EA scan and size formatting
69 for tree container
70 13 Jul 09 GKY Fixed double free of memory buffer in UM_COLLECTFROMFILE
71 15 Sep 09 SHL Use UM_GREP when passing pathname
72 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
73 23 Oct 10 GKY Add menu items for opening directory cnrs based on path of selected item
74 including the option to use walk directories to select path
75 28 May 11 GKY Fixed trap caused by passing a nonexistant pci to FillInRecordFromFFB in
76 UM_COLLECT because pci is limited to 65535 files. (nRecord is a USHORT)
77 29 May 11 SHL Rework UM_COLLECT >65K records logic to not require double loop
78 29 May 11 SHL Tweak UM_COLLECT to bypass FindCnrRecord when container initially empty
79 08 Aug 11 SHL Rework UM_COLLECT to avoid spurious container items free
80 13 Aug 11 GKY Have file count and KIBs update at the same time
81 04 Aug 12 GKY Changes to use Unlock to unlock files if Unlock.exe is in path both from menu and as part of copy, move and
82 delete operations
83 05 Sep 12 SHL Correct UM_COLLECTFROMFILE bad list file reporting
84 13 Dec 13 SHL CollectorCnrWndProc IDM_FILTER: avoid exception on missing fileName
85 22 Feb 14 GKY Fix warn readonly yes don't ask to work when recursing directories.
86
87***********************************************************************/
88
89#include <stdlib.h>
90#include <string.h>
91#include <ctype.h>
92#include <share.h>
93#include <limits.h> // USHRT_MAX
94// #include <process.h> // _beginthread
95
96#define INCL_DOS // QSV_MS_COUNT
97#define INCL_WIN
98#define INCL_DOSERRORS
99#define INCL_LONGLONG
100
101#include "fm3dll.h"
102#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
103#include "dircnrs.h" // Data declaration(s)
104#include "info.h" // Data declaration(s)
105#include "init.h" // Data declaration(s)
106#include "fm3dlg.h"
107#include "fm3str.h"
108#include "mle.h"
109#include "grep.h"
110#include "comp.h"
111#include "arccnrs.h" // StartArcCnr
112#include "filldir.h" // EmptyCnr...
113#include "strutil.h" // GetPString
114#include "errutil.h" // Runtime_Error
115#include "tmrsvcs.h" // ITIMER_DESC
116#include "notebook.h" // CfgDlgProc
117#include "command.h" // RunCommand
118#include "worker.h" // Action, MassAction
119#include "notify.h" // AddNote
120#include "misc.h" // AdjustCnrColsForPref, AdjustDetailsSwitches, CnrDirectEdit,
121 // LoadDetailsSwitches, OpenEdit, QuickPopup, SayFilter
122 // SaySort, SayView, SetCnrCols, SetDetailsSwitches
123 // SetSortChecks, SetViewMenu, disable_menuitem, CheckMenu
124 // CurrentRecord, DrawTargetEmphasis, IsFm2Window
125#include "chklist.h" // CenterOverWindow, DropListProc
126#include "collect.h"
127#include "common.h" // CommonCnrProc, CommonCreateTextChildren, CommonFrameWndProc
128 // CommonTextPaint
129#include "select.h" // DeselectAll, HideAll, RemoveAll, SelectAll, SelectList
130#include "dirsize.h" // DirSizeProc
131#include "grep2.h" // GrepDlgProc
132#include "mainwnd.h" // MakeBubble
133#include "objwin.h" // MakeObjWin
134#include "saveclip.h" // SaveListDlgProc
135#include "findrec.h" // ShowCnrRecord
136#include "sortcnr.h" // SortCollectorCnr
137#include "seeall.h" // StartSeeAll
138#include "update.h" // UpdateCnrList, UpdateCnrRecord
139#include "droplist.h" // CheckPmDrgLimit
140#include "common.h" // CommonTextButton, CommonTextProc
141#include "presparm.h" // CopyPresParams
142#include "defview.h" // DefaultViewKeys
143#include "draglist.h" // DoFileDrag, FreeDragInfoData
144#include "systemf.h" // ExecOnList
145#include "filter.h" // Filter
146#include "findrec.h" // FindCnrRecord
147#include "shadow.h" // OpenObject
148#include "mkdir.h" // PMMkDir
149#include "valid.h" // ParentIsDesktop
150#include "viewer.h" // StartMLEEditor
151#include "newview.h" // StartViewer
152#include "undel.h" // UndeleteDlgProc
153#include "i18nutil.h" // commafmt
154#include "getnames.h" // insert_filename
155#include "select.h" // InvertAll
156#include "strips.h" // bstrip
157#include "wrappers.h" // xDosFindFirst
158#include "fortify.h"
159#include "excputil.h" // xbeginthread
160#include "walkem.h" // WalkAllDlgProc
161#include "copyf.h" // ignorereadonly
162
163// Data definitions
164#pragma data_seg(GLOBAL1)
165HWND CollectorCnrMenu;
166HWND hwndStatus2;
167
168#pragma data_seg(GLOBAL2)
169INT CollectorsortFlags;
170
171#pragma data_seg(DATA1)
172static PSZ pszSrcFile = __FILE__;
173
174MRESULT EXPENTRY CollectorFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
175 MPARAM mp2)
176{
177 return CommonFrameWndProc(COLLECTOR_CNR, hwnd, msg, mp1, mp2);
178}
179
180MRESULT EXPENTRY CollectorTextProc(HWND hwnd, ULONG msg, MPARAM mp1,
181 MPARAM mp2)
182{
183 DIRCNRDATA *dcd;
184
185 static BOOL emphasized = FALSE;
186 static HWND hwndButtonPopup = (HWND) 0;
187 static ULONG timestamp = ULONG_MAX;
188 static USHORT lastid = 0;
189
190 switch (msg) {
191 case WM_CREATE:
192 return CommonTextProc(hwnd, msg, mp1, mp2);
193
194 case UM_CONTEXTMENU:
195 case WM_CONTEXTMENU:
196 {
197 USHORT id;
198
199 id = WinQueryWindowUShort(hwnd, QWS_ID);
200 switch (id) {
201 case DIR_SELECTED:
202 case DIR_VIEW:
203 case DIR_SORT:
204 {
205 POINTL ptl = { 0, 0 };
206 SWP swp;
207
208 if (hwndButtonPopup)
209 WinDestroyWindow(hwndButtonPopup);
210 if (id == lastid) {
211 ULONG check;
212
213 DosQuerySysInfo(QSV_MS_COUNT,
214 QSV_MS_COUNT, &check, sizeof(check));
215 if (check < timestamp + 500) {
216 lastid = 0;
217 goto MenuAbort;
218 }
219 }
220 hwndButtonPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
221 if (hwndButtonPopup) {
222 WinSetWindowUShort(hwndButtonPopup, QWS_ID, id);
223 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
224 QW_PARENT),
225 COLLECTOR_CNR), QWL_USER);
226 if (id == DIR_VIEW) {
227 if (dcd) {
228 SetViewMenu(hwndButtonPopup, dcd->flWindowAttr);
229 SetDetailsSwitches(hwndButtonPopup, &dcd->ds);
230 CopyPresParams(hwndButtonPopup, hwnd);
231 }
232
233 // don't have tree view in collector
234 WinSendMsg(hwndButtonPopup,
235 MM_DELETEITEM,
236 MPFROM2SHORT(IDM_TREEVIEW, FALSE), MPVOID);
237
238 }
239 else if (id == DIR_SORT) {
240 if (dcd)
241 SetSortChecks(hwndButtonPopup, dcd->sortFlags);
242 }
243 ptl.x = 0;
244 if (WinPopupMenu(HWND_OBJECT,
245 HWND_OBJECT,
246 hwndButtonPopup, -32767, -32767, 0, 0)) {
247 WinQueryWindowPos(hwndButtonPopup, &swp);
248 ptl.y = -(swp.cy + 2);
249 }
250 else {
251 WinQueryWindowPos(hwnd, &swp);
252 ptl.y = swp.cy + 2;
253 }
254 if (WinPopupMenu(hwnd,
255 hwnd,
256 hwndButtonPopup,
257 ptl.x,
258 ptl.y,
259 0,
260 PU_HCONSTRAIN | PU_VCONSTRAIN |
261 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
262 CenterOverWindow(hwndButtonPopup);
263 PaintRecessedWindow(hwnd, NULLHANDLE, FALSE, FALSE);
264 }
265 }
266 }
267 break;
268 default:
269 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
270 COLLECTOR_CNR),
271 WM_CONTROL,
272 MPFROM2SHORT(COLLECTOR_CNR, CN_CONTEXTMENU), MPVOID);
273 break;
274 }
275 }
276 MenuAbort:
277 if (msg == UM_CONTEXTMENU)
278 return 0;
279 break;
280
281 case WM_MENUEND:
282 if (hwndButtonPopup == (HWND) mp2) {
283 lastid = WinQueryWindowUShort((HWND) mp2, QWS_ID);
284 WinDestroyWindow(hwndButtonPopup);
285 hwndButtonPopup = (HWND) 0;
286 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &timestamp,
287 sizeof(timestamp));
288 switch (lastid) {
289 case DIR_SELECTED:
290 case DIR_VIEW:
291 case DIR_SORT:
292 PaintRecessedWindow(hwnd, NULLHANDLE, TRUE, FALSE);
293 break;
294 }
295 }
296 break;
297
298 case WM_COMMAND:
299 {
300 DIRCNRDATA *dcd;
301 MRESULT mr;
302
303 mr = WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,
304 QW_PARENT),
305 COLLECTOR_CNR), msg, mp1, mp2);
306 if (hwndButtonPopup &&
307 SHORT1FROMMP(mp1) > IDM_DETAILSTITLES &&
308 SHORT1FROMMP(mp1) < IDM_DETAILSSETUP) {
309 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
310 QW_PARENT),
311 COLLECTOR_CNR), QWL_USER);
312 if (dcd)
313 SetDetailsSwitches(hwndButtonPopup, &dcd->ds);
314 }
315 return mr;
316 }
317
318 case WM_MOUSEMOVE:
319 {
320 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
321 PCSZ s = NULL;
322
323 if (fOtherHelp) {
324 if ((!hwndBubble ||
325 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
326 !WinQueryCapture(HWND_DESKTOP)) {
327 switch (id) {
328 case DIR_SELECTED:
329 s = GetPString(IDS_COLSELECTEDHELP);
330 break;
331 case DIR_TOTALS:
332 s = GetPString(IDS_COLTOTALSHELP);
333 break;
334 case DIR_VIEW:
335 s = GetPString(IDS_DIRCNRVIEWHELP);
336 break;
337 case DIR_SORT:
338 s = GetPString(IDS_DIRCNRSORTHELP);
339 break;
340 case DIR_FILTER:
341 s = GetPString(IDS_DIRCNRFILTERHELP);
342 break;
343 default:
344 break;
345 }
346 if (s)
347 MakeBubble(hwnd, TRUE, s);
348 else if (hwndBubble)
349 WinDestroyWindow(hwndBubble);
350 }
351 }
352 switch (id) {
353 case DIR_FILTER:
354 case DIR_SORT:
355 case DIR_VIEW:
356 case DIR_SELECTED:
357 return CommonTextButton(hwnd, msg, mp1, mp2);
358 }
359 }
360 break;
361
362 case WM_BUTTON3UP:
363 case WM_BUTTON1UP:
364 case WM_BUTTON3DOWN:
365 case WM_BUTTON1DOWN:
366 {
367 USHORT id;
368
369 id = WinQueryWindowUShort(hwnd, QWS_ID);
370 switch (id) {
371 case DIR_FILTER:
372 case DIR_SORT:
373 case DIR_VIEW:
374 case DIR_SELECTED:
375 return CommonTextButton(hwnd, msg, mp1, mp2);
376 }
377 }
378 break;
379
380 case UM_CLICKED:
381 case UM_CLICKED3:
382 {
383 USHORT id, cmd = 0;
384
385 id = WinQueryWindowUShort(hwnd, QWS_ID);
386 switch (id) {
387 case DIR_VIEW:
388 case DIR_SORT:
389 case DIR_SELECTED:
390 PostMsg(hwnd, UM_CONTEXTMENU, MPVOID, MPVOID);
391 break;
392 case DIR_FILTER:
393 cmd = IDM_FILTER;
394 break;
395 default:
396 break;
397 }
398 if (cmd)
399 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
400 COLLECTOR_CNR),
401 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
402 }
403 return 0;
404
405 case DM_DROP:
406 case DM_DRAGOVER:
407 case DM_DRAGLEAVE:
408 case DM_DROPHELP:
409 if (msg == DM_DRAGOVER) {
410 if (!emphasized) {
411 emphasized = TRUE;
412 DrawTargetEmphasis(hwnd, emphasized);
413 }
414 }
415 else {
416 if (emphasized) {
417 emphasized = FALSE;
418 DrawTargetEmphasis(hwnd, emphasized);
419 }
420 }
421 {
422 CNRDRAGINFO cnd;
423 USHORT dcmd;
424
425 switch (msg) {
426 case DM_DROP:
427 dcmd = CN_DROP;
428 break;
429 case DM_DRAGOVER:
430 dcmd = CN_DRAGOVER;
431 break;
432 case DM_DRAGLEAVE:
433 dcmd = CN_DRAGLEAVE;
434 break;
435 case DM_DROPHELP:
436 dcmd = CN_DROPHELP;
437 break;
438 }
439 memset(&cnd, 0, sizeof(cnd));
440 cnd.pDragInfo = (PDRAGINFO) mp1;
441 cnd.pRecord = NULL;
442 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_CONTROL,
443 MPFROM2SHORT(COLLECTOR_CNR, dcmd), MPFROMP(&cnd));
444 }
445 }
446 return PFNWPStatic(hwnd, msg, mp1, mp2);
447}
448
449MRESULT EXPENTRY CollectorClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
450 MPARAM mp2)
451{
452 switch (msg) {
453 case UM_CONTAINERHWND:
454 return MRFROMLONG(WinWindowFromID(hwnd, COLLECTOR_CNR));
455
456 case UM_VIEWSMENU:
457 return MRFROMLONG(CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP));
458
459 case MM_PORTHOLEINIT:
460 case WM_INITMENU:
461 case UM_INITMENU:
462 case UM_CONTAINER_FILLED:
463 case UM_FILESMENU:
464 case UM_UPDATERECORD:
465 case UM_UPDATERECORDLIST:
466 return WinSendMsg(WinWindowFromID(hwnd, COLLECTOR_CNR), msg, mp1, mp2);
467
468 case WM_PSETFOCUS:
469 case WM_SETFOCUS:
470 if (mp2)
471 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
472 break;
473
474 case UM_FOCUSME:
475 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, COLLECTOR_CNR));
476 break;
477
478 case WM_PAINT:
479 {
480 HPS hps;
481 RECTL rcl;
482
483 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
484 if (hps) {
485 WinQueryWindowRect(hwnd, &rcl);
486 WinFillRect(hps, &rcl, CLR_PALEGRAY);
487 CommonTextPaint(hwnd, hps);
488 WinEndPaint(hps);
489 }
490 }
491 break;
492
493 case UM_SIZE:
494 case WM_SIZE:
495 if (msg == UM_SIZE) {
496 SWP swp;
497
498 WinQueryWindowPos(hwnd, &swp);
499 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
500 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
501 }
502 {
503 USHORT cx, cy, bx;
504
505 cx = SHORT1FROMMP(mp2);
506 cy = SHORT2FROMMP(mp2);
507 WinSetWindowPos(WinWindowFromID(hwnd, COLLECTOR_CNR), HWND_TOP,
508 0, 0, cx, cy - 24, SWP_SHOW | SWP_MOVE | SWP_SIZE);
509 WinSetWindowPos(WinWindowFromID(hwnd, DIR_TOTALS), HWND_TOP,
510 2,
511 cy - 22,
512 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
513 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SELECTED), HWND_TOP,
514 2 + (cx / 3) + 2,
515 cy - 22,
516 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
517 bx = (cx - (2 + (((cx / 3) + 2) * 2))) / 3;
518 WinSetWindowPos(WinWindowFromID(hwnd, DIR_VIEW), HWND_TOP,
519 2 + (((cx / 3) + 2) * 2),
520 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
521 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SORT), HWND_TOP,
522 2 + (((cx / 3) + 2) * 2) + bx,
523 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
524 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FILTER), HWND_TOP,
525 2 + (((cx / 3) + 2) * 2) + (bx * 2),
526 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
527 }
528 CommonTextPaint(hwnd, NULLHANDLE);
529 if (msg == UM_SIZE) {
530 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
531 SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE);
532 return 0;
533 }
534 break;
535
536 case UM_COMMAND:
537 case WM_COMMAND:
538 case WM_CONTROL:
539 case WM_CLOSE:
540 return WinSendMsg(WinWindowFromID(hwnd, COLLECTOR_CNR), msg, mp1, mp2);
541 }
542 return WinDefWindowProc(hwnd, msg, mp1, mp2);
543}
544
545MRESULT EXPENTRY CollectorObjWndProc(HWND hwnd, ULONG msg,
546 MPARAM mp1, MPARAM mp2)
547{
548 ULONG size;
549 DIRCNRDATA *dcd;
550
551 switch (msg) {
552 case WM_CREATE:
553 // 18 Jul 08 SHL fixme to doc why messsage gets lost
554 DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2); // 18 Jul 08 SHL fixme
555 break;
556
557 case DM_PRINTOBJECT:
558 return MRFROMLONG(DRR_TARGET);
559
560 case DM_DISCARDOBJECT:
561 dcd = INSTDATA(hwnd);
562 if (fFM2Deletes && dcd) {
563 LISTINFO *li;
564 CNRDRAGINFO cni;
565
566 cni.pRecord = NULL;
567 cni.pDragInfo = (PDRAGINFO) mp1;
568 li = DoFileDrop(dcd->hwndCnr, NULL, FALSE, MPVOID, MPFROMP(&cni));
569 CheckPmDrgLimit(cni.pDragInfo);
570 if (li) {
571 li->type = fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE;
572 if (!PostMsg(hwnd, UM_MASSACTION, MPFROMP(li), MPVOID))
573 FreeListInfo(li);
574 else
575 return MRFROMLONG(DRR_SOURCE);
576 }
577 }
578 return MRFROMLONG(DRR_TARGET);
579
580 case UM_UPDATERECORDLIST:
581 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
582 if (dcd && mp1) {
583 INT numentries = 0;
584 CHAR **list = (CHAR **) mp1;
585
586 while (list[numentries])
587 numentries++;
588 if (numentries)
589 UpdateCnrList(dcd->hwndCnr, list, numentries, FALSE, dcd);
590 }
591 return 0;
592
593 case UM_SETUP:
594# ifdef FORTIFY
595 Fortify_EnterScope();
596# endif
597 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
598 if (dcd) {
599# ifdef FORTIFY
600 Fortify_BecomeOwner(dcd);
601# endif
602 // set unique id
603 WinSetWindowUShort(hwnd,
604 QWS_ID,
605 COLLECTOROBJ_FRAME + (COLLECTOR_FRAME - dcd->id));
606 dcd->hwndObject = hwnd;
607 // 09 Feb 08 SHL fixme to be sure applet does not really need this
608 // if (ParentIsDesktop(hwnd, dcd->hwndParent))
609 // DosSleep(100); //05 Aug 07 GKY 250
610 }
611 else
612 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
613 return 0;
614
615 case UM_COMMAND:
616 if (mp1) {
617 LISTINFO *li = (LISTINFO *) mp1;
618
619 switch (li->type) {
620 case IDM_DOITYOURSELF:
621 case IDM_APPENDTOCLIP:
622 case IDM_APPENDTOCLIPFILENAME:
623 case IDM_SAVETOCLIP:
624 case IDM_ARCHIVE:
625 case IDM_ARCHIVEM:
626 case IDM_VIEW:
627 case IDM_VIEWTEXT:
628 case IDM_VIEWBINARY:
629 case IDM_VIEWARCHIVE:
630 case IDM_EDIT:
631 case IDM_EDITTEXT:
632 case IDM_EDITBINARY:
633 case IDM_OBJECT:
634 case IDM_SHADOW:
635 case IDM_SHADOW2:
636 case IDM_PRINT:
637 case IDM_ATTRS:
638 case IDM_DELETE:
639 case IDM_PERMDELETE:
640 case IDM_FAKEEXTRACT:
641 case IDM_FAKEEXTRACTM:
642 case IDM_MCIPLAY:
643 case IDM_UPDATE:
644 if (li->type == IDM_DELETE)
645 ignorereadonly = FALSE;
646 if (PostMsg(hwnd, UM_MASSACTION, mp1, mp2))
647 return (MRESULT) TRUE;
648 break;
649 default:
650 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
651 return (MRESULT) TRUE;
652 }
653 }
654 return 0;
655
656 case UM_COLLECT:
657 DosError(FERR_DISABLEHARDERR);
658 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
659 if (dcd) {
660 LISTINFO *li = (LISTINFO *) mp1;
661 INT x;
662 FILEFINDBUF4L fb4;
663 HDIR hdir;
664 ULONG ulMaxFiles;
665 CHAR fullname[CCHMAXPATH];
666
667 if (!hwndStatus) {
668 WinSetWindowText(WinWindowFromID(dcd->hwndClient, DIR_SELECTED),
669 (CHAR *) GetPString(IDS_COLLECTINGTEXT));
670 }
671 else {
672 if (WinQueryFocus(HWND_DESKTOP) == dcd->hwndCnr)
673 WinSetWindowText(hwndStatus, (CHAR *) GetPString(IDS_COLLECTINGTEXT));
674 }
675
676 for (ulMaxFiles = 0; li->list[ulMaxFiles]; ulMaxFiles++) ; // Count
677
678 if (ulMaxFiles) {
679 PCNRITEM pci = NULL;
680 PCNRITEM pciFirst = NULL;
681 PCNRITEM pciPrev;
682 ULONG nm;
683 ULONG ulRecsAtStart;
684 ULONG ulRecsToInsert;
685 ULONG ulRecsInserted = 0;
686 ULONGLONG ullTotalBytes = 0;
687 BOOL checkToInsert = FALSE;
688 CNRINFO cnri;
689 RECORDINSERT ri;
690 ITIMER_DESC itdSleep = { 0 }; // 06 Feb 08 SHL
691
692 InitITimer(&itdSleep, 500); // Sleep every 500 mSec
693
694 // Query initial count
695 // 2011-05-29 SHL fixme to be utility
696 memset(&cnri, 0, sizeof(CNRINFO));
697 cnri.cb = sizeof(CNRINFO);
698 if (WinSendMsg(dcd->hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
699 MPFROMLONG(sizeof(CNRINFO)))) {
700 ulRecsAtStart = cnri.cRecords;
701 }
702 else {
703 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, PCSZ_QUERYCNRINFO);
704 ulRecsAtStart = 0;
705 }
706
707 for (x = 0; li->list[x]; x++) {
708
709 // Allocate more container items if needed
710 if (!pci) {
711 ulRecsToInsert = ulMaxFiles - ulRecsInserted; // Left to do
712 if (ulRecsToInsert > USHRT_MAX)
713 ulRecsToInsert = USHRT_MAX; // Avoid USHORT overflows
714 pci = WinSendMsg(dcd->hwndCnr, CM_ALLOCRECORD,
715 MPFROMLONG(EXTRA_RECORD_BYTES),
716 MPFROMLONG(ulRecsToInsert));
717 pciFirst = pci;
718 pciPrev = NULL;
719 if (!pci) {
720 Runtime_Error(pszSrcFile, __LINE__, PCSZ_CM_ALLOCRECORD);
721 break;
722 }
723 } // if need allocate
724
725 nm = 1;
726 hdir = HDIR_CREATE;
727 DosError(FERR_DISABLEHARDERR);
728 // If started with records in container, check if updating existing record
729 if (ulRecsAtStart &&
730 FindCnrRecord(dcd->hwndCnr,
731 li->list[x],
732 NULL,
733 FALSE,
734 FALSE,
735 TRUE))
736 {
737 // Updating existing record
738 PCNRITEM pciUpd = UpdateCnrRecord(dcd->hwndCnr, li->list[x], FALSE, dcd);
739 if (!pciUpd) {
740 // file has disappeared
741 Runtime_Error(pszSrcFile, __LINE__, "pci NULL for list[%u]", x);
742 }
743 else {
744 // Update OK
745 if (Filter((PMINIRECORDCORE) pciUpd, (PVOID) & dcd->mask)) {
746 pciUpd->rc.flRecordAttr &= ~CRA_FILTERED; // Ensure visible
747 // 2011-05-29 SHL fixme to check fail
748 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
749 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
750 }
751 }
752 ulMaxFiles--; // No insert needed
753 checkToInsert = TRUE;
754 }
755 // Add new entry maybe
756 else if (*li->list[x] &&
757 !DosQueryPathInfo(li->list[x], FIL_QUERYFULLNAME,
758 fullname, sizeof(fullname)) &&
759 !IsRoot(fullname) &&
760 !xDosFindFirst(fullname,
761 &hdir,
762 FILE_NORMAL | FILE_DIRECTORY |
763 FILE_ARCHIVED | FILE_SYSTEM |
764 FILE_HIDDEN | FILE_READONLY,
765 &fb4, sizeof(fb4), &nm, FIL_QUERYEASIZEL))
766 {
767 // OK to add
768 DosFindClose(hdir);
769 priority_normal();
770 *fb4.achName = 0;
771 ullTotalBytes += FillInRecordFromFFB(dcd->hwndCnr,
772 pci,
773 fullname, &fb4, FALSE, dcd);
774 pciPrev = pci;
775 pci = (PCNRITEM) pci->rc.preccNextRecord;
776 }
777 else {
778 // DosQueryPathInfo etc. failed - try to recover
779 Runtime_Error(pszSrcFile, __LINE__, "DosQueryPathInfo failed for %s", fullname);
780 ulMaxFiles--; // Nothing to insert
781 checkToInsert = TRUE;
782 }
783
784 if (checkToInsert) {
785 checkToInsert = FALSE;
786 // Remove extra records from chain
787 while (ulRecsInserted + ulRecsToInsert > ulMaxFiles) {
788 PCNRITEM pciNext = (PCNRITEM)pci->rc.preccNextRecord;
789 if (pciPrev)
790 pciPrev->rc.preccNextRecord = (PMINIRECORDCORE)pciNext;
791 else
792 pciFirst = pciNext;
793 pci->pszFileName = NullStr; // Avoid spurious complaints
794 FreeCnrItem(dcd->hwndCnr, pci);
795 pci = pciNext;
796 ulRecsToInsert--; // Remember gone
797 }
798 }
799
800 // Check if time to insert
801 if (!pci) {
802 // All allocated CNRITEMs filled
803 if (ulRecsToInsert) {
804 // Have CNRITEMs to insert
805 memset(&ri, 0, sizeof(RECORDINSERT));
806 ri.cb = sizeof(RECORDINSERT);
807 ri.pRecordOrder = (PRECORDCORE) CMA_END;
808 ri.pRecordParent = (PRECORDCORE) 0;
809 ri.zOrder = (ULONG) CMA_TOP;
810 ri.cRecordsInsert = ulRecsToInsert;
811 ri.fInvalidateRecord = TRUE;
812 WinSendMsg(dcd->hwndCnr,
813 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
814 // 2011-05-29 SHL fixme to complain on failure
815 PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
816 ulRecsInserted += ulRecsToInsert;
817 dcd->ullTotalBytes = ullTotalBytes;
818 pciFirst = NULL;
819 ulRecsToInsert = 0;
820 }
821 } // if need CM_INSERTRECORD
822 SleepIfNeeded(&itdSleep, 1); // 09 Feb 08 SHL
823 } // for
824
825 // Clean up in case stopped early by error
826 if (pci)
827 Runtime_Error(pszSrcFile, __LINE__, "pci not NULL");
828
829 if (pciFirst) {
830 Runtime_Error(pszSrcFile, __LINE__, "pciFirst not NULL");
831 // 2011-08-08 SHL fixme to initialze pszFileName to prevent spurious complaints
832 FreeCnrItemList(dcd->hwndCnr, pciFirst);
833 }
834
835 } // if have files
836
837 if (dcd->flWindowAttr & CV_DETAIL)
838 WinSendDlgItemMsg(hwnd,
839 COLLECTOR_CNR,
840 CM_INVALIDATERECORD,
841 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
842 } // if dcd
843 return 0;
844
845 case UM_COLLECTFROMFILE:
846 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
847# ifdef FORTIFY
848 Fortify_EnterScope();
849# endif
850
851 if (dcd && mp1) {
852 // mp1 is pszFileName, mp2 is unused
853 FILESTATUS4L fs4;
854 PCNRITEM pci;
855 RECORDINSERT ri;
856 CHAR fullname[1024], *p;
857 FILE *fp;
858 ULONG errs = 0;
859 BOOL first = TRUE; // 2012-09-05 SHL
860 size_t c;
861 CHAR *moder = "r";
862
863# ifdef FORTIFY
864 Fortify_BecomeOwner(mp1);
865# endif
866
867 fp = xfsopen((CHAR *)mp1, moder, SH_DENYNO, pszSrcFile, __LINE__, TRUE);
868 if (fp) {
869 while (!feof(fp)) {
870 // Avoid too much noise if collecting from binary file - oops
871 if (!fgets(fullname, sizeof(fullname), fp)) {
872 if (ferror(fp))
873 Runtime_Error(pszSrcFile, __LINE__, "fgets");
874 break;
875 }
876
877 c = strlen(fullname);
878 if (c + 1 >= sizeof(fullname))
879 errs++; // Name too long
880 else if (!c || (fullname[c - 1] != '\n' && fullname[c - 1] != '\r'))
881 errs++; // Probably reading a binary file
882 else {
883 bstripcr(fullname);
884
885 if (*fullname == '\"') {
886 // Strip quotes
887 memmove(fullname, fullname + 1, strlen(fullname) + 1);
888 lstrip(fullname);
889 p = strchr(fullname, '\"');
890 if (p)
891 *p = 0;
892 rstrip(fullname);
893 }
894 else {
895 // Strip trailing spaces
896 p = strchr(fullname, ' ');
897 if (p)
898 *p = 0;
899 }
900 // fullname now contains name of file to collect
901 DosError(FERR_DISABLEHARDERR);
902 if (FindCnrRecord(dcd->hwndCnr,
903 fullname,
904 NULL,
905 FALSE,
906 FALSE,
907 TRUE)) {
908 // Already in container
909 pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd);
910 if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) {
911 pci->rc.flRecordAttr &= ~CRA_FILTERED;
912 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
913 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
914 }
915 }
916 else if (IsFullName(fullname) &&
917 !IsRoot(fullname) &&
918 !DosQueryPathInfo(fullname,
919 FIL_QUERYEASIZEL,
920 &fs4,
921 sizeof(fs4))) {
922 // Add to collector containter
923 pci = WinSendMsg(dcd->hwndCnr,
924 CM_ALLOCRECORD,
925 MPFROMLONG(EXTRA_RECORD_BYTES),
926 MPFROMLONG(1));
927 if (pci) {
928 dcd->ullTotalBytes += FillInRecordFromFSA(dcd->hwndCnr, pci,
929 fullname,
930 &fs4, FALSE, NULL, dcd);
931 memset(&ri, 0, sizeof(RECORDINSERT));
932 ri.cb = sizeof(RECORDINSERT);
933 ri.pRecordOrder = (PRECORDCORE) CMA_END;
934 ri.pRecordParent = (PRECORDCORE) 0;
935 ri.zOrder = (ULONG) CMA_TOP;
936 ri.cRecordsInsert = 1;
937 ri.fInvalidateRecord = TRUE;
938 WinSendMsg(dcd->hwndCnr, CM_INSERTRECORD,
939 MPFROMP(pci), MPFROMP(&ri));
940 }
941 }
942 else
943 errs++; // Something wrong with filename or file
944 }
945 if (errs > (first ? 0 : 50)) {
946 // prevent runaway on bad file
947 APIRET ret = saymsg(MB_YESNO, dcd->hwndCnr,
948 GetPString(IDS_COLLECTNOLISTHDRTEXT),
949 GetPString(IDS_COLLECTNOLISTTEXT),
950 (CHAR *)mp1);
951
952 if (ret == MBID_NO)
953 break; // Give up
954 if (!first)
955 errs = 0;
956 else
957 first = FALSE;
958 }
959 } // while not eof
960 fclose(fp);
961 } // if file opened
962 free(mp1);
963 }
964# ifdef FORTIFY
965 Fortify_LeaveScope();
966# endif
967 return 0;
968
969 case UM_SELECT:
970 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
971 if (dcd) {
972 switch (SHORT1FROMMP(mp1)) {
973 case IDM_SELECTLIST:
974 {
975 CHAR filename[CCHMAXPATH], *p, *pp;
976
977 strcpy(filename, PCSZ_STARDOTLST);
978 size = CCHMAXPATH;
979 PrfQueryProfileData(fmprof, appname, "SaveToListName", filename,
980 &size);
981 pp = strrchr(filename, '\\');
982 if (!pp)
983 pp = filename;
984 p = strrchr(pp, '.');
985 if (p && *(p + 1) && p > pp + 1) {
986 if (pp > filename)
987 pp++;
988 *pp = '*';
989 pp++;
990 if (p > pp)
991 memmove(pp, p, strlen(p) + 1);
992 }
993 if (insert_filename(hwnd, filename, FALSE, FALSE))
994 SelectList(dcd->hwndCnr, TRUE, FALSE, FALSE, NULL, filename,
995 NULL);
996 }
997 break;
998 case IDM_SELECTALL:
999 SelectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, FALSE);
1000 break;
1001 case IDM_DESELECTALL:
1002 DeselectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, FALSE);
1003 break;
1004 case IDM_SELECTALLFILES:
1005 SelectAll(dcd->hwndCnr, TRUE, FALSE, NULL, NULL, FALSE);
1006 break;
1007 case IDM_DESELECTALLFILES:
1008 DeselectAll(dcd->hwndCnr, TRUE, FALSE, NULL, NULL, FALSE);
1009 break;
1010 case IDM_SELECTALLDIRS:
1011 SelectAll(dcd->hwndCnr, FALSE, TRUE, NULL, NULL, FALSE);
1012 break;
1013 case IDM_DESELECTALLDIRS:
1014 DeselectAll(dcd->hwndCnr, FALSE, TRUE, NULL, NULL, FALSE);
1015 break;
1016 case IDM_DESELECTMASK:
1017 case IDM_SELECTMASK:
1018 {
1019 MASK mask;
1020 PCNRITEM pci = (PCNRITEM) mp2;
1021
1022 memset(&mask, 0, sizeof(MASK));
1023 mask.fNoAttribs = TRUE;
1024 mask.fNoDirs = TRUE;
1025 mask.fText = TRUE;
1026 strcpy(mask.prompt,
1027 GetPString((SHORT1FROMMP(mp1) == IDM_SELECTMASK) ?
1028 IDS_SELECTFILTERTEXT : IDS_DESELECTFILTERTEXT));
1029 if (pci && (INT) pci != -1)
1030 strcpy(mask.szMask, pci->pszFileName);
1031 if (WinDlgBox(HWND_DESKTOP, dcd->hwndCnr, PickMaskDlgProc,
1032 FM3ModHandle, MSK_FRAME, MPFROMP(&mask))) {
1033 if (SHORT1FROMMP(mp1) == IDM_SELECTMASK)
1034 SelectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, mask.szText,
1035 FALSE);
1036 else
1037 DeselectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, mask.szText,
1038 FALSE);
1039 }
1040 }
1041
1042 case IDM_DESELECTCLIP:
1043 case IDM_SELECTCLIP:
1044 {
1045 CHAR **list;
1046
1047 list = ListFromClipboard(hwnd);
1048 if (list) {
1049 SelectList(dcd->hwndCnr, TRUE, FALSE,
1050 (SHORT1FROMMP(mp1) == IDM_DESELECTCLIP),
1051 NULL, NULL, list);
1052 FreeList(list);
1053 }
1054 }
1055 break;
1056
1057 case IDM_INVERT:
1058 InvertAll(dcd->hwndCnr);
1059 break;
1060 }
1061 }
1062 return 0;
1063
1064 case UM_MASSACTION:
1065# ifdef FORTIFY
1066 Fortify_EnterScope();
1067# endif
1068 if (mp1) {
1069# ifdef FORTIFY
1070 Fortify_BecomeOwner(mp1);
1071# endif
1072 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1073 if (dcd) {
1074 WORKER *wk;
1075 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
1076 if (!wk)
1077 FreeListInfo((LISTINFO *) mp1);
1078 else {
1079 wk->size = sizeof(WORKER);
1080 wk->hwndCnr = dcd->hwndCnr;
1081 wk->hwndParent = dcd->hwndParent;
1082 wk->hwndFrame = dcd->hwndFrame;
1083 wk->hwndClient = dcd->hwndClient;
1084 wk->li = (LISTINFO *) mp1;
1085 strcpy(wk->directory, dcd->directory);
1086 if (xbeginthread(MassAction,
1087 122880,
1088 wk,
1089 pszSrcFile,
1090 __LINE__) == -1)
1091 {
1092 free(wk);
1093 FreeListInfo((LISTINFO *) mp1);
1094 }
1095 }
1096 }
1097 }
1098# ifdef FORTIFY
1099 DosSleep(1); // Let receiver take ownership
1100 Fortify_LeaveScope();
1101# endif
1102 return 0;
1103
1104 case UM_ACTION:
1105# ifdef FORTIFY
1106 Fortify_EnterScope();
1107# endif
1108 if (mp1) {
1109# ifdef FORTIFY
1110 Fortify_BecomeOwner(mp1);
1111# endif
1112 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1113 if (dcd) {
1114 WORKER *wk;
1115 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
1116 if (!wk)
1117 FreeListInfo((LISTINFO *) mp1);
1118 else {
1119 wk->size = sizeof(WORKER);
1120 wk->hwndCnr = dcd->hwndCnr;
1121 wk->hwndParent = dcd->hwndParent;
1122 wk->hwndFrame = dcd->hwndFrame;
1123 wk->hwndClient = dcd->hwndClient;
1124 wk->li = (LISTINFO *) mp1;
1125 strcpy(wk->directory, dcd->directory);
1126 if (xbeginthread(Action,
1127 122880,
1128 wk,
1129 pszSrcFile,
1130 __LINE__) == -1)
1131 {
1132 free(wk);
1133 FreeListInfo((LISTINFO *) mp1);
1134 }
1135 }
1136 }
1137 }
1138# ifdef FORTIFY
1139 DosSleep(1); // Let receiver take ownership
1140 Fortify_LeaveScope();
1141# endif
1142 return 0;
1143
1144 case WM_CLOSE:
1145 WinDestroyWindow(hwnd);
1146 break;
1147
1148 case WM_DESTROY:
1149 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1150 if (dcd) {
1151 INT x;
1152
1153 dcd->stopflag = 1;
1154 // Allow other threads to honor stop request
1155 for (x = 0; x < 100 && dcd->amextracted; x++)
1156 DosSleep(10);
1157 if (dcd->amextracted)
1158 Runtime_Error(pszSrcFile, __LINE__, "still busy");
1159 WinSendMsg(dcd->hwndCnr, UM_CLOSE, MPVOID, MPVOID);
1160 FreeList(dcd->lastselection);
1161 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); // 13 Apr 10 SHL Set NULL before freeing dcd
1162 free(dcd);
1163# ifdef FORTIFY
1164 Fortify_LeaveScope();
1165# endif
1166 }
1167 DosPostEventSem(CompactSem);
1168 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
1169 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
1170 break;
1171 }
1172 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1173}
1174
1175MRESULT EXPENTRY CollectorCnrWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1176 MPARAM mp2)
1177{
1178 DIRCNRDATA *dcd = INSTDATA(hwnd);
1179 ULONG size;
1180
1181 static INT savedSortFlags;
1182
1183 switch (msg) {
1184 case DM_PRINTOBJECT:
1185 return MRFROMLONG(DRR_TARGET);
1186
1187 case DM_DISCARDOBJECT:
1188 if (dcd)
1189 return WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1190 else
1191 return MRFROMLONG(DRR_TARGET);
1192
1193 case WM_CHAR:
1194 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1195 if (SHORT1FROMMP(mp1) & KC_KEYUP)
1196 return (MRESULT) TRUE;
1197 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
1198 switch (SHORT2FROMMP(mp2)) {
1199 case VK_DELETE:
1200 if ((shiftstate & KC_CTRL) == KC_CTRL)
1201 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_PERMDELETE, 0), MPVOID);
1202 else if ((shiftstate & KC_SHIFT) == KC_SHIFT)
1203 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_SAVETOCLIP, 0), MPVOID);
1204 else
1205 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
1206 break;
1207 }
1208 }
1209 if (shiftstate || fNoSearch)
1210 break;
1211 if (SHORT1FROMMP(mp1) & KC_CHAR) {
1212 ULONG thistime, len;
1213 SEARCHSTRING srch;
1214 PCNRITEM pci;
1215
1216 if (!dcd)
1217 break;
1218 switch (SHORT1FROMMP(mp2)) {
1219 case '\x1b':
1220 case '\r':
1221 case '\n':
1222 dcd->lasttime = 0;
1223 *dcd->szCommonName = 0;
1224 break;
1225 default:
1226 thistime = WinQueryMsgTime(WinQueryAnchorBlock(hwnd));
1227 if (thistime > dcd->lasttime + 1250)
1228 *dcd->szCommonName = 0;
1229 dcd->lasttime = thistime;
1230 if (SHORT1FROMMP(mp2) == ' ' && !dcd->szCommonName)
1231 break;
1232 KbdRetry:
1233 len = strlen(dcd->szCommonName);
1234 if (len >= CCHMAXPATH - 1) {
1235 *dcd->szCommonName = 0;
1236 len = 0;
1237 }
1238 dcd->szCommonName[len] = toupper(SHORT1FROMMP(mp2));
1239 dcd->szCommonName[len + 1] = 0;
1240 memset(&srch, 0, sizeof(SEARCHSTRING));
1241 srch.cb = sizeof(SEARCHSTRING);
1242 srch.pszSearch = dcd->szCommonName;
1243 srch.fsPrefix = TRUE;
1244 srch.fsCaseSensitive = FALSE;
1245 srch.usView = CV_ICON;
1246 pci = WinSendMsg(hwnd, CM_SEARCHSTRING, MPFROMP(&srch),
1247 MPFROMLONG(CMA_FIRST));
1248 if (pci && (INT) pci != -1) {
1249 USHORT attrib = CRA_CURSORED;
1250
1251 // make found item current item
1252 if (!stricmp(pci->pszFileName, dcd->szCommonName))
1253 attrib |= CRA_SELECTED;
1254 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
1255 MPFROM2SHORT(TRUE, attrib));
1256 // make sure that record shows in viewport
1257 ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
1258 return (MRESULT) TRUE;
1259 }
1260 else {
1261 if (SHORT1FROMMP(mp2) == ' ') {
1262 dcd->szCommonName[len] = 0;
1263 break;
1264 }
1265 *dcd->szCommonName = 0;
1266 dcd->lasttime = 0;
1267 if (len) // retry as first letter if no match
1268
1269 goto KbdRetry;
1270 }
1271 break;
1272 }
1273 }
1274 break;
1275
1276 case WM_MOUSEMOVE:
1277 case WM_BUTTON1UP:
1278 case WM_BUTTON2UP:
1279 case WM_BUTTON3UP:
1280 case WM_CHORD:
1281 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1282 break;
1283
1284 case WM_BUTTON1MOTIONEND:
1285 {
1286 CNRINFO cnri;
1287
1288 memset(&cnri, 0, sizeof(CNRINFO));
1289 cnri.cb = sizeof(CNRINFO);
1290 if (WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1291 MPFROMLONG(sizeof(CNRINFO)))) {
1292 if (cnri.flWindowAttr & CV_DETAIL)
1293 PrfWriteProfileData(fmprof, appname, "CollectorCnrSplitBar",
1294 (PVOID) & cnri.xVertSplitbar, sizeof(LONG));
1295 }
1296 }
1297 break;
1298
1299 case WM_PRESPARAMCHANGED:
1300 PresParamChanged(hwnd, PCSZ_COLLECTOR, mp1, mp2);
1301 break;
1302
1303 case UM_COMPARE:
1304 if (dcd && mp1 && mp2) {
1305 COMPARE *cmp;
1306 CHAR *leftdir = (CHAR *)mp1, *rightdir = (CHAR *)mp2;
1307
1308 if (!IsFile(leftdir) && !IsFile(rightdir)) {
1309 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
1310 if (cmp) {
1311 cmp->size = sizeof(COMPARE);
1312 strcpy(cmp->leftdir, leftdir);
1313 strcpy(cmp->rightdir, rightdir);
1314 cmp->hwndParent = dcd->hwndParent;
1315 cmp->dcd.hwndParent = dcd->hwndParent;
1316 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, CompareDlgProc,
1317 FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
1318 }
1319 }
1320 }
1321 return 0;
1322
1323 case UM_UPDATERECORDLIST:
1324 if (dcd && mp1)
1325 WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1326 return 0;
1327
1328 case UM_UPDATERECORD:
1329 if (dcd && mp1) {
1330 CHAR *filename;
1331
1332 filename = mp1;
1333 if (filename)
1334 UpdateCnrRecord(hwnd, filename, TRUE, dcd);
1335 }
1336 return 0;
1337
1338 case WM_SETFOCUS:
1339 // put name of our window on status line
1340 if (dcd && hwndStatus && mp2) {
1341 PCNRITEM pci = NULL;
1342
1343 if (fAutoView && hwndMain) {
1344 pci = WinSendMsg(hwnd,
1345 CM_QUERYRECORDEMPHASIS,
1346 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1347 if (pci && (INT) pci != -1 &&
1348 (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW)))
1349 WinSendMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName), MPVOID);
1350 else
1351 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1352 }
1353 if (dcd->amextracted)
1354 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1355 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1356 }
1357 break;
1358
1359 case UM_RESCAN:
1360 if (dcd) {
1361 CNRINFO cnri;
1362 CHAR s[CCHMAXPATH + 69], tb[81], tf[81], szDate[DATE_BUF_BYTES] *p;
1363 PCNRITEM pci = NULL;
1364
1365 memset(&cnri, 0, sizeof(CNRINFO));
1366 cnri.cb = sizeof(CNRINFO);
1367 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1368 MPFROMLONG(sizeof(CNRINFO)));
1369 dcd->totalfiles = cnri.cRecords;
1370 commafmt(tf, sizeof(tf), dcd->totalfiles);
1371 CommaFmtULL(tb, sizeof(tb), dcd->ullTotalBytes, ' ');
1372 sprintf(s, "%s / %s", tf, tb);
1373 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, s);
1374
1375 commafmt(tf, sizeof(tf), dcd->selectedfiles);
1376 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
1377 sprintf(s, "%s / %s", tf, tb);
1378 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
1379
1380 if (hwndStatus &&
1381 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
1382 if (hwndMain) {
1383 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1384 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1385 if (pci && (INT) pci != -1)
1386 PostMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName), MPVOID);
1387 else
1388 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1389 }
1390 if (!dcd->amextracted) {
1391 if (!fMoreButtons) {
1392 sprintf(s, " %s%s%s%s",
1393 GetPString(IDS_COLLECTORTEXT),
1394 *dcd->mask.szMask || dcd->mask.antiattr ||
1395 dcd->mask.attrFile != ALLATTRS ? " (" : NullStr,
1396 *dcd->mask.szMask ?
1397 dcd->mask.szMask :
1398 dcd->mask.antiattr ||
1399 dcd->mask.attrFile != ALLATTRS ?
1400 GetPString(IDS_ATTRTEXT) : NullStr,
1401 *dcd->mask.szMask || dcd->mask.antiattr ||
1402 dcd->mask.attrFile != ALLATTRS ?
1403 ")" : NullStr);
1404 }
1405 else
1406 strcpy(s, GetPString(IDS_COLLECTORTEXT));
1407 WinSetWindowText(hwndStatus, s);
1408 }
1409 if (!pci)
1410 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1411 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1412 if (pci && (INT) pci != -1) {
1413 BOOL fStatus2Used = FALSE;
1414
1415 if (fSplitStatus && hwndStatus2) {
1416 if (pci->attrFile & FILE_DIRECTORY)
1417 p = pci->pszFileName;
1418 else {
1419 if (!pci->pszFileName)
1420 Runtime_Error(pszSrcFile, __LINE__, "pci->pszFileName NULL for %p", pci);
1421 p = strrchr(pci->pszFileName, '\\');
1422 if (p) {
1423 if (*(p + 1))
1424 p++;
1425 else
1426 p = pci->pszFileName;
1427 }
1428 else
1429 p = pci->pszFileName;
1430 }
1431 CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
1432 if (!fMoreButtons) {
1433 DateFormat(szDate, pci->date);
1434 sprintf(s, " %s %s %02u%s%02u%s%02u [%s] %s",
1435 tb, szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
1436 TimeSeparator, pci->time.seconds, pci->pszDispAttr, p);
1437 }
1438 else {
1439 if (pci->cbFile + pci->easize > 1024)
1440 CommaFmtULL(tf, sizeof(tf), pci->cbFile + pci->easize, 'K');
1441 else
1442 *tf = 0;
1443 sprintf(s, GetPString(IDS_STATUSSIZETEXT),
1444 tb, *tf ? " (" : NullStr, tf, *tf ? ")" : NullStr);
1445 }
1446 WinSetWindowText(hwndStatus2, s);
1447 fStatus2Used = TRUE;
1448 }
1449 if (fMoreButtons) {
1450 WinSetWindowText(hwndName, pci->pszFileName);
1451 DateFormat(szDate, pci->date);
1452 sprintf(s, "%s %02u%s%02u%s%02u",
1453 szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
1454 TimeSeparator, pci->time.seconds);
1455 WinSetWindowText(hwndDate, s);
1456 WinSetWindowText(hwndAttr, pci->pszDispAttr);
1457 }
1458 if (dcd->amextracted && hwndStatus2 && !fStatus2Used)
1459 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1460 }
1461 else {
1462 if (hwndStatus2) {
1463 if (dcd->amextracted)
1464 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1465 else
1466 WinSetWindowText(hwndStatus2, NullStr);
1467 }
1468 if (fMoreButtons) {
1469 WinSetWindowText(hwndName, NullStr);
1470 WinSetWindowText(hwndDate, NullStr);
1471 WinSetWindowText(hwndAttr, NullStr);
1472 }
1473 }
1474 }
1475 }
1476 return 0;
1477
1478 case UM_CONTAINER_FILLED:
1479 if (!fAlertBeepOff)
1480 DosBeep(1000, 50); // Wake up user?
1481 WinSendMsg(hwnd,
1482 CM_INVALIDATERECORD,
1483 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
1484 disable_menuitem(WinWindowFromID(WinQueryWindow(hwndMain, QW_PARENT),
1485 FID_MENU), IDM_GREP, FALSE);
1486 disable_menuitem(TreeMenu, IDM_GREP, FALSE);
1487 disable_menuitem(DirMenu, IDM_GREP, FALSE);
1488 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1489 if (dcd) {
1490 dcd->stopflag = 0;
1491 dcd->amextracted = FALSE; // Say not busy
1492 if (dcd->namecanchange) {
1493 if (!PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID))
1494 WinSendMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1495 }
1496 else
1497 WinSetWindowPos(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
1498 QW_PARENT),
1499 HWND_TOP,
1500 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ZORDER);
1501 }
1502 return 0;
1503
1504 case UM_SETUP:
1505 if (dcd) {
1506 if (!dcd->hwndObject) {
1507 // first time through -- set things up
1508
1509 CNRINFO cnri;
1510
1511 RestorePresParams(hwnd, PCSZ_COLLECTOR);
1512 LoadDetailsSwitches(PCSZ_COLLECTOR, &dcd->ds, FALSE);
1513
1514 dcd->amextracted = FALSE; // Say not busy
1515 dcd->stopflag = 0;
1516 memset(&cnri, 0, sizeof(CNRINFO));
1517 cnri.cb = sizeof(CNRINFO);
1518 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1519 MPFROMLONG(sizeof(CNRINFO)));
1520 cnri.cyLineSpacing = 0;
1521 cnri.cxTreeIndent = 12;
1522
1523 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT | CV_DETAIL));
1524 cnri.flWindowAttr |= (CV_NAME | CA_DETAILSVIEWTITLES |
1525 CV_MINI | CV_FLOW);
1526 cnri.pSortRecord = (PVOID) SortCollectorCnr;
1527
1528 size = sizeof(ULONG);
1529 PrfQueryProfileData(fmprof, appname, "CollectorflWindowAttr",
1530 (PVOID) & cnri.flWindowAttr, &size);
1531 size = sizeof(MASK);
1532 if (PrfQueryProfileSize(fmprof, appname, "CollectorFilter", &size) &&
1533 size) {
1534 PrfQueryProfileData(fmprof, appname, "CollectorFilter", &dcd->mask,
1535 &size);
1536 SetMask(NULL, &dcd->mask);
1537 }
1538 else {
1539 dcd->mask.attrFile = (FILE_NORMAL | FILE_READONLY |
1540 FILE_DIRECTORY | FILE_HIDDEN |
1541 FILE_SYSTEM | FILE_ARCHIVED);
1542 dcd->mask.antiattr = 0;
1543 }
1544
1545 *(dcd->mask.prompt) = 0;
1546
1547 cnri.flWindowAttr |= CV_FLOW;
1548 cnri.flWindowAttr &= (~(CA_MIXEDTARGETEMPH | CA_ORDEREDTARGETEMPH));
1549 dcd->flWindowAttr = cnri.flWindowAttr;
1550 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
1551 MPFROMLONG(CMA_FLWINDOWATTR | CMA_LINESPACING |
1552 CMA_CXTREEINDENT | CMA_PSORTRECORD));
1553 SetCnrCols(hwnd, FALSE);
1554 AdjustCnrColsForPref(hwnd, NULL, &dcd->ds, FALSE);
1555
1556 // fix splitbar for collector container
1557 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
1558 size = sizeof(LONG);
1559 PrfQueryProfileData(fmprof, appname, "CollectorCnrSplitBar",
1560 &cnri.xVertSplitbar, &size);
1561 if (cnri.xVertSplitbar <= 0)
1562 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
1563 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
1564 MPFROMLONG(CMA_XVERTSPLITBAR));
1565
1566 if (xbeginthread(MakeObjWin,
1567 245760,
1568 dcd,
1569 pszSrcFile,
1570 __LINE__) == -1)
1571 {
1572 Runtime_Error(pszSrcFile, __LINE__,
1573 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1574 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1575 return 0;
1576 }
1577 else
1578 DosSleep(32); // Let object window get started
1579 }
1580 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1581 DIR_FILTER), &dcd->mask, FALSE);
1582 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1583 DIR_SORT), CollectorsortFlags, FALSE);
1584 SayView(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1585 DIR_VIEW), dcd->flWindowAttr);
1586 }
1587 else {
1588 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1589 return 0;
1590 }
1591 return 0;
1592
1593 case WM_MENUEND:
1594 if (dcd) {
1595 HWND hwndMenu = (HWND) mp2;
1596
1597 if (hwndMenu == CollectorCnrMenu || hwndMenu == CollectorFileMenu ||
1598 hwndMenu == CollectorDirMenu) {
1599 MarkAll(hwnd, TRUE, FALSE, TRUE);
1600 if (dcd->cnremphasized) {
1601 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1602 MPFROM2SHORT(FALSE, CRA_SOURCE));
1603 dcd->cnremphasized = FALSE;
1604 }
1605 }
1606 }
1607 break;
1608
1609 case UM_OPENWINDOWFORME:
1610 if (dcd) {
1611 if (mp1 && !IsFile((CHAR *)mp1))
1612 OpenDirCnr(HWND_DESKTOP, hwndMain, dcd->hwndFrame, FALSE, (PSZ) mp1);
1613 else if (mp1 && IsFile(mp1) == 1 &&
1614 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2)
1615 StartArcCnr(HWND_DESKTOP,
1616 dcd->hwndFrame, (CHAR *)mp1, 4, (ARC_TYPE *) mp2);
1617 }
1618 return 0;
1619
1620 case MM_PORTHOLEINIT:
1621 if (dcd) {
1622 switch (SHORT1FROMMP(mp1)) {
1623 case 0:
1624 case 1:
1625 {
1626 ULONG wmsg;
1627
1628 wmsg = (SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU;
1629 PortholeInit((HWND) WinSendMsg(dcd->hwndClient, wmsg, MPVOID,
1630 MPVOID), mp1, mp2);
1631 }
1632 break;
1633 }
1634 }
1635 break;
1636
1637 case UM_INITMENU:
1638 case WM_INITMENU:
1639 if (dcd) {
1640 switch (SHORT1FROMMP(mp1)) {
1641 case IDM_VIEWSMENU:
1642 SetViewMenu((HWND) mp2, dcd->flWindowAttr);
1643 WinEnableMenuItem((HWND) mp2, IDM_RESELECT,
1644 (dcd->lastselection != NULL));
1645 CopyPresParams((HWND) mp2, hwnd);
1646 break;
1647
1648 case IDM_DETAILSSETUP:
1649 SetDetailsSwitches((HWND) mp2, &dcd->ds);
1650 break;
1651
1652 case IDM_COMMANDSMENU:
1653 SetupCommandMenu((HWND) mp2, hwnd);
1654 break;
1655
1656 case IDM_SORTSUBMENU:
1657 SetSortChecks((HWND) mp2, CollectorsortFlags);
1658 break;
1659 }
1660 dcd->hwndLastMenu = (HWND) mp2;
1661 }
1662 if (msg == WM_INITMENU)
1663 break;
1664 return 0;
1665
1666 case UM_COLLECTFROMFILE:
1667 if (mp1) {
1668# ifdef FORTIFY
1669 Fortify_EnterScope();
1670 Fortify_BecomeOwner(mp1);
1671# endif
1672 if (!dcd) {
1673 Runtime_Error(pszSrcFile, __LINE__, NULL);
1674 free(mp1);
1675 }
1676 else {
1677 if (!PostMsg(dcd->hwndObject, UM_COLLECTFROMFILE, mp1, mp2)) {
1678 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
1679 free(mp1);
1680 }
1681 }
1682# ifdef FORTIFY
1683 DosSleep(1); // Let receiver take ownership
1684 Fortify_LeaveScope();
1685# endif
1686 }
1687 return 0;
1688
1689 case UM_COMMAND:
1690 if (mp1) {
1691 if (dcd) {
1692 if (!PostMsg(dcd->hwndObject, UM_COMMAND, mp1, mp2)) {
1693 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
1694 FreeListInfo((LISTINFO *) mp1);
1695 }
1696 else
1697 return (MRESULT) TRUE;
1698 }
1699 else
1700 FreeListInfo((LISTINFO *) mp1);
1701 }
1702 return 0;
1703
1704 case UM_NOTIFY:
1705 if (mp2)
1706 AddNote((CHAR *)mp2);
1707 return 0;
1708
1709 case WM_COMMAND:
1710 DosError(FERR_DISABLEHARDERR);
1711 if (dcd) {
1712 switch (SHORT1FROMMP(mp1)) {
1713 case IDM_SETTARGET:
1714 SetTargetDir(hwnd, FALSE, NULL);
1715 break;
1716
1717 case IDM_CONTEXTMENU:
1718 {
1719 PCNRITEM pci;
1720
1721 pci = (PCNRITEM) CurrentRecord(hwnd);
1722 PostMsg(hwnd, WM_CONTROL, MPFROM2SHORT(COLLECTOR_CNR,
1723 CN_CONTEXTMENU),
1724 MPFROMP(pci));
1725 }
1726 break;
1727
1728 case IDM_SHOWALLFILES:
1729 {
1730 PCNRITEM pci;
1731
1732 pci = WinSendMsg(hwnd,
1733 CM_QUERYRECORDEMPHASIS,
1734 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1735 if (pci && (INT) pci != -1) {
1736 static CHAR dirname[CCHMAXPATH];
1737
1738 strcpy(dirname, pci->pszFileName);
1739 MakeValidDir(dirname);
1740 StartSeeAll(HWND_DESKTOP, FALSE, dirname);
1741 }
1742 }
1743 break;
1744
1745 case IDM_BEGINEDIT:
1746 OpenEdit(hwnd);
1747 break;
1748
1749 case IDM_ENDEDIT:
1750 WinSendMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
1751 break;
1752
1753 case IDM_SHOWSELECT:
1754 QuickPopup(hwnd, dcd,
1755 CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP),
1756 IDM_SELECTSUBMENU);
1757 break;
1758
1759 case IDM_SHOWSORT:
1760 QuickPopup(hwnd, dcd,
1761 CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP),
1762 IDM_SORTSUBMENU);
1763 break;
1764
1765 case IDM_VIEWORARC:
1766 {
1767 SWP swp;
1768 PCNRITEM pci;
1769
1770 pci = (PCNRITEM) WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1771 MPFROMLONG(CMA_FIRST),
1772 MPFROMSHORT(CRA_CURSORED));
1773 if (pci && (INT) pci != -1) {
1774 WinQueryWindowPos(dcd->hwndFrame, &swp);
1775 DefaultViewKeys(hwnd, dcd->hwndFrame, dcd->hwndParent, &swp,
1776 pci->pszFileName);
1777 }
1778 }
1779 break;
1780
1781 case IDM_SEEALL:
1782 StartSeeAll(HWND_DESKTOP, FALSE, NULL);
1783 break;
1784
1785 case IDM_COLLECTSELECT:
1786 {
1787 CHAR filename[CCHMAXPATH], *p, *pp;
1788
1789 strcpy(filename, PCSZ_STARDOTLST);
1790 size = CCHMAXPATH;
1791 PrfQueryProfileData(fmprof, appname, "SaveToListName",
1792 filename, &size);
1793 pp = strrchr(filename, '\\');
1794 if (!pp)
1795 pp = filename;
1796 p = strrchr(pp, '.');
1797 if (p && *(p + 1) && p > pp + 1) {
1798 if (pp > filename)
1799 pp++;
1800 *pp = '*';
1801 pp++;
1802 if (p > pp)
1803 memmove(pp, p, strlen(p) + 1);
1804 }
1805 if (insert_filename(hwnd, filename, FALSE, FALSE)) {
1806# ifdef FORTIFY
1807 Fortify_EnterScope();
1808# endif
1809 p = xstrdup(filename, pszSrcFile, __LINE__);
1810 if (p) {
1811 if (!PostMsg(hwnd, UM_COLLECTFROMFILE, MPFROMP(p), MPVOID))
1812 free(p);
1813 }
1814# ifdef FORTIFY
1815 DosSleep(1); // Let receiver take ownership
1816 Fortify_LeaveScope();
1817# endif
1818 }
1819 }
1820 break;
1821
1822 case IDM_COLLECTORVIEWSETTINGS:
1823 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
1824 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_COLLECTORVIEWSETTINGS), mp2);
1825 else {
1826 WinDlgBox(HWND_DESKTOP,
1827 hwnd,
1828 CfgDlgProc,
1829 FM3ModHandle,
1830 CFG_FRAME,
1831 MPFROMLONG(IDM_COLLECTORVIEWSETTINGS));
1832 }
1833 break;
1834
1835 case IDM_RESELECT:
1836 SelectList(hwnd, FALSE, FALSE, FALSE, NULL, NULL, dcd->lastselection);
1837 break;
1838
1839 case IDM_WALKDIR:
1840 case IDM_OPENDIRWINDOW:
1841 case IDM_OPENDIRICON:
1842 case IDM_OPENDIRDETAILS:
1843 case IDM_OPENDIRTREE:
1844 {
1845 CHAR newpath[CCHMAXPATH];
1846 PCNRITEM pci;
1847
1848 pci = (PCNRITEM) CurrentRecord(hwnd);
1849 if (pci && (INT) pci != -1) {
1850 strcpy(newpath, pci->pszFileName);
1851 MakeValidDir(newpath);
1852 }
1853 else
1854 strcpy(newpath, pFM2SaveDirectory);
1855 if (*newpath) {
1856 switch (SHORT1FROMMP(mp1)) {
1857 case IDM_WALKDIR:
1858 WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkAllDlgProc,
1859 FM3ModHandle, WALK_FRAME, MPFROMP(newpath));
1860 break;
1861 case IDM_OPENDIRWINDOW:
1862 WinSendMsg(hwnd, UM_OPENWINDOWFORME, MPFROMP(newpath), MPVOID);
1863 break;
1864 case IDM_OPENDIRICON:
1865 OpenObject(newpath, PCSZ_ICON, hwnd);
1866 break;
1867 case IDM_OPENDIRDETAILS:
1868 OpenObject(newpath, Details, hwnd);
1869 break;
1870 case IDM_OPENDIRTREE:
1871 OpenObject(newpath, PCSZ_TREE, hwnd);
1872 break;
1873 default:
1874 break;
1875 }
1876 }
1877 }
1878 break;
1879
1880 case IDM_HELP:
1881 if (hwndHelp)
1882 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1883 MPFROM2SHORT(HELP_COLLECT, 0),
1884 MPFROMSHORT(HM_RESOURCEID));
1885 break;
1886
1887 case IDM_SORTNONE:
1888 case IDM_SORTSMARTNAME:
1889 case IDM_SORTNAME:
1890 case IDM_SORTFILENAME:
1891 case IDM_SORTSIZE:
1892 case IDM_SORTEASIZE:
1893 case IDM_SORTFIRST:
1894 case IDM_SORTLAST:
1895 case IDM_SORTLWDATE:
1896 case IDM_SORTLADATE:
1897 case IDM_SORTCRDATE:
1898 case IDM_SORTSUBJECT:
1899 savedSortFlags = CollectorsortFlags;
1900 CollectorsortFlags &= (SORT_REVERSE | SORT_DIRSFIRST | SORT_DIRSLAST);
1901 case IDM_SORTDIRSFIRST:
1902 case IDM_SORTDIRSLAST:
1903 case IDM_SORTREVERSE:
1904 switch (SHORT1FROMMP(mp1)) {
1905 case IDM_SORTSUBJECT:
1906 CollectorsortFlags |= SORT_SUBJECT;
1907 break;
1908 case IDM_SORTNONE:
1909 CollectorsortFlags |= SORT_NOSORT;
1910 break;
1911 case IDM_SORTSMARTNAME:
1912 if (~savedSortFlags & SORT_FILENAME)
1913 CollectorsortFlags |= SORT_FILENAME;
1914 break;
1915 case IDM_SORTFILENAME:
1916 CollectorsortFlags |= SORT_FILENAME;
1917 break;
1918 case IDM_SORTSIZE:
1919 CollectorsortFlags |= SORT_SIZE;
1920 break;
1921 case IDM_SORTEASIZE:
1922 CollectorsortFlags |= SORT_EASIZE;
1923 break;
1924 case IDM_SORTFIRST:
1925 CollectorsortFlags |= SORT_FIRSTEXTENSION;
1926 break;
1927 case IDM_SORTLAST:
1928 CollectorsortFlags |= SORT_LASTEXTENSION;
1929 break;
1930 case IDM_SORTLWDATE:
1931 CollectorsortFlags |= SORT_LWDATE;
1932 break;
1933 case IDM_SORTLADATE:
1934 CollectorsortFlags |= SORT_LADATE;
1935 break;
1936 case IDM_SORTCRDATE:
1937 CollectorsortFlags |= SORT_CRDATE;
1938 break;
1939 case IDM_SORTDIRSFIRST:
1940 if (CollectorsortFlags & SORT_DIRSFIRST)
1941 CollectorsortFlags &= (~SORT_DIRSFIRST);
1942 else {
1943 CollectorsortFlags |= SORT_DIRSFIRST;
1944 CollectorsortFlags &= (~SORT_DIRSLAST);
1945 }
1946 break;
1947 case IDM_SORTDIRSLAST:
1948 if (CollectorsortFlags & SORT_DIRSLAST)
1949 CollectorsortFlags &= (~SORT_DIRSLAST);
1950 else {
1951 CollectorsortFlags |= SORT_DIRSLAST;
1952 CollectorsortFlags &= (~SORT_DIRSFIRST);
1953 }
1954 break;
1955 case IDM_SORTREVERSE:
1956 if (CollectorsortFlags & SORT_REVERSE)
1957 CollectorsortFlags &= (~SORT_REVERSE);
1958 else
1959 CollectorsortFlags |= SORT_REVERSE;
1960 break;
1961 }
1962 PrfWriteProfileData(fmprof, appname, "CollectorSort",
1963 &CollectorsortFlags, sizeof(INT));
1964 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortCollectorCnr), MPVOID);
1965 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1966 DIR_SORT), CollectorsortFlags, FALSE);
1967 break;
1968
1969 case IDM_COLLECTFROMCLIP:
1970 {
1971 LISTINFO *li;
1972# ifdef FORTIFY
1973 Fortify_EnterScope();
1974# endif
1975 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
1976 if (li) {
1977 li->list = ListFromClipboard(hwnd);
1978 if (!li->list || !li->list[0])
1979 FreeListInfo(li);
1980 else {
1981 li->type = IDM_COLLECT;
1982 if (!PostMsg(dcd->hwndObject, UM_COLLECT, MPFROMP(li), MPVOID))
1983 FreeListInfo(li);
1984 }
1985 }
1986# ifdef FORTIFY
1987 DosSleep(1); // Let receiver take ownership
1988 Fortify_LeaveScope();
1989# endif
1990 }
1991 break;
1992
1993 case IDM_REMOVE:
1994 if (fAutoView && hwndMain)
1995 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1996 dcd->suspendview = 1;
1997 RemoveAll(hwnd, &dcd->ullTotalBytes, &dcd->totalfiles);
1998 dcd->suspendview = 0;
1999 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2000 break;
2001
2002 case IDM_CLEARCNR:
2003 {
2004 PCNRITEM pci;
2005
2006 pci = (PCNRITEM) WinSendMsg(hwnd,
2007 CM_QUERYRECORD,
2008 MPVOID,
2009 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
2010 if (pci && (INT) pci != -1) {
2011 RemoveCnrItems(hwnd, NULL, 0, CMA_FREE | CMA_INVALIDATE);
2012 dcd->ullTotalBytes = dcd->selectedbytes = dcd->selectedfiles =
2013 dcd->totalfiles = 0;
2014 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2015 }
2016 }
2017 break;
2018
2019 case DID_CANCEL:
2020 if (dcd->amextracted)
2021 dcd->stopflag = 1; // Request cancel
2022 break;
2023
2024 case IDM_COLLECTOR:
2025 if (mp2) {
2026 LISTINFO *li;
2027# ifdef FORTIFY
2028 Fortify_EnterScope();
2029# endif
2030 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2031 if (li) {
2032 li->list = mp2;
2033 if (!li->list || !li->list[0])
2034 FreeListInfo(li);
2035 else {
2036 li->type = IDM_COLLECT;
2037 if (!PostMsg(dcd->hwndObject, UM_COLLECT, MPFROMP(li), MPVOID))
2038 FreeListInfo(li);
2039 }
2040 }
2041 else
2042 FreeList(mp2);
2043# ifdef FORTIFY
2044 DosSleep(1); // Let receiver take ownership
2045 Fortify_LeaveScope();
2046# endif
2047 }
2048 break;
2049
2050 case IDM_UNDELETE:
2051 {
2052 PCNRITEM pci;
2053 CHAR path[CCHMAXPATH];
2054 HOBJECT hObject;
2055 HWND hwndDesktop;
2056
2057 hObject = WinQueryObject("<XWP_TRASHCAN>");
2058 if (hObject != NULLHANDLE && fTrashCan) {
2059 hwndDesktop = WinQueryDesktopWindow((HAB) 0, NULLHANDLE);
2060 WinSetFocus(HWND_DESKTOP, hwndDesktop);
2061 WinOpenObject(hObject, 0, TRUE);
2062 }
2063 else {
2064 pci = (PCNRITEM) CurrentRecord(hwnd);
2065 if (pci && (INT) pci != -1) {
2066 strcpy(path, pci->pszFileName);
2067 MakeValidDir(path);
2068 WinDlgBox(HWND_DESKTOP, hwnd, UndeleteDlgProc, FM3ModHandle,
2069 UNDEL_FRAME, MPFROMP(path));
2070 }
2071 }
2072 }
2073 break;
2074
2075 case IDM_GREP:
2076 case UM_GREP:
2077 if (dcd->amextracted) {
2078 saymsg(MB_OK | MB_ICONASTERISK,
2079 hwnd,
2080 GetPString(IDS_WARNINGTEXT),
2081 "Collector busy - please try again later");
2082 }
2083 else {
2084 GREPINFO *GrepInfo;
2085
2086 GrepInfo = xmallocz(sizeof(GREPINFO), pszSrcFile, __LINE__);
2087 if (GrepInfo) {
2088 GrepInfo->hwnd = &hwnd;
2089 if (msg == UM_GREP && mp2)
2090 GrepInfo->szGrepPath = mp2;
2091 if (WinDlgBox(HWND_DESKTOP, hwnd, GrepDlgProc,
2092 FM3ModHandle, GREP_FRAME, (PVOID) GrepInfo)) {
2093 free(GrepInfo);
2094 dcd->amextracted = TRUE; // Say busy scanning
2095 disable_menuitem(WinWindowFromID
2096 (WinQueryWindow(hwndMain, QW_PARENT), FID_MENU),
2097 IDM_GREP, TRUE);
2098 disable_menuitem(TreeMenu, IDM_GREP, TRUE);
2099 disable_menuitem(DirMenu, IDM_GREP, TRUE);
2100 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2101 }
2102 else
2103 free(GrepInfo);
2104 }
2105 }
2106 break;
2107
2108 case IDM_RESORT:
2109 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortCollectorCnr), MPVOID);
2110 break;
2111
2112 case IDM_FILTER:
2113 {
2114 BOOL empty = FALSE;
2115 PCNRITEM pci;
2116 CHAR *p;
2117
2118 if (!*dcd->mask.szMask) {
2119 empty = TRUE;
2120 // 2013-12-13 SHL Allow nul pszFileName
2121 pci = (PCNRITEM) CurrentRecord(hwnd);
2122 if (pci && pci->pszFileName && ~pci->attrFile & FILE_DIRECTORY) {
2123 p = strrchr(pci->pszFileName, '\\');
2124 if (p) {
2125 p++;
2126 strcpy(dcd->mask.szMask, p);
2127 }
2128 }
2129 }
2130 *(dcd->mask.prompt) = 0;
2131
2132 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2133 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask))) {
2134 size = sizeof(MASK);
2135 PrfWriteProfileData(fmprof, appname, "CollectorFilter",
2136 &dcd->mask, size);
2137 dcd->suspendview = 1;
2138 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2139 dcd->suspendview = 0;
2140 if (fAutoView && hwndMain) {
2141 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
2142 MPFROMLONG(CMA_FIRST),
2143 MPFROMSHORT(CRA_CURSORED));
2144 if (pci && (INT) pci != -1 &&
2145 (!(driveflags[toupper(*pci->pszFileName) - 'A'] &
2146 DRIVE_SLOW)))
2147 WinSendMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName),
2148 MPVOID);
2149 else
2150 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2151 }
2152 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2153 }
2154 else if (empty)
2155 *dcd->mask.szMask = 0;
2156 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2157 DIR_FILTER), &dcd->mask, FALSE);
2158 }
2159 break;
2160
2161 case IDM_UNHIDEALL:
2162 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2163 break;
2164
2165 case IDM_HIDEALL:
2166 if (fAutoView && hwndMain)
2167 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2168 dcd->suspendview = 1;
2169 HideAll(hwnd);
2170 dcd->suspendview = 0;
2171 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2172 break;
2173
2174 case IDM_SELECTLIST:
2175 case IDM_SELECTALL:
2176 case IDM_DESELECTALL:
2177 case IDM_SELECTALLFILES:
2178 case IDM_DESELECTALLFILES:
2179 case IDM_SELECTALLDIRS:
2180 case IDM_DESELECTALLDIRS:
2181 case IDM_SELECTMASK:
2182 case IDM_DESELECTMASK:
2183 case IDM_INVERT:
2184 case IDM_SELECTCLIP:
2185 case IDM_DESELECTCLIP:
2186 {
2187 PCNRITEM pci;
2188
2189 pci = (PCNRITEM) CurrentRecord(hwnd);
2190 if ((INT) pci == -1)
2191 pci = NULL;
2192 if (SHORT1FROMMP(mp1) == IDM_HIDEALL) {
2193 if (pci) {
2194 if (!(pci->rc.flRecordAttr & CRA_SELECTED))
2195 pci->rc.flRecordAttr |= CRA_FILTERED;
2196 WinSendMsg(hwnd, CM_INVALIDATERECORD, MPFROMP(&pci),
2197 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2198 break;
2199 }
2200 }
2201 PostMsg(dcd->hwndObject, UM_SELECT, mp1, MPFROMP(pci));
2202 }
2203 break;
2204
2205 case IDM_RESCAN:
2206 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2207 break;
2208
2209 case IDM_SHOWLNAMES:
2210 case IDM_SHOWSUBJECT:
2211 case IDM_SHOWEAS:
2212 case IDM_SHOWSIZE:
2213 case IDM_SHOWICON:
2214 case IDM_SHOWLWDATE:
2215 case IDM_SHOWLWTIME:
2216 case IDM_SHOWLADATE:
2217 case IDM_SHOWLATIME:
2218 case IDM_SHOWCRDATE:
2219 case IDM_SHOWCRTIME:
2220 case IDM_SHOWATTR:
2221 AdjustDetailsSwitches(hwnd, dcd->hwndLastMenu,
2222 SHORT1FROMMP(mp1), NULL,
2223 PCSZ_COLLECTOR, &dcd->ds, FALSE);
2224 break;
2225
2226 case IDM_ICON:
2227 case IDM_TEXT:
2228 case IDM_DETAILS:
2229 case IDM_NAME:
2230 case IDM_MINIICONS:
2231 case IDM_DETAILSTITLES:
2232 {
2233 CNRINFO cnri;
2234
2235 memset(&cnri, 0, sizeof(CNRINFO));
2236 cnri.cb = sizeof(CNRINFO);
2237 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
2238 MPFROMLONG(sizeof(CNRINFO)));
2239 switch (SHORT1FROMMP(mp1)) {
2240 case IDM_ICON:
2241 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2242 CV_DETAIL | CV_NAME));
2243 cnri.flWindowAttr |= CV_ICON;
2244 break;
2245 case IDM_NAME:
2246 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2247 CV_DETAIL | CV_NAME));
2248 cnri.flWindowAttr |= CV_NAME;
2249 break;
2250 case IDM_TEXT:
2251 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2252 CV_DETAIL | CV_NAME));
2253 cnri.flWindowAttr |= CV_TEXT;
2254 break;
2255 case IDM_DETAILS:
2256 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2257 CV_DETAIL | CV_NAME));
2258 cnri.flWindowAttr |= CV_DETAIL;
2259 break;
2260 case IDM_MINIICONS:
2261 if (cnri.flWindowAttr & CV_MINI)
2262 cnri.flWindowAttr &= (~CV_MINI);
2263 else
2264 cnri.flWindowAttr |= CV_MINI;
2265 break;
2266 case IDM_DETAILSTITLES:
2267 if (cnri.flWindowAttr & CA_DETAILSVIEWTITLES)
2268 cnri.flWindowAttr &= (~CA_DETAILSVIEWTITLES);
2269 else
2270 cnri.flWindowAttr |= CA_DETAILSVIEWTITLES;
2271 break;
2272 }
2273 cnri.flWindowAttr &= (~(CA_ORDEREDTARGETEMPH | CA_MIXEDTARGETEMPH));
2274 cnri.flWindowAttr |= CV_FLOW;
2275 dcd->flWindowAttr = cnri.flWindowAttr;
2276 PrfWriteProfileData(fmprof, appname, "CollectorflWindowAttr",
2277 &cnri.flWindowAttr, sizeof(ULONG));
2278 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
2279 MPFROMLONG(CMA_FLWINDOWATTR));
2280 WinSendMsg(hwnd, CM_INVALIDATERECORD, MPVOID,
2281 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
2282 SayView(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2283 DIR_VIEW), dcd->flWindowAttr);
2284 }
2285 break;
2286
2287 case IDM_SAVETOLIST:
2288 WinDlgBox(HWND_DESKTOP, hwnd, SaveListDlgProc, FM3ModHandle,
2289 SAV_FRAME, MPFROMP(&hwnd));
2290 break;
2291
2292 case IDM_SIZES:
2293 {
2294 PCNRITEM pci;
2295
2296 pci = (PCNRITEM) CurrentRecord(hwnd);
2297 if (pci && (INT) pci != -1)
2298 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, DirSizeProc, FM3ModHandle,
2299 DSZ_FRAME, pci->pszFileName);
2300 }
2301 break;
2302
2303 case IDM_MKDIR:
2304 {
2305 PCNRITEM pci;
2306
2307 pci = (PCNRITEM) CurrentRecord(hwnd);
2308 PMMkDir(dcd->hwndParent, (pci && (INT) pci != -1) ?
2309 pci->pszFileName : NULL, FALSE);
2310 }
2311 break;
2312
2313 case IDM_DOITYOURSELF:
2314 case IDM_UPDATE:
2315 case IDM_COLLECTFROMFILE:
2316 case IDM_OPENWINDOW:
2317 case IDM_OPENSETTINGS:
2318 case IDM_OPENDEFAULT:
2319 case IDM_OPENICON:
2320 case IDM_OPENDETAILS:
2321 case IDM_OPENTREE:
2322 case IDM_OBJECT:
2323 case IDM_SHADOW:
2324 case IDM_SHADOW2:
2325 case IDM_DELETE:
2326 case IDM_PERMDELETE:
2327 case IDM_PRINT:
2328 case IDM_ATTRS:
2329 case IDM_INFO:
2330 case IDM_COPY:
2331 case IDM_MOVE:
2332 case IDM_WPSCOPY:
2333 case IDM_WPSMOVE:
2334 case IDM_COPYPRESERVE:
2335 case IDM_MOVEPRESERVE:
2336 case IDM_WILDCOPY:
2337 case IDM_WILDMOVE:
2338 case IDM_RENAME:
2339 case IDM_COMPARE:
2340 case IDM_EAS:
2341 case IDM_SUBJECT:
2342 case IDM_VIEW:
2343 case IDM_VIEWTEXT:
2344 case IDM_VIEWBINARY:
2345 case IDM_VIEWARCHIVE:
2346 case IDM_EDIT:
2347 case IDM_EDITTEXT:
2348 case IDM_EDITBINARY:
2349 case IDM_SAVETOCLIP:
2350 case IDM_SAVETOCLIPFILENAME:
2351 case IDM_APPENDTOCLIP:
2352 case IDM_APPENDTOCLIPFILENAME:
2353 case IDM_ARCHIVE:
2354 case IDM_ARCHIVEM:
2355 case IDM_EXTRACT:
2356 case IDM_MCIPLAY:
2357 case IDM_UUDECODE:
2358 case IDM_UNLOCKFILE:
2359 case IDM_MERGE:
2360 {
2361 LISTINFO *li;
2362 ULONG action = UM_ACTION;
2363# ifdef FORTIFY
2364 Fortify_EnterScope();
2365# endif
2366 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2367 if (li) {
2368 li->type = SHORT1FROMMP(mp1);
2369 li->hwnd = hwnd;
2370 li->list = BuildList(hwnd);
2371 if (li->list) {
2372 switch (SHORT1FROMMP(mp1)) {
2373 case IDM_DOITYOURSELF:
2374 case IDM_APPENDTOCLIP:
2375 case IDM_APPENDTOCLIPFILENAME:
2376 case IDM_SAVETOCLIP:
2377 case IDM_SAVETOCLIPFILENAME:
2378 case IDM_ARCHIVE:
2379 case IDM_ARCHIVEM:
2380 case IDM_DELETE:
2381 case IDM_PERMDELETE:
2382 case IDM_ATTRS:
2383 case IDM_PRINT:
2384 case IDM_SHADOW:
2385 case IDM_SHADOW2:
2386 case IDM_OBJECT:
2387 case IDM_VIEW:
2388 case IDM_VIEWTEXT:
2389 case IDM_VIEWBINARY:
2390 case IDM_EDIT:
2391 case IDM_EDITTEXT:
2392 case IDM_EDITBINARY:
2393 case IDM_MCIPLAY:
2394 case IDM_UPDATE:
2395 case IDM_INFO:
2396 case IDM_EAS:
2397 action = UM_MASSACTION;
2398 break;
2399 }
2400 if (li->type == IDM_DELETE)
2401 ignorereadonly = FALSE;
2402 if (li->type == IDM_SHADOW || li->type == IDM_OBJECT ||
2403 li->type == IDM_SHADOW2)
2404 *li->targetpath = 0;
2405 if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID)) {
2406 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
2407 FreeListInfo(li);
2408 }
2409 else if (fUnHilite)
2410 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2411 }
2412 else
2413 free(li);
2414 }
2415# ifdef FORTIFY
2416 Fortify_LeaveScope();
2417# endif
2418 }
2419 break;
2420
2421 default:
2422 if (!cmdloaded)
2423 load_commands();
2424 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
2425 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
2426 INT x;
2427
2428 x = SHORT1FROMMP(mp1); // - IDM_COMMANDSTART;
2429 if (x >= 0) {
2430 //x++;
2431 RunCommand(hwnd, x);
2432 if (fUnHilite)
2433 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2434 }
2435 }
2436 break;
2437 }
2438 }
2439 return 0;
2440
2441 case UM_FIXCNRMLE:
2442 case UM_FIXEDITNAME:
2443 return CommonCnrProc(hwnd, msg, mp1, mp2);
2444
2445 case UM_FILESMENU:
2446 {
2447 PCNRITEM pci;
2448 HWND menuHwnd = (HWND) 0;
2449
2450 pci = (PCNRITEM) CurrentRecord(hwnd);
2451 if (pci && (INT) pci != -1) {
2452 if (pci->attrFile & FILE_DIRECTORY)
2453 menuHwnd = CheckMenu(hwnd, &CollectorDirMenu, COLLECTORDIR_POPUP);
2454 else
2455 menuHwnd = CheckMenu(hwnd, &CollectorFileMenu, COLLECTORFILE_POPUP);
2456 }
2457 return MRFROMLONG(menuHwnd);
2458 }
2459
2460 case WM_CONTROL:
2461 DosError(FERR_DISABLEHARDERR);
2462 if (dcd) {
2463 switch (SHORT2FROMMP(mp1)) {
2464 case CN_CONTEXTMENU:
2465 {
2466 PCNRITEM pci = (PCNRITEM) mp2;
2467
2468 if (pci) {
2469 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
2470 MPFROM2SHORT(TRUE, CRA_CURSORED));
2471 MarkAll(hwnd, FALSE, FALSE, TRUE);
2472 if (pci->attrFile & FILE_DIRECTORY)
2473 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorDirMenu,
2474 COLLECTORDIR_POPUP);
2475 else
2476 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorFileMenu,
2477 COLLECTORFILE_POPUP);
2478 }
2479 else {
2480 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorCnrMenu,
2481 COLLECTORCNR_POPUP);
2482 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
2483 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
2484 MPFROM2SHORT(TRUE, CRA_SOURCE));
2485 dcd->cnremphasized = TRUE;
2486 }
2487 }
2488 if (dcd->hwndLastMenu) {
2489 if (dcd->hwndLastMenu == CollectorCnrMenu) {
2490 SetViewMenu(dcd->hwndLastMenu, dcd->flWindowAttr);
2491 SetDetailsSwitches(dcd->hwndLastMenu, &dcd->ds);
2492 CopyPresParams(dcd->hwndLastMenu, hwnd);
2493 if (dcd->flWindowAttr & CV_MINI)
2494 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
2495 disable_menuitem(dcd->hwndLastMenu, DID_CANCEL,
2496 !dcd->amextracted);
2497 disable_menuitem(dcd->hwndLastMenu, IDM_GREP, dcd->amextracted);
2498 }
2499 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
2500 if (dcd->cnremphasized) {
2501 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
2502 MPFROM2SHORT(FALSE, CRA_SOURCE));
2503 dcd->cnremphasized = TRUE;
2504 }
2505 MarkAll(hwnd, TRUE, FALSE, TRUE);
2506 }
2507 }
2508 }
2509 break;
2510
2511 case CN_DROPHELP:
2512 if (mp2) {
2513 PDRAGINFO pDInfo;
2514 PCNRITEM pci;
2515 ULONG numitems;
2516 USHORT usOperation;
2517
2518 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
2519 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2520 if (!DrgAccessDraginfo(pDInfo)) {
2521 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
2522 PCSZ_DRGACCESSDRAGINFO);
2523 return 0;
2524 }
2525 numitems = DrgQueryDragitemCount(pDInfo);
2526 usOperation = pDInfo->usOperation;
2527 if (usOperation == DO_DEFAULT)
2528 usOperation = fCopyDefault ? DO_COPY : DO_MOVE;
2529 FreeDragInfoData(hwnd, pDInfo);
2530 saymsg(MB_ENTER | MB_ICONASTERISK,
2531 hwnd,
2532 GetPString(IDS_DROPHELPHDRTEXT),
2533 GetPString(IDS_DROPHELPTEXT),
2534 numitems,
2535 &"s"[numitems == 1],
2536 (pci) ? NullStr : GetPString(IDS_NOTEXT),
2537 (pci) ? NullStr : " ",
2538 (pci) ? pci->pszFileName : NullStr,
2539 (pci) ? " " : NullStr,
2540 GetPString((usOperation == DO_COPY) ?
2541 IDS_COPYTEXT :
2542 (usOperation == DO_LINK) ?
2543 IDS_LINKTEXT : IDS_MOVETEXT));
2544 }
2545 return 0;
2546
2547 case CN_DRAGLEAVE:
2548 if (mp2) {
2549 PDRAGINFO pDInfo;
2550
2551 // fixme to know why needed
2552 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2553 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
2554 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2555 }
2556 return 0;
2557
2558 case CN_DRAGAFTER:
2559 case CN_DRAGOVER:
2560 if (mp2) {
2561 PDRAGITEM pDItem; // Pointer to DRAGITEM
2562 PDRAGINFO pDInfo; // Pointer to DRAGINFO
2563 PCNRITEM pci;
2564 USHORT uso;
2565
2566 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
2567 // if(SHORT1FROMMP(mp1) == CN_DRAGAFTER)
2568 // pci = NULL;
2569 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2570 if (!DrgAccessDraginfo(pDInfo)) {
2571 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
2572 PCSZ_DRGACCESSDRAGINFO);
2573 return (MRFROM2SHORT(DOR_NODROP, 0)); // Drop not valid
2574 }
2575 if (pci) {
2576 if (pci->rc.flRecordAttr & CRA_SOURCE) {
2577 DrgFreeDraginfo(pDInfo);
2578 return (MRFROM2SHORT(DOR_NODROP, 0));
2579 }
2580 uso = pDInfo->usOperation;
2581 if (uso == DO_DEFAULT)
2582 uso = (fCopyDefault) ? DO_COPY : DO_MOVE;
2583 if (!(pci->attrFile & FILE_DIRECTORY)) {
2584 if (uso != DO_LINK && uso != DO_MOVE && uso != DO_COPY) {
2585 DrgFreeDraginfo(pDInfo);
2586 return MRFROM2SHORT(DOR_NODROP, 0);
2587 }
2588 if (uso != DO_LINK &&
2589 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
2590 DRIVE_NOTWRITEABLE)) {
2591 ARC_TYPE *info = NULL;
2592
2593 if (!fQuickArcFind &&
2594 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
2595 DRIVE_SLOW))
2596 info = find_type(pci->pszFileName, NULL);
2597 else
2598 info = quick_find_type(pci->pszFileName, NULL);
2599 if (!info || ((uso == DO_MOVE && !info->move) ||
2600 (uso == DO_COPY && !info->create))) {
2601 DrgFreeDraginfo(pDInfo);
2602 return MRFROM2SHORT(DOR_NODROP, 0);
2603 }
2604 }
2605 }
2606 }
2607 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
2608 0); // Index to DRAGITEM
2609 if (DrgVerifyRMF(pDItem, // Check valid rendering
2610 (CHAR *) DRM_OS2FILE, // mechanisms and data
2611 NULL)) {
2612 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2613 if (pci) {
2614 if (driveflags[toupper(*pci->pszFileName) - 'A'] &
2615 DRIVE_NOTWRITEABLE)
2616 return MRFROM2SHORT(DOR_DROP, DO_LINK);
2617 if (toupper(*pci->pszFileName) < 'C')
2618 return MRFROM2SHORT(DOR_DROP, DO_COPY);
2619 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
2620 ((fCopyDefault) ? DO_COPY : DO_MOVE));
2621 }
2622 else
2623 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
2624 DO_COPY);
2625 }
2626 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2627 }
2628 return (MRFROM2SHORT(DOR_NODROP, 0)); // Drop not valid
2629
2630 case CN_INITDRAG:
2631 if (mp2) {
2632 BOOL wasemphasized = FALSE;
2633 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
2634 PCNRITEM pci;
2635
2636 if (pcd) {
2637 pci = (PCNRITEM) pcd->pRecord;
2638 if (pci) {
2639 if (pci->rc.flRecordAttr & CRA_SELECTED)
2640 wasemphasized = TRUE;
2641 if (IsRoot(pci->pszFileName))
2642 break;
2643 if (hwndStatus2)
2644 WinSetWindowText(hwndStatus2,
2645 (CHAR *) GetPString(IDS_DRAGFILEOBJTEXT));
2646 if (DoFileDrag(hwnd, dcd->hwndObject, mp2, NULL, NULL, TRUE)) {
2647 if ((fUnHilite && wasemphasized) || dcd->ulItemsToUnHilite)
2648 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2649 }
2650 if (hwndStatus2)
2651 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2652 }
2653 }
2654 }
2655 return 0;
2656
2657 case CN_DROP:
2658 if (mp2) {
2659 LISTINFO *li;
2660 ULONG action = UM_ACTION;
2661
2662 li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
2663 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
2664 if (li) {
2665 if (!*li->targetpath) {
2666 li->type = IDM_COLLECT;
2667 action = UM_COLLECT;
2668 }
2669 else {
2670 if (li->list && li->list[0] && IsRoot(li->list[0]))
2671 li->type = DO_LINK;
2672 else if (fDragndropDlg && (!*li->arcname || !li->info)) {
2673 CHECKLIST cl;
2674
2675 memset(&cl, 0, sizeof(cl));
2676 cl.size = sizeof(cl);
2677 cl.flags = li->type;
2678 cl.list = li->list;
2679 cl.cmd = li->type;
2680 cl.prompt = li->targetpath;
2681 li->type = WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
2682 DropListProc, FM3ModHandle,
2683 DND_FRAME, MPFROMP(&cl));
2684 if (li->type == DID_ERROR)
2685 Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
2686 GetPString(IDS_DRAGDROPDIALOGTEXT));
2687 if (!li->type) {
2688 FreeListInfo(li);
2689 return 0;
2690 }
2691 li->list = cl.list;
2692 if (!li->list || !li->list[0]) {
2693 FreeListInfo(li);
2694 return 0;
2695 }
2696 }
2697 switch (li->type) {
2698 case DND_LAUNCH:
2699 strcat(li->targetpath, " %a");
2700 ExecOnList(dcd->hwndParent, li->targetpath,
2701 PROMPT | WINDOWED, NULL, NULL, li->list, NULL,
2702 pszSrcFile, __LINE__);
2703 FreeList(li->list);
2704 li->list = NULL;
2705 break;
2706 case DO_LINK:
2707 if (fLinkSetsIcon) {
2708 li->type = IDM_SETICON;
2709 action = UM_MASSACTION;
2710 }
2711 else
2712 li->type = IDM_COMPARE;
2713 break;
2714 case DND_EXTRACT:
2715 if (*li->targetpath && !IsFile(li->targetpath))
2716 li->type = IDM_EXTRACT;
2717 break;
2718 case DND_MOVE:
2719 li->type = IDM_MOVE;
2720 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2721 action = UM_MASSACTION;
2722 li->type = IDM_ARCHIVEM;
2723 }
2724 break;
2725 case DND_WILDMOVE:
2726 li->type = IDM_WILDMOVE;
2727 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2728 action = UM_MASSACTION;
2729 li->type = IDM_ARCHIVEM;
2730 }
2731 break;
2732 case DND_OBJECT:
2733 li->type = IDM_OBJECT;
2734 action = UM_MASSACTION;
2735 break;
2736 case DND_SHADOW:
2737 li->type = IDM_SHADOW;
2738 action = UM_MASSACTION;
2739 break;
2740 case DND_COMPARE:
2741 li->type = IDM_COMPARE;
2742 break;
2743 case DND_SETICON:
2744 action = UM_MASSACTION;
2745 li->type = IDM_SETICON;
2746 break;
2747 case DND_WILDCOPY:
2748 li->type = IDM_WILDCOPY;
2749 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2750 action = UM_MASSACTION;
2751 li->type = IDM_ARCHIVE;
2752 }
2753 break;
2754 case DND_COPY:
2755 li->type = IDM_COPY;
2756 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2757 action = UM_MASSACTION;
2758 li->type = IDM_ARCHIVE;
2759 }
2760 break;
2761 default:
2762 if (*li->arcname && li->info) {
2763 action = UM_MASSACTION;
2764 li->type =
2765 (li->type ==
2766 DO_MOVE) ? IDM_FAKEEXTRACTM : IDM_FAKEEXTRACT;
2767 }
2768 else if (*li->targetpath && IsFile(li->targetpath) == 1) {
2769 action = UM_MASSACTION;
2770 li->type =
2771 (li->type == DO_MOVE) ? IDM_ARCHIVEM : IDM_ARCHIVE;
2772 }
2773 else
2774 li->type = (li->type == DO_MOVE) ? IDM_MOVE : IDM_COPY;
2775 break;
2776 } // switch
2777 } // if !collect
2778 if (!li->list || !li->list[0])
2779 FreeListInfo(li);
2780 else if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID))
2781 FreeListInfo(li);
2782 else {
2783 USHORT usop = 0;
2784
2785 switch (li->type) {
2786 case IDM_COPY:
2787 case IDM_WILDCOPY:
2788 usop = DO_COPY;
2789 break;
2790 case IDM_MOVE:
2791 case IDM_WILDMOVE:
2792 case IDM_ARCHIVEM:
2793 usop = DO_MOVE;
2794 break;
2795 }
2796 if (usop)
2797 return MRFROM2SHORT(DOR_DROP, usop);
2798 }
2799 }
2800 }
2801 return 0;
2802
2803 case CN_BEGINEDIT:
2804 case CN_REALLOCPSZ:
2805 case CN_ENDEDIT:
2806 {
2807 MRESULT mre;
2808
2809 mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
2810 if (mre != (MRESULT) - 1)
2811 return mre;
2812 }
2813 break;
2814
2815 case CN_EMPHASIS:
2816 if (mp2) {
2817 PNOTIFYRECORDEMPHASIS pre = mp2;
2818 PCNRITEM pci;
2819 CHAR s[CCHMAXPATH + 91], tb[81], tf[81], szDate[DATE_BUF_BYTES], *p;
2820
2821 pci = (PCNRITEM) ((pre) ? pre->pRecord : NULL);
2822 if (!pci) {
2823 if (hwndStatus2)
2824 WinSetWindowText(hwndStatus2, NullStr);
2825 if (fMoreButtons) {
2826 WinSetWindowText(hwndName, NullStr);
2827 WinSetWindowText(hwndDate, NullStr);
2828 WinSetWindowText(hwndAttr, NullStr);
2829 }
2830 if (hwndMain)
2831 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2832 break;
2833 }
2834 if (pre->fEmphasisMask & CRA_SELECTED) {
2835 if (pci->rc.flRecordAttr & CRA_SELECTED) {
2836 dcd->selectedbytes += (pci->cbFile + pci->easize);
2837 dcd->selectedfiles++;
2838 }
2839 else if (dcd->selectedfiles) {
2840 dcd->selectedbytes -= (pci->cbFile + pci->easize);
2841 dcd->selectedfiles--;
2842 }
2843 if (!dcd->suspendview) {
2844 commafmt(tf, sizeof(tf), dcd->selectedfiles);
2845 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
2846 sprintf(s, "%s / %s", tf, tb);
2847 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
2848 }
2849 }
2850 if (!dcd->suspendview &&
2851 WinQueryActiveWindow(dcd->hwndParent) == dcd->hwndFrame) {
2852 if (pre->fEmphasisMask & CRA_CURSORED) {
2853 if (pci->rc.flRecordAttr & CRA_CURSORED) {
2854 if (fSplitStatus && hwndStatus2) {
2855 if (pci->attrFile & FILE_DIRECTORY)
2856 p = pci->pszFileName;
2857 else {
2858 p = strrchr(pci->pszFileName, '\\');
2859 if (p) {
2860 if (*(p + 1))
2861 p++;
2862 else
2863 p = pci->pszFileName;
2864 }
2865 else
2866 p = pci->pszFileName;
2867 }
2868 CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
2869 if (!fMoreButtons) {
2870 DateFormat(szDate, pci->date);
2871 sprintf(s, " %s %s %02u%s%02u%s%02u [%s] %s",
2872 tb, szDate, pci->time.hours, TimeSeparator,
2873 pci->time.minutes, TimeSeparator, pci->time.seconds,
2874 pci->pszDispAttr, p);
2875 }
2876 else {
2877 if (pci->cbFile + pci->easize > 1024)
2878 CommaFmtULL(tf, sizeof(tf), pci->cbFile + pci->easize,
2879 ' ');
2880 else
2881 *tf = 0;
2882 sprintf(s, GetPString(IDS_STATUSSIZETEXT),
2883 tb,
2884 *tf ? " (" : NullStr, tf, *tf ? ")" : NullStr);
2885 }
2886 WinSetWindowText(hwndStatus2, s);
2887 }
2888 if (fMoreButtons) {
2889 WinSetWindowText(hwndName, pci->pszFileName);
2890 DateFormat(szDate, pci->date);
2891 sprintf(s, "%s %02u%s%02u%s%02u",
2892 szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
2893 TimeSeparator, pci->time.seconds);
2894 WinSetWindowText(hwndDate, s);
2895 WinSetWindowText(hwndAttr, pci->pszDispAttr);
2896 }
2897 }
2898 }
2899 }
2900 if (!dcd->suspendview && hwndMain &&
2901 (pre->fEmphasisMask & CRA_CURSORED) &&
2902 (pci->rc.flRecordAttr & CRA_CURSORED) &&
2903 WinQueryActiveWindow(dcd->hwndParent) == dcd->hwndFrame)
2904 WinSendMsg(hwndMain, UM_LOADFILE,
2905 MPFROMP(((fComments
2906 || (pci->attrFile & FILE_DIRECTORY) ==
2907 0) ? pci->pszFileName : NULL)), MPVOID);
2908 }
2909 break;
2910
2911 case CN_ENTER:
2912 if (mp2) {
2913 PCNRITEM pci = (PCNRITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
2914 FILEFINDBUF3 ffb;
2915 HDIR hDir = HDIR_CREATE;
2916 ULONG nm = 1;
2917 APIRET status = 0;
2918
2919 SetShiftState();
2920 if (pci) {
2921 if (pci->rc.flRecordAttr & CRA_INUSE)
2922 break;
2923 DosError(FERR_DISABLEHARDERR);
2924 status = DosFindFirst(pci->pszFileName, &hDir,
2925 FILE_NORMAL | FILE_DIRECTORY |
2926 FILE_ARCHIVED | FILE_READONLY |
2927 FILE_HIDDEN | FILE_SYSTEM,
2928 &ffb, sizeof(ffb), &nm, FIL_STANDARD);
2929 priority_bumped();
2930 if (!status) {
2931 DosFindClose(hDir);
2932 if (ffb.attrFile & FILE_DIRECTORY) {
2933 if ((shiftstate & (KC_CTRL | KC_ALT)) == (KC_CTRL | KC_ALT))
2934 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_SHOWALLFILES, 0),
2935 MPVOID);
2936 else if ((shiftstate & (KC_CTRL | KC_SHIFT)) ==
2937 (KC_CTRL | KC_SHIFT))
2938 OpenObject(pci->pszFileName, Settings, dcd->hwndFrame);
2939 else if (shiftstate & KC_CTRL)
2940 OpenObject(pci->pszFileName, Default, dcd->hwndFrame);
2941 else
2942 OpenDirCnr(HWND_DESKTOP,
2943 hwndMain,
2944 dcd->hwndFrame, FALSE, pci->pszFileName);
2945 }
2946 else {
2947 SWP swp;
2948
2949 WinSendMsg(hwnd,
2950 CM_SETRECORDEMPHASIS,
2951 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_INUSE));
2952 WinQueryWindowPos(dcd->hwndFrame, &swp);
2953 DefaultViewKeys(hwnd,
2954 dcd->hwndFrame,
2955 dcd->hwndParent, &swp, pci->pszFileName);
2956 WinSendMsg(hwnd,
2957 CM_SETRECORDEMPHASIS,
2958 MPFROMP(pci),
2959 MPFROM2SHORT(FALSE, CRA_INUSE |
2960 ((fUnHilite) ? CRA_SELECTED : 0)));
2961 }
2962 }
2963 else
2964 RemoveCnrItems(hwnd, pci, 1, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
2965 }
2966 }
2967 break;
2968 }
2969 }
2970 return 0;
2971
2972 case UM_LOADFILE:
2973 if (dcd && mp2) {
2974
2975 HWND hwnd;
2976
2977 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2978 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2979 (CHAR *)mp2, dcd->hwndFrame);
2980 else
2981 hwnd = StartMLEEditor(dcd->hwndParent,
2982 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
2983 free((CHAR *)mp2);
2984 return MRFROMLONG(hwnd);
2985 }
2986 return 0;
2987
2988 case UM_CLOSE:
2989 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
2990 QW_PARENT));
2991 return 0;
2992
2993 case UM_FOLDUP:
2994 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
2995 DosExit(EXIT_PROCESS, 1);
2996 return 0;
2997
2998 case WM_CLOSE:
2999 if (dcd) {
3000 dcd->namecanchange = TRUE;
3001 dcd->stopflag = 1;
3002 if (dcd->amextracted)
3003 return 0; // Can not close yet
3004 }
3005 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3006 if (dcd) {
3007 if (!dcd->dontclose && ParentIsDesktop(hwnd, dcd->hwndParent))
3008 PostMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID);
3009 if (dcd->hwndObject) {
3010 DosSleep(32); // Allow UM_FOLDUP to process
3011 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3012 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3013 }
3014 }
3015 else
3016 WinSendMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
3017 return 0;
3018
3019 case WM_DESTROY:
3020 if (CollectorDirMenu)
3021 WinDestroyWindow(CollectorDirMenu);
3022 if (CollectorFileMenu)
3023 WinDestroyWindow(CollectorFileMenu);
3024 if (CollectorCnrMenu)
3025 WinDestroyWindow(CollectorCnrMenu);
3026 CollectorCnrMenu = CollectorFileMenu = CollectorDirMenu = (HWND) 0;
3027 Collector = (HWND) 0;
3028 EmptyCnr(hwnd);
3029 break;
3030 }
3031 if (dcd && dcd->oldproc){
3032 return dcd->oldproc(hwnd, msg, mp1, mp2);
3033 }
3034 else
3035 return PFNWPCnr(hwnd, msg, mp1, mp2);
3036}
3037
3038MRESULT EXPENTRY CollectorMenuProc(HWND hwnd, ULONG msg, MPARAM mp1,
3039 MPARAM mp2)
3040{
3041 PFNWP oldMenuProc = WinQueryWindowPtr(hwnd, QWL_USER);
3042 static short sLastMenuitem;
3043
3044 switch (msg) {
3045 case WM_MOUSEMOVE: {
3046 if (fOtherHelp) {
3047 RECTL rectl;
3048 SHORT i, sCurrentMenuitem;
3049 SHORT MenuItems = 5;
3050 SHORT asMenuIDs[5] = {IDM_GREP,
3051 IDM_SEEALL,
3052 IDM_CLEARCNR,
3053 IDM_REMOVE,
3054 0};
3055 PCSZ szHelpString = NULL;
3056
3057 for (i=0; i<MenuItems; i++) {
3058 sCurrentMenuitem = asMenuIDs[i];
3059 oldMenuProc(hwnd,MM_QUERYITEMRECT,
3060 MPFROM2SHORT(asMenuIDs[i], FALSE),
3061 &rectl);
3062
3063 if (MOUSEMSG(&msg)->x > rectl.xLeft &&
3064 MOUSEMSG(&msg)->x < rectl.xRight &&
3065 MOUSEMSG(&msg)->y > rectl.yBottom &&
3066 MOUSEMSG(&msg)->y < rectl.yTop)
3067 break;
3068 } // for
3069
3070 switch (sCurrentMenuitem) {
3071 case 0:
3072 break;
3073 case IDM_GREP:
3074 szHelpString = GetPString(IDS_COLMENUSEEKSCANHELP);
3075 break;
3076 case IDM_SEEALL:
3077 szHelpString = GetPString(IDS_COLMENUSEEALLHELP);
3078 break;
3079 case IDM_CLEARCNR:
3080 szHelpString = GetPString(IDS_COLMENUCLEARCNRHELP);
3081 break;
3082 case IDM_REMOVE:
3083 szHelpString = GetPString(IDS_COLMENUREMOVECNRHELP);
3084 break;
3085 default:
3086 break;
3087 }
3088
3089 if (sLastMenuitem != sCurrentMenuitem && szHelpString) {
3090 sLastMenuitem = sCurrentMenuitem;
3091 MakeBubble(hwnd, TRUE, szHelpString);
3092 }
3093 else if (hwndBubble && !sCurrentMenuitem){
3094 sLastMenuitem = sCurrentMenuitem;
3095 WinDestroyWindow(hwndBubble);
3096 }
3097 }
3098 }
3099 }
3100 return oldMenuProc(hwnd, msg, mp1, mp2);
3101}
3102
3103HWND StartCollector(HWND hwndParent, INT flags)
3104{
3105 HWND hwndFrame = (HWND) 0;
3106 HWND hwndClient;
3107 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3108 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3109 USHORT id;
3110 DIRCNRDATA *dcd;
3111
3112 static USHORT idinc = 0;
3113
3114 if (ParentIsDesktop(hwndParent, hwndParent))
3115 FrameFlags |= (FCF_TASKLIST | FCF_SHELLPOSITION | FCF_MENU);
3116 if (Collector) {
3117 WinSetWindowPos(WinQueryWindow(WinQueryWindow(Collector,
3118 QW_PARENT),
3119 QW_PARENT),
3120 HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE);
3121 return WinQueryWindow(WinQueryWindow(Collector, QW_PARENT), QW_PARENT);
3122 }
3123 hwndFrame = WinCreateStdWindow(hwndParent,
3124 WS_VISIBLE,
3125 &FrameFlags,
3126 (CHAR *) WC_COLLECTOR,
3127 NULL,
3128 WS_VISIBLE | fwsAnimate,
3129 FM3ModHandle, COLLECTOR_FRAME, &hwndClient);
3130 if (hwndFrame && hwndClient) {
3131 id = COLLECTOR_FRAME + idinc++;
3132 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3133# ifdef FORTIFY
3134 Fortify_EnterScope();
3135# endif
3136 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3137 if (!dcd) {
3138 Runtime_Error(pszSrcFile, __LINE__, NULL);
3139 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3140 hwndFrame = (HWND) 0;
3141 }
3142 else {
3143 dcd->size = sizeof(DIRCNRDATA);
3144 dcd->id = id;
3145 dcd->type = COLLECTOR_FRAME;
3146 dcd->hwndParent = (hwndParent) ? hwndParent : HWND_DESKTOP;
3147 dcd->hwndFrame = hwndFrame;
3148 dcd->hwndClient = hwndClient;
3149 if (flags & 4)
3150 dcd->dontclose = TRUE;
3151 {
3152 PFNWP oldproc;
3153
3154 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) CollectorFrameWndProc);
3155 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3156 }
3157 dcd->hwndCnr = WinCreateWindow(hwndClient,
3158 WC_CONTAINER,
3159 NULL,
3160 CCS_AUTOPOSITION | CCS_MINIICONS |
3161 CCS_MINIRECORDCORE | ulCnrType |
3162 WS_VISIBLE,
3163 0,
3164 0,
3165 0,
3166 0,
3167 hwndClient,
3168 HWND_TOP,
3169 (ULONG) COLLECTOR_CNR, NULL, NULL);
3170 if (!dcd->hwndCnr) {
3171 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3172 PCSZ_WINCREATEWINDOW);
3173 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3174 free(dcd);
3175 hwndFrame = (HWND) 0;
3176 }
3177 else {
3178 Collector = dcd->hwndCnr;
3179 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3180 WinSetWindowText(hwndFrame, (CHAR *) GetPString(IDS_COLLECTORTITLETEXT));
3181 if (FrameFlags & FCF_MENU) {
3182 PFNWP oldmenuproc;
3183 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3184
3185 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) CollectorMenuProc);
3186 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3187 if (!fToolbar) {
3188 if (hwndMenu) {
3189
3190 WinSendMsg(hwndMenu,
3191 MM_DELETEITEM,
3192 MPFROM2SHORT(IDM_SEEALL, FALSE), MPVOID);
3193 WinSendMsg(hwndMenu,
3194 MM_DELETEITEM,
3195 MPFROM2SHORT(IDM_GREP, FALSE), MPVOID);
3196 WinSendMsg(hwndMenu,
3197 MM_DELETEITEM,
3198 MPFROM2SHORT(IDM_CLEARCNR, FALSE), MPVOID);
3199 WinSendMsg(hwndMenu,
3200 MM_DELETEITEM,
3201 MPFROM2SHORT(IDM_REMOVE, FALSE), MPVOID);
3202 }
3203 }
3204 }
3205 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3206 (PFNWP) CollectorCnrWndProc);
3207 {
3208 USHORT ids[] = { DIR_TOTALS,
3209 DIR_SELECTED,
3210 DIR_VIEW,
3211 DIR_SORT,
3212 DIR_FILTER,
3213 0
3214 };
3215
3216 CommonCreateTextChildren(dcd->hwndClient,
3217 WC_COLSTATUS, ids);
3218 }
3219 if (FrameFlags & FCF_SHELLPOSITION)
3220 PostMsg(hwndClient, UM_SIZE, MPVOID, MPVOID);
3221 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3222 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3223 }
3224 }
3225# ifdef FORTIFY
3226 DosSleep(1); // Let receiver take ownership
3227 Fortify_LeaveScope();
3228# endif
3229 }
3230 return hwndFrame;
3231}
3232
3233#pragma alloc_text(COLLECTOR,CollectorCnrWndProc,CollectorObjWndProc)
3234#pragma alloc_text(COLLECTOR,CollectorClientWndProc,CollectorTextProc)
3235#pragma alloc_text(COLLECTOR,CollectorFrameWndProc)
3236#pragma alloc_text(STARTUP,StartCollector)
Note: See TracBrowser for help on using the repository browser.