source: trunk/dll/select.c@ 1565

Last change on this file since 1565 was 1565, checked in by Steven Levine, 14 years ago

Ensure mask->pszMasks[1] initialize to NULL if not used

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.4 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: select.c 1565 2011-05-31 18:37:01Z stevenhl $
5
[362]6 Container item selection support routines
7
[123]8 Copyright (c) 1993-98 M. Kimes
[1565]9 Copyright (c) 2004, 2011 Steven H. Levine
[123]10
[158]11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 25 May 05 SHL Rework for ULONGLONG
[204]13 06 Jun 05 SHL Drop unused code
[317]14 06 Jul 06 SHL Support compare content (IDM_SELECTSAMECONTENT)
[362]15 13 Jul 06 SHL Use Runtime_Error
[406]16 29 Jul 06 SHL Use xfgets_bstripcr
[442]17 15 Aug 06 SHL Rework SetMask args and logic
[603]18 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
[618]19 19 Apr 07 SHL Sync with NumItemsToUnhilite mods
[672]20 12 May 07 SHL Use dcd->ulItemsToUnHilite
[690]21 14 Jun 07 SHL SelectAll: make odd expression go away
[751]22 02 Aug 07 SHL Sync with CNRITEM mods
[762]23 04 Aug 07 SHL Use Runtime_Error
[769]24 05 Aug 07 SHL Rework SpecialSelect to use CNRITEM_EXISTS and
25 not use pszFileName since CNRITEM_EXISTS set implies
26 pszFileName not null
[787]27 14 Aug 07 SHL Revert ExpandAll DosSleep to 0
[793]28 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[814]29 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
[924]30 12 Jan 08 SHL Localize SpecialSelect in comp.c
[985]31 29 Feb 08 GKY Use xfree where appropriate
[1565]32 31 May 11 SHL Ensure mask->pszMasks[1] initialize to NULL if not used
[123]33
34***********************************************************************/
35
[2]36#include <stdlib.h>
37#include <string.h>
38#include <share.h>
[317]39#include <io.h>
[158]40
[907]41#define INCL_DOS
42#define INCL_WIN
43#define INCL_LONGLONG
44
[1180]45#include "fm3dll.h"
[1226]46#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
47#include "select.h"
[1212]48#include "notebook.h" // Data declaration(s)
49#include "newview.h" // Data declarations
[907]50#include "fm3str.h"
51#include "filldir.h" // RemoveCnrItems
52#include "makelist.h" // AddToList
53#include "errutil.h" // Dos_Error...
54#include "strutil.h" // GetPString
[1158]55#include "valid.h" // TestCDates
[1180]56#include "misc.h" // CurrentRecord
57#include "findrec.h" // FindCnrRecord
58#include "notify.h" // Notify
59#include "literal.h" // wildcard
60#include "wrappers.h" // xrealloc
61#include "strips.h" // bstrip
62#include "stristr.h" // findstring
[1039]63#include "fortify.h"
[2]64
[362]65static PSZ pszSrcFile = __FILE__;
66
[672]67VOID UnHilite(HWND hwndCnr, BOOL all, CHAR *** list, ULONG ulItemsToUnHilite)
[317]68{
[2]69 PCNRITEM pci;
[907]70 UINT numfiles = 0, numalloc = 0;
71 UINT x = 0;
[551]72 INT attribute = CRA_CURSORED;
[2]73
[362]74 if (all && list && *list) {
[2]75 FreeList(*list);
76 *list = NULL;
77 }
[551]78 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]79 if (pci && (INT)pci != -1) {
[362]80 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]81 attribute = CRA_SELECTED;
[551]82 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
83 MPFROMSHORT(attribute));
[2]84 }
[748]85 while (pci && (INT)pci != -1) {
[551]86 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
87 MPFROM2SHORT(FALSE, CRA_SELECTED));
[362]88 if (!all)
[690]89 break;
[618]90 // Count is one extra to ensure non-zero elsewhere
[672]91 // x is 0 based index
92 if (x + 2 == ulItemsToUnHilite)
[690]93 break;
[362]94 if (list)
[730]95 AddToList(pci->pszFileName, list, &numfiles, &numalloc);
[551]96 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
97 MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
[603]98 x++;
[2]99 }
100 }
101}
102
[551]103VOID SelectList(HWND hwndCnr, BOOL partial, BOOL deselect, BOOL clearfirst,
[748]104 PCNRITEM pciParent, PSZ filename, CHAR ** list)
[362]105{
[2]106
[551]107 PCNRITEM pci;
[2]108 register INT x;
[551]109 BOOL foundone = FALSE;
[766]110 ULONG errs = 0;
[2]111
[362]112 if (clearfirst && !deselect)
[672]113 UnHilite(hwndCnr, TRUE, NULL, 0);
[362]114 if (list && list[0]) {
[551]115 for (x = 0; list[x]; x++) {
[2]116 pci = FindCnrRecord(hwndCnr,
[551]117 list[x], pciParent, partial, partial, TRUE);
[362]118 if (pci) {
[551]119 WinSendMsg(hwndCnr,
120 CM_SETRECORDEMPHASIS,
121 MPFROMP(pci),
122 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
123 CRA_SELECTED));
124 foundone = TRUE;
[2]125 }
126 }
[362]127 if (!foundone)
128 Runtime_Error(pszSrcFile, __LINE__, "select failed");
[2]129 }
[362]130 else if (filename && *filename) {
[2]131
132 FILE *fp;
[551]133 CHAR input[1024], *p;
[1544]134 CHAR *moder = "r";
[2]135
[1544]136 fp = xfsopen(filename, moder, SH_DENYNO, pszSrcFile, __LINE__, TRUE);
[362]137 if (fp) {
138 while (!feof(fp)) {
[551]139 if (!xfgets_bstripcr(input, sizeof(input), fp, pszSrcFile, __LINE__))
140 break;
141 if (*input == '\"') {
142 memmove(input, input + 1, strlen(input) + 1);
143 lstrip(input);
144 p = strchr(input, '\"');
145 if (p)
146 *p = 0;
147 rstrip(input);
148 }
149 else {
150 p = strchr(input, ' ');
151 if (p)
152 *p = 0;
153 }
[1565]154 // Input now contains name of file to select
[551]155 pci = FindCnrRecord(hwndCnr,
156 input, pciParent, partial, partial, TRUE);
[1565]157 if (pci) // Found it?
[551]158 WinSendMsg(hwndCnr,
159 CM_SETRECORDEMPHASIS,
160 MPFROMP(pci),
161 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
162 CRA_SELECTED));
163 else
164 errs++;
[1565]165 if (errs > 50) { // Prevent runaway on bad file
[2]166
[551]167 APIRET ret;
[2]168
[551]169 ret = saymsg(MB_YESNO,
170 hwndCnr,
171 GetPString(IDS_POSSIBLEERRORTEXT),
172 GetPString(IDS_MAYNOTBELISTTEXT), filename);
173 if (ret == MBID_NO)
174 break;
[766]175 errs = 0;
[551]176 }
[2]177 }
178 fclose(fp);
179 }
180 }
181}
182
[748]183VOID SelectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
184 PSZ text, BOOL is_arc)
[362]185{
[2]186
[551]187 PCNRITEM pci;
188 BOOL markit;
[748]189 PSZ file;
190 PSZ pszToMatch;
[551]191 MASK Mask;
[748]192 INT x;
[551]193 ULONG textlen = 0;
[2]194
[362]195 if (text)
[2]196 textlen = strlen(text);
[551]197 memset(&Mask, 0, sizeof(Mask));
[442]198 if (maskstr)
[551]199 SetMask(maskstr, &Mask);
200 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
201 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]202 while (pci && (INT)pci != -1) {
203
[2]204 markit = FALSE;
[748]205
206 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[362]207 if (!is_arc) {
[748]208 if (files && ~pci->attrFile & FILE_DIRECTORY)
[551]209 markit = TRUE;
[748]210 if (dirs && pci->attrFile & FILE_DIRECTORY)
[551]211 markit = TRUE;
[2]212 }
213 else
[551]214 markit = TRUE;
[442]215 if (maskstr && *maskstr && markit) {
[551]216 markit = FALSE;
[748]217 // Point a filename part
[730]218 file = strrchr(pci->pszFileName, '\\');
[551]219 if (!file)
[730]220 file = strrchr(pci->pszFileName, ':');
[551]221 if (file)
222 file++;
223 else
[730]224 file = pci->pszFileName;
[551]225 for (x = 0; Mask.pszMasks[x]; x++) {
226 if (*Mask.pszMasks[x]) {
[748]227 if ((strchr(Mask.pszMasks[x], '\\') ||
228 strchr(Mask.pszMasks[x], ':')))
229 pszToMatch = pci->pszFileName;
230 else
231 pszToMatch = file;
[551]232 if (*Mask.pszMasks[x] != '/') {
[1565]233 if (wildcard(pszToMatch, Mask.pszMasks[x], TRUE)) {
[551]234 markit = TRUE;
[690]235 }
[551]236 }
237 else {
[1413]238 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, TRUE)) {
[551]239 markit = FALSE;
240 break;
241 }
242 }
243 }
[690]244 } // for
[2]245 }
246 }
247
[748]248 if (markit && text && *text) {
249 if (~pci->attrFile & FILE_DIRECTORY) {
250 PSZ input;
251 markit = FALSE;
252 input = xmalloc(65537, pszSrcFile, __LINE__);
253 if (input) {
254 ULONG pos;
255 LONG len;
[1565]256 FILE *inputFile;
257 CHAR *moderb = "rb";
[2]258
[1565]259 if ((inputFile = xfsopen(pci->pszFileName, moderb, SH_DENYNO,
260 pszSrcFile, __LINE__, TRUE)) != NULL) {
[748]261 pos = ftell(inputFile);
262 while (!feof(inputFile)) {
263 if (pos)
264 fseek(inputFile, pos - 256, SEEK_SET);
265 len = fread(input, 1, 65536, inputFile);
266 if (len >= 0) {
267 if (findstring(text, textlen, input, len, FALSE)) {
268 markit = TRUE;
269 break;
270 }
271 }
272 else
[551]273 break;
[787]274 } // while
[748]275 fclose(inputFile);
[551]276 }
[1039]277 free(input);
[766]278 DosSleep(1);
[551]279 }
[2]280 }
[748]281 else
282 markit = FALSE;
[2]283 }
[748]284
[362]285 if (markit)
[551]286 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
287 MPFROM2SHORT(TRUE, CRA_SELECTED));
288 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
289 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
290 } // while
[2]291}
292
[748]293VOID DeselectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
294 PSZ text, BOOL is_arc)
[362]295{
[551]296 PCNRITEM pci;
297 BOOL unmarkit;
[748]298 PSZ file;
299 PSZ pszToMatch;
[551]300 MASK Mask;
301 register INT x;
302 ULONG textlen = 0;
[2]303
[362]304 if (text)
[2]305 textlen = strlen(text);
[551]306 memset(&Mask, 0, sizeof(Mask));
[442]307 if (maskstr && *maskstr)
[551]308 SetMask(maskstr, &Mask);
309 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
310 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]311 while (pci && (INT)pci != -1) {
[2]312 unmarkit = FALSE;
[748]313 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[362]314 if (!is_arc) {
[748]315 if (files && ~pci->attrFile & FILE_DIRECTORY)
[551]316 unmarkit = TRUE;
317 if (dirs && (pci->attrFile & FILE_DIRECTORY))
318 unmarkit = TRUE;
[2]319 }
320 else
[551]321 unmarkit = TRUE;
[442]322 if (maskstr && *maskstr && unmarkit) {
[551]323 unmarkit = FALSE;
[730]324 file = strrchr(pci->pszFileName, '\\');
[551]325 if (!file)
[730]326 file = strrchr(pci->pszFileName, ':');
[551]327 if (file)
328 file++;
329 else
[730]330 file = pci->pszFileName;
[551]331 for (x = 0; Mask.pszMasks[x]; x++) {
332 if (*Mask.pszMasks[x]) {
[748]333 if (strchr(Mask.pszMasks[x], '\\') ||
334 strchr(Mask.pszMasks[x], ':'))
335 pszToMatch = pci->pszFileName;
336 else
337 pszToMatch = file;
[551]338 if (*Mask.pszMasks[x] != '/') {
[1413]339 if (wildcard(pszToMatch, Mask.pszMasks[x], TRUE))
[551]340 unmarkit = TRUE;
341 }
342 else {
[1413]343 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, TRUE)) {
[551]344 unmarkit = FALSE;
345 break;
346 }
347 }
348 }
349 }
[2]350 }
351 }
352
[748]353 if (unmarkit && text && *text) {
354 if (~pci->attrFile & FILE_DIRECTORY) {
355 PSZ input;
356 unmarkit = FALSE;
357 input = xmalloc(65537, pszSrcFile, __LINE__);
358 if (input) {
359 ULONG pos;
360 LONG len;
361 FILE *inputFile;
[1565]362 CHAR *moderb = "rb";
[2]363
[1565]364 if ((inputFile = xfsopen(pci->pszFileName, moderb, SH_DENYNO,
365 pszSrcFile, __LINE__, TRUE)) != NULL) {
[748]366 pos = ftell(inputFile);
367 while (!feof(inputFile)) {
368 if (pos)
369 fseek(inputFile, pos - 256, SEEK_SET);
370 len = fread(input, 1, 65536, inputFile);
371 if (len >= 0) {
372 if (findstring(text, textlen, input, len, FALSE)) {
373 unmarkit = TRUE;
374 break;
375 }
376 }
377 else
[551]378 break;
[787]379 } // while
[748]380 fclose(inputFile);
[551]381 }
[1039]382 free(input);
[766]383 DosSleep(1);
[551]384 }
[2]385 }
[748]386 else
387 unmarkit = FALSE;
[2]388 }
[748]389
[362]390 if (unmarkit)
[551]391 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, pci,
392 MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED |
393 CRA_INUSE | CRA_SOURCE));
394 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
395 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]396 }
397}
398
[551]399VOID Deselect(HWND hwndCnr)
[317]400{
[2]401 PCNRITEM pcil;
402
[551]403 pcil = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
404 MPFROMLONG(CMA_FIRST),
405 MPFROMSHORT(CRA_SELECTED));
[748]406 while (pcil && (INT)pcil != -1) {
[551]407 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pcil),
408 MPFROM2SHORT(FALSE, CRA_SELECTED));
409 pcil = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pcil),
410 MPFROMSHORT(CRA_SELECTED));
[2]411 }
412}
413
[317]414//=== HideAll() Hide all selected records ===
[2]415
[551]416VOID HideAll(HWND hwndCnr)
[317]417{
[551]418 PCNRITEM pci, pciH;
419 INT attribute = CRA_CURSORED;
420 CNRINFO cnri;
421 BOOL didone = FALSE;
[2]422
[551]423 memset(&cnri, 0, sizeof(CNRINFO));
[2]424 cnri.cb = sizeof(CNRINFO);
[551]425 WinSendMsg(hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
426 MPFROMLONG(sizeof(CNRINFO)));
427 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]428 if (pci && (INT)pci != -1) {
[362]429 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]430 attribute = CRA_SELECTED;
[551]431 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
432 MPFROMSHORT(attribute));
[2]433 }
434 }
[748]435 while (pci && (INT)pci != -1) {
[551]436 pciH = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
437 MPFROMSHORT(attribute));
438 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
439 MPFROM2SHORT(FALSE, CRA_CURSORED | CRA_SELECTED |
440 CRA_INUSE | CRA_SOURCE));
[2]441 pci->rc.flRecordAttr |= CRA_FILTERED;
442 didone = TRUE;
[362]443 if (fSyncUpdates) {
444 if (cnri.flWindowAttr & CV_DETAIL)
[551]445 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
446 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
[2]447 else
[551]448 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci),
449 MPFROM2SHORT(1, CMA_REPOSITION | CMA_ERASE));
[2]450 }
451 pci = pciH;
452 }
[362]453 if (didone && !fSyncUpdates)
[551]454 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
455 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
[2]456}
457
[551]458VOID MarkAll(HWND hwndCnr, BOOL quitit, BOOL target, BOOL source)
[317]459{
[2]460 PCNRITEM pci;
[551]461 INT attribute = CRA_CURSORED;
[2]462
[362]463 if (quitit)
[618]464 attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
[551]465 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
466 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
[748]467 if (pci && (INT)pci != -1) {
[362]468 if (attribute == CRA_CURSORED) {
469 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[551]470 attribute = CRA_SELECTED;
471 pci =
472 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
473 MPFROMSHORT(attribute));
[2]474 }
475 }
476 }
[748]477 while (pci && (INT)pci != -1) {
[551]478 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
479 MPFROM2SHORT(!quitit,
[618]480 target ? CRA_TARGET : source ? CRA_SOURCE :
481 CRA_INUSE));
[551]482 pci =
483 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
484 MPFROMSHORT(attribute));
[2]485 }
486}
487
[551]488VOID RemoveAll(HWND hwndCnr, ULONGLONG * pullTotalBytes,
489 ULONG * pulTotalFiles)
[317]490{
[2]491 PCNRITEM pci;
[551]492 INT attribute = CRA_CURSORED;
493 BOOL didone = FALSE;
[2]494
[551]495 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]496 if (pci && (INT)pci != -1) {
[362]497 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]498 attribute = CRA_SELECTED;
[551]499 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
500 MPFROMSHORT(attribute));
[2]501 }
502 }
[748]503 while (pci && (INT)pci != -1) {
504 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[2]505 didone = TRUE;
[158]506 if (pulTotalFiles)
[689]507 *pulTotalFiles -= 1;
[158]508 if (pullTotalBytes)
[551]509 *pullTotalBytes -= (pci->cbFile + pci->easize);
510 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
511 MPFROM2SHORT(0, CRA_SELECTED));
[362]512 if (fSyncUpdates)
[751]513 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
[2]514 else
[751]515 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE);
[362]516 if (attribute == CRA_CURSORED)
[551]517 break;
518 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
519 MPFROMSHORT(attribute));
[2]520 }
521 else
[551]522 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
523 MPFROMSHORT(attribute));
[2]524 }
[362]525 if (didone && !fSyncUpdates)
[551]526 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
527 MPFROM2SHORT(0, CMA_REPOSITION));
[2]528}
529
[442]530//== SetMask() Convert mask string to array of pointers to masks ==
531
[1565]532VOID SetMask(PSZ maskstr, MASK *mask)
[317]533{
[442]534 UINT x;
535 PSZ p;
[2]536
[1304]537 DosEnterCritSec();
[442]538 if (maskstr)
[551]539 strcpy(mask->szMask, maskstr); // Got new mask string
[442]540 // Build array of pointers
541 p = mask->szMaskCopy;
[551]542 strcpy(p, mask->szMask);
[442]543 // Allow up to 25 masks - ignore extras
544 for (x = 0; *p && x < 25; x++) {
545 mask->pszMasks[x] = p;
[362]546 while (*p && *p != ';')
[442]547 p++; // Find separator
[362]548 if (*p) {
[1565]549 *p = 0; // Replace ; will nul to terminate string
[2]550 p++;
551 }
[551]552 } // for
[442]553 mask->pszMasks[x] = NULL; // Mark end
[1565]554 if (!x)
555 mask->pszMasks[1] = NULL; // Need 1 more for multiple mask detect 2011-05-31 SHL
[1304]556 DosExitCritSec();
[2]557}
558
[551]559VOID ExpandAll(HWND hwndCnr, BOOL expand, PCNRITEM pciParent)
[317]560{
[2]561 PCNRITEM pci;
562
[362]563 if (!pciParent)
[551]564 pciParent = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
565 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[362]566 if (pciParent) {
[748]567 if (expand && ~pciParent->rc.flRecordAttr & CRA_EXPANDED)
[551]568 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciParent), MPVOID);
[362]569 else if (!expand && (pciParent->rc.flRecordAttr & CRA_EXPANDED))
[551]570 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciParent), MPVOID);
571 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
572 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[362]573 if (pci)
[787]574 DosSleep(0);
[748]575 while (pci && (INT)pci != -1) {
[551]576 ExpandAll(hwndCnr, expand, pci);
577 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
578 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]579 }
580 }
[787]581 DosSleep(0);
[2]582}
583
[551]584VOID InvertAll(HWND hwndCnr)
[317]585{
[2]586 PCNRITEM pci;
587
[551]588 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
589 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]590 while (pci && (INT)pci != -1) {
591 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
592 if (~pci->rc.flRecordAttr & CRA_SELECTED)
[551]593 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
594 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]595 else
[551]596 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
597 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]598 }
[551]599 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
600 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]601 }
602}
603
[551]604struct SS
605{
606 PCNRITEM pci;
607 BOOL unique, all, smallest, largest, newest, oldest;
[2]608};
609
[551]610struct Cnr
611{
612 HWND hwndCnr;
613 ULONG numfiles;
[2]614 struct SS *ss;
615};
616
[551]617static int CompSSNamesB(const void *s1, const void *s2)
[317]618{
[2]619 struct SS *ss2 = (struct SS *)s2;
620
[748]621 return stricmp((PSZ)s1, ss2->pci->pszFileName);
[2]622}
623
[551]624static int CompSSNames(const void *s1, const void *s2)
[317]625{
[2]626 struct SS *ss1 = (struct SS *)s1;
627 struct SS *ss2 = (struct SS *)s2;
628
[551]629 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
[2]630}
631
[551]632VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
[317]633{
[2]634 register INT z;
635
[551]636 for (z = 0; z < numw; z++) {
[1009]637 xfree(Cnrs[z].ss, pszSrcFile, __LINE__);
[2]638 }
[1009]639 xfree(Cnrs, pszSrcFile, __LINE__);
[2]640 DosPostEventSem(CompactSem);
641}
642
[762]643/**
644 * Do select actions for single container
645 *
646 */
647
[551]648VOID SpecialSelect2(HWND hwndParent, INT action)
[317]649{
[551]650 PCNRITEM pci;
651 HENUM henum;
652 HWND hwnd;
[897]653 INT numwindows = 0, w, x, z, cmp = 0;
[551]654 struct Cnr *Cnrs = NULL;
655 struct SS *bsres;
[2]656
[362]657 if (!hwndParent)
[2]658 return;
659
[1565]660 // Count directory containers, build array of hwnds
[2]661 henum = WinBeginEnumWindows(hwndParent);
[362]662 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
[551]663 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
664 Cnrs =
665 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
666 __LINE__);
[362]667 if (!Cnrs) {
[551]668 Notify(GetPString(IDS_OUTOFMEMORY));
669 return;
[2]670 }
[551]671 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
[2]672 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
[551]673 FID_CLIENT),
674 DIR_CNR);
[2]675 numwindows++;
676 }
677 }
678 WinEndEnumWindows(henum);
[362]679 if (numwindows < 2) {
[551]680 FreeCnrs(Cnrs, numwindows);
[362]681 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
[2]682 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
683 return;
684 }
[362]685 if (numwindows > 4) {
[2]686 WinSendMsg(Cnrs[0].
[551]687 hwndCnr,
688 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
[1565]689 DosSleep(0); // Allow other windows to update
[2]690 }
691
[1565]692 // Count records, build array of pointers to records
[551]693 for (z = 0; z < numwindows; z++) {
694 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
695 CM_QUERYRECORD,
696 MPVOID,
697 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[2]698 x = 0;
[748]699 while (pci && (INT)pci != -1) {
700 if (~pci->rc.flRecordAttr & CRA_FILTERED &&
701 ~pci->attrFile & FILE_DIRECTORY) {
[551]702 Cnrs[z].ss =
703 xrealloc(Cnrs[z].ss, (x + 1) * sizeof(struct SS), pszSrcFile,
704 __LINE__);
705 if (!Cnrs[z].ss) {
706 FreeCnrs(Cnrs, numwindows);
707 Notify(GetPString(IDS_OUTOFMEMORY));
708 return;
709 }
710 memset(&Cnrs[z].ss[x], 0, sizeof(struct SS));
711 Cnrs[z].ss[x].pci = pci;
712 x++;
[2]713 }
[551]714 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
715 CM_QUERYRECORD,
716 MPFROMP(pci),
717 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]718 }
[1565]719 DosSleep(0); // Allow other windows to update
[2]720 Cnrs[z].numfiles = x;
[362]721 if (Cnrs[z].numfiles)
[551]722 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
[2]723 }
724
[551]725 for (z = 0; z < numwindows; z++) {
726 for (x = 0; x < Cnrs[z].numfiles; x++) {
[2]727 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
[551]728 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].smallest =
729 Cnrs[z].ss[x].largest = TRUE;
730 for (w = 0; w < numwindows; w++) {
731 if (w != z && Cnrs[w].numfiles) {
732 bsres = (struct SS *)bsearch(Cnrs[z].ss[x].pci->pszFileName,
733 Cnrs[w].ss, Cnrs[w].numfiles,
734 sizeof(struct SS), CompSSNamesB);
735 if (bsres) {
736 Cnrs[z].ss[x].unique = FALSE;
737 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize >
738 bsres->pci->cbFile + bsres->pci->easize)
739 Cnrs[z].ss[x].smallest = FALSE;
740 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize <
741 bsres->pci->cbFile + bsres->pci->easize)
742 Cnrs[z].ss[x].largest = FALSE;
[897]743 cmp = TestCDates(&bsres->pci->date, &bsres->pci->time,
[1565]744 &Cnrs[z].ss[x].pci->date, &Cnrs[z].ss[x].pci->time);
[897]745 /*(Cnrs[z].ss[x].pci->date.year >
[551]746 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year <
747 bsres->pci->date.
748 year) ? FALSE : (Cnrs[z].
749 ss[x].pci->
750 date.month >
751 bsres->pci->
752 date.
753 month) ? TRUE
754 : (Cnrs[z].ss[x].pci->date.month <
755 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
756 day >
757 bsres->pci->date.
758 day) ? TRUE : (Cnrs[z].
759 ss[x].pci->
760 date.day <
761 bsres->
762 pci->date.
763 day) ?
764 FALSE : (Cnrs[z].ss[x].pci->time.hours >
765 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
766 time.hours <
767 bsres->pci->time.
768 hours) ? FALSE
769 : (Cnrs[z].ss[x].pci->time.minutes >
770 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
771 minutes <
772 bsres->pci->time.
773 minutes) ? FALSE
774 : (Cnrs[z].ss[x].pci->time.seconds >
775 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
776 seconds <
777 bsres->pci->time.
[897]778 seconds) ? FALSE : FALSE;*/
779 if (cmp != 1)
[551]780 Cnrs[z].ss[x].newest = FALSE;
[897]781 /*cmp =
[551]782 (Cnrs[z].ss[x].pci->date.year <
783 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year >
784 bsres->pci->date.
785 year) ? FALSE : (Cnrs[z].
786 ss[x].pci->
787 date.month <
788 bsres->pci->
789 date.
790 month) ? TRUE
791 : (Cnrs[z].ss[x].pci->date.month >
792 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
793 day <
794 bsres->pci->date.
795 day) ? TRUE : (Cnrs[z].
796 ss[x].pci->
797 date.day >
798 bsres->
799 pci->date.
800 day) ?
801 FALSE : (Cnrs[z].ss[x].pci->time.hours <
802 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
803 time.hours >
804 bsres->pci->time.
805 hours) ? FALSE
806 : (Cnrs[z].ss[x].pci->time.minutes <
807 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
808 minutes >
809 bsres->pci->time.
810 minutes) ? FALSE
811 : (Cnrs[z].ss[x].pci->time.seconds <
812 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
813 seconds >
814 bsres->pci->time.
[897]815 seconds) ? FALSE : FALSE;*/
816 if (cmp != -1)
[551]817 Cnrs[z].ss[x].oldest = FALSE;
818 cmp = 0;
819 break;
820 }
821 else
822 Cnrs[z].ss[x].all = FALSE;
823 }
[2]824 }
[362]825 if (Cnrs[z].ss[x].unique)
[551]826 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].newest = Cnrs[z].ss[x].all =
827 Cnrs[z].ss[x].largest = Cnrs[z].ss[x].smallest = FALSE;
[748]828 DosSleep(1);
[2]829 }
[766]830 DosSleep(1);
[2]831 }
832
[551]833 switch (action) {
834 case IDM_SELECTBOTH:
835 for (z = 0; z < numwindows; z++) {
836 for (x = 0; x < Cnrs[z].numfiles; x++) {
837 if (Cnrs[z].ss[x].all)
838 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
839 MPFROMP(Cnrs[z].ss[x].pci),
840 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]841 }
[1565]842 DosSleep(0); // Allow other windows to update
[551]843 }
844 break;
845 case IDM_SELECTMORE:
846 for (z = 0; z < numwindows; z++) {
847 for (x = 0; x < Cnrs[z].numfiles; x++) {
848 if (!Cnrs[z].ss[x].unique)
849 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
850 MPFROMP(Cnrs[z].ss[x].pci),
851 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]852 }
[1565]853 DosSleep(0); // Allow other windows to update
[551]854 }
855 break;
856 case IDM_SELECTONE:
857 for (z = 0; z < numwindows; z++) {
858 for (x = 0; x < Cnrs[z].numfiles; x++) {
859 if (Cnrs[z].ss[x].unique)
860 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
861 MPFROMP(Cnrs[z].ss[x].pci),
862 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]863 }
[1565]864 DosSleep(0); // Allow other windows to update
[551]865 }
866 break;
867 case IDM_SELECTNEWER:
868 for (z = 0; z < numwindows; z++) {
869 for (x = 0; x < Cnrs[z].numfiles; x++) {
870 if (Cnrs[z].ss[x].newest)
871 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
872 MPFROMP(Cnrs[z].ss[x].pci),
873 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]874 }
[1565]875 DosSleep(0); // Allow other windows to update
[551]876 }
877 break;
878 case IDM_SELECTOLDER:
879 for (z = 0; z < numwindows; z++) {
880 for (x = 0; x < Cnrs[z].numfiles; x++) {
881 if (Cnrs[z].ss[x].oldest)
882 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
883 MPFROMP(Cnrs[z].ss[x].pci),
884 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]885 }
[1565]886 DosSleep(0); // Allow other windows to update
[551]887 }
888 break;
889 case IDM_SELECTBIGGER:
890 for (z = 0; z < numwindows; z++) {
891 for (x = 0; x < Cnrs[z].numfiles; x++) {
892 if (Cnrs[z].ss[x].largest)
893 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
894 MPFROMP(Cnrs[z].ss[x].pci),
895 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]896 }
[1565]897 DosSleep(0); // Allow other windows to update
[551]898 }
899 break;
900 case IDM_SELECTSMALLER:
901 for (z = 0; z < numwindows; z++) {
902 for (x = 0; x < Cnrs[z].numfiles; x++) {
903 if (Cnrs[z].ss[x].smallest)
904 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
905 MPFROMP(Cnrs[z].ss[x].pci),
906 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]907 }
[1565]908 DosSleep(0); // Allow other windows to update
[551]909 }
910 break;
[2]911
[551]912 case IDM_DESELECTBOTH:
913 for (z = 0; z < numwindows; z++) {
914 for (x = 0; x < Cnrs[z].numfiles; x++) {
915 if (Cnrs[z].ss[x].all)
916 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
917 MPFROMP(Cnrs[z].ss[x].pci),
918 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]919 }
[1565]920 DosSleep(0); // Allow other windows to update
[551]921 }
922 break;
923 case IDM_DESELECTMORE:
924 for (z = 0; z < numwindows; z++) {
925 for (x = 0; x < Cnrs[z].numfiles; x++) {
926 if (!Cnrs[z].ss[x].unique)
927 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
928 MPFROMP(Cnrs[z].ss[x].pci),
929 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]930 }
[1565]931 DosSleep(0); // Allow other windows to update
[551]932 }
933 break;
934 case IDM_DESELECTONE:
935 for (z = 0; z < numwindows; z++) {
936 for (x = 0; x < Cnrs[z].numfiles; x++) {
937 if (Cnrs[z].ss[x].unique)
938 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
939 MPFROMP(Cnrs[z].ss[x].pci),
940 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]941 }
[1565]942 DosSleep(0); // Allow other windows to update
[551]943 }
944 break;
945 case IDM_DESELECTNEWER:
946 for (z = 0; z < numwindows; z++) {
947 for (x = 0; x < Cnrs[z].numfiles; x++) {
948 if (Cnrs[z].ss[x].newest)
949 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
950 MPFROMP(Cnrs[z].ss[x].pci),
951 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]952 }
[1565]953 DosSleep(0); // Allow other windows to update
[551]954 }
955 break;
956 case IDM_DESELECTOLDER:
957 for (z = 0; z < numwindows; z++) {
958 for (x = 0; x < Cnrs[z].numfiles; x++) {
959 if (Cnrs[z].ss[x].oldest)
960 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
961 MPFROMP(Cnrs[z].ss[x].pci),
962 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]963 }
[1565]964 DosSleep(0); // Allow other windows to update
[551]965 }
966 break;
967 case IDM_DESELECTBIGGER:
968 for (z = 0; z < numwindows; z++) {
969 for (x = 0; x < Cnrs[z].numfiles; x++) {
970 if (Cnrs[z].ss[x].largest)
971 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
972 MPFROMP(Cnrs[z].ss[x].pci),
973 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]974 }
[1565]975 DosSleep(0); // Allow other windows to update
[551]976 }
977 break;
978 case IDM_DESELECTSMALLER:
979 for (z = 0; z < numwindows; z++) {
980 for (x = 0; x < Cnrs[z].numfiles; x++) {
981 if (Cnrs[z].ss[x].smallest)
982 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
983 MPFROMP(Cnrs[z].ss[x].pci),
984 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]985 }
[1565]986 DosSleep(0); // Allow other windows to update
[551]987 }
988 break;
[2]989 }
990
[551]991 FreeCnrs(Cnrs, numwindows);
[2]992}
[793]993
994#pragma alloc_text(SELECT,UnHilite,SelectAll,DeselectAll,MarkAll,SetMask)
995#pragma alloc_text(SELECT,SelectList)
996#pragma alloc_text(SELECT1,Deselect,HideAll,RemoveAll,ExpandAll,InvertAll)
997#pragma alloc_text(SELECT4,FreeCnrs,SpecialSelect2,CompSSNames,CompSSNamesB)
Note: See TracBrowser for help on using the repository browser.