source: trunk/dll/misc.c@ 350

Last change on this file since 350 was 350, checked in by root, 19 years ago

Use Runtime_Error

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