source: trunk/dll/misc.c@ 1400

Last change on this file since 1400 was 1400, checked in by Gregg Young, 16 years ago

Remainder of changes to rename commafmt.h/c (Ticket 28, 82); Additional strings moved to PCSZs in init.c (Ticket 6); Added WriteDetailsSwitches used it and LoadDetailsSwitches to consolidate inline code (Ticket 343, 344)

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