source: trunk/dll/misc.c@ 1354

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

Added driveflags to over ride write verify for USB removable drives that fail when it is on (Ticket 323); A flag to prevent directory name from being broadcast to drives in the tree cnr prior to a recursive scan of the drive (causes dbl directory names Ticket 321) Add option for multithreaded recursive scan of user selected drives at startup (Ticket 322).

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