void ToolBar::ReCreateButtons() { // SetSizer(NULL) detaches mHSizer and deletes it. // Do not use Detach() here, as that attempts to detach mHSizer from itself! SetSizer( NULL ); // Get rid of any children we may have DestroyChildren(); // Create the main sizer wxBoxSizer *ms = new wxBoxSizer( wxHORIZONTAL ); // Create the grabber and add it to the main sizer mGrabber = new Grabber( this, mType ); ms->Add( mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1 ); // Use a box sizer for laying out controls mHSizer = new wxBoxSizer( wxHORIZONTAL ); ms->Add( mHSizer, 1, wxEXPAND ); // (Re)Establish dock state SetDocked( GetDock(), false ); // Go add all the rest of the gadgets Populate(); // Add some space for the resize border if( IsResizable() ) { mSpacer = ms->Add( RWIDTH, 1 ); } // Set the sizer SetSizerAndFit( ms ); // Recalculate the height to be a multiple of toolbarSingle const int tbs = toolbarSingle + toolbarGap; wxSize sz = GetSize(); sz.y = ( ( ( sz.y + tbs ) / tbs ) * tbs ) - 1; // Set the true AND minimum sizes and do final layout if(IsResizable()) { sz.SetWidth(GetMinToolbarWidth()); SetMinSize(sz); sz.SetWidth(GetInitialWidth()); SetSize(sz); } else { SetInitialSize(sz); } Layout(); }
void ToolBar::ReCreateButtons() { // SetSizer(NULL) detaches mHSizer and deletes it. // Do not use Detach() here, as that attempts to detach mHSizer from itself! SetSizer( NULL ); // Get rid of any children we may have DestroyChildren(); mGrabber = NULL; mResizer = NULL; { // Create the main sizer auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL); // Create the grabber and add it to the main sizer mGrabber = safenew Grabber(this, mType); ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1); // Use a box sizer for laying out controls ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND); // (Re)Establish dock state SetDocked(GetDock(), false); // Go add all the rest of the gadgets Populate(); // Add some space for the resize border if (IsResizable()) { // Create the resizer and add it to the main sizer mResizer = safenew ToolBarResizer(this); ms->Add(mResizer, 0, wxEXPAND | wxALIGN_TOP | wxLEFT, 1); mResizer->SetToolTip(_("Click and drag to resize toolbar")); } // Set the sizer SetSizerAndFit(ms.release()); } // Recalculate the height to be a multiple of toolbarSingle const int tbs = toolbarSingle + toolbarGap; wxSize sz = GetSize(); sz.y = ( ( ( sz.y + tbs -1) / tbs ) * tbs ) - 1; // Set the true AND minimum sizes and do final layout if(IsResizable()) { sz.SetWidth(GetMinToolbarWidth()); // JKC we're going to allow all resizable toolbars to be resized // to 1 unit high! wxSize sz2 = sz; sz2.y = tbs -1; SetMinSize(sz2); sz.SetWidth(GetInitialWidth()); SetSize(sz); } else { SetInitialSize(sz); } Layout(); }