source: trunk/dll/misc.c@ 687

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

Add CheckPmDrgLimit function to fix crash when dragging to FM/2 for other apps

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