]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/generic/fdrepgg.cpp | |
3 | // Purpose: Find/Replace dialogs | |
4 | // Author: Markus Greither and Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 05/25/01 | |
7 | // RCS-ID: | |
8 | // Copyright: (c) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
17 | #pragma implementation "genericfdrepdlg.h" | |
18 | #endif | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // headers | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #if wxUSE_FINDREPLDLG | |
32 | ||
33 | #ifndef WX_PRECOMP | |
34 | #include "wx/intl.h" | |
35 | #include "wx/log.h" | |
36 | ||
37 | #include "wx/sizer.h" | |
38 | ||
39 | #include "wx/button.h" | |
40 | #include "wx/checkbox.h" | |
41 | #include "wx/radiobox.h" | |
42 | #include "wx/stattext.h" | |
43 | #include "wx/textctrl.h" | |
44 | #endif | |
45 | ||
46 | #include "wx/fdrepdlg.h" | |
47 | #include "wx/settings.h" | |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // constants | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | // ============================================================================ | |
54 | // implementation | |
55 | // ============================================================================ | |
56 | ||
57 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog, wxDialog) | |
58 | ||
59 | BEGIN_EVENT_TABLE(wxGenericFindReplaceDialog, wxDialog) | |
60 | EVT_BUTTON(wxID_FIND, wxGenericFindReplaceDialog::OnFind) | |
61 | EVT_BUTTON(wxID_REPLACE, wxGenericFindReplaceDialog::OnReplace) | |
62 | EVT_BUTTON(wxID_REPLACE_ALL, wxGenericFindReplaceDialog::OnReplaceAll) | |
63 | EVT_BUTTON(wxID_CANCEL, wxGenericFindReplaceDialog::OnCancel) | |
64 | ||
65 | EVT_UPDATE_UI(wxID_FIND, wxGenericFindReplaceDialog::OnUpdateFindUI) | |
66 | EVT_UPDATE_UI(wxID_REPLACE, wxGenericFindReplaceDialog::OnUpdateFindUI) | |
67 | EVT_UPDATE_UI(wxID_REPLACE_ALL, wxGenericFindReplaceDialog::OnUpdateFindUI) | |
68 | ||
69 | EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow) | |
70 | END_EVENT_TABLE() | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // wxGenericFindReplaceDialog | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | void wxGenericFindReplaceDialog::Init() | |
77 | { | |
78 | m_FindReplaceData = NULL; | |
79 | ||
80 | m_chkWord = | |
81 | m_chkCase = NULL; | |
82 | ||
83 | m_radioDir = NULL; | |
84 | ||
85 | m_textFind = | |
86 | m_textRepl = NULL; | |
87 | } | |
88 | ||
89 | bool wxGenericFindReplaceDialog::Create(wxWindow *parent, | |
90 | wxFindReplaceData *data, | |
91 | const wxString& title, | |
92 | int style) | |
93 | { | |
94 | if ( !wxDialog::Create(parent, wxID_ANY, title, | |
95 | wxDefaultPosition, wxDefaultSize, | |
96 | wxDEFAULT_DIALOG_STYLE | |
97 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) | |
98 | | wxRESIZE_BORDER | |
99 | #endif | |
100 | | style) ) | |
101 | { | |
102 | return false; | |
103 | } | |
104 | ||
105 | SetData(data); | |
106 | ||
107 | wxCHECK_MSG( m_FindReplaceData, false, | |
108 | _T("can't create dialog without data") ); | |
109 | ||
110 | bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); | |
111 | ||
112 | wxBoxSizer *leftsizer = new wxBoxSizer( wxVERTICAL ); | |
113 | ||
114 | // 3 columns because there is a spacer in the middle | |
115 | wxFlexGridSizer *sizer2Col = new wxFlexGridSizer(3); | |
116 | sizer2Col->AddGrowableCol(2); | |
117 | ||
118 | sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Search for:"), | |
119 | wxDefaultPosition, wxSize(80, wxDefaultCoord)), | |
120 | 0, | |
121 | wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT); | |
122 | ||
123 | sizer2Col->Add(10, 0); | |
124 | ||
125 | m_textFind = new wxTextCtrl(this, wxID_ANY, m_FindReplaceData->GetFindString()); | |
126 | sizer2Col->Add(m_textFind, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND); | |
127 | ||
128 | if ( style & wxFR_REPLACEDIALOG ) | |
129 | { | |
130 | sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Replace with:"), | |
131 | wxDefaultPosition, wxSize(80, wxDefaultCoord)), | |
132 | 0, | |
133 | wxALIGN_CENTRE_VERTICAL | | |
134 | wxALIGN_RIGHT | wxTOP, 5); | |
135 | ||
136 | sizer2Col->Add(isPda ? 2 : 10, 0); | |
137 | ||
138 | m_textRepl = new wxTextCtrl(this, wxID_ANY, | |
139 | m_FindReplaceData->GetReplaceString()); | |
140 | sizer2Col->Add(m_textRepl, 1, | |
141 | wxALIGN_CENTRE_VERTICAL | wxEXPAND | wxTOP, 5); | |
142 | } | |
143 | ||
144 | leftsizer->Add(sizer2Col, 0, wxEXPAND | wxALL, 5); | |
145 | ||
146 | wxBoxSizer *optsizer = new wxBoxSizer( isPda ? wxVERTICAL : wxHORIZONTAL ); | |
147 | ||
148 | wxBoxSizer *chksizer = new wxBoxSizer( wxVERTICAL); | |
149 | ||
150 | m_chkWord = new wxCheckBox(this, wxID_ANY, _("Whole word")); | |
151 | chksizer->Add(m_chkWord, 0, wxALL, 3); | |
152 | ||
153 | m_chkCase = new wxCheckBox(this, wxID_ANY, _("Match case")); | |
154 | chksizer->Add(m_chkCase, 0, wxALL, 3); | |
155 | ||
156 | optsizer->Add(chksizer, 0, wxALL, 10); | |
157 | ||
158 | static const wxString searchDirections[] = {_("Up"), _("Down")}; | |
159 | int majorDimension = 0; | |
160 | int rbStyle ; | |
161 | if (isPda) | |
162 | rbStyle = wxRA_SPECIFY_ROWS; | |
163 | else | |
164 | rbStyle = wxRA_SPECIFY_COLS; | |
165 | ||
166 | m_radioDir = new wxRadioBox(this, wxID_ANY, _("Search direction"), | |
167 | wxDefaultPosition, wxDefaultSize, | |
168 | WXSIZEOF(searchDirections), searchDirections, | |
169 | majorDimension, rbStyle); | |
170 | ||
171 | optsizer->Add(m_radioDir, 0, wxALL, isPda ? 5 : 10); | |
172 | ||
173 | leftsizer->Add(optsizer); | |
174 | ||
175 | wxBoxSizer *bttnsizer = new wxBoxSizer(wxVERTICAL); | |
176 | ||
177 | bttnsizer->Add(new wxButton(this, wxID_FIND), 0, wxALL, 3); | |
178 | ||
179 | bttnsizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 3); | |
180 | ||
181 | if ( style & wxFR_REPLACEDIALOG ) | |
182 | { | |
183 | bttnsizer->Add(new wxButton(this, wxID_REPLACE, _("&Replace")), | |
184 | 0, wxALL, 3); | |
185 | ||
186 | bttnsizer->Add(new wxButton(this, wxID_REPLACE_ALL, _("Replace &all")), | |
187 | 0, wxALL, 3); | |
188 | } | |
189 | ||
190 | wxBoxSizer *topsizer = new wxBoxSizer( wxHORIZONTAL ); | |
191 | ||
192 | topsizer->Add(leftsizer, 1, wxALL, isPda ? 0 : 5); | |
193 | topsizer->Add(bttnsizer, 0, wxALL, isPda ? 0 : 5); | |
194 | ||
195 | int flags = m_FindReplaceData->GetFlags(); | |
196 | ||
197 | if ( flags & wxFR_MATCHCASE ) | |
198 | m_chkCase->SetValue(true); | |
199 | ||
200 | if ( flags & wxFR_WHOLEWORD ) | |
201 | m_chkWord->SetValue(true); | |
202 | ||
203 | m_radioDir->SetSelection( flags & wxFR_DOWN ); | |
204 | ||
205 | if ( style & wxFR_NOMATCHCASE ) | |
206 | m_chkCase->Enable(false); | |
207 | ||
208 | if ( style & wxFR_NOWHOLEWORD ) | |
209 | m_chkWord->Enable(false); | |
210 | ||
211 | if ( style & wxFR_NOUPDOWN) | |
212 | m_radioDir->Enable(false); | |
213 | ||
214 | SetAutoLayout( true ); | |
215 | SetSizer( topsizer ); | |
216 | ||
217 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) | |
218 | topsizer->SetSizeHints( this ); | |
219 | topsizer->Fit( this ); | |
220 | ||
221 | Centre( wxBOTH ); | |
222 | #endif | |
223 | ||
224 | m_textFind->SetFocus(); | |
225 | ||
226 | return true; | |
227 | } | |
228 | ||
229 | // ---------------------------------------------------------------------------- | |
230 | // send the notification event | |
231 | // ---------------------------------------------------------------------------- | |
232 | ||
233 | void wxGenericFindReplaceDialog::SendEvent(const wxEventType& evtType) | |
234 | { | |
235 | wxFindDialogEvent event(evtType, GetId()); | |
236 | event.SetEventObject(this); | |
237 | event.SetFindString(m_textFind->GetValue()); | |
238 | if ( HasFlag(wxFR_REPLACEDIALOG) ) | |
239 | { | |
240 | event.SetReplaceString(m_textRepl->GetValue()); | |
241 | } | |
242 | ||
243 | int flags = 0; | |
244 | ||
245 | if ( m_chkCase->GetValue() ) | |
246 | flags |= wxFR_MATCHCASE; | |
247 | ||
248 | if ( m_chkWord->GetValue() ) | |
249 | flags |= wxFR_WHOLEWORD; | |
250 | ||
251 | if ( !m_radioDir || m_radioDir->GetSelection() == 1 ) | |
252 | { | |
253 | flags |= wxFR_DOWN; | |
254 | } | |
255 | ||
256 | event.SetFlags(flags); | |
257 | ||
258 | wxFindReplaceDialogBase::Send(event); | |
259 | } | |
260 | ||
261 | // ---------------------------------------------------------------------------- | |
262 | // event handlers | |
263 | // ---------------------------------------------------------------------------- | |
264 | ||
265 | void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event)) | |
266 | { | |
267 | SendEvent(wxEVT_COMMAND_FIND_NEXT); | |
268 | } | |
269 | ||
270 | void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event)) | |
271 | { | |
272 | SendEvent(wxEVT_COMMAND_FIND_REPLACE); | |
273 | } | |
274 | ||
275 | void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event)) | |
276 | { | |
277 | SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL); | |
278 | } | |
279 | ||
280 | void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
281 | { | |
282 | SendEvent(wxEVT_COMMAND_FIND_CLOSE); | |
283 | ||
284 | Show(false); | |
285 | } | |
286 | ||
287 | void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event) | |
288 | { | |
289 | // we can't search for empty strings | |
290 | event.Enable( !m_textFind->GetValue().empty() ); | |
291 | } | |
292 | ||
293 | void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent &) | |
294 | { | |
295 | SendEvent(wxEVT_COMMAND_FIND_CLOSE); | |
296 | } | |
297 | ||
298 | #endif // wxUSE_FINDREPLDLG | |
299 |