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
Line 
1
2/***********************************************************************
3
4 $Id: select.c 1039 2008-07-05 22:16:21Z 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#include "fortify.h"
51
52static PSZ pszSrcFile = __FILE__;
53
54VOID UnHilite(HWND hwndCnr, BOOL all, CHAR *** list, ULONG ulItemsToUnHilite)
55{
56 PCNRITEM pci;
57 UINT numfiles = 0, numalloc = 0;
58 UINT x = 0;
59 INT attribute = CRA_CURSORED;
60
61 if (all && list && *list) {
62 FreeList(*list);
63 *list = NULL;
64 }
65 pci = (PCNRITEM) CurrentRecord(hwndCnr);
66 if (pci && (INT)pci != -1) {
67 if (pci->rc.flRecordAttr & CRA_SELECTED) {
68 attribute = CRA_SELECTED;
69 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
70 MPFROMSHORT(attribute));
71 }
72 while (pci && (INT)pci != -1) {
73 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
74 MPFROM2SHORT(FALSE, CRA_SELECTED));
75 if (!all)
76 break;
77 // Count is one extra to ensure non-zero elsewhere
78 // x is 0 based index
79 if (x + 2 == ulItemsToUnHilite)
80 break;
81 if (list)
82 AddToList(pci->pszFileName, list, &numfiles, &numalloc);
83 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
84 MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
85 x++;
86 }
87 }
88}
89
90VOID SelectList(HWND hwndCnr, BOOL partial, BOOL deselect, BOOL clearfirst,
91 PCNRITEM pciParent, PSZ filename, CHAR ** list)
92{
93
94 PCNRITEM pci;
95 register INT x;
96 BOOL foundone = FALSE;
97 ULONG errs = 0;
98
99 if (clearfirst && !deselect)
100 UnHilite(hwndCnr, TRUE, NULL, 0);
101 if (list && list[0]) {
102 for (x = 0; list[x]; x++) {
103 pci = FindCnrRecord(hwndCnr,
104 list[x], pciParent, partial, partial, TRUE);
105 if (pci) {
106 WinSendMsg(hwndCnr,
107 CM_SETRECORDEMPHASIS,
108 MPFROMP(pci),
109 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
110 CRA_SELECTED));
111 foundone = TRUE;
112 }
113 }
114 if (!foundone)
115 Runtime_Error(pszSrcFile, __LINE__, "select failed");
116 }
117 else if (filename && *filename) {
118
119 FILE *fp;
120 CHAR input[1024], *p;
121
122 fp = _fsopen(filename, "r", SH_DENYNO);
123 if (fp) {
124 while (!feof(fp)) {
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++;
151 if (errs > 50) { /* prevent runaway on bad file */
152
153 APIRET ret;
154
155 ret = saymsg(MB_YESNO,
156 hwndCnr,
157 GetPString(IDS_POSSIBLEERRORTEXT),
158 GetPString(IDS_MAYNOTBELISTTEXT), filename);
159 if (ret == MBID_NO)
160 break;
161 errs = 0;
162 }
163 }
164 fclose(fp);
165 }
166 }
167}
168
169VOID SelectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
170 PSZ text, BOOL is_arc)
171{
172
173 PCNRITEM pci;
174 BOOL markit;
175 PSZ file;
176 PSZ pszToMatch;
177 MASK Mask;
178 INT x;
179 ULONG textlen = 0;
180
181 if (text)
182 textlen = strlen(text);
183 memset(&Mask, 0, sizeof(Mask));
184 if (maskstr)
185 SetMask(maskstr, &Mask);
186 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
187 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
188 while (pci && (INT)pci != -1) {
189
190 markit = FALSE;
191
192 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
193 if (!is_arc) {
194 if (files && ~pci->attrFile & FILE_DIRECTORY)
195 markit = TRUE;
196 if (dirs && pci->attrFile & FILE_DIRECTORY)
197 markit = TRUE;
198 }
199 else
200 markit = TRUE;
201 if (maskstr && *maskstr && markit) {
202 markit = FALSE;
203 // Point a filename part
204 file = strrchr(pci->pszFileName, '\\');
205 if (!file)
206 file = strrchr(pci->pszFileName, ':');
207 if (file)
208 file++;
209 else
210 file = pci->pszFileName;
211 for (x = 0; Mask.pszMasks[x]; x++) {
212 if (*Mask.pszMasks[x]) {
213 if ((strchr(Mask.pszMasks[x], '\\') ||
214 strchr(Mask.pszMasks[x], ':')))
215 pszToMatch = pci->pszFileName;
216 else
217 pszToMatch = file;
218 if (*Mask.pszMasks[x] != '/') {
219 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE)) {
220 markit = TRUE;
221 }
222 }
223 else {
224 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
225 markit = FALSE;
226 break;
227 }
228 }
229 }
230 } // for
231 }
232 }
233
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;
243
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
257 break;
258 } // while
259 fclose(inputFile);
260 }
261 free(input);
262 DosSleep(1);
263 }
264 }
265 else
266 markit = FALSE;
267 }
268
269 if (markit)
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
275}
276
277VOID DeselectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
278 PSZ text, BOOL is_arc)
279{
280 PCNRITEM pci;
281 BOOL unmarkit;
282 PSZ file;
283 PSZ pszToMatch;
284 MASK Mask;
285 register INT x;
286 ULONG textlen = 0;
287
288 if (text)
289 textlen = strlen(text);
290 memset(&Mask, 0, sizeof(Mask));
291 if (maskstr && *maskstr)
292 SetMask(maskstr, &Mask);
293 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
294 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
295 while (pci && (INT)pci != -1) {
296 unmarkit = FALSE;
297 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
298 if (!is_arc) {
299 if (files && ~pci->attrFile & FILE_DIRECTORY)
300 unmarkit = TRUE;
301 if (dirs && (pci->attrFile & FILE_DIRECTORY))
302 unmarkit = TRUE;
303 }
304 else
305 unmarkit = TRUE;
306 if (maskstr && *maskstr && unmarkit) {
307 unmarkit = FALSE;
308 file = strrchr(pci->pszFileName, '\\');
309 if (!file)
310 file = strrchr(pci->pszFileName, ':');
311 if (file)
312 file++;
313 else
314 file = pci->pszFileName;
315 for (x = 0; Mask.pszMasks[x]; x++) {
316 if (*Mask.pszMasks[x]) {
317 if (strchr(Mask.pszMasks[x], '\\') ||
318 strchr(Mask.pszMasks[x], ':'))
319 pszToMatch = pci->pszFileName;
320 else
321 pszToMatch = file;
322 if (*Mask.pszMasks[x] != '/') {
323 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE))
324 unmarkit = TRUE;
325 }
326 else {
327 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
328 unmarkit = FALSE;
329 break;
330 }
331 }
332 }
333 }
334 }
335 }
336
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;
346
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
360 break;
361 } // while
362 fclose(inputFile);
363 }
364 free(input);
365 DosSleep(1);
366 }
367 }
368 else
369 unmarkit = FALSE;
370 }
371
372 if (unmarkit)
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));
378 }
379}
380
381VOID Deselect(HWND hwndCnr)
382{
383 PCNRITEM pcil;
384
385 pcil = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
386 MPFROMLONG(CMA_FIRST),
387 MPFROMSHORT(CRA_SELECTED));
388 while (pcil && (INT)pcil != -1) {
389 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pcil),
390 MPFROM2SHORT(FALSE, CRA_SELECTED));
391 pcil = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pcil),
392 MPFROMSHORT(CRA_SELECTED));
393 }
394}
395
396//=== HideAll() Hide all selected records ===
397
398VOID HideAll(HWND hwndCnr)
399{
400 PCNRITEM pci, pciH;
401 INT attribute = CRA_CURSORED;
402 CNRINFO cnri;
403 BOOL didone = FALSE;
404
405 memset(&cnri, 0, sizeof(CNRINFO));
406 cnri.cb = sizeof(CNRINFO);
407 WinSendMsg(hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
408 MPFROMLONG(sizeof(CNRINFO)));
409 pci = (PCNRITEM) CurrentRecord(hwndCnr);
410 if (pci && (INT)pci != -1) {
411 if (pci->rc.flRecordAttr & CRA_SELECTED) {
412 attribute = CRA_SELECTED;
413 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
414 MPFROMSHORT(attribute));
415 }
416 }
417 while (pci && (INT)pci != -1) {
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));
423 pci->rc.flRecordAttr |= CRA_FILTERED;
424 didone = TRUE;
425 if (fSyncUpdates) {
426 if (cnri.flWindowAttr & CV_DETAIL)
427 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
428 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
429 else
430 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci),
431 MPFROM2SHORT(1, CMA_REPOSITION | CMA_ERASE));
432 }
433 pci = pciH;
434 }
435 if (didone && !fSyncUpdates)
436 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
437 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
438}
439
440VOID MarkAll(HWND hwndCnr, BOOL quitit, BOOL target, BOOL source)
441{
442 PCNRITEM pci;
443 INT attribute = CRA_CURSORED;
444
445 if (quitit)
446 attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
447 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
448 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
449 if (pci && (INT)pci != -1) {
450 if (attribute == CRA_CURSORED) {
451 if (pci->rc.flRecordAttr & CRA_SELECTED) {
452 attribute = CRA_SELECTED;
453 pci =
454 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
455 MPFROMSHORT(attribute));
456 }
457 }
458 }
459 while (pci && (INT)pci != -1) {
460 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
461 MPFROM2SHORT(!quitit,
462 target ? CRA_TARGET : source ? CRA_SOURCE :
463 CRA_INUSE));
464 pci =
465 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
466 MPFROMSHORT(attribute));
467 }
468}
469
470VOID RemoveAll(HWND hwndCnr, ULONGLONG * pullTotalBytes,
471 ULONG * pulTotalFiles)
472{
473 PCNRITEM pci;
474 INT attribute = CRA_CURSORED;
475 BOOL didone = FALSE;
476
477 pci = (PCNRITEM) CurrentRecord(hwndCnr);
478 if (pci && (INT)pci != -1) {
479 if (pci->rc.flRecordAttr & CRA_SELECTED) {
480 attribute = CRA_SELECTED;
481 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
482 MPFROMSHORT(attribute));
483 }
484 }
485 while (pci && (INT)pci != -1) {
486 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
487 didone = TRUE;
488 if (pulTotalFiles)
489 *pulTotalFiles -= 1;
490 if (pullTotalBytes)
491 *pullTotalBytes -= (pci->cbFile + pci->easize);
492 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
493 MPFROM2SHORT(0, CRA_SELECTED));
494 if (fSyncUpdates)
495 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
496 else
497 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE);
498 if (attribute == CRA_CURSORED)
499 break;
500 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
501 MPFROMSHORT(attribute));
502 }
503 else
504 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
505 MPFROMSHORT(attribute));
506 }
507 if (didone && !fSyncUpdates)
508 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
509 MPFROM2SHORT(0, CMA_REPOSITION));
510}
511
512//== SetMask() Convert mask string to array of pointers to masks ==
513
514VOID SetMask(PSZ maskstr, MASK * mask)
515{
516 UINT x;
517 PSZ p;
518
519 if (maskstr)
520 strcpy(mask->szMask, maskstr); // Got new mask string
521 // Build array of pointers
522 p = mask->szMaskCopy;
523 strcpy(p, mask->szMask);
524 // Allow up to 25 masks - ignore extras
525 for (x = 0; *p && x < 25; x++) {
526 mask->pszMasks[x] = p;
527 while (*p && *p != ';')
528 p++; // Find separator
529 if (*p) {
530 *p = 0; // Replace ;
531 p++;
532 }
533 } // for
534 mask->pszMasks[x] = NULL; // Mark end
535}
536
537VOID ExpandAll(HWND hwndCnr, BOOL expand, PCNRITEM pciParent)
538{
539 PCNRITEM pci;
540
541 if (!pciParent)
542 pciParent = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
543 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
544 if (pciParent) {
545 if (expand && ~pciParent->rc.flRecordAttr & CRA_EXPANDED)
546 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciParent), MPVOID);
547 else if (!expand && (pciParent->rc.flRecordAttr & CRA_EXPANDED))
548 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciParent), MPVOID);
549 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
550 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
551 if (pci)
552 DosSleep(0);
553 while (pci && (INT)pci != -1) {
554 ExpandAll(hwndCnr, expand, pci);
555 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
556 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
557 }
558 }
559 DosSleep(0);
560}
561
562VOID InvertAll(HWND hwndCnr)
563{
564 PCNRITEM pci;
565
566 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
567 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
568 while (pci && (INT)pci != -1) {
569 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
570 if (~pci->rc.flRecordAttr & CRA_SELECTED)
571 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
572 MPFROM2SHORT(TRUE, CRA_SELECTED));
573 else
574 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
575 MPFROM2SHORT(FALSE, CRA_SELECTED));
576 }
577 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
578 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
579 }
580}
581
582struct SS
583{
584 PCNRITEM pci;
585 BOOL unique, all, smallest, largest, newest, oldest;
586};
587
588struct Cnr
589{
590 HWND hwndCnr;
591 ULONG numfiles;
592 struct SS *ss;
593};
594
595static int CompSSNamesB(const void *s1, const void *s2)
596{
597 struct SS *ss2 = (struct SS *)s2;
598
599 return stricmp((PSZ)s1, ss2->pci->pszFileName);
600}
601
602static int CompSSNames(const void *s1, const void *s2)
603{
604 struct SS *ss1 = (struct SS *)s1;
605 struct SS *ss2 = (struct SS *)s2;
606
607 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
608}
609
610VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
611{
612 register INT z;
613
614 for (z = 0; z < numw; z++) {
615 xfree(Cnrs[z].ss, pszSrcFile, __LINE__);
616 }
617 xfree(Cnrs, pszSrcFile, __LINE__);
618 DosPostEventSem(CompactSem);
619}
620
621/**
622 * Do select actions for single container
623 *
624 */
625
626VOID SpecialSelect2(HWND hwndParent, INT action)
627{
628 PCNRITEM pci;
629 HENUM henum;
630 HWND hwnd;
631 INT numwindows = 0, w, x, z, cmp = 0;
632 struct Cnr *Cnrs = NULL;
633 struct SS *bsres;
634
635 if (!hwndParent)
636 return;
637
638 /* count directory containers, build array of hwnds */
639 henum = WinBeginEnumWindows(hwndParent);
640 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
641 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
642 Cnrs =
643 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
644 __LINE__);
645 if (!Cnrs) {
646 Notify(GetPString(IDS_OUTOFMEMORY));
647 return;
648 }
649 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
650 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
651 FID_CLIENT),
652 DIR_CNR);
653 numwindows++;
654 }
655 }
656 WinEndEnumWindows(henum);
657 if (numwindows < 2) {
658 FreeCnrs(Cnrs, numwindows);
659 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
660 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
661 return;
662 }
663 if (numwindows > 4) {
664 WinSendMsg(Cnrs[0].
665 hwndCnr,
666 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
667 DosSleep(0); //26 Aug 07 GKY 1
668 }
669
670 /* count records, build array of pointers to records */
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));
676 x = 0;
677 while (pci && (INT)pci != -1) {
678 if (~pci->rc.flRecordAttr & CRA_FILTERED &&
679 ~pci->attrFile & FILE_DIRECTORY) {
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++;
691 }
692 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
693 CM_QUERYRECORD,
694 MPFROMP(pci),
695 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
696 }
697 DosSleep(0); //26 Aug 07 GKY 1
698 Cnrs[z].numfiles = x;
699 if (Cnrs[z].numfiles)
700 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
701 }
702
703 for (z = 0; z < numwindows; z++) {
704 for (x = 0; x < Cnrs[z].numfiles; x++) {
705 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
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;
721 cmp = TestCDates(&bsres->pci->date, &bsres->pci->time,
722 &Cnrs[z].ss[x].pci->date, &Cnrs[z].ss[x].pci->time);
723 /*(Cnrs[z].ss[x].pci->date.year >
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.
756 seconds) ? FALSE : FALSE;*/
757 if (cmp != 1)
758 Cnrs[z].ss[x].newest = FALSE;
759 /*cmp =
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.
793 seconds) ? FALSE : FALSE;*/
794 if (cmp != -1)
795 Cnrs[z].ss[x].oldest = FALSE;
796 cmp = 0;
797 break;
798 }
799 else
800 Cnrs[z].ss[x].all = FALSE;
801 }
802 }
803 if (Cnrs[z].ss[x].unique)
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;
806 DosSleep(1);
807 }
808 DosSleep(1);
809 }
810
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));
819 }
820 DosSleep(0); //26 Aug 07 GKY 1
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));
830 }
831 DosSleep(0); //26 Aug 07 GKY 1
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));
841 }
842 DosSleep(0); //26 Aug 07 GKY 1
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));
852 }
853 DosSleep(0); //26 Aug 07 GKY 1
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));
863 }
864 DosSleep(0); //26 Aug 07 GKY 1
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));
874 }
875 DosSleep(0); //26 Aug 07 GKY 1
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));
885 }
886 DosSleep(0); //26 Aug 07 GKY 1
887 }
888 break;
889
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));
897 }
898 DosSleep(0); //26 Aug 07 GKY 1
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));
908 }
909 DosSleep(0); //26 Aug 07 GKY 1
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));
919 }
920 DosSleep(0); //26 Aug 07 GKY 1
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));
930 }
931 DosSleep(0); //26 Aug 07 GKY 1
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));
941 }
942 DosSleep(0); //26 Aug 07 GKY 1
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));
952 }
953 DosSleep(0); //26 Aug 07 GKY 1
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));
963 }
964 DosSleep(0); //26 Aug 07 GKY 1
965 }
966 break;
967 }
968
969 FreeCnrs(Cnrs, numwindows);
970}
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.