source: trunk/dll/misc.c@ 796

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

Make subject column in dircnrs movable from one pane to the other; allow column to be sized truncating long subjects

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