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
parent
4af0d7ac04
commit
146912d5b8
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue