source: trunk/dll/misc.c@ 1009

Last change on this file since 1009 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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