X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/408859237485ea905d349a5e430837151c472b99..74b31181b345aaaef0c967cc5707bef72ce0a405:/samples/controls/controls.cpp diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 6f06969923..55d24885bb 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -23,7 +23,9 @@ #include "wx/wx.h" #endif +#if !defined( __WXMSW__ ) || defined( __WIN95__ ) #include "wx/spinbutt.h" +#endif #include "wx/notebook.h" #include "wx/imaglist.h" @@ -84,6 +86,8 @@ public: void OnPageChanging( wxNotebookEvent &event ); void OnSliderUpdate( wxCommandEvent &event ); #ifndef wxUSE_SPINBUTTON + void OnSpinUp( wxSpinEvent &event ); + void OnSpinDown( wxSpinEvent &event ); void OnSpinUpdate( wxSpinEvent &event ); void OnUpdateShowProgress( wxUpdateUIEvent& event ); void OnShowProgress( wxCommandEvent &event ); @@ -164,7 +168,7 @@ bool MyApp::OnInit() frame->SetIcon( wxICON(mondrian) ); - wxMenu *file_menu = new wxMenu; + wxMenu *file_menu = new wxMenu("", wxMENU_TEAROFF ); file_menu->Append(MINIMAL_ABOUT, "&About\tF1"); file_menu->Append(MINIMAL_QUIT, "E&xit\tAlt-X", "Quit controls sample"); @@ -279,6 +283,8 @@ EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) #ifndef wxUSE_SPINBUTTON EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) +EVT_SPIN_UP (ID_SPIN, MyPanel::OnSpinUp) +EVT_SPIN_DOWN (ID_SPIN, MyPanel::OnSpinDown) EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress) EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress) #endif @@ -380,7 +386,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) button->SetToolTip( "Press here to set italic font" ); #endif // wxUSE_TOOLTIPS - m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,130), wxSize(-1, -1), wxALIGN_RIGHT ); + m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "&Disable", wxPoint(20,130) ); m_checkbox->SetValue(FALSE); #if wxUSE_TOOLTIPS m_checkbox->SetToolTip( "Click here to disable the listbox" ); @@ -397,6 +403,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) (void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); (void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); (void)new wxCheckBox( panel, ID_CHOICE_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); + m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); panel = new wxPanel(m_notebook); @@ -426,22 +433,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(340,80), wxSize(140,30) ); (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); - wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30) ); + wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, "Radiobutton1", wxPoint(210,170), wxSize(110,30), wxRB_GROUP ); rb->SetValue( FALSE ); (void)new wxRadioButton( panel, ID_RADIOBUTTON_2, "Radiobutton2", wxPoint(340,170), wxSize(110,30) ); m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); panel = new wxPanel(m_notebook); - (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(180,130) ); + (void)new wxStaticBox( panel, -1, "wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) ); m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30) ); m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS ); - (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(200,10), wxSize(290,130) ); + (void)new wxStaticBox( panel, -1, "Explanation", wxPoint(220,10), wxSize(270,130) ); #ifdef __WXMOTIF__ // No wrapping text in wxStaticText yet :-( (void)new wxStaticText( panel, -1, "Drag the slider!", - wxPoint(208,30), - wxSize(210, -1) + wxPoint(228,30), + wxSize(240, -1) ); #else (void)new wxStaticText( panel, -1, @@ -451,20 +458,54 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) "\n" "This is also supposed to demonstrate how\n" "to use static controls.\n", - wxPoint(208,25), - wxSize(250, 110) + wxPoint(228,25), + wxSize(240, 110) ); #endif - m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); + int initialSpinValue = -5; + wxString s; + s << initialSpinValue; + m_spintext = new wxTextCtrl( panel, -1, s, wxPoint(20,160), wxSize(80,-1) ); #ifndef wxUSE_SPINBUTTON m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); m_spinbutton->SetRange(-10,30); - m_spinbutton->SetValue(-5); + m_spinbutton->SetValue(initialSpinValue); m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog", wxPoint(208, 159) ); #endif m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); + + panel = new wxPanel(m_notebook); + +#ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB + wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); + wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon, wxPoint(10, 10)); + + bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10)); + bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION)); +#endif + + wxBitmap bitmap( 100, 100 ); + wxMemoryDC dc; + dc.SelectObject( bitmap ); + dc.SetPen(*wxGREEN_PEN); + dc.DrawEllipse(5, 5, 90, 90); + dc.DrawText("Bitmap", 20, 20); + dc.SelectObject( wxNullBitmap ); + + wxBitmapButton *bmpBtn = new wxBitmapButton + ( + panel, + -1, + bitmap, + wxPoint(100, 20) + ); + bmpBtn = NULL; // suppress warning + + new wxButton(panel, -1, "Another button", wxPoint(250, 20)); + + m_notebook->AddPage(panel, "wxBitmapXXX"); } void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) @@ -479,22 +520,22 @@ void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) void MyPanel::OnPageChanging( wxNotebookEvent &event ) { - int selNew = event.GetSelection(), - selOld = event.GetOldSelection(); - if ( selOld == 2 && selNew == 4 ) + int selOld = event.GetOldSelection(); + if ( selOld == 2 ) { - wxMessageBox("This demonstrates how a program may prevent the " - "page change from taking place - the current page will " - "stay the third one", "Conntrol sample", - wxICON_INFORMATION | wxOK); + if ( wxMessageBox("This demonstrates how a program may prevent the\n" + "page change from taking place - if you select\n" + "[No] the current page will stay the third one\n", + "Control sample", + wxICON_QUESTION | wxYES_NO) != wxYES ) + { + event.Veto(); - event.Veto(); - } - else - { - *m_text << "Notebook selection is being changed from " - << selOld << " to " << selNew << "\n"; + return; + } } + + *m_text << "Notebook selection is being changed from " << selOld << "\n"; } void MyPanel::OnPageChanged( wxNotebookEvent &event ) @@ -539,13 +580,13 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event ) case ID_LISTBOX_SEL_NUM: { m_listbox->SetSelection( 2 ); - m_lbSelectThis->WarpPointer( 40, 14 ); + m_lbSelectThis->WarpPointer( 40, 14 ); break; } case ID_LISTBOX_SEL_STR: { m_listbox->SetStringSelection( "This" ); - m_lbSelectNum->WarpPointer( 40, 14 ); + m_lbSelectNum->WarpPointer( 40, 14 ); break; } case ID_LISTBOX_CLEAR: @@ -725,6 +766,38 @@ void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) } #ifndef wxUSE_SPINBUTTON +void MyPanel::OnSpinUp( wxSpinEvent &event ) +{ + wxString value; + value.Printf( _T("Spin control up: current = %d\n"), + m_spinbutton->GetValue()); + + if ( m_spinbutton->GetValue() > 17 ) + { + value += _T("Preventing the spin button from going above 17.\n"); + + event.Veto(); + } + + m_text->AppendText(value); +} + +void MyPanel::OnSpinDown( wxSpinEvent &event ) +{ + wxString value; + value.Printf( _T("Spin control down: current = %d\n"), + m_spinbutton->GetValue()); + + if ( m_spinbutton->GetValue() < -17 ) + { + value += _T("Preventing the spin button from going below -17.\n"); + + event.Veto(); + } + + m_text->AppendText(value); +} + void MyPanel::OnSpinUpdate( wxSpinEvent &event ) { wxString value; @@ -750,8 +823,12 @@ void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) ) "An informative message", max, // range this, // parent - wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME); - + wxPD_CAN_ABORT | + wxPD_APP_MODAL | + wxPD_ELAPSED_TIME | + wxPD_ESTIMATED_TIME | + wxPD_REMAINING_TIME); + bool cont = TRUE; for ( int i = 0; i < max && cont; i++ ) @@ -769,7 +846,6 @@ void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) ) { cont = dialog.Update(i); } - wxYield(); } if ( !cont )