]> git.saurik.com Git - wxWidgets.git/blame - src/generic/fdrepdlg.cpp
* Made GSocket::GetError() exp/imp from net library and provide an inline
[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
14f355c2 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8db37e06
VZ
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
8db37e06
VZ
52// ============================================================================
53// implementation
54// ============================================================================
55
56IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog, wxDialog)
57
58BEGIN_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)
69END_EVENT_TABLE()
70
71// ----------------------------------------------------------------------------
72// wxGenericFindReplaceDialog
73// ----------------------------------------------------------------------------
74
75void 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
88bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
89 wxFindReplaceData *data,
90 const wxString& title,
91 int style)
92{
ca65c044 93 if ( !wxDialog::Create(parent, wxID_ANY, title,
8db37e06
VZ
94 wxDefaultPosition, wxDefaultSize,
95 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | style) )
96 {
ca65c044 97 return false;
8db37e06
VZ
98 }
99
100 SetData(data);
101
ca65c044 102 wxCHECK_MSG( m_FindReplaceData, false,
8db37e06
VZ
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
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
129 sizer2Col->Add(10, 0);
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
139 wxBoxSizer *optsizer = new wxBoxSizer( wxHORIZONTAL );
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")};
ca65c044 152 m_radioDir = new wxRadioBox(this, wxID_ANY, _("Search direction"),
8db37e06
VZ
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 )
ca65c044 183 m_chkCase->SetValue(true);
8db37e06
VZ
184
185 if ( flags & wxFR_WHOLEWORD )
ca65c044 186 m_chkWord->SetValue(true);
8db37e06
VZ
187
188 m_radioDir->SetSelection( flags & wxFR_DOWN );
189
190 if ( style & wxFR_NOMATCHCASE )
ca65c044 191 m_chkCase->Enable(false);
8db37e06
VZ
192
193 if ( style & wxFR_NOWHOLEWORD )
ca65c044 194 m_chkWord->Enable(false);
8db37e06
VZ
195
196 if ( style & wxFR_NOUPDOWN)
ca65c044 197 m_radioDir->Enable(false);
8db37e06 198
ca65c044 199 SetAutoLayout( true );
8db37e06
VZ
200 SetSizer( topsizer );
201
202 topsizer->SetSizeHints( this );
203 topsizer->Fit( this );
204
205 Centre( wxBOTH );
206
207 m_textFind->SetFocus();
208
ca65c044 209 return true;
8db37e06
VZ
210}
211
212// ----------------------------------------------------------------------------
213// send the notification event
214// ----------------------------------------------------------------------------
215
216void 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
d84afea9 248void wxGenericFindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
249{
250 SendEvent(wxEVT_COMMAND_FIND_NEXT);
251}
252
d84afea9 253void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
254{
255 SendEvent(wxEVT_COMMAND_FIND_REPLACE);
256}
257
d84afea9 258void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
259{
260 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL);
261}
262
d84afea9 263void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
8db37e06
VZ
264{
265 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
266
ca65c044 267 Show(false);
8db37e06
VZ
268}
269
270void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event)
271{
272 // we can't search for empty strings
273 event.Enable( !m_textFind->GetValue().empty() );
274}
275
276void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent &)
277{
278 SendEvent(wxEVT_COMMAND_FIND_CLOSE);
279}
280
281#endif // wxUSE_FINDREPLDLG
282