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
 
  93 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) 
 103     wxCHECK_MSG( m_FindReplaceData
, false, 
 104                  _T("can't create dialog without data") ); 
 106     bool isPda 
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
); 
 108     wxBoxSizer 
*leftsizer 
= new wxBoxSizer( wxVERTICAL 
); 
 110     // 3 columns because there is a spacer in the middle 
 111     wxFlexGridSizer 
*sizer2Col 
= new wxFlexGridSizer(3); 
 112     sizer2Col
->AddGrowableCol(2); 
 114     sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Search for:"), 
 115                                     wxDefaultPosition
, wxSize(80, wxDefaultCoord
)), 
 117                                     wxALIGN_CENTRE_VERTICAL 
| wxALIGN_RIGHT
); 
 119     sizer2Col
->Add(10, 0); 
 121     m_textFind 
= new wxTextCtrl(this, wxID_ANY
, m_FindReplaceData
->GetFindString()); 
 122     sizer2Col
->Add(m_textFind
, 1, wxALIGN_CENTRE_VERTICAL 
| wxEXPAND
); 
 124     if ( style 
& wxFR_REPLACEDIALOG 
) 
 126         sizer2Col
->Add(new wxStaticText(this, wxID_ANY
, _("Replace with:"), 
 127                                         wxDefaultPosition
, wxSize(80, wxDefaultCoord
)), 
 129                                         wxALIGN_CENTRE_VERTICAL 
| 
 130                                         wxALIGN_RIGHT 
| wxTOP
, 5); 
 132         sizer2Col
->Add(isPda 
? 2 : 10, 0); 
 134         m_textRepl 
= new wxTextCtrl(this, wxID_ANY
, 
 135                                     m_FindReplaceData
->GetReplaceString()); 
 136         sizer2Col
->Add(m_textRepl
, 1, 
 137                        wxALIGN_CENTRE_VERTICAL 
| wxEXPAND 
| wxTOP
, 5); 
 140     leftsizer
->Add(sizer2Col
, 0, wxEXPAND 
| wxALL
, 5); 
 142     wxBoxSizer 
*optsizer 
= new wxBoxSizer( isPda 
? wxVERTICAL 
: wxHORIZONTAL 
); 
 144     wxBoxSizer 
*chksizer 
= new wxBoxSizer( wxVERTICAL
); 
 146     m_chkWord 
= new wxCheckBox(this, wxID_ANY
, _("Whole word")); 
 147     chksizer
->Add(m_chkWord
, 0, wxALL
, 3); 
 149     m_chkCase 
= new wxCheckBox(this, wxID_ANY
, _("Match case")); 
 150     chksizer
->Add(m_chkCase
, 0, wxALL
, 3); 
 152     optsizer
->Add(chksizer
, 0, wxALL
, 10); 
 154     static const wxString searchDirections
[] = {_("Up"), _("Down")}; 
 155     int majorDimension 
= 0; 
 158         rbStyle 
= wxRA_SPECIFY_ROWS
; 
 160         rbStyle 
= wxRA_SPECIFY_COLS
; 
 162     m_radioDir 
= new wxRadioBox(this, wxID_ANY
, _("Search direction"), 
 163                                 wxDefaultPosition
, wxDefaultSize
, 
 164                                 WXSIZEOF(searchDirections
), searchDirections
, 
 165                                 majorDimension
, rbStyle
); 
 167     optsizer
->Add(m_radioDir
, 0, wxALL
, isPda 
? 5 : 10); 
 169     leftsizer
->Add(optsizer
); 
 171     wxBoxSizer 
*bttnsizer 
= new wxBoxSizer(wxVERTICAL
); 
 173     wxButton
* btn 
= new wxButton(this, wxID_FIND
); 
 175     bttnsizer
->Add(btn
, 0, wxALL
, 3); 
 177     bttnsizer
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 3); 
 179     if ( style 
& wxFR_REPLACEDIALOG 
) 
 181         bttnsizer
->Add(new wxButton(this, wxID_REPLACE
, _("&Replace")), 
 184         bttnsizer
->Add(new wxButton(this, wxID_REPLACE_ALL
, _("Replace &all")), 
 188     wxBoxSizer 
*topsizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 190     topsizer
->Add(leftsizer
, 1, wxALL
, isPda 
? 0 : 5); 
 191     topsizer
->Add(bttnsizer
, 0, wxALL
, isPda 
? 0 : 5); 
 193     int flags 
= m_FindReplaceData
->GetFlags(); 
 195     if ( flags 
& wxFR_MATCHCASE 
) 
 196         m_chkCase
->SetValue(true); 
 198     if ( flags 
& wxFR_WHOLEWORD 
) 
 199         m_chkWord
->SetValue(true); 
 201     m_radioDir
->SetSelection( flags 
& wxFR_DOWN 
); 
 203     if ( style 
& wxFR_NOMATCHCASE 
) 
 204         m_chkCase
->Enable(false); 
 206     if ( style 
& wxFR_NOWHOLEWORD 
) 
 207         m_chkWord
->Enable(false); 
 209     if ( style 
& wxFR_NOUPDOWN
) 
 210         m_radioDir
->Enable(false); 
 212     SetAutoLayout( true ); 
 213     SetSizer( topsizer 
); 
 215 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) 
 216     topsizer
->SetSizeHints( this ); 
 217     topsizer
->Fit( this ); 
 222     m_textFind
->SetFocus(); 
 227 // ---------------------------------------------------------------------------- 
 228 // send the notification event 
 229 // ---------------------------------------------------------------------------- 
 231 void wxGenericFindReplaceDialog::SendEvent(const wxEventType
& evtType
) 
 233     wxFindDialogEvent 
event(evtType
, GetId()); 
 234     event
.SetEventObject(this); 
 235     event
.SetFindString(m_textFind
->GetValue()); 
 236     if ( HasFlag(wxFR_REPLACEDIALOG
) ) 
 238         event
.SetReplaceString(m_textRepl
->GetValue()); 
 243     if ( m_chkCase
->GetValue() ) 
 244         flags 
|= wxFR_MATCHCASE
; 
 246     if ( m_chkWord
->GetValue() ) 
 247         flags 
|= wxFR_WHOLEWORD
; 
 249     if ( !m_radioDir 
|| m_radioDir
->GetSelection() == 1 ) 
 254     event
.SetFlags(flags
); 
 256     wxFindReplaceDialogBase::Send(event
); 
 259 // ---------------------------------------------------------------------------- 
 261 // ---------------------------------------------------------------------------- 
 263 void wxGenericFindReplaceDialog::OnFind(wxCommandEvent
& WXUNUSED(event
)) 
 265     SendEvent(wxEVT_COMMAND_FIND_NEXT
); 
 268 void wxGenericFindReplaceDialog::OnReplace(wxCommandEvent
& WXUNUSED(event
)) 
 270     SendEvent(wxEVT_COMMAND_FIND_REPLACE
); 
 273 void wxGenericFindReplaceDialog::OnReplaceAll(wxCommandEvent
& WXUNUSED(event
)) 
 275     SendEvent(wxEVT_COMMAND_FIND_REPLACE_ALL
); 
 278 void wxGenericFindReplaceDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
)) 
 280     SendEvent(wxEVT_COMMAND_FIND_CLOSE
); 
 285 void wxGenericFindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent 
&event
) 
 287     // we can't search for empty strings 
 288     event
.Enable( !m_textFind
->GetValue().empty() ); 
 291 void wxGenericFindReplaceDialog::OnCloseWindow(wxCloseEvent 
&) 
 293     SendEvent(wxEVT_COMMAND_FIND_CLOSE
); 
 296 #endif // wxUSE_FINDREPLDLG