Search code examples
c++eventsdrop-down-menutoolbarwxwidgets

Which event to open a wxToolBar drop-down menu?


I'm using a wxToolBar with an drop-down item:

g_toolBar1->AddTool(TOOLBAR_CMD_CONTROL_DROPDOWN,_("Control elements"),MainWin::getBitmap(gearsXPM,"gears"),wxNullBitmap,wxITEM_DROPDOWN);
custParent->Connect(TOOLBAR_CMD_CONTROL_DROPDOWN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(DrawCanvasSwitcher::OnToolbar),NULL,g_drawCanvas);
.... // add items to controlMenu here
g_toolBar1->SetDropdownMenu(TOOLBAR_CMD_CONTROL_DROPDOWN,controlMenu);

The drop-down menu opens automatically when somebody left-clicks the arrow right beside the tool. But what event do I have to send to open the drop-down menu programmatically?

Thanks!


Solution

  • You can open any menu, also a drop down menu by calling PopupMenu:

    bool wxWindow::PopupMenu (wxMenu*        menu,
                              const wxPoint& pos = wxDefaultPosition);
    

    So in your case it should be:

    yourWxWindow->PopupMenu(controlMenu);
    

    or when you are already in a class that inherits from wxWindow:

    PopupMenu(controlMenu);