source: trunk/dll/misc.c@ 959

Last change on this file since 959 was 959, checked in by Gregg Young, 18 years ago

Use xfree where appropriate. Check that buffer exists following all xmallocs. Stopped at eas.c with xfree checking. One remaining xmalloc without test in dirsize.c

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