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