source: trunk/dll/misc.c@ 198

Last change on this file since 198 was 198, checked in by root, 20 years ago

Drop obsoletes

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