source: trunk/dll/misc.c@ 555

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

Added NTFS support (read only); minor dive icon code cleanup; update help files

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