source: trunk/dll/misc.c@ 877

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

Cleaned up actual fix for drop down menu fonts and colors not matching.

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