]> git.saurik.com Git - wxWidgets.git/blob - src/generic/fdrepdlg.cpp
We need wxUSE_COMMON_DIALOGS for PPC
[wxWidgets.git] / src / generic / fdrepdlg.cpp
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 | wxRESIZE_BORDER | 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 bttnsizer->Add(new wxButton(this, wxID_FIND), 0, wxALL, 3);
174
175 bttnsizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 3);
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
188 topsizer->Add(leftsizer, 1, wxALL, isPda ? 0 : 5);
189 topsizer->Add(bttnsizer, 0, wxALL, isPda ? 0 : 5);
190
191 int flags = m_FindReplaceData->GetFlags();
192
193 if ( flags & wxFR_MATCHCASE )
194 m_chkCase->SetValue(true);
195
196 if ( flags & wxFR_WHOLEWORD )
197 m_chkWord->SetValue(true);
198
199 m_radioDir->SetSelection( flags & wxFR_DOWN );
200
201 if ( style & wxFR_NOMATCHCASE )
202 m_chkCase->Enable(false);
203
204 if ( style & wxFR_NOWHOLEWORD )
205 m_chkWord->Enable(false);
206
207 if ( style & wxFR_NOUPDOWN)
208 m_radioDir->Enable(false);
209
210 SetAutoLayout( true );
211 SetSizer( topsizer );
212
213 topsizer->SetSizeHints( this );
214 topsizer->Fit( this );
215
216 Centre( wxBOTH );
217
218 m_textFind->SetFocus();
219
220 return true;
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
259 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
260 {
261 SendEvent(wxEVT_COMMAND_FIND_NEXT);
262 }
263
264 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
265 {
266 SendEvent(wxEVT_COMMAND_FIND_REPLACE);
267 }
268
269 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
270 {
271 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL);
272 }
273
274 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
275 {
276 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
277
278 Show(false);
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 {
289 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
290 }
291
292 #endif // wxUSE_FINDREPLDLG
293