source: trunk/dll/misc.c@ 1358

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

Comments for CS 1354/55

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