source: trunk/dll/collect.c@ 1878

Last change on this file since 1878 was 1878, checked in by Gregg Young, 10 years ago

Remove some dead code and comments source files starting with A-D

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