source: trunk/dll/misc.c@ 1106

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

Fix problem of 2 default choices on save to clipboard/list file submenu Ticket 257

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