1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fdrepgg.cpp
3 // Purpose: Find/Replace dialogs
4 // Author: Markus Greither and Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
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 // ----------------------------------------------------------------------------
58 // ============================================================================
60 // ============================================================================
62 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog
, wxDialog
)
64 BEGIN_EVENT_TABLE(wxGenericFindReplaceDialog
, wxDialog
)
65 EVT_BUTTON(wxID_FIND
, wxGenericFindReplaceDialog::OnFind
)
66 EVT_BUTTON(wxID_REPLACE
, wxGenericFindReplaceDialog::OnReplace
)
67 EVT_BUTTON(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnReplaceAll
)
68 EVT_BUTTON(wxID_CANCEL
, wxGenericFindReplaceDialog::OnCancel
)
70 EVT_UPDATE_UI(wxID_FIND
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
71 EVT_UPDATE_UI(wxID_REPLACE
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
72 EVT_UPDATE_UI(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
74 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow
)
77 // ----------------------------------------------------------------------------
78 // wxGenericFindReplaceDialog
79 // ----------------------------------------------------------------------------
81 void wxGenericFindReplaceDialog::Init()
83 m_FindReplaceData
= NULL
;
94 bool wxGenericFindReplaceDialog::Create(wxWindow
*parent
,
95 wxFindReplaceData
*data
,
96 const wxString
& title
,
99 if ( !wxDialog::Create(parent
, -1, title
,
100 wxDefaultPosition
, wxDefaultSize
,
101 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
| style
) )
108 wxCHECK_MSG( m_FindReplaceData
, FALSE
,
109 _T("can't create dialog without data") );
111 wxBoxSizer
*leftsizer
= new wxBoxSizer( wxVERTICAL
);
113 // 3 columns because there is a spacer in the middle
114 wxFlexGridSizer
*sizer2Col
= new wxFlexGridSizer(3);
115 sizer2Col
->AddGrowableCol(2);
117 sizer2Col
->Add(new wxStaticText(this, -1, _("Search for:"),
118 wxDefaultPosition
, wxSize(80, -1)),
120 wxALIGN_CENTRE_VERTICAL
| wxALIGN_RIGHT
);
122 sizer2Col
->Add(10, 0);
124 m_textFind
= new wxTextCtrl(this, -1, m_FindReplaceData
->GetFindString());
125 sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL
| wxEXPAND
);
127 if ( style
& wxFR_REPLACEDIALOG
)
129 sizer2Col
->Add(new wxStaticText(this, -1, _("Replace with:"),
130 wxDefaultPosition
, wxSize(80, -1)),
132 wxALIGN_CENTRE_VERTICAL
|
133 wxALIGN_RIGHT
| wxTOP
, 5);
135 sizer2Col
->Add(10, 0);
137 m_textRepl
= new wxTextCtrl(this, -1,
138 m_FindReplaceData
->GetReplaceString());
139 sizer2Col
->Add(m_textRepl
, 1,
140 wxALIGN_CENTRE_VERTICAL
| wxEXPAND
| wxTOP
, 5);
143 leftsizer
->Add(sizer2Col
, 0, wxEXPAND
| wxALL
, 5);
145 wxBoxSizer
*optsizer
= new wxBoxSizer( wxHORIZONTAL
);
147 wxBoxSizer
*chksizer
= new wxBoxSizer( wxVERTICAL
);
149 m_chkWord
= new wxCheckBox(this, -1, _("Whole word"));
150 chksizer
->Add(m_chkWord
, 0, wxALL
, 3);
152 m_chkCase
= new wxCheckBox(this, -1, _("Match case"));
153 chksizer
->Add(m_chkCase
, 0, wxALL
, 3);
155 optsizer
->Add(chksizer
, 0, wxALL
, 10);
157 static const wxString searchDirections
[] = {_("Up"), _("Down")};
158 m_radioDir
= new wxRadioBox(this, -1, _("Search direction"),
159 wxDefaultPosition
, wxDefaultSize
,
160 WXSIZEOF(searchDirections
), searchDirections
);
162 optsizer
->Add(m_radioDir
, 0, wxALL
, 10);
164 leftsizer
->Add(optsizer
);
166 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
168 bttnsizer
->Add(new wxButton(this, wxID_FIND
, _("&Find")), 0, wxALL
, 3);
170 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
, _("&Cancel")), 0, wxALL
, 3);
172 if ( style
& wxFR_REPLACEDIALOG
)
174 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
177 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
181 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
183 topsizer
->Add(leftsizer
, 1, wxALL
, 5);
184 topsizer
->Add(bttnsizer
, 0, wxALL
, 5);
186 int flags
= m_FindReplaceData
->GetFlags();
188 if ( flags
& wxFR_MATCHCASE
)
189 m_chkCase
->SetValue(TRUE
);
191 if ( flags
& wxFR_WHOLEWORD
)
192 m_chkWord
->SetValue(TRUE
);
194 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
196 if ( style
& wxFR_NOMATCHCASE
)
197 m_chkCase
->Enable(FALSE
);
199 if ( style
& wxFR_NOWHOLEWORD
)
200 m_chkWord
->Enable(FALSE
);
202 if ( style
& wxFR_NOUPDOWN
)
203 m_radioDir
->Enable(FALSE
);
205 SetAutoLayout( TRUE
);
206 SetSizer( topsizer
);
208 topsizer
->SetSizeHints( this );
209 topsizer
->Fit( this );
213 m_textFind
->SetFocus();
218 // ----------------------------------------------------------------------------
219 // send the notification event
220 // ----------------------------------------------------------------------------
222 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
224 wxFindDialogEvent
event(evtType
, GetId());
225 event
.SetEventObject(this);
226 event
.SetFindString(m_textFind
->GetValue());
227 if ( HasFlag(wxFR_REPLACEDIALOG
) )
229 event
.SetReplaceString(m_textRepl
->GetValue());
234 if ( m_chkCase
->GetValue() )
235 flags
|= wxFR_MATCHCASE
;
237 if ( m_chkWord
->GetValue() )
238 flags
|= wxFR_WHOLEWORD
;
240 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
245 event
.SetFlags(flags
);
247 wxFindReplaceDialogBase::Send(event
);
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& event
)
256 SendEvent(wxEVT_COMMAND_FIND_NEXT
);
259 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& event
)
261 SendEvent(wxEVT_COMMAND_FIND_REPLACE
);
264 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& event
)
266 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL
);
269 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& event
)
271 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
276 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
278 // we can't search for empty strings
279 event
.Enable( !m_textFind
->GetValue().empty() );
282 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
284 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
287 #endif // wxUSE_FINDREPLDLG