source: trunk/dll/misc.c@ 732

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

Preliminary work on variable sized container buffers. Removes szFileName etc. Builds fine but traps.

  • 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 730 2007-07-22 17:57:09Z 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 10 Jun 07 GKY Add IsFm2Window as part of work around PM drag limit
26 05 Jul 07 GKY Fix menu removals for WORKPLACE_PROCESS=YES
27
28***********************************************************************/
29
30#define INCL_DOS
31#define INCL_WIN
32#define INCL_GPI
33#include <os2.h>
34
35#include <stdarg.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <ctype.h>
40#include <share.h>
41#include <malloc.h> // headmin
42
43#include "fm3dll.h"
44#include "fm3dlg.h"
45#include "fm3str.h"
46
47#pragma data_seg(DATA1)
48
49static PSZ pszSrcFile = __FILE__;
50
51#pragma alloc_text(MAINWND5,SetSysMenu)
52#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
53#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
54#pragma alloc_text(CNR_MISC1,AdjustCnrColVis,AdjustCnrColsForFSType)
55#pragma alloc_text(CNR_MISC1,AdjustCnrColsForPref,SetCnrCols)
56#pragma alloc_text(CNR_MISC2,CnrDirectEdit,EmptyCnr,OpenEdit)
57#pragma alloc_text(MISC2,SetMenuCheck,disable_menuitem,SetSortChecks)
58#pragma alloc_text(MISC2,SetDetailsSwitches,SetViewMenu)
59#pragma alloc_text(MISC3,SetupCommandMenu,AdjustDetailsSwitches)
60#pragma alloc_text(MISC3,ViewHelp,GetCmdSpec)
61#pragma alloc_text(MISC3,ExecFile,SetConditionalCascade,LoadDetailsSwitches)
62#pragma alloc_text(MISC3,FreeMallocedMem,FcloseFile)
63#pragma alloc_text(MISC4,PortholeInit,CheckMenu,Broadcast,SetupWinList,SwitchCommand)
64#pragma alloc_text(MISC6,DrawTargetEmphasis,EmphasizeButton)
65#pragma alloc_text(MISC_LIBPATH,LoadLibPath)
66#pragma alloc_text(MISC_SAY,SayView,SaySort,SayFilter)
67
68#ifndef BEGIN_LIBPATH
69#define BEGIN_LIBPATH 1
70#endif
71
72#ifndef END_LIBPATH
73#define END_LIBPATH 2
74#endif
75
76#ifndef ORD_DOS32QUERYEXTLIBPATH
77#define ORD_DOS32QUERYEXTLIBPATH 874
78#endif
79
80BOOL IsFm2Window(HWND hwnd, BOOL chkTid)
81{
82 PIB *ppib;
83 TIB *ptib;
84 APIRET rc;
85
86 rc = DosGetInfoBlocks(&ptib, &ppib);
87 if (rc)
88 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
89 "DosGetInfoBlocks");
90 else {
91 PID pid;
92 TID tid;
93
94 if (WinQueryWindowProcess(hwnd, &pid, &tid))
95 if (chkTid) {
96 // If window owned by FM2 process on same thread?
97 if (pid == ppib->pib_ulpid && tid == ptib->tib_ptib2->tib2_ultid)
98 return TRUE;
99 }
100 //Window is owned by FM2
101 else if (pid == ppib->pib_ulpid)
102 return TRUE;
103 }
104 return FALSE;
105}
106
107VOID SetShiftState(VOID)
108{
109 shiftstate = 0;
110 if (WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
111 shiftstate |= KC_CTRL;
112 if (WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
113 shiftstate |= KC_SHIFT;
114 if (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000)
115 shiftstate |= KC_ALT;
116}
117
118void EmphasizeButton(HWND hwnd, BOOL on)
119{
120 HPS hps = DrgGetPS(hwnd);
121
122 // fixme to complain?
123 if (hps) {
124 POINTL ptl;
125 SWP swp;
126
127 WinQueryWindowPos(hwnd, &swp);
128 ptl.x = 1;
129 ptl.y = 1;
130 GpiMove(hps, &ptl);
131 GpiSetColor(hps, ((on) ? CLR_BLACK : CLR_PALEGRAY));
132 ptl.x = swp.cx - 2;
133 ptl.y = swp.cy - 2;
134 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
135 DrgReleasePS(hps);
136 if (remove) //fixme always true
137 WinInvalidateRect(hwnd, NULL, FALSE);
138 }
139}
140
141void DrawTargetEmphasis(HWND hwnd, BOOL on)
142{
143 HPS hps = DrgGetPS(WinQueryWindow(hwnd, QW_PARENT));
144
145 if (hps) {
146 BoxWindow(hwnd, hps, ((on) ? CLR_BLACK : CLR_PALEGRAY));
147 DrgReleasePS(hps);
148 }
149}
150
151void BoxWindow(HWND hwnd, HPS hps, LONG color)
152{
153 POINTL ptl;
154 SWP swp;
155 BOOL releaseme = FALSE;
156
157 if (!hps) {
158 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
159 releaseme = TRUE;
160 }
161 if (hps && WinQueryWindowPos(hwnd, &swp)) {
162 ptl.x = swp.x - 2;
163 ptl.y = swp.y - 2;
164 GpiMove(hps, &ptl);
165 GpiSetColor(hps, color);
166 ptl.x = swp.x + swp.cx + 1;
167 ptl.y = swp.y + swp.cy + 1;
168 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
169 }
170 if (releaseme && hps)
171 WinReleasePS(hps);
172}
173
174void PaintSTextWindow(HWND hwnd, HPS hps)
175{
176 /*
177 * paint a text window such that the rightmost part of the text is
178 * always visible even if the text length exceeds the length of the
179 * window -- otherwise, paint the window so that it is left-justified
180 * and vertically centered.
181 */
182
183 char *s = NULL;
184 long len;
185 POINTL aptl[TXTBOX_COUNT], ptl;
186 RECTL rcl;
187 char *p;
188 BOOL releaseme = FALSE;
189
190 if (!hps) {
191 releaseme = TRUE;
192 hps = WinGetPS(hwnd);
193 }
194 if (hps) {
195 WinQueryWindowRect(hwnd, &rcl);
196 WinFillRect(hps, &rcl, CLR_PALEGRAY);
197 len = WinQueryWindowTextLength(hwnd);
198 if (len)
199 s = xmalloc(len + 1, pszSrcFile, __LINE__);
200 if (s) {
201 *s = 0;
202 WinQueryWindowText(hwnd, CCHMAXPATH, s);
203 if (*s) {
204 rcl.xRight -= 3;
205 p = s;
206 GpiQueryTextBox(hps, 3, "...", TXTBOX_COUNT, aptl);
207 len = aptl[TXTBOX_TOPRIGHT].x;
208 do {
209 GpiQueryTextBox(hps, strlen(p), p, TXTBOX_COUNT, aptl);
210 if (aptl[TXTBOX_TOPRIGHT].x > (rcl.xRight - ((p != s) ? len : 0)))
211 p++;
212 else
213 break;
214 }
215 while (*p);
216 if (*p) {
217 GpiSetMix(hps, FM_OVERPAINT);
218 GpiSetColor(hps, CLR_BLACK);
219 ptl.x = 3;
220 ptl.y = ((rcl.yTop / 2) -
221 ((aptl[TXTBOX_TOPRIGHT].y +
222 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
223 GpiMove(hps, &ptl);
224 if (p != s)
225 GpiCharString(hps, 3, "...");
226 GpiCharString(hps, strlen(p), p);
227 }
228 }
229 free(s);
230 }
231 if (releaseme)
232 WinReleasePS(hps);
233 }
234}
235
236VOID PaintRecessedWindow(HWND hwnd, HPS hps, BOOL outtie, BOOL dbl)
237{
238 /*
239 * paint a recessed box around the window
240 * two pixels width required around window for painting...
241 */
242 BOOL releaseme = FALSE;
243
244 if (!hps) {
245 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
246 releaseme = TRUE;
247 }
248 if (hps) {
249
250 POINTL ptl;
251 SWP swp;
252
253 WinQueryWindowPos(hwnd, &swp);
254 ptl.x = swp.x - 1;
255 ptl.y = swp.y - 1;
256 GpiMove(hps, &ptl);
257 if (!outtie)
258 GpiSetColor(hps, CLR_WHITE);
259 else
260 GpiSetColor(hps, CLR_DARKGRAY);
261 ptl.x = swp.x + swp.cx;
262 GpiLine(hps, &ptl);
263 ptl.y = swp.y + swp.cy;
264 GpiLine(hps, &ptl);
265 if (dbl) {
266 ptl.x = swp.x - 2;
267 ptl.y = swp.y - 2;
268 GpiMove(hps, &ptl);
269 ptl.x = swp.x + swp.cx + 1;
270 GpiLine(hps, &ptl);
271 ptl.y = swp.y + swp.cy + 1;
272 GpiLine(hps, &ptl);
273 }
274 if (!outtie)
275 GpiSetColor(hps, CLR_DARKGRAY);
276 else
277 GpiSetColor(hps, CLR_WHITE);
278 if (dbl) {
279 ptl.x = swp.x - 2;
280 GpiLine(hps, &ptl);
281 ptl.y = swp.y - 2;
282 GpiLine(hps, &ptl);
283 ptl.x = swp.x + swp.cx;
284 ptl.y = swp.y + swp.cy;
285 GpiMove(hps, &ptl);
286 }
287 ptl.x = swp.x - 1;
288 GpiLine(hps, &ptl);
289 ptl.y = swp.y - 1;
290 GpiLine(hps, &ptl);
291 GpiSetColor(hps, CLR_PALEGRAY);
292 ptl.x = swp.x - (2 + (dbl != FALSE));
293 ptl.y = swp.y - (2 + (dbl != FALSE));
294 GpiMove(hps, &ptl);
295 ptl.x = swp.x + swp.cx + (1 + (dbl != FALSE));
296 GpiLine(hps, &ptl);
297 ptl.y = swp.y + swp.cy + (1 + (dbl != FALSE));
298 GpiLine(hps, &ptl);
299 ptl.x = swp.x - (2 + (dbl != FALSE));
300 GpiLine(hps, &ptl);
301 ptl.y = swp.y - (2 + (dbl != FALSE));
302 GpiLine(hps, &ptl);
303 if (releaseme)
304 WinReleasePS(hps);
305 }
306}
307
308BOOL AdjustCnrColVis(HWND hwndCnr, CHAR * title, BOOL visible, BOOL toggle)
309{
310 PFIELDINFO pfi = (PFIELDINFO) WinSendMsg(hwndCnr,
311 CM_QUERYDETAILFIELDINFO,
312 MPVOID, MPFROMSHORT(CMA_FIRST));
313
314 while (pfi) {
315 if (!strcmp(pfi->pTitleData, title)) {
316 if (toggle) {
317 if (pfi->flData & CFA_INVISIBLE)
318 pfi->flData &= (~CFA_INVISIBLE);
319 else
320 pfi->flData |= CFA_INVISIBLE;
321 return !(pfi->flData & CFA_INVISIBLE);
322 }
323 else {
324 if (visible)
325 pfi->flData &= (~CFA_INVISIBLE);
326 else
327 pfi->flData |= CFA_INVISIBLE;
328 }
329 return TRUE;
330 }
331 pfi = pfi->pNextFieldInfo;
332 }
333 return FALSE;
334}
335
336BOOL AdjustCnrColRO(HWND hwndCnr, CHAR * title, BOOL readonly, BOOL toggle)
337{
338 PFIELDINFO pfi = (PFIELDINFO) WinSendMsg(hwndCnr,
339 CM_QUERYDETAILFIELDINFO,
340 MPVOID, MPFROMSHORT(CMA_FIRST));
341
342 while (pfi) {
343 if (!strcmp(pfi->pTitleData, title)) {
344 if (toggle) {
345 if (pfi->flData & CFA_FIREADONLY)
346 pfi->flData &= (~CFA_FIREADONLY);
347 else
348 pfi->flData |= CFA_FIREADONLY;
349 return (pfi->flData & CFA_FIREADONLY);
350 }
351 else {
352 if (!readonly)
353 pfi->flData &= (~CFA_FIREADONLY);
354 else
355 pfi->flData |= CFA_FIREADONLY;
356 }
357 return TRUE;
358 }
359 pfi = pfi->pNextFieldInfo;
360 }
361 return FALSE;
362}
363
364VOID AdjustCnrColsForFSType(HWND hwndCnr, CHAR * directory, DIRCNRDATA * dcd)
365{
366 CHAR FileSystem[CCHMAXPATH];
367 INT x;
368 BOOL hasCreateDT;
369 BOOL hasAccessDT;
370 BOOL hasLongNames;
371 BOOL *pBool;
372
373 if (!directory || !*directory)
374 return;
375 x = CheckDrive(toupper(*directory), FileSystem, NULL);
376 if (x != -1) {
377 if (!stricmp(FileSystem, HPFS) ||
378 !stricmp(FileSystem, JFS) ||
379 !stricmp(FileSystem, FAT32) ||
380 !stricmp(FileSystem, RAMFS) ||
381 !stricmp(FileSystem, NDFS32) ||
382 !stricmp(FileSystem, NTFS) ||
383 !stricmp(FileSystem, HPFS386)) {
384 hasCreateDT = TRUE;
385 hasAccessDT = TRUE;
386 hasLongNames = TRUE;
387 }
388 else if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
389 hasCreateDT = TRUE;
390 hasAccessDT = FALSE;
391 hasLongNames = FALSE;
392 }
393 else {
394 // Assume FAT
395 hasCreateDT = FALSE;
396 hasAccessDT = FALSE;
397 hasLongNames = FALSE;
398 }
399 }
400 else {
401 // Assume FAT
402 hasCreateDT = FALSE;
403 hasAccessDT = FALSE;
404 hasLongNames = FALSE;
405 }
406 pBool = (dcd) ? &dcd->detailsladate : &detailsladate;
407 AdjustCnrColVis(hwndCnr, GetPString(IDS_LADATE),
408 (*pBool) ? hasAccessDT : FALSE, FALSE);
409 pBool = (dcd) ? &dcd->detailslatime : &detailslatime;
410 AdjustCnrColVis(hwndCnr, GetPString(IDS_LATIME),
411 (*pBool) ? hasAccessDT : FALSE, FALSE);
412 pBool = (dcd) ? &dcd->detailscrdate : &detailscrdate;
413 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRDATE),
414 (*pBool) ? hasCreateDT : FALSE, FALSE);
415 pBool = (dcd) ? &dcd->detailscrtime : &detailscrtime;
416 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRTIME),
417 (*pBool) ? hasCreateDT : FALSE, FALSE);
418 pBool = (dcd) ? &dcd->detailslongname : &detailslongname;
419 AdjustCnrColVis(hwndCnr, GetPString(IDS_LNAME),
420 (*pBool) ? hasLongNames : FALSE, FALSE);
421 WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
422}
423
424VOID AdjustCnrColsForPref(HWND hwndCnr, CHAR * directory, DIRCNRDATA * dcd,
425 BOOL compare)
426{
427 BOOL *bool;
428
429 bool = (dcd) ? &dcd->detailssubject : &detailssubject;
430 AdjustCnrColVis(hwndCnr, ((compare) ? GetPString(IDS_STATUS) :
431 GetPString(IDS_SUBJ)), *bool, FALSE);
432 bool = (dcd) ? &dcd->detailsattr : &detailsattr;
433 AdjustCnrColVis(hwndCnr, GetPString(IDS_ATTR), *bool, FALSE);
434 bool = (dcd) ? &dcd->detailsicon : &detailsicon;
435 AdjustCnrColVis(hwndCnr, GetPString(IDS_ICON), *bool, FALSE);
436 bool = (dcd) ? &dcd->detailslwdate : &detailslwdate;
437 AdjustCnrColVis(hwndCnr, GetPString(IDS_LWDATE), *bool, FALSE);
438 bool = (dcd) ? &dcd->detailslwtime : &detailslwtime;
439 AdjustCnrColVis(hwndCnr, GetPString(IDS_LWTIME), *bool, FALSE);
440 bool = (dcd) ? &dcd->detailsea : &detailsea;
441 AdjustCnrColVis(hwndCnr, GetPString(IDS_EA), *bool, FALSE);
442 bool = (dcd) ? &dcd->detailssize : &detailssize;
443 AdjustCnrColVis(hwndCnr, GetPString(IDS_SIZE), *bool, FALSE);
444 if (!directory) {
445 bool = (dcd) ? &dcd->detailsladate : &detailsladate;
446 AdjustCnrColVis(hwndCnr, GetPString(IDS_LADATE), *bool, FALSE);
447 bool = (dcd) ? &dcd->detailslatime : &detailslatime;
448 AdjustCnrColVis(hwndCnr, GetPString(IDS_LATIME), *bool, FALSE);
449 bool = (dcd) ? &dcd->detailscrdate : &detailscrdate;
450 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRDATE), *bool, FALSE);
451 bool = (dcd) ? &dcd->detailscrtime : &detailscrtime;
452 AdjustCnrColVis(hwndCnr, GetPString(IDS_CRTIME), *bool, FALSE);
453 bool = (dcd) ? &dcd->detailslongname : &detailslongname;
454 AdjustCnrColVis(hwndCnr, GetPString(IDS_LNAME), *bool, FALSE);
455 WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
456 }
457 else
458 AdjustCnrColsForFSType(hwndCnr, directory, dcd);
459}
460
461BOOL SetCnrCols(HWND hwndCnr, BOOL compare)
462{
463 BOOL fSuccess = TRUE;
464 PFIELDINFO pfi, pfiLastLeftCol, pfiIconCol;
465
466 // Allocate storage for container column data
467
468 pfi = WinSendMsg(hwndCnr, CM_ALLOCDETAILFIELDINFO,
469 MPFROMLONG(CONTAINER_COLUMNS), NULL);
470
471 if (pfi) {
472
473 PFIELDINFO pfiFirst;
474 FIELDINFOINSERT fii;
475
476 // Store original value of pfi so we won't lose it when it changes.
477 // This will be needed on the CM_INSERTDETAILFIELDINFO message.
478
479 pfiFirst = pfi;
480
481 // Fill in column information for the icon column
482
483 pfi->flData = CFA_BITMAPORICON | CFA_CENTER | CFA_FIREADONLY;
484 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
485 pfi->pTitleData = GetPString(IDS_ICON);
486 pfi->offStruct = FIELDOFFSET(MINIRECORDCORE, hptrIcon);
487
488 pfiIconCol = pfi;
489
490 // Fill in column information for the file name. Note that we are
491 // using the pszFileName variable rather than szFileName. We do this
492 // because the container needs a pointer to the file name. If we used
493 // szFileName (a character array, not a pointer), the container would
494 // take the first 4 bytes of szFileName and think it was a pointer,
495 // which of course it is not. Later in the FillInRecord* functions we set
496 // pszFileName to point to szFileName.
497
498 pfi = pfi->pNextFieldInfo;
499 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
500 pfi->flTitle = CFA_CENTER;
501 pfi->pTitleData = GetPString(IDS_FILENAME);
502 pfi->offStruct = FIELDOFFSET(CNRITEM, pszFileName);
503
504 // Fill in column information for the longname.
505
506 pfi = pfi->pNextFieldInfo;
507 pfi->flData = CFA_STRING | CFA_LEFT;
508 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
509 pfi->pTitleData = GetPString(IDS_LNAME);
510 pfi->offStruct = FIELDOFFSET(CNRITEM, pszLongname);
511
512 // Store the current pfi value as that will be used to indicate the
513 // last column in the lefthand container window (we have a splitbar)
514
515 pfiLastLeftCol = pfi;
516
517 // Fill in column info for subjects
518
519 pfi = pfi->pNextFieldInfo;
520 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
521 if (compare)
522 pfi->flData |= CFA_FIREADONLY;
523 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
524 pfi->pTitleData = (compare) ? GetPString(IDS_STATUS) :
525 GetPString(IDS_SUBJ);
526 pfi->offStruct = FIELDOFFSET(CNRITEM, pszSubject);
527
528 // Fill in column information for the file size
529
530 pfi = pfi->pNextFieldInfo;
531 pfi->flData = CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
532 pfi->flTitle = CFA_CENTER;
533 pfi->pTitleData = GetPString(IDS_SIZE);
534 pfi->offStruct = FIELDOFFSET(CNRITEM, cbFile);
535
536 // Fill in the column information for the file's ea size
537
538 pfi = pfi->pNextFieldInfo;
539 pfi->flData = CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
540 pfi->flTitle = CFA_CENTER;
541 pfi->pTitleData = GetPString(IDS_EA);
542 pfi->offStruct = FIELDOFFSET(CNRITEM, easize);
543
544 // Fill in the column information for the file attribute
545
546 pfi = pfi->pNextFieldInfo;
547 pfi->flData = CFA_STRING | CFA_CENTER | CFA_SEPARATOR | CFA_FIREADONLY;
548 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
549 pfi->pTitleData = GetPString(IDS_ATTR);
550 pfi->offStruct = FIELDOFFSET(CNRITEM, pszDispAttr);
551
552 // Fill in column information for last write file date
553
554 pfi = pfi->pNextFieldInfo;
555 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
556 pfi->flTitle = CFA_CENTER;
557 pfi->pTitleData = GetPString(IDS_LWDATE);
558 pfi->offStruct = FIELDOFFSET(CNRITEM, date);
559
560 // Fill in column information for the last write file time
561
562 pfi = pfi->pNextFieldInfo;
563 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
564 pfi->flTitle = CFA_CENTER;
565 pfi->pTitleData = GetPString(IDS_LWTIME);
566 pfi->offStruct = FIELDOFFSET(CNRITEM, time);
567
568 // Fill in column information for last access file date
569
570 pfi = pfi->pNextFieldInfo;
571 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
572 pfi->flTitle = CFA_CENTER;
573 pfi->pTitleData = GetPString(IDS_LADATE);
574 pfi->offStruct = FIELDOFFSET(CNRITEM, ladate);
575
576 // Fill in column information for the last access file time
577
578 pfi = pfi->pNextFieldInfo;
579 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
580 pfi->flTitle = CFA_CENTER;
581 pfi->pTitleData = GetPString(IDS_LATIME);
582 pfi->offStruct = FIELDOFFSET(CNRITEM, latime);
583
584 // Fill in column information for create file date
585
586 pfi = pfi->pNextFieldInfo;
587 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
588 pfi->flTitle = CFA_CENTER;
589 pfi->pTitleData = GetPString(IDS_CRDATE);
590 pfi->offStruct = FIELDOFFSET(CNRITEM, crdate);
591
592 // Fill in column information for the create file time
593
594 pfi = pfi->pNextFieldInfo;
595 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_FIREADONLY;
596 pfi->flTitle = CFA_CENTER;
597 pfi->pTitleData = GetPString(IDS_CRTIME);
598 pfi->offStruct = FIELDOFFSET(CNRITEM, crtime);
599
600 // Use the CM_INSERTDETAILFIELDINFO message to tell the container
601 // all the column information it needs to function properly. Place
602 // this column info first in the column list and update the display
603 // after they are inserted (fInvalidateFieldInfo = TRUE)
604
605 (void)memset(&fii, 0, sizeof(FIELDINFOINSERT));
606
607 fii.cb = sizeof(FIELDINFOINSERT);
608 fii.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
609 fii.cFieldInfoInsert = (SHORT) CONTAINER_COLUMNS;
610 fii.fInvalidateFieldInfo = TRUE;
611
612 if (!WinSendMsg(hwndCnr, CM_INSERTDETAILFIELDINFO, MPFROMP(pfiFirst),
613 MPFROMP(&fii)))
614 fSuccess = FALSE;
615 }
616 else
617 fSuccess = FALSE;
618
619 if (fSuccess) {
620
621 CNRINFO cnri;
622 ULONG size;
623
624 // Tell the container about the splitbar and where it goes
625
626 cnri.cb = sizeof(CNRINFO);
627 cnri.pFieldInfoLast = pfiLastLeftCol;
628 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
629 cnri.pFieldInfoObject = pfiIconCol;
630 size = sizeof(LONG);
631 PrfQueryProfileData(fmprof,
632 appname, "CnrSplitBar", &cnri.xVertSplitbar, &size);
633 if (cnri.xVertSplitbar <= 0)
634 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
635 if (!WinSendMsg(hwndCnr, CM_SETCNRINFO, MPFROMP(&cnri),
636 MPFROMLONG(CMA_PFIELDINFOLAST | CMA_PFIELDINFOOBJECT |
637 CMA_XVERTSPLITBAR)))
638 fSuccess = FALSE;
639 }
640
641 return fSuccess;
642}
643
644MRESULT CnrDirectEdit(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
645{
646 switch (SHORT2FROMMP(mp1)) {
647 case CN_BEGINEDIT:
648 if (mp2) {
649 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
650 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
651
652 if (pci &&
653 (INT) pci != -1 &&
654 !IsRoot(pci->pszFileName) &&
655 !(pci->flags & RECFLAGS_ENV) && !(pci->flags & RECFLAGS_UNDERENV)) {
656 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszFileName)) {
657 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMP(pci->pszFileName), MPVOID);
658 }
659 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject))
660 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(40), MPVOID);
661 else
662 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(CCHMAXPATH), MPVOID);
663 }
664 else
665 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
666 }
667 break;
668
669 case CN_REALLOCPSZ:
670 if (mp2) {
671 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
672 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
673 CHAR szData[CCHMAXPATH], testname[CCHMAXPATH];
674 HWND hwndMLE = WinWindowFromID(hwnd, CID_MLE);
675
676 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
677 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject)) {
678
679 APIRET rc;
680 EAOP2 eaop;
681 PFEA2LIST pfealist = NULL;
682 CHAR szSubject[256];
683 ULONG ealen;
684 USHORT len;
685 CHAR *eaval;
686
687 WinQueryWindowText(hwndMLE, 40, szSubject);
688 szSubject[39] = 0;
689 chop_at_crnl(szSubject);
690 bstrip(szSubject);
691 WinSetWindowText(hwndMLE, szSubject);
692 len = strlen(szSubject);
693 if (len)
694 ealen = sizeof(FEA2LIST) + 9 + len + 4;
695 else
696 ealen = sizeof(FEALIST) + 9;
697 rc = DosAllocMem((PPVOID) & pfealist, ealen + 64L,
698 OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
699 if (rc)
700 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile,
701 __LINE__, GetPString(IDS_OUTOFMEMORY));
702 else {
703 memset(pfealist, 0, ealen + 1);
704 pfealist->cbList = ealen;
705 pfealist->list[0].oNextEntryOffset = 0L;
706 pfealist->list[0].fEA = 0;
707 pfealist->list[0].cbName = 8;
708 strcpy(pfealist->list[0].szName, SUBJECT);
709 if (len) {
710 eaval = pfealist->list[0].szName + 9;
711 *(USHORT *) eaval = (USHORT) EAT_ASCII;
712 eaval += sizeof(USHORT);
713 *(USHORT *) eaval = (USHORT) len;
714 eaval += sizeof(USHORT);
715 memcpy(eaval, szSubject, len);
716 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
717 }
718 else
719 pfealist->list[0].cbValue = 0;
720 eaop.fpGEA2List = (PGEA2LIST) 0;
721 eaop.fpFEA2List = pfealist;
722 eaop.oError = 0L;
723 rc = DosSetPathInfo(pci->pszFileName,
724 FIL_QUERYEASIZE,
725 (PVOID) & eaop, sizeof(EAOP2), DSPI_WRTTHRU);
726 DosFreeMem(pfealist);
727 if (rc)
728 return FALSE;
729 }
730 return (MRESULT) TRUE;
731 }
732 else if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszLongname)) {
733
734 CHAR longname[CCHMAXPATHCOMP];
735
736 *longname = 0;
737 WinQueryWindowText(hwndMLE, sizeof(longname), longname);
738 longname[CCHMAXPATHCOMP - 1] = 0;
739 chop_at_crnl(longname);
740 WinSetWindowText(hwndMLE, longname);
741 return (MRESULT) WriteLongName(pci->pszFileName, longname);
742 }
743 else {
744 WinQueryWindowText(hwndMLE, sizeof(szData), szData);
745 if (strchr(szData, '?') ||
746 strchr(szData, '*') || IsRoot(pci->pszFileName))
747 return (MRESULT) FALSE;
748 /* If the text changed, rename the file system object. */
749 chop_at_crnl(szData);
750 bstrip(szData);
751 if (!IsFullName(szData))
752 Runtime_Error(pszSrcFile, __LINE__, "bad name");
753 else {
754 if (DosQueryPathInfo(szData,
755 FIL_QUERYFULLNAME,
756 testname, sizeof(testname)))
757 return FALSE;
758 if (DosQueryPathInfo(pci->pszFileName,
759 FIL_QUERYFULLNAME, szData, sizeof(szData)))
760 strcpy(szData, pci->pszFileName);
761 WinSetWindowText(hwndMLE, szData);
762 if (strcmp(szData, testname)) {
763 if (stricmp(szData, testname) && IsFile(testname) != -1) {
764 DosBeep(50, 100); /* exists; disallow */
765 return (MRESULT) FALSE;
766 }
767 if (docopyf(MOVE, szData, "%s", testname))
768 Runtime_Error(pszSrcFile, __LINE__, "docopyf");
769 else {
770 CHAR *filename;
771
772 filename = xstrdup(testname, pszSrcFile, __LINE__);
773 if (filename) {
774 if (!PostMsg(hwnd,
775 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
776 free(filename);
777 }
778 if (stricmp(testname, pci->pszFileName)) {
779 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci));
780 filename = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
781 if (filename) {
782 if (!PostMsg(hwnd,
783 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
784 free(filename);
785 }
786 }
787 }
788 }
789 }
790 }
791 }
792 }
793 return FALSE;
794
795 case CN_ENDEDIT:
796 if (mp2) {
797 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
798 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
799
800 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
801 WinSendMsg(hwnd,
802 CM_INVALIDATERECORD,
803 MPFROMP(&pci),
804 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
805 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszFileName))
806 PostMsg(hwnd, UM_SORTRECORD, MPVOID, MPVOID);
807 }
808 else {
809 USHORT cmd = 0;
810
811 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszFileName))
812 cmd = IDM_SORTSMARTNAME;
813 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, cbFile))
814 cmd = IDM_SORTSIZE;
815 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, easize))
816 cmd = IDM_SORTEASIZE;
817 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, date))
818 cmd = IDM_SORTLWDATE;
819 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, time))
820 cmd = IDM_SORTLWDATE;
821 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, ladate))
822 cmd = IDM_SORTLADATE;
823 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, latime))
824 cmd = IDM_SORTLADATE;
825 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crdate))
826 cmd = IDM_SORTCRDATE;
827 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crtime))
828 cmd = IDM_SORTCRDATE;
829 if (cmd)
830 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
831 }
832 }
833 break;
834 }
835 return (MRESULT) - 1;
836}
837
838BOOL SetMenuCheck(HWND hwndMenu, USHORT id, BOOL * bool, BOOL toggle,
839 CHAR * savename)
840{
841 if (toggle) {
842 *bool = (*bool) ? FALSE : TRUE;
843 if (savename && *savename)
844 PrfWriteProfileData(fmprof, appname, savename, bool, sizeof(BOOL));
845 }
846 WinSendMsg(hwndMenu, MM_SETITEMATTR,
847 MPFROM2SHORT(id, 1),
848 MPFROM2SHORT(MIA_CHECKED, (*bool ? MIA_CHECKED : 0)));
849 return *bool;
850}
851
852//== disable_menuitem() disable or enable_menuitem ==
853
854VOID disable_menuitem(HWND hwndMenu, USHORT id, BOOL disable)
855{
856 WinSendMsg(hwndMenu, MM_SETITEMATTR,
857 MPFROM2SHORT(id, TRUE),
858 MPFROM2SHORT(MIA_DISABLED, (disable ? MIA_DISABLED : 0)));
859}
860
861//== ViewHelp() invoke view.exe, return TRUE if OK ==
862
863BOOL ViewHelp(CHAR * filename)
864{
865 CHAR s[CCHMAXPATH + 81];
866 FILE *fp;
867 INT ret = -1;
868
869 fp = _fsopen(filename, "rb", SH_DENYNO);
870 if (fp) {
871 *s = 0;
872 fread(s, 1, 3, fp);
873 if (*s != 'H' || s[1] != 'S' || s[2] != 'P') {
874 fclose(fp);
875 return FALSE;
876 }
877 fclose(fp);
878 ret = runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, NULL, NULL,
879 "VIEW.EXE \"%s\"", filename);
880 }
881
882 return (ret != -1);
883}
884
885//== ExecFile() run file, return 1 if OK 0 if skipped -1 if can't run ==
886
887INT ExecFile(HWND hwnd, CHAR * filename)
888{
889 EXECARGS ex;
890 CHAR cl[1001], path[CCHMAXPATH], *p;
891 APIRET ret;
892 static INT lastflags = 0;
893
894 strcpy(path, filename);
895 p = strrchr(path, '\\');
896 if (!p)
897 p = strrchr(path, ':');
898 if (p) {
899 if (*p == ':') {
900 p++;
901 *p = '\\';
902 p++;
903 }
904 *p = 0;
905 }
906 else
907 *path = 0;
908 *cl = 0;
909 if (needs_quoting(filename))
910 strcat(cl, "\"");
911 strcat(cl, filename);
912 if (needs_quoting(filename))
913 strcat(cl, "\"");
914 memset(&ex, 0, sizeof(ex));
915 ex.flags = lastflags;
916 ex.commandline = cl;
917 *ex.path = 0;
918 *ex.environment = 0;
919 ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
920 EXEC_FRAME, &ex);
921 if (ret == 1) {
922 lastflags = ex.flags;
923 return runemf2(ex.flags, hwnd, path,
924 (*ex.environment) ? ex.environment : NULL, "%s", cl) != -1;
925 }
926 else if (ret != 0)
927 return -1;
928 return 0;
929}
930
931VOID EmptyCnr(HWND hwnd)
932{
933 /* Empty out a container in preparation to it dying */
934 PCNRITEM pci;
935 PFIELDINFO pfi;
936
937 pci = (PCNRITEM) WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
938 MPFROMSHORT(CMA_FIRST));
939 if (pci && (INT) pci != -1)
940 WinSendMsg(hwnd, CM_REMOVERECORD, MPVOID, MPFROM2SHORT(0, CMA_FREE));
941 pfi = (PFIELDINFO) WinSendMsg(hwnd, CM_QUERYDETAILFIELDINFO, MPVOID,
942 MPFROMSHORT(CMA_FIRST));
943 if (pfi)
944 WinSendMsg(hwnd, CM_REMOVEDETAILFIELDINFO, MPVOID,
945 MPFROM2SHORT(0, CMA_FREE));
946}
947
948VOID SetDetailsSwitches(HWND hwnd, DIRCNRDATA * dcd)
949{
950 WinCheckMenuItem(hwnd, IDM_SHOWLNAMES,
951 (dcd) ? dcd->detailslongname : detailslongname);
952 WinCheckMenuItem(hwnd, IDM_SHOWSUBJECT,
953 (dcd) ? dcd->detailssubject : detailssubject);
954 WinCheckMenuItem(hwnd, IDM_SHOWEAS, (dcd) ? dcd->detailsea : detailsea);
955 WinCheckMenuItem(hwnd, IDM_SHOWSIZE,
956 (dcd) ? dcd->detailssize : detailssize);
957 WinCheckMenuItem(hwnd, IDM_SHOWICON,
958 (dcd) ? dcd->detailsicon : detailsicon);
959 WinCheckMenuItem(hwnd, IDM_SHOWLWDATE,
960 (dcd) ? dcd->detailslwdate : detailslwdate);
961 WinCheckMenuItem(hwnd, IDM_SHOWLWTIME,
962 (dcd) ? dcd->detailslwtime : detailslwtime);
963 WinCheckMenuItem(hwnd, IDM_SHOWLADATE,
964 (dcd) ? dcd->detailsladate : detailsladate);
965 WinCheckMenuItem(hwnd, IDM_SHOWLATIME,
966 (dcd) ? dcd->detailslatime : detailslatime);
967 WinCheckMenuItem(hwnd, IDM_SHOWCRDATE,
968 (dcd) ? dcd->detailscrdate : detailscrdate);
969 WinCheckMenuItem(hwnd, IDM_SHOWCRTIME,
970 (dcd) ? dcd->detailscrtime : detailscrtime);
971 WinCheckMenuItem(hwnd, IDM_SHOWATTR,
972 (dcd) ? dcd->detailsattr : detailsattr);
973}
974
975VOID AdjustDetailsSwitches(HWND hwnd, HWND hwndMenu, USHORT cmd,
976 CHAR * directory, CHAR * keyroot,
977 DIRCNRDATA * dcd, BOOL compare)
978{
979 CHAR s[CCHMAXPATH], *eos = s;
980 BOOL *bool = NULL;
981
982 *s = 0;
983 if (keyroot) {
984 strcpy(s, keyroot);
985 strcat(s, ".");
986 eos = &s[strlen(s)];
987 }
988 switch (cmd) {
989 case IDM_SHOWLNAMES:
990 bool = (dcd) ? &dcd->detailslongname : &detailslongname;
991 strcpy(eos, "DetailsLongname");
992 break;
993 case IDM_SHOWSUBJECT:
994 bool = (dcd) ? &dcd->detailssubject : &detailssubject;
995 strcpy(eos, "DetailsSubject");
996 break;
997 case IDM_SHOWEAS:
998 bool = (dcd) ? &dcd->detailsea : &detailsea;
999 strcpy(eos, "DetailsEA");
1000 break;
1001 case IDM_SHOWSIZE:
1002 bool = (dcd) ? &dcd->detailssize : &detailssize;
1003 strcpy(eos, "DetailsSize");
1004 break;
1005 case IDM_SHOWICON:
1006 bool = (dcd) ? &dcd->detailsicon : &detailsicon;
1007 strcpy(eos, "DetailsIcon");
1008 break;
1009 case IDM_SHOWLWDATE:
1010 bool = (dcd) ? &dcd->detailslwdate : &detailslwdate;
1011 strcpy(eos, "DetailsLWDate");
1012 break;
1013 case IDM_SHOWLWTIME:
1014 bool = (dcd) ? &dcd->detailslwtime : &detailslwtime;
1015 strcpy(eos, "DetailsLWTime");
1016 break;
1017 case IDM_SHOWLADATE:
1018 bool = (dcd) ? &dcd->detailsladate : &detailsladate;
1019 strcpy(eos, "DetailsLADate");
1020 break;
1021 case IDM_SHOWLATIME:
1022 bool = (dcd) ? &dcd->detailslatime : &detailslatime;
1023 strcpy(eos, "DetailsLATime");
1024 break;
1025 case IDM_SHOWCRDATE:
1026 bool = (dcd) ? &dcd->detailscrdate : &detailscrdate;
1027 strcpy(eos, "DetailsCRDate");
1028 break;
1029 case IDM_SHOWCRTIME:
1030 bool = (dcd) ? &dcd->detailscrtime : &detailscrtime;
1031 strcpy(eos, "DetailsCRTime");
1032 break;
1033 case IDM_SHOWATTR:
1034 bool = (dcd) ? &dcd->detailsattr : &detailsattr;
1035 strcpy(eos, "DetailsAttr");
1036 break;
1037 default:
1038 if (hwndMenu)
1039 SetDetailsSwitches(hwndMenu, dcd);
1040 return;
1041 }
1042 if (bool)
1043 *bool = (*bool) ? FALSE : TRUE;
1044 if (*s && bool)
1045 PrfWriteProfileData(fmprof, appname, s, bool, sizeof(BOOL));
1046 if (hwnd)
1047 AdjustCnrColsForPref(hwnd, directory, dcd, compare);
1048 if (hwndMenu)
1049 SetDetailsSwitches(hwndMenu, dcd);
1050}
1051
1052VOID SetConditionalCascade(HWND hwndMenu, USHORT id, USHORT def)
1053{
1054 MENUITEM mi;
1055
1056 mi.iPosition = MIT_END;
1057 mi.hItem = 0L;
1058 mi.hwndSubMenu = (HWND) 0;
1059 mi.afAttribute = 0;
1060 mi.afStyle = MIS_TEXT;
1061 if (WinSendMsg
1062 (hwndMenu, MM_QUERYITEM, MPFROM2SHORT(id, TRUE), MPFROMP(&mi))) {
1063 WinSetWindowBits(mi.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE,
1064 MS_CONDITIONALCASCADE);
1065 WinSendMsg(mi.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(def), MPVOID);
1066 WinCheckMenuItem(mi.hwndSubMenu, def, TRUE);
1067 }
1068}
1069
1070VOID SetSortChecks(HWND hwndMenu, INT sortflags)
1071{
1072 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, FALSE);
1073 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, FALSE);
1074 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, FALSE);
1075 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, FALSE);
1076 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, FALSE);
1077 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, FALSE);
1078 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, FALSE);
1079 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, FALSE);
1080 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, FALSE);
1081 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, FALSE);
1082 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, FALSE);
1083 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, FALSE);
1084 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, FALSE);
1085 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, FALSE);
1086 if (sortflags & SORT_FIRSTEXTENSION)
1087 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, TRUE);
1088 else if (sortflags & SORT_LASTEXTENSION)
1089 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, TRUE);
1090 else if (sortflags & SORT_SIZE)
1091 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, TRUE);
1092 else if (sortflags & SORT_EASIZE)
1093 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, TRUE);
1094 else if (sortflags & SORT_LWDATE)
1095 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, TRUE);
1096 else if (sortflags & SORT_LADATE)
1097 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, TRUE);
1098 else if (sortflags & SORT_CRDATE)
1099 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, TRUE);
1100 else if (sortflags & SORT_FILENAME)
1101 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, TRUE);
1102 else if (sortflags & SORT_NOSORT)
1103 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, TRUE);
1104 else if (sortflags & SORT_SUBJECT)
1105 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, TRUE);
1106 else
1107 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, TRUE);
1108 if (sortflags & SORT_DIRSFIRST)
1109 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, TRUE);
1110 else if (sortflags & SORT_DIRSLAST)
1111 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, TRUE);
1112 if (sortflags & SORT_REVERSE)
1113 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, TRUE);
1114}
1115
1116VOID FreeMallocedMem(VOID * mem)
1117{
1118 /* for use by apps that don't use the DLLs runtime library */
1119 free(mem);
1120}
1121
1122VOID FcloseFile(FILE * fp)
1123{
1124 /* for use by apps that don't use the DLLs runtime library */
1125 fclose(fp);
1126}
1127
1128VOID SetupCommandMenu(HWND hwndMenu, HWND hwndCnr)
1129{
1130 MENUITEM mi, mit;
1131 INT x;
1132 SHORT numitems;
1133 LINKCMDS *info;
1134
1135 if (!cmdloaded)
1136 load_commands();
1137 mi.iPosition = MIT_END;
1138 mi.hwndSubMenu = (HWND) 0;
1139 mi.hItem = 0L;
1140 mi.afAttribute = 0;
1141 mi.afStyle = MIS_TEXT;
1142 memset(&mit, 0, sizeof(MENUITEM));
1143 if (WinQueryWindowUShort(hwndMenu, QWS_ID) == IDM_COMMANDSMENU)
1144 mit.hwndSubMenu = hwndMenu;
1145 else
1146 WinSendMsg(hwndMenu, MM_QUERYITEM,
1147 MPFROM2SHORT(IDM_COMMANDSMENU, TRUE), MPFROMP(&mit));
1148 if (mit.hwndSubMenu) {
1149 numitems = (SHORT) WinSendMsg(mit.hwndSubMenu, MM_QUERYITEMCOUNT,
1150 MPVOID, MPVOID);
1151 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM, MPFROMSHORT(-1), MPVOID);
1152 for (x = 0; x < numitems; x++)
1153 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
1154 MPFROMSHORT((SHORT) (x + IDM_COMMANDSTART)), MPVOID);
1155 if (hwndCnr && cmdhead) {
1156 x = 0;
1157 info = cmdhead;
1158 while (info) {
1159
1160 CHAR s[CCHMAXPATH + 24];
1161
1162 sprintf(s,
1163 "%s%s%s",
1164 info->title,
1165 (x < 20) ? "\tCtrl + " : NullStr,
1166 (x < 20 && x > 9) ? "Shift + " : NullStr);
1167 if (x < 20)
1168 sprintf(&s[strlen(s)], "%d",
1169 (((x % 10) + 1) == 10) ? 0 : (x % 10) + 1);
1170 mi.id = IDM_COMMANDSTART + x;
1171 mi.afAttribute = (((info->flags & ONCE) != 0) ?
1172 MIA_CHECKED : 0) |
1173 (((info->flags & PROMPT) != 0) ? MIA_FRAMED : 0);
1174 mi.afStyle = MIS_TEXT;
1175 if (!(x % 24) && x && info->next)
1176 mi.afStyle |= MIS_BREAK;
1177 WinSendMsg(mit.hwndSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s));
1178 x++;
1179 info = info->next;
1180 }
1181 }
1182 }
1183}
1184
1185VOID LoadDetailsSwitches(CHAR * keyroot, DIRCNRDATA * dcd)
1186{
1187 ULONG size;
1188 CHAR s[CCHMAXPATH], *eos = s;
1189 BOOL *bool;
1190
1191 *s = 0;
1192 if (keyroot) {
1193 strcpy(s, keyroot);
1194 strcat(s, ".");
1195 eos = &s[strlen(s)];
1196 }
1197 strcpy(eos, "DetailsLongname");
1198 if (dcd)
1199 bool = &dcd->detailslongname;
1200 else
1201 bool = &detailslongname;
1202 *bool = detailslongname;
1203 size = sizeof(BOOL);
1204 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1205 strcpy(eos, "DetailsSubject");
1206 if (dcd)
1207 bool = &dcd->detailssubject;
1208 else
1209 bool = &detailssubject;
1210 *bool = detailssubject;
1211 size = sizeof(BOOL);
1212 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1213 strcpy(eos, "DetailsEA");
1214 if (dcd)
1215 bool = &dcd->detailsea;
1216 else
1217 bool = &detailsea;
1218 *bool = detailsea;
1219 size = sizeof(BOOL);
1220 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1221 strcpy(eos, "DetailsSize");
1222 if (dcd)
1223 bool = &dcd->detailssize;
1224 else
1225 bool = &detailssize;
1226 *bool = detailssize;
1227 size = sizeof(BOOL);
1228 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1229 strcpy(eos, "DetailsIcon");
1230 if (dcd)
1231 bool = &dcd->detailsicon;
1232 else
1233 bool = &detailsicon;
1234 *bool = detailsicon;
1235 size = sizeof(BOOL);
1236 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1237 strcpy(eos, "DetailsAttr");
1238 if (dcd)
1239 bool = &dcd->detailsattr;
1240 else
1241 bool = &detailsattr;
1242 *bool = detailsattr;
1243 size = sizeof(BOOL);
1244 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1245 strcpy(eos, "DetailsCRDate");
1246 if (dcd)
1247 bool = &dcd->detailscrdate;
1248 else
1249 bool = &detailscrdate;
1250 *bool = detailscrdate;
1251 size = sizeof(BOOL);
1252 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1253 strcpy(eos, "DetailsCRTime");
1254 if (dcd)
1255 bool = &dcd->detailscrtime;
1256 else
1257 bool = &detailscrtime;
1258 *bool = detailscrtime;
1259 size = sizeof(BOOL);
1260 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1261 strcpy(eos, "DetailsLWDate");
1262 if (dcd)
1263 bool = &dcd->detailslwdate;
1264 else
1265 bool = &detailslwdate;
1266 *bool = detailslwdate;
1267 size = sizeof(BOOL);
1268 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1269 strcpy(eos, "DetailsLWTime");
1270 if (dcd)
1271 bool = &dcd->detailslwtime;
1272 else
1273 bool = &detailslwtime;
1274 *bool = detailslwtime;
1275 size = sizeof(BOOL);
1276 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1277 strcpy(eos, "DetailsLADate");
1278 if (dcd)
1279 bool = &dcd->detailsladate;
1280 else
1281 bool = &detailsladate;
1282 *bool = detailsladate;
1283 size = sizeof(BOOL);
1284 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1285 strcpy(eos, "DetailsLATime");
1286 if (dcd)
1287 bool = &dcd->detailslatime;
1288 else
1289 bool = &detailslatime;
1290 *bool = detailslatime;
1291 size = sizeof(BOOL);
1292 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1293}
1294
1295HWND FindDirCnr(HWND hwndParent)
1296{
1297 HWND found, hwndDir = (HWND) 0;
1298 HENUM henum;
1299
1300 henum = WinBeginEnumWindows(hwndParent);
1301 while ((found = WinGetNextWindow(henum)) != NULLHANDLE) {
1302 hwndDir = WinWindowFromID(found, FID_CLIENT);
1303 if (hwndDir) {
1304 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
1305 if (hwndDir)
1306 break;
1307 hwndDir = (HWND) 0;
1308 }
1309 }
1310 WinEndEnumWindows(henum);
1311
1312 return hwndDir;
1313}
1314
1315VOID HeapThread(VOID * dummy)
1316{
1317 ULONG postcount;
1318 APIRET rc;
1319
1320 rc = DosCreateEventSem(NULL, &CompactSem, 0L, FALSE);
1321 if (rc)
1322 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1323 "DosCreateEventSem");
1324 else {
1325 priority_normal();
1326 for (;;) {
1327 if (DosWaitEventSem(CompactSem, SEM_INDEFINITE_WAIT))
1328 break;
1329 _heapmin();
1330 DosResetEventSem(CompactSem, &postcount);
1331 }
1332 }
1333}
1334
1335VOID FixSwitchList(HWND hwnd, CHAR * text)
1336{
1337 HSWITCH hswitch;
1338 SWCNTRL swctl;
1339
1340 hswitch = WinQuerySwitchHandle(hwnd, 0);
1341 if (hswitch) {
1342 if (!WinQuerySwitchEntry(hswitch, &swctl)) {
1343 strcpy(swctl.szSwtitle, "FM/2");
1344 WinChangeSwitchEntry(hswitch, &swctl);
1345 }
1346 }
1347}
1348
1349VOID QuickPopup(HWND hwnd, DIRCNRDATA * dcd, HWND hwndMenu, USHORT id)
1350{
1351 dcd->hwndLastMenu = hwndMenu;
1352 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
1353 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1354 MPFROM2SHORT(TRUE, CRA_SOURCE));
1355 dcd->cnremphasized = TRUE;
1356 }
1357 if (dcd->flWindowAttr & CV_MINI)
1358 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
1359 if (!WinPopupMenu(hwnd, hwnd, dcd->hwndLastMenu,
1360 8, 8, 0,
1361 PU_HCONSTRAIN | PU_VCONSTRAIN |
1362 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
1363 if (dcd->cnremphasized) {
1364 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1365 MPFROM2SHORT(FALSE, CRA_SOURCE));
1366 dcd->cnremphasized = FALSE;
1367 }
1368 }
1369 else
1370 WinSendMsg(dcd->hwndLastMenu, MM_SELECTITEM,
1371 MPFROM2SHORT(id, TRUE), MPFROM2SHORT(0, FALSE));
1372}
1373
1374PMINIRECORDCORE CurrentRecord(HWND hwndCnr)
1375{
1376 SHORT attrib = (fSelectedAlways) ? CRA_SELECTED : CRA_CURSORED;
1377 PMINIRECORDCORE pmi;
1378
1379 for (;;) {
1380 pmi = (PMINIRECORDCORE) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
1381 MPFROMLONG(CMA_FIRST),
1382 MPFROMSHORT(attrib));
1383 if ((!pmi || (INT) pmi == -1) && attrib == CRA_SELECTED) /* punt */
1384 attrib = CRA_CURSORED;
1385 else
1386 break;
1387 }
1388 return ((INT) pmi == -1) ? NULL : pmi;
1389}
1390
1391BOOL PostMsg(HWND h, ULONG msg, MPARAM mp1, MPARAM mp2)
1392{
1393 BOOL rc = WinPostMsg(h, msg, mp1, mp2);
1394
1395 if (!rc) {
1396 /* PIB *ppib;
1397 TIB *ptib;
1398
1399 if (!DosGetInfoBlocks(&ptib, &ppib)) {
1400 PID pid;
1401 TID tid;
1402 QMSG qmsg;
1403
1404 if (WinQueryWindowProcess(h, &pid, &tid)) {
1405 // If window owned by some other process or some other thread?
1406 if (pid != ppib->pib_ulpid || tid != ptib->tib_ptib2->tib2_ultid)*/
1407 if(!IsFm2Window(h, 1)){
1408 QMSG qmsg;
1409 for (;;) {
1410 DosSleep(1L);
1411 rc = WinPostMsg(h, msg, mp1, mp2);
1412 if (rc)
1413 break; // OK
1414 if (!WinIsWindow((HAB) 0, h))
1415 break; // Window gone
1416 if (WinPeekMsg((HAB) 0, &qmsg, (HWND) 0, 0, 0, PM_NOREMOVE))
1417 break; // Queue has message(s)
1418 } // for
1419 }
1420 }
1421 return rc;
1422}
1423
1424VOID OpenEdit(HWND hwnd)
1425{
1426 CNREDITDATA ced;
1427 PCNRITEM pci;
1428 PFIELDINFO pfi;
1429
1430 pci = (PCNRITEM) WinSendMsg(hwnd,
1431 CM_QUERYRECORDEMPHASIS,
1432 MPFROMLONG(CMA_FIRST),
1433 MPFROMSHORT(CRA_CURSORED));
1434 if (pci && (INT) pci != -1) {
1435 memset(&ced, 0, sizeof(ced));
1436 ced.cb = sizeof(ced);
1437 ced.hwndCnr = hwnd;
1438 ced.id = WinQueryWindowUShort(hwnd, QWS_ID);
1439 ced.pRecord = (PRECORDCORE) pci;
1440 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1441 CM_QUERYDETAILFIELDINFO,
1442 MPVOID, MPFROMSHORT(CMA_FIRST));
1443 if (!pfi)
1444 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1445 else {
1446 while (pfi && (INT) pfi != -1 &&
1447 pfi->offStruct != FIELDOFFSET(CNRITEM, pszFileName))
1448 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1449 CM_QUERYDETAILFIELDINFO,
1450 MPFROMP(pfi), MPFROMSHORT(CMA_NEXT));
1451 if (pfi && (INT) pfi != -1) {
1452 ced.pFieldInfo = pfi;
1453 {
1454 CNRINFO cnri;
1455
1456 memset(&cnri, 0, sizeof(CNRINFO));
1457 cnri.cb = sizeof(CNRINFO);
1458 WinSendMsg(hwnd,
1459 CM_QUERYCNRINFO,
1460 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1461 if (cnri.flWindowAttr & CV_DETAIL)
1462 ced.id = CID_LEFTDVWND;
1463 }
1464 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1465 }
1466 }
1467 }
1468}
1469
1470#ifdef NEVER
1471VOID QuickView(HWND hwnd, CHAR * filename)
1472{
1473 if (filename && IsFile(filename) == 1) {
1474 if (TestBinary(filename) && *binview) {
1475
1476 CHAR *list[2];
1477
1478 list[0] = filename;
1479 list[1] = NULL;
1480 ExecOnList(hwnd, binview, WINDOWED | SEPARATE, NULL, list, NULL);
1481 return;
1482 }
1483 else if (*viewer) {
1484
1485 CHAR *list[2];
1486
1487 list[0] = filename;
1488 list[1] = NULL;
1489 ExecOnList(hwnd, viewer, WINDOWED | SEPARATE |
1490 ((fViewChild) ? CHILD : 0), NULL, list, NULL);
1491 return;
1492 }
1493 StartMLEEditor(HWND_DESKTOP, 5, filename, (HWND) 0);
1494 }
1495}
1496
1497VOID QuickEdit(HWND hwnd, CHAR * filename)
1498{
1499 if (filename && IsFile(filename) == 1) {
1500 if (TestBinary(filename) && *bined) {
1501
1502 CHAR *list[2];
1503
1504 list[0] = filename;
1505 list[1] = NULL;
1506 ExecOnList(hwnd, bined, WINDOWED | SEPARATE, NULL, list, NULL);
1507 return;
1508 }
1509 else if (*editor) {
1510
1511 CHAR *list[2];
1512
1513 list[0] = filename;
1514 list[1] = NULL;
1515 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, list, NULL);
1516 return;
1517 }
1518 StartMLEEditor(HWND_DESKTOP, 4, filename, (HWND) 0);
1519 }
1520}
1521#endif
1522
1523VOID PortholeInit(HWND hwndNew, MPARAM mp1, MPARAM mp2)
1524{
1525 static HWND DefMenu = (HWND) 0;
1526 HWND hwndMenu = (HWND) mp2;
1527
1528 {
1529 ULONG style;
1530
1531 style = WinQueryWindowULong(hwndMenu, QWL_STYLE);
1532 if (!(style & MS_ACTIONBAR))
1533 return;
1534 }
1535
1536 switch (SHORT1FROMMP(mp1)) {
1537 case 0:
1538 {
1539 HWND hwndNow;
1540 MENUITEM mi;
1541 ULONG ulStyle;
1542
1543 memset(&mi, 0, sizeof(mi));
1544 mi.iPosition = MIT_END;
1545 mi.afStyle = MIS_TEXT;
1546 WinSendMsg(hwndMenu, MM_QUERYITEM,
1547 MPFROM2SHORT(IDM_FILESMENU, TRUE), MPFROMP(&mi));
1548 if (!DefMenu)
1549 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1550 hwndNow = mi.hwndSubMenu;
1551 mi.hwndSubMenu = hwndNew;
1552 if (!mi.hwndSubMenu)
1553 mi.hwndSubMenu = DefMenu;
1554 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1555 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1556 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1557 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1558 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_FILESMENU);
1559 mi.afStyle = MIS_SUBMENU;
1560 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1561 ulStyle &= -WS_SAVEBITS;
1562 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1563 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1564 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1565 }
1566 break;
1567
1568 case 1:
1569 {
1570 HWND hwndNow;
1571 MENUITEM mi;
1572 ULONG ulStyle;
1573
1574 memset(&mi, 0, sizeof(mi));
1575 mi.iPosition = MIT_END;
1576 mi.afStyle = MIS_TEXT;
1577 WinSendMsg(hwndMenu, MM_QUERYITEM,
1578 MPFROM2SHORT(IDM_VIEWSMENU, TRUE), MPFROMP(&mi));
1579 if (!DefMenu)
1580 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1581 hwndNow = mi.hwndSubMenu;
1582 mi.hwndSubMenu = hwndNew;
1583 if (!mi.hwndSubMenu)
1584 mi.hwndSubMenu = DefMenu;
1585 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1586 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1587 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1588 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1589 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_VIEWSMENU);
1590 mi.afStyle = MIS_SUBMENU;
1591 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1592 ulStyle &= -WS_SAVEBITS;
1593 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1594 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1595 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1596 }
1597 break;
1598 }
1599}
1600
1601HWND CheckMenu(HWND * hwndMenu, USHORT id)
1602{
1603 /* load and adjust menus as required */
1604 if (!*hwndMenu || !WinIsWindow((HAB) 0, *hwndMenu)) {
1605 *hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1606 if (hwndMenu == &DirMenu) {
1607 WinSetWindowUShort(DirMenu, QWS_ID, IDM_FILESMENU);
1608 SetConditionalCascade(DirMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1609 SetConditionalCascade(DirMenu, IDM_COPYMENU, IDM_COPY);
1610 SetConditionalCascade(DirMenu, IDM_MOVEMENU, IDM_MOVE);
1611 SetConditionalCascade(DirMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1612 SetConditionalCascade(DirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1613 SetConditionalCascade(DirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1614 SetConditionalCascade(DirMenu, IDM_DELETESUBMENU,
1615 (fDefaultDeletePerm) ? IDM_PERMDELETE :
1616 IDM_DELETE);
1617 SetConditionalCascade(DirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1618 SetConditionalCascade(DirMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1619 if (fWorkPlace) {
1620 WinSendMsg(DirMenu, MM_DELETEITEM,
1621 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1622 WinSendMsg(DirMenu, MM_DELETEITEM,
1623 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1624 }
1625 }
1626 else if (hwndMenu == &TreeMenu) {
1627 WinSetWindowUShort(TreeMenu, QWS_ID, IDM_FILESMENU);
1628 SetConditionalCascade(TreeMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1629 SetConditionalCascade(TreeMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1630 SetConditionalCascade(TreeMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1631 SetConditionalCascade(TreeMenu, IDM_EXPANDSUBMENU, IDM_EXPAND);
1632 SetConditionalCascade(TreeMenu, IDM_MISCSUBMENU, IDM_SIZES);
1633 SetConditionalCascade(TreeMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1634 if (fWorkPlace) {
1635 WinSendMsg(TreeMenu, MM_DELETEITEM,
1636 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1637 WinSendMsg(TreeMenu, MM_DELETEITEM,
1638 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1639 }
1640 }
1641 else if (hwndMenu == &ArcMenu) {
1642 WinSetWindowUShort(ArcMenu, QWS_ID, IDM_FILESMENU);
1643 SetConditionalCascade(ArcMenu, IDM_EXTRACTSUBMENU, IDM_EXTRACT);
1644 SetConditionalCascade(ArcMenu, IDM_EDITSUBMENU, IDM_EDIT);
1645 SetConditionalCascade(ArcMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1646 if (fWorkPlace)
1647 WinSendMsg(ArcMenu, MM_DELETEITEM,
1648 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1649 }
1650 else if (hwndMenu == &FileMenu) {
1651 WinSetWindowUShort(FileMenu, QWS_ID, IDM_FILESMENU);
1652 SetConditionalCascade(FileMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1653 SetConditionalCascade(FileMenu, IDM_COPYMENU, IDM_COPY);
1654 SetConditionalCascade(FileMenu, IDM_MOVEMENU, IDM_MOVE);
1655 SetConditionalCascade(FileMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1656 SetConditionalCascade(FileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1657 SetConditionalCascade(FileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1658 SetConditionalCascade(FileMenu, IDM_COLLECTMENU, IDM_COLLECT);
1659 SetConditionalCascade(FileMenu, IDM_DELETESUBMENU,
1660 (fDefaultDeletePerm) ? IDM_PERMDELETE :
1661 IDM_DELETE);
1662 SetConditionalCascade(FileMenu, IDM_OPENSUBMENU, IDM_OPENDEFAULT);
1663 SetConditionalCascade(FileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1664 if (fWorkPlace) {
1665 WinSendMsg(FileMenu, MM_DELETEITEM,
1666 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1667 WinSendMsg(FileMenu, MM_DELETEITEM,
1668 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1669 }
1670 }
1671 else if (hwndMenu == &DirCnrMenu) {
1672 WinSetWindowUShort(DirCnrMenu, QWS_ID, IDM_VIEWSMENU);
1673 SetConditionalCascade(DirCnrMenu, IDM_MISCSUBMENU, IDM_SIZES);
1674 SetConditionalCascade(DirCnrMenu, IDM_OPENSUBMENU, IDM_OPENSETTINGSME);
1675 if (fWorkPlace)
1676 WinSendMsg(DirCnrMenu, MM_DELETEITEM,
1677 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1678 }
1679 else if (hwndMenu == &TreeCnrMenu) {
1680 WinSetWindowUShort(TreeCnrMenu, QWS_ID, IDM_VIEWSMENU);
1681 SetConditionalCascade(TreeCnrMenu, IDM_PARTITIONSMENU, IDM_PARTITION);
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.