source: trunk/dll/misc.c@ 688

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

Update History and file headers for CheckPmDrgLimit etc changes

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