source: trunk/dll/select.c@ 1039

Last change on this file since 1039 was 1039, checked in by Gregg Young, 17 years ago

Removed unnecessary xfrees and included fortify.h where needed; moved several misplaced (x)frees;

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