source: trunk/dll/misc.c@ 787

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

Rework UM_FILLSETUPLIST IDM_SAVEDIRCNRSTATE and ..._setups() logic for ticket# 109 and #31
Add GetMSecTimer()
Use GetMSecTimer in DbgMsg
Tweak notebook.ipf scanning page
Move more #pragma alloc_text statements to end of files for OpenWatcom
Delete obsoletes
Revert ExpandAll() ShowTreeRec() DosSleeps to 0 - DosSleep(1) was slowing down inner loops
Drop afFilesToGet - use FilesToGet directly
Optimze ShowTreeRec() collapse logic - was really slow

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 63.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: misc.c 787 2007-08-19 21:02:37Z stevenhl $
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_CENTER;
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_CENTER | CFA_FITITLEREADONLY;
513 pfi->pTitleData = GetPString(IDS_LNAME);
514 pfi->offStruct = FIELDOFFSET(CNRITEM, pszLongName);
515
516 // Store the current pfi value as that will be used to indicate the
517 // last column in the lefthand container window (we have a splitbar)
518
519 pfiLastLeftCol = pfi;
520
521 // Fill in column info for subjects
522
523 pfi = pfi->pNextFieldInfo;
524 pfi->flData = CFA_STRING | CFA_LEFT | CFA_SEPARATOR;
525 if (isCompCnr)
526 pfi->flData |= CFA_FIREADONLY;
527 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
528 pfi->pTitleData = isCompCnr ? GetPString(IDS_STATUS) :
529 GetPString(IDS_SUBJ);
530 pfi->offStruct = FIELDOFFSET(CNRITEM, pszSubject);
531
532 // Fill in column information for the file size
533
534 pfi = pfi->pNextFieldInfo;
535 pfi->flData = CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
536 pfi->flTitle = CFA_CENTER;
537 pfi->pTitleData = GetPString(IDS_SIZE);
538 pfi->offStruct = FIELDOFFSET(CNRITEM, cbFile);
539
540 // Fill in the column information for the file's ea size
541
542 pfi = pfi->pNextFieldInfo;
543 pfi->flData = CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
544 pfi->flTitle = CFA_CENTER;
545 pfi->pTitleData = GetPString(IDS_EA);
546 pfi->offStruct = FIELDOFFSET(CNRITEM, easize);
547
548 // Fill in the column information for the file attribute
549
550 pfi = pfi->pNextFieldInfo;
551 pfi->flData = CFA_STRING | CFA_CENTER | CFA_SEPARATOR | CFA_FIREADONLY;
552 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
553 pfi->pTitleData = GetPString(IDS_ATTR);
554 pfi->offStruct = FIELDOFFSET(CNRITEM, pszDispAttr);
555
556 // Fill in column information for last write file date
557
558 pfi = pfi->pNextFieldInfo;
559 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
560 pfi->flTitle = CFA_CENTER;
561 pfi->pTitleData = GetPString(IDS_LWDATE);
562 pfi->offStruct = FIELDOFFSET(CNRITEM, date);
563
564 // Fill in column information for the last write file time
565
566 pfi = pfi->pNextFieldInfo;
567 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
568 pfi->flTitle = CFA_CENTER;
569 pfi->pTitleData = GetPString(IDS_LWTIME);
570 pfi->offStruct = FIELDOFFSET(CNRITEM, time);
571
572 // Fill in column information for last access file date
573
574 pfi = pfi->pNextFieldInfo;
575 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
576 pfi->flTitle = CFA_CENTER;
577 pfi->pTitleData = GetPString(IDS_LADATE);
578 pfi->offStruct = FIELDOFFSET(CNRITEM, ladate);
579
580 // Fill in column information for the last access file time
581
582 pfi = pfi->pNextFieldInfo;
583 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
584 pfi->flTitle = CFA_CENTER;
585 pfi->pTitleData = GetPString(IDS_LATIME);
586 pfi->offStruct = FIELDOFFSET(CNRITEM, latime);
587
588 // Fill in column information for create file date
589
590 pfi = pfi->pNextFieldInfo;
591 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
592 pfi->flTitle = CFA_CENTER;
593 pfi->pTitleData = GetPString(IDS_CRDATE);
594 pfi->offStruct = FIELDOFFSET(CNRITEM, crdate);
595
596 // Fill in column information for the create file time
597
598 pfi = pfi->pNextFieldInfo;
599 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_FIREADONLY;
600 pfi->flTitle = CFA_CENTER;
601 pfi->pTitleData = GetPString(IDS_CRTIME);
602 pfi->offStruct = FIELDOFFSET(CNRITEM, crtime);
603
604 // Use the CM_INSERTDETAILFIELDINFO message to tell the container
605 // all the column information it needs to function properly. Place
606 // this column info first in the column list and update the display
607 // after they are inserted (fInvalidateFieldInfo = TRUE)
608
609 (void)memset(&fii, 0, sizeof(FIELDINFOINSERT));
610
611 fii.cb = sizeof(FIELDINFOINSERT);
612 fii.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
613 fii.cFieldInfoInsert = (SHORT) CONTAINER_COLUMNS;
614 fii.fInvalidateFieldInfo = TRUE;
615
616 if (!WinSendMsg(hwndCnr, CM_INSERTDETAILFIELDINFO, MPFROMP(pfiFirst),
617 MPFROMP(&fii))) {
618 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_INSERTDETAILFIELDINFO");
619 fSuccess = FALSE;
620 }
621 }
622
623 if (fSuccess) {
624
625 CNRINFO cnri;
626 ULONG size;
627
628 // Tell the container about the splitbar and where it goes
629
630 cnri.cb = sizeof(CNRINFO);
631 cnri.pFieldInfoLast = pfiLastLeftCol;
632 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
633 cnri.pFieldInfoObject = pfiIconCol;
634 size = sizeof(LONG);
635 PrfQueryProfileData(fmprof,
636 appname, "CnrSplitBar", &cnri.xVertSplitbar, &size);
637 if (cnri.xVertSplitbar <= 0)
638 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
639 if (!WinSendMsg(hwndCnr, CM_SETCNRINFO, MPFROMP(&cnri),
640 MPFROMLONG(CMA_PFIELDINFOLAST | CMA_PFIELDINFOOBJECT |
641 CMA_XVERTSPLITBAR))) {
642 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_SETCNRINFO");
643 fSuccess = FALSE;
644 }
645 }
646
647 return fSuccess;
648}
649
650MRESULT CnrDirectEdit(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
651{
652 switch (SHORT2FROMMP(mp1)) {
653 case CN_BEGINEDIT:
654 if (mp2) {
655 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
656 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
657
658 if (pci &&
659 (INT) pci != -1 &&
660 !IsRoot(pci->pszFileName) &&
661 !(pci->flags & RECFLAGS_ENV) && !(pci->flags & RECFLAGS_UNDERENV)) {
662 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName)) {
663 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMP(pci->pszFileName), MPVOID);
664 }
665 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject))
666 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(40), MPVOID);
667 else
668 PostMsg(hwnd, UM_FIXCNRMLE, MPFROMLONG(CCHMAXPATH), MPVOID);
669 }
670 else
671 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
672 }
673 break;
674
675 case CN_REALLOCPSZ:
676 if (mp2) {
677 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
678 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
679 CHAR szData[CCHMAXPATH], testname[CCHMAXPATH];
680 HWND hwndMLE = WinWindowFromID(hwnd, CID_MLE);
681
682 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
683 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject)) {
684
685 APIRET rc;
686 EAOP2 eaop;
687 PFEA2LIST pfealist = NULL;
688 CHAR szSubject[1048];
689 ULONG ealen;
690 USHORT len;
691 CHAR *eaval;
692 LONG retlen;
693
694 retlen = WinQueryWindowText(hwndMLE, sizeof(szSubject), szSubject);
695 szSubject[retlen + 1] = 0;
696 //chop_at_crnl(szSubject);
697 bstrip(szSubject);
698 pci->pszSubject = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
699 WinSetWindowText(hwndMLE, szSubject);
700 len = strlen(szSubject);
701 if (len)
702 ealen = sizeof(FEA2LIST) + 9 + len + 4;
703 else
704 ealen = sizeof(FEALIST) + 9;
705 rc = DosAllocMem((PPVOID) & pfealist, ealen + 64,
706 OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
707 if (rc)
708 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile,
709 __LINE__, GetPString(IDS_OUTOFMEMORY));
710 else {
711 memset(pfealist, 0, ealen + 1);
712 pfealist->cbList = ealen;
713 pfealist->list[0].oNextEntryOffset = 0;
714 pfealist->list[0].fEA = 0;
715 pfealist->list[0].cbName = 8;
716 strcpy(pfealist->list[0].szName, SUBJECT);
717 if (len) {
718 eaval = pfealist->list[0].szName + 9;
719 *(USHORT *) eaval = (USHORT) EAT_ASCII;
720 eaval += sizeof(USHORT);
721 *(USHORT *) eaval = (USHORT) len;
722 eaval += sizeof(USHORT);
723 memcpy(eaval, szSubject, len);
724 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
725 }
726 else
727 pfealist->list[0].cbValue = 0;
728 eaop.fpGEA2List = (PGEA2LIST) 0;
729 eaop.fpFEA2List = pfealist;
730 eaop.oError = 0L;
731 rc = DosSetPathInfo(pci->pszFileName,
732 FIL_QUERYEASIZE,
733 (PVOID) & eaop, sizeof(EAOP2), DSPI_WRTTHRU);
734 DosFreeMem(pfealist);
735 if (rc)
736 return FALSE;
737 }
738 return (MRESULT) TRUE;
739 }
740 else if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszLongName)) {
741
742 CHAR longname[CCHMAXPATHCOMP];
743 LONG retlen;
744
745 *longname = 0;
746 retlen = WinQueryWindowText(hwndMLE, sizeof(longname), longname);
747 longname[retlen + 1] = 0;
748 //chop_at_crnl(longname);
749 pci->pszLongName = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
750 WinSetWindowText(hwndMLE, longname);
751 pci->pszFileName = xrealloc(pci->pszFileName, retlen + 1, pszSrcFile, __LINE__);
752 return (MRESULT) WriteLongName(pci->pszFileName, longname);
753 }
754 else {
755 WinQueryWindowText(hwndMLE, sizeof(szData), szData);
756 if (strchr(szData, '?') ||
757 strchr(szData, '*') || IsRoot(pci->pszFileName))
758 return (MRESULT) FALSE;
759 /* If the text changed, rename the file system object. */
760 chop_at_crnl(szData);
761 bstrip(szData);
762 if (!IsFullName(szData))
763 Runtime_Error(pszSrcFile, __LINE__, "bad name");
764 else {
765 if (DosQueryPathInfo(szData,
766 FIL_QUERYFULLNAME,
767 testname, sizeof(testname)))
768 return FALSE;
769 if (DosQueryPathInfo(pci->pszFileName,
770 FIL_QUERYFULLNAME, szData, sizeof(szData))){
771 pci->pszFileName = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__);
772 strcpy(szData, pci->pszFileName);
773 }
774 WinSetWindowText(hwndMLE, szData);
775 if (strcmp(szData, testname)) {
776 if (stricmp(szData, testname) && IsFile(testname) != -1) {
777 DosBeep(50, 100); /* exists; disallow */
778 return (MRESULT) FALSE;
779 }
780 if (docopyf(MOVE, szData, "%s", testname))
781 Runtime_Error(pszSrcFile, __LINE__, "docopyf");
782 else {
783 CHAR *filename;
784
785 filename = xstrdup(testname, pszSrcFile, __LINE__);
786 if (filename) {
787 if (!PostMsg(hwnd,
788 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
789 free(filename);
790 }
791 if (stricmp(testname, pci->pszFileName)) {
792 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci));
793 filename = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
794 if (filename) {
795 if (!PostMsg(hwnd,
796 UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
797 free(filename);
798 }
799 }
800 }
801 }
802 }
803 }
804 }
805 }
806 return FALSE;
807
808 case CN_ENDEDIT:
809 if (mp2) {
810 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
811 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
812
813 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
814 WinSendMsg(hwnd,
815 CM_INVALIDATERECORD,
816 MPFROMP(&pci),
817 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
818 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName))
819 PostMsg(hwnd, UM_SORTRECORD, MPVOID, MPVOID);
820 }
821 else {
822 USHORT cmd = 0;
823
824 if (!pfi || pfi->offStruct == FIELDOFFSET(CNRITEM, pszDisplayName))
825 cmd = IDM_SORTSMARTNAME;
826 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, cbFile))
827 cmd = IDM_SORTSIZE;
828 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, easize))
829 cmd = IDM_SORTEASIZE;
830 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, date))
831 cmd = IDM_SORTLWDATE;
832 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, time))
833 cmd = IDM_SORTLWDATE;
834 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, ladate))
835 cmd = IDM_SORTLADATE;
836 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, latime))
837 cmd = IDM_SORTLADATE;
838 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crdate))
839 cmd = IDM_SORTCRDATE;
840 else if (pfi->offStruct == FIELDOFFSET(CNRITEM, crtime))
841 cmd = IDM_SORTCRDATE;
842 if (cmd)
843 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
844 }
845 }
846 break;
847 }
848 return (MRESULT) - 1;
849}
850
851BOOL SetMenuCheck(HWND hwndMenu, USHORT id, BOOL * bool, BOOL toggle,
852 CHAR * savename)
853{
854 if (toggle) {
855 *bool = *bool ? FALSE : TRUE;
856 if (savename && *savename)
857 PrfWriteProfileData(fmprof, appname, savename, bool, sizeof(BOOL));
858 }
859 WinSendMsg(hwndMenu, MM_SETITEMATTR,
860 MPFROM2SHORT(id, 1),
861 MPFROM2SHORT(MIA_CHECKED, (*bool ? MIA_CHECKED : 0)));
862 return *bool;
863}
864
865//== disable_menuitem() disable or enable_menuitem ==
866
867VOID disable_menuitem(HWND hwndMenu, USHORT id, BOOL disable)
868{
869 WinSendMsg(hwndMenu, MM_SETITEMATTR,
870 MPFROM2SHORT(id, TRUE),
871 MPFROM2SHORT(MIA_DISABLED, (disable ? MIA_DISABLED : 0)));
872}
873
874//== ViewHelp() invoke view.exe, return TRUE if OK ==
875
876BOOL ViewHelp(CHAR * filename)
877{
878 CHAR s[CCHMAXPATH + 81];
879 FILE *fp;
880 INT ret = -1;
881
882 fp = _fsopen(filename, "rb", SH_DENYNO);
883 if (fp) {
884 *s = 0;
885 fread(s, 1, 3, fp);
886 if (*s != 'H' || s[1] != 'S' || s[2] != 'P') {
887 fclose(fp);
888 return FALSE;
889 }
890 fclose(fp);
891 ret = runemf2(SEPARATE | WINDOWED, HWND_DESKTOP, NULL, NULL,
892 "VIEW.EXE \"%s\"", filename);
893 }
894
895 return (ret != -1);
896}
897
898//== ExecFile() run file, return 1 if OK 0 if skipped -1 if can't run ==
899
900INT ExecFile(HWND hwnd, CHAR * filename)
901{
902 EXECARGS ex;
903 CHAR cl[1001], path[CCHMAXPATH], *p;
904 APIRET ret;
905 static INT lastflags = 0;
906
907 strcpy(path, filename);
908 p = strrchr(path, '\\');
909 if (!p)
910 p = strrchr(path, ':');
911 if (p) {
912 if (*p == ':') {
913 p++;
914 *p = '\\';
915 p++;
916 }
917 *p = 0;
918 }
919 else
920 *path = 0;
921 *cl = 0;
922 BldQuotedFileName(cl, filename);
923 // *cl = 0;
924 // if (needs_quoting(filename))
925 // strcat(cl, "\"");
926 // strcat(cl, filename);
927 // if (needs_quoting(filename))
928 // strcat(cl, "\"");
929 memset(&ex, 0, sizeof(ex));
930 ex.flags = lastflags;
931 ex.commandline = cl;
932 *ex.path = 0;
933 *ex.environment = 0;
934 ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
935 EXEC_FRAME, &ex);
936 if (ret == 1) {
937 lastflags = ex.flags;
938 return runemf2(ex.flags, hwnd, path,
939 *ex.environment ? ex.environment : NULL,
940 "%s", cl) != -1;
941 }
942 else if (ret != 0)
943 return -1;
944 return 0;
945}
946
947VOID SetDetailsSwitches(HWND hwnd, DIRCNRDATA * dcd)
948{
949 WinCheckMenuItem(hwnd, IDM_SHOWLNAMES,
950 dcd ? dcd->detailslongname : detailslongname);
951 WinCheckMenuItem(hwnd, IDM_SHOWSUBJECT,
952 dcd ? dcd->detailssubject : detailssubject);
953 WinCheckMenuItem(hwnd, IDM_SHOWEAS, dcd ? dcd->detailsea : detailsea);
954 WinCheckMenuItem(hwnd, IDM_SHOWSIZE,
955 dcd ? dcd->detailssize : detailssize);
956 WinCheckMenuItem(hwnd, IDM_SHOWICON,
957 dcd ? dcd->detailsicon : detailsicon);
958 WinCheckMenuItem(hwnd, IDM_SHOWLWDATE,
959 dcd ? dcd->detailslwdate : detailslwdate);
960 WinCheckMenuItem(hwnd, IDM_SHOWLWTIME,
961 dcd ? dcd->detailslwtime : detailslwtime);
962 WinCheckMenuItem(hwnd, IDM_SHOWLADATE,
963 dcd ? dcd->detailsladate : detailsladate);
964 WinCheckMenuItem(hwnd, IDM_SHOWLATIME,
965 dcd ? dcd->detailslatime : detailslatime);
966 WinCheckMenuItem(hwnd, IDM_SHOWCRDATE,
967 dcd ? dcd->detailscrdate : detailscrdate);
968 WinCheckMenuItem(hwnd, IDM_SHOWCRTIME,
969 dcd ? dcd->detailscrtime : detailscrtime);
970 WinCheckMenuItem(hwnd, IDM_SHOWATTR,
971 dcd ? dcd->detailsattr : detailsattr);
972}
973
974VOID AdjustDetailsSwitches(HWND hwnd, HWND hwndMenu, USHORT cmd,
975 CHAR * directory, CHAR * keyroot,
976 DIRCNRDATA * dcd, BOOL compare)
977{
978 CHAR s[CCHMAXPATH], *eos = s;
979 BOOL *bool = NULL;
980
981 *s = 0;
982 if (keyroot) {
983 strcpy(s, keyroot);
984 strcat(s, ".");
985 eos = &s[strlen(s)];
986 }
987 switch (cmd) {
988 case IDM_SHOWLNAMES:
989 bool = dcd ? &dcd->detailslongname : &detailslongname;
990 strcpy(eos, "DetailsLongname");
991 break;
992 case IDM_SHOWSUBJECT:
993 bool = dcd ? &dcd->detailssubject : &detailssubject;
994 strcpy(eos, "DetailsSubject");
995 break;
996 case IDM_SHOWEAS:
997 bool = dcd ? &dcd->detailsea : &detailsea;
998 strcpy(eos, "DetailsEA");
999 break;
1000 case IDM_SHOWSIZE:
1001 bool = dcd ? &dcd->detailssize : &detailssize;
1002 strcpy(eos, "DetailsSize");
1003 break;
1004 case IDM_SHOWICON:
1005 bool = dcd ? &dcd->detailsicon : &detailsicon;
1006 strcpy(eos, "DetailsIcon");
1007 break;
1008 case IDM_SHOWLWDATE:
1009 bool = dcd ? &dcd->detailslwdate : &detailslwdate;
1010 strcpy(eos, "DetailsLWDate");
1011 break;
1012 case IDM_SHOWLWTIME:
1013 bool = dcd ? &dcd->detailslwtime : &detailslwtime;
1014 strcpy(eos, "DetailsLWTime");
1015 break;
1016 case IDM_SHOWLADATE:
1017 bool = dcd ? &dcd->detailsladate : &detailsladate;
1018 strcpy(eos, "DetailsLADate");
1019 break;
1020 case IDM_SHOWLATIME:
1021 bool = dcd ? &dcd->detailslatime : &detailslatime;
1022 strcpy(eos, "DetailsLATime");
1023 break;
1024 case IDM_SHOWCRDATE:
1025 bool = dcd ? &dcd->detailscrdate : &detailscrdate;
1026 strcpy(eos, "DetailsCRDate");
1027 break;
1028 case IDM_SHOWCRTIME:
1029 bool = dcd ? &dcd->detailscrtime : &detailscrtime;
1030 strcpy(eos, "DetailsCRTime");
1031 break;
1032 case IDM_SHOWATTR:
1033 bool = dcd ? &dcd->detailsattr : &detailsattr;
1034 strcpy(eos, "DetailsAttr");
1035 break;
1036 default:
1037 if (hwndMenu)
1038 SetDetailsSwitches(hwndMenu, dcd);
1039 return;
1040 }
1041 if (bool)
1042 *bool = *bool ? FALSE : TRUE;
1043 if (*s && bool)
1044 PrfWriteProfileData(fmprof, appname, s, bool, sizeof(BOOL));
1045 if (hwnd)
1046 AdjustCnrColsForPref(hwnd, directory, dcd, compare);
1047 if (hwndMenu)
1048 SetDetailsSwitches(hwndMenu, dcd);
1049}
1050
1051VOID SetConditionalCascade(HWND hwndMenu, USHORT id, USHORT def)
1052{
1053 MENUITEM mi;
1054
1055 mi.iPosition = MIT_END;
1056 mi.hItem = 0L;
1057 mi.hwndSubMenu = (HWND) 0;
1058 mi.afAttribute = 0;
1059 mi.afStyle = MIS_TEXT;
1060 if (WinSendMsg
1061 (hwndMenu, MM_QUERYITEM, MPFROM2SHORT(id, TRUE), MPFROMP(&mi))) {
1062 WinSetWindowBits(mi.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE,
1063 MS_CONDITIONALCASCADE);
1064 WinSendMsg(mi.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(def), MPVOID);
1065 WinCheckMenuItem(mi.hwndSubMenu, def, TRUE);
1066 }
1067}
1068
1069VOID SetSortChecks(HWND hwndMenu, INT sortflags)
1070{
1071 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, FALSE);
1072 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, FALSE);
1073 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, FALSE);
1074 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, FALSE);
1075 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, FALSE);
1076 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, FALSE);
1077 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, FALSE);
1078 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, FALSE);
1079 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, FALSE);
1080 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, FALSE);
1081 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, FALSE);
1082 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, FALSE);
1083 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, FALSE);
1084 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, FALSE);
1085 if (sortflags & SORT_FIRSTEXTENSION)
1086 WinCheckMenuItem(hwndMenu, IDM_SORTFIRST, TRUE);
1087 else if (sortflags & SORT_LASTEXTENSION)
1088 WinCheckMenuItem(hwndMenu, IDM_SORTLAST, TRUE);
1089 else if (sortflags & SORT_SIZE)
1090 WinCheckMenuItem(hwndMenu, IDM_SORTSIZE, TRUE);
1091 else if (sortflags & SORT_EASIZE)
1092 WinCheckMenuItem(hwndMenu, IDM_SORTEASIZE, TRUE);
1093 else if (sortflags & SORT_LWDATE)
1094 WinCheckMenuItem(hwndMenu, IDM_SORTLWDATE, TRUE);
1095 else if (sortflags & SORT_LADATE)
1096 WinCheckMenuItem(hwndMenu, IDM_SORTLADATE, TRUE);
1097 else if (sortflags & SORT_CRDATE)
1098 WinCheckMenuItem(hwndMenu, IDM_SORTCRDATE, TRUE);
1099 else if (sortflags & SORT_FILENAME)
1100 WinCheckMenuItem(hwndMenu, IDM_SORTFILENAME, TRUE);
1101 else if (sortflags & SORT_NOSORT)
1102 WinCheckMenuItem(hwndMenu, IDM_SORTNONE, TRUE);
1103 else if (sortflags & SORT_SUBJECT)
1104 WinCheckMenuItem(hwndMenu, IDM_SORTSUBJECT, TRUE);
1105 else
1106 WinCheckMenuItem(hwndMenu, IDM_SORTNAME, TRUE);
1107 if (sortflags & SORT_DIRSFIRST)
1108 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSFIRST, TRUE);
1109 else if (sortflags & SORT_DIRSLAST)
1110 WinCheckMenuItem(hwndMenu, IDM_SORTDIRSLAST, TRUE);
1111 if (sortflags & SORT_REVERSE)
1112 WinCheckMenuItem(hwndMenu, IDM_SORTREVERSE, TRUE);
1113}
1114
1115VOID FcloseFile(FILE * fp)
1116{
1117 /* for use by apps that don't use the DLLs runtime library */
1118 fclose(fp);
1119}
1120
1121VOID SetupCommandMenu(HWND hwndMenu, HWND hwndCnr)
1122{
1123 MENUITEM mi, mit;
1124 INT x;
1125 SHORT numitems;
1126 LINKCMDS *info;
1127
1128 if (!cmdloaded)
1129 load_commands();
1130 mi.iPosition = MIT_END;
1131 mi.hwndSubMenu = (HWND) 0;
1132 mi.hItem = 0L;
1133 mi.afAttribute = 0;
1134 mi.afStyle = MIS_TEXT;
1135 memset(&mit, 0, sizeof(MENUITEM));
1136 if (WinQueryWindowUShort(hwndMenu, QWS_ID) == IDM_COMMANDSMENU)
1137 mit.hwndSubMenu = hwndMenu;
1138 else
1139 WinSendMsg(hwndMenu, MM_QUERYITEM,
1140 MPFROM2SHORT(IDM_COMMANDSMENU, TRUE), MPFROMP(&mit));
1141 if (mit.hwndSubMenu) {
1142 numitems = (SHORT) WinSendMsg(mit.hwndSubMenu, MM_QUERYITEMCOUNT,
1143 MPVOID, MPVOID);
1144 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM, MPFROMSHORT(-1), MPVOID);
1145 for (x = 0; x < numitems; x++)
1146 WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
1147 MPFROMSHORT((SHORT) (x + IDM_COMMANDSTART)), MPVOID);
1148 if (hwndCnr && cmdhead) {
1149 x = 0;
1150 info = cmdhead;
1151 while (info) {
1152
1153 CHAR s[CCHMAXPATH + 24];
1154
1155 sprintf(s,
1156 "%s%s%s",
1157 info->title,
1158 x < 20 ? "\tCtrl + " : NullStr,
1159 x < 20 && x > 9 ? "Shift + " : NullStr);
1160 if (x < 20)
1161 sprintf(&s[strlen(s)], "%d",
1162 ((x % 10) + 1) == 10 ? 0 : (x % 10) + 1);
1163 mi.id = IDM_COMMANDSTART + x;
1164 mi.afAttribute = (info->flags & ONCE ? MIA_CHECKED : 0) |
1165 (info->flags & PROMPT ? MIA_FRAMED : 0);
1166 mi.afStyle = MIS_TEXT;
1167 if (!(x % 24) && x && info->next)
1168 mi.afStyle |= MIS_BREAK;
1169 WinSendMsg(mit.hwndSubMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(s));
1170 x++;
1171 info = info->next;
1172 }
1173 }
1174 }
1175}
1176
1177VOID LoadDetailsSwitches(CHAR * keyroot, DIRCNRDATA * dcd)
1178{
1179 ULONG size;
1180 CHAR s[CCHMAXPATH], *eos = s;
1181 BOOL *bool;
1182
1183 *s = 0;
1184 if (keyroot) {
1185 strcpy(s, keyroot);
1186 strcat(s, ".");
1187 eos = &s[strlen(s)];
1188 }
1189 strcpy(eos, "DetailsLongname");
1190 if (dcd)
1191 bool = &dcd->detailslongname;
1192 else
1193 bool = &detailslongname;
1194 *bool = detailslongname;
1195 size = sizeof(BOOL);
1196 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1197 strcpy(eos, "DetailsSubject");
1198 if (dcd)
1199 bool = &dcd->detailssubject;
1200 else
1201 bool = &detailssubject;
1202 *bool = detailssubject;
1203 size = sizeof(BOOL);
1204 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1205 strcpy(eos, "DetailsEA");
1206 if (dcd)
1207 bool = &dcd->detailsea;
1208 else
1209 bool = &detailsea;
1210 *bool = detailsea;
1211 size = sizeof(BOOL);
1212 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1213 strcpy(eos, "DetailsSize");
1214 if (dcd)
1215 bool = &dcd->detailssize;
1216 else
1217 bool = &detailssize;
1218 *bool = detailssize;
1219 size = sizeof(BOOL);
1220 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1221 strcpy(eos, "DetailsIcon");
1222 if (dcd)
1223 bool = &dcd->detailsicon;
1224 else
1225 bool = &detailsicon;
1226 *bool = detailsicon;
1227 size = sizeof(BOOL);
1228 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1229 strcpy(eos, "DetailsAttr");
1230 if (dcd)
1231 bool = &dcd->detailsattr;
1232 else
1233 bool = &detailsattr;
1234 *bool = detailsattr;
1235 size = sizeof(BOOL);
1236 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1237 strcpy(eos, "DetailsCRDate");
1238 if (dcd)
1239 bool = &dcd->detailscrdate;
1240 else
1241 bool = &detailscrdate;
1242 *bool = detailscrdate;
1243 size = sizeof(BOOL);
1244 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1245 strcpy(eos, "DetailsCRTime");
1246 if (dcd)
1247 bool = &dcd->detailscrtime;
1248 else
1249 bool = &detailscrtime;
1250 *bool = detailscrtime;
1251 size = sizeof(BOOL);
1252 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1253 strcpy(eos, "DetailsLWDate");
1254 if (dcd)
1255 bool = &dcd->detailslwdate;
1256 else
1257 bool = &detailslwdate;
1258 *bool = detailslwdate;
1259 size = sizeof(BOOL);
1260 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1261 strcpy(eos, "DetailsLWTime");
1262 if (dcd)
1263 bool = &dcd->detailslwtime;
1264 else
1265 bool = &detailslwtime;
1266 *bool = detailslwtime;
1267 size = sizeof(BOOL);
1268 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1269 strcpy(eos, "DetailsLADate");
1270 if (dcd)
1271 bool = &dcd->detailsladate;
1272 else
1273 bool = &detailsladate;
1274 *bool = detailsladate;
1275 size = sizeof(BOOL);
1276 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1277 strcpy(eos, "DetailsLATime");
1278 if (dcd)
1279 bool = &dcd->detailslatime;
1280 else
1281 bool = &detailslatime;
1282 *bool = detailslatime;
1283 size = sizeof(BOOL);
1284 PrfQueryProfileData(fmprof, appname, s, (PVOID) bool, &size);
1285}
1286
1287HWND FindDirCnr(HWND hwndParent)
1288{
1289 HWND found, hwndDir = (HWND) 0;
1290 HENUM henum;
1291
1292 henum = WinBeginEnumWindows(hwndParent);
1293 while ((found = WinGetNextWindow(henum)) != NULLHANDLE) {
1294 hwndDir = WinWindowFromID(found, FID_CLIENT);
1295 if (hwndDir) {
1296 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
1297 if (hwndDir)
1298 break;
1299 hwndDir = (HWND) 0;
1300 }
1301 }
1302 WinEndEnumWindows(henum);
1303
1304 return hwndDir;
1305}
1306
1307VOID HeapThread(VOID * dummy)
1308{
1309 ULONG postcount;
1310 APIRET rc;
1311
1312 rc = DosCreateEventSem(NULL, &CompactSem, 0L, FALSE);
1313 if (rc)
1314 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1315 "DosCreateEventSem");
1316 else {
1317 priority_normal();
1318 for (;;) {
1319 if (DosWaitEventSem(CompactSem, SEM_INDEFINITE_WAIT))
1320 break;
1321 _heapmin();
1322 DosResetEventSem(CompactSem, &postcount);
1323 }
1324 }
1325}
1326
1327VOID FixSwitchList(HWND hwnd, CHAR * text)
1328{
1329 HSWITCH hswitch;
1330 SWCNTRL swctl;
1331
1332 hswitch = WinQuerySwitchHandle(hwnd, 0);
1333 if (hswitch) {
1334 if (!WinQuerySwitchEntry(hswitch, &swctl)) {
1335 strcpy(swctl.szSwtitle, "FM/2");
1336 WinChangeSwitchEntry(hswitch, &swctl);
1337 }
1338 }
1339}
1340
1341VOID QuickPopup(HWND hwnd, DIRCNRDATA * dcd, HWND hwndMenu, USHORT id)
1342{
1343 dcd->hwndLastMenu = hwndMenu;
1344 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
1345 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1346 MPFROM2SHORT(TRUE, CRA_SOURCE));
1347 dcd->cnremphasized = TRUE;
1348 }
1349 if (dcd->flWindowAttr & CV_MINI)
1350 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
1351 if (!WinPopupMenu(hwnd, hwnd, dcd->hwndLastMenu,
1352 8, 8, 0,
1353 PU_HCONSTRAIN | PU_VCONSTRAIN |
1354 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
1355 if (dcd->cnremphasized) {
1356 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1357 MPFROM2SHORT(FALSE, CRA_SOURCE));
1358 dcd->cnremphasized = FALSE;
1359 }
1360 }
1361 else
1362 WinSendMsg(dcd->hwndLastMenu, MM_SELECTITEM,
1363 MPFROM2SHORT(id, TRUE), MPFROM2SHORT(0, FALSE));
1364}
1365
1366PMINIRECORDCORE CurrentRecord(HWND hwndCnr)
1367{
1368 SHORT attrib = fSelectedAlways ? CRA_SELECTED : CRA_CURSORED;
1369 PMINIRECORDCORE pmi;
1370
1371 for (;;) {
1372 pmi = (PMINIRECORDCORE) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
1373 MPFROMLONG(CMA_FIRST),
1374 MPFROMSHORT(attrib));
1375 if ((!pmi || (INT) pmi == -1) && attrib == CRA_SELECTED) /* punt */
1376 attrib = CRA_CURSORED;
1377 else
1378 break;
1379 }
1380 return ((INT)pmi == -1) ? NULL : pmi;
1381}
1382
1383BOOL PostMsg(HWND h, ULONG msg, MPARAM mp1, MPARAM mp2)
1384{
1385 BOOL rc = WinPostMsg(h, msg, mp1, mp2);
1386
1387 if (!rc) {
1388
1389 // If window owned by some other process or some other thread?
1390 if (!IsFm2Window(h, 1)) {
1391 QMSG qmsg;
1392 for (;;) {
1393 DosSleep(1);
1394 rc = WinPostMsg(h, msg, mp1, mp2);
1395 if (rc)
1396 break; // OK
1397 if (!WinIsWindow((HAB) 0, h))
1398 break; // Window gone
1399 if (WinPeekMsg((HAB) 0, &qmsg, (HWND) 0, 0, 0, PM_NOREMOVE))
1400 break; // Queue has message(s)
1401 } // for
1402 }
1403 }
1404 return rc;
1405}
1406
1407VOID OpenEdit(HWND hwnd)
1408{
1409 CNREDITDATA ced;
1410 PCNRITEM pci;
1411 PFIELDINFO pfi;
1412
1413 pci = (PCNRITEM) WinSendMsg(hwnd,
1414 CM_QUERYRECORDEMPHASIS,
1415 MPFROMLONG(CMA_FIRST),
1416 MPFROMSHORT(CRA_CURSORED));
1417 if (pci && (INT) pci != -1) {
1418 memset(&ced, 0, sizeof(ced));
1419 ced.cb = sizeof(ced);
1420 ced.hwndCnr = hwnd;
1421 ced.id = WinQueryWindowUShort(hwnd, QWS_ID);
1422 ced.pRecord = (PRECORDCORE) pci;
1423 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1424 CM_QUERYDETAILFIELDINFO,
1425 MPVOID, MPFROMSHORT(CMA_FIRST));
1426 if (!pfi)
1427 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1428 else {
1429 while (pfi && (INT) pfi != -1 &&
1430 pfi->offStruct != FIELDOFFSET(CNRITEM, pszFileName))
1431 pfi = (PFIELDINFO) WinSendMsg(hwnd,
1432 CM_QUERYDETAILFIELDINFO,
1433 MPFROMP(pfi), MPFROMSHORT(CMA_NEXT));
1434 if (pfi && (INT) pfi != -1) {
1435 ced.pFieldInfo = pfi;
1436 {
1437 CNRINFO cnri;
1438
1439 memset(&cnri, 0, sizeof(CNRINFO));
1440 cnri.cb = sizeof(CNRINFO);
1441 WinSendMsg(hwnd,
1442 CM_QUERYCNRINFO,
1443 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1444 if (cnri.flWindowAttr & CV_DETAIL)
1445 ced.id = CID_LEFTDVWND;
1446 }
1447 WinSendMsg(hwnd, CM_OPENEDIT, MPFROMP(&ced), MPVOID);
1448 }
1449 }
1450 }
1451}
1452
1453#ifdef NEVER
1454VOID QuickView(HWND hwnd, CHAR * filename)
1455{
1456 if (filename && IsFile(filename) == 1) {
1457 if (TestBinary(filename) && *binview) {
1458
1459 CHAR *list[2];
1460
1461 list[0] = filename;
1462 list[1] = NULL;
1463 ExecOnList(hwnd, binview, WINDOWED | SEPARATE, NULL, list, NULL);
1464 return;
1465 }
1466 else if (*viewer) {
1467
1468 CHAR *list[2];
1469
1470 list[0] = filename;
1471 list[1] = NULL;
1472 ExecOnList(hwnd, viewer,
1473 WINDOWED | SEPARATE | (fViewChild ? CHILD : 0),
1474 NULL, list, NULL);
1475 return;
1476 }
1477 StartMLEEditor(HWND_DESKTOP, 5, filename, (HWND) 0);
1478 }
1479}
1480
1481VOID QuickEdit(HWND hwnd, CHAR * filename)
1482{
1483 if (filename && IsFile(filename) == 1) {
1484 if (TestBinary(filename) && *bined) {
1485
1486 CHAR *list[2];
1487
1488 list[0] = filename;
1489 list[1] = NULL;
1490 ExecOnList(hwnd, bined, WINDOWED | SEPARATE, NULL, list, NULL);
1491 return;
1492 }
1493 else if (*editor) {
1494
1495 CHAR *list[2];
1496
1497 list[0] = filename;
1498 list[1] = NULL;
1499 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, list, NULL);
1500 return;
1501 }
1502 StartMLEEditor(HWND_DESKTOP, 4, filename, (HWND) 0);
1503 }
1504}
1505#endif
1506
1507VOID PortholeInit(HWND hwndNew, MPARAM mp1, MPARAM mp2)
1508{
1509 static HWND DefMenu = (HWND) 0;
1510 HWND hwndMenu = (HWND) mp2;
1511
1512 {
1513 ULONG style;
1514
1515 style = WinQueryWindowULong(hwndMenu, QWL_STYLE);
1516 if (!(style & MS_ACTIONBAR))
1517 return;
1518 }
1519
1520 switch (SHORT1FROMMP(mp1)) {
1521 case 0:
1522 {
1523 HWND hwndNow;
1524 MENUITEM mi;
1525 ULONG ulStyle;
1526
1527 memset(&mi, 0, sizeof(mi));
1528 mi.iPosition = MIT_END;
1529 mi.afStyle = MIS_TEXT;
1530 WinSendMsg(hwndMenu, MM_QUERYITEM,
1531 MPFROM2SHORT(IDM_FILESMENU, TRUE), MPFROMP(&mi));
1532 if (!DefMenu)
1533 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1534 hwndNow = mi.hwndSubMenu;
1535 mi.hwndSubMenu = hwndNew;
1536 if (!mi.hwndSubMenu)
1537 mi.hwndSubMenu = DefMenu;
1538 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1539 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1540 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1541 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1542 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_FILESMENU);
1543 mi.afStyle = MIS_SUBMENU;
1544 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1545 ulStyle &= -WS_SAVEBITS;
1546 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1547 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1548 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1549 }
1550 break;
1551
1552 case 1:
1553 {
1554 HWND hwndNow;
1555 MENUITEM mi;
1556 ULONG ulStyle;
1557
1558 memset(&mi, 0, sizeof(mi));
1559 mi.iPosition = MIT_END;
1560 mi.afStyle = MIS_TEXT;
1561 WinSendMsg(hwndMenu, MM_QUERYITEM,
1562 MPFROM2SHORT(IDM_VIEWSMENU, TRUE), MPFROMP(&mi));
1563 if (!DefMenu)
1564 DefMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, DEFMENU);
1565 hwndNow = mi.hwndSubMenu;
1566 mi.hwndSubMenu = hwndNew;
1567 if (!mi.hwndSubMenu)
1568 mi.hwndSubMenu = DefMenu;
1569 WinSetParent(hwndNow, WinQueryObjectWindow(HWND_DESKTOP), FALSE);
1570 WinSetOwner(hwndNow, WinQueryObjectWindow(HWND_DESKTOP));
1571 WinSetOwner(mi.hwndSubMenu, hwndMenu);
1572 WinSetParent(mi.hwndSubMenu, hwndMenu, FALSE);
1573 WinSetWindowUShort(mi.hwndSubMenu, QWS_ID, IDM_VIEWSMENU);
1574 mi.afStyle = MIS_SUBMENU;
1575 ulStyle = WinQueryWindowULong(mi.hwndSubMenu, QWL_STYLE);
1576 ulStyle &= -WS_SAVEBITS;
1577 ulStyle |= MS_POPUP | WS_CLIPSIBLINGS | WS_SAVEBITS;
1578 WinSetWindowULong(mi.hwndSubMenu, QWL_STYLE, ulStyle);
1579 WinSendMsg(hwndMenu, MM_SETITEM, MPFROM2SHORT(0, TRUE), MPFROMP(&mi));
1580 }
1581 break;
1582 }
1583}
1584
1585HWND CheckMenu(HWND * hwndMenu, USHORT id)
1586{
1587 /* load and adjust menus as required */
1588 if (!*hwndMenu || !WinIsWindow((HAB) 0, *hwndMenu)) {
1589 *hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1590 if (hwndMenu == &DirMenu) {
1591 WinSetWindowUShort(DirMenu, QWS_ID, IDM_FILESMENU);
1592 SetConditionalCascade(DirMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1593 SetConditionalCascade(DirMenu, IDM_COPYMENU, IDM_COPY);
1594 SetConditionalCascade(DirMenu, IDM_MOVEMENU, IDM_MOVE);
1595 SetConditionalCascade(DirMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1596 SetConditionalCascade(DirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1597 SetConditionalCascade(DirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1598 SetConditionalCascade(DirMenu, IDM_DELETESUBMENU,
1599 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1600 SetConditionalCascade(DirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1601 SetConditionalCascade(DirMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1602 if (fWorkPlace) {
1603 WinSendMsg(DirMenu, MM_DELETEITEM,
1604 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1605 WinSendMsg(DirMenu, MM_DELETEITEM,
1606 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1607 }
1608 }
1609 else if (hwndMenu == &TreeMenu) {
1610 WinSetWindowUShort(TreeMenu, QWS_ID, IDM_FILESMENU);
1611 SetConditionalCascade(TreeMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1612 SetConditionalCascade(TreeMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1613 SetConditionalCascade(TreeMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1614 SetConditionalCascade(TreeMenu, IDM_EXPANDSUBMENU, IDM_EXPAND);
1615 SetConditionalCascade(TreeMenu, IDM_MISCSUBMENU, IDM_SIZES);
1616 SetConditionalCascade(TreeMenu, IDM_OPENSUBMENU, IDM_OPENWINDOW);
1617 if (fWorkPlace) {
1618 WinSendMsg(TreeMenu, MM_DELETEITEM,
1619 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1620 WinSendMsg(TreeMenu, MM_DELETEITEM,
1621 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1622 }
1623 }
1624 else if (hwndMenu == &ArcMenu) {
1625 WinSetWindowUShort(ArcMenu, QWS_ID, IDM_FILESMENU);
1626 SetConditionalCascade(ArcMenu, IDM_EXTRACTSUBMENU, IDM_EXTRACT);
1627 SetConditionalCascade(ArcMenu, IDM_EDITSUBMENU, IDM_EDIT);
1628 SetConditionalCascade(ArcMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1629 if (fWorkPlace)
1630 WinSendMsg(ArcMenu, MM_DELETEITEM,
1631 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1632 }
1633 else if (hwndMenu == &FileMenu) {
1634 WinSetWindowUShort(FileMenu, QWS_ID, IDM_FILESMENU);
1635 SetConditionalCascade(FileMenu, IDM_COMMANDSMENU, IDM_DOITYOURSELF);
1636 SetConditionalCascade(FileMenu, IDM_COPYMENU, IDM_COPY);
1637 SetConditionalCascade(FileMenu, IDM_MOVEMENU, IDM_MOVE);
1638 SetConditionalCascade(FileMenu, IDM_SAVESUBMENU, IDM_SAVETOCLIP);
1639 SetConditionalCascade(FileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1640 SetConditionalCascade(FileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1641 SetConditionalCascade(FileMenu, IDM_COLLECTMENU, IDM_COLLECT);
1642 SetConditionalCascade(FileMenu, IDM_DELETESUBMENU,
1643 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1644 SetConditionalCascade(FileMenu, IDM_OPENSUBMENU, IDM_OPENDEFAULT);
1645 SetConditionalCascade(FileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1646 if (fWorkPlace) {
1647 WinSendMsg(FileMenu, MM_DELETEITEM,
1648 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1649 WinSendMsg(FileMenu, MM_DELETEITEM,
1650 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1651 }
1652 }
1653 else if (hwndMenu == &DirCnrMenu) {
1654 WinSetWindowUShort(DirCnrMenu, QWS_ID, IDM_VIEWSMENU);
1655 SetConditionalCascade(DirCnrMenu, IDM_MISCSUBMENU, IDM_SIZES);
1656 SetConditionalCascade(DirCnrMenu, IDM_OPENSUBMENU, IDM_OPENSETTINGSME);
1657 if (fWorkPlace)
1658 WinSendMsg(DirCnrMenu, MM_DELETEITEM,
1659 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1660 }
1661 else if (hwndMenu == &TreeCnrMenu) {
1662 WinSetWindowUShort(TreeCnrMenu, QWS_ID, IDM_VIEWSMENU);
1663 SetConditionalCascade(TreeCnrMenu, IDM_PARTITIONSMENU, IDM_PARTITION);
1664 }
1665 else if (hwndMenu == &ArcCnrMenu) {
1666 WinSetWindowUShort(ArcCnrMenu, QWS_ID, IDM_VIEWSMENU);
1667 SetConditionalCascade(ArcCnrMenu, IDM_EXTRACTSUBMENU, IDM_ARCEXTRACT);
1668 if (fWorkPlace)
1669 WinSendMsg(ArcCnrMenu, MM_DELETEITEM,
1670 MPFROM2SHORT(IDM_FOLDERAFTEREXTRACT, TRUE), MPVOID);
1671 }
1672 else if (hwndMenu == &CollectorCnrMenu) {
1673 WinSetWindowUShort(CollectorCnrMenu, QWS_ID, IDM_VIEWSMENU);
1674 SetConditionalCascade(CollectorCnrMenu, IDM_COLLECTMENU,
1675 IDM_COLLECTFROMCLIP);
1676 }
1677 else if (hwndMenu == &CollectorFileMenu) {
1678 WinSetWindowUShort(CollectorFileMenu, QWS_ID, IDM_FILESMENU);
1679 SetConditionalCascade(CollectorFileMenu, IDM_COMMANDSMENU,
1680 IDM_DOITYOURSELF);
1681 SetConditionalCascade(CollectorFileMenu, IDM_COPYMENU, IDM_COPY);
1682 SetConditionalCascade(CollectorFileMenu, IDM_MOVEMENU, IDM_MOVE);
1683 SetConditionalCascade(CollectorFileMenu, IDM_SAVESUBMENU,
1684 IDM_SAVETOCLIP);
1685 SetConditionalCascade(CollectorFileMenu, IDM_VIEWSUBMENU, IDM_VIEW);
1686 SetConditionalCascade(CollectorFileMenu, IDM_EDITSUBMENU, IDM_EDIT);
1687 SetConditionalCascade(CollectorFileMenu, IDM_DELETESUBMENU,
1688 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1689 SetConditionalCascade(CollectorFileMenu, IDM_OPENSUBMENU,
1690 IDM_OPENDEFAULT);
1691 SetConditionalCascade(CollectorFileMenu, IDM_OBJECTSUBMENU, IDM_SHADOW);
1692 if (fWorkPlace) {
1693 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1694 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1695 WinSendMsg(CollectorFileMenu, MM_DELETEITEM,
1696 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1697 }
1698 }
1699 else if (hwndMenu == &CollectorDirMenu) {
1700 WinSetWindowUShort(CollectorDirMenu, QWS_ID, IDM_FILESMENU);
1701 SetConditionalCascade(CollectorDirMenu, IDM_COMMANDSMENU,
1702 IDM_DOITYOURSELF);
1703 SetConditionalCascade(CollectorDirMenu, IDM_COPYMENU, IDM_COPY);
1704 SetConditionalCascade(CollectorDirMenu, IDM_MOVEMENU, IDM_MOVE);
1705 SetConditionalCascade(CollectorDirMenu, IDM_SAVESUBMENU,
1706 IDM_SAVETOCLIP);
1707 SetConditionalCascade(CollectorDirMenu, IDM_VIEWSUBMENU, IDM_INFO);
1708 SetConditionalCascade(CollectorDirMenu, IDM_EDITSUBMENU, IDM_ATTRS);
1709 SetConditionalCascade(CollectorDirMenu, IDM_DELETESUBMENU,
1710 fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
1711 SetConditionalCascade(CollectorDirMenu, IDM_MISCSUBMENU, IDM_SIZES);
1712 SetConditionalCascade(CollectorDirMenu, IDM_OPENSUBMENU,
1713 IDM_OPENWINDOW);
1714 if (fWorkPlace) {
1715 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1716 MPFROM2SHORT(IDM_OPENSUBMENU, TRUE), MPVOID);
1717 WinSendMsg(CollectorDirMenu, MM_DELETEITEM,
1718 MPFROM2SHORT(IDM_OBJECTSUBMENU, TRUE), MPVOID);
1719 }
1720 }
1721 else if (hwndMenu == &MainPopupMenu) {
1722 WinSetWindowUShort(MainPopupMenu, QWS_ID, IDM_MAINPOPUP);
1723 SetConditionalCascade(MainPopupMenu, IDM_TOOLSUBMENU, IDM_TOOLBAR);
1724 SetConditionalCascade(MainPopupMenu, IDM_AUTOVIEWSUBMENU, IDM_AUTOVIEW);
1725 }
1726 }
1727 return *hwndMenu;
1728}
1729
1730SHORT AddToListboxBottom(HWND hwnd, CHAR * str)
1731{
1732 SHORT ln;
1733
1734 ln = (SHORT) WinSendMsg(hwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0),
1735 MPFROMP(str));
1736 if (ln)
1737 WinSendMsg(hwnd, LM_SELECTITEM, MPFROM2SHORT(ln, 0), MPVOID);
1738 return ln;
1739}
1740
1741VOID SetSysMenu(HWND hwndSysMenu)
1742{
1743 CHAR s[128], *p;
1744
1745 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1746 MPFROM2SHORT(SC_RESTORE, 128), MPFROMP(s))) {
1747 p = strchr(s, '\t');
1748 if (p) {
1749 p++;
1750 strcpy(p, "Ctrl+Alt+F5");
1751 WinSetMenuItemText(hwndSysMenu, SC_RESTORE, s);
1752 }
1753 }
1754 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1755 MPFROM2SHORT(SC_CLOSE, 128), MPFROMP(s))) {
1756 p = strchr(s, '\t');
1757 if (p) {
1758 p++;
1759 strcpy(p, "Ctrl+Alt+F4");
1760 WinSetMenuItemText(hwndSysMenu, SC_CLOSE, s);
1761 }
1762 }
1763 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1764 MPFROM2SHORT(SC_MOVE, 128), MPFROMP(s))) {
1765 p = strchr(s, '\t');
1766 if (p) {
1767 p++;
1768 strcpy(p, "Ctrl+Alt+F7");
1769 WinSetMenuItemText(hwndSysMenu, SC_MOVE, s);
1770 }
1771 }
1772 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1773 MPFROM2SHORT(SC_SIZE, 128), MPFROMP(s))) {
1774 p = strchr(s, '\t');
1775 if (p) {
1776 p++;
1777 strcpy(p, "Ctrl+Alt+F8");
1778 WinSetMenuItemText(hwndSysMenu, SC_SIZE, s);
1779 }
1780 }
1781 if (WinSendMsg(hwndSysMenu, MM_QUERYITEMTEXT,
1782 MPFROM2SHORT(SC_MINIMIZE, 128), MPFROMP(s))) {
1783 p = strchr(s, '\t');
1784 if (p) {
1785 p++;
1786 strcpy(p, "Ctrl+Alt+F9");
1787 WinSetMenuItemText(hwndSysMenu, SC_MINIMIZE, s);
1788 }
1789 }
1790 if (WinSendMsg(hwndSysMenu,
1791 MM_QUERYITEMTEXT,
1792 MPFROM2SHORT(SC_MAXIMIZE, 128), MPFROMP(s))) {
1793 p = strchr(s, '\t');
1794 if (p) {
1795 p++;
1796 strcpy(p, "Ctrl+Alt+F10");
1797 WinSetMenuItemText(hwndSysMenu, SC_MAXIMIZE, s);
1798 }
1799 }
1800 if (WinSendMsg(hwndSysMenu,
1801 MM_QUERYITEMTEXT, MPFROM2SHORT(SC_HIDE, 128), MPFROMP(s))) {
1802 p = strchr(s, '\t');
1803 if (p) {
1804 p++;
1805 strcpy(p, "Ctrl+Alt+F11");
1806 WinSetMenuItemText(hwndSysMenu, SC_HIDE, s);
1807 }
1808 }
1809}
1810
1811VOID LoadLibPath(CHAR * str, LONG len)
1812{
1813 ULONG ver[2];
1814 CHAR configsys[] = "C:\\CONFIG.SYS";
1815 static CHAR var[8192], beg[16384], end[16384];
1816 BOOL warp;
1817 FILE *fp;
1818 PFN DQELIBPATH = NULL;
1819 HMODULE hmod;
1820
1821 if (str && len) {
1822 *str = 0;
1823 if (DosQuerySysInfo(QSV_BOOT_DRIVE,
1824 QSV_BOOT_DRIVE, (PVOID) ver, (ULONG) sizeof(ULONG)))
1825 ver[0] = 3L;
1826 *configsys = (CHAR) ver[0] + '@';
1827 if (!DosQuerySysInfo(QSV_VERSION_MAJOR,
1828 QSV_VERSION_MINOR,
1829 (PVOID) ver, (ULONG) sizeof(ver)) && ver[1] >= 30)
1830 warp = TRUE;
1831 *var = *beg = *end = 0;
1832 if (warp) {
1833 if (!DosLoadModule(var, sizeof(var), "DOSCALL1.DLL", &hmod)) {
1834 if (!DosQueryProcAddr(hmod,
1835 ORD_DOS32QUERYEXTLIBPATH,
1836 NULL, (PFN *) & DQELIBPATH)) {
1837 DQELIBPATH(beg, BEGIN_LIBPATH);
1838 DQELIBPATH(end, END_LIBPATH);
1839 }
1840 DosFreeModule(hmod);
1841 }
1842 *var = 0;
1843 }
1844 fp = xfopen(configsys, "r", pszSrcFile, __LINE__);
1845 if (fp) {
1846 while (!feof(fp)) {
1847 if (!xfgets_bstripcr(var, sizeof(var), fp, pszSrcFile, __LINE__))
1848 break;
1849 if (!strnicmp(var, "LIBPATH=", 8)) {
1850 memmove(var, var + 8, strlen(var + 8) + 1);
1851 lstrip(var);
1852 break;
1853 }
1854 }
1855 fclose(fp);
1856 }
1857 strncpy(str, beg, len);
1858 strncat(str, var, len - strlen(str));
1859 strncat(str, end, len - strlen(str));
1860 str[len - 1] = 0;
1861 }
1862}
1863
1864void SetViewMenu(HWND hwndMenu, ULONG flWindowAttr)
1865{
1866 WinCheckMenuItem(hwndMenu, IDM_MINIICONS, ((flWindowAttr & CV_MINI)));
1867 WinCheckMenuItem(hwndMenu, IDM_TEXT, ((flWindowAttr & CV_TEXT)));
1868 WinCheckMenuItem(hwndMenu, IDM_ICON, ((flWindowAttr & CV_ICON) &&
1869 !(flWindowAttr & CV_TREE)));
1870 WinCheckMenuItem(hwndMenu, IDM_TREEVIEW, ((flWindowAttr & CV_TREE)));
1871 WinCheckMenuItem(hwndMenu, IDM_DETAILS, ((flWindowAttr & CV_DETAIL)));
1872 WinCheckMenuItem(hwndMenu, IDM_NAME, ((flWindowAttr & CV_NAME)));
1873}
1874
1875void SaySort(HWND hwnd, INT sortflags, BOOL archive)
1876{
1877 char *s = NULL;
1878
1879 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
1880 if (s) {
1881 sprintf(s, "S:%s%s",
1882 sortflags & SORT_REVERSE ? "^" : NullStr,
1883 (sortflags & SORT_FIRSTEXTENSION) ?
1884 GetPString(IDS_FIRSTX) : (sortflags & SORT_LASTEXTENSION) ?
1885 GetPString(IDS_LASTX) : (sortflags & SORT_SIZE) ?
1886 "Size" : (sortflags & SORT_EASIZE) ?
1887 (archive == 0) ?
1888 GetPString(IDS_EASIZE) : GetPString(IDS_CSIZE) :
1889 (sortflags & SORT_LWDATE) ?
1890 (archive == 0) ?
1891 GetPString(IDS_LWDATE) : GetPString(IDS_DATE) :
1892 (sortflags & SORT_LADATE) ?
1893 GetPString(IDS_LADATE) : (sortflags & SORT_CRDATE) ?
1894 GetPString(IDS_CRDATE) :
1895 (sortflags & SORT_PATHNAME) ?
1896 GetPString(IDS_PATH) : (sortflags & SORT_NOSORT) ?
1897 GetPString(IDS_NONE) : (sortflags & SORT_SUBJECT) ?
1898 GetPString(IDS_SUBJ) : GetPString(IDS_NAME));
1899 WinSetWindowText(hwnd, s);
1900 free(s);
1901 }
1902}
1903
1904void SayView(HWND hwnd, ULONG flWindowAttr)
1905{
1906 char *s = NULL;
1907
1908 s = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
1909 if (s) {
1910 sprintf(s, "V:%s%s",
1911 (flWindowAttr & CV_TREE) ? GetPString(IDS_TREE) :
1912 (flWindowAttr & CV_NAME) ? GetPString(IDS_NAME) :
1913 (flWindowAttr & CV_DETAIL) ? GetPString(IDS_DETAIL) :
1914 (flWindowAttr & CV_TEXT) ? GetPString(IDS_TEXT) :
1915 GetPString(IDS_ICON),
1916 ((flWindowAttr & CV_MINI) &&
1917 !(flWindowAttr & CV_TEXT)) ? GetPString(IDS_MINI) : NullStr);
1918 WinSetWindowText(hwnd, s);
1919 free(s);
1920 }
1921}
1922
1923void SayFilter(HWND hwnd, MASK * mask, BOOL archive)
1924{
1925 char *s = NULL;
1926
1927 s = xmalloc(CCHMAXPATH * 2, pszSrcFile, __LINE__);
1928 if (s) {
1929 sprintf(s, "F:%s%s",
1930 mask->szMask,
1931 (!archive && (mask->attrFile != ALLATTRS ||
1932 mask->antiattr != 0)) ? " " : NullStr,
1933 (!archive && (mask->attrFile != ALLATTRS ||
1934 mask->antiattr !=
1935 0)) ? GetPString(IDS_ATTRTEXT) : NullStr);
1936 if (!s[2])
1937 sprintf(s, "F:%s", GetPString(IDS_ALLTEXT));
1938 WinSetWindowText(hwnd, s);
1939 free(s);
1940 }
1941}
1942
1943char *GetCmdSpec(BOOL dos)
1944{
1945 char *cmspec;
1946
1947 if (!dos) {
1948 cmspec = getenv("OS2_SHELL");
1949 if (!cmspec)
1950 cmspec = getenv("COMSPEC");
1951 if (!cmspec)
1952 cmspec = "CMD.EXE";
1953 }
1954 else {
1955 cmspec = getenv("DOS_SHELL");
1956 if (!cmspec)
1957 cmspec = "COMMAND.COM";
1958 }
1959 return cmspec;
1960}
1961
1962void Broadcast(HAB hab, HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1963{
1964 if (hwndMain)
1965 WinBroadcastMsg(hwndMain, msg, mp1, mp2, BMSG_SEND | BMSG_FRAMEONLY);
1966 if (hwnd &&
1967 hwnd != HWND_DESKTOP &&
1968 hwnd != hwndMain &&
1969 hwnd != WinQueryDesktopWindow(hab, NULLHANDLE) &&
1970 WinIsWindow(hab, hwnd) && (!hwndMain || !WinIsChild(hwnd, hwndMain)))
1971 WinSendMsg(hwnd, msg, mp1, mp2);
1972}
1973
1974void SetupWinList(HWND hwndMenu, HWND hwndTop, HWND hwndFrame)
1975{
1976 /*
1977 * add switchlist entries to end of pulldown menu
1978 */
1979
1980 SHORT sItemCount, x = 0, y = 0;
1981 MENUITEM mi;
1982
1983 sItemCount = (SHORT) WinSendMsg(hwndMenu,
1984 MM_QUERYITEMCOUNT, MPVOID, MPVOID);
1985
1986 /* clean out old additions */
1987 while ((SHORT) WinSendMsg(hwndMenu,
1988 MM_DELETEITEM,
1989 MPFROM2SHORT(IDM_SWITCHSTART + x++,
1990 TRUE), MPVOID) < sItemCount)
1991 sItemCount--;
1992 x = 0;
1993 while ((SHORT) WinSendMsg(hwndMenu,
1994 MM_DELETEITEM,
1995 MPFROM2SHORT(IDM_WINDOWSTART + x++,
1996 TRUE), MPVOID) < sItemCount)
1997 sItemCount--;
1998
1999 x = 0;
2000 if (hwndTop) {
2001
2002 char wtext[CCHMAXPATH + 8];
2003 HENUM henum;
2004 HWND hwndChild;
2005
2006 /* add children of the main FM/2 client */
2007 henum = WinBeginEnumWindows(hwndTop);
2008 memset(&mi, 0, sizeof(mi));
2009 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2010 if (WinQueryWindowUShort(hwndChild, QWS_ID) && hwndChild != hwndFrame) {
2011 *wtext = 0;
2012 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, wtext);
2013 if (*wtext) {
2014 wtext[CCHMAXPATH + 7] = 0;
2015 mi.afStyle = MIS_TEXT;
2016 if (!((x + sItemCount) % 28))
2017 mi.afStyle |= MIS_BREAK;
2018 mi.id = IDM_WINDOWSTART + x;
2019 mi.iPosition = MIT_END;
2020 if ((SHORT) WinSendMsg(hwndMenu,
2021 MM_INSERTITEM,
2022 MPFROMP(&mi), MPFROMP(wtext)) >= 0)
2023 x++;
2024 }
2025 }
2026 }
2027 WinEndEnumWindows(henum);
2028 }
2029
2030 /* add external FM/2 windows */
2031 {
2032 PSWBLOCK pswb;
2033 ULONG ulSize, ulcEntries;
2034 HWND hwndTopFrame;
2035 register INT i;
2036
2037 hwndTopFrame = hwndTop ? WinQueryWindow(hwndTop, QW_PARENT) : (HWND)0;
2038 /* Get the switch list information */
2039 x = 0;
2040 ulcEntries = WinQuerySwitchList(0, NULL, 0);
2041 ulSize = sizeof(SWBLOCK) + sizeof(HSWITCH) + (ulcEntries + 4L) *
2042 (LONG) sizeof(SWENTRY);
2043 /* Allocate memory for list */
2044 pswb = xmalloc(ulSize, pszSrcFile, __LINE__);
2045 if (pswb) {
2046 /* Put the info in the list */
2047 ulcEntries = WinQuerySwitchList(0, pswb, ulSize - sizeof(SWENTRY));
2048 /* do the dirty deed */
2049 memset(&mi, 0, sizeof(mi));
2050 for (i = 0; i < pswb->cswentry; i++) {
2051 if (pswb->aswentry[i].swctl.uchVisibility == SWL_VISIBLE &&
2052 pswb->aswentry[i].swctl.fbJump == SWL_JUMPABLE &&
2053 (pswb->aswentry[i].swctl.idProcess != mypid ||
2054 !hwndFrame ||
2055 pswb->aswentry[i].swctl.hwnd != hwndFrame) &&
2056 (pswb->aswentry[i].swctl.idProcess != mypid ||
2057 !hwndTopFrame ||
2058 pswb->aswentry[i].swctl.hwnd != hwndTopFrame ||
2059 !WinIsChild(hwndFrame, hwndTop))) {
2060 if (!strnicmp(pswb->aswentry[i].swctl.szSwtitle, "AV/2", 4)
2061 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "File Manager/2")
2062 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "Collector")
2063 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VTree", 5)
2064 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VDir", 4)
2065 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, FM2Str, 4)) {
2066 mi.afStyle = MIS_TEXT;
2067 if (x && !(x % 28))
2068 mi.afStyle |= MIS_BREAK;
2069 mi.id = IDM_SWITCHSTART + y;
2070 mi.iPosition = MIT_END;
2071 switches[y] = pswb->aswentry[i].hswitch;
2072 if ((SHORT) WinSendMsg(hwndMenu,
2073 MM_INSERTITEM,
2074 MPFROMP(&mi),
2075 MPFROMP(pswb->aswentry[i].
2076 swctl.szSwtitle)) >= 0) {
2077 y++;
2078 x++;
2079 }
2080 }
2081 }
2082 }
2083 numswitches = y;
2084 free(pswb);
2085 DosPostEventSem(CompactSem);
2086 }
2087 }
2088}
2089
2090BOOL SwitchCommand(HWND hwndMenu, USHORT cmd)
2091{
2092 BOOL ret = FALSE;
2093
2094 if (hwndMain && hwndMenu && cmd >= IDM_WINDOWSTART && cmd < IDM_SWITCHSTART) {
2095 /*
2096 * select a child window (of client)
2097 */
2098
2099 MENUITEM mi;
2100 HWND hwndSubMenu = (HWND) 0, hwndChild;
2101 CHAR s[CCHMAXPATH + 8];
2102
2103 if (WinQueryWindowUShort(hwndMenu, QWS_ID) != IDM_WINDOWSMENU) {
2104 memset(&mi, 0, sizeof(mi));
2105 mi.iPosition = MIT_END;
2106 mi.afStyle = MIS_TEXT;
2107 if (WinSendMsg(hwndMenu,
2108 MM_QUERYITEM,
2109 MPFROM2SHORT(IDM_WINDOWSMENU, TRUE), MPFROMP(&mi)))
2110 hwndSubMenu = mi.hwndSubMenu;
2111 }
2112 else
2113 hwndSubMenu = hwndMenu;
2114 if (hwndSubMenu) {
2115 *s = 0;
2116 if (WinSendMsg(hwndSubMenu,
2117 MM_QUERYITEMTEXT,
2118 MPFROM2SHORT(cmd, CCHMAXPATH + 8), MPFROMP(s)) && *s) {
2119
2120 HENUM henum;
2121 CHAR checkText[CCHMAXPATH + 8];
2122 SWP swp;
2123
2124 s[CCHMAXPATH + 7] = 0;
2125 henum = WinBeginEnumWindows(hwndMain);
2126 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
2127 if (WinQueryWindowUShort(hwndChild, QWS_ID)) {
2128 *checkText = 0;
2129 WinQueryWindowText(hwndChild, CCHMAXPATH + 8, checkText);
2130 checkText[CCHMAXPATH + 7] = 0;
2131 if (!stricmp(checkText, s)) {
2132 if (WinQueryWindowPos(hwndChild, &swp)) {
2133 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE))
2134 WinSetWindowPos(hwndChild,
2135 HWND_TOP,
2136 0, 0, 0, 0, SWP_RESTORE | SWP_ZORDER);
2137 }
2138 WinSetActiveWindow(HWND_DESKTOP, hwndChild);
2139 ret = TRUE;
2140 break;
2141 }
2142 }
2143 }
2144 WinEndEnumWindows(henum);
2145 }
2146 }
2147 }
2148 else if (cmd >= IDM_SWITCHSTART && cmd < IDM_SWITCHSTART + 499) {
2149 if (cmd - IDM_SWITCHSTART < numswitches) {
2150 WinSwitchToProgram(switches[cmd - IDM_SWITCHSTART]);
2151 ret = TRUE;
2152 }
2153 }
2154
2155 return ret;
2156}
2157
2158#pragma alloc_text(MAINWND5,SetSysMenu)
2159#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
2160#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
2161#pragma alloc_text(CNR_MISC1,AdjustCnrColVis,AdjustCnrColsForFSType)
2162#pragma alloc_text(CNR_MISC1,AdjustCnrColsForPref,SetCnrCols)
2163#pragma alloc_text(CNR_MISC2,CnrDirectEdit,OpenEdit)
2164#pragma alloc_text(MISC2,SetMenuCheck,disable_menuitem,SetSortChecks)
2165#pragma alloc_text(MISC2,SetDetailsSwitches,SetViewMenu)
2166#pragma alloc_text(MISC3,SetupCommandMenu,AdjustDetailsSwitches)
2167#pragma alloc_text(MISC3,ViewHelp,GetCmdSpec)
2168#pragma alloc_text(MISC3,ExecFile,SetConditionalCascade,LoadDetailsSwitches)
2169#pragma alloc_text(MISC4,PortholeInit,CheckMenu,Broadcast,SetupWinList,SwitchCommand)
2170#pragma alloc_text(MISC6,DrawTargetEmphasis,EmphasizeButton)
2171#pragma alloc_text(MISC_LIBPATH,LoadLibPath)
2172#pragma alloc_text(MISC_SAY,SayView,SaySort,SayFilter)
2173
Note: See TracBrowser for help on using the repository browser.