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