OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
findrepl.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of abstract class TFindReplaceDialog, and leaf classes
7/// TFindDialog and TReplaceDialog that encapsulate Common Dialogs
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/findrepl.h>
11
12#if !defined(ctlFirst)
13# include <dlgs.h>
14#endif
15
16namespace owl {
17
19
20//
21/// Constructs a TData object with the specified flag value that initializes the
22/// status of the dialog box control buttons and the buffer size for the find and
23/// replace search strings.
24//
26:
27 Flags(flags), BuffSize(buffSize), Error(0)
28{
29 FindWhat = new tchar[BuffSize];
31 *FindWhat = *ReplaceWith = 0;
32}
33
34//
35//
36//
38:
39 Flags(src.Flags),
40 BuffSize(src.BuffSize),
41 Error(0)
42{
43 FindWhat = strnewdup(src.FindWhat, BuffSize);
44 ReplaceWith = strnewdup(src.ReplaceWith, BuffSize);
45}
46
47
48//
49/// Destroys a ~TData object.
50//
52{
53 delete[] FindWhat;
54 delete[] ReplaceWith;
55}
56
57//
58//
59//
62{
63 Flags = src.Flags;
64 BuffSize = src.BuffSize;
65 Error = 0;
66
67 delete[] FindWhat;
68 FindWhat = strnewdup(src.FindWhat, BuffSize);
69
70 delete[] ReplaceWith;
71 ReplaceWith = strnewdup(src.ReplaceWith, BuffSize);
72
73 return *this;
74}
75
76
77//----------------------------------------------------------------------------
78
82
83//
84/// Used by constructors in derived classes, Init initializes a TFindReplaceDialog
85/// object with the current resource ID and other members.
86//
87void
89{
90 memset(&fr, 0, sizeof(FINDREPLACE));
91 fr.lStructSize = sizeof(FINDREPLACE);
92 fr.hwndOwner = GetParentO() ? GetParentO()->GetHandle() : nullptr;
93 fr.hInstance = *GetModule();
95 fr.Flags = FR_ENABLEHOOK | Data.Flags;
96 if (templateId) {
97 fr.lpTemplateName = templateId;
98 fr.Flags |= FR_ENABLETEMPLATE;
99 }
100 else
101 fr.Flags &= ~FR_ENABLETEMPLATE;
102
103 fr.lpstrFindWhat = Data.FindWhat;
104 fr.wFindWhatLen = static_cast<uint16>(Data.BuffSize);
105 fr.lpstrReplaceWith = Data.ReplaceWith;
106 fr.wReplaceWithLen = static_cast<uint16>(Data.BuffSize);
107}
108
109//
110/// Constructs a TFindReplaceDialog object with a parent window, resource ID, and
111/// caption. Sets the attributes of the dialog box with the specified data from the
112/// TFindReplaceDialog::TData structure.
113//
115 LPCTSTR title, TModule* module)
116:
117 TCommonDialog(parent, title, module),
118 Data(data)
119{
121}
122
123//
124/// String-aware overload
125//
127:
128 TCommonDialog(parent, title, module),
129 Data(data)
130{
132}
133
134//
135//
136//
139{
140 PRECONDITIONX(false, _T("Incorrect use of base class."));
141 return nullptr;
142}
143
144//
145/// Returns true if a message is handled.
146//
152
153//
154/// Calls TWindow::EvNCDestroy, which responds to an incoming EV_WM_NCDESTROY
155/// message which tells the owner window that is nonclient area is being destroyed.
156///
157/// Make sure flags get copied over before we go
158//
159void
161{
162 Data.Flags = fr.Flags;
164}
165
166//
167/// Updates the flags from the passed-in parameter. Assumes the parameters is a
168/// pointer to a FINDREPLACE structure.
169//
170void
172{
173 if (param2)
174 Data.Flags = (reinterpret_cast<LPFINDREPLACE>(param2))->Flags;
175 else
176 Data.Flags = fr.Flags;
177}
178
179//----------------------------------------------------------------------------
180
181//
182/// Constructs a TFindDialog object with the given parent window, resource ID, and
183/// caption. Sets the attributes of the dialog box based onTFindReplaceDialog::TData
184/// structure, which contains information about the text string to search for.
185//
186TFindDialog::TFindDialog(TWindow* parent, TData& data, TResId templateId,
187 LPCTSTR title, TModule* module)
188:
189 TFindReplaceDialog(parent, data, templateId, title, module)
190{
191}
192
193//
194/// String-aware overload
195//
196TFindDialog::TFindDialog(TWindow* parent, TData& data, TResId templateId, const tstring& title, TModule* module)
197:
198 TFindReplaceDialog(parent, data, templateId, title, module)
199{}
200
201//
202//
203//
206{
207 fr.lpfnHook = LPFRHOOKPROC(StdDlgProc);
208 return FindText(&fr);
209}
210
211//----------------------------------------------------------------------------
212
213//
214/// Constructs a TReplaceDialog object with a parent window, resource ID, template
215/// name, caption, and module instance. The data parameter is a reference to the
216/// TFindReplaceDialog::TData class that contains information about the appearance
217/// and functionality of the dialog box, such as the user-entered text strings to
218/// search for and replace.
219//
226
227//
228/// String-aware overload
229//
234
235//
236//
237//
240{
241 fr.lpfnHook = LPFRHOOKPROC(StdDlgProc);
242 return ReplaceText(&fr);
243}
244
245//Keep streaming out if not used
246
247//
248//
249//
250void
252{
253 is >> Flags;
254 is >> BuffSize;
255 delete[] FindWhat;
256 delete[] ReplaceWith;
257 FindWhat = new tchar[BuffSize];
259 is.readBytes(FindWhat, BuffSize);
260 is.readBytes(ReplaceWith, BuffSize);
261}
262
263//
264//
265//
266void
268{
269 os << Flags;
270 os << BuffSize;
271 os.writeBytes(FindWhat, BuffSize);
272 os.writeBytes(ReplaceWith, BuffSize);
273}
274
275
276
277} // OWL namespace
278
#define PRECONDITIONX(condition, message)
Definition checks.h:231
Derived from TDialog, TCommonDialog is the abstract base class for TCommonDialog objects.
Definition commdial.h:62
virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2)
Override this to process messages within the dialog function.
Definition dialog.cpp:353
static INT_PTR CALLBACK StdDlgProc(HWND, UINT, WPARAM, LPARAM) noexcept
Callback procs for hooking TDialog to native window.
Definition dialog.cpp:440
virtual THandle PerformCreate() override
Definition findrepl.cpp:205
The TFindReplaceDialog::TData class encapsulates information necessary to initialize a TFindReplace d...
Definition findrepl.h:41
int BuffSize
BuffSize contains the size of the text buffer.
Definition findrepl.h:64
TData(uint32 flags=0, int buffSize=81)
Constructs a TData object with the specified flag value that initializes the status of the dialog box...
Definition findrepl.cpp:25
TData & operator=(const TData &src)
Definition findrepl.cpp:61
TCHAR * ReplaceWith
ReplaceWith contains the replacement string.
Definition findrepl.h:80
TCHAR * FindWhat
Contains the search string.
Definition findrepl.h:77
~TData()
Destroys a ~TData object.
Definition findrepl.cpp:51
uint32 Flags
Flags, which indicates the state of the control buttons and the action that occurred in the dialog bo...
Definition findrepl.h:61
TFindReplaceDialog is an abstract base class for a modeless dialog box that lets you search for and r...
Definition findrepl.h:34
TFindReplaceDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=nullptr, TModule *module=nullptr)
Constructs a TFindReplaceDialog object with a parent window, resource ID, and caption.
Definition findrepl.cpp:114
void EvNCDestroy()
Calls TWindow::EvNCDestroy, which responds to an incoming EV_WM_NCDESTROY message which tells the own...
Definition findrepl.cpp:160
void UpdateData(TParam2 param=0)
Updates the flags from the passed-in parameter.
Definition findrepl.cpp:171
auto PerformCreate() -> THandle override
Definition findrepl.cpp:138
auto DialogFunction(TMsgId, TParam1, TParam2) -> INT_PTR override
Returns true if a message is handled.
Definition findrepl.cpp:148
virtual void Init(TResId templateId)
Used by constructors in derived classes, Init initializes a TFindReplaceDialog object with the curren...
Definition findrepl.cpp:88
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TReplaceDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=nullptr, TModule *module=nullptr)
Constructs a TReplaceDialog object with a parent window, resource ID, template name,...
Definition findrepl.cpp:220
virtual THandle PerformCreate() override
Definition findrepl.cpp:239
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
void EvNCDestroy()
Responds to an incoming WM_NCDESTROY message, the last message sent to an MS-Windows interface elemen...
Definition window.cpp:2871
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
Base class for writing streamable objects.
Definition objstrm.h:480
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Definition of FindReplace- abstract, Find-, Replace- common Dialog classes.
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
EV_WM_NCDESTROY
Definition editview.cpp:31
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79