1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fdrepgg.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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "genericfdrepdlg.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
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"
46 #include "wx/fdrepdlg.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 // ============================================================================
54 // ============================================================================
56 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog
, wxDialog
)
58 BEGIN_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
)
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
)
68 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow
)
71 // ----------------------------------------------------------------------------
72 // wxGenericFindReplaceDialog
73 // ----------------------------------------------------------------------------
75 void wxGenericFindReplaceDialog::Init()
77 m_FindReplaceData
= NULL
;
88 bool wxGenericFindReplaceDialog::Create(wxWindow
*parent
,
89 wxFindReplaceData
*data
,
90 const wxString
& title
,
93 if ( !wxDialog::Create(parent
, wxID_ANY
, title
,
94 wxDefaultPosition
, wxDefaultSize
,
95 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
| style
) )
102 wxCHECK_MSG( m_FindReplaceData
, false,
103 _T("can't create dialog without data") );
105 wxBoxSizer
*leftsizer
= new wxBoxSizer( wxVERTICAL
);
107 // 3 columns because there is a spacer in the middle
108 wxFlexGridSizer
*sizer2Col
= new wxFlexGridSizer(3);
109 sizer2Col
->AddGrowableCol(2);
111 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Search for:"),
112 wxDefaultPosition
, wxSize(80, wxDefaultSize
.y
)),
114 wxALIGN_CENTRE_VERTICAL
| wxALIGN_RIGHT
);
116 sizer2Col
->Add(10, 0);
118 m_textFind
= new wxTextCtrl(this, wxID_ANY
, m_FindReplaceData
->GetFindString());
119 sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL
| wxEXPAND
);
121 if ( style
& wxFR_REPLACEDIALOG
)
123 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Replace with:"),
124 wxDefaultPosition
, wxSize(80, wxDefaultSize
.y
)),
126 wxALIGN_CENTRE_VERTICAL
|
127 wxALIGN_RIGHT
| wxTOP
, 5);
129 sizer2Col
->Add(10, 0);
131 m_textRepl
= new wxTextCtrl(this, wxID_ANY
,
132 m_FindReplaceData
->GetReplaceString());
133 sizer2Col
->Add(m_textRepl
, 1,
134 wxALIGN_CENTRE_VERTICAL
| wxEXPAND
| wxTOP
, 5);
137 leftsizer
->Add(sizer2Col
, 0, wxEXPAND
| wxALL
, 5);
139 wxBoxSizer
*optsizer
= new wxBoxSizer( wxHORIZONTAL
);
141 wxBoxSizer
*chksizer
= new wxBoxSizer( wxVERTICAL
);
143 m_chkWord
= new wxCheckBox(this, wxID_ANY
, _("Whole word"));
144 chksizer
->Add(m_chkWord
, 0, wxALL
, 3);
146 m_chkCase
= new wxCheckBox(this, wxID_ANY
, _("Match case"));
147 chksizer
->Add(m_chkCase
, 0, wxALL
, 3);
149 optsizer
->Add(chksizer
, 0, wxALL
, 10);
151 static const wxString searchDirections
[] = {_("Up"), _("Down")};
152 m_radioDir
= new wxRadioBox(this, wxID_ANY
, _("Search direction"),
153 wxDefaultPosition
, wxDefaultSize
,
154 WXSIZEOF(searchDirections
), searchDirections
);
156 optsizer
->Add(m_radioDir
, 0, wxALL
, 10);
158 leftsizer
->Add(optsizer
);
160 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
162 bttnsizer
->Add(new wxButton(this, wxID_FIND
, _("&Find")), 0, wxALL
, 3);
164 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
, _("&Cancel")), 0, wxALL
, 3);
166 if ( style
& wxFR_REPLACEDIALOG
)
168 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
171 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
175 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
177 topsizer
->Add(leftsizer
, 1, wxALL
, 5);
178 topsizer
->Add(bttnsizer
, 0, wxALL
, 5);
180 int flags
= m_FindReplaceData
->GetFlags();
182 if ( flags
& wxFR_MATCHCASE
)
183 m_chkCase
->SetValue(true);
185 if ( flags
& wxFR_WHOLEWORD
)
186 m_chkWord
->SetValue(true);
188 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
190 if ( style
& wxFR_NOMATCHCASE
)
191 m_chkCase
->Enable(false);
193 if ( style
& wxFR_NOWHOLEWORD
)
194 m_chkWord
->Enable(false);
196 if ( style
& wxFR_NOUPDOWN
)
197 m_radioDir
->Enable(false);
199 SetAutoLayout( true );
200 SetSizer( topsizer
);
202 topsizer
->SetSizeHints( this );
203 topsizer
->Fit( this );
207 m_textFind
->SetFocus();
212 // ----------------------------------------------------------------------------
213 // send the notification event
214 // ----------------------------------------------------------------------------
216 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
218 wxFindDialogEvent
event(evtType
, GetId());
219 event
.SetEventObject(this);
220 event
.SetFindString(m_textFind
->GetValue());
221 if ( HasFlag(wxFR_REPLACEDIALOG
) )
223 event
.SetReplaceString(m_textRepl
->GetValue());
228 if ( m_chkCase
->GetValue() )
229 flags
|= wxFR_MATCHCASE
;
231 if ( m_chkWord
->GetValue() )
232 flags
|= wxFR_WHOLEWORD
;
234 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
239 event
.SetFlags(flags
);
241 wxFindReplaceDialogBase::Send(event
);
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
))
250 SendEvent(wxEVT_COMMAND_FIND_NEXT
);
253 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
))
255 SendEvent(wxEVT_COMMAND_FIND_REPLACE
);
258 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
))
260 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL
);
263 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
265 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
270 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
272 // we can't search for empty strings
273 event
.Enable( !m_textFind
->GetValue().empty() );
276 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
278 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
281 #endif // wxUSE_FINDREPLDLG