source: trunk/dll/misc.c@ 552

Last change on this file since 552 was 552, checked in by Gregg Young, 18 years ago

font cleanup; new image and archiver masks; messages moved to string file; new drive flags including David's icons mostly working

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