1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fdrepdlg.cpp
3 // Purpose: Find/Replace dialogs
4 // Author: Markus Greither and Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
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 #include "wx/settings.h"
43 #include "wx/fdrepdlg.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // ============================================================================
51 // ============================================================================
53 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog
, wxDialog
)
55 BEGIN_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
)
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
)
65 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow
)
68 // ----------------------------------------------------------------------------
69 // wxGenericFindReplaceDialog
70 // ----------------------------------------------------------------------------
72 void wxGenericFindReplaceDialog::Init()
74 m_FindReplaceData
= NULL
;
85 bool wxGenericFindReplaceDialog::Create(wxWindow
*parent
,
86 wxFindReplaceData
*data
,
87 const wxString
& title
,
90 parent
= GetParentForModalDialog(parent
, style
);
92 if ( !wxDialog::Create(parent
, wxID_ANY
, title
,
93 wxDefaultPosition
, wxDefaultSize
,
94 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
102 wxCHECK_MSG( m_FindReplaceData
, false,
103 wxT("can't create dialog without data") );
105 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
107 wxBoxSizer
*leftsizer
= new wxBoxSizer( wxVERTICAL
);
109 // 3 columns because there is a spacer in the middle
110 wxFlexGridSizer
*sizer2Col
= new wxFlexGridSizer(3);
111 sizer2Col
->AddGrowableCol(2);
113 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Search for:"),
114 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
116 wxALIGN_CENTRE_VERTICAL
| wxALIGN_RIGHT
);
118 sizer2Col
->Add(10, 0);
120 m_textFind
= new wxTextCtrl(this, wxID_ANY
, m_FindReplaceData
->GetFindString());
121 sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL
| wxEXPAND
);
123 if ( style
& wxFR_REPLACEDIALOG
)
125 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Replace with:"),
126 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
128 wxALIGN_CENTRE_VERTICAL
|
129 wxALIGN_RIGHT
| wxTOP
, 5);
131 sizer2Col
->Add(isPda
? 2 : 10, 0);
133 m_textRepl
= new wxTextCtrl(this, wxID_ANY
,
134 m_FindReplaceData
->GetReplaceString());
135 sizer2Col
->Add(m_textRepl
, 1,
136 wxALIGN_CENTRE_VERTICAL
| wxEXPAND
| wxTOP
, 5);
139 leftsizer
->Add(sizer2Col
, 0, wxEXPAND
| wxALL
, 5);
141 wxBoxSizer
*optsizer
= new wxBoxSizer( isPda
? wxVERTICAL
: wxHORIZONTAL
);
143 wxBoxSizer
*chksizer
= new wxBoxSizer( wxVERTICAL
);
145 m_chkWord
= new wxCheckBox(this, wxID_ANY
, _("Whole word"));
146 chksizer
->Add(m_chkWord
, 0, wxALL
, 3);
148 m_chkCase
= new wxCheckBox(this, wxID_ANY
, _("Match case"));
149 chksizer
->Add(m_chkCase
, 0, wxALL
, 3);
151 optsizer
->Add(chksizer
, 0, wxALL
, 10);
153 static const wxString searchDirections
[] = {_("Up"), _("Down")};
154 int majorDimension
= 0;
157 rbStyle
= wxRA_SPECIFY_ROWS
;
159 rbStyle
= wxRA_SPECIFY_COLS
;
161 m_radioDir
= new wxRadioBox(this, wxID_ANY
, _("Search direction"),
162 wxDefaultPosition
, wxDefaultSize
,
163 WXSIZEOF(searchDirections
), searchDirections
,
164 majorDimension
, rbStyle
);
166 optsizer
->Add(m_radioDir
, 0, wxALL
, isPda
? 5 : 10);
168 leftsizer
->Add(optsizer
);
170 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
172 wxButton
* btn
= new wxButton(this, wxID_FIND
);
174 bttnsizer
->Add(btn
, 0, wxALL
, 3);
176 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 3);
178 if ( style
& wxFR_REPLACEDIALOG
)
180 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
183 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
187 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
189 topsizer
->Add(leftsizer
, 1, wxALL
, isPda
? 0 : 5);
190 topsizer
->Add(bttnsizer
, 0, wxALL
, isPda
? 0 : 5);
192 int flags
= m_FindReplaceData
->GetFlags();
194 if ( flags
& wxFR_MATCHCASE
)
195 m_chkCase
->SetValue(true);
197 if ( flags
& wxFR_WHOLEWORD
)
198 m_chkWord
->SetValue(true);
200 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
202 if ( style
& wxFR_NOMATCHCASE
)
203 m_chkCase
->Enable(false);
205 if ( style
& wxFR_NOWHOLEWORD
)
206 m_chkWord
->Enable(false);
208 if ( style
& wxFR_NOUPDOWN
)
209 m_radioDir
->Enable(false);
211 SetAutoLayout( true );
212 SetSizer( topsizer
);
214 topsizer
->SetSizeHints( this );
215 topsizer
->Fit( this );
219 m_textFind
->SetFocus();
224 // ----------------------------------------------------------------------------
225 // send the notification event
226 // ----------------------------------------------------------------------------
228 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
230 wxFindDialogEvent
event(evtType
, GetId());
231 event
.SetEventObject(this);
232 event
.SetFindString(m_textFind
->GetValue());
233 if ( HasFlag(wxFR_REPLACEDIALOG
) )
235 event
.SetReplaceString(m_textRepl
->GetValue());
240 if ( m_chkCase
->GetValue() )
241 flags
|= wxFR_MATCHCASE
;
243 if ( m_chkWord
->GetValue() )
244 flags
|= wxFR_WHOLEWORD
;
246 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
251 event
.SetFlags(flags
);
253 wxFindReplaceDialogBase::Send(event
);
256 // ----------------------------------------------------------------------------
258 // ----------------------------------------------------------------------------
260 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
))
262 SendEvent(wxEVT_FIND_NEXT
);
265 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
))
267 SendEvent(wxEVT_FIND_REPLACE
);
270 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
))
272 SendEvent(wxEVT_FIND_REPLACE_ALL
);
275 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
277 SendEvent(wxEVT_FIND_CLOSE
);
282 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
284 // we can't search for empty strings
285 event
.Enable( !m_textFind
->GetValue().empty() );
288 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
290 SendEvent(wxEVT_FIND_CLOSE
);
293 #endif // wxUSE_FINDREPLDLG