source: trunk/dll/findrec.c@ 1865

Last change on this file since 1865 was 1865, checked in by Steven Levine, 10 years ago

Correct WaitFleshWorkListEmpty typo that could corrupt heap
Protect some read-only strings from overwriting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: findrec.c 1865 2015-08-23 20:36:02Z stevenhl $
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
17***********************************************************************/
18
19#include <string.h>
20#include <stdlib.h>
21
22#define INCL_LONGLONG // dircnrs.h
23
24#include "fm3dll.h"
25#include "findrec.h"
26#include "errutil.h" // Dos_Error...
27
28//static PSZ pszSrcFile = __FILE__;
29
30PCNRITEM FindCnrRecord(HWND hwndCnr, PCSZ filename, PCNRITEM pciParent,
31 BOOL partial, BOOL partmatch, BOOL noenv)
32{
33 SEARCHSTRING srch;
34 PCNRITEM pci;
35 PCSZ file;
36 PCSZ p;
37
38 if (partial) {
39 if (strlen(filename) > 3) {
40 file = strrchr(filename, '\\');
41 if (!file) {
42 file = strrchr(filename, ':');
43 if (file)
44 file++;
45 else
46 file = filename;
47 }
48 else
49 file++;
50 }
51 else
52 file = filename;
53 }
54 else
55 file = filename;
56 memset(&srch, 0, sizeof(SEARCHSTRING));
57 srch.cb = (ULONG) sizeof(SEARCHSTRING);
58 srch.pszSearch = (PSZ) file;
59 srch.fsPrefix = FALSE;
60 srch.fsCaseSensitive = FALSE;
61 srch.usView = CV_TREE;
62 if (!pciParent)
63 pciParent = (PCNRITEM) CMA_FIRST;
64 pci = WinSendMsg(hwndCnr,
65 CM_SEARCHSTRING, MPFROMP(&srch), MPFROMP(pciParent));
66 while (pci && (INT) pci != -1) {
67 if (!noenv || (pci->flags & (RECFLAGS_ENV | RECFLAGS_UNDERENV)) == 0) {
68 // CNRITEM for file/directory
69 if (!partmatch) { // file name must match full name
70 if (!stricmp(pci->pszFileName, filename))
71 return pci; // got full match
72 }
73 else { // only root name must match
74 // partial match
75 if (strlen(pci->pszFileName) <= 3)
76 p = pci->pszFileName; // Root
77 else {
78 p = strrchr(pci->pszFileName, '\\');
79 if (p)
80 p++; // After slash
81 else {
82 p = strrchr(pci->pszFileName, ':');
83 if (p)
84 p++; // After colon
85 else
86 p = pci->pszFileName; // Must be bare file name
87 }
88 }
89 if (!stricmp(p, file))
90 return pci; // got partial match
91 }
92 }
93 pci = WinSendMsg(hwndCnr, CM_SEARCHSTRING, MPFROMP(&srch), MPFROMP(pci));
94 }
95
96 return NULL; // failure
97}
98
99PCNRITEM FindParentRecord(HWND hwndCnr, PCNRITEM pciC)
100{
101
102 PCNRITEM pciP = (PCNRITEM) NULL, pci = pciC;
103
104 if (pci) {
105 for (;;) {
106 pciP = WinSendMsg(hwndCnr,
107 CM_QUERYRECORD,
108 MPFROMP(pci),
109 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
110 if (pciP && (INT) pciP != -1)
111 pci = pciP;
112 else
113 break;
114 }
115 }
116 return pci;
117}
118
119VOID ShowCnrRecord(HWND hwndCnr, PMINIRECORDCORE pmi)
120{
121
122 QUERYRECORDRECT qrecrct;
123 RECTL rcl;
124 RECTL rclViewport;
125
126 memset(&qrecrct, 0, sizeof(QUERYRECORDRECT));
127 qrecrct.cb = sizeof(QUERYRECORDRECT);
128 qrecrct.pRecord = (PRECORDCORE) pmi;
129 qrecrct.fsExtent = (CMA_ICON | CMA_TEXT | CMA_TREEICON);
130 if (!WinSendMsg(hwndCnr,
131 CM_QUERYRECORDRECT, MPFROMP(&rcl), MPFROMP(&qrecrct))) {
132 qrecrct.fsExtent = CMA_TEXT | CMA_TREEICON;
133 WinSendMsg(hwndCnr, CM_QUERYRECORDRECT, MPFROMP(&rcl), MPFROMP(&qrecrct));
134 }
135 WinSendMsg(hwndCnr,
136 CM_QUERYVIEWPORTRECT,
137 MPFROMP(&rclViewport), MPFROM2SHORT(CMA_WINDOW, TRUE));
138 //DbgMsg(pszSrcFile, __LINE__, "TOPPORT %i TOPRCL %i", rclViewport.yTop , rcl.yTop);
139 WinSendMsg(hwndCnr,
140 CM_SCROLLWINDOW,
141 MPFROMSHORT(CMA_HORIZONTAL), MPFROMLONG(rcl.xRight - rclViewport.xRight));
142 WinSendMsg(hwndCnr,
143 CM_SCROLLWINDOW,
144 MPFROMSHORT(CMA_VERTICAL),
145 MPFROMLONG((rclViewport.yTop - (rcl.yTop) - 4)));
146}
147
148#pragma alloc_text(FINDREC,FindCnrRecord,FindParentRecord,ShowCnrRecord)
Note: See TracBrowser for help on using the repository browser.