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