source: trunk/dll/misc.c@ 552

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

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

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