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 // ----------------------------------------------------------------------------
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"
42 #include "wx/fdrepdlg.h"
43 #include "wx/settings.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 if ( !wxDialog::Create(parent
, wxID_ANY
, title
,
91 wxDefaultPosition
, wxDefaultSize
,
92 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
100 wxCHECK_MSG( m_FindReplaceData
, false,
101 _T("can't create dialog without data") );
103 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
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, wxDefaultCoord
)),
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, wxDefaultCoord
)),
126 wxALIGN_CENTRE_VERTICAL
|
127 wxALIGN_RIGHT
| wxTOP
, 5);
129 sizer2Col
->Add(isPda
? 2 : 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( isPda
? wxVERTICAL
: 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 int majorDimension
= 0;
155 rbStyle
= wxRA_SPECIFY_ROWS
;
157 rbStyle
= wxRA_SPECIFY_COLS
;
159 m_radioDir
= new wxRadioBox(this, wxID_ANY
, _("Search direction"),
160 wxDefaultPosition
, wxDefaultSize
,
161 WXSIZEOF(searchDirections
), searchDirections
,
162 majorDimension
, rbStyle
);
164 optsizer
->Add(m_radioDir
, 0, wxALL
, isPda
? 5 : 10);
166 leftsizer
->Add(optsizer
);
168 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
170 wxButton
* btn
= new wxButton(this, wxID_FIND
);
172 bttnsizer
->Add(btn
, 0, wxALL
, 3);
174 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 3);
176 if ( style
& wxFR_REPLACEDIALOG
)
178 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
181 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
185 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
187 topsizer
->Add(leftsizer
, 1, wxALL
, isPda
? 0 : 5);
188 topsizer
->Add(bttnsizer
, 0, wxALL
, isPda
? 0 : 5);
190 int flags
= m_FindReplaceData
->GetFlags();
192 if ( flags
& wxFR_MATCHCASE
)
193 m_chkCase
->SetValue(true);
195 if ( flags
& wxFR_WHOLEWORD
)
196 m_chkWord
->SetValue(true);
198 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
200 if ( style
& wxFR_NOMATCHCASE
)
201 m_chkCase
->Enable(false);
203 if ( style
& wxFR_NOWHOLEWORD
)
204 m_chkWord
->Enable(false);
206 if ( style
& wxFR_NOUPDOWN
)
207 m_radioDir
->Enable(false);
209 SetAutoLayout( true );
210 SetSizer( topsizer
);
212 topsizer
->SetSizeHints( this );
213 topsizer
->Fit( this );
217 m_textFind
->SetFocus();
222 // ----------------------------------------------------------------------------
223 // send the notification event
224 // ----------------------------------------------------------------------------
226 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
228 wxFindDialogEvent
event(evtType
, GetId());
229 event
.SetEventObject(this);
230 event
.SetFindString(m_textFind
->GetValue());
231 if ( HasFlag(wxFR_REPLACEDIALOG
) )
233 event
.SetReplaceString(m_textRepl
->GetValue());
238 if ( m_chkCase
->GetValue() )
239 flags
|= wxFR_MATCHCASE
;
241 if ( m_chkWord
->GetValue() )
242 flags
|= wxFR_WHOLEWORD
;
244 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
249 event
.SetFlags(flags
);
251 wxFindReplaceDialogBase::Send(event
);
254 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
258 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
))
260 SendEvent(wxEVT_COMMAND_FIND_NEXT
);
263 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
))
265 SendEvent(wxEVT_COMMAND_FIND_REPLACE
);
268 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
))
270 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL
);
273 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
275 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
280 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
282 // we can't search for empty strings
283 event
.Enable( !m_textFind
->GetValue().empty() );
286 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
288 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
291 #endif // wxUSE_FINDREPLDLG