diff --git a/panda/src/display/windowHandle.h b/panda/src/display/windowHandle.h index f99919ccae..2f1ac4f923 100644 --- a/panda/src/display/windowHandle.h +++ b/panda/src/display/windowHandle.h @@ -58,7 +58,7 @@ PUBLISHED: // This internal pointer within WindowHandle stores the actual // OS-specific window handle type, whatever type that is. It is // subclassed for each OS. - class OSHandle : public TypedReferenceCount { + class EXPCL_PANDA_DISPLAY OSHandle : public TypedReferenceCount { protected: INLINE OSHandle(); @@ -89,7 +89,7 @@ PUBLISHED: // OS handle as a size_t object, as the WindowProperties object did // historically. New code should use // GraphicsPipe::make_window_handle() instead of this. - class IntHandle : public OSHandle { + class EXPCL_PANDA_DISPLAY IntHandle : public OSHandle { PUBLISHED: INLINE IntHandle(size_t handle); virtual void format_string_handle(ostream &out) const; diff --git a/panda/src/windisplay/config_windisplay.cxx b/panda/src/windisplay/config_windisplay.cxx index 852aecfce1..1c21aafa76 100644 --- a/panda/src/windisplay/config_windisplay.cxx +++ b/panda/src/windisplay/config_windisplay.cxx @@ -77,5 +77,6 @@ init_libwindisplay() { initialized = true; WinGraphicsPipe::init_type(); + WinGraphicsPipe::WinHandle::init_type(); WinGraphicsWindow::init_type(); } diff --git a/panda/src/windisplay/winGraphicsPipe.I b/panda/src/windisplay/winGraphicsPipe.I index 4af7c7a8da..84f9d4a427 100644 --- a/panda/src/windisplay/winGraphicsPipe.I +++ b/panda/src/windisplay/winGraphicsPipe.I @@ -11,3 +11,23 @@ // with this source code in a file named "LICENSE." // //////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::WinHandle::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE WinGraphicsPipe::WinHandle:: +WinHandle(HWND handle) : _handle(handle) { +} + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::WinHandle::get_handle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE HWND WinGraphicsPipe::WinHandle:: +get_handle() const { + return _handle; +} diff --git a/panda/src/windisplay/winGraphicsPipe.cxx b/panda/src/windisplay/winGraphicsPipe.cxx index 5bdbf0ab1a..3822204723 100644 --- a/panda/src/windisplay/winGraphicsPipe.cxx +++ b/panda/src/windisplay/winGraphicsPipe.cxx @@ -27,6 +27,7 @@ TypeHandle WinGraphicsPipe::_type_handle; +TypeHandle WinGraphicsPipe::WinHandle::_type_handle; #define MAXIMUM_PROCESSORS 32 @@ -1021,3 +1022,60 @@ bool MyLoadLib(HINSTANCE &hDLL, const char *DLLname) { } return true; } + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::make_window_handle +// Access: Public +// Description: Constructs a new WindowHandle object that +// encapsulates a window with the indicated Window +// handle. +//////////////////////////////////////////////////////////////////// +WindowHandle *WinGraphicsPipe:: +make_window_handle(HWND window) { + return new WindowHandle(new WinHandle(window)); +} + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::make_int_window_handle +// Access: Public, Virtual +// Description: Creates a WindowHandle by interpreting the indicated +// integer value as an OS-specific pointer, e.g. to a +// HWND or a Window object, if this makes sense for the +// current OS. Returns the WindowHandle if successful, +// or NULL if not. +// +// This method exists primarily for the benefit of +// Python, which likes to pass around pointers as +// integers. For other languages, see the OS-specific +// make_window_handle() method, which is defined for +// each particular OS-specific GraphicsPipe type. It is +// preferable to use make_window_handle() instead of +// make_int_window_handle(). +//////////////////////////////////////////////////////////////////// +WindowHandle *WinGraphicsPipe:: +make_int_window_handle(size_t window) { + return make_window_handle((HWND)window); +} + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::WinHandle::format_string_handle +// Access: Published, Virtual +// Description: Writes the OS-specific value to the indicated stream +// in whatever representation makes sense, but it should +// format it as a decimal integer if possible, for +// consistency between platforms. +//////////////////////////////////////////////////////////////////// +void WinGraphicsPipe::WinHandle:: +format_string_handle(ostream &out) const { + out << (size_t)_handle; +} + +//////////////////////////////////////////////////////////////////// +// Function: WinGraphicsPipe::WinHandle::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void WinGraphicsPipe::WinHandle:: +output(ostream &out) const { + out << (void *)_handle; +} diff --git a/panda/src/windisplay/winGraphicsPipe.h b/panda/src/windisplay/winGraphicsPipe.h index 96bdc0ed2c..82aeebf6c6 100644 --- a/panda/src/windisplay/winGraphicsPipe.h +++ b/panda/src/windisplay/winGraphicsPipe.h @@ -39,6 +39,40 @@ public: virtual void lookup_cpu_data(); + WindowHandle *make_window_handle(HWND window); + virtual WindowHandle *make_int_window_handle(size_t window); + +public: + // Wraps a WindowHandle type for Windows. + class EXPCL_PANDAWIN WinHandle : public WindowHandle::OSHandle { + PUBLISHED: + INLINE WinHandle(HWND handle); + virtual void format_string_handle(ostream &out) const; + virtual void output(ostream &out) const; + + INLINE HWND get_handle() const; + + private: + HWND _handle; + + public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + OSHandle::init_type(); + register_type(_type_handle, "WinGraphicsPipe::WinHandle", + OSHandle::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + + private: + static TypeHandle _type_handle; + }; + private: HINSTANCE _hUser32; typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT); diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index b0d21d6e10..0453019c4c 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -878,10 +878,10 @@ open_regular_window() { windisplay_cat.info() << "os_handle type " << os_handle->get_type() << "\n"; - /*if (os_handle->is_of_type(WinGraphicsPipe::WinHandle::get_class_type())) { + if (os_handle->is_of_type(WinGraphicsPipe::WinHandle::get_class_type())) { WinGraphicsPipe::WinHandle *win_handle = DCAST(WinGraphicsPipe::WinHandle, os_handle); _hparent = win_handle->get_handle(); - } else*/ if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { + } else if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { WindowHandle::IntHandle *int_handle = DCAST(WindowHandle::IntHandle, os_handle); _hparent = (HWND)int_handle->get_handle(); }