提交 146912d5 编写于 作者: J jp9000

add wrapper for popup menus so you aren't forced to write a god forsaken...

add wrapper for popup menus so you aren't forced to write a god forsaken function handler whenever you just want to do a basic popup menu
上级 4af0d7ac
......@@ -20,6 +20,9 @@
#include <obs.h>
#include "wx-wrappers.hpp"
#include <memory>
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<MenuWrapper> 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;
}
......@@ -19,6 +19,7 @@
#include <wx/window.h>
#include <wx/event.h>
#include <wx/menu.h>
#include <vector>
......@@ -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
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册