From 21aad12650cb263d07f364cae8f3e82bb7cf4b70 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 18 Nov 2009 19:26:39 +0000 Subject: [PATCH] move towards explicit handle type in P3D_window_handle --- direct/src/plugin/p3dWindowParams.I | 2 +- direct/src/plugin/p3dWindowParams.cxx | 3 ++- direct/src/plugin/p3dWindowParams.h | 2 +- direct/src/plugin/p3dX11SplashWindow.cxx | 4 ++- direct/src/plugin/p3d_plugin.h | 34 ++++++++++++++++++++---- direct/src/plugin_npapi/ppInstance.cxx | 16 ++++++----- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/direct/src/plugin/p3dWindowParams.I b/direct/src/plugin/p3dWindowParams.I index eb67cc84c5..8b7eff0162 100644 --- a/direct/src/plugin/p3dWindowParams.I +++ b/direct/src/plugin/p3dWindowParams.I @@ -84,7 +84,7 @@ get_win_height() const { // Description: Returns the parent window handle that was passed to // the constructor. //////////////////////////////////////////////////////////////////// -inline P3D_window_handle P3DWindowParams:: +inline const P3D_window_handle &P3DWindowParams:: get_parent_window() const { return _parent_window; } diff --git a/direct/src/plugin/p3dWindowParams.cxx b/direct/src/plugin/p3dWindowParams.cxx index f272ccee77..6b6d60577b 100644 --- a/direct/src/plugin/p3dWindowParams.cxx +++ b/direct/src/plugin/p3dWindowParams.cxx @@ -88,7 +88,8 @@ make_xml(P3DInstance *inst) { // stringstream to do it ourselves. { ostringstream strm; - strm << _parent_window._xwindow; + assert(_parent_window._window_handle_type == P3D_WHT_x11_window); + strm << _parent_window._handle._x11_window._xwindow; xwparams->SetAttribute("parent_xwindow", strm.str()); } #endif diff --git a/direct/src/plugin/p3dWindowParams.h b/direct/src/plugin/p3dWindowParams.h index 17b3001c98..3036f4e681 100644 --- a/direct/src/plugin/p3dWindowParams.h +++ b/direct/src/plugin/p3dWindowParams.h @@ -41,7 +41,7 @@ public: inline int get_win_y() const; inline int get_win_width() const; inline int get_win_height() const; - inline P3D_window_handle get_parent_window() const; + inline const P3D_window_handle &get_parent_window() const; TiXmlElement *make_xml(P3DInstance *inst); diff --git a/direct/src/plugin/p3dX11SplashWindow.cxx b/direct/src/plugin/p3dX11SplashWindow.cxx index 90084c9eb2..99651708a5 100755 --- a/direct/src/plugin/p3dX11SplashWindow.cxx +++ b/direct/src/plugin/p3dX11SplashWindow.cxx @@ -805,7 +805,9 @@ make_window() { if (_wparams.get_window_type() == P3D_WT_embedded) { // Create an embedded window. - parent = _wparams.get_parent_window()._xwindow; + const P3D_window_handle &handle = _wparams.get_parent_window(); + assert(handle._window_handle_type == P3D_WHT_x11_window); + parent = handle._handle._x11_window._xwindow; } else { // Create a toplevel window. parent = XRootWindow(_display, _screen); diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index a051123726..a42a15cbb2 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -197,20 +197,44 @@ typedef struct { /* Additional opaque data may be stored here. */ } P3D_instance; -/* This structure abstracts out the various window handle types for - the different platforms. */ +/* This enum and set of structures abstract out the various window + handle types for the different platforms. */ + +typedef enum { + P3D_WHT_none, + P3D_WHT_win_hwnd, + P3D_WHT_osx_port, + P3D_WHT_x11_window, +} P3D_window_handle_type; + typedef struct { #ifdef _WIN32 HWND _hwnd; +#endif +} P3D_window_handle_win_hwnd; -#elif defined(__APPLE__) - /* As provided by Mozilla. */ + /* As provided by Mozilla, by default. Not compatible with Snow + Leopard. */ +typedef struct { +#if defined(__APPLE__) GrafPtr _port; +#endif +} P3D_window_handle_osx_port; -#elif defined(HAVE_X11) +typedef struct { +#if defined(HAVE_X11) unsigned long _xwindow; void *_xdisplay; #endif +} P3D_window_handle_x11_window; + +typedef struct { + P3D_window_handle_type _window_handle_type; + union { + P3D_window_handle_win_hwnd _win_hwnd; + P3D_window_handle_osx_port _osx_port; + P3D_window_handle_x11_window _x11_window; + } _handle; } P3D_window_handle; /* This enum lists the different kinds of window types that may be diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index c0aec727e0..040fb51d09 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -1292,6 +1292,9 @@ send_window() { int y = _window.y; P3D_window_handle parent_window; + memset(&parent_window, 0, sizeof(parent_window)); + parent_window._window_handle_type = P3D_WHT_none; + if (_window.type == NPWindowTypeWindow) { // We have a "windowed" plugin. Parent our window to the one we // were given. In this case, we should also reset the offset to @@ -1314,7 +1317,8 @@ send_window() { #elif defined(HAVE_X11) // We make it an 'unsigned long' instead of 'Window' // to avoid nppanda3d.so getting a dependency on X11. - parent_window._xwindow = (unsigned long)(_window.window); + parent_window._window_handle_type = P3D_WHT_x11_window; + parent_window._handle._x11_window._xwindow = (unsigned long)(_window.window); x = 0; y = 0; #endif @@ -1340,22 +1344,22 @@ send_window() { */ #elif defined(HAVE_X11) - parent_window._xwindow = 0; unsigned long win; if (browser->getvalue(_npp_instance, NPNVnetscapeWindow, &win) == NPERR_NO_ERROR) { - parent_window._xwindow = win; + parent_window._window_handle_type = P3D_WHT_x11_window; + parent_window._handle._x11_window._xwindow = win; } #endif } #ifdef HAVE_X11 // In the case of X11, grab the display as well. - parent_window._xdisplay = 0; - void* disp; + parent_window._handle._x11_window._xdisplay = 0; + void *disp; if (browser->getvalue(_npp_instance, NPNVxDisplay, &disp) == NPERR_NO_ERROR) { - parent_window._xdisplay = disp; + parent_window._handle._x11_window._xdisplay = disp; } #endif