X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..538f284a44001ff8285eaafebcc384bf638b5d66:/samples/toolbar/toolbar.cpp diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 7629206d39..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 @@ -305,7 +305,7 @@ bool MyApp::OnInit() // Create the main frame window MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY, wxT("wxToolBar Sample"), - wxPoint(100, 100), wxSize(550, 300)); + wxPoint(100, 100), wxSize(650, 300)); frame->Show(true); @@ -315,8 +315,6 @@ bool MyApp::OnInit() wxInitAllImageHandlers(); - SetTopWindow(frame); - return true; } @@ -458,9 +456,12 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) #endif // USE_CONTROLS_IN_TOOLBAR toolBar->AddTool(wxID_SAVE, wxT("Save"), toolBarBitmaps[Tool_save], wxT("Toggle button 1"), wxITEM_CHECK); + + toolBar->AddSeparator(); toolBar->AddTool(wxID_COPY, wxT("Copy"), toolBarBitmaps[Tool_copy], wxT("Toggle button 2"), wxITEM_CHECK); toolBar->AddTool(wxID_CUT, wxT("Cut"), toolBarBitmaps[Tool_cut], wxT("Toggle/Untoggle help button")); toolBar->AddTool(wxID_PASTE, wxT("Paste"), toolBarBitmaps[Tool_paste], wxT("Paste")); + toolBar->AddSeparator(); if ( m_useCustomDisabled ) { @@ -484,14 +485,16 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) wxT("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with.")); } - toolBar->AddSeparator(); + // add a stretchable space before the "Help" button to make it + // right-aligned + toolBar->AddStretchableSpace(); toolBar->AddTool(wxID_HELP, wxT("Help"), toolBarBitmaps[Tool_help], wxT("Help button"), wxITEM_CHECK); if ( !m_pathBmp.empty() ) { // 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)); @@ -538,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; @@ -622,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); @@ -636,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); @@ -700,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); } } @@ -717,8 +723,7 @@ void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) { if ( m_tbar ) { - delete m_tbar; - m_tbar = NULL; + wxDELETE(m_tbar); } else { @@ -873,14 +878,12 @@ void MyFrame::DoToggleHelp() void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event)) { - static const int searchPos = 3; - wxToolBarBase * const tb = GetToolBar(); if ( !m_searchTool ) { wxSearchCtrl * const srch = new wxSearchCtrl(tb, wxID_ANY, "needle"); srch->SetMinSize(wxSize(80, -1)); - m_searchTool = tb->InsertControl(searchPos, srch); + m_searchTool = tb->AddControl(srch); } else // tool already exists { @@ -893,7 +896,7 @@ void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event)) } else // tool exists in detached state, attach it back { - tb->InsertTool(searchPos, m_searchTool); + tb->AddTool(m_searchTool); win->Show(); } }