source: trunk/dll/misc.c@ 989

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

Refactor fm3dll.h to create command.h; broken ini is now replaced with backup or new ini as available; more variable command line ledth changes

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