]> git.saurik.com Git - wxWidgets.git/blame - src/generic/fdrepdlg.cpp
replaced all int/size_t indices in wxControlWithItems API with unsigned int (committi...
[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:
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
8db37e06
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
8db37e06
VZ
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"
94f53923 43#include "wx/settings.h"
8db37e06
VZ
44
45// ----------------------------------------------------------------------------
46// constants
47// ----------------------------------------------------------------------------
48
8db37e06
VZ
49// ============================================================================
50// implementation
51// ============================================================================
52
53IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog, wxDialog)
54
55BEGIN_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)
66END_EVENT_TABLE()
67
68// ----------------------------------------------------------------------------
69// wxGenericFindReplaceDialog
70// ----------------------------------------------------------------------------
71
72void 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
85bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
86 wxFindReplaceData *data,
87 const wxString& title,
88 int style)
89{
ca65c044 90 if ( !wxDialog::Create(parent, wxID_ANY, title,
8db37e06 91 wxDefaultPosition, wxDefaultSize,
aa66250b
JS
92 wxDEFAULT_DIALOG_STYLE
93#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
94 | wxRESIZE_BORDER
95#endif
96 | style) )
8db37e06 97 {
ca65c044 98 return false;
8db37e06
VZ
99 }
100
101 SetData(data);
102
ca65c044 103 wxCHECK_MSG( m_FindReplaceData, false,
8db37e06
VZ
104 _T("can't create dialog without data") );
105
94f53923
JS
106 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
107
8db37e06
VZ
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
ca65c044 114 sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Search for:"),
422d0ff0 115 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
8db37e06
VZ
116 0,
117 wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
118
119 sizer2Col->Add(10, 0);
120
ca65c044 121 m_textFind = new wxTextCtrl(this, wxID_ANY, m_FindReplaceData->GetFindString());
8db37e06
VZ
122 sizer2Col->Add(m_textFind, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
123
124 if ( style & wxFR_REPLACEDIALOG )
125 {
ca65c044 126 sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Replace with:"),
422d0ff0 127 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
8db37e06
VZ
128 0,
129 wxALIGN_CENTRE_VERTICAL |
130 wxALIGN_RIGHT | wxTOP, 5);
131
94f53923 132 sizer2Col->Add(isPda ? 2 : 10, 0);
8db37e06 133
ca65c044 134 m_textRepl = new wxTextCtrl(this, wxID_ANY,
8db37e06
VZ
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
94f53923 142 wxBoxSizer *optsizer = new wxBoxSizer( isPda ? wxVERTICAL : wxHORIZONTAL );
8db37e06
VZ
143
144 wxBoxSizer *chksizer = new wxBoxSizer( wxVERTICAL);
145
ca65c044 146 m_chkWord = new wxCheckBox(this, wxID_ANY, _("Whole word"));
8db37e06
VZ
147 chksizer->Add(m_chkWord, 0, wxALL, 3);
148
ca65c044 149 m_chkCase = new wxCheckBox(this, wxID_ANY, _("Match case"));
8db37e06
VZ
150 chksizer->Add(m_chkCase, 0, wxALL, 3);
151
152 optsizer->Add(chksizer, 0, wxALL, 10);
153
154 static const wxString searchDirections[] = {_("Up"), _("Down")};
94f53923
JS
155 int majorDimension = 0;
156 int rbStyle ;
157 if (isPda)
158 rbStyle = wxRA_SPECIFY_ROWS;
159 else
160 rbStyle = wxRA_SPECIFY_COLS;
161
ca65c044 162 m_radioDir = new wxRadioBox(this, wxID_ANY, _("Search direction"),
8db37e06 163 wxDefaultPosition, wxDefaultSize,
94f53923
JS
164 WXSIZEOF(searchDirections), searchDirections,
165 majorDimension, rbStyle);
8db37e06 166
94f53923 167 optsizer->Add(m_radioDir, 0, wxALL, isPda ? 5 : 10);
8db37e06
VZ
168
169 leftsizer->Add(optsizer);
170
171 wxBoxSizer *bttnsizer = new wxBoxSizer(wxVERTICAL);
172
1c95468e
RD
173 wxButton* btn = new wxButton(this, wxID_FIND);
174 btn->SetDefault();
175 bttnsizer->Add(btn, 0, wxALL, 3);
8db37e06 176
5f7bcb48 177 bttnsizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 3);
8db37e06
VZ
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
94f53923
JS
190 topsizer->Add(leftsizer, 1, wxALL, isPda ? 0 : 5);
191 topsizer->Add(bttnsizer, 0, wxALL, isPda ? 0 : 5);
8db37e06
VZ
192
193 int flags = m_FindReplaceData->GetFlags();
194
195 if ( flags & wxFR_MATCHCASE )
ca65c044 196 m_chkCase->SetValue(true);
8db37e06
VZ
197
198 if ( flags & wxFR_WHOLEWORD )
ca65c044 199 m_chkWord->SetValue(true);
8db37e06
VZ
200
201 m_radioDir->SetSelection( flags & wxFR_DOWN );
202
203 if ( style & wxFR_NOMATCHCASE )
ca65c044 204 m_chkCase->Enable(false);
8db37e06
VZ
205
206 if ( style & wxFR_NOWHOLEWORD )
ca65c044 207 m_chkWord->Enable(false);
8db37e06
VZ
208
209 if ( style & wxFR_NOUPDOWN)
ca65c044 210 m_radioDir->Enable(false);
8db37e06 211
ca65c044 212 SetAutoLayout( true );
8db37e06
VZ
213 SetSizer( topsizer );
214
aa66250b 215#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
8db37e06
VZ
216 topsizer->SetSizeHints( this );
217 topsizer->Fit( this );
218
219 Centre( wxBOTH );
aa66250b 220#endif
8db37e06
VZ
221
222 m_textFind->SetFocus();
223
ca65c044 224 return true;
8db37e06
VZ
225}
226
227// ----------------------------------------------------------------------------
228// send the notification event
229// ----------------------------------------------------------------------------
230
231void 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
d84afea9 263void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
264{
265 SendEvent(wxEVT_COMMAND_FIND_NEXT);
266}
267
d84afea9 268void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
269{
270 SendEvent(wxEVT_COMMAND_FIND_REPLACE);
271}
272
d84afea9 273void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
274{
275 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL);
276}
277
d84afea9 278void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
279{
280 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
281
ca65c044 282 Show(false);
8db37e06
VZ
283}
284
285void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event)
286{
287 // we can't search for empty strings
288 event.Enable( !m_textFind->GetValue().empty() );
289}
290
291void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent &)
292{
293 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
294}
295
296#endif // wxUSE_FINDREPLDLG
297