wx-wrappers.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <wx/window.h>
  15. #include <wx/msgdlg.h>
  16. #include <obs.h>
  17. #include "wx-wrappers.hpp"
  18. #include <memory>
  19. using namespace std;
  20. #ifdef __linux__
  21. #include <gdk/gdkx.h>
  22. #include <gtk/gtk.h>
  23. #endif
  24. #include <memory>
  25. using namespace std;
  26. gs_window WxToGSWindow(const wxWindow *wxwin)
  27. {
  28. gs_window window;
  29. #ifdef __APPLE__
  30. window.view = (id)wxwin->GetHandle();
  31. #elif _WIN32
  32. window.hwnd = wxwin->GetHandle();
  33. #else
  34. window.id = gdk_x11_drawable_get_xid(gtk_widget_get_window(wxwin->GetHandle()));
  35. #endif
  36. return window;
  37. }
  38. void OBSErrorBox(wxWindow *parent, const char *message, ...)
  39. {
  40. va_list args;
  41. char output[4096];
  42. va_start(args, message);
  43. vsnprintf(output, 4095, message, args);
  44. va_end(args);
  45. wxMessageBox(message, "Error", wxOK|wxCENTRE, parent);
  46. blog(LOG_ERROR, "%s", output);
  47. }
  48. class MenuWrapper : public wxEvtHandler {
  49. public:
  50. int retId;
  51. inline MenuWrapper() : retId(-1) {}
  52. void GetItem(wxCommandEvent &event)
  53. {
  54. retId = event.GetId();
  55. }
  56. };
  57. int WXDoPopupMenu(wxWindow *parent, wxMenu *menu)
  58. {
  59. unique_ptr<MenuWrapper> wrapper(new MenuWrapper);
  60. menu->Connect(wxEVT_MENU,
  61. wxCommandEventHandler(MenuWrapper::GetItem),
  62. NULL, wrapper.get());
  63. bool success = parent->PopupMenu(menu);
  64. menu->Disconnect(wxEVT_MENU,
  65. wxCommandEventHandler(MenuWrapper::GetItem),
  66. NULL, wrapper.get());
  67. return (success) ? wrapper->retId : -1;
  68. }