views:

19

answers:

0

I'm just loving these wx designs more and more...

I have created this set of objects and such that are meant to represent tools that are accessable through the toolbar and through menus. These of course have to be managed independently and even if not, I need to be able to toggle things in response to events not associated with toolbar events. So what I want to do is iterate all the toolbars in a wxAuiMDIFrame and then check/uncheck, enable/disable, etc...all the buttons in it based on what the manager thing I've created tells me. Right now I only have the one toolbar but in the future the user will likely be able to create more if they want and I don't want to have to mess with this again....so I need to be able to query the frame for its toolbars.

wxAuiMDIFrame does inherit from wxFrame but GetToolBar() returns 0 (LSP violation's are quite common in WX :) So obviously that's not the way.

I looked at the class definition of wxAuiMDIFrame (since it's nicely undocumented) and found nothing there that would help. I thought I could use something similar to CreateTool in wxToolBar and just track all the items independently (since the user can't ever create new toolbar items, they can just move them around and put them in different bars). Unfortunately, wxAuiToolBar doesn't return the item so I can't do that.

Here's the only thing I could think of with what I could find of a query interface:

void refresh_toolbars()
{
  auto panes = aui_manager.GetAllPanes();
  for (size_t i = 0; i < panes.size(); ++i)
  {
    wxAuiPaneInfo & info = panes[i];
    if (info.IsToolbar())
    {
      wxAuiToolBar * bar = boost::polymorphic_downcast<wxAuiToolBar*>(info.window);
      wxAuiToolBarItem * item = bar->FindTool(ui::toolbar_control_cache::ID_CALC);
      if (item)
        bar->ToggleTool(ui::toolbar_control_cache::ID_CALC, ui::toolbar_control_cache::instance()[ui::toolbar_control_cache::ID_CALC].checked(active_editor()));
      bar->Refresh();
    }
  }
}

That's just a test run that works with only one tool but it's the gist. I'm not fond of this method but it's all I could come up with. Does anyone in SO have enough experience with this API to tell me if there's a better method?

One place that seems like it would be an excellent improvement is to call something on the item pointer to do the toggle since surely bar->ToggleTool does the search again. Unfortunately nothing in the item's interface seems appropriate. Nothing has a name that sounds right and NONE of the functions or variables are documented.

I'd ask on the wx forum but in my experience they don't know jack about AUI either.

Thanks.