source: trunk/dll/select.c@ 985

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

Update sizes dialog (ticket 44); Make max command line length user settable (ticket 199); use xfree for free in most cases (ticket 212); initial code to check for valid ini file (ticket 102); Some additional refactoring and structure rework; Some documentation updates;

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: select.c 985 2008-03-01 01:37:14Z gyoung $
5
6 Container item selection support routines
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2008 Steven H. Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 25 May 05 SHL Rework for ULONGLONG
13 06 Jun 05 SHL Drop unused code
14 06 Jul 06 SHL Support compare content (IDM_SELECTSAMECONTENT)
15 13 Jul 06 SHL Use Runtime_Error
16 29 Jul 06 SHL Use xfgets_bstripcr
17 15 Aug 06 SHL Rework SetMask args and logic
18 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
19 19 Apr 07 SHL Sync with NumItemsToUnhilite mods
20 12 May 07 SHL Use dcd->ulItemsToUnHilite
21 14 Jun 07 SHL SelectAll: make odd expression go away
22 02 Aug 07 SHL Sync with CNRITEM mods
23 04 Aug 07 SHL Use Runtime_Error
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
27 14 Aug 07 SHL Revert ExpandAll DosSleep to 0
28 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
29 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
30 12 Jan 08 SHL Localize SpecialSelect in comp.c
31 29 Feb 08 GKY Use xfree where appropriate
32
33***********************************************************************/
34
35#include <stdlib.h>
36#include <string.h>
37#include <share.h>
38#include <io.h>
39
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
49#include "fm3dll.h"
50
51static PSZ pszSrcFile = __FILE__;
52
53VOID UnHilite(HWND hwndCnr, BOOL all, CHAR *** list, ULONG ulItemsToUnHilite)
54{
55 PCNRITEM pci;
56 UINT numfiles = 0, numalloc = 0;
57 UINT x = 0;
58 INT attribute = CRA_CURSORED;
59
60 if (all && list && *list) {
61 FreeList(*list);
62 *list = NULL;
63 }
64 pci = (PCNRITEM) CurrentRecord(hwndCnr);
65 if (pci && (INT)pci != -1) {
66 if (pci->rc.flRecordAttr & CRA_SELECTED) {
67 attribute = CRA_SELECTED;
68 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
69 MPFROMSHORT(attribute));
70 }
71 while (pci && (INT)pci != -1) {
72 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
73 MPFROM2SHORT(FALSE, CRA_SELECTED));
74 if (!all)
75 break;
76 // Count is one extra to ensure non-zero elsewhere
77 // x is 0 based index
78 if (x + 2 == ulItemsToUnHilite)
79 break;
80 if (list)
81 AddToList(pci->pszFileName, list, &numfiles, &numalloc);
82 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
83 MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
84 x++;
85 }
86 }
87}
88
89VOID SelectList(HWND hwndCnr, BOOL partial, BOOL deselect, BOOL clearfirst,
90 PCNRITEM pciParent, PSZ filename, CHAR ** list)
91{
92
93 PCNRITEM pci;
94 register INT x;
95 BOOL foundone = FALSE;
96 ULONG errs = 0;
97
98 if (clearfirst && !deselect)
99 UnHilite(hwndCnr, TRUE, NULL, 0);
100 if (list && list[0]) {
101 for (x = 0; list[x]; x++) {
102 pci = FindCnrRecord(hwndCnr,
103 list[x], pciParent, partial, partial, TRUE);
104 if (pci) {
105 WinSendMsg(hwndCnr,
106 CM_SETRECORDEMPHASIS,
107 MPFROMP(pci),
108 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
109 CRA_SELECTED));
110 foundone = TRUE;
111 }
112 }
113 if (!foundone)
114 Runtime_Error(pszSrcFile, __LINE__, "select failed");
115 }
116 else if (filename && *filename) {
117
118 FILE *fp;
119 CHAR input[1024], *p;
120
121 fp = _fsopen(filename, "r", SH_DENYNO);
122 if (fp) {
123 while (!feof(fp)) {
124 if (!xfgets_bstripcr(input, sizeof(input), fp, pszSrcFile, __LINE__))
125 break;
126 if (*input == '\"') {
127 memmove(input, input + 1, strlen(input) + 1);
128 lstrip(input);
129 p = strchr(input, '\"');
130 if (p)
131 *p = 0;
132 rstrip(input);
133 }
134 else {
135 p = strchr(input, ' ');
136 if (p)
137 *p = 0;
138 }
139 /* input now contains name of file to select */
140 pci = FindCnrRecord(hwndCnr,
141 input, pciParent, partial, partial, TRUE);
142 if (pci) /* found it? */
143 WinSendMsg(hwndCnr,
144 CM_SETRECORDEMPHASIS,
145 MPFROMP(pci),
146 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
147 CRA_SELECTED));
148 else
149 errs++;
150 if (errs > 50) { /* prevent runaway on bad file */
151
152 APIRET ret;
153
154 ret = saymsg(MB_YESNO,
155 hwndCnr,
156 GetPString(IDS_POSSIBLEERRORTEXT),
157 GetPString(IDS_MAYNOTBELISTTEXT), filename);
158 if (ret == MBID_NO)
159 break;
160 errs = 0;
161 }
162 }
163 fclose(fp);
164 }
165 }
166}
167
168VOID SelectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
169 PSZ text, BOOL is_arc)
170{
171
172 PCNRITEM pci;
173 BOOL markit;
174 PSZ file;
175 PSZ pszToMatch;
176 MASK Mask;
177 INT x;
178 ULONG textlen = 0;
179
180 if (text)
181 textlen = strlen(text);
182 memset(&Mask, 0, sizeof(Mask));
183 if (maskstr)
184 SetMask(maskstr, &Mask);
185 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
186 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
187 while (pci && (INT)pci != -1) {
188
189 markit = FALSE;
190
191 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
192 if (!is_arc) {
193 if (files && ~pci->attrFile & FILE_DIRECTORY)
194 markit = TRUE;
195 if (dirs && pci->attrFile & FILE_DIRECTORY)
196 markit = TRUE;
197 }
198 else
199 markit = TRUE;
200 if (maskstr && *maskstr && markit) {
201 markit = FALSE;
202 // Point a filename part
203 file = strrchr(pci->pszFileName, '\\');
204 if (!file)
205 file = strrchr(pci->pszFileName, ':');
206 if (file)
207 file++;
208 else
209 file = pci->pszFileName;
210 for (x = 0; Mask.pszMasks[x]; x++) {
211 if (*Mask.pszMasks[x]) {
212 if ((strchr(Mask.pszMasks[x], '\\') ||
213 strchr(Mask.pszMasks[x], ':')))
214 pszToMatch = pci->pszFileName;
215 else
216 pszToMatch = file;
217 if (*Mask.pszMasks[x] != '/') {
218 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE)) {
219 markit = TRUE;
220 }
221 }
222 else {
223 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
224 markit = FALSE;
225 break;
226 }
227 }
228 }
229 } // for
230 }
231 }
232
233 if (markit && text && *text) {
234 if (~pci->attrFile & FILE_DIRECTORY) {
235 PSZ input;
236 markit = FALSE;
237 input = xmalloc(65537, pszSrcFile, __LINE__);
238 if (input) {
239 ULONG pos;
240 LONG len;
241 FILE *inputFile;
242
243 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
244 pos = ftell(inputFile);
245 while (!feof(inputFile)) {
246 if (pos)
247 fseek(inputFile, pos - 256, SEEK_SET);
248 len = fread(input, 1, 65536, inputFile);
249 if (len >= 0) {
250 if (findstring(text, textlen, input, len, FALSE)) {
251 markit = TRUE;
252 break;
253 }
254 }
255 else
256 break;
257 } // while
258 fclose(inputFile);
259 }
260 xfree(input);
261 DosSleep(1);
262 }
263 }
264 else
265 markit = FALSE;
266 }
267
268 if (markit)
269 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
270 MPFROM2SHORT(TRUE, CRA_SELECTED));
271 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
272 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
273 } // while
274}
275
276VOID DeselectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
277 PSZ text, BOOL is_arc)
278{
279 PCNRITEM pci;
280 BOOL unmarkit;
281 PSZ file;
282 PSZ pszToMatch;
283 MASK Mask;
284 register INT x;
285 ULONG textlen = 0;
286
287 if (text)
288 textlen = strlen(text);
289 memset(&Mask, 0, sizeof(Mask));
290 if (maskstr && *maskstr)
291 SetMask(maskstr, &Mask);
292 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
293 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
294 while (pci && (INT)pci != -1) {
295 unmarkit = FALSE;
296 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
297 if (!is_arc) {
298 if (files && ~pci->attrFile & FILE_DIRECTORY)
299 unmarkit = TRUE;
300 if (dirs && (pci->attrFile & FILE_DIRECTORY))
301 unmarkit = TRUE;
302 }
303 else
304 unmarkit = TRUE;
305 if (maskstr && *maskstr && unmarkit) {
306 unmarkit = FALSE;
307 file = strrchr(pci->pszFileName, '\\');
308 if (!file)
309 file = strrchr(pci->pszFileName, ':');
310 if (file)
311 file++;
312 else
313 file = pci->pszFileName;
314 for (x = 0; Mask.pszMasks[x]; x++) {
315 if (*Mask.pszMasks[x]) {
316 if (strchr(Mask.pszMasks[x], '\\') ||
317 strchr(Mask.pszMasks[x], ':'))
318 pszToMatch = pci->pszFileName;
319 else
320 pszToMatch = file;
321 if (*Mask.pszMasks[x] != '/') {
322 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE))
323 unmarkit = TRUE;
324 }
325 else {
326 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
327 unmarkit = FALSE;
328 break;
329 }
330 }
331 }
332 }
333 }
334 }
335
336 if (unmarkit && text && *text) {
337 if (~pci->attrFile & FILE_DIRECTORY) {
338 PSZ input;
339 unmarkit = FALSE;
340 input = xmalloc(65537, pszSrcFile, __LINE__);
341 if (input) {
342 ULONG pos;
343 LONG len;
344 FILE *inputFile;
345
346 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
347 pos = ftell(inputFile);
348 while (!feof(inputFile)) {
349 if (pos)
350 fseek(inputFile, pos - 256, SEEK_SET);
351 len = fread(input, 1, 65536, inputFile);
352 if (len >= 0) {
353 if (findstring(text, textlen, input, len, FALSE)) {
354 unmarkit = TRUE;
355 break;
356 }
357 }
358 else
359 break;
360 } // while
361 fclose(inputFile);
362 }
363 xfree(input);
364 DosSleep(1);
365 }
366 }
367 else
368 unmarkit = FALSE;
369 }
370
371 if (unmarkit)
372 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, pci,
373 MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED |
374 CRA_INUSE | CRA_SOURCE));
375 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
376 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
377 }
378}
379
380VOID Deselect(HWND hwndCnr)
381{
382 PCNRITEM pcil;
383
384 pcil = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
385 MPFROMLONG(CMA_FIRST),
386 MPFROMSHORT(CRA_SELECTED));
387 while (pcil && (INT)pcil != -1) {
388 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pcil),
389 MPFROM2SHORT(FALSE, CRA_SELECTED));
390 pcil = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pcil),
391 MPFROMSHORT(CRA_SELECTED));
392 }
393}
394
395//=== HideAll() Hide all selected records ===
396
397VOID HideAll(HWND hwndCnr)
398{
399 PCNRITEM pci, pciH;
400 INT attribute = CRA_CURSORED;
401 CNRINFO cnri;
402 BOOL didone = FALSE;
403
404 memset(&cnri, 0, sizeof(CNRINFO));
405 cnri.cb = sizeof(CNRINFO);
406 WinSendMsg(hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
407 MPFROMLONG(sizeof(CNRINFO)));
408 pci = (PCNRITEM) CurrentRecord(hwndCnr);
409 if (pci && (INT)pci != -1) {
410 if (pci->rc.flRecordAttr & CRA_SELECTED) {
411 attribute = CRA_SELECTED;
412 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
413 MPFROMSHORT(attribute));
414 }
415 }
416 while (pci && (INT)pci != -1) {
417 pciH = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
418 MPFROMSHORT(attribute));
419 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
420 MPFROM2SHORT(FALSE, CRA_CURSORED | CRA_SELECTED |
421 CRA_INUSE | CRA_SOURCE));
422 pci->rc.flRecordAttr |= CRA_FILTERED;
423 didone = TRUE;
424 if (fSyncUpdates) {
425 if (cnri.flWindowAttr & CV_DETAIL)
426 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
427 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
428 else
429 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci),
430 MPFROM2SHORT(1, CMA_REPOSITION | CMA_ERASE));
431 }
432 pci = pciH;
433 }
434 if (didone && !fSyncUpdates)
435 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
436 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
437}
438
439VOID MarkAll(HWND hwndCnr, BOOL quitit, BOOL target, BOOL source)
440{
441 PCNRITEM pci;
442 INT attribute = CRA_CURSORED;
443
444 if (quitit)
445 attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
446 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
447 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
448 if (pci && (INT)pci != -1) {
449 if (attribute == CRA_CURSORED) {
450 if (pci->rc.flRecordAttr & CRA_SELECTED) {
451 attribute = CRA_SELECTED;
452 pci =
453 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
454 MPFROMSHORT(attribute));
455 }
456 }
457 }
458 while (pci && (INT)pci != -1) {
459 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
460 MPFROM2SHORT(!quitit,
461 target ? CRA_TARGET : source ? CRA_SOURCE :
462 CRA_INUSE));
463 pci =
464 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
465 MPFROMSHORT(attribute));
466 }
467}
468
469VOID RemoveAll(HWND hwndCnr, ULONGLONG * pullTotalBytes,
470 ULONG * pulTotalFiles)
471{
472 PCNRITEM pci;
473 INT attribute = CRA_CURSORED;
474 BOOL didone = FALSE;
475
476 pci = (PCNRITEM) CurrentRecord(hwndCnr);
477 if (pci && (INT)pci != -1) {
478 if (pci->rc.flRecordAttr & CRA_SELECTED) {
479 attribute = CRA_SELECTED;
480 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
481 MPFROMSHORT(attribute));
482 }
483 }
484 while (pci && (INT)pci != -1) {
485 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
486 didone = TRUE;
487 if (pulTotalFiles)
488 *pulTotalFiles -= 1;
489 if (pullTotalBytes)
490 *pullTotalBytes -= (pci->cbFile + pci->easize);
491 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
492 MPFROM2SHORT(0, CRA_SELECTED));
493 if (fSyncUpdates)
494 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
495 else
496 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE);
497 if (attribute == CRA_CURSORED)
498 break;
499 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
500 MPFROMSHORT(attribute));
501 }
502 else
503 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
504 MPFROMSHORT(attribute));
505 }
506 if (didone && !fSyncUpdates)
507 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
508 MPFROM2SHORT(0, CMA_REPOSITION));
509}
510
511//== SetMask() Convert mask string to array of pointers to masks ==
512
513VOID SetMask(PSZ maskstr, MASK * mask)
514{
515 UINT x;
516 PSZ p;
517
518 if (maskstr)
519 strcpy(mask->szMask, maskstr); // Got new mask string
520 // Build array of pointers
521 p = mask->szMaskCopy;
522 strcpy(p, mask->szMask);
523 // Allow up to 25 masks - ignore extras
524 for (x = 0; *p && x < 25; x++) {
525 mask->pszMasks[x] = p;
526 while (*p && *p != ';')
527 p++; // Find separator
528 if (*p) {
529 *p = 0; // Replace ;
530 p++;
531 }
532 } // for
533 mask->pszMasks[x] = NULL; // Mark end
534}
535
536VOID ExpandAll(HWND hwndCnr, BOOL expand, PCNRITEM pciParent)
537{
538 PCNRITEM pci;
539
540 if (!pciParent)
541 pciParent = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
542 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
543 if (pciParent) {
544 if (expand && ~pciParent->rc.flRecordAttr & CRA_EXPANDED)
545 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciParent), MPVOID);
546 else if (!expand && (pciParent->rc.flRecordAttr & CRA_EXPANDED))
547 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciParent), MPVOID);
548 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
549 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
550 if (pci)
551 DosSleep(0);
552 while (pci && (INT)pci != -1) {
553 ExpandAll(hwndCnr, expand, pci);
554 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
555 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
556 }
557 }
558 DosSleep(0);
559}
560
561VOID InvertAll(HWND hwndCnr)
562{
563 PCNRITEM pci;
564
565 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
566 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
567 while (pci && (INT)pci != -1) {
568 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
569 if (~pci->rc.flRecordAttr & CRA_SELECTED)
570 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
571 MPFROM2SHORT(TRUE, CRA_SELECTED));
572 else
573 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
574 MPFROM2SHORT(FALSE, CRA_SELECTED));
575 }
576 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
577 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
578 }
579}
580
581struct SS
582{
583 PCNRITEM pci;
584 BOOL unique, all, smallest, largest, newest, oldest;
585};
586
587struct Cnr
588{
589 HWND hwndCnr;
590 ULONG numfiles;
591 struct SS *ss;
592};
593
594static int CompSSNamesB(const void *s1, const void *s2)
595{
596 struct SS *ss2 = (struct SS *)s2;
597
598 return stricmp((PSZ)s1, ss2->pci->pszFileName);
599}
600
601static int CompSSNames(const void *s1, const void *s2)
602{
603 struct SS *ss1 = (struct SS *)s1;
604 struct SS *ss2 = (struct SS *)s2;
605
606 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
607}
608
609VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
610{
611 register INT z;
612
613 for (z = 0; z < numw; z++) {
614 xfree(Cnrs[z].ss);
615 }
616 xfree(Cnrs);
617 DosPostEventSem(CompactSem);
618}
619
620/**
621 * Do select actions for single container
622 *
623 */
624
625VOID SpecialSelect2(HWND hwndParent, INT action)
626{
627 PCNRITEM pci;
628 HENUM henum;
629 HWND hwnd;
630 INT numwindows = 0, w, x, z, cmp = 0;
631 struct Cnr *Cnrs = NULL;
632 struct SS *bsres;
633
634 if (!hwndParent)
635 return;
636
637 /* count directory containers, build array of hwnds */
638 henum = WinBeginEnumWindows(hwndParent);
639 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
640 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
641 Cnrs =
642 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
643 __LINE__);
644 if (!Cnrs) {
645 Notify(GetPString(IDS_OUTOFMEMORY));
646 return;
647 }
648 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
649 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
650 FID_CLIENT),
651 DIR_CNR);
652 numwindows++;
653 }
654 }
655 WinEndEnumWindows(henum);
656 if (numwindows < 2) {
657 FreeCnrs(Cnrs, numwindows);
658 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
659 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
660 return;
661 }
662 if (numwindows > 4) {
663 WinSendMsg(Cnrs[0].
664 hwndCnr,
665 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
666 DosSleep(0); //26 Aug 07 GKY 1
667 }
668
669 /* count records, build array of pointers to records */
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));
675 x = 0;
676 while (pci && (INT)pci != -1) {
677 if (~pci->rc.flRecordAttr & CRA_FILTERED &&
678 ~pci->attrFile & FILE_DIRECTORY) {
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++;
690 }
691 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
692 CM_QUERYRECORD,
693 MPFROMP(pci),
694 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
695 }
696 DosSleep(0); //26 Aug 07 GKY 1
697 Cnrs[z].numfiles = x;
698 if (Cnrs[z].numfiles)
699 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
700 }
701
702 for (z = 0; z < numwindows; z++) {
703 for (x = 0; x < Cnrs[z].numfiles; x++) {
704 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
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;
720 cmp = TestCDates(&bsres->pci->date, &bsres->pci->time,
721 &Cnrs[z].ss[x].pci->date, &Cnrs[z].ss[x].pci->time);
722 /*(Cnrs[z].ss[x].pci->date.year >
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.
755 seconds) ? FALSE : FALSE;*/
756 if (cmp != 1)
757 Cnrs[z].ss[x].newest = FALSE;
758 /*cmp =
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.
792 seconds) ? FALSE : FALSE;*/
793 if (cmp != -1)
794 Cnrs[z].ss[x].oldest = FALSE;
795 cmp = 0;
796 break;
797 }
798 else
799 Cnrs[z].ss[x].all = FALSE;
800 }
801 }
802 if (Cnrs[z].ss[x].unique)
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;
805 DosSleep(1);
806 }
807 DosSleep(1);
808 }
809
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));
818 }
819 DosSleep(0); //26 Aug 07 GKY 1
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));
829 }
830 DosSleep(0); //26 Aug 07 GKY 1
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));
840 }
841 DosSleep(0); //26 Aug 07 GKY 1
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));
851 }
852 DosSleep(0); //26 Aug 07 GKY 1
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));
862 }
863 DosSleep(0); //26 Aug 07 GKY 1
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));
873 }
874 DosSleep(0); //26 Aug 07 GKY 1
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));
884 }
885 DosSleep(0); //26 Aug 07 GKY 1
886 }
887 break;
888
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));
896 }
897 DosSleep(0); //26 Aug 07 GKY 1
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));
907 }
908 DosSleep(0); //26 Aug 07 GKY 1
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));
918 }
919 DosSleep(0); //26 Aug 07 GKY 1
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));
929 }
930 DosSleep(0); //26 Aug 07 GKY 1
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));
940 }
941 DosSleep(0); //26 Aug 07 GKY 1
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));
951 }
952 DosSleep(0); //26 Aug 07 GKY 1
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));
962 }
963 DosSleep(0); //26 Aug 07 GKY 1
964 }
965 break;
966 }
967
968 FreeCnrs(Cnrs, numwindows);
969}
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.