source: trunk/dll/misc.c@ 859

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

Changed display logic so CommaFmtULL is used both with and without large file support for file size display. GiB notation can actually be selected in the source (in addition to being used automatically on very large drives).

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