source: trunk/dll/select.c@ 1226

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

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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