X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6adaedf0fc6607ee5bb4e86358396e5e07c6649f..57160afe2bdc4df4aa08c8eed85e9b4d1c2bad24:/samples/controls/controls.cpp?ds=sidebyside diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 395c4ebc9a..7dab094d53 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -61,11 +61,6 @@ #include "wx/progdlg.h" -// VZ: this is a temp. hack, will remove soon -#ifndef wxUSE_SPINCTRL -#define wxUSE_SPINCTRL 1 -#endif - #if wxUSE_SPINCTRL #include "wx/spinctrl.h" #endif // wxUSE_SPINCTRL @@ -110,7 +105,7 @@ public: #endif // wxUSE_SPINBTN #if wxUSE_SPINCTRL - void OnSpinCtrl(wxSpinEvent& event); + void OnSpinCtrl(wxCommandEvent& event); #endif // wxUSE_SPINCTRL void OnEnableAll(wxCommandEvent& event); @@ -167,6 +162,8 @@ public: void OnSize( wxSizeEvent& event ); void OnMove( wxMoveEvent& event ); + MyPanel *GetPanel() const { return m_panel; } + private: void UpdateStatusBar(const wxPoint& pos, const wxSize& size) { @@ -176,7 +173,7 @@ private: SetStatusText(msg, 1); } - wxPanel *m_panel; + MyPanel *m_panel; DECLARE_EVENT_TABLE() }; @@ -210,10 +207,21 @@ enum bool MyApp::OnInit() { + // parse the cmd line + int x = 50, + y = 50; + if ( argc == 2 ) + { + wxSscanf(argv[1], "%d", &x); + wxSscanf(argv[2], "%d", &y); + } + // Create the main frame window MyFrame *frame = new MyFrame((wxFrame *) NULL, "Controls wxWindows App", - 50, 50, 530, 420); + x, y, 540, 430); + + frame->SetSizeHints( 500, 425 ); // Give it an icon // The wxICON() macros loads an icon from a resource under Windows @@ -250,6 +258,8 @@ bool MyApp::OnInit() frame->Show(TRUE); frame->SetCursor(wxCursor(wxCURSOR_HAND)); + //frame->GetPanel()->m_notebook->SetSelection(3); + SetTopWindow(frame); return TRUE; @@ -357,7 +367,7 @@ EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress) EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress) #endif // wxUSE_SPINBTN #if wxUSE_SPINCTRL -EVT_SPIN (ID_SPINCTRL, MyPanel::OnSpinCtrl) +EVT_SPINCTRL (ID_SPINCTRL, MyPanel::OnSpinCtrl) #endif // wxUSE_SPINCTRL EVT_BUTTON (ID_BUTTON_LABEL, MyPanel::OnUpdateLabel) EVT_CHECKBOX (ID_CHANGE_COLOUR, MyPanel::OnChangeColour) @@ -370,7 +380,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_text = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE ); // m_text->SetBackgroundColour("wheat"); - delete wxLog::SetActiveTarget(new wxLogStderr); + //delete wxLog::SetActiveTarget(new wxLogStderr); m_notebook = new wxNotebook( this, ID_NOTEBOOK, wxPoint(0,0), wxSize(200,150) ); @@ -459,6 +469,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); wxButton *button = new wxButton( panel, ID_LISTBOX_FONT, "Set &Italic font", wxPoint(340,130), wxSize(140,30) ); + + button->SetDefault(); + + button->SetForegroundColour(*wxBLUE); + #if wxUSE_TOOLTIPS button->SetToolTip( "Press here to set italic font" ); #endif // wxUSE_TOOLTIPS @@ -495,7 +510,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice); panel = new wxPanel(m_notebook); - m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY ); + (void)new wxStaticBox( panel, -1, "Box around combobox", + wxPoint(5, 5), wxSize(150, 100)); + m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(20,20), wxSize(120,-1), 5, choices, wxCB_READONLY ); (void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); (void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); @@ -516,6 +533,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) panel = new wxPanel(m_notebook); (void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS ); m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS ); + +#if wxUSE_TOOLTIPS + m_radio->SetToolTip("Ever seen a radiobox?"); +#endif // wxUSE_TOOLTIPS + (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) ); @@ -575,7 +597,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #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)); + 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)); @@ -585,11 +608,32 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) wxMemoryDC dc; dc.SelectObject( bitmap ); dc.SetPen(*wxGREEN_PEN); + dc.Clear(); dc.DrawEllipse(5, 5, 90, 90); - dc.DrawText("Bitmap", 20, 20); + dc.DrawText("Bitmap", 30, 40); dc.SelectObject( wxNullBitmap ); (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20)); + +#if 0 + bitmap = wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp", + wxBITMAP_TYPE_BMP); + bitmap.SetMask(new wxMask(bitmap, *wxBLUE)); + (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(300, 120)); +#endif + + wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)), + bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)), + bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION)); + wxBitmapButton *bmpBtn = new wxBitmapButton + ( + panel, -1, + bmp1, + wxPoint(30, 50) + ); + bmpBtn->SetBitmapSelected(bmp2); + bmpBtn->SetBitmapFocus(bmp3); + (void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20)); m_label = new wxStaticText(panel, -1, "Label with some long text", wxPoint(250, 60), wxDefaultSize, @@ -689,6 +733,7 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event)) SetBackgroundColour(s_colOld); s_colOld = wxNullColour; + m_lbSelectThis->SetForegroundColour("yellow"); m_lbSelectThis->SetBackgroundColour("blue"); } else @@ -696,6 +741,7 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event)) s_colOld = GetBackgroundColour(); SetBackgroundColour("green"); + m_lbSelectThis->SetForegroundColour("white"); m_lbSelectThis->SetBackgroundColour("red"); } @@ -705,6 +751,8 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event)) void MyPanel::OnListBox( wxCommandEvent &event ) { +// GetParent()->Move(100, 100); + wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox : m_listboxSorted; @@ -754,6 +802,8 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event ) cb->SetToolTip( "Click to disable listbox" ); #endif // wxUSE_TOOLTIPS m_listbox->Enable( event.GetInt() == 0 ); + m_lbSelectThis->Enable( event.GetInt() == 0 ); + m_lbSelectNum->Enable( event.GetInt() == 0 ); m_listboxSorted->Enable( event.GetInt() == 0 ); break; } @@ -992,10 +1042,11 @@ void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) #if wxUSE_SPINCTRL -void MyPanel::OnSpinCtrl(wxSpinEvent& event) +void MyPanel::OnSpinCtrl(wxCommandEvent& event) { wxString s; - s.Printf(_T("Current value of spin ctrl is %d\n"), m_spinctrl->GetValue()); + s.Printf(_T("Spin ctrl changed: now %d (from event: %d)\n"), + m_spinctrl->GetValue(), event.GetInt()); m_text->AppendText(s); }