source: trunk/dll/misc.c@ 1166

Last change on this file since 1166 was 1159, checked in by John Small, 17 years ago

Ticket 187: Draft 1: Functions only

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