source: trunk/dll/misc.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

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