source: trunk/dll/misc.c@ 551

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

Indentation cleanup

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