1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fdrepdlg.cpp
3 // Purpose: Find/Replace dialogs
4 // Author: Markus Greither and Vadim Zeitlin
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/radiobox.h"
37 #include "wx/stattext.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
42 #include "wx/fdrepdlg.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // ============================================================================
50 // ============================================================================
52 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog
, wxDialog
)
54 BEGIN_EVENT_TABLE(wxGenericFindReplaceDialog
, wxDialog
)
55 EVT_BUTTON(wxID_FIND
, wxGenericFindReplaceDialog::OnFind
)
56 EVT_BUTTON(wxID_REPLACE
, wxGenericFindReplaceDialog::OnReplace
)
57 EVT_BUTTON(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnReplaceAll
)
58 EVT_BUTTON(wxID_CANCEL
, wxGenericFindReplaceDialog::OnCancel
)
60 EVT_UPDATE_UI(wxID_FIND
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
61 EVT_UPDATE_UI(wxID_REPLACE
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
62 EVT_UPDATE_UI(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
64 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow
)
67 // ----------------------------------------------------------------------------
68 // wxGenericFindReplaceDialog
69 // ----------------------------------------------------------------------------
71 void wxGenericFindReplaceDialog::Init()
73 m_FindReplaceData
= NULL
;
84 bool wxGenericFindReplaceDialog::Create(wxWindow
*parent
,
85 wxFindReplaceData
*data
,
86 const wxString
& title
,
89 parent
= GetParentForModalDialog(parent
, style
);
91 if ( !wxDialog::Create(parent
, wxID_ANY
, title
,
92 wxDefaultPosition
, wxDefaultSize
,
93 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
101 wxCHECK_MSG( m_FindReplaceData
, false,
102 wxT("can't create dialog without data") );
104 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
106 wxBoxSizer
*leftsizer
= new wxBoxSizer( wxVERTICAL
);
108 // 3 columns because there is a spacer in the middle
109 wxFlexGridSizer
*sizer2Col
= new wxFlexGridSizer(3);
110 sizer2Col
->AddGrowableCol(2);
112 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Search for:"),
113 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
115 wxALIGN_CENTRE_VERTICAL
| wxALIGN_RIGHT
);
117 sizer2Col
->Add(10, 0);
119 m_textFind
= new wxTextCtrl(this, wxID_ANY
, m_FindReplaceData
->GetFindString());
120 sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL
| wxEXPAND
);
122 if ( style
& wxFR_REPLACEDIALOG
)
124 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Replace with:"),
125 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
127 wxALIGN_CENTRE_VERTICAL
|
128 wxALIGN_RIGHT
| wxTOP
, 5);
130 sizer2Col
->Add(isPda
? 2 : 10, 0);
132 m_textRepl
= new wxTextCtrl(this, wxID_ANY
,
133 m_FindReplaceData
->GetReplaceString());
134 sizer2Col
->Add(m_textRepl
, 1,
135 wxALIGN_CENTRE_VERTICAL
| wxEXPAND
| wxTOP
, 5);
138 leftsizer
->Add(sizer2Col
, 0, wxEXPAND
| wxALL
, 5);
140 wxBoxSizer
*optsizer
= new wxBoxSizer( isPda
? wxVERTICAL
: wxHORIZONTAL
);
142 wxBoxSizer
*chksizer
= new wxBoxSizer( wxVERTICAL
);
144 m_chkWord
= new wxCheckBox(this, wxID_ANY
, _("Whole word"));
145 chksizer
->Add(m_chkWord
, 0, wxALL
, 3);
147 m_chkCase
= new wxCheckBox(this, wxID_ANY
, _("Match case"));
148 chksizer
->Add(m_chkCase
, 0, wxALL
, 3);
150 optsizer
->Add(chksizer
, 0, wxALL
, 10);
152 static const wxString searchDirections
[] = {_("Up"), _("Down")};
153 int majorDimension
= 0;
156 rbStyle
= wxRA_SPECIFY_ROWS
;
158 rbStyle
= wxRA_SPECIFY_COLS
;
160 m_radioDir
= new wxRadioBox(this, wxID_ANY
, _("Search direction"),
161 wxDefaultPosition
, wxDefaultSize
,
162 WXSIZEOF(searchDirections
), searchDirections
,
163 majorDimension
, rbStyle
);
165 optsizer
->Add(m_radioDir
, 0, wxALL
, isPda
? 5 : 10);
167 leftsizer
->Add(optsizer
);
169 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
171 wxButton
* btn
= new wxButton(this, wxID_FIND
);
173 bttnsizer
->Add(btn
, 0, wxALL
, 3);
175 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 3);
177 if ( style
& wxFR_REPLACEDIALOG
)
179 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
182 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
186 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
188 topsizer
->Add(leftsizer
, 1, wxALL
, isPda
? 0 : 5);
189 topsizer
->Add(bttnsizer
, 0, wxALL
, isPda
? 0 : 5);
191 int flags
= m_FindReplaceData
->GetFlags();
193 if ( flags
& wxFR_MATCHCASE
)
194 m_chkCase
->SetValue(true);
196 if ( flags
& wxFR_WHOLEWORD
)
197 m_chkWord
->SetValue(true);
199 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
201 if ( style
& wxFR_NOMATCHCASE
)
202 m_chkCase
->Enable(false);
204 if ( style
& wxFR_NOWHOLEWORD
)
205 m_chkWord
->Enable(false);
207 if ( style
& wxFR_NOUPDOWN
)
208 m_radioDir
->Enable(false);
210 SetAutoLayout( true );
211 SetSizer( topsizer
);
213 topsizer
->SetSizeHints( this );
214 topsizer
->Fit( this );
218 m_textFind
->SetFocus();
223 // ----------------------------------------------------------------------------
224 // send the notification event
225 // ----------------------------------------------------------------------------
227 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
229 wxFindDialogEvent
event(evtType
, GetId());
230 event
.SetEventObject(this);
231 event
.SetFindString(m_textFind
->GetValue());
232 if ( HasFlag(wxFR_REPLACEDIALOG
) )
234 event
.SetReplaceString(m_textRepl
->GetValue());
239 if ( m_chkCase
->GetValue() )
240 flags
|= wxFR_MATCHCASE
;
242 if ( m_chkWord
->GetValue() )
243 flags
|= wxFR_WHOLEWORD
;
245 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
250 event
.SetFlags(flags
);
252 wxFindReplaceDialogBase::Send(event
);
255 // ----------------------------------------------------------------------------
257 // ----------------------------------------------------------------------------
259 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
))
261 SendEvent(wxEVT_FIND_NEXT
);
264 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
))
266 SendEvent(wxEVT_FIND_REPLACE
);
269 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
))
271 SendEvent(wxEVT_FIND_REPLACE_ALL
);
274 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
276 SendEvent(wxEVT_FIND_CLOSE
);
281 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
283 // we can't search for empty strings
284 event
.Enable( !m_textFind
->GetValue().empty() );
287 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
289 SendEvent(wxEVT_FIND_CLOSE
);
292 #endif // wxUSE_FINDREPLDLG