OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
editsear.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 class TEditWindow, an edit control that responds to Find,
7/// Replace and FindNext commands.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/editsear.h>
11#include <owl/applicat.h>
12#include <owl/edit.h>
13#include <owl/findrepl.h>
14#include <stdio.h>
15
16namespace owl {
17
19
20
21DEFINE_RESPONSE_TABLE1(TEditSearch, TEdit)
22 EV_COMMAND(CM_EDITFIND, CmEditFind),
23 EV_COMMAND_ENABLE(CM_EDITFIND, CeEditFindReplace),
24 EV_COMMAND(CM_EDITREPLACE, CmEditReplace),
25 EV_COMMAND_ENABLE(CM_EDITREPLACE, CeEditFindReplace),
26 EV_COMMAND(CM_EDITFINDNEXT, CmEditFindNext),
30
31//
32/// Constructs a TEditSearch object given the parent window, resource ID,
33/// and character string (text).
34//
36 int id,
38 int x, int y, int w, int h,
39 TModule* module)
40:
41 TEdit(parent, id, text, x, y, w, h, 0, true, module),
42 SearchData(FR_DOWN)
43{
44 Attr.Style |= ES_NOHIDESEL;
45 SearchDialog = nullptr;
46 SearchCmd = 0;
47}
48
49//
50/// String-aware overload
51//
53 TWindow* parent,
54 int id,
55 const tstring& text,
56 int x, int y, int w, int h,
57 TModule* module
58 )
59 : TEdit(parent, id, text, x, y, w, h, 0, true, module),
60 SearchData(FR_DOWN)
61{
62 Attr.Style |= ES_NOHIDESEL;
63 SearchDialog = nullptr;
64 SearchCmd = 0;
65}
66
67//
68//
69//
71{
72 delete SearchDialog;
73}
74
75//
76// Post a CM_EDITFIND or a CM_EDITREPLACE to re-open a previously open
77// find or replace modeless dialog
78//
79void
81{
83 if (SearchCmd)
84 PostMessage(WM_COMMAND, SearchCmd);
85}
86
87//
88/// Performs a search or replace operation base on information in SearchData.
89//
90void
92{
93 do {
94 if (Search(-1, SearchData.FindWhat, bool(SearchData.Flags&FR_MATCHCASE),
95 bool(SearchData.Flags&FR_WHOLEWORD),
96 !(SearchData.Flags&FR_DOWN)) >= 0)
97 {
98 if (SearchData.Flags & (FR_REPLACE|FR_REPLACEALL))
99 Insert(SearchData.ReplaceWith);
100 }
101 else
102 {
103 if (SearchData.Flags & (FR_FINDNEXT|FR_REPLACE))
104 {
106 }
107 else if (SearchData.Flags & FR_REPLACEALL)
108 break;
109 }
110 } while (SearchData.Flags & FR_REPLACEALL);
111}
112
113//
114/// Opens a modeless TFindDialog in response to an incoming Find command with a CM_EDITFIND
115/// command.
116//
117void
119{
120 if (!SearchCmd) {
121 SearchCmd = CM_EDITFIND;
122 delete SearchDialog;
123 SearchDialog = new TFindDialog(this, SearchData);
124 SearchDialog->Create();
125 }
126}
127
128//
129/// Opens a TReplaceDialog in response to an incoming Replace command with a
130/// CM_EDITREPLACE command.
131//
132void
134{
135 if (!SearchCmd) {
136 SearchCmd = CM_EDITREPLACE;
137 delete SearchDialog;
138 SearchDialog = new TReplaceDialog(this, SearchData);
139 SearchDialog->Create();
140 }
141}
142
143//
144/// Enables the find or replace option (only if no dialog is up).
145//
146void
148{
149 ce.Enable(!SearchCmd);
150}
151
152//
153/// Responds to an incoming FindNext command with a CM_EDITFINDNEXT command
154/// identifier by calling DoSearch to repeat the search operation.
155//
156void
158{
159 if (SearchDialog)
160 SearchDialog->UpdateData();
161 SearchData.Flags |= FR_FINDNEXT;
162 DoSearch();
163}
164
165//
166/// Enables FindNext (only if there's data to search for).
167//
168void
170{
171 ce.Enable(SearchData.FindWhat && *SearchData.FindWhat);
172}
173
174//
175/// Responds to a message sent by the modeless find or replace dialog box. Calls
176/// DoSearch to continue searching if text is not found or the end of the document
177/// has not been reached.
178//
181{
182 PRECONDITION(SearchDialog);
183
184 SearchDialog->UpdateData(param2);
185 if (SearchData.Flags & FR_DIALOGTERM)
186 SearchCmd = 0;
187
188 else
189 DoSearch();
190 return 0;
191}
192
193
194
196
197#if OWL_PERSISTENT_STREAMS
198
199//
200// reads an instance of TEditSearch from the passed ipstream.
201// Re-opens the modeless find or replace dialog if one was up.
202//
203void*
204TEditSearch::Streamer::Read(ipstream& is, uint32 /*version*/) const
205{
206 ReadBaseObject((TEdit*)GetObject(), is);
207
208 GetObject()->SearchData.Read(is);
209 is >> GetObject()->SearchCmd;
210 GetObject()->SearchDialog = 0;
211 return GetObject();
212}
213
214//
215// writes the TEditSearch to the passed opstream
216//
217void
218TEditSearch::Streamer::Write(opstream& os) const
219{
220 WriteBaseObject((TEdit*)GetObject(), os);
221
222 GetObject()->SearchData.Write(os);
223 os << GetObject()->SearchCmd;
224}
225
226#endif
227
228} // OWL namespace
229
Definition of class TApplication.
#define PRECONDITION(condition)
Definition checks.h:227
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
auto Create() -> bool override
Creates a modeless dialog box interface element associated with the TDialog object.
Definition dialog.cpp:490
A TEdit is an interface object that represents an edit control interface element.
Definition edit.h:34
TEditSearch is an edit control that responds to Find, Replace, and FindNext menu commands.
Definition editsear.h:35
TFindDialog objects represents modeless dialog box interface elements that let you specify text to fi...
Definition findrepl.h:150
TCHAR * ReplaceWith
ReplaceWith contains the replacement string.
Definition findrepl.h:80
TCHAR * FindWhat
Contains the search string.
Definition findrepl.h:77
uint32 Flags
Flags, which indicates the state of the control buttons and the action that occurred in the dialog bo...
Definition findrepl.h:61
void UpdateData(TParam2 param=0)
Updates the flags from the passed-in parameter.
Definition findrepl.cpp:171
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TReplaceDialog creates a modeless dialog box that lets the user enter a selection of text to replace.
Definition findrepl.h:180
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
tstring LoadString(uint id) const
Definition window.h:608
auto FormatMessageBox(const tstring &formatStr, const tstring &caption, uint flags,...) const -> int
Definition window.cpp:4361
bool PostMessage(TMsgId, TParam1=0, TParam2=0)
Posts a message (msg) to the window in the application's message queue.
Definition window.h:2103
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _T(x)
Definition cygwin.h:51
Definition of class TEdit.
Definition of class TEditSearch, an edit control that responds to Find, Replace and FindNext menu com...
#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.
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
TResult EvFindMsg(TParam1, TParam2)
Registered commdlg message.
Definition editsear.cpp:180
void CmEditFindNext()
CM_EDITFINDNEXT.
Definition editsear.cpp:157
void DoSearch()
Performs a search or replace operation base on information in SearchData.
Definition editsear.cpp:91
TEditSearch(TWindow *parent=nullptr, int id=0, LPCTSTR text=nullptr, int x=0, int y=0, int w=0, int h=0, TModule *module=nullptr)
Constructs a TEditSearch object given the parent window, resource ID, and character string (text).
Definition editsear.cpp:35
void CmEditFind()
CM_EDITFIND.
Definition editsear.cpp:118
void SetupWindow() override
Definition edit.cpp:1000
void SetupWindow() override
Definition editsear.cpp:80
void CeEditFindReplace(TCommandEnabler &ce)
Enables the find or replace option (only if no dialog is up).
Definition editsear.cpp:147
~TEditSearch() override
Definition editsear.cpp:70
void Insert(LPCTSTR str)
Inserts the text supplied in str into the edit control at the current text insertion point (cursor po...
Definition edit.h:553
virtual int Search(int startPos, LPCTSTR text, bool caseSensitive=false, bool wholeWord=false, bool up=false)
searches for and selects the given text and returns the offset of the text or -1 if the text is not f...
Definition edit.cpp:746
void CeEditFindNext(TCommandEnabler &ce)
Enables FindNext (only if there's data to search for).
Definition editsear.cpp:169
void CmEditReplace()
CM_EDITREPLACE.
Definition editsear.cpp:133
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
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
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
Definition windowev.h:193
#define EV_REGISTERED(str, method)
Resonse table entry for a registered message.
Definition windowev.h:122
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171