]> git.saurik.com Git - wxWidgets.git/blame - src/generic/fdrepdlg.cpp
Added Set/GetQuickBestSize
[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,
f43255e8 92 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
aa66250b 93 | style) )
8db37e06 94 {
ca65c044 95 return false;
8db37e06
VZ
96 }
97
98 SetData(data);
99
ca65c044 100 wxCHECK_MSG( m_FindReplaceData, false,
8db37e06
VZ
101 _T("can't create dialog without data") );
102
94f53923 103 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
f43255e8 104
8db37e06
VZ
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
ca65c044 111 sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Search for:"),
422d0ff0 112 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
8db37e06
VZ
113 0,
114 wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
115
116 sizer2Col->Add(10, 0);
117
ca65c044 118 m_textFind = new wxTextCtrl(this, wxID_ANY, m_FindReplaceData->GetFindString());
8db37e06
VZ
119 sizer2Col->Add(m_textFind, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
120
121 if ( style & wxFR_REPLACEDIALOG )
122 {
ca65c044 123 sizer2Col->Add(new wxStaticText(this, wxID_ANY, _("Replace with:"),
422d0ff0 124 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
8db37e06
VZ
125 0,
126 wxALIGN_CENTRE_VERTICAL |
127 wxALIGN_RIGHT | wxTOP, 5);
128
94f53923 129 sizer2Col->Add(isPda ? 2 : 10, 0);
8db37e06 130
ca65c044 131 m_textRepl = new wxTextCtrl(this, wxID_ANY,
8db37e06
VZ
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
94f53923 139 wxBoxSizer *optsizer = new wxBoxSizer( isPda ? wxVERTICAL : wxHORIZONTAL );
8db37e06
VZ
140
141 wxBoxSizer *chksizer = new wxBoxSizer( wxVERTICAL);
142
ca65c044 143 m_chkWord = new wxCheckBox(this, wxID_ANY, _("Whole word"));
8db37e06
VZ
144 chksizer->Add(m_chkWord, 0, wxALL, 3);
145
ca65c044 146 m_chkCase = new wxCheckBox(this, wxID_ANY, _("Match case"));
8db37e06
VZ
147 chksizer->Add(m_chkCase, 0, wxALL, 3);
148
149 optsizer->Add(chksizer, 0, wxALL, 10);
150
151 static const wxString searchDirections[] = {_("Up"), _("Down")};
94f53923
JS
152 int majorDimension = 0;
153 int rbStyle ;
154 if (isPda)
155 rbStyle = wxRA_SPECIFY_ROWS;
156 else
157 rbStyle = wxRA_SPECIFY_COLS;
f43255e8 158
ca65c044 159 m_radioDir = new wxRadioBox(this, wxID_ANY, _("Search direction"),
8db37e06 160 wxDefaultPosition, wxDefaultSize,
94f53923
JS
161 WXSIZEOF(searchDirections), searchDirections,
162 majorDimension, rbStyle);
8db37e06 163
94f53923 164 optsizer->Add(m_radioDir, 0, wxALL, isPda ? 5 : 10);
8db37e06
VZ
165
166 leftsizer->Add(optsizer);
167
168 wxBoxSizer *bttnsizer = new wxBoxSizer(wxVERTICAL);
169
1c95468e
RD
170 wxButton* btn = new wxButton(this, wxID_FIND);
171 btn->SetDefault();
172 bttnsizer->Add(btn, 0, wxALL, 3);
8db37e06 173
5f7bcb48 174 bttnsizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 3);
8db37e06
VZ
175
176 if ( style & wxFR_REPLACEDIALOG )
177 {
178 bttnsizer->Add(new wxButton(this, wxID_REPLACE, _("&Replace")),
179 0, wxALL, 3);
180
181 bttnsizer->Add(new wxButton(this, wxID_REPLACE_ALL, _("Replace &all")),
182 0, wxALL, 3);
183 }
184
185 wxBoxSizer *topsizer = new wxBoxSizer( wxHORIZONTAL );
186
94f53923
JS
187 topsizer->Add(leftsizer, 1, wxALL, isPda ? 0 : 5);
188 topsizer->Add(bttnsizer, 0, wxALL, isPda ? 0 : 5);
8db37e06
VZ
189
190 int flags = m_FindReplaceData->GetFlags();
191
192 if ( flags & wxFR_MATCHCASE )
ca65c044 193 m_chkCase->SetValue(true);
8db37e06
VZ
194
195 if ( flags & wxFR_WHOLEWORD )
ca65c044 196 m_chkWord->SetValue(true);
8db37e06
VZ
197
198 m_radioDir->SetSelection( flags & wxFR_DOWN );
199
200 if ( style & wxFR_NOMATCHCASE )
ca65c044 201 m_chkCase->Enable(false);
8db37e06
VZ
202
203 if ( style & wxFR_NOWHOLEWORD )
ca65c044 204 m_chkWord->Enable(false);
8db37e06
VZ
205
206 if ( style & wxFR_NOUPDOWN)
ca65c044 207 m_radioDir->Enable(false);
8db37e06 208
ca65c044 209 SetAutoLayout( true );
8db37e06
VZ
210 SetSizer( topsizer );
211
212 topsizer->SetSizeHints( this );
213 topsizer->Fit( this );
214
215 Centre( wxBOTH );
216
217 m_textFind->SetFocus();
218
ca65c044 219 return true;
8db37e06
VZ
220}
221
222// ----------------------------------------------------------------------------
223// send the notification event
224// ----------------------------------------------------------------------------
225
226void wxGenericFindReplaceDialog::SendEvent(const wxEventType& evtType)
227{
228 wxFindDialogEvent event(evtType, GetId());
229 event.SetEventObject(this);
230 event.SetFindString(m_textFind->GetValue());
231 if ( HasFlag(wxFR_REPLACEDIALOG) )
232 {
233 event.SetReplaceString(m_textRepl->GetValue());
234 }
235
236 int flags = 0;
237
238 if ( m_chkCase->GetValue() )
239 flags |= wxFR_MATCHCASE;
240
241 if ( m_chkWord->GetValue() )
242 flags |= wxFR_WHOLEWORD;
243
244 if ( !m_radioDir || m_radioDir->GetSelection() == 1 )
245 {
246 flags |= wxFR_DOWN;
247 }
248
249 event.SetFlags(flags);
250
251 wxFindReplaceDialogBase::Send(event);
252}
253
254// ----------------------------------------------------------------------------
255// event handlers
256// ----------------------------------------------------------------------------
257
d84afea9 258void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
259{
260 SendEvent(wxEVT_COMMAND_FIND_NEXT);
261}
262
d84afea9 263void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
264{
265 SendEvent(wxEVT_COMMAND_FIND_REPLACE);
266}
267
d84afea9 268void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
269{
270 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL);
271}
272
d84afea9 273void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
274{
275 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
276
ca65c044 277 Show(false);
8db37e06
VZ
278}
279
280void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event)
281{
282 // we can't search for empty strings
283 event.Enable( !m_textFind->GetValue().empty() );
284}
285
286void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent &)
287{
288 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
289}
290
291#endif // wxUSE_FINDREPLDLG