source: trunk/dll/misc.c@ 1253

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

Fix instance of a submenu having 2 default items

  • 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 1253 2008-10-19 23:11:48Z 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
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_VIEWSUBMENU, IDM_INFO);
1693 SetConditionalCascade(DirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1694 SetConditionalCascade(DirMenu, IDM_DELETESUBMENU,
1695 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1696 SetConditionalCascade(DirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1697 SetConditionalCascade(DirMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1698 if (fWorkPlace) {
1699 WinSendMsg(DirMenu, MM_DELETEITEM,
1700 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1701 WinSendMsg(DirMenu, MM_DELETEITEM,
1702 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1703 }
1704 }
1705 else if (hwndMenu == &TreeMenu) {
1706 WinSetWindowUShort(TreeMenu, QWS_ID, IDM_FILESMENU);
1707 SetConditionalCascade(TreeMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1708 SetConditionalCascade(TreeMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1709 SetConditionalCascade(TreeMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1710 SetConditionalCascade(TreeMenu, IDM_EXPANDSUBMENU, IDM_EXPAND);
1711 SetConditionalCascade(TreeMenu, IDM_MISCSUBMENU, IDM_SIZES);
1712 SetConditionalCascade(TreeMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1713 if (fWorkPlace) {
1714 WinSendMsg(TreeMenu, MM_DELETEITEM,
1715 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1716 WinSendMsg(TreeMenu, MM_DELETEITEM,
1717 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1718 }
1719 }
1720 else if (hwndMenu == &ArcMenu) {
1721 WinSetWindowUShort(ArcMenu, QWS_ID, IDM_FILESMENU);
1722 SetConditionalCascade(ArcMenu, IDM_EXTRACTSUBMENU, IDM_EXTRACT);
1723 SetConditionalCascade(ArcMenu, IDM_EDITSUBMENU, IDM_EDIT);
1724 SetConditionalCascade(ArcMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1725 if (fWorkPlace)
1726 WinSendMsg(ArcMenu, MM_DELETEITEM,
1727 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1728 }
1729 else if (hwndMenu == &FileMenu) {
1730 WinSetWindowUShort(FileMenu, QWS_ID, IDM_FILESMENU);
1731 SetConditionalCascade(FileMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1732 SetConditionalCascade(FileMenu, IDM_COPYMENU, IDM_COPY);
1733 SetConditionalCascade(FileMenu, IDM_MOVEMENU, IDM_MOVE);
1734 SetConditionalCascade(FileMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1735 SetConditionalCascade(FileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1736 SetConditionalCascade(FileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1737 SetConditionalCascade(FileMenu, IDM_COLLECTMENU, IDM_COLLECT);
1738 SetConditionalCascade(FileMenu, IDM_DELETESUBMENU,
1739 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1740 SetConditionalCascade(FileMenu, IDM_OPENSUBMENU, IDM_OPENDEFAULT);
1741 SetConditionalCascade(FileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1742 if (fWorkPlace) {
1743 WinSendMsg(FileMenu, MM_DELETEITEM,
1744 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1745 WinSendMsg(FileMenu, MM_DELETEITEM,
1746 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1747 }
1748 }
1749 else if (hwndMenu == &DirCnrMenu) {
1750 WinSetWindowUShort(DirCnrMenu, QWS_ID, IDM_VIEWSMENU);
1751 SetConditionalCascade(DirCnrMenu, IDM_MISCSUBMENU, IDM_SIZES);
1752 SetConditionalCascade(DirCnrMenu, IDM_OPENSUBMENU, IDM_OPENSETTINGSME);
1753 if (fWorkPlace)
1754 WinSendMsg(DirCnrMenu, MM_DELETEITEM,
1755 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1756 }
1757 else if (hwndMenu == &TreeCnrMenu) {
1758 WinSetWindowUShort(TreeCnrMenu, QWS_ID, IDM_VIEWSMENU);
1759 SetConditionalCascade(TreeCnrMenu, IDM_PARTITIONSMENU, IDM_PARTITION);
1760 }
1761 else if (hwndMenu == &ArcCnrMenu) {
1762 WinSetWindowUShort(ArcCnrMenu, QWS_ID, IDM_VIEWSMENU);
1763 SetConditionalCascade(ArcCnrMenu, IDM_EXTRACTSUBMENU, IDM_ARCEXTRACT);
1764 if (fWorkPlace)
1765 WinSendMsg(ArcCnrMenu, MM_DELETEITEM,
1766 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1767 }
1768 else if (hwndMenu == &CollectorCnrMenu) {
1769 WinSetWindowUShort(CollectorCnrMenu, QWS_ID, IDM_VIEWSMENU);
1770 SetConditionalCascade(CollectorCnrMenu, IDM_COLLECTMENU,
1771 IDM_COLLECTFROMCLIP);
1772 }
1773 else if (hwndMenu == &CollectorFileMenu) {
1774 WinSetWindowUShort(CollectorFileMenu, QWS_ID, IDM_FILESMENU);
1775 SetConditionalCascade(CollectorFileMenu, IDM_COMMANDSMENU,
1776 IDM_DOITYOURSELF);
1777 SetConditionalCascade(CollectorFileMenu, IDM_COPYMENU, IDM_COPY);
1778 SetConditionalCascade(CollectorFileMenu, IDM_MOVEMENU, IDM_MOVE);
1779 SetConditionalCascade(CollectorFileMenu, IDM_SAVESUBMENU,
1780 IDM_SAVETOCLIP);
1781 SetConditionalCascade(CollectorFileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1782 SetConditionalCascade(CollectorFileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1783 SetConditionalCascade(CollectorFileMenu, IDM_DELETESUBMENU,
1784 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1785 SetConditionalCascade(CollectorFileMenu, IDM_OPENSUBMENU,
1786 IDM_OPENDEFAULT);
1787 SetConditionalCascade(CollectorFileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1788 if (fWorkPlace) {
1789 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1790 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1791 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1792 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1793 }
1794 }
1795 else if (hwndMenu == &CollectorDirMenu) {
1796 WinSetWindowUShort(CollectorDirMenu, QWS_ID, IDM_FILESMENU);
1797 SetConditionalCascade(CollectorDirMenu, IDM_COMMANDSMENU,
1798 IDM_DOITYOURSELF);
1799 SetConditionalCascade(CollectorDirMenu, IDM_COPYMENU, IDM_COPY);
1800 SetConditionalCascade(CollectorDirMenu, IDM_MOVEMENU, IDM_MOVE);
1801 SetConditionalCascade(CollectorDirMenu, IDM_SAVESUBMENU,
1802 IDM_SAVETOCLIP);
1803 SetConditionalCascade(CollectorDirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1804 SetConditionalCascade(CollectorDirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1805 SetConditionalCascade(CollectorDirMenu, IDM_DELETESUBMENU,
1806 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1807 SetConditionalCascade(CollectorDirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1808 SetConditionalCascade(CollectorDirMenu, IDM_OPENSUBMENU,
1809 IDM_OPENWINDOW);
1810 if (fWorkPlace) {
1811 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1812 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1813 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1814 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1815 }
1816 }
1817 else if (hwndMenu == &MainPopupMenu) {
1818 WinSetWindowUShort(MainPopupMenu, QWS_ID, IDM_MAINPOPUP);
1819 SetConditionalCascade(MainPopupMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
1820 SetConditionalCascade(MainPopupMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
1821 }
1822 }
1823 CopyPresParams(*hwndMenu, hwnd);
1824 return *hwndMenu;
1825}
1826
1827SHORT AddToListboxBottom(HWND hwnd, CHAR * str)
1828{
1829 SHORT ln;
1830
1831 ln = (SHORT) WinSendMsg(hwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
1832 MPFROMP(str));
1833 if (ln)
1834 WinSendMsg(hwnd, LM_SELECTITEM, MPFROM2SHORT(ln, 0), MPVOID);
1835 return ln;
1836}
1837
1838VOID SetSysMenu(HWND hwndSysMenu)
1839{
1840 CHAR s[128], *p;
1841
1842 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1843 MPFROM2SHORT(SC_RESTORE, 128), MPFROMP(s))) {
1844 p = strchr(s, '\t');
1845 if (p) {
1846 p++;
1847 strcpy(p, "Ctrl+Alt+F5");
1848 WinSetMenuItemText(hwndSysMenu, SC_RESTORE, s);
1849 }
1850 }
1851 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1852 MPFROM2SHORT(SC_CLOSE, 128), MPFROMP(s))) {
1853 p = strchr(s, '\t');
1854 if (p) {
1855 p++;
1856 strcpy(p, "Ctrl+Alt+F4");
1857 WinSetMenuItemText(hwndSysMenu, SC_CLOSE, s);
1858 }
1859 }
1860 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1861 MPFROM2SHORT(SC_MOVE, 128), MPFROMP(s))) {
1862 p = strchr(s, '\t');
1863 if (p) {
1864 p++;
1865 strcpy(p, "Ctrl+Alt+F7");
1866 WinSetMenuItemText(hwndSysMenu, SC_MOVE, s);
1867 }
1868 }
1869 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1870 MPFROM2SHORT(SC_SIZE, 128), MPFROMP(s))) {
1871 p = strchr(s, '\t');
1872 if (p) {
1873 p++;
1874 strcpy(p, "Ctrl+Alt+F8");
1875 WinSetMenuItemText(hwndSysMenu, SC_SIZE, s);
1876 }
1877 }
1878 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1879 MPFROM2SHORT(SC_MINIMIZE, 128), MPFROMP(s))) {
1880 p = strchr(s, '\t');
1881 if (p) {
1882 p++;
1883 strcpy(p, "Ctrl+Alt+F9");
1884 WinSetMenuItemText(hwndSysMenu, SC_MINIMIZE, s);
1885 }
1886 }
1887 if (WinSendMsg(hwndSysMenu,
1888 MM_QUERYITEMTEXT,
1889 MPFROM2SHORT(SC_MAXIMIZE, 128), MPFROMP(s))) {
1890 p = strchr(s, '\t');
1891 if (p) {
1892 p++;
1893 strcpy(p, "Ctrl+Alt+F10");
1894 WinSetMenuItemText(hwndSysMenu, SC_MAXIMIZE, s);
1895 }
1896 }
1897 if (WinSendMsg(hwndSysMenu,
1898 MM_QUERYITEMTEXT, MPFROM2SHORT(SC_HIDE, 128), MPFROMP(s))) {
1899 p = strchr(s, '\t');
1900 if (p) {
1901 p++;
1902 strcpy(p, "Ctrl+Alt+F11");
1903 WinSetMenuItemText(hwndSysMenu, SC_HIDE, s);
1904 }
1905 }
1906}
1907
1908VOID LoadLibPath(CHAR * str, LONG len)
1909{
1910 ULONG ver[2];
1911 CHAR configsys[] = "C:\\CONFIG.SYS";
1912 static CHAR var[8192], beg[16384], end[16384];
1913 BOOL warp;
1914 FILE *fp;
1915 PFN DQELIBPATH = NULL;
1916 HMODULE hmod;
1917
1918 if (str && len) {
1919 *str = 0;
1920 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
1921 QSV_BOOT_DRIVE, (PVOID) ver, (ULONG) sizeof(ULONG)))
1922 ver[0] = 3L;
1923 *configsys = (CHAR) ver[0] + '@';
1924 if (!DosQuerySysInfo(QSV_VERSION_MAJOR,
1925 QSV_VERSION_MINOR,
1926 (PVOID) ver, (ULONG) sizeof(ver)) && ver[1] >= 30)
1927 warp = TRUE;
1928 *var = *beg = *end = 0;
1929 if (warp) {
1930 if (!DosLoadModule(var, sizeof(var), "DOSCALL1.DLL", &hmod)) {
1931 if (!DosQueryProcAddr(hmod,
1932 ORD_DOS32QUERYEXTLIBPATH,
1933 NULL, (PFN *) & DQELIBPATH)) {
1934 DQELIBPATH(beg, BEGIN_LIBPATH);
1935 DQELIBPATH(end, END_LIBPATH);
1936 }
1937 DosFreeModule(hmod);
1938 }
1939 *var = 0;
1940 }
1941 fp = xfopen(configsys, "r", pszSrcFile, __LINE__);
1942 if (fp) {
1943 while (!feof(fp)) {
1944 if (!xfgets_bstripcr(var, sizeof(var), fp, pszSrcFile, __LINE__))
1945 break;
1946 if (!strnicmp(var, "LIBPATH=", 8)) {
1947 memmove(var, var + 8, strlen(var + 8) + 1);
1948 lstrip(var);
1949 break;
1950 }
1951 }
1952 fclose(fp);
1953 }
1954 strncpy(str, beg, len);
1955 strncat(str, var, len - strlen(str));
1956 strncat(str, end, len - strlen(str));
1957 str[len - 1] = 0;
1958 }
1959}
1960
1961void SetViewMenu(HWND hwndMenu, ULONG flWindowAttr)
1962{
1963 WinCheckMenuItem(hwndMenu, IDM_MINIICONS, ((flWindowAttr & CV_MINI)));
1964 WinCheckMenuItem(hwndMenu, IDM_TEXT, ((flWindowAttr & CV_TEXT)));
1965 WinCheckMenuItem(hwndMenu, IDM_ICON, ((flWindowAttr & CV_ICON) &&
1966 !(flWindowAttr & CV_TREE)));
1967 WinCheckMenuItem(hwndMenu, IDM_TREEVIEW, ((flWindowAttr & CV_TREE)));
1968 WinCheckMenuItem(hwndMenu, IDM_DETAILS, ((flWindowAttr & CV_DETAIL)));
1969 WinCheckMenuItem(hwndMenu, IDM_NAME, ((flWindowAttr & CV_NAME)));
1970}
1971
1972void SaySort(HWND hwnd, INT sortflags, BOOL archive)
1973{
1974 char *s = NULL;
1975
1976 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
1977 if (s) {
1978 sprintf(s, "S:%s%s",
1979 sortflags & SORT_REVERSE ? "^" : NullStr,
1980 (sortflags & SORT_FIRSTEXTENSION) ?
1981 GetPString(IDS_FIRSTX) : (sortflags & SORT_LASTEXTENSION) ?
1982 GetPString(IDS_LASTX) : (sortflags & SORT_SIZE) ?
1983 "Size" : (sortflags & SORT_EASIZE) ?
1984 (archive == 0) ?
1985 GetPString(IDS_EASIZE) : GetPString(IDS_CSIZE) :
1986 (sortflags & SORT_LWDATE) ?
1987 (archive == 0) ?
1988 GetPString(IDS_LWDATE) : GetPString(IDS_DATE) :
1989 (sortflags & SORT_LADATE) ?
1990 GetPString(IDS_LADATE) : (sortflags & SORT_CRDATE) ?
1991 GetPString(IDS_CRDATE) :
1992 (sortflags & SORT_PATHNAME) ?
1993 GetPString(IDS_PATH) : (sortflags & SORT_NOSORT) ?
1994 GetPString(IDS_NONE) : (sortflags & SORT_SUBJECT) ?
1995 GetPString(IDS_SUBJ) : GetPString(IDS_NAME));
1996 WinSetWindowText(hwnd, s);
1997 free(s);
1998 }
1999}
2000
2001void SayView(HWND hwnd, ULONG flWindowAttr)
2002{
2003 char *s = NULL;
2004
2005 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
2006 if (s) {
2007 sprintf(s, "V:%s%s",
2008 (flWindowAttr & CV_TREE) ? GetPString(IDS_TREE) :
2009 (flWindowAttr & CV_NAME) ? GetPString(IDS_NAME) :
2010 (flWindowAttr & CV_DETAIL) ? GetPString(IDS_DETAIL) :
2011 (flWindowAttr & CV_TEXT) ? GetPString(IDS_TEXT) :
2012 GetPString(IDS_ICON),
2013 ((flWindowAttr & CV_MINI) &&
2014 !(flWindowAttr & CV_TEXT)) ? GetPString(IDS_MINI) : NullStr);
2015 WinSetWindowText(hwnd, s);
2016 free(s);
2017 }
2018}
2019
2020void SayFilter(HWND hwnd, MASK * mask, BOOL archive)
2021{
2022 char *s = NULL;
2023
2024 s = xmalloc(CCHMAXPATH * 2, pszSrcFile, __LINE__);
2025 if (s) {
2026 sprintf(s, "F:%s%s",
2027 mask->szMask,
2028 (!archive && (mask->attrFile != ALLATTRS ||
2029 mask->antiattr != 0)) ? " " : NullStr,
2030 (!archive && (mask->attrFile != ALLATTRS ||
2031 mask->antiattr !=
2032 0)) ? GetPString(IDS_ATTRTEXT) : NullStr);
2033 if (!s[2])
2034 sprintf(s, "F:%s", GetPString(IDS_ALLTEXT));
2035 WinSetWindowText(hwnd, s);
2036 free(s);
2037 }
2038}
2039
2040char *GetCmdSpec(BOOL dos)
2041{
2042 char *cmspec;
2043
2044 if (!dos) {
2045 cmspec = getenv("OS2_SHELL");
2046 if (!cmspec)
2047 cmspec = getenv("COMSPEC");
2048 if (!cmspec)
2049 cmspec = "CMD.EXE";
2050 }
2051 else {
2052 cmspec = getenv("DOS_SHELL");
2053 if (!cmspec)
2054 cmspec = "COMMAND.COM";
2055 }
2056 return cmspec;
2057}
2058
2059void Broadcast(HAB hab, HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2060{
2061 if (hwndMain)
2062 WinBroadcastMsg(hwndMain, msg, mp1, mp2, BMSG_SEND | BMSG_FRAMEONLY);
2063 if (hwnd &&
2064 hwnd != HWND_DESKTOP &&
2065 hwnd != hwndMain &&
2066 hwnd != WinQueryDesktopWindow(hab, NULLHANDLE) &&
2067 WinIsWindow(hab, hwnd) && (!hwndMain || !WinIsChild(hwnd, hwndMain)))
2068 WinSendMsg(hwnd, msg, mp1, mp2);
2069}
2070
2071void SetupWinList(HWND hwndMenu, HWND hwndTop, HWND hwndFrame)
2072{
2073 /*
2074 * add switchlist entries to end of pulldown menu
2075 */
2076
2077 SHORT sItemCount, x = 0, y = 0;
2078 MENUITEM mi;
2079
2080 sItemCount = (SHORT) WinSendMsg(hwndMenu,
2081 MM_QUERYITEMCOUNT, MPVOID, MPVOID);
2082
2083 /* clean out old additions */
2084 while ((SHORT) WinSendMsg(hwndMenu,
2085 MM_DELETEITEM,
2086 MPFROM2SHORT(IDM_SWITCHSTART + x++,
2087 TRUE), MPVOID) < sItemCount)
2088 sItemCount--;
2089 x = 0;
2090 while ((SHORT) WinSendMsg(hwndMenu,
2091 MM_DELETEITEM,
2092 MPFROM2SHORT(IDM_WINDOWSTART + x++,
2093 TRUE), MPVOID) < sItemCount)
2094 sItemCount--;
2095
2096 x = 0;
2097 if (hwndTop) {
2098
2099 char wtext[CCHMAXPATH + 8];
2100 HENUM henum;
2101 HWND hwndChild;
2102
2103 /* add children of the main FM/2 client */
2104 henum = WinBeginEnumWindows(hwndTop);
2105 memset(&mi, 0, sizeof(mi));
2106 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2107 if (WinQueryWindowUShort(hwndChild, QWS_ID) && hwndChild != hwndFrame) {
2108 *wtext = 0;
2109 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, wtext);
2110 if (*wtext) {
2111 wtext[CCHMAXPATH + 7] = 0;
2112 mi.afStyle = MIS_TEXT;
2113 if (!((x + sItemCount) % 28))
2114 mi.afStyle |= MIS_BREAK;
2115 mi.id = IDM_WINDOWSTART + x;
2116 mi.iPosition = MIT_END;
2117 if ((SHORT) WinSendMsg(hwndMenu,
2118 MM_INSERTITEM,
2119 MPFROMP(&mi), MPFROMP(wtext)) >= 0)
2120 x++;
2121 }
2122 }
2123 }
2124 WinEndEnumWindows(henum);
2125 }
2126
2127 /* add external FM/2 windows */
2128 {
2129 PSWBLOCK pswb;
2130 ULONG ulSize, ulcEntries;
2131 HWND hwndTopFrame;
2132 register INT i;
2133
2134 hwndTopFrame = hwndTop ? WinQueryWindow(hwndTop, QW_PARENT) : (HWND)0;
2135 /* Get the switch list information */
2136 x = 0;
2137 ulcEntries = WinQuerySwitchList(0, NULL, 0);
2138 ulSize = sizeof(SWBLOCK) + sizeof(HSWITCH) + (ulcEntries + 4L) *
2139 (LONG) sizeof(SWENTRY);
2140 /* Allocate memory for list */
2141 pswb = xmalloc(ulSize, pszSrcFile, __LINE__);
2142 if (pswb) {
2143 /* Put the info in the list */
2144 ulcEntries = WinQuerySwitchList(0, pswb, ulSize - sizeof(SWENTRY));
2145 /* do the dirty deed */
2146 memset(&mi, 0, sizeof(mi));
2147 for (i = 0; i < pswb->cswentry; i++) {
2148 if (pswb->aswentry[i].swctl.uchVisibility == SWL_VISIBLE &&
2149 pswb->aswentry[i].swctl.fbJump == SWL_JUMPABLE &&
2150 (pswb->aswentry[i].swctl.idProcess != mypid ||
2151 !hwndFrame ||
2152 pswb->aswentry[i].swctl.hwnd != hwndFrame) &&
2153 (pswb->aswentry[i].swctl.idProcess != mypid ||
2154 !hwndTopFrame ||
2155 pswb->aswentry[i].swctl.hwnd != hwndTopFrame ||
2156 !WinIsChild(hwndFrame, hwndTop))) {
2157 if (!strnicmp(pswb->aswentry[i].swctl.szSwtitle, "AV/2", 4)
2158 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "File Manager/2")
2159 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "Collector")
2160 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VTree", 5)
2161 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VDir", 4)
2162 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, FM2Str, 4)) {
2163 mi.afStyle = MIS_TEXT;
2164 if (x && !(x % 28))
2165 mi.afStyle |= MIS_BREAK;
2166 mi.id = IDM_SWITCHSTART + y;
2167 mi.iPosition = MIT_END;
2168 switches[y] = pswb->aswentry[i].hswitch;
2169 if ((SHORT) WinSendMsg(hwndMenu,
2170 MM_INSERTITEM,
2171 MPFROMP(&mi),
2172 MPFROMP(pswb->aswentry[i].
2173 swctl.szSwtitle)) >= 0) {
2174 y++;
2175 x++;
2176 }
2177 }
2178 }
2179 }
2180 numswitches = y;
2181 free(pswb);
2182 DosPostEventSem(CompactSem);
2183 }
2184 }
2185}
2186
2187BOOL SwitchCommand(HWND hwndMenu, USHORT cmd)
2188{
2189 BOOL ret = FALSE;
2190
2191 if (hwndMain && hwndMenu && cmd >= IDM_WINDOWSTART && cmd < IDM_SWITCHSTART) {
2192 /*
2193 * select a child window (of client)
2194 */
2195
2196 MENUITEM mi;
2197 HWND hwndSubMenu = (HWND) 0, hwndChild;
2198 CHAR s[CCHMAXPATH + 8];
2199
2200 if (WinQueryWindowUShort(hwndMenu, QWS_ID) != IDM_WINDOWSMENU) {
2201 memset(&mi, 0, sizeof(mi));
2202 mi.iPosition = MIT_END;
2203 mi.afStyle = MIS_TEXT;
2204 if (WinSendMsg(hwndMenu,
2205 MM_QUERYITEM,
2206 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
2207 hwndSubMenu = mi.hwndSubMenu;
2208 }
2209 else
2210 hwndSubMenu = hwndMenu;
2211 if (hwndSubMenu) {
2212 *s = 0;
2213 if (WinSendMsg(hwndSubMenu,
2214 MM_QUERYITEMTEXT,
2215 MPFROM2SHORT(cmd, CCHMAXPATH + 8), MPFROMP(s)) && *s) {
2216
2217 HENUM henum;
2218 CHAR checkText[CCHMAXPATH + 8];
2219 SWP swp;
2220
2221 s[CCHMAXPATH + 7] = 0;
2222 henum = WinBeginEnumWindows(hwndMain);
2223 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2224 if (WinQueryWindowUShort(hwndChild, QWS_ID)) {
2225 *checkText = 0;
2226 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, checkText);
2227 checkText[CCHMAXPATH + 7] = 0;
2228 if (!stricmp(checkText, s)) {
2229 if (WinQueryWindowPos(hwndChild, &swp)) {
2230 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE))
2231 WinSetWindowPos(hwndChild,
2232 HWND_TOP,
2233 0, 0, 0, 0, SWP_RESTORE | SWP_ZORDER);
2234 }
2235 WinSetActiveWindow(HWND_DESKTOP, hwndChild);
2236 ret = TRUE;
2237 break;
2238 }
2239 }
2240 }
2241 WinEndEnumWindows(henum);
2242 }
2243 }
2244 }
2245 else if (cmd >= IDM_SWITCHSTART && cmd < IDM_SWITCHSTART + 499) {
2246 if (cmd - IDM_SWITCHSTART < numswitches) {
2247 WinSwitchToProgram(switches[cmd - IDM_SWITCHSTART]);
2248 ret = TRUE;
2249 }
2250 }
2251
2252 return ret;
2253}
2254
2255/** CheckDriveSpaceAvail
2256 * Take space needed and checks that drive has at least 1000 bits in excess of the required space.
2257 * Returns 0 if sufficient space is available; 1 if the drive is full & 2 on abort of operation
2258 * when the drive would have less than ullFreeSpaceWhenComplete remaining or has insufficient space.
2259 */
2260
2261INT CheckDriveSpaceAvail(CHAR *pTargetPath, ULONGLONG ullSpaceNeeded,
2262 ULONGLONG ullFreeSpaceWhenComplete)
2263{
2264 FSALLOCATE fsa;
2265 ULONGLONG ullFreeQty;
2266 APIRET ret;
2267
2268 DosQueryFSInfo(toupper(*pTargetPath) - 'A' + 1, FSIL_ALLOC, &fsa, sizeof(FSALLOCATE));
2269 ullFreeQty = (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
2270 if (ullFreeQty > ullSpaceNeeded + ullFreeSpaceWhenComplete)
2271 return 0;
2272 else if (ullFreeQty < ullSpaceNeeded + 1024) {
2273 CHAR szKB[20];
2274
2275 CommaFmtULL(szKB, sizeof(szKB),
2276 ullFreeQty - ullSpaceNeeded, ' ');
2277 if (ullFreeSpaceWhenComplete == 0) {
2278 saymsg(MB_OK,
2279 HWND_DESKTOP,
2280 NullStr,
2281 GetPString(IDS_DRIVESPACELIMITEDTMPSAVE),
2282 pTargetPath);
2283 return 0;
2284 }
2285 else {
2286 if (ullFreeQty > ullSpaceNeeded) {
2287 ret = saymsg(MB_YESNO,
2288 HWND_DESKTOP,
2289 NullStr,
2290 GetPString(IDS_DRIVESPACELIMITED),
2291 pTargetPath,
2292 szKB);
2293 if (ret == MBID_YES)
2294 return 0;
2295 else
2296 return 2;
2297 }
2298 else {
2299 saymsg(MB_OK,
2300 HWND_DESKTOP,
2301 NullStr,
2302 GetPString(IDS_DRIVESPACEEXCEEDED),
2303 pTargetPath);
2304 return 2;
2305 }
2306 }
2307 }
2308 else
2309 return 1;
2310}
2311
2312#pragma alloc_text(MAINWND5,SetSysMenu)
2313#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
2314#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
2315#pragma alloc_text(MISC1,CheckDriveSpaceAvail)
2316
2317#ifdef FORTIFY
2318#pragma alloc_text(MISC1,GetTidForWindow)
2319#endif // FORTIFY
2320
2321#pragma alloc_text(CNR_MISC1,AdjustCnrColVis,AdjustCnrColsForFSType)
2322#pragma alloc_text(CNR_MISC1,AdjustCnrColsForPref,SetCnrCols)
2323#pragma alloc_text(CNR_MISC2,CnrDirectEdit,OpenEdit)
2324#pragma alloc_text(MISC2,SetMenuCheck,disable_menuitem,SetSortChecks)
2325#pragma alloc_text(MISC2,SetDetailsSwitches,SetViewMenu)
2326#pragma alloc_text(MISC3,SetupCommandMenu,AdjustDetailsSwitches)
2327#pragma alloc_text(MISC3,ViewHelp,GetCmdSpec)
2328#pragma alloc_text(MISC3,ExecFile,SetConditionalCascade,LoadDetailsSwitches)
2329#pragma alloc_text(MISC4,PortholeInit,CheckMenu,Broadcast,SetupWinList,SwitchCommand)
2330#pragma alloc_text(MISC6,DrawTargetEmphasis,EmphasizeButton)
2331#pragma alloc_text(MISC_LIBPATH,LoadLibPath)
2332#pragma alloc_text(MISC_SAY,SayView,SaySort,SayFilter)
2333
Note: See TracBrowser for help on using the repository browser.