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"
47 #include "wx/settings.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 // ============================================================================
55 // ============================================================================
57 IMPLEMENT_DYNAMIC_CLASS(wxGenericFindReplaceDialog
, wxDialog
)
59 BEGIN_EVENT_TABLE(wxGenericFindReplaceDialog
, wxDialog
)
60 EVT_BUTTON(wxID_FIND
, wxGenericFindReplaceDialog::OnFind
)
61 EVT_BUTTON(wxID_REPLACE
, wxGenericFindReplaceDialog::OnReplace
)
62 EVT_BUTTON(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnReplaceAll
)
63 EVT_BUTTON(wxID_CANCEL
, wxGenericFindReplaceDialog::OnCancel
)
65 EVT_UPDATE_UI(wxID_FIND
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
66 EVT_UPDATE_UI(wxID_REPLACE
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
67 EVT_UPDATE_UI(wxID_REPLACE_ALL
, wxGenericFindReplaceDialog::OnUpdateFindUI
)
69 EVT_CLOSE(wxGenericFindReplaceDialog::OnCloseWindow
)
72 // ----------------------------------------------------------------------------
73 // wxGenericFindReplaceDialog
74 // ----------------------------------------------------------------------------
76 void wxGenericFindReplaceDialog::Init()
78 m_FindReplaceData
= NULL
;
89 bool wxGenericFindReplaceDialog::Create(wxWindow
*parent
,
90 wxFindReplaceData
*data
,
91 const wxString
& title
,
94 if ( !wxDialog::Create(parent
, wxID_ANY
, title
,
95 wxDefaultPosition
, wxDefaultSize
,
96 wxDEFAULT_DIALOG_STYLE
97 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
107 wxCHECK_MSG( m_FindReplaceData
, false,
108 _T("can't create dialog without data") );
110 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
112 wxBoxSizer
*leftsizer
= new wxBoxSizer( wxVERTICAL
);
114 // 3 columns because there is a spacer in the middle
115 wxFlexGridSizer
*sizer2Col
= new wxFlexGridSizer(3);
116 sizer2Col
->AddGrowableCol(2);
118 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Search for:"),
119 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
121 wxALIGN_CENTRE_VERTICAL
| wxALIGN_RIGHT
);
123 sizer2Col
->Add(10, 0);
125 m_textFind
= new wxTextCtrl(this, wxID_ANY
, m_FindReplaceData
->GetFindString());
126 sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL
| wxEXPAND
);
128 if ( style
& wxFR_REPLACEDIALOG
)
130 sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Replace with:"),
131 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
133 wxALIGN_CENTRE_VERTICAL
|
134 wxALIGN_RIGHT
| wxTOP
, 5);
136 sizer2Col
->Add(isPda
? 2 : 10, 0);
138 m_textRepl
= new wxTextCtrl(this, wxID_ANY
,
139 m_FindReplaceData
->GetReplaceString());
140 sizer2Col
->Add(m_textRepl
, 1,
141 wxALIGN_CENTRE_VERTICAL
| wxEXPAND
| wxTOP
, 5);
144 leftsizer
->Add(sizer2Col
, 0, wxEXPAND
| wxALL
, 5);
146 wxBoxSizer
*optsizer
= new wxBoxSizer( isPda
? wxVERTICAL
: wxHORIZONTAL
);
148 wxBoxSizer
*chksizer
= new wxBoxSizer( wxVERTICAL
);
150 m_chkWord
= new wxCheckBox(this, wxID_ANY
, _("Whole word"));
151 chksizer
->Add(m_chkWord
, 0, wxALL
, 3);
153 m_chkCase
= new wxCheckBox(this, wxID_ANY
, _("Match case"));
154 chksizer
->Add(m_chkCase
, 0, wxALL
, 3);
156 optsizer
->Add(chksizer
, 0, wxALL
, 10);
158 static const wxString searchDirections
[] = {_("Up"), _("Down")};
159 int majorDimension
= 0;
162 rbStyle
= wxRA_SPECIFY_ROWS
;
164 rbStyle
= wxRA_SPECIFY_COLS
;
166 m_radioDir
= new wxRadioBox(this, wxID_ANY
, _("Search direction"),
167 wxDefaultPosition
, wxDefaultSize
,
168 WXSIZEOF(searchDirections
), searchDirections
,
169 majorDimension
, rbStyle
);
171 optsizer
->Add(m_radioDir
, 0, wxALL
, isPda
? 5 : 10);
173 leftsizer
->Add(optsizer
);
175 wxBoxSizer
*bttnsizer
= new wxBoxSizer(wxVERTICAL
);
177 wxButton
* btn
= new wxButton(this, wxID_FIND
);
179 bttnsizer
->Add(btn
, 0, wxALL
, 3);
181 bttnsizer
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 3);
183 if ( style
& wxFR_REPLACEDIALOG
)
185 bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")),
188 bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")),
192 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
194 topsizer
->Add(leftsizer
, 1, wxALL
, isPda
? 0 : 5);
195 topsizer
->Add(bttnsizer
, 0, wxALL
, isPda
? 0 : 5);
197 int flags
= m_FindReplaceData
->GetFlags();
199 if ( flags
& wxFR_MATCHCASE
)
200 m_chkCase
->SetValue(true);
202 if ( flags
& wxFR_WHOLEWORD
)
203 m_chkWord
->SetValue(true);
205 m_radioDir
->SetSelection( flags
& wxFR_DOWN
);
207 if ( style
& wxFR_NOMATCHCASE
)
208 m_chkCase
->Enable(false);
210 if ( style
& wxFR_NOWHOLEWORD
)
211 m_chkWord
->Enable(false);
213 if ( style
& wxFR_NOUPDOWN
)
214 m_radioDir
->Enable(false);
216 SetAutoLayout( true );
217 SetSizer( topsizer
);
219 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
220 topsizer
->SetSizeHints( this );
221 topsizer
->Fit( this );
226 m_textFind
->SetFocus();
231 // ----------------------------------------------------------------------------
232 // send the notification event
233 // ----------------------------------------------------------------------------
235 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
)
237 wxFindDialogEvent
event(evtType
, GetId());
238 event
.SetEventObject(this);
239 event
.SetFindString(m_textFind
->GetValue());
240 if ( HasFlag(wxFR_REPLACEDIALOG
) )
242 event
.SetReplaceString(m_textRepl
->GetValue());
247 if ( m_chkCase
->GetValue() )
248 flags
|= wxFR_MATCHCASE
;
250 if ( m_chkWord
->GetValue() )
251 flags
|= wxFR_WHOLEWORD
;
253 if ( !m_radioDir
|| m_radioDir
->GetSelection() == 1 )
258 event
.SetFlags(flags
);
260 wxFindReplaceDialogBase::Send(event
);
263 // ----------------------------------------------------------------------------
265 // ----------------------------------------------------------------------------
267 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
))
269 SendEvent(wxEVT_COMMAND_FIND_NEXT
);
272 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
))
274 SendEvent(wxEVT_COMMAND_FIND_REPLACE
);
277 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
))
279 SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL
);
282 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
284 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
289 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent
&event
)
291 // we can't search for empty strings
292 event
.Enable( !m_textFind
->GetValue().empty() );
295 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent
&)
297 SendEvent(wxEVT_COMMAND_FIND_CLOSE
);
300 #endif // wxUSE_FINDREPLDLG