source: trunk/dll/misc.c@ 1078

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

More Fortify infrastructure enhancements
Rework Fortify_SetOwner
Add Fortify_BecomeOwner
Avoid more spurious leak reports

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