source: trunk/dll/select.c@ 924

Last change on this file since 924 was 924, checked in by Steven Levine, 18 years ago

Avoid error reports for R/O FAT directories (ticket #116)
Change Config->Edit and Config->Palette menus to have no default
Move SpecialSelect to comp.c

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