source: trunk/dll/misc.c@ 771

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

Increase subject to 1024 reduce DosSleep times

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