added generic implementation and documentation for wxFindReplaceDialog
[wxWidgets.git] / include / wx / fdrepdlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fdrepdlg.h
3 // Purpose: wxFindReplaceDialog class
4 // Author: Markus Greither and Vadim Zeitlin
5 // Modified by:
6 // Created: 23/03/2001
7 // RCS-ID:
8 // Copyright: (c) Markus Greither
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FINDREPLACEDLG_H_
13 #define _WX_FINDREPLACEDLG_H_
14
15 #ifdef __GNUG__
16 #pragma interface "fdrepdlg.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_FINDREPLDLG
22
23 #include "wx/dialog.h"
24
25 class WXDLLEXPORT wxFindDialogEvent;
26 class WXDLLEXPORT wxFindReplaceDialog;
27 class WXDLLEXPORT wxFindReplaceData;
28 class WXDLLEXPORT wxFindReplaceDialogImpl;
29
30 // ----------------------------------------------------------------------------
31 // Flags for wxFindReplaceData.Flags
32 // ----------------------------------------------------------------------------
33
34 // flages used by wxFindDialogEvent::GetFlags()
35 enum wxFindReplaceFlags
36 {
37 // downward search/replace selected (otherwise - upwards)
38 wxFR_DOWN = 1,
39
40 // whole word search/replace selected
41 wxFR_WHOLEWORD = 2,
42
43 // case sensitive search/replace selected (otherwise - case insensitive)
44 wxFR_MATCHCASE = 4
45 };
46
47 // these flags can be specified in wxFindReplaceDialog ctor or Create()
48 enum wxFindReplaceDialogStyles
49 {
50 // replace dialog (otherwise find dialog)
51 wxFR_REPLACEDIALOG = 1,
52
53 // don't allow changing the search direction
54 wxFR_NOUPDOWN = 2,
55
56 // don't allow case sensitive searching
57 wxFR_NOMATCHCASE = 4,
58
59 // don't allow whole word searching
60 wxFR_NOWHOLEWORD = 8
61 };
62
63 // ----------------------------------------------------------------------------
64 // wxFindReplaceData: holds Setup Data/Feedback Data for wxFindReplaceDialog
65 // ----------------------------------------------------------------------------
66
67 class WXDLLEXPORT wxFindReplaceData : public wxObject
68 {
69 public:
70 wxFindReplaceData() { Init(); }
71 wxFindReplaceData(wxUint32 flags) { Init(); SetFlags(flags); }
72
73 // accessors
74 const wxString& GetFindString() { return m_FindWhat; }
75 const wxString& GetReplaceString() { return m_ReplaceWith; }
76
77 int GetFlags() const { return m_Flags; }
78
79 // setters: may only be called before showing the dialog, no effect later
80 void SetFlags(wxUint32 flags) { m_Flags = flags; }
81
82 void SetFindString(const wxString& str) { m_FindWhat = str; }
83 void SetReplaceString(const wxString& str) { m_ReplaceWith = str; }
84
85 protected:
86 void Init();
87
88 private:
89 wxUint32 m_Flags;
90 wxString m_FindWhat,
91 m_ReplaceWith;
92
93 friend class wxFindReplaceDialogBase;
94 };
95
96 // ----------------------------------------------------------------------------
97 // wxFindReplaceDialogBase
98 // ----------------------------------------------------------------------------
99
100 class WXDLLEXPORT wxFindReplaceDialogBase : public wxDialog
101 {
102 public:
103 // ctors and such
104 wxFindReplaceDialogBase() { m_FindReplaceData = NULL; }
105 wxFindReplaceDialogBase(wxWindow * WXUNUSED(parent),
106 wxFindReplaceData *data,
107 const wxString& WXUNUSED(title),
108 int WXUNUSED(style) = 0)
109 {
110 m_FindReplaceData = data;
111 }
112
113 virtual ~wxFindReplaceDialogBase();
114
115 // find dialog data access
116 const wxFindReplaceData *GetData() const { return m_FindReplaceData; }
117 void SetData(wxFindReplaceData *data) { m_FindReplaceData = data; }
118
119 // implementation only, don't use
120 void Send(wxFindDialogEvent& event);
121
122 protected:
123 wxFindReplaceData *m_FindReplaceData;
124
125 // the last string we searched for
126 wxString m_lastSearch;
127 };
128
129 // include wxFindReplaceDialog declaration
130 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
131 #include "wx/msw/fdrepdlg.h"
132 #else
133 #define wxGenericFindReplaceDialog wxFindReplaceDialog
134 #define sm_classwxGenericFindReplaceDialog sm_classwxFindReplaceDialog
135
136 #include "wx/generic/fdrepdlg.h"
137 #endif
138
139 // ----------------------------------------------------------------------------
140 // wxFindReplaceDialog events
141 // ----------------------------------------------------------------------------
142
143 class WXDLLEXPORT wxFindDialogEvent : public wxCommandEvent
144 {
145 public:
146 wxFindDialogEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
147 : wxCommandEvent(commandType, id) { }
148
149 int GetFlags() const { return GetInt(); }
150 wxString GetFindString() const { return GetString(); }
151 const wxString& GetReplaceString() const { return m_strReplace; }
152
153 wxFindReplaceDialog *GetDialog() const
154 { return wxStaticCast(GetEventObject(), wxFindReplaceDialog); }
155
156 // implementation only
157 void SetFlags(int flags) { SetInt(flags); }
158 void SetFindString(const wxString& str) { SetString(str); }
159 void SetReplaceString(const wxString& str) { m_strReplace = str; }
160
161 private:
162 wxString m_strReplace;
163
164 DECLARE_DYNAMIC_CLASS(wxFindDialogEvent)
165 };
166
167 BEGIN_DECLARE_EVENT_TYPES()
168 DECLARE_EVENT_TYPE(wxEVT_COMMAND_FIND, 510)
169 DECLARE_EVENT_TYPE(wxEVT_COMMAND_FIND_NEXT, 511)
170 DECLARE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE, 512)
171 DECLARE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE_ALL, 513)
172 DECLARE_EVENT_TYPE(wxEVT_COMMAND_FIND_CLOSE, 514)
173 END_DECLARE_EVENT_TYPES()
174
175 typedef void (wxEvtHandler::*wxFindDialogEventFunction)(wxFindDialogEvent&);
176
177 #define EVT_FIND(id, fn) \
178 DECLARE_EVENT_TABLE_ENTRY( \
179 wxEVT_COMMAND_FIND, id, -1, \
180 (wxObjectEventFunction)(wxEventFunction)(wxFindDialogEventFunction) \
181 & fn, \
182 (wxObject *) NULL \
183 ),
184
185 #define EVT_FIND_NEXT(id, fn) \
186 DECLARE_EVENT_TABLE_ENTRY( \
187 wxEVT_COMMAND_FIND_NEXT, id, -1, \
188 (wxObjectEventFunction)(wxEventFunction)(wxFindDialogEventFunction) \
189 & fn, \
190 (wxObject *) NULL \
191 ),
192
193 #define EVT_FIND_REPLACE(id, fn) \
194 DECLARE_EVENT_TABLE_ENTRY( \
195 wxEVT_COMMAND_FIND_REPLACE, id, -1, \
196 (wxObjectEventFunction)(wxEventFunction)(wxFindDialogEventFunction) \
197 & fn, \
198 (wxObject *) NULL \
199 ),
200
201 #define EVT_FIND_REPLACE_ALL(id, fn) \
202 DECLARE_EVENT_TABLE_ENTRY( \
203 wxEVT_COMMAND_FIND_REPLACE_ALL, id, -1, \
204 (wxObjectEventFunction)(wxEventFunction)(wxFindDialogEventFunction) \
205 & fn, \
206 (wxObject *) NULL \
207 ),
208
209 #define EVT_FIND_CLOSE(id, fn) \
210 DECLARE_EVENT_TABLE_ENTRY( \
211 wxEVT_COMMAND_FIND_CLOSE, id, -1, \
212 (wxObjectEventFunction)(wxEventFunction)(wxFindDialogEventFunction) \
213 & fn, \
214 (wxObject *) NULL \
215 ),
216
217 #endif // wxUSE_FINDREPLDLG
218
219 #endif
220 // _WX_FDREPDLG_H