source: trunk/dll/select.c@ 1180

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

Ticket 187: Draft 2: Move remaining function declarations

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