source: trunk/dll/misc.c@ 985

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

Update sizes dialog (ticket 44); Make max command line length user settable (ticket 199); use xfree for free in most cases (ticket 212); initial code to check for valid ini file (ticket 102); Some additional refactoring and structure rework; Some documentation updates;

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