source: trunk/dll/misc.c@ 1225

Last change on this file since 1225 was 1225, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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