source: trunk/dll/misc.c@ 762

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

Use two pass logic to free CNRITEMs and ARCITEMs
Rename pszLongname to pszLongName
More compare directories rework
Make directory sizes item draw placement deterministic - how did it ever work?

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