Author Topic: how to create multi toolbar  (Read 7590 times)

Offline asugix

  • Single posting newcomer
  • *
  • Posts: 3
how to create multi toolbar
« on: January 14, 2013, 07:13:54 am »
How to create toolbar on top and right side and left side using wxsmith?
If using wxAui, then how to proper access to toolbar item? I want to know whether it is checked or not.

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: how to create multi toolbar
« Reply #1 on: August 18, 2013, 10:50:10 pm »
I need to manage several toolbars (wxToolbar-based) too. Does wxSmith can manage this by a way or another ?
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: how to create multi toolbar
« Reply #2 on: August 19, 2013, 08:47:58 pm »
Well, knowing I really need to manage several toolbars (wxToolbar ones) and would like to stay with wxSmith, I've taken a look at the source (knowing I'm under Windows 7 64-bit with MinGW64, I've worked in another Windows with MinGW32 under VirtualBox) and managed a way. Here it is :

1) In "wxwidgets\defitems\wxstoolbar.cpp", I've commented a part of wxsToolBar::OnCanAddToResource() like this :

Code
bool wxsToolBar::OnCanAddToResource(wxsItemResData* Data,bool ShowMessage)
{
    if ( Data->GetClassType() != _T("wxFrame") )
    {
        if ( ShowMessage )
        {
            cbMessageBox(_("wxToolBar can be added to wxFrame only"));
        }
        return false;
    }

/* ***eranon : disabled to allow several wxToolbar in a frame (dev being responsible to fix the multi SetToolBar() issue by hand
   for ( int i=0; i<Data->GetToolsCount(); i++ )
    {
        if ( Data->GetTool(i)->GetClassName() == _T("wxToolBar") )
        {
            if ( ShowMessage )
            {
                cbMessageBox(_("Can not add two or more wxToolBar classes\ninto one wxFrame"));
            }
            return false;
        }
    }
*/

    return true;
}

Then, wxSmith doesn't limit the toolbar to one only anymore...


2) Of course, knowing wxSmith generates code calling SetToolBar() for every toolbar, I've had to override this method in my own project (the best would be to manage the stuff from within wxSmith, but it require to go deeper than I had) to do every toolbar be added to a specific container (ie. a panel or a sizer) :

Code
void TestFrame::SetToolBar(wxToolBar* toolBar)
{
    // Overrides wxFrame::SetToolbar to customize the association
    // NB : workaround to use wxSmith even if it calls SetToolBar systematically
    if (toolBar->GetName() == "ID_TOOLBAR2"){
        toolBar->Reparent(panelMain);
        sizerForT2->Add(toolBar);}
    else {
        wxFrame::SetToolBar(toolBar);}
}

At this time, it works, but, of course, now I can't open my project in the standard (stable or nightly) Code::Blocks, because it removes my toolbars (except the first one) at first wxSmith launch :(

If a wxSmith maintainer could confirm me it doesn't have wrong side effects and, if not, if he could manage to remove the lock in the official wxSmith (maybe extending with a choice to do SetToolBar or not), it would be nice ;D

--
EDIT : in some circumstances, I've seen a wrong behavior (not about wxSmith, but about app working) : sometime, the standard location of the toolbar remains visible as reserved area (ie. a transparent, unrefreshed rect w/o toolbar anymore). So, suspecting this to come from the base wxFrame::SetToolBar(), I've prevented this doing my overriding as const (so the passed this pointer is now forced to stay of TestFrame type), like this :

Code
void TestFrame::SetToolBar(wxToolBar* toolBar) const
{
    // Overrides wxFrame::SetToolbar to customize the association
    // NB : workaround to use wxSmith even if it calls SetToolBar systematically
    if (toolBar->GetName() == "ID_TOOLBAR2"){
        toolBar->Reparent(panelMain);
        sizerForT2->Add(toolBar);}
    else {
        ((wxFrame*) this)->SetToolBar(toolBar);}
}
« Last Edit: August 20, 2013, 02:24:15 am by eranon »
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]