]> git.saurik.com Git - wxWidgets.git/blob - src/generic/fdrepdlg.cpp
wxCocoa: Added preliminary Blit support
[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) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 #ifdef __GNUG__
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
48 // ----------------------------------------------------------------------------
49 // constants
50 // ----------------------------------------------------------------------------
51
52 // ============================================================================
53 // implementation
54 // ============================================================================
55
56 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog, wxDialog)
57
58 BEGIN_EVENT_TABLE(wxGenericFindReplaceDialog, wxDialog)
59 EVT_BUTTON(wxID_FIND, wxGenericFindReplaceDialog::OnFind)
60 EVT_BUTTON(wxID_REPLACE, wxGenericFindReplaceDialog::OnReplace)
61 EVT_BUTTON(wxID_REPLACE_ALL, wxGenericFindReplaceDialog::OnReplaceAll)
62 EVT_BUTTON(wxID_CANCEL, wxGenericFindReplaceDialog::OnCancel)
63
64 EVT_UPDATE_UI(wxID_FIND, wxGenericFindReplaceDialog::OnUpdateFindUI)
65 EVT_UPDATE_UI(wxID_REPLACE, wxGenericFindReplaceDialog::OnUpdateFindUI)
66 EVT_UPDATE_UI(wxID_REPLACE_ALL, wxGenericFindReplaceDialog::OnUpdateFindUI)
67
68 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow)
69 END_EVENT_TABLE()
70
71 // ----------------------------------------------------------------------------
72 // wxGenericFindReplaceDialog
73 // ----------------------------------------------------------------------------
74
75 void wxGenericFindReplaceDialog::Init()
76 {
77 m_FindReplaceData = NULL;
78
79 m_chkWord =
80 m_chkCase = NULL;
81
82 m_radioDir = NULL;
83
84 m_textFind =
85 m_textRepl = NULL;
86 }
87
88 bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
89 wxFindReplaceData *data,
90 const wxString& title,
91 int style)
92 {
93 if ( !wxDialog::Create(parent, -1, title,
94 wxDefaultPosition, wxDefaultSize,
95 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | style) )
96 {
97 return FALSE;
98 }
99
100 SetData(data);
101
102 wxCHECK_MSG( m_FindReplaceData, FALSE,
103 _T("can't create dialog without data") );
104
105 wxBoxSizer *leftsizer = new wxBoxSizer( wxVERTICAL );
106
107 // 3 columns because there is a spacer in the middle
108 wxFlexGridSizer *sizer2Col = new wxFlexGridSizer(3);
109 sizer2Col->AddGrowableCol(2);
110
111 sizer2Col->Add(new wxStaticText(this, -1, _("Search for:"),
112 wxDefaultPosition, wxSize(80, -1)),
113 0,
114 wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
115
116 sizer2Col->Add(10, 0);
117
118 m_textFind = new wxTextCtrl(this, -1, m_FindReplaceData->GetFindString());
119 sizer2Col->Add(m_textFind, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
120
121 if ( style & wxFR_REPLACEDIALOG )
122 {
123 sizer2Col->Add(new wxStaticText(this, -1, _("Replace with:"),
124 wxDefaultPosition, wxSize(80, -1)),
125 0,
126 wxALIGN_CENTRE_VERTICAL |
127 wxALIGN_RIGHT | wxTOP, 5);
128
129 sizer2Col->Add(10, 0);
130
131 m_textRepl = new wxTextCtrl(this, -1,
132 m_FindReplaceData->GetReplaceString());
133 sizer2Col->Add(m_textRepl, 1,
134 wxALIGN_CENTRE_VERTICAL | wxEXPAND | wxTOP, 5);
135 }
136
137 leftsizer->Add(sizer2Col, 0, wxEXPAND | wxALL, 5);
138
139 wxBoxSizer *optsizer = new wxBoxSizer( wxHORIZONTAL );
140
141 wxBoxSizer *chksizer = new wxBoxSizer( wxVERTICAL);
142
143 m_chkWord = new wxCheckBox(this, -1, _("Whole word"));
144 chksizer->Add(m_chkWord, 0, wxALL, 3);
145
146 m_chkCase = new wxCheckBox(this, -1, _("Match case"));
147 chksizer->Add(m_chkCase, 0, wxALL, 3);
148
149 optsizer->Add(chksizer, 0, wxALL, 10);
150
151 static const wxString searchDirections[] = {_("Up"), _("Down")};
152 m_radioDir = new wxRadioBox(this, -1, _("Search direction"),
153 wxDefaultPosition, wxDefaultSize,
154 WXSIZEOF(searchDirections), searchDirections);
155
156 optsizer->Add(m_radioDir, 0, wxALL, 10);
157
158 leftsizer->Add(optsizer);
159
160 wxBoxSizer *bttnsizer = new wxBoxSizer(wxVERTICAL);
161
162 bttnsizer->Add(new wxButton(this, wxID_FIND, _("&Find")), 0, wxALL, 3);
163
164 bttnsizer->Add(new wxButton(this, wxID_CANCEL, _("&Cancel")), 0, wxALL, 3);
165
166 if ( style & wxFR_REPLACEDIALOG )
167 {
168 bttnsizer->Add(new wxButton(this, wxID_REPLACE, _("&Replace")),
169 0, wxALL, 3);
170
171 bttnsizer->Add(new wxButton(this, wxID_REPLACE_ALL, _("Replace &all")),
172 0, wxALL, 3);
173 }
174
175 wxBoxSizer *topsizer = new wxBoxSizer( wxHORIZONTAL );
176
177 topsizer->Add(leftsizer, 1, wxALL, 5);
178 topsizer->Add(bttnsizer, 0, wxALL, 5);
179
180 int flags = m_FindReplaceData->GetFlags();
181
182 if ( flags & wxFR_MATCHCASE )
183 m_chkCase->SetValue(TRUE);
184
185 if ( flags & wxFR_WHOLEWORD )
186 m_chkWord->SetValue(TRUE);
187
188 m_radioDir->SetSelection( flags & wxFR_DOWN );
189
190 if ( style & wxFR_NOMATCHCASE )
191 m_chkCase->Enable(FALSE);
192
193 if ( style & wxFR_NOWHOLEWORD )
194 m_chkWord->Enable(FALSE);
195
196 if ( style & wxFR_NOUPDOWN)
197 m_radioDir->Enable(FALSE);
198
199 SetAutoLayout( TRUE );
200 SetSizer( topsizer );
201
202 topsizer->SetSizeHints( this );
203 topsizer->Fit( this );
204
205 Centre( wxBOTH );
206
207 m_textFind->SetFocus();
208
209 return TRUE;
210 }
211
212 // ----------------------------------------------------------------------------
213 // send the notification event
214 // ----------------------------------------------------------------------------
215
216 void wxGenericFindReplaceDialog::SendEvent(const wxEventType& evtType)
217 {
218 wxFindDialogEvent event(evtType, GetId());
219 event.SetEventObject(this);
220 event.SetFindString(m_textFind->GetValue());
221 if ( HasFlag(wxFR_REPLACEDIALOG) )
222 {
223 event.SetReplaceString(m_textRepl->GetValue());
224 }
225
226 int flags = 0;
227
228 if ( m_chkCase->GetValue() )
229 flags |= wxFR_MATCHCASE;
230
231 if ( m_chkWord->GetValue() )
232 flags |= wxFR_WHOLEWORD;
233
234 if ( !m_radioDir || m_radioDir->GetSelection() == 1 )
235 {
236 flags |= wxFR_DOWN;
237 }
238
239 event.SetFlags(flags);
240
241 wxFindReplaceDialogBase::Send(event);
242 }
243
244 // ----------------------------------------------------------------------------
245 // event handlers
246 // ----------------------------------------------------------------------------
247
248 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
249 {
250 SendEvent(wxEVT_COMMAND_FIND_NEXT);
251 }
252
253 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
254 {
255 SendEvent(wxEVT_COMMAND_FIND_REPLACE);
256 }
257
258 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
259 {
260 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL);
261 }
262
263 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
264 {
265 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
266
267 Show(FALSE);
268 }
269
270 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event)
271 {
272 // we can't search for empty strings
273 event.Enable( !m_textFind->GetValue().empty() );
274 }
275
276 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent &)
277 {
278 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
279 }
280
281 #endif // wxUSE_FINDREPLDLG
282