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