move towards explicit handle type in P3D_window_handle

This commit is contained in:
David Rose 2009-11-18 19:26:39 +00:00
parent 3ea273ddb6
commit 21aad12650
6 changed files with 46 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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