X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fe1bc2853c883255b239d42b3845188d66b3ac87..0d8c57c00668287faa84cb9ddb4a631ae7100954:/samples/controls/controls.cpp diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 56a209450e..57daa3fd06 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -19,9 +19,7 @@ #include "wx/wx.h" #endif -#if !defined( __WXMSW__ ) || defined( __WIN95__ ) #include "wx/spinbutt.h" -#endif #include "wx/tglbtn.h" #include "wx/bookctrl.h" #include "wx/imaglist.h" @@ -77,6 +75,7 @@ public: virtual ~MyPanel(); void OnSize( wxSizeEvent& event ); + void OnIdle( wxIdleEvent &event ); void OnListBox( wxCommandEvent &event ); void OnListBoxDoubleClick( wxCommandEvent &event ); void OnListBoxButtons( wxCommandEvent &event ); @@ -314,6 +313,42 @@ private: DECLARE_EVENT_TABLE() }; +// a choice which handles focus set/kill (for testing) +class MyChoice : public wxChoice +{ +public: + MyChoice(wxWindow *parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxChoiceNameStr ) + : wxChoice(parent, id, pos, size, n, choices, + style, validator, name) { } + +protected: + void OnFocusGot(wxFocusEvent& event) + { + wxLogMessage(_T("MyChoice::OnFocusGot")); + + event.Skip(); + } + + void OnFocusLost(wxFocusEvent& event) + { + wxLogMessage(_T("MyChoice::OnFocusLost")); + + event.Skip(); + } + +private: + DECLARE_EVENT_TABLE() +}; + + + //---------------------------------------------------------------------- // other //---------------------------------------------------------------------- @@ -332,9 +367,9 @@ IMPLEMENT_APP(MyApp) enum { - CONTROLS_QUIT = 100, - CONTROLS_TEXT, - CONTROLS_ABOUT, + CONTROLS_QUIT = wxID_EXIT, + CONTROLS_ABOUT = wxID_ABOUT, + CONTROLS_TEXT = 100, CONTROLS_CLEAR_LOG, // tooltip menu @@ -445,6 +480,7 @@ const int ID_SIZER_CHECKBIG = 206; BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_SIZE ( MyPanel::OnSize) +EVT_IDLE ( MyPanel::OnIdle) EVT_BOOKCTRL_PAGE_CHANGING(ID_BOOK, MyPanel::OnPageChanging) EVT_BOOKCTRL_PAGE_CHANGED(ID_BOOK, MyPanel::OnPageChanged) EVT_LISTBOX (ID_LISTBOX, MyPanel::OnListBox) @@ -538,6 +574,11 @@ BEGIN_EVENT_TABLE(MyRadioBox, wxRadioBox) EVT_KILL_FOCUS(MyRadioBox::OnFocusLost) END_EVENT_TABLE() +BEGIN_EVENT_TABLE(MyChoice, wxChoice) + EVT_SET_FOCUS(MyChoice::OnFocusGot) + EVT_KILL_FOCUS(MyChoice::OnFocusLost) +END_EVENT_TABLE() + // ============================================================================ // implementation // ============================================================================ @@ -721,8 +762,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #if wxUSE_CHOICE panel = new wxPanel(m_book); - m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices ); - m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,wxDefaultCoord), + m_choice = new MyChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices ); + m_choiceSorted = new MyChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,wxDefaultCoord), 5, choices, wxCB_SORT ); SetChoiceClientData(wxT("choice"), m_choice); @@ -790,10 +831,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #if wxUSE_SLIDER && wxUSE_GAUGE panel = new wxPanel(m_book); - + wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL ); panel->SetSizer( main_sizer ); - + wxStaticBoxSizer *gauge_sizer = new wxStaticBoxSizer( wxHORIZONTAL, panel, _T("&wxGauge and wxSlider") ); main_sizer->Add( gauge_sizer, 0, wxALL, 5 ); wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL ); @@ -810,7 +851,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_slider->SetToolTip(_T("This is a sliding slider")); #endif // wxUSE_TOOLTIPS sz->Add( m_slider, 0, wxALL, 10 ); - + m_gaugeVert = new wxGauge( panel, wxID_ANY, 100, wxDefaultPosition, wxSize(wxDefaultCoord, 90), wxGA_VERTICAL | wxGA_SMOOTH | wxNO_BORDER ); @@ -839,7 +880,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) _T("This is also supposed to demonstrate how ") _T("to use static controls with line wrapping."), wxDefaultPosition, - wxSize(240, -1) + wxSize(240, wxDefaultCoord) ); #endif wrapping_sizer->Add( m_wrappingText ); @@ -872,7 +913,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #endif // wxUSE_SPINBTN #if wxUSE_SPINCTRL - m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, _T(""), wxPoint(200, 160), wxSize(80, wxDefaultCoord) ); + m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, wxEmptyString, wxPoint(200, 160), wxSize(80, wxDefaultCoord) ); m_spinctrl->SetRange(10,30); m_spinctrl->SetValue(15); #endif // wxUSE_SPINCTRL @@ -1008,6 +1049,39 @@ void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) if (m_text) m_text->SetSize( 2, y*2/3+2, x-4, y/3-4 ); } +void MyPanel::OnIdle(wxIdleEvent& event) +{ + static const int INVALID_SELECTION = -2; + + static int s_selCombo = INVALID_SELECTION; + int sel = m_combo->GetSelection(); + if ( sel != s_selCombo ) + { + if ( s_selCombo != INVALID_SELECTION ) + { + wxLogMessage(_T("EVT_IDLE: combobox selection changed from %d to %d"), + s_selCombo, sel); + } + + s_selCombo = sel; + } + + static int s_selChoice = INVALID_SELECTION; + sel = m_choice->GetSelection(); + if ( sel != s_selChoice ) + { + if ( s_selChoice != INVALID_SELECTION ) + { + wxLogMessage(_T("EVT_IDLE: choice selection changed from %d to %d"), + s_selChoice, sel); + } + + s_selChoice = sel; + } + + event.Skip(); +} + void MyPanel::OnPageChanging( wxBookCtrlEvent &event ) { int selOld = event.GetOldSelection(); @@ -1285,20 +1359,18 @@ void MyPanel::OnChoiceButtons( wxCommandEvent &event ) void MyPanel::OnCombo( wxCommandEvent &event ) { - m_text->AppendText( _T("ComboBox event selection string is: ") ); - m_text->AppendText( event.GetString() ); - m_text->AppendText( _T("\n") ); - m_text->AppendText( _T("ComboBox control selection string is: ") ); - m_text->AppendText( m_combo->GetStringSelection() ); - m_text->AppendText( _T("\n") ); + wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string \"%s\"/\"%s\""), + (int)event.GetInt(), + m_combo->GetSelection(), + event.GetString().c_str(), + m_combo->GetStringSelection().c_str()); } void MyPanel::OnComboTextChanged(wxCommandEvent& event) { - wxString str; - str.Printf( wxT("Text in the combobox changed: now is '%s'."), - event.GetString().c_str() ); - wxLogMessage( str.c_str() ); + wxLogMessage(wxT("EVT_TEXT for the combobox: \"%s\" (event) or \"%s\" (control)."), + event.GetString().c_str(), + m_combo->GetValue().c_str()); } void MyPanel::OnComboTextEnter(wxCommandEvent& WXUNUSED(event))