wxAuiToolBar updated not properly

311 Views Asked by At

have a wxAuiToolBar to which items are added and removed during runtime. Unfornunately, when adding or removing an item, the toolbar isn't updated (painted) correctly

Creating toolbar:

_toolbar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                                     wxAUI_TB_DEFAULT_STYLE |
                                     wxAUI_TB_OVERFLOW |
                                     wxAUI_TB_TEXT | 
                                     wxAUI_TB_HORZ_TEXT);
_mgr.AddPane(_mdi_frames_toolbar, wxAuiPaneInfo().      
                    Name("tbxxx").Caption("xxx caption").ToolbarPane().Top().Gripper(true).Dockable(true).Floatable(true).CaptionVisible(false));
...
_mgr.Update();

What i do when adding an item:

            wxAuiToolBarItem* pItem=_toolbar->AddTool(wxID_TCMDI_FRAME_TOOL_TB + pchild->uid(),pchild->GetName(),wxNullBitmap,"",wxITEM_NORMAL);                                    
            _toolbar->Realize();

This makes the new tool visible but the upper and lower frame of the toolbar is finshed before the new tool. Repeating this, it generates sooner or later garbage. It seems that the toolbar itself is not updated properly.

If i add

_mgr.Update();

after AddTool, the Tool is not visible until i move the toolbar by gripper.

Can anyone tell me what to do in order to get the aui toolbar updated correctly when a tool has been added (after initial add tools, which works well) ?

Hint: The hosting frame on size event is skipped.

I use wxWidgets 3.01 in Windows 7, debug 64 static build. Same happens in release build.

Thank you

1

There are 1 best solutions below

1
On

The code in the question is not adding _toolbar to the AUI manager, but I assume that's just a copy-paste issue when creating the question.

Seems kinda hacky, but how about detaching the toolbar pane from the AUI manager, adding the toolbar items, then re-attaching to the AUI manager?

_mgr.DetachPane(_toolbar);
wxAuiToolBarItem* pItem = _toolbar->AddTool(
      wxID_TCMDI_FRAME_TOOL_TB + pchild->uid(),
     pchild->GetName(),
     wxNullBitmap,
     "",
     wxITEM_NORMAL
);
wxAuiPaneInfo info;
info.Name("tbxxx")
    .Caption("xxx caption")
    .ToolbarPane().Top()
    .Gripper(true).Dockable(true)
    .Floatable(true).CaptionVisible(false);
_mgr.AddPane(_toolbar, paneInfo);