diff --git a/obs/wx-wrappers.cpp b/obs/wx-wrappers.cpp index cd7448336..2bbf747dd 100644 --- a/obs/wx-wrappers.cpp +++ b/obs/wx-wrappers.cpp @@ -20,6 +20,9 @@ #include #include "wx-wrappers.hpp" +#include +using namespace std; + gs_window WxToGSWindow(const wxWindow *wxwin) { gs_window window; @@ -45,3 +48,32 @@ void OBSErrorBox(wxWindow *parent, const char *message, ...) wxMessageBox(message, "Error", wxOK|wxCENTRE, parent); blog(LOG_ERROR, "%s", output); } + +class MenuWrapper : public wxEvtHandler { +public: + int retId; + + inline MenuWrapper() : retId(-1) {} + + void GetItem(wxCommandEvent &event) + { + retId = event.GetId(); + } +}; + +int WXDoPopupMenu(wxWindow *parent, wxMenu *menu) +{ + unique_ptr wrapper(new MenuWrapper); + + menu->Connect(wxEVT_MENU, + wxCommandEventHandler(MenuWrapper::GetItem), + NULL, wrapper.get()); + + bool success = parent->PopupMenu(menu); + + menu->Disconnect(wxEVT_MENU, + wxCommandEventHandler(MenuWrapper::GetItem), + NULL, wrapper.get()); + + return (success) ? wrapper->retId : -1; +} diff --git a/obs/wx-wrappers.hpp b/obs/wx-wrappers.hpp index b4016db8f..31522d907 100644 --- a/obs/wx-wrappers.hpp +++ b/obs/wx-wrappers.hpp @@ -19,6 +19,7 @@ #include #include +#include #include @@ -27,6 +28,10 @@ struct gs_window; gs_window WxToGSWindow(const wxWindow *window); void OBSErrorBox(wxWindow *parent, const char *message, ...); +/* returns actual ID of menu item clicked rather than be forced to use + * all the BS handler crap */ +int WXDoPopupMenu(wxWindow *parent, wxMenu *menu); + /* * RAII wx connection wrapper *