source: trunk/dll/misc.c@ 1398

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

Move embeded strings to PCSZ variables or string table; Eliminate Error2 functions Runtime_Error with NULL format string returns "No data" error. Change declares from PSZ to PCSZ in functions where the variable isn't changed. Added btm as an executable file type in several additional places. Use fProtectOnly to prevent attempt to execute Dos and Win programs on "Protect only" installs in several additional places.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 70.0 KB
Line 
1/***********************************************************************
2
3 $Id: misc.c 1398 2009-02-21 17:43:00Z gyoung $
4
5 Misc GUI support functions
6
7 Copyright (c) 1993-98 M. Kimes
8 Copyright (c) 2003, 2009 Steven H. Levine
9
10 11 Jun 03 SHL Add JFS and FAT32 support
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 01 Aug 04 SHL LoadLibPath: avoid buffer overflow
13 07 Jun 05 SHL Drop obsoletes
14 24 Jul 05 SHL Beautify
15 24 Jul 05 SHL Correct longname display option
16 17 Jul 06 SHL Use Runtime_Error
17 26 Jul 06 SHL Use chop_at_crnl
18 27 Jul 06 SHL Comments, apply indent
19 29 Jul 06 SHL Use xfgets_bstripcr
20 16 Aug 06 SHL Comments
21 31 Aug 06 SHL disable_menuitem: rework args to match name - sheesh
22 10 Oct 06 GKY Add NDFS32 support
23 18 Feb 07 GKY More drive type and drive icon support
24 10 Jun 07 GKY Add IsFm2Window as part of work around PM drag limit
25 05 Jul 07 GKY Fix menu removals for WORKPLACE_PROCESS=YES
26 23 Jul 07 SHL Sync with CNRITEM updates (ticket#24)
27 31 Jul 07 SHL Clean up and report errors (ticket#24)
28 03 Aug 07 GKY Direct editting fixed (ticket#24)
29 06 Aug 07 SHL Use BldQuotedFileName
30 06 Aug 07 GKY Increase Subject EA to 1024
31 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
32 14 Aug 07 SHL Delete obsoletes
33 14 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
34 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
35 05 Nov 07 GKY Use commafmtULL to display file sizes for large file support
36 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
37 12 Jan 08 SHL Document SetConditionalCascade
38 13 Jan 08 GKY Get Subjectwidth/Subjectleft working in the collector.
39 19 Jan 08 JBS Ticket 150: fix/improve save and restore of dir cnr state at FM/2 close/reopen
40 21 Jan 08 GKY Stop reallocating NullStr by direct editing of empty subject and longname strings.
41 29 Feb 08 GKY Use xfree where appropriate
42 08 Mar 08 JBS Ticket 230: Replace prefixless INI keys for default directory containers with
43 keys using a "DirCnr." prefix
44 19 Jun 08 JBS Ticket 239: Fix LoadDetailsSwitches so INI file is read correctly and details
45 switches are set correctly.
46 11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
47 all the details view settings (both the global variables and those in the
48 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
49 17 Jul 08 SHL Add GetTidForWindow for Fortify support
50 20 Jul 08 GKY Add save/append filename to clipboard.
51 Change menu wording to make these easier to find
52 23 Aug 08 GKY Add CheckDriveSpaceAvail To pre check drive space to prevent failures
53 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
54 28 Dec 08 GKY Check for LVM.EXE and remove Refresh removable media menu item as appropriate
55 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
56
57***********************************************************************/
58
59#include <stdlib.h>
60#include <string.h>
61#include <ctype.h>
62#include <share.h>
63#include <malloc.h> // _heapmin
64
65#define INCL_DOS
66#define INCL_WIN
67#define INCL_GPI
68#define INCL_LONGLONG
69
70#include "fm3dll.h"
71#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
72#include "misc.h"
73#include "killproc.h" // Data declaration(s)
74#include "comp.h" // Data declaration(s)
75#include "treecnr.h" // Data declaration(s)
76#include "mainwnd.h" // Data declaration(s)
77#include "init.h" // Data declaration(s)
78#include "dircnrs.h" // Data declaration(s)
79#include "newview.h" // Data declarations
80#include "collect.h" // data declaration(s)
81#include "notebook.h" // data declaration(s)
82#include "arccnrs.h"
83#include "fm3dlg.h"
84#include "fm3str.h"
85#include "pathutil.h" // BldQuotedFileName
86#include "errutil.h" // Dos_Error...
87#include "strutil.h" // GetPString
88#include "command.h" // LINKCMDS
89#include "cmdline.h" // CmdLineDlgProc
90#include "defview.h" // QuickView
91#include "copyf.h" // WriteLongName
92#include "strips.h" // chop_at_crnl
93#include "valid.h" // CheckDrive
94#include "presparm.h" // CopyPresParams
95#include "systemf.h" // ExecOnList
96#include "viewer.h" // StartMLEEditor
97#include "subj.h" // Subject
98#include "wrappers.h" // xDosSetPathInfo
99#include "commafmt.h" // CommaFmtULL
100#include "fortify.h"
101#include "info.h" // driveflags
102
103#define CONTAINER_COLUMNS 13 /* Number of columns in details view */
104#define MS_POPUP 0x00000010L
105
106// Data definitions
107#pragma data_seg(GLOBAL1)
108HWND CollectorDirMenu;
109HWND CollectorFileMenu;
110HWND DirMenu;
111HWND FileMenu;
112HWND TreeMenu;
113BOOL fDefaultDeletePerm;
114BOOL fWorkPlace;
115
116#pragma data_seg(GLOBAL4)
117ULONG numswitches;
118HSWITCH switches[499];
119
120#pragma data_seg(DATA1)
121static PSZ pszSrcFile = __FILE__;
122
123#ifndef BEGIN_LIBPATH
124#define BEGIN_LIBPATH 1
125#endif
126
127#ifndef END_LIBPATH
128#define END_LIBPATH 2
129#endif
130
131#ifndef ORD_DOS32QUERYEXTLIBPATH
132#define ORD_DOS32QUERYEXTLIBPATH 874
133#endif
134
135BOOL IsFm2Window(HWND hwnd, BOOL chkTid)
136{
137 PIB *ppib;
138 TIB *ptib;
139 BOOL yes;
140 APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
141
142 if (rc) {
143 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
144 PCSZ_DOSGETINFOBLOCKS);
145 yes = FALSE;
146 }
147 else {
148 PID pid;
149 TID tid;
150
151 // Check window owned by FM2 process
152 // Check say same thread too, if requested
153 // OK for window to be dead - just return FALSE
154 yes = WinQueryWindowProcess(hwnd, &pid, &tid) &&
155 pid == ppib->pib_ulpid &&
156 (!chkTid || tid == ptib->tib_ptib2->tib2_ultid);
157 }
158 return yes;
159}
160
161#ifdef FORTIFY
162
163/**
164 * Return thread ordinal for fm/2 window
165 * window must exist and must be created by fm/2
166 * @param hwnd is window handle
167 * @returns thread ordinal or -1 if error
168 */
169
170INT GetTidForWindow(HWND hwnd)
171{
172 PIB *ppib;
173 TIB *ptib;
174 LONG ordinal = -1;
175 APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
176
177 if (rc) {
178 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
179 PCSZ_DOSGETINFOBLOCKS);
180 }
181 else {
182 PID pid;
183 TID tid;
184 if (!WinQueryWindowProcess(hwnd, &pid, &tid))
185 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryWindowProcess failed for %X", hwnd);
186 else if (pid != ppib->pib_ulpid)
187 Runtime_Error(pszSrcFile, __LINE__, "hwnd %X not created by fm/2", hwnd);
188 else
189 ordinal = ptib->tib_ptib2->tib2_ultid;
190 }
191 return ordinal;
192}
193
194/**
195 * Return thread ordinal for current thread
196 * @returns thread ordinal or -1 if error
197 */
198
199INT GetTidForThread(VOID)
200{
201 PIB *ppib;
202 TIB *ptib;
203 LONG ordinal = -1;
204 APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
205
206 if (rc) {
207 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
208 PCSZ_DOSGETINFOBLOCKS);
209 }
210 else
211 ordinal = ptib->tib_ptib2->tib2_ultid;
212
213 return ordinal;
214}
215
216#endif // FORTIFY
217
218VOID SetShiftState(VOID)
219{
220 shiftstate = 0;
221 if (WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
222 shiftstate |= KC_CTRL;
223 if (WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
224 shiftstate |= KC_SHIFT;
225 if (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000)
226 shiftstate |= KC_ALT;
227}
228
229void EmphasizeButton(HWND hwnd, BOOL on)
230{
231 HPS hps = DrgGetPS(hwnd);
232
233 // fixme to complain?
234 if (hps) {
235 POINTL ptl;
236 SWP swp;
237
238 WinQueryWindowPos(hwnd, &swp);
239 ptl.x = 1;
240 ptl.y = 1;
241 GpiMove(hps, &ptl);
242 GpiSetColor(hps, on ? CLR_BLACK : CLR_PALEGRAY);
243 ptl.x = swp.cx - 2;
244 ptl.y = swp.cy - 2;
245 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
246 DrgReleasePS(hps);
247 if (remove) //fixme always true
248 WinInvalidateRect(hwnd, NULL, FALSE);
249 }
250}
251
252void DrawTargetEmphasis(HWND hwnd, BOOL on)
253{
254 HPS hps = DrgGetPS(WinQueryWindow(hwnd, QW_PARENT));
255
256 if (hps) {
257 BoxWindow(hwnd, hps, on ? CLR_BLACK : CLR_PALEGRAY);
258 DrgReleasePS(hps);
259 }
260}
261
262void BoxWindow(HWND hwnd, HPS hps, LONG color)
263{
264 POINTL ptl;
265 SWP swp;
266 BOOL releaseme = FALSE;
267
268 if (!hps) {
269 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
270 releaseme = TRUE;
271 }
272 if (hps && WinQueryWindowPos(hwnd, &swp)) {
273 ptl.x = swp.x - 2;
274 ptl.y = swp.y - 2;
275 GpiMove(hps, &ptl);
276 GpiSetColor(hps, color);
277 ptl.x = swp.x + swp.cx + 1;
278 ptl.y = swp.y + swp.cy + 1;
279 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
280 }
281 if (releaseme && hps)
282 WinReleasePS(hps);
283}
284
285void PaintSTextWindow(HWND hwnd, HPS hps)
286{
287 /*
288 * paint a text window such that the rightmost part of the text is
289 * always visible even if the text length exceeds the length of the
290 * window -- otherwise, paint the window so that it is left-justified
291 * and vertically centered.
292 */
293
294 char *s = NULL;
295 long len;
296 POINTL aptl[TXTBOX_COUNT], ptl;
297 RECTL rcl;
298 char *p;
299 BOOL releaseme = FALSE;
300
301 if (!hps) {
302 releaseme = TRUE;
303 hps = WinGetPS(hwnd);
304 }
305 if (hps) {
306 WinQueryWindowRect(hwnd, &rcl);
307 WinFillRect(hps, &rcl, CLR_PALEGRAY);
308 len = WinQueryWindowTextLength(hwnd);
309 if (len)
310 s = xmalloc(len + 1, pszSrcFile, __LINE__);
311 if (s) {
312 *s = 0;
313 WinQueryWindowText(hwnd, CCHMAXPATH, s);
314 if (*s) {
315 rcl.xRight -= 3;
316 p = s;
317 GpiQueryTextBox(hps, 3, "...", TXTBOX_COUNT, aptl);
318 len = aptl[TXTBOX_TOPRIGHT].x;
319 do {
320 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
321 if (aptl[TXTBOX_TOPRIGHT].x > (rcl.xRight - (p != s ? len : 0)))
322 p++;
323 else
324 break;
325 }
326 while (*p);
327 if (*p) {
328 GpiSetMix(hps, FM_OVERPAINT);
329 GpiSetColor(hps, CLR_BLACK);
330 ptl.x = 3;
331 ptl.y = ((rcl.yTop / 2) -
332 ((aptl[TXTBOX_TOPRIGHT].y +
333 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
334 GpiMove(hps, &ptl);
335 if (p != s)
336 GpiCharString(hps, 3, "...");
337 GpiCharString(hps, strlen(p), p);
338 }
339 }
340 free(s);
341 }
342 if (releaseme)
343 WinReleasePS(hps);
344 }
345}
346
347VOID PaintRecessedWindow(HWND hwnd, HPS hps, BOOL outtie, BOOL dbl)
348{
349 /*
350 * paint a recessed box around the window
351 * two pixels width required around window for painting...
352 */
353 BOOL releaseme = FALSE;
354
355 if (!hps) {
356 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
357 releaseme = TRUE;
358 }
359 if (hps) {
360
361 POINTL ptl;
362 SWP swp;
363
364 WinQueryWindowPos(hwnd, &swp);
365 ptl.x = swp.x - 1;
366 ptl.y = swp.y - 1;
367 GpiMove(hps, &ptl);
368 if (!outtie)
369 GpiSetColor(hps, CLR_WHITE);
370 else
371 GpiSetColor(hps, CLR_DARKGRAY);
372 ptl.x = swp.x + swp.cx;
373 GpiLine(hps, &ptl);
374 ptl.y = swp.y + swp.cy;
375 GpiLine(hps, &ptl);
376 if (dbl) {
377 ptl.x = swp.x - 2;
378 ptl.y = swp.y - 2;
379 GpiMove(hps, &ptl);
380 ptl.x = swp.x + swp.cx + 1;
381 GpiLine(hps, &ptl);
382 ptl.y = swp.y + swp.cy + 1;
383 GpiLine(hps, &ptl);
384 }
385 if (!outtie)
386 GpiSetColor(hps, CLR_DARKGRAY);
387 else
388 GpiSetColor(hps, CLR_WHITE);
389 if (dbl) {
390 ptl.x = swp.x - 2;
391 GpiLine(hps, &ptl);
392 ptl.y = swp.y - 2;
393 GpiLine(hps, &ptl);
394 ptl.x = swp.x + swp.cx;
395 ptl.y = swp.y + swp.cy;
396 GpiMove(hps, &ptl);
397 }
398 ptl.x = swp.x - 1;
399 GpiLine(hps, &ptl);
400 ptl.y = swp.y - 1;
401 GpiLine(hps, &ptl);
402 GpiSetColor(hps, CLR_PALEGRAY);
403 ptl.x = swp.x - (2 + (dbl != FALSE));
404 ptl.y = swp.y - (2 + (dbl != FALSE));
405 GpiMove(hps, &ptl);
406 ptl.x = swp.x + swp.cx + (1 + (dbl != FALSE));
407 GpiLine(hps, &ptl);
408 ptl.y = swp.y + swp.cy + (1 + (dbl != FALSE));
409 GpiLine(hps, &ptl);
410 ptl.x = swp.x - (2 + (dbl != FALSE));
411 GpiLine(hps, &ptl);
412 ptl.y = swp.y - (2 + (dbl != FALSE));
413 GpiLine(hps, &ptl);
414 if (releaseme)
415 WinReleasePS(hps);
416 }
417}
418
419BOOL AdjustCnrColVis(HWND hwndCnr, PCSZ title, BOOL visible, BOOL toggle)
420{
421 PFIELDINFO pfi = (PFIELDINFO) WinSendMsg(hwndCnr,
422 CM_QUERYDETAILFIELDINFO,
423 MPVOID, MPFROMSHORT(CMA_FIRST));
424
425 while (pfi) {
426 if (!strcmp(pfi->pTitleData, title)) {
427 if (toggle) {
428 if (pfi->flData & CFA_INVISIBLE)
429 pfi->flData &= (~CFA_INVISIBLE);
430 else
431 pfi->flData |= CFA_INVISIBLE;
432 return !(pfi->flData & CFA_INVISIBLE);
433 }
434 else {
435 if (visible)
436 pfi->flData &= (~CFA_INVISIBLE);
437 else
438 pfi->flData |= CFA_INVISIBLE;
439 }
440 return TRUE;
441 }
442 pfi = pfi->pNextFieldInfo;
443 }
444 return FALSE;
445}
446
447BOOL AdjustCnrColRO(HWND hwndCnr, PCSZ title, BOOL readonly, BOOL toggle)
448{
449 PFIELDINFO pfi = (PFIELDINFO) WinSendMsg(hwndCnr,
450 CM_QUERYDETAILFIELDINFO,
451 MPVOID, MPFROMSHORT(CMA_FIRST));
452
453 while (pfi) {
454 if (!strcmp(pfi->pTitleData, title)) {
455 if (toggle) {
456 if (pfi->flData & CFA_FIREADONLY)
457 pfi->flData &= (~CFA_FIREADONLY);
458 else
459 pfi->flData |= CFA_FIREADONLY;
460 return (pfi->flData & CFA_FIREADONLY);
461 }
462 else {
463 if (!readonly)
464 pfi->flData &= (~CFA_FIREADONLY);
465 else
466 pfi->flData |= CFA_FIREADONLY;
467 }
468 return TRUE;
469 }
470 pfi = pfi->pNextFieldInfo;
471 }
472 return FALSE;
473}
474
475VOID AdjustCnrColsForFSType(HWND hwndCnr, PCSZ directory, DETAILS_SETTINGS * pds)
476{
477 CHAR FileSystem[CCHMAXPATH];
478 INT x;
479 BOOL hasCreateDT;
480 BOOL hasAccessDT;
481 BOOL hasLongNames;
482
483 if (!directory || !*directory)
484 return;
485 x = CheckDrive(toupper(*directory), FileSystem, NULL);
486 if (x != -1) {
487 if (!stricmp(FileSystem, HPFS) ||
488 !stricmp(FileSystem, JFS) ||
489 !stricmp(FileSystem, FAT32) ||
490 !stricmp(FileSystem, RAMFS) ||
491 !stricmp(FileSystem, NDFS32) ||
492 !stricmp(FileSystem, NTFS) ||
493 !stricmp(FileSystem, HPFS386)) {
494 hasCreateDT = TRUE;
495 hasAccessDT = TRUE;
496 hasLongNames = TRUE;
497 }
498 else if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
499 hasCreateDT = TRUE;
500 hasAccessDT = FALSE;
501 hasLongNames = FALSE;
502 }
503 else {
504 // Assume FAT
505 hasCreateDT = FALSE;
506 hasAccessDT = FALSE;
507 hasLongNames = FALSE;
508 }
509 }
510 else {
511 // Assume FAT
512 hasCreateDT = FALSE;
513 hasAccessDT = FALSE;
514 hasLongNames = FALSE;
515 }
516 AdjustCnrColVis(hwndCnr,
517 GetPString(IDS_LADATE),
518 pds->detailsladate ? hasAccessDT : FALSE,
519 FALSE);
520 AdjustCnrColVis(hwndCnr,
521 GetPString(IDS_LATIME),
522 pds->detailslatime ? hasAccessDT : FALSE,
523 FALSE);
524 AdjustCnrColVis(hwndCnr,
525 GetPString(IDS_CRDATE),
526 pds->detailscrdate ? hasCreateDT : FALSE,
527 FALSE);
528 AdjustCnrColVis(hwndCnr,
529 GetPString(IDS_CRTIME),
530 pds->detailscrtime ? hasCreateDT : FALSE,
531 FALSE);
532 AdjustCnrColVis(hwndCnr,
533 GetPString(IDS_LNAME),
534 pds->detailslongname ? hasLongNames : FALSE,
535 FALSE);
536 WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
537}
538
539VOID AdjustCnrColsForPref(HWND hwndCnr, PCSZ directory, DETAILS_SETTINGS * pds,
540 BOOL compare)
541{
542
543 AdjustCnrColVis(hwndCnr,
544 compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
545 pds->detailssubject,
546 FALSE);
547
548 AdjustCnrColVis(hwndCnr, GetPString(IDS_ATTR), pds->detailsattr, FALSE);
549 AdjustCnrColVis(hwndCnr, GetPString(IDS_ICON), pds->detailsicon, FALSE);
550 AdjustCnrColVis(hwndCnr, GetPString(IDS_LWDATE), pds->detailslwdate, FALSE);
551 AdjustCnrColVis(hwndCnr, GetPString(IDS_LWTIME), pds->detailslwtime, FALSE);
552 AdjustCnrColVis(hwndCnr, GetPString(IDS_EA), pds->detailsea, FALSE);
553 AdjustCnrColVis(hwndCnr, GetPString(IDS_SIZE), pds->detailssize, FALSE);
554
555 if (!directory) {
556 AdjustCnrColVis(hwndCnr, GetPString(IDS_LADATE), pds->detailsladate, FALSE);
557 AdjustCnrColVis(hwndCnr, GetPString(IDS_LATIME), pds->detailslatime, FALSE);
558 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRDATE), pds->detailscrdate, FALSE);
559 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRTIME), pds->detailscrtime, FALSE);
560 AdjustCnrColVis(hwndCnr, GetPString(IDS_LNAME), pds->detailslongname, FALSE);
561 WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
562 }
563 else
564 AdjustCnrColsForFSType(hwndCnr, directory, pds);
565}
566
567BOOL SetCnrCols(HWND hwndCnr, BOOL isCompCnr)
568{
569 BOOL fSuccess = TRUE;
570 PFIELDINFO pfi, pfiLastLeftCol, pfiIconCol;
571
572 // Allocate storage for container column data
573
574 pfi = WinSendMsg(hwndCnr, CM_ALLOCDETAILFIELDINFO,
575 MPFROMLONG(CONTAINER_COLUMNS), NULL);
576
577 if (!pfi) {
578 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_ALLOCDETAILFIELDINFO");
579 fSuccess = FALSE;
580 }
581 else {
582
583 PFIELDINFO pfiFirst;
584 FIELDINFOINSERT fii;
585
586 // Store original value of pfi so we won't lose it when it changes.
587 // This will be needed on the CM_INSERTDETAILFIELDINFO message.
588
589 pfiFirst = pfi;
590
591 // Fill in column information for the icon column
592
593 pfi->flData = CFA_BITMAPORICON | CFA_CENTER | CFA_FIREADONLY;
594 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
595 pfi->pTitleData = (PSZ)GetPString(IDS_ICON);
596 pfi->offStruct = FIELDOFFSET(MINIRECORDCORE, hptrIcon);
597
598 pfiIconCol = pfi;
599
600 // Fill in column information for the file name. Note that we are
601 // using the pszDisplayName variable rather than pszFileName. We do this
602 // because the container does not always display the full path file name.
603
604 pfi = pfi->pNextFieldInfo;
605
606 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
607 pfi->flTitle = CFA_LEFT;
608 pfi->pTitleData = (PSZ)GetPString(IDS_FILENAME);
609 pfi->offStruct = FIELDOFFSET(CNRITEM, pszDisplayName);
610
611 // Fill in column information for the longname.
612
613 pfi = pfi->pNextFieldInfo;
614 pfi->flData = CFA_STRING | CFA_LEFT;
615 pfi->flTitle = CFA_LEFT | CFA_FITITLEREADONLY;
616 pfi->pTitleData = (PSZ)GetPString(IDS_LNAME);
617 pfi->offStruct = FIELDOFFSET(CNRITEM, pszLongName);
618
619 // Fill in column info for subjects
620
621 if (dsDirCnrDefault.fSubjectInLeftPane) {
622 pfi = pfi->pNextFieldInfo;
623 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
624 if (isCompCnr)
625 pfi->flData |= CFA_FIREADONLY;
626 pfi->flTitle = CFA_LEFT | CFA_FITITLEREADONLY;
627 pfi->pTitleData = isCompCnr ? (PSZ)GetPString(IDS_STATUS) :
628 (PSZ)GetPString(IDS_SUBJ);
629 pfi->offStruct = FIELDOFFSET(CNRITEM, pszSubject);
630 pfi->cxWidth = dsDirCnrDefault.SubjectDisplayWidth;
631
632 // Store the current pfi value as that will be used to indicate the
633 // last column in the lefthand container window (we have a splitbar)
634
635 pfiLastLeftCol = pfi;
636 }
637 else {
638 // Store the current pfi value as that will be used to indicate the
639 // last column in the lefthand container window (we have a splitbar)
640
641 pfiLastLeftCol = pfi;
642 pfi = pfi->pNextFieldInfo;
643 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
644 if (isCompCnr)
645 pfi->flData |= CFA_FIREADONLY;
646 pfi->flTitle = CFA_LEFT | CFA_FITITLEREADONLY;
647 pfi->pTitleData = isCompCnr ? (PSZ)GetPString(IDS_STATUS) :
648 (PSZ)GetPString(IDS_SUBJ);
649 pfi->offStruct = FIELDOFFSET(CNRITEM, pszSubject);
650 pfi->cxWidth = dsDirCnrDefault.SubjectDisplayWidth;
651 }
652
653 // Fill in column information for the file size
654
655
656 pfi = pfi->pNextFieldInfo;
657 pfi->flData = CFA_STRING | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
658 pfi->flTitle = CFA_CENTER;
659 pfi->pTitleData = (PSZ)GetPString(IDS_SIZE);
660 pfi->offStruct = FIELDOFFSET(CNRITEM, pszFmtFileSize);
661
662
663 // Fill in the column information for the file's ea size
664
665 pfi = pfi->pNextFieldInfo;
666 pfi->flData = CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
667 pfi->flTitle = CFA_CENTER;
668 pfi->pTitleData = (PSZ)GetPString(IDS_EA);
669 pfi->offStruct = FIELDOFFSET(CNRITEM, easize);
670
671 // Fill in the column information for the file attribute
672
673 pfi = pfi->pNextFieldInfo;
674 pfi->flData = CFA_STRING | CFA_CENTER | CFA_SEPARATOR | CFA_FIREADONLY;
675 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
676 pfi->pTitleData = (PSZ)GetPString(IDS_ATTR);
677 pfi->offStruct = FIELDOFFSET(CNRITEM, pszDispAttr);
678
679 // Fill in column information for last write file date
680
681 pfi = pfi->pNextFieldInfo;
682 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
683 pfi->flTitle = CFA_CENTER;
684 pfi->pTitleData = (PSZ)GetPString(IDS_LWDATE);
685 pfi->offStruct = FIELDOFFSET(CNRITEM, date);
686
687 // Fill in column information for the last write file time
688
689 pfi = pfi->pNextFieldInfo;
690 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
691 pfi->flTitle = CFA_CENTER;
692 pfi->pTitleData = (PSZ)GetPString(IDS_LWTIME);
693 pfi->offStruct = FIELDOFFSET(CNRITEM, time);
694
695 // Fill in column information for last access file date
696
697 pfi = pfi->pNextFieldInfo;
698 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
699 pfi->flTitle = CFA_CENTER;
700 pfi->pTitleData = (PSZ)GetPString(IDS_LADATE);
701 pfi->offStruct = FIELDOFFSET(CNRITEM, ladate);
702
703 // Fill in column information for the last access file time
704
705 pfi = pfi->pNextFieldInfo;
706 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
707 pfi->flTitle = CFA_CENTER;
708 pfi->pTitleData = (PSZ)GetPString(IDS_LATIME);
709 pfi->offStruct = FIELDOFFSET(CNRITEM, latime);
710
711 // Fill in column information for create file date
712
713 pfi = pfi->pNextFieldInfo;
714 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
715 pfi->flTitle = CFA_CENTER;
716 pfi->pTitleData = (PSZ)GetPString(IDS_CRDATE);
717 pfi->offStruct = FIELDOFFSET(CNRITEM, crdate);
718
719 // Fill in column information for the create file time
720
721 pfi = pfi->pNextFieldInfo;
722 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_FIREADONLY;
723 pfi->flTitle = CFA_CENTER;
724 pfi->pTitleData = (PSZ)GetPString(IDS_CRTIME);
725 pfi->offStruct = FIELDOFFSET(CNRITEM, crtime);
726
727 // Use the CM_INSERTDETAILFIELDINFO message to tell the container
728 // all the column information it needs to function properly. Place
729 // this column info first in the column list and update the display
730 // after they are inserted (fInvalidateFieldInfo = TRUE)
731
732 (void)memset(&fii, 0, sizeof(FIELDINFOINSERT));
733
734 fii.cb = sizeof(FIELDINFOINSERT);
735 fii.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
736 fii.cFieldInfoInsert = (SHORT) CONTAINER_COLUMNS;
737 fii.fInvalidateFieldInfo = TRUE;
738
739 if (!WinSendMsg(hwndCnr, CM_INSERTDETAILFIELDINFO, MPFROMP(pfiFirst),
740 MPFROMP(&fii))) {
741 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_INSERTDETAILFIELDINFO");
742 fSuccess = FALSE;
743 }
744 }
745
746 if (fSuccess) {
747
748 CNRINFO cnri;
749 ULONG size;
750
751 // Tell the container about the splitbar and where it goes
752
753 cnri.cb = sizeof(CNRINFO);
754 cnri.pFieldInfoLast = pfiLastLeftCol;
755 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
756 cnri.pFieldInfoObject = pfiIconCol;
757 size = sizeof(LONG);
758 PrfQueryProfileData(fmprof,
759 appname, "CnrSplitBar", &cnri.xVertSplitbar, &size);
760 if (cnri.xVertSplitbar <= 0)
761 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
762 if (!WinSendMsg(hwndCnr, CM_SETCNRINFO, MPFROMP(&cnri),
763 MPFROMLONG(CMA_PFIELDINFOLAST | CMA_PFIELDINFOOBJECT |
764 CMA_XVERTSPLITBAR))) {
765 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_SETCNRINFO");
766 fSuccess = FALSE;
767 }
768 }
769
770 return fSuccess;
771}
772
773MRESULT CnrDirectEdit(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
774{
775 switch (SHORT2FROMMP(mp1)) {
776 case CN_BEGINEDIT:
777 if (mp2) {
778 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
779 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
780
781 if (pci &&
782 (INT) pci != -1 &&
783 !IsRoot(pci->pszFileName) &&
784 !(pci->flags & RECFLAGS_ENV) && !(pci->flags & RECFLAGS_UNDERENV)) {
785 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName)) {
786 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMP(pci->pszFileName), MPVOID);
787 }
788 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject))
789 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(1048), MPVOID);
790 else
791 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(CCHMAXPATH), MPVOID);
792 }
793 else
794 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
795 }
796 break;
797
798 case CN_REALLOCPSZ:
799 if (mp2) {
800 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
801 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
802 CHAR szData[CCHMAXPATH], testname[CCHMAXPATH];
803 HWND hwndMLE = WinWindowFromID(hwnd, CID_MLE);
804 BOOL fResetVerify = FALSE;
805
806 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
807 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject)) {
808
809 APIRET rc;
810 EAOP2 eaop;
811 PFEA2LIST pfealist = NULL;
812 CHAR szSubject[1048];
813 ULONG ealen;
814 USHORT len;
815 CHAR *eaval;
816 LONG retlen;
817 PSZ psz;
818
819 retlen = WinQueryWindowText(hwndMLE, sizeof(szSubject), szSubject);
820 szSubject[retlen + 1] = 0;
821 bstrip(szSubject);
822 if (pci->pszSubject != NullStr) {
823 if (retlen == 0) {
824 psz = pci->pszSubject;
825 pci->pszSubject = NullStr;
826 xfree(psz, pszSrcFile, __LINE__);
827 }
828 else
829 pci->pszSubject = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
830 }
831 else {
832 pci->pszSubject = xmalloc(retlen + 1, pszSrcFile, __LINE__);
833 if (!pci->pszSubject)
834 return FALSE;
835 }
836 len = strlen(szSubject);
837 if (len)
838 ealen = sizeof(FEA2LIST) + 9 + len + 4;
839 else
840 ealen = sizeof(FEALIST) + 9;
841 rc = DosAllocMem((PPVOID) & pfealist, ealen + 64,
842 OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
843 if (rc)
844 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile,
845 __LINE__, GetPString(IDS_OUTOFMEMORY));
846 else {
847 memset(pfealist, 0, ealen + 1);
848 pfealist->cbList = ealen;
849 pfealist->list[0].oNextEntryOffset = 0;
850 pfealist->list[0].fEA = 0;
851 pfealist->list[0].cbName = 8;
852 strcpy(pfealist->list[0].szName, SUBJECT);
853 if (len) {
854 eaval = pfealist->list[0].szName + 9;
855 *(USHORT *) eaval = (USHORT) EAT_ASCII;
856 eaval += sizeof(USHORT);
857 *(USHORT *) eaval = (USHORT) len;
858 eaval += sizeof(USHORT);
859 memcpy(eaval, szSubject, len);
860 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
861 }
862 else
863 pfealist->list[0].cbValue = 0;
864 eaop.fpGEA2List = (PGEA2LIST) 0;
865 eaop.fpFEA2List = pfealist;
866 eaop.oError = 0;
867 rc = xDosSetPathInfo(pci->pszFileName, FIL_QUERYEASIZE,
868 &eaop, sizeof(eaop), DSPI_WRTTHRU);
869 DosFreeMem(pfealist);
870 if (rc)
871 return FALSE;
872 }
873 return (MRESULT) TRUE;
874 }
875 else if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszLongName)) {
876
877 CHAR longname[CCHMAXPATHCOMP];
878 LONG retlen;
879 PSZ psz;
880
881 *longname = 0;
882 retlen = WinQueryWindowText(hwndMLE, sizeof(longname), longname);
883 longname[retlen + 1] = 0;
884 chop_at_crnl(longname);
885 bstrip(longname);
886 WinSetWindowText(hwndMLE, longname);
887 if (pci->pszLongName != NullStr) {
888 if (retlen == 0) {
889 psz = pci->pszLongName;
890 pci->pszLongName = NullStr;
891 xfree(psz, pszSrcFile, __LINE__);
892 }
893 else
894 pci->pszLongName = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
895 }
896 else {
897 pci->pszLongName = xmalloc(retlen + 1, pszSrcFile, __LINE__);
898 if (!pci->pszLongName)
899 return FALSE;
900 }
901 return (MRESULT) WriteLongName(pci->pszFileName, longname);
902 }
903 else {
904 WinQueryWindowText(hwndMLE, sizeof(szData), szData);
905 if (strchr(szData, '?') ||
906 strchr(szData, '*') || IsRoot(pci->pszFileName))
907 return (MRESULT) FALSE;
908 /* If the text changed, rename the file system object. */
909 chop_at_crnl(szData);
910 bstrip(szData);
911 if (!IsFullName(szData))
912 Runtime_Error(pszSrcFile, __LINE__, "bad name");
913 else {
914 if (DosQueryPathInfo(szData,
915 FIL_QUERYFULLNAME,
916 testname, sizeof(testname)))
917 return FALSE;
918 if (DosQueryPathInfo(pci->pszFileName,
919 FIL_QUERYFULLNAME,
920 szData,
921 sizeof(szData)))
922 {
923 pci->pszFileName = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__);
924 strcpy(szData, pci->pszFileName);
925 }
926 WinSetWindowText(hwndMLE, szData);
927 if (strcmp(szData, testname)) {
928 if (stricmp(szData, testname) && IsFile(testname) != -1) {
929 if (!fAlertBeepOff)
930 DosBeep(50, 100); /* exists; disallow */
931 return (MRESULT) FALSE;
932 }
933 if (fVerify && (driveflags[toupper(*szData) - 'A'] & DRIVE_WRITEVERIFYOFF ||
934 driveflags[toupper(*testname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
935 DosSetVerify(FALSE);
936 fResetVerify = TRUE;
937 }
938 if (docopyf(MOVE, szData, "%s", testname))
939 Runtime_Error(pszSrcFile, __LINE__, "docopyf");
940 else {
941 CHAR *filename;
942
943 filename = xstrdup(testname, pszSrcFile, __LINE__);
944 if (filename) {
945 if (!PostMsg(hwnd,
946 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
947 free(filename);
948 }
949 if (stricmp(testname, pci->pszFileName)) {
950 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci));
951 filename = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
952 if (filename) {
953 if (!PostMsg(hwnd,
954 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
955 free(filename);
956 }
957 }
958 }
959 if (fResetVerify) {
960 DosSetVerify(fVerify);
961 fResetVerify = FALSE;
962 }
963 }
964 }
965 }
966 }
967 }
968 return FALSE;
969
970 case CN_ENDEDIT:
971 if (mp2) {
972 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
973 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
974
975 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
976 WinSendMsg(hwnd,
977 CM_INVALIDATERECORD,
978 MPFROMP(&pci),
979 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
980 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName))
981 PostMsg(hwnd, UM_SORTRECORD, MPVOID, MPVOID);
982 }
983 else {
984 USHORT cmd = 0;
985
986 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName))
987 cmd = IDM_SORTSMARTNAME;
988 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, cbFile))
989 cmd = IDM_SORTSIZE;
990 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, easize))
991 cmd = IDM_SORTEASIZE;
992 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, date))
993 cmd = IDM_SORTLWDATE;
994 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, time))
995 cmd = IDM_SORTLWDATE;
996 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, ladate))
997 cmd = IDM_SORTLADATE;
998 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, latime))
999 cmd = IDM_SORTLADATE;
1000 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crdate))
1001 cmd = IDM_SORTCRDATE;
1002 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crtime))
1003 cmd = IDM_SORTCRDATE;
1004 if (cmd)
1005 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
1006 }
1007 }
1008 break;
1009 }
1010 return (MRESULT) - 1;
1011}
1012
1013BOOL SetMenuCheck(HWND hwndMenu, USHORT id, BOOL * bool, BOOL toggle,
1014 PCSZ savename)
1015{
1016 if (toggle) {
1017 *bool = *bool ? FALSE : TRUE;
1018 if (savename && *savename)
1019 PrfWriteProfileData(fmprof, appname, savename, bool, sizeof(BOOL));
1020 }
1021 WinSendMsg(hwndMenu, MM_SETITEMATTR,
1022 MPFROM2SHORT(id, 1),
1023 MPFROM2SHORT(MIA_CHECKED, (*bool ? MIA_CHECKED : 0)));
1024 return *bool;
1025}
1026
1027//== disable_menuitem() disable or enable_menuitem ==
1028
1029VOID disable_menuitem(HWND hwndMenu, USHORT id, BOOL disable)
1030{
1031 WinSendMsg(hwndMenu, MM_SETITEMATTR,
1032 MPFROM2SHORT(id, TRUE),
1033 MPFROM2SHORT(MIA_DISABLED, (disable ? MIA_DISABLED : 0)));
1034}
1035
1036//== ViewHelp() invoke view.exe, return TRUE if OK ==
1037
1038BOOL ViewHelp(PCSZ filename)
1039{
1040 CHAR s[CCHMAXPATH + 81];
1041 CHAR szQuotedFileName[CCHMAXPATH];
1042 FILE *fp;
1043 INT ret = -1;
1044
1045 fp = _fsopen(filename, "rb", SH_DENYNO);
1046 if (fp) {
1047 *s = 0;
1048 fread(s, 1, 3, fp);
1049 if (*s != 'H' || s[1] != 'S' || s[2] != 'P') {
1050 fclose(fp);
1051 return FALSE;
1052 }
1053 fclose(fp);
1054 ret = runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, pszSrcFile, __LINE__,
1055 NULL, NULL,
1056 "VIEW.EXE \"%s\"",
1057 BldQuotedFileName(szQuotedFileName, filename));
1058 }
1059
1060 return (ret != -1);
1061}
1062
1063//== ExecFile() run file, return 1 if OK 0 if skipped -1 if can't run ==
1064
1065INT ExecFile(HWND hwnd, PCSZ filename)
1066{
1067 EXECARGS ex;
1068 CHAR path[CCHMAXPATH], *p;
1069 PSZ pszCmdLine;
1070 APIRET ret;
1071 static INT lastflags = 0;
1072
1073 strcpy(path, filename);
1074 p = strrchr(path, '\\');
1075 if (!p)
1076 p = strrchr(path, ':');
1077 if (p) {
1078 if (*p == ':') {
1079 p++;
1080 *p = '\\';
1081 p++;
1082 }
1083 *p = 0;
1084 }
1085 else
1086 *path = 0;
1087 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1088 if (pszCmdLine) {
1089 BldQuotedFileName(pszCmdLine, filename);
1090 memset(&ex, 0, sizeof(ex));
1091 ex.flags = lastflags;
1092 ex.commandline = pszCmdLine;
1093 *ex.path = 0;
1094 *ex.environment = 0;
1095 ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
1096 EXEC_FRAME, &ex);
1097 if (ret == 1) {
1098 lastflags = ex.flags;
1099 return runemf2(ex.flags, hwnd, pszSrcFile, __LINE__, path,
1100 *ex.environment ? ex.environment : NULL,
1101 "%s", pszCmdLine) != -1;
1102 }
1103 else if (ret != 0)
1104 return -1;
1105 free(pszCmdLine);
1106 }
1107 return 0;
1108}
1109
1110VOID SetDetailsSwitches(HWND hwnd, DETAILS_SETTINGS * pds)
1111{
1112 WinCheckMenuItem(hwnd, IDM_SHOWLNAMES, pds->detailslongname);
1113 WinCheckMenuItem(hwnd, IDM_SHOWSUBJECT, pds->detailssubject);
1114 WinCheckMenuItem(hwnd, IDM_SHOWEAS, pds->detailsea);
1115 WinCheckMenuItem(hwnd, IDM_SHOWSIZE, pds->detailssize);
1116 WinCheckMenuItem(hwnd, IDM_SHOWICON, pds->detailsicon);
1117 WinCheckMenuItem(hwnd, IDM_SHOWLWDATE, pds->detailslwdate);
1118 WinCheckMenuItem(hwnd, IDM_SHOWLWTIME, pds->detailslwtime);
1119 WinCheckMenuItem(hwnd, IDM_SHOWLADATE, pds->detailsladate);
1120 WinCheckMenuItem(hwnd, IDM_SHOWLATIME, pds->detailslatime);
1121 WinCheckMenuItem(hwnd, IDM_SHOWCRDATE, pds->detailscrdate);
1122 WinCheckMenuItem(hwnd, IDM_SHOWCRTIME, pds->detailscrtime);
1123 WinCheckMenuItem(hwnd, IDM_SHOWATTR, pds->detailsattr);
1124}
1125
1126VOID AdjustDetailsSwitches(HWND hwnd, HWND hwndMenu, USHORT cmd,
1127 PCSZ directory, PCSZ keyroot,
1128 DETAILS_SETTINGS * pds, BOOL compare)
1129{
1130 BOOL *bool = NULL;
1131
1132 switch (cmd) {
1133 case IDM_SHOWLNAMES:
1134 bool = &pds->detailslongname;
1135 break;
1136 case IDM_SHOWSUBJECT:
1137 bool = &pds->detailssubject;
1138 break;
1139 case IDM_SHOWEAS:
1140 bool = &pds->detailsea;
1141 break;
1142 case IDM_SHOWSIZE:
1143 bool = &pds->detailssize;
1144 break;
1145 case IDM_SHOWICON:
1146 bool = &pds->detailsicon;
1147 break;
1148 case IDM_SHOWLWDATE:
1149 bool = &pds->detailslwdate;
1150 break;
1151 case IDM_SHOWLWTIME:
1152 bool = &pds->detailslwtime;
1153 break;
1154 case IDM_SHOWLADATE:
1155 bool = &pds->detailsladate;
1156 break;
1157 case IDM_SHOWLATIME:
1158 bool = &pds->detailslatime;
1159 break;
1160 case IDM_SHOWCRDATE:
1161 bool = &pds->detailscrdate;
1162 break;
1163 case IDM_SHOWCRTIME:
1164 bool = &pds->detailscrtime;
1165 break;
1166 case IDM_SHOWATTR:
1167 bool = &pds->detailsattr;
1168 break;
1169 default:
1170 if (hwndMenu)
1171 SetDetailsSwitches(hwndMenu, pds);
1172 return;
1173 }
1174 if (bool)
1175 *bool = *bool ? FALSE : TRUE;
1176 if (hwnd)
1177 AdjustCnrColsForPref(hwnd, directory, pds, compare);
1178 if (hwndMenu)
1179 SetDetailsSwitches(hwndMenu, pds);
1180}
1181
1182/**
1183 * Set default menu item to invoke for top level conditional cascade menu
1184 * @param def is default menu id (i.e. IDM_...)
1185 */
1186
1187VOID SetConditionalCascade(HWND hwndMenu, USHORT id, USHORT def)
1188{
1189 MENUITEM mi;
1190
1191 mi.iPosition = MIT_END;
1192 mi.hItem = 0;
1193 mi.hwndSubMenu = (HWND)0;
1194 mi.afAttribute = 0;
1195 mi.afStyle = MIS_TEXT;
1196 if (WinSendMsg(hwndMenu,
1197 MM_QUERYITEM,
1198 MPFROM2SHORT(id, TRUE),
1199 MPFROMP(&mi)))
1200 {
1201 WinSetWindowBits(mi.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE,
1202 MS_CONDITIONALCASCADE);
1203 WinSendMsg(mi.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(def), MPVOID);
1204 WinCheckMenuItem(mi.hwndSubMenu, def, TRUE);
1205 }
1206}
1207
1208VOID SetSortChecks(HWND hwndMenu, INT sortflags)
1209{
1210 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, FALSE);
1211 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, FALSE);
1212 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, FALSE);
1213 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, FALSE);
1214 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, FALSE);
1215 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, FALSE);
1216 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, FALSE);
1217 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, FALSE);
1218 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, FALSE);
1219 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, FALSE);
1220 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, FALSE);
1221 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, FALSE);
1222 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, FALSE);
1223 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, FALSE);
1224 if (sortflags & SORT_FIRSTEXTENSION)
1225 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, TRUE);
1226 else if (sortflags & SORT_LASTEXTENSION)
1227 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, TRUE);
1228 else if (sortflags & SORT_SIZE)
1229 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, TRUE);
1230 else if (sortflags & SORT_EASIZE)
1231 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, TRUE);
1232 else if (sortflags & SORT_LWDATE)
1233 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, TRUE);
1234 else if (sortflags & SORT_LADATE)
1235 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, TRUE);
1236 else if (sortflags & SORT_CRDATE)
1237 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, TRUE);
1238 else if (sortflags & SORT_FILENAME)
1239 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, TRUE);
1240 else if (sortflags & SORT_NOSORT)
1241 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, TRUE);
1242 else if (sortflags & SORT_SUBJECT)
1243 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, TRUE);
1244 else
1245 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, TRUE);
1246 if (sortflags & SORT_DIRSFIRST)
1247 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, TRUE);
1248 else if (sortflags & SORT_DIRSLAST)
1249 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, TRUE);
1250 if (sortflags & SORT_REVERSE)
1251 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, TRUE);
1252}
1253
1254VOID FcloseFile(FILE * fp)
1255{
1256 /* for use by apps that don't use the DLLs runtime library */
1257 fclose(fp);
1258}
1259
1260VOID SetupCommandMenu(HWND hwndMenu, HWND hwndCnr)
1261{
1262 MENUITEM mi, mit;
1263 INT x;
1264 SHORT numitems;
1265 LINKCMDS *info;
1266
1267 if (!cmdloaded)
1268 load_commands();
1269 mi.iPosition = MIT_END;
1270 mi.hwndSubMenu = (HWND) 0;
1271 mi.hItem = 0L;
1272 mi.afAttribute = 0;
1273 mi.afStyle = MIS_TEXT;
1274 memset(&mit, 0, sizeof(MENUITEM));
1275 if (WinQueryWindowUShort(hwndMenu, QWS_ID) == IDM_COMMANDSMENU)
1276 mit.hwndSubMenu = hwndMenu;
1277 else
1278 WinSendMsg(hwndMenu, MM_QUERYITEM,
1279 MPFROM2SHORT(IDM_COMMANDSMENU, TRUE), MPFROMP(&mit));
1280 if (mit.hwndSubMenu) {
1281 numitems = (SHORT) WinSendMsg(mit.hwndSubMenu, MM_QUERYITEMCOUNT,
1282 MPVOID, MPVOID);
1283 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM, MPFROMSHORT(-1), MPVOID);
1284 for (x = 0; x < numitems; x++)
1285 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
1286 MPFROMSHORT((SHORT) (x + IDM_COMMANDSTART)), MPVOID);
1287 if (hwndCnr && cmdhead) {
1288 x = 0;
1289 info = cmdhead;
1290 while (info) {
1291
1292 CHAR s[CCHMAXPATH + 24];
1293
1294 sprintf(s,
1295 "%s%s%s",
1296 info->title,
1297 x < 20 ? "\tCtrl + " : NullStr,
1298 x < 20 && x > 9 ? "Shift + " : NullStr);
1299 if (x < 20)
1300 sprintf(&s[strlen(s)], "%d",
1301 ((x % 10) + 1) == 10 ? 0 : (x % 10) + 1);
1302 mi.id = IDM_COMMANDSTART + x;
1303 mi.afAttribute = (info->flags & ONCE ? MIA_CHECKED : 0) |
1304 (info->flags & PROMPT ? MIA_FRAMED : 0);
1305 mi.afStyle = MIS_TEXT;
1306 if (!(x % 24) && x && info->next)
1307 mi.afStyle |= MIS_BREAK;
1308 WinSendMsg(mit.hwndSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s));
1309 x++;
1310 info = info->next;
1311 }
1312 }
1313 }
1314}
1315
1316VOID LoadDetailsSwitches(PCSZ keyroot, DETAILS_SETTINGS * pds)
1317{
1318 ULONG size;
1319 CHAR s[CCHMAXPATH], *eos = s;
1320
1321 strcpy(s, keyroot);
1322 strcat(s, ".");
1323 eos = &s[strlen(s)];
1324 strcpy(eos, "DetailsLongname");
1325 pds->detailslongname = dsDirCnrDefault.detailslongname;
1326 size = sizeof(BOOL);
1327 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailslongname, &size);
1328 strcpy(eos, "DetailsSubject");
1329 pds->detailssubject = dsDirCnrDefault.detailssubject;
1330 size = sizeof(BOOL);
1331 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailssubject, &size);
1332 strcpy(eos, "DetailsEA");
1333 pds->detailsea = dsDirCnrDefault.detailsea;
1334 size = sizeof(BOOL);
1335 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailsea, &size);
1336 strcpy(eos, "DetailsSize");
1337 pds->detailssize = dsDirCnrDefault.detailssize;
1338 size = sizeof(BOOL);
1339 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailssize, &size);
1340 strcpy(eos, "DetailsIcon");
1341 pds->detailsicon = dsDirCnrDefault.detailsicon;
1342 size = sizeof(BOOL);
1343 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailsicon, &size);
1344 strcpy(eos, "DetailsAttr");
1345 pds->detailsattr = dsDirCnrDefault.detailsattr;
1346 size = sizeof(BOOL);
1347 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailsattr, &size);
1348 strcpy(eos, "DetailsCRDate");
1349 pds->detailscrdate = dsDirCnrDefault.detailscrdate;
1350 size = sizeof(BOOL);
1351 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailscrdate, &size);
1352 strcpy(eos, "DetailsCRTime");
1353 pds->detailscrtime = dsDirCnrDefault.detailscrtime;
1354 size = sizeof(BOOL);
1355 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailscrtime, &size);
1356 strcpy(eos, "DetailsLWDate");
1357 pds->detailslwdate = dsDirCnrDefault.detailslwdate;
1358 size = sizeof(BOOL);
1359 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailslwdate, &size);
1360 strcpy(eos, "DetailsLWTime");
1361 pds->detailslwtime = dsDirCnrDefault.detailslwtime;
1362 size = sizeof(BOOL);
1363 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailslwtime, &size);
1364 strcpy(eos, "DetailsLADate");
1365 pds->detailsladate = dsDirCnrDefault.detailsladate;
1366 size = sizeof(BOOL);
1367 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailsladate, &size);
1368 strcpy(eos, "DetailsLATime");
1369 pds->detailslatime = dsDirCnrDefault.detailslatime;
1370 size = sizeof(BOOL);
1371 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->detailslatime, &size);
1372 strcpy(eos, "SubjectInLeftPane");
1373 pds->fSubjectInLeftPane = dsDirCnrDefault.fSubjectInLeftPane;
1374 size = sizeof(BOOL);
1375 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->fSubjectInLeftPane, &size);
1376 strcpy(eos, "SubjectLengthMax");
1377 pds->fSubjectLengthMax = dsDirCnrDefault.fSubjectLengthMax;
1378 size = sizeof(BOOL);
1379 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->fSubjectLengthMax, &size);
1380 if (pds->fSubjectLengthMax)
1381 pds->SubjectDisplayWidth = 0;
1382 else {
1383 strcpy(eos, "SubjectDisplayWidth");
1384 pds->SubjectDisplayWidth = dsDirCnrDefault.SubjectDisplayWidth;
1385 size = sizeof(ULONG);
1386 PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->SubjectDisplayWidth, &size);
1387 if (pds->SubjectDisplayWidth < 50)
1388 pds->SubjectDisplayWidth = 0;
1389 else if (pds->SubjectDisplayWidth > 1000)
1390 pds->SubjectDisplayWidth = 1000;
1391 }
1392}
1393
1394HWND FindDirCnr(HWND hwndParent)
1395{
1396 HWND found, hwndDir = (HWND) 0;
1397 HENUM henum;
1398
1399 henum = WinBeginEnumWindows(hwndParent);
1400 while ((found = WinGetNextWindow(henum)) != NULLHANDLE) {
1401 hwndDir = WinWindowFromID(found, FID_CLIENT);
1402 if (hwndDir) {
1403 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
1404 if (hwndDir)
1405 break;
1406 hwndDir = (HWND) 0;
1407 }
1408 }
1409 WinEndEnumWindows(henum);
1410
1411 return hwndDir;
1412}
1413
1414VOID HeapThread(VOID * dummy)
1415{
1416 ULONG postcount;
1417 APIRET rc;
1418
1419 rc = DosCreateEventSem(NULL, &CompactSem, 0L, FALSE);
1420 if (rc)
1421 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1422 "DosCreateEventSem");
1423 else {
1424 priority_normal();
1425 for (;;) {
1426 if (DosWaitEventSem(CompactSem, SEM_INDEFINITE_WAIT))
1427 break;
1428 _heapmin();
1429 DosResetEventSem(CompactSem, &postcount);
1430 }
1431 }
1432}
1433
1434VOID FixSwitchList(HWND hwnd, PCSZ text)
1435{
1436 HSWITCH hswitch;
1437 SWCNTRL swctl;
1438
1439 hswitch = WinQuerySwitchHandle(hwnd, 0);
1440 if (hswitch) {
1441 if (!WinQuerySwitchEntry(hswitch, &swctl)) {
1442 strcpy(swctl.szSwtitle, "FM/2");
1443 WinChangeSwitchEntry(hswitch, &swctl);
1444 }
1445 }
1446}
1447
1448VOID QuickPopup(HWND hwnd, DIRCNRDATA * dcd, HWND hwndMenu, USHORT id)
1449{
1450 dcd->hwndLastMenu = hwndMenu;
1451 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
1452 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1453 MPFROM2SHORT(TRUE, CRA_SOURCE));
1454 dcd->cnremphasized = TRUE;
1455 }
1456 if (dcd->flWindowAttr & CV_MINI)
1457 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
1458 if (!WinPopupMenu(hwnd, hwnd, dcd->hwndLastMenu,
1459 8, 8, 0,
1460 PU_HCONSTRAIN | PU_VCONSTRAIN |
1461 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
1462 if (dcd->cnremphasized) {
1463 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1464 MPFROM2SHORT(FALSE, CRA_SOURCE));
1465 dcd->cnremphasized = FALSE;
1466 }
1467 }
1468 else
1469 WinSendMsg(dcd->hwndLastMenu, MM_SELECTITEM,
1470 MPFROM2SHORT(id, TRUE), MPFROM2SHORT(0, FALSE));
1471}
1472
1473PMINIRECORDCORE CurrentRecord(HWND hwndCnr)
1474{
1475 SHORT attrib = fSelectedAlways ? CRA_SELECTED : CRA_CURSORED;
1476 PMINIRECORDCORE pmi;
1477
1478 for (;;) {
1479 pmi = (PMINIRECORDCORE) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
1480 MPFROMLONG(CMA_FIRST),
1481 MPFROMSHORT(attrib));
1482 if ((!pmi || (INT) pmi == -1) && attrib == CRA_SELECTED) /* punt */
1483 attrib = CRA_CURSORED;
1484 else
1485 break;
1486 }
1487 return ((INT)pmi == -1) ? NULL : pmi;
1488}
1489
1490BOOL PostMsg(HWND h, ULONG msg, MPARAM mp1, MPARAM mp2)
1491{
1492 BOOL rc = WinPostMsg(h, msg, mp1, mp2);
1493
1494 if (!rc) {
1495
1496 // If window owned by some other process or some other thread?
1497 if (!IsFm2Window(h, 1)) {
1498 QMSG qmsg;
1499 for (;;) {
1500 DosSleep(1);
1501 rc = WinPostMsg(h, msg, mp1, mp2);
1502 if (rc)
1503 break; // OK
1504 if (!WinIsWindow((HAB) 0, h))
1505 break; // Window gone
1506 if (WinPeekMsg((HAB) 0, &qmsg, (HWND) 0, 0, 0, PM_NOREMOVE))
1507 break; // Queue has message(s)
1508 } // for
1509 }
1510 }
1511 return rc;
1512}
1513
1514VOID OpenEdit(HWND hwnd)
1515{
1516 CNREDITDATA ced;
1517 PCNRITEM pci;
1518 PFIELDINFO pfi;
1519
1520 pci = (PCNRITEM) WinSendMsg(hwnd,
1521 CM_QUERYRECORDEMPHASIS,
1522 MPFROMLONG(CMA_FIRST),
1523 MPFROMSHORT(CRA_CURSORED));
1524 if (pci && (INT) pci != -1) {
1525 memset(&ced, 0, sizeof(ced));
1526 ced.cb = sizeof(ced);
1527 ced.hwndCnr = hwnd;
1528 ced.id = WinQueryWindowUShort(hwnd, QWS_ID);
1529 ced.pRecord = (PRECORDCORE) pci;
1530 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1531 CM_QUERYDETAILFIELDINFO,
1532 MPVOID, MPFROMSHORT(CMA_FIRST));
1533 if (!pfi)
1534 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1535 else {
1536 while (pfi && (INT) pfi != -1 &&
1537 pfi->offStruct != FIELDOFFSET(CNRITEM, pszFileName))
1538 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1539 CM_QUERYDETAILFIELDINFO,
1540 MPFROMP(pfi), MPFROMSHORT(CMA_NEXT));
1541 if (pfi && (INT) pfi != -1) {
1542 ced.pFieldInfo = pfi;
1543 {
1544 CNRINFO cnri;
1545
1546 memset(&cnri, 0, sizeof(CNRINFO));
1547 cnri.cb = sizeof(CNRINFO);
1548 WinSendMsg(hwnd,
1549 CM_QUERYCNRINFO,
1550 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1551 if (cnri.flWindowAttr & CV_DETAIL)
1552 ced.id = CID_LEFTDVWND;
1553 }
1554 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1555 }
1556 }
1557 }
1558}
1559
1560#ifdef NEVER
1561VOID QuickView(HWND hwnd, PCSZ filename)
1562{
1563 if (filename && IsFile(filename) == 1) {
1564 if (TestBinary(filename) && *binview) {
1565
1566 CHAR *list[2];
1567
1568 list[0] = filename;
1569 list[1] = NULL;
1570 ExecOnList(hwnd, binview, WINDOWED | SEPARATE, NULL, list, NULL,
1571 pszSrcFile, __LINE__);
1572 return;
1573 }
1574 else if (*viewer) {
1575
1576 CHAR *list[2];
1577
1578 list[0] = filename;
1579 list[1] = NULL;
1580 ExecOnList(hwnd, viewer,
1581 WINDOWED | SEPARATE | (fViewChild ? CHILD : 0),
1582 NULL, list, NULL, pszSrcFile, __LINE__);
1583 return;
1584 }
1585 StartMLEEditor(HWND_DESKTOP, 5, filename, (HWND) 0);
1586 }
1587}
1588
1589VOID QuickEdit(HWND hwnd, CHAR * filename)
1590{
1591 if (filename && IsFile(filename) == 1) {
1592 if (TestBinary(filename) && *bined) {
1593
1594 CHAR *list[2];
1595
1596 list[0] = filename;
1597 list[1] = NULL;
1598 ExecOnList(hwnd, bined, WINDOWED | SEPARATE, NULL, list, NULL,
1599 pszSrcFile, __LINE__);
1600 return;
1601 }
1602 else if (*editor) {
1603
1604 CHAR *list[2];
1605
1606 list[0] = filename;
1607 list[1] = NULL;
1608 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, list, NULL,
1609 pszSrcFile, __LINE__);
1610 return;
1611 }
1612 StartMLEEditor(HWND_DESKTOP, 4, filename, (HWND) 0);
1613 }
1614}
1615#endif
1616
1617VOID PortholeInit(HWND hwndNew, MPARAM mp1, MPARAM mp2)
1618{
1619 static HWND DefMenu = (HWND) 0;
1620 HWND hwndMenu = (HWND) mp2;
1621
1622 {
1623 ULONG style;
1624
1625 style = WinQueryWindowULong(hwndMenu, QWL_STYLE);
1626 if (!(style & MS_ACTIONBAR))
1627 return;
1628 }
1629
1630 switch (SHORT1FROMMP(mp1)) {
1631 case 0:
1632 {
1633 HWND hwndNow;
1634 MENUITEM mi;
1635 ULONG ulStyle;
1636
1637 memset(&mi, 0, sizeof(mi));
1638 mi.iPosition = MIT_END;
1639 mi.afStyle = MIS_TEXT;
1640 WinSendMsg(hwndMenu, MM_QUERYITEM,
1641 MPFROM2SHORT(IDM_FILESMENU, TRUE), MPFROMP(&mi));
1642 if (!DefMenu)
1643 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1644 hwndNow = mi.hwndSubMenu;
1645 mi.hwndSubMenu = hwndNew;
1646 if (!mi.hwndSubMenu)
1647 mi.hwndSubMenu = DefMenu;
1648 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1649 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1650 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1651 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1652 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_FILESMENU);
1653 mi.afStyle = MIS_SUBMENU;
1654 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1655 ulStyle &= -WS_SAVEBITS;
1656 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1657 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1658 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1659 }
1660 break;
1661
1662 case 1:
1663 {
1664 HWND hwndNow;
1665 MENUITEM mi;
1666 ULONG ulStyle;
1667
1668 memset(&mi, 0, sizeof(mi));
1669 mi.iPosition = MIT_END;
1670 mi.afStyle = MIS_TEXT;
1671 WinSendMsg(hwndMenu, MM_QUERYITEM,
1672 MPFROM2SHORT(IDM_VIEWSMENU, TRUE), MPFROMP(&mi));
1673 if (!DefMenu)
1674 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1675 hwndNow = mi.hwndSubMenu;
1676 mi.hwndSubMenu = hwndNew;
1677 if (!mi.hwndSubMenu)
1678 mi.hwndSubMenu = DefMenu;
1679 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1680 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1681 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1682 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1683 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_VIEWSMENU);
1684 mi.afStyle = MIS_SUBMENU;
1685 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1686 ulStyle &= -WS_SAVEBITS;
1687 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1688 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1689 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1690 }
1691 break;
1692 }
1693}
1694
1695HWND CheckMenu(HWND hwnd, HWND * hwndMenu, USHORT id)
1696{
1697 /* load and adjust menus as required */
1698 if (!*hwndMenu || !WinIsWindow((HAB) 0, *hwndMenu)) {
1699 *hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1700 CopyPresParams(*hwndMenu, hwnd);
1701 if (hwndMenu == &DirMenu) {
1702 WinSetWindowUShort(DirMenu, QWS_ID, IDM_FILESMENU);
1703 SetConditionalCascade(DirMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1704 SetConditionalCascade(DirMenu, IDM_COPYMENU, IDM_COPY);
1705 SetConditionalCascade(DirMenu, IDM_MOVEMENU, IDM_MOVE);
1706 SetConditionalCascade(DirMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1707 SetConditionalCascade(DirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1708 SetConditionalCascade(DirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1709 SetConditionalCascade(DirMenu, IDM_DELETESUBMENU,
1710 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1711 SetConditionalCascade(DirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1712 SetConditionalCascade(DirMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1713 if (fWorkPlace) {
1714 WinSendMsg(DirMenu, MM_DELETEITEM,
1715 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1716 WinSendMsg(DirMenu, MM_DELETEITEM,
1717 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1718 }
1719 }
1720 else if (hwndMenu == &TreeMenu) {
1721 WinSetWindowUShort(TreeMenu, QWS_ID, IDM_FILESMENU);
1722 SetConditionalCascade(TreeMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1723 SetConditionalCascade(TreeMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1724 SetConditionalCascade(TreeMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1725 SetConditionalCascade(TreeMenu, IDM_EXPANDSUBMENU, IDM_EXPAND);
1726 SetConditionalCascade(TreeMenu, IDM_MISCSUBMENU, IDM_SIZES);
1727 SetConditionalCascade(TreeMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1728 if (fWorkPlace) {
1729 WinSendMsg(TreeMenu, MM_DELETEITEM,
1730 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1731 WinSendMsg(TreeMenu, MM_DELETEITEM,
1732 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1733 }
1734 if (!fLVM)
1735 WinSendMsg(TreeMenu, MM_DELETEITEM,
1736 MPFROM2SHORT(IDM_REFRESHREMOVABLES, TRUE), MPVOID);
1737 }
1738 else if (hwndMenu == &ArcMenu) {
1739 WinSetWindowUShort(ArcMenu, QWS_ID, IDM_FILESMENU);
1740 SetConditionalCascade(ArcMenu, IDM_EXTRACTSUBMENU, IDM_EXTRACT);
1741 SetConditionalCascade(ArcMenu, IDM_EDITSUBMENU, IDM_EDIT);
1742 SetConditionalCascade(ArcMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1743 if (fWorkPlace)
1744 WinSendMsg(ArcMenu, MM_DELETEITEM,
1745 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1746 }
1747 else if (hwndMenu == &FileMenu) {
1748 WinSetWindowUShort(FileMenu, QWS_ID, IDM_FILESMENU);
1749 SetConditionalCascade(FileMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1750 SetConditionalCascade(FileMenu, IDM_COPYMENU, IDM_COPY);
1751 SetConditionalCascade(FileMenu, IDM_MOVEMENU, IDM_MOVE);
1752 SetConditionalCascade(FileMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1753 SetConditionalCascade(FileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1754 SetConditionalCascade(FileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1755 SetConditionalCascade(FileMenu, IDM_COLLECTMENU, IDM_COLLECT);
1756 SetConditionalCascade(FileMenu, IDM_DELETESUBMENU,
1757 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1758 SetConditionalCascade(FileMenu, IDM_OPENSUBMENU, IDM_OPENDEFAULT);
1759 SetConditionalCascade(FileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1760 if (fWorkPlace) {
1761 WinSendMsg(FileMenu, MM_DELETEITEM,
1762 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1763 WinSendMsg(FileMenu, MM_DELETEITEM,
1764 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1765 }
1766 if (!fLVM)
1767 WinSendMsg(FileMenu, MM_DELETEITEM,
1768 MPFROM2SHORT(IDM_REFRESHREMOVABLES, TRUE), MPVOID);
1769 }
1770 else if (hwndMenu == &DirCnrMenu) {
1771 WinSetWindowUShort(DirCnrMenu, QWS_ID, IDM_VIEWSMENU);
1772 SetConditionalCascade(DirCnrMenu, IDM_MISCSUBMENU, IDM_SIZES);
1773 SetConditionalCascade(DirCnrMenu, IDM_OPENSUBMENU, IDM_OPENSETTINGSME);
1774 if (fWorkPlace)
1775 WinSendMsg(DirCnrMenu, MM_DELETEITEM,
1776 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1777 }
1778 else if (hwndMenu == &TreeCnrMenu) {
1779 WinSetWindowUShort(TreeCnrMenu, QWS_ID, IDM_VIEWSMENU);
1780 if (!fLVM)
1781 WinSendMsg(TreeCnrMenu, MM_DELETEITEM,
1782 MPFROM2SHORT(IDM_REFRESHREMOVABLES, TRUE), MPVOID);
1783 }
1784 else if (hwndMenu == &ArcCnrMenu) {
1785 WinSetWindowUShort(ArcCnrMenu, QWS_ID, IDM_VIEWSMENU);
1786 SetConditionalCascade(ArcCnrMenu, IDM_EXTRACTSUBMENU, IDM_ARCEXTRACT);
1787 if (fWorkPlace)
1788 WinSendMsg(ArcCnrMenu, MM_DELETEITEM,
1789 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1790 }
1791 else if (hwndMenu == &CollectorCnrMenu) {
1792 WinSetWindowUShort(CollectorCnrMenu, QWS_ID, IDM_VIEWSMENU);
1793 SetConditionalCascade(CollectorCnrMenu, IDM_COLLECTMENU,
1794 IDM_COLLECTFROMCLIP);
1795 }
1796 else if (hwndMenu == &CollectorFileMenu) {
1797 WinSetWindowUShort(CollectorFileMenu, QWS_ID, IDM_FILESMENU);
1798 SetConditionalCascade(CollectorFileMenu, IDM_COMMANDSMENU,
1799 IDM_DOITYOURSELF);
1800 SetConditionalCascade(CollectorFileMenu, IDM_COPYMENU, IDM_COPY);
1801 SetConditionalCascade(CollectorFileMenu, IDM_MOVEMENU, IDM_MOVE);
1802 SetConditionalCascade(CollectorFileMenu, IDM_SAVESUBMENU,
1803 IDM_SAVETOCLIP);
1804 SetConditionalCascade(CollectorFileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1805 SetConditionalCascade(CollectorFileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1806 SetConditionalCascade(CollectorFileMenu, IDM_DELETESUBMENU,
1807 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1808 SetConditionalCascade(CollectorFileMenu, IDM_OPENSUBMENU,
1809 IDM_OPENDEFAULT);
1810 SetConditionalCascade(CollectorFileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1811 if (fWorkPlace) {
1812 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1813 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1814 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1815 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1816 }
1817 }
1818 else if (hwndMenu == &CollectorDirMenu) {
1819 WinSetWindowUShort(CollectorDirMenu, QWS_ID, IDM_FILESMENU);
1820 SetConditionalCascade(CollectorDirMenu, IDM_COMMANDSMENU,
1821 IDM_DOITYOURSELF);
1822 SetConditionalCascade(CollectorDirMenu, IDM_COPYMENU, IDM_COPY);
1823 SetConditionalCascade(CollectorDirMenu, IDM_MOVEMENU, IDM_MOVE);
1824 SetConditionalCascade(CollectorDirMenu, IDM_SAVESUBMENU,
1825 IDM_SAVETOCLIP);
1826 SetConditionalCascade(CollectorDirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1827 SetConditionalCascade(CollectorDirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1828 SetConditionalCascade(CollectorDirMenu, IDM_DELETESUBMENU,
1829 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1830 SetConditionalCascade(CollectorDirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1831 SetConditionalCascade(CollectorDirMenu, IDM_OPENSUBMENU,
1832 IDM_OPENWINDOW);
1833 if (fWorkPlace) {
1834 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1835 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1836 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1837 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1838 }
1839 }
1840 else if (hwndMenu == &MainPopupMenu) {
1841 WinSetWindowUShort(MainPopupMenu, QWS_ID, IDM_MAINPOPUP);
1842 SetConditionalCascade(MainPopupMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
1843 SetConditionalCascade(MainPopupMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
1844 }
1845 }
1846 CopyPresParams(*hwndMenu, hwnd);
1847 return *hwndMenu;
1848}
1849
1850SHORT AddToListboxBottom(HWND hwnd, PCSZ str)
1851{
1852 SHORT ln;
1853
1854 ln = (SHORT) WinSendMsg(hwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
1855 MPFROMP(str));
1856 if (ln)
1857 WinSendMsg(hwnd, LM_SELECTITEM, MPFROM2SHORT(ln, 0), MPVOID);
1858 return ln;
1859}
1860
1861VOID SetSysMenu(HWND hwndSysMenu)
1862{
1863 CHAR s[128], *p;
1864
1865 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1866 MPFROM2SHORT(SC_RESTORE, 128), MPFROMP(s))) {
1867 p = strchr(s, '\t');
1868 if (p) {
1869 p++;
1870 strcpy(p, "Ctrl+Alt+F5");
1871 WinSetMenuItemText(hwndSysMenu, SC_RESTORE, s);
1872 }
1873 }
1874 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1875 MPFROM2SHORT(SC_CLOSE, 128), MPFROMP(s))) {
1876 p = strchr(s, '\t');
1877 if (p) {
1878 p++;
1879 strcpy(p, "Ctrl+Alt+F4");
1880 WinSetMenuItemText(hwndSysMenu, SC_CLOSE, s);
1881 }
1882 }
1883 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1884 MPFROM2SHORT(SC_MOVE, 128), MPFROMP(s))) {
1885 p = strchr(s, '\t');
1886 if (p) {
1887 p++;
1888 strcpy(p, "Ctrl+Alt+F7");
1889 WinSetMenuItemText(hwndSysMenu, SC_MOVE, s);
1890 }
1891 }
1892 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1893 MPFROM2SHORT(SC_SIZE, 128), MPFROMP(s))) {
1894 p = strchr(s, '\t');
1895 if (p) {
1896 p++;
1897 strcpy(p, "Ctrl+Alt+F8");
1898 WinSetMenuItemText(hwndSysMenu, SC_SIZE, s);
1899 }
1900 }
1901 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1902 MPFROM2SHORT(SC_MINIMIZE, 128), MPFROMP(s))) {
1903 p = strchr(s, '\t');
1904 if (p) {
1905 p++;
1906 strcpy(p, "Ctrl+Alt+F9");
1907 WinSetMenuItemText(hwndSysMenu, SC_MINIMIZE, s);
1908 }
1909 }
1910 if (WinSendMsg(hwndSysMenu,
1911 MM_QUERYITEMTEXT,
1912 MPFROM2SHORT(SC_MAXIMIZE, 128), MPFROMP(s))) {
1913 p = strchr(s, '\t');
1914 if (p) {
1915 p++;
1916 strcpy(p, "Ctrl+Alt+F10");
1917 WinSetMenuItemText(hwndSysMenu, SC_MAXIMIZE, s);
1918 }
1919 }
1920 if (WinSendMsg(hwndSysMenu,
1921 MM_QUERYITEMTEXT, MPFROM2SHORT(SC_HIDE, 128), MPFROMP(s))) {
1922 p = strchr(s, '\t');
1923 if (p) {
1924 p++;
1925 strcpy(p, "Ctrl+Alt+F11");
1926 WinSetMenuItemText(hwndSysMenu, SC_HIDE, s);
1927 }
1928 }
1929}
1930
1931VOID LoadLibPath(PSZ str, LONG len)
1932{
1933 ULONG ver[2];
1934 CHAR configsys[] = "C:\\CONFIG.SYS";
1935 static CHAR var[8192], beg[16384], end[16384];
1936 BOOL warp;
1937 FILE *fp;
1938 PFN DQELIBPATH = NULL;
1939 HMODULE hmod;
1940
1941 if (str && len) {
1942 *str = 0;
1943 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
1944 QSV_BOOT_DRIVE, (PVOID) ver, (ULONG) sizeof(ULONG)))
1945 ver[0] = 3L;
1946 *configsys = (CHAR) ver[0] + '@';
1947 if (!DosQuerySysInfo(QSV_VERSION_MAJOR,
1948 QSV_VERSION_MINOR,
1949 (PVOID) ver, (ULONG) sizeof(ver)) && ver[1] >= 30)
1950 warp = TRUE;
1951 *var = *beg = *end = 0;
1952 if (warp) {
1953 if (!DosLoadModule(var, sizeof(var), "DOSCALL1.DLL", &hmod)) {
1954 if (!DosQueryProcAddr(hmod,
1955 ORD_DOS32QUERYEXTLIBPATH,
1956 NULL, (PFN *) & DQELIBPATH)) {
1957 DQELIBPATH(beg, BEGIN_LIBPATH);
1958 DQELIBPATH(end, END_LIBPATH);
1959 }
1960 DosFreeModule(hmod);
1961 }
1962 *var = 0;
1963 }
1964 fp = xfopen(configsys, "r", pszSrcFile, __LINE__);
1965 if (fp) {
1966 while (!feof(fp)) {
1967 if (!xfgets_bstripcr(var, sizeof(var), fp, pszSrcFile, __LINE__))
1968 break;
1969 if (!strnicmp(var, "LIBPATH=", 8)) {
1970 memmove(var, var + 8, strlen(var + 8) + 1);
1971 lstrip(var);
1972 break;
1973 }
1974 }
1975 fclose(fp);
1976 }
1977 strncpy(str, beg, len);
1978 strncat(str, var, len - strlen(str));
1979 strncat(str, end, len - strlen(str));
1980 str[len - 1] = 0;
1981 }
1982}
1983
1984void SetViewMenu(HWND hwndMenu, ULONG flWindowAttr)
1985{
1986 WinCheckMenuItem(hwndMenu, IDM_MINIICONS, ((flWindowAttr & CV_MINI)));
1987 WinCheckMenuItem(hwndMenu, IDM_TEXT, ((flWindowAttr & CV_TEXT)));
1988 WinCheckMenuItem(hwndMenu, IDM_ICON, ((flWindowAttr & CV_ICON) &&
1989 !(flWindowAttr & CV_TREE)));
1990 WinCheckMenuItem(hwndMenu, IDM_TREEVIEW, ((flWindowAttr & CV_TREE)));
1991 WinCheckMenuItem(hwndMenu, IDM_DETAILS, ((flWindowAttr & CV_DETAIL)));
1992 WinCheckMenuItem(hwndMenu, IDM_NAME, ((flWindowAttr & CV_NAME)));
1993}
1994
1995void SaySort(HWND hwnd, INT sortflags, BOOL archive)
1996{
1997 char *s = NULL;
1998
1999 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
2000 if (s) {
2001 sprintf(s, "S:%s%s",
2002 sortflags & SORT_REVERSE ? "^" : NullStr,
2003 (sortflags & SORT_FIRSTEXTENSION) ?
2004 GetPString(IDS_FIRSTX) : (sortflags & SORT_LASTEXTENSION) ?
2005 GetPString(IDS_LASTX) : (sortflags & SORT_SIZE) ?
2006 "Size" : (sortflags & SORT_EASIZE) ?
2007 (archive == 0) ?
2008 GetPString(IDS_EASIZE) : GetPString(IDS_CSIZE) :
2009 (sortflags & SORT_LWDATE) ?
2010 (archive == 0) ?
2011 GetPString(IDS_LWDATE) : GetPString(IDS_DATE) :
2012 (sortflags & SORT_LADATE) ?
2013 GetPString(IDS_LADATE) : (sortflags & SORT_CRDATE) ?
2014 GetPString(IDS_CRDATE) :
2015 (sortflags & SORT_PATHNAME) ?
2016 GetPString(IDS_PATH) : (sortflags & SORT_NOSORT) ?
2017 GetPString(IDS_NONE) : (sortflags & SORT_SUBJECT) ?
2018 GetPString(IDS_SUBJ) : GetPString(IDS_NAME));
2019 WinSetWindowText(hwnd, s);
2020 free(s);
2021 }
2022}
2023
2024void SayView(HWND hwnd, ULONG flWindowAttr)
2025{
2026 char *s = NULL;
2027
2028 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
2029 if (s) {
2030 sprintf(s, "V:%s%s",
2031 (flWindowAttr & CV_TREE) ? GetPString(IDS_TREE) :
2032 (flWindowAttr & CV_NAME) ? GetPString(IDS_NAME) :
2033 (flWindowAttr & CV_DETAIL) ? GetPString(IDS_DETAIL) :
2034 (flWindowAttr & CV_TEXT) ? GetPString(IDS_TEXT) :
2035 GetPString(IDS_ICON),
2036 ((flWindowAttr & CV_MINI) &&
2037 !(flWindowAttr & CV_TEXT)) ? GetPString(IDS_MINI) : NullStr);
2038 WinSetWindowText(hwnd, s);
2039 free(s);
2040 }
2041}
2042
2043void SayFilter(HWND hwnd, MASK * mask, BOOL archive)
2044{
2045 char *s = NULL;
2046
2047 s = xmalloc(CCHMAXPATH * 2, pszSrcFile, __LINE__);
2048 if (s) {
2049 sprintf(s, "F:%s%s",
2050 mask->szMask,
2051 (!archive && (mask->attrFile != ALLATTRS ||
2052 mask->antiattr != 0)) ? " " : NullStr,
2053 (!archive && (mask->attrFile != ALLATTRS ||
2054 mask->antiattr !=
2055 0)) ? GetPString(IDS_ATTRTEXT) : NullStr);
2056 if (!s[2])
2057 sprintf(s, "F:%s", GetPString(IDS_ALLTEXT));
2058 WinSetWindowText(hwnd, s);
2059 free(s);
2060 }
2061}
2062
2063char *GetCmdSpec(BOOL dos)
2064{
2065 char *cmspec;
2066
2067 if (!dos) {
2068 cmspec = getenv("OS2_SHELL");
2069 if (!cmspec)
2070 cmspec = getenv("COMSPEC");
2071 if (!cmspec)
2072 cmspec = "CMD.EXE";
2073 }
2074 else {
2075 cmspec = getenv("DOS_SHELL");
2076 if (!cmspec)
2077 cmspec = "COMMAND.COM";
2078 }
2079 return cmspec;
2080}
2081
2082void Broadcast(HAB hab, HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2083{
2084 if (hwndMain)
2085 WinBroadcastMsg(hwndMain, msg, mp1, mp2, BMSG_SEND | BMSG_FRAMEONLY);
2086 if (hwnd &&
2087 hwnd != HWND_DESKTOP &&
2088 hwnd != hwndMain &&
2089 hwnd != WinQueryDesktopWindow(hab, NULLHANDLE) &&
2090 WinIsWindow(hab, hwnd) && (!hwndMain || !WinIsChild(hwnd, hwndMain)))
2091 WinSendMsg(hwnd, msg, mp1, mp2);
2092}
2093
2094void SetupWinList(HWND hwndMenu, HWND hwndTop, HWND hwndFrame)
2095{
2096 /*
2097 * add switchlist entries to end of pulldown menu
2098 */
2099
2100 SHORT sItemCount, x = 0, y = 0;
2101 MENUITEM mi;
2102
2103 sItemCount = (SHORT) WinSendMsg(hwndMenu,
2104 MM_QUERYITEMCOUNT, MPVOID, MPVOID);
2105
2106 /* clean out old additions */
2107 while ((SHORT) WinSendMsg(hwndMenu,
2108 MM_DELETEITEM,
2109 MPFROM2SHORT(IDM_SWITCHSTART + x++,
2110 TRUE), MPVOID) < sItemCount)
2111 sItemCount--;
2112 x = 0;
2113 while ((SHORT) WinSendMsg(hwndMenu,
2114 MM_DELETEITEM,
2115 MPFROM2SHORT(IDM_WINDOWSTART + x++,
2116 TRUE), MPVOID) < sItemCount)
2117 sItemCount--;
2118
2119 x = 0;
2120 if (hwndTop) {
2121
2122 char wtext[CCHMAXPATH + 8];
2123 HENUM henum;
2124 HWND hwndChild;
2125
2126 /* add children of the main FM/2 client */
2127 henum = WinBeginEnumWindows(hwndTop);
2128 memset(&mi, 0, sizeof(mi));
2129 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2130 if (WinQueryWindowUShort(hwndChild, QWS_ID) && hwndChild != hwndFrame) {
2131 *wtext = 0;
2132 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, wtext);
2133 if (*wtext) {
2134 wtext[CCHMAXPATH + 7] = 0;
2135 mi.afStyle = MIS_TEXT;
2136 if (!((x + sItemCount) % 28))
2137 mi.afStyle |= MIS_BREAK;
2138 mi.id = IDM_WINDOWSTART + x;
2139 mi.iPosition = MIT_END;
2140 if ((SHORT) WinSendMsg(hwndMenu,
2141 MM_INSERTITEM,
2142 MPFROMP(&mi), MPFROMP(wtext)) >= 0)
2143 x++;
2144 }
2145 }
2146 }
2147 WinEndEnumWindows(henum);
2148 }
2149
2150 /* add external FM/2 windows */
2151 {
2152 PSWBLOCK pswb;
2153 ULONG ulSize, ulcEntries;
2154 HWND hwndTopFrame;
2155 register INT i;
2156
2157 hwndTopFrame = hwndTop ? WinQueryWindow(hwndTop, QW_PARENT) : (HWND)0;
2158 /* Get the switch list information */
2159 x = 0;
2160 ulcEntries = WinQuerySwitchList(0, NULL, 0);
2161 ulSize = sizeof(SWBLOCK) + sizeof(HSWITCH) + (ulcEntries + 4L) *
2162 (LONG) sizeof(SWENTRY);
2163 /* Allocate memory for list */
2164 pswb = xmalloc(ulSize, pszSrcFile, __LINE__);
2165 if (pswb) {
2166 /* Put the info in the list */
2167 ulcEntries = WinQuerySwitchList(0, pswb, ulSize - sizeof(SWENTRY));
2168 /* do the dirty deed */
2169 memset(&mi, 0, sizeof(mi));
2170 for (i = 0; i < pswb->cswentry; i++) {
2171 if (pswb->aswentry[i].swctl.uchVisibility == SWL_VISIBLE &&
2172 pswb->aswentry[i].swctl.fbJump == SWL_JUMPABLE &&
2173 (pswb->aswentry[i].swctl.idProcess != mypid ||
2174 !hwndFrame ||
2175 pswb->aswentry[i].swctl.hwnd != hwndFrame) &&
2176 (pswb->aswentry[i].swctl.idProcess != mypid ||
2177 !hwndTopFrame ||
2178 pswb->aswentry[i].swctl.hwnd != hwndTopFrame ||
2179 !WinIsChild(hwndFrame, hwndTop))) {
2180 if (!strnicmp(pswb->aswentry[i].swctl.szSwtitle, "AV/2", 4)
2181 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "File Manager/2")
2182 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "Collector")
2183 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VTree", 5)
2184 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VDir", 4)
2185 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, FM2Str, 4)) {
2186 mi.afStyle = MIS_TEXT;
2187 if (x && !(x % 28))
2188 mi.afStyle |= MIS_BREAK;
2189 mi.id = IDM_SWITCHSTART + y;
2190 mi.iPosition = MIT_END;
2191 switches[y] = pswb->aswentry[i].hswitch;
2192 if ((SHORT) WinSendMsg(hwndMenu,
2193 MM_INSERTITEM,
2194 MPFROMP(&mi),
2195 MPFROMP(pswb->aswentry[i].
2196 swctl.szSwtitle)) >= 0) {
2197 y++;
2198 x++;
2199 }
2200 }
2201 }
2202 }
2203 numswitches = y;
2204 free(pswb);
2205 DosPostEventSem(CompactSem);
2206 }
2207 }
2208}
2209
2210BOOL SwitchCommand(HWND hwndMenu, USHORT cmd)
2211{
2212 BOOL ret = FALSE;
2213
2214 if (hwndMain && hwndMenu && cmd >= IDM_WINDOWSTART && cmd < IDM_SWITCHSTART) {
2215 /*
2216 * select a child window (of client)
2217 */
2218
2219 MENUITEM mi;
2220 HWND hwndSubMenu = (HWND) 0, hwndChild;
2221 CHAR s[CCHMAXPATH + 8];
2222
2223 if (WinQueryWindowUShort(hwndMenu, QWS_ID) != IDM_WINDOWSMENU) {
2224 memset(&mi, 0, sizeof(mi));
2225 mi.iPosition = MIT_END;
2226 mi.afStyle = MIS_TEXT;
2227 if (WinSendMsg(hwndMenu,
2228 MM_QUERYITEM,
2229 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
2230 hwndSubMenu = mi.hwndSubMenu;
2231 }
2232 else
2233 hwndSubMenu = hwndMenu;
2234 if (hwndSubMenu) {
2235 *s = 0;
2236 if (WinSendMsg(hwndSubMenu,
2237 MM_QUERYITEMTEXT,
2238 MPFROM2SHORT(cmd, CCHMAXPATH + 8), MPFROMP(s)) && *s) {
2239
2240 HENUM henum;
2241 CHAR checkText[CCHMAXPATH + 8];
2242 SWP swp;
2243
2244 s[CCHMAXPATH + 7] = 0;
2245 henum = WinBeginEnumWindows(hwndMain);
2246 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2247 if (WinQueryWindowUShort(hwndChild, QWS_ID)) {
2248 *checkText = 0;
2249 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, checkText);
2250 checkText[CCHMAXPATH + 7] = 0;
2251 if (!stricmp(checkText, s)) {
2252 if (WinQueryWindowPos(hwndChild, &swp)) {
2253 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE))
2254 WinSetWindowPos(hwndChild,
2255 HWND_TOP,
2256 0, 0, 0, 0, SWP_RESTORE | SWP_ZORDER);
2257 }
2258 WinSetActiveWindow(HWND_DESKTOP, hwndChild);
2259 ret = TRUE;
2260 break;
2261 }
2262 }
2263 }
2264 WinEndEnumWindows(henum);
2265 }
2266 }
2267 }
2268 else if (cmd >= IDM_SWITCHSTART && cmd < IDM_SWITCHSTART + 499) {
2269 if (cmd - IDM_SWITCHSTART < numswitches) {
2270 WinSwitchToProgram(switches[cmd - IDM_SWITCHSTART]);
2271 ret = TRUE;
2272 }
2273 }
2274
2275 return ret;
2276}
2277
2278/** CheckDriveSpaceAvail
2279 * Take space needed and checks that drive has at least 1000 bits in excess of the required space.
2280 * Returns 0 if sufficient space is available; 1 if the drive is full & 2 on abort of operation
2281 * when the drive would have less than ullFreeSpaceWhenComplete remaining or has insufficient space.
2282 */
2283
2284INT CheckDriveSpaceAvail(PCSZ pTargetPath, ULONGLONG ullSpaceNeeded,
2285 ULONGLONG ullFreeSpaceWhenComplete)
2286{
2287 FSALLOCATE fsa;
2288 ULONGLONG ullFreeQty;
2289 APIRET ret;
2290
2291 DosQueryFSInfo(toupper(*pTargetPath) - 'A' + 1, FSIL_ALLOC, &fsa, sizeof(FSALLOCATE));
2292 ullFreeQty = (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
2293 if (ullFreeQty > ullSpaceNeeded + ullFreeSpaceWhenComplete)
2294 return 0;
2295 else if (ullFreeQty < ullSpaceNeeded + 1024) {
2296 CHAR szKB[20];
2297
2298 CommaFmtULL(szKB, sizeof(szKB),
2299 ullFreeQty - ullSpaceNeeded, ' ');
2300 if (ullFreeSpaceWhenComplete == 0) {
2301 saymsg(MB_OK,
2302 HWND_DESKTOP,
2303 NullStr,
2304 GetPString(IDS_DRIVESPACELIMITEDTMPSAVE),
2305 pTargetPath);
2306 return 0;
2307 }
2308 else {
2309 if (ullFreeQty > ullSpaceNeeded) {
2310 ret = saymsg(MB_YESNO,
2311 HWND_DESKTOP,
2312 NullStr,
2313 GetPString(IDS_DRIVESPACELIMITED),
2314 pTargetPath,
2315 szKB);
2316 if (ret == MBID_YES)
2317 return 0;
2318 else
2319 return 2;
2320 }
2321 else {
2322 saymsg(MB_OK,
2323 HWND_DESKTOP,
2324 NullStr,
2325 GetPString(IDS_DRIVESPACEEXCEEDED),
2326 pTargetPath);
2327 return 2;
2328 }
2329 }
2330 }
2331 else
2332 return 1;
2333}
2334
2335#pragma alloc_text(MAINWND5,SetSysMenu)
2336#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
2337#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
2338#pragma alloc_text(MISC1,CheckDriveSpaceAvail)
2339
2340#ifdef FORTIFY
2341#pragma alloc_text(MISC1,GetTidForWindow)
2342#endif // FORTIFY
2343
2344#pragma alloc_text(CNR_MISC1,AdjustCnrColVis,AdjustCnrColsForFSType)
2345#pragma alloc_text(CNR_MISC1,AdjustCnrColsForPref,SetCnrCols)
2346#pragma alloc_text(CNR_MISC2,CnrDirectEdit,OpenEdit)
2347#pragma alloc_text(MISC2,SetMenuCheck,disable_menuitem,SetSortChecks)
2348#pragma alloc_text(MISC2,SetDetailsSwitches,SetViewMenu)
2349#pragma alloc_text(MISC3,SetupCommandMenu,AdjustDetailsSwitches)
2350#pragma alloc_text(MISC3,ViewHelp,GetCmdSpec)
2351#pragma alloc_text(MISC3,ExecFile,SetConditionalCascade,LoadDetailsSwitches)
2352#pragma alloc_text(MISC4,PortholeInit,CheckMenu,Broadcast,SetupWinList,SwitchCommand)
2353#pragma alloc_text(MISC6,DrawTargetEmphasis,EmphasizeButton)
2354#pragma alloc_text(MISC_LIBPATH,LoadLibPath)
2355#pragma alloc_text(MISC_SAY,SayView,SaySort,SayFilter)
2356
Note: See TracBrowser for help on using the repository browser.