source: trunk/dll/misc.c@ 773

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

Correct some compare directories collector nits
Use BldQuoted... functions
Move BldQuoted... functions near primary callers
Add RUNTYPE_MASK
Use Runtime_Error2 more

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