source: trunk/dll/misc.c@ 689

Last change on this file since 689 was 689, checked in by Steven Levine, 18 years ago

Commit OpenWatcom compatibility updates

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