[793] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: findrec.c 1877 2015-10-11 21:43:27Z gyoung $
|
---|
| 5 |
|
---|
| 6 | Copyright (c) 1993-98 M. Kimes
|
---|
[1854] | 7 | Copyright (c) 2003, 2015 Steven H.Levine
|
---|
[793] | 8 |
|
---|
| 9 | Find records
|
---|
| 10 |
|
---|
| 11 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[1361] | 12 | 28 Dec 08 GKY Containers will only scroll to the right if needed to show end of selected
|
---|
[1865] | 13 | item and will scroll left to eliminate space after a selected item. Ticket 204
|
---|
[1854] | 14 | 06 Aug 15 SHL Clean up and comment
|
---|
[1865] | 15 | 23 Aug 15 SHL Protect FindCnrRecord filename arg
|
---|
[1871] | 16 | 20 Sep 15 GKY Add a correction factor so directories don't get placed above the top of the
|
---|
| 17 | tree container when a large drive has been expanded.
|
---|
[793] | 18 |
|
---|
| 19 | ***********************************************************************/
|
---|
| 20 |
|
---|
[907] | 21 | #include <string.h>
|
---|
[1549] | 22 | #include <stdlib.h>
|
---|
[2] | 23 |
|
---|
[907] | 24 | #define INCL_LONGLONG // dircnrs.h
|
---|
| 25 |
|
---|
[2] | 26 | #include "fm3dll.h"
|
---|
[1160] | 27 | #include "findrec.h"
|
---|
[1549] | 28 | #include "errutil.h" // Dos_Error...
|
---|
[2] | 29 |
|
---|
[1549] | 30 | //static PSZ pszSrcFile = __FILE__;
|
---|
| 31 |
|
---|
[1865] | 32 | PCNRITEM FindCnrRecord(HWND hwndCnr, PCSZ filename, PCNRITEM pciParent,
|
---|
[551] | 33 | BOOL partial, BOOL partmatch, BOOL noenv)
|
---|
| 34 | {
|
---|
| 35 | SEARCHSTRING srch;
|
---|
| 36 | PCNRITEM pci;
|
---|
[1865] | 37 | PCSZ file;
|
---|
| 38 | PCSZ p;
|
---|
[2] | 39 |
|
---|
[551] | 40 | if (partial) {
|
---|
| 41 | if (strlen(filename) > 3) {
|
---|
| 42 | file = strrchr(filename, '\\');
|
---|
| 43 | if (!file) {
|
---|
| 44 | file = strrchr(filename, ':');
|
---|
| 45 | if (file)
|
---|
| 46 | file++;
|
---|
| 47 | else
|
---|
| 48 | file = filename;
|
---|
[2] | 49 | }
|
---|
| 50 | else
|
---|
[551] | 51 | file++;
|
---|
[2] | 52 | }
|
---|
| 53 | else
|
---|
| 54 | file = filename;
|
---|
| 55 | }
|
---|
| 56 | else
|
---|
| 57 | file = filename;
|
---|
[551] | 58 | memset(&srch, 0, sizeof(SEARCHSTRING));
|
---|
| 59 | srch.cb = (ULONG) sizeof(SEARCHSTRING);
|
---|
| 60 | srch.pszSearch = (PSZ) file;
|
---|
[2] | 61 | srch.fsPrefix = FALSE;
|
---|
| 62 | srch.fsCaseSensitive = FALSE;
|
---|
[1854] | 63 | srch.usView = CV_TREE;
|
---|
[551] | 64 | if (!pciParent)
|
---|
| 65 | pciParent = (PCNRITEM) CMA_FIRST;
|
---|
[2] | 66 | pci = WinSendMsg(hwndCnr,
|
---|
[1871] | 67 | CM_SEARCHSTRING, MPFROMP(&srch), MPFROMP(pciParent));
|
---|
[551] | 68 | while (pci && (INT) pci != -1) {
|
---|
| 69 | if (!noenv || (pci->flags & (RECFLAGS_ENV | RECFLAGS_UNDERENV)) == 0) {
|
---|
[1854] | 70 | // CNRITEM for file/directory
|
---|
| 71 | if (!partmatch) { // file name must match full name
|
---|
[730] | 72 | if (!stricmp(pci->pszFileName, filename))
|
---|
[1854] | 73 | return pci; // got full match
|
---|
[2] | 74 | }
|
---|
[1673] | 75 | else { // only root name must match
|
---|
[1854] | 76 | // partial match
|
---|
| 77 | if (strlen(pci->pszFileName) <= 3)
|
---|
| 78 | p = pci->pszFileName; // Root
|
---|
| 79 | else {
|
---|
[730] | 80 | p = strrchr(pci->pszFileName, '\\');
|
---|
[1854] | 81 | if (p)
|
---|
| 82 | p++; // After slash
|
---|
| 83 | else {
|
---|
[730] | 84 | p = strrchr(pci->pszFileName, ':');
|
---|
[551] | 85 | if (p)
|
---|
[1854] | 86 | p++; // After colon
|
---|
[551] | 87 | else
|
---|
[1854] | 88 | p = pci->pszFileName; // Must be bare file name
|
---|
[551] | 89 | }
|
---|
| 90 | }
|
---|
| 91 | if (!stricmp(p, file))
|
---|
[1854] | 92 | return pci; // got partial match
|
---|
[2] | 93 | }
|
---|
| 94 | }
|
---|
[551] | 95 | pci = WinSendMsg(hwndCnr, CM_SEARCHSTRING, MPFROMP(&srch), MPFROMP(pci));
|
---|
[2] | 96 | }
|
---|
[689] | 97 |
|
---|
[1673] | 98 | return NULL; // failure
|
---|
[2] | 99 | }
|
---|
| 100 |
|
---|
[551] | 101 | PCNRITEM FindParentRecord(HWND hwndCnr, PCNRITEM pciC)
|
---|
| 102 | {
|
---|
[2] | 103 |
|
---|
[551] | 104 | PCNRITEM pciP = (PCNRITEM) NULL, pci = pciC;
|
---|
[2] | 105 |
|
---|
[551] | 106 | if (pci) {
|
---|
| 107 | for (;;) {
|
---|
[2] | 108 | pciP = WinSendMsg(hwndCnr,
|
---|
[551] | 109 | CM_QUERYRECORD,
|
---|
| 110 | MPFROMP(pci),
|
---|
| 111 | MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
|
---|
| 112 | if (pciP && (INT) pciP != -1)
|
---|
| 113 | pci = pciP;
|
---|
[2] | 114 | else
|
---|
[551] | 115 | break;
|
---|
[2] | 116 | }
|
---|
| 117 | }
|
---|
| 118 | return pci;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[551] | 121 | VOID ShowCnrRecord(HWND hwndCnr, PMINIRECORDCORE pmi)
|
---|
| 122 | {
|
---|
[2] | 123 |
|
---|
[551] | 124 | QUERYRECORDRECT qrecrct;
|
---|
| 125 | RECTL rcl;
|
---|
| 126 | RECTL rclViewport;
|
---|
[1871] | 127 | RECTL rclFirst;
|
---|
| 128 | RECTL rclLast;
|
---|
| 129 | PMINIRECORDCORE pmiFirst;
|
---|
| 130 | PMINIRECORDCORE pmiLast;
|
---|
| 131 | INT correction;
|
---|
[2] | 132 |
|
---|
[1871] | 133 | pmiFirst = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
|
---|
| 134 | MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
|
---|
| 135 | pmiLast = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
|
---|
| 136 | MPFROM2SHORT(CMA_LAST, CMA_ITEMORDER));
|
---|
| 137 | WinSendMsg(hwndCnr,
|
---|
| 138 | CM_QUERYVIEWPORTRECT,
|
---|
| 139 | MPFROMP(&rclViewport), MPFROM2SHORT(CMA_WINDOW , TRUE));
|
---|
[551] | 140 | memset(&qrecrct, 0, sizeof(QUERYRECORDRECT));
|
---|
[2] | 141 | qrecrct.cb = sizeof(QUERYRECORDRECT);
|
---|
[551] | 142 | qrecrct.pRecord = (PRECORDCORE) pmi;
|
---|
[2] | 143 | qrecrct.fsExtent = (CMA_ICON | CMA_TEXT | CMA_TREEICON);
|
---|
[551] | 144 | if (!WinSendMsg(hwndCnr,
|
---|
[1865] | 145 | CM_QUERYRECORDRECT, MPFROMP(&rcl), MPFROMP(&qrecrct))) {
|
---|
[2] | 146 | qrecrct.fsExtent = CMA_TEXT | CMA_TREEICON;
|
---|
[551] | 147 | WinSendMsg(hwndCnr, CM_QUERYRECORDRECT, MPFROMP(&rcl), MPFROMP(&qrecrct));
|
---|
[2] | 148 | }
|
---|
[1871] | 149 | qrecrct.pRecord = (PRECORDCORE) pmiFirst;
|
---|
| 150 | WinSendMsg(hwndCnr, CM_QUERYRECORDRECT, MPFROMP(&rclFirst), MPFROMP(&qrecrct));
|
---|
| 151 | qrecrct.pRecord = (PRECORDCORE) pmiLast;
|
---|
| 152 | WinSendMsg(hwndCnr, CM_QUERYRECORDRECT, MPFROMP(&rclLast), MPFROMP(&qrecrct));
|
---|
| 153 | correction = 5 + ((abs(rclFirst.yTop) + abs(rclLast.yTop)) / 22500);
|
---|
[2] | 154 | WinSendMsg(hwndCnr,
|
---|
[1871] | 155 | CM_SCROLLWINDOW,
|
---|
| 156 | MPFROMSHORT(CMA_VERTICAL),
|
---|
| 157 | MPFROMLONG((rclViewport.yTop - (rcl.yTop) - correction)));
|
---|
[2] | 158 | WinSendMsg(hwndCnr,
|
---|
[551] | 159 | CM_SCROLLWINDOW,
|
---|
[1854] | 160 | MPFROMSHORT(CMA_HORIZONTAL), MPFROMLONG(rcl.xRight - rclViewport.xRight));
|
---|
[1871] | 161 |
|
---|
[2] | 162 | }
|
---|
[793] | 163 |
|
---|
| 164 | #pragma alloc_text(FINDREC,FindCnrRecord,FindParentRecord,ShowCnrRecord)
|
---|