X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc26010927f5bb12825a32487949d063e6c605fc..538f284a44001ff8285eaafebcc384bf638b5d66:/samples/toolbar/toolbar.cpp?ds=sidebyside diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 2c62dcd5c0..6f8327a911 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -61,7 +61,7 @@ // ---------------------------------------------------------------------------- #if !defined(__WXMSW__) && !defined(__WXPM__) - #include "mondrian.xpm" + #include "../sample.xpm" #endif #if USE_XPM_BITMAPS @@ -134,7 +134,6 @@ public: void OnToolbarStyle(wxCommandEvent& event); void OnToolbarBgCol(wxCommandEvent& event); - void OnToolbarCustomBg(wxCommandEvent& event); void OnToolbarCustomBitmap(wxCommandEvent& event); void OnToolLeftClick(wxCommandEvent& event); @@ -149,8 +148,6 @@ public: { event.Enable( m_tbar != NULL ); } private: - void OnEraseToolBarBackground(wxEraseEvent& event); - void DoEnablePrint(); void DoDeletePrint(); void DoToggleHelp(); @@ -209,7 +206,6 @@ enum IDM_TOOLBAR_SHOW_ICONS, IDM_TOOLBAR_SHOW_BOTH, IDM_TOOLBAR_BG_COL, - IDM_TOOLBAR_CUSTOM_BG, IDM_TOOLBAR_CUSTOM_PATH, IDM_TOOLBAR_TOP_ORIENTATION, IDM_TOOLBAR_LEFT_ORIENTATION, @@ -268,7 +264,6 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH, MyFrame::OnToolbarStyle) EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol) - EVT_MENU(IDM_TOOLBAR_CUSTOM_BG, MyFrame::OnToolbarCustomBg) EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap) @@ -320,8 +315,6 @@ bool MyApp::OnInit() wxInitAllImageHandlers(); - SetTopWindow(frame); - return true; } @@ -376,17 +369,6 @@ void MyFrame::RecreateToolbar() toolBar = CreateToolBar(style, ID_TOOLBAR); #endif - if ( GetMenuBar()->IsChecked(IDM_TOOLBAR_CUSTOM_BG) ) - { - toolBar->Connect - ( - wxEVT_ERASE_BACKGROUND, - wxEraseEventHandler(MyFrame::OnEraseToolBarBackground), - NULL, - this - ); - } - PopulateToolbar(toolBar); } @@ -512,7 +494,7 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) { // create a tool with a custom bitmap for testing wxImage img(m_pathBmp); - if ( img.Ok() ) + if ( img.IsOk() ) { if ( img.GetWidth() > w && img.GetHeight() > h ) img = img.GetSubImage(wxRect(0, 0, w, h)); @@ -559,7 +541,7 @@ MyFrame::MyFrame(wxFrame* parent, #endif // Give it an icon - SetIcon(wxICON(mondrian)); + SetIcon(wxICON(sample)); // Make a menubar wxMenu *tbarMenu = new wxMenu; @@ -612,7 +594,6 @@ MyFrame::MyFrame(wxFrame* parent, tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B")); tbarMenu->AppendSeparator(); tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour...")); - tbarMenu->AppendCheckItem(IDM_TOOLBAR_CUSTOM_BG, wxT("Draw custom back&ground")); tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B")); wxMenu *toolMenu = new wxMenu; @@ -644,6 +625,7 @@ MyFrame::MyFrame(wxFrame* parent, // Associate the menu bar with the frame SetMenuBar(menuBar); + menuBar->Check(IDM_TOOLBAR_TOGGLE_TOOLBAR, true); menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, true); menuBar->Check(IDM_TOOLBAR_TOGGLETOOLTIPS, true); @@ -658,7 +640,7 @@ MyFrame::MyFrame(wxFrame* parent, m_extraToolBar = new wxToolBar(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_TEXT|wxTB_FLAT|wxTB_TOP); PopulateToolbar(m_extraToolBar); #endif - + m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); @@ -712,15 +694,6 @@ void MyFrame::OnSize(wxSizeEvent& event) } } -void MyFrame::OnEraseToolBarBackground(wxEraseEvent& event) -{ - wxDC& dc = *event.GetDC(); - const wxSize size = dc.GetSize(); - dc.SetPen(*wxRED_PEN); - dc.DrawLine(0, 0, size.x, size.y); - dc.DrawLine(0, size.y, size.x, 0); -} - void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) { wxToolBar *tbar = GetToolBar(); @@ -731,9 +704,11 @@ void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) } else { + // notice that there is no need to call SetToolBar(NULL) here (although + // this it is harmless to do and it must be called if you do not delete + // the toolbar but keep it for later reuse), just delete the toolbar + // directly and it will reset the associated frame toolbar pointer delete tbar; - - SetToolBar(NULL); } } @@ -748,8 +723,7 @@ void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) { if ( m_tbar ) { - delete m_tbar; - m_tbar = NULL; + wxDELETE(m_tbar); } else { @@ -985,34 +959,6 @@ void MyFrame::OnToolbarBgCol(wxCommandEvent& WXUNUSED(event)) } } -void MyFrame::OnToolbarCustomBg(wxCommandEvent& event) -{ - wxToolBarBase *tb = GetToolBar(); - - if ( event.IsChecked() ) - { - tb->Connect - ( - wxEVT_ERASE_BACKGROUND, - wxEraseEventHandler(MyFrame::OnEraseToolBarBackground), - NULL, - this - ); - } - else - { - tb->Disconnect - ( - wxEVT_ERASE_BACKGROUND, - wxEraseEventHandler(MyFrame::OnEraseToolBarBackground), - NULL, - this - ); - } - - tb->Refresh(); -} - void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event)) { m_pathBmp = wxLoadFileSelector("custom bitmap", "");