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