0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

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

This commit is contained in:
jp9000 2013-12-30 06:55:58 -07:00
parent 4af0d7ac04
commit 146912d5b8
2 changed files with 37 additions and 0 deletions

View File

@ -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;
}

View File

@ -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
*