source: trunk/dll/misc.c@ 1077

Last change on this file since 1077 was 1077, checked in by Steven Levine, 17 years ago

Enhance Fortify infrastructure
Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT support
Add more fm/2 Fortify tooling and rework existing tooling for correct nesting
Still lots to do for cross-thread allocations
Add misc.h
Add walkem.h

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