From 7857e5fa9bd5d067e1a675ac69440979ce6fccb1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 1 Oct 2009 00:23:12 +0000 Subject: [PATCH] better WindowHandle stuff --- panda/src/display/Sources.pp | 3 + panda/src/display/config_display.cxx | 3 +- panda/src/display/display_composite2.cxx | 1 + panda/src/display/graphicsPipe.cxx | 22 -- panda/src/display/graphicsPipe.h | 1 - panda/src/display/nativeWindowHandle.I | 98 +++++++++ panda/src/display/nativeWindowHandle.cxx | 167 +++++++++++++++ panda/src/display/nativeWindowHandle.h | 199 ++++++++++++++++++ panda/src/display/windowHandle.I | 20 -- panda/src/display/windowHandle.cxx | 56 ++--- panda/src/display/windowHandle.h | 39 +--- panda/src/display/windowProperties.I | 26 --- panda/src/display/windowProperties.cxx | 82 +++++++- panda/src/display/windowProperties.h | 8 +- panda/src/egldisplay/eglGraphicsWindow.cxx | 10 +- panda/src/glxdisplay/glxGraphicsWindow.cxx | 9 +- panda/src/tinydisplay/tinyXGraphicsWindow.cxx | 9 +- panda/src/windisplay/winGraphicsPipe.I | 18 -- panda/src/windisplay/winGraphicsPipe.cxx | 57 ----- panda/src/windisplay/winGraphicsPipe.h | 34 --- panda/src/windisplay/winGraphicsWindow.cxx | 9 +- panda/src/x11display/config_x11display.cxx | 1 - panda/src/x11display/x11GraphicsPipe.I | 19 -- panda/src/x11display/x11GraphicsPipe.cxx | 58 ----- panda/src/x11display/x11GraphicsPipe.h | 34 --- 25 files changed, 594 insertions(+), 389 deletions(-) create mode 100644 panda/src/display/nativeWindowHandle.I create mode 100644 panda/src/display/nativeWindowHandle.cxx create mode 100644 panda/src/display/nativeWindowHandle.h diff --git a/panda/src/display/Sources.pp b/panda/src/display/Sources.pp index d9414ba1ab..63ac6c9d5c 100644 --- a/panda/src/display/Sources.pp +++ b/panda/src/display/Sources.pp @@ -31,6 +31,7 @@ graphicsWindowInputDevice.h \ graphicsDevice.h graphicsDevice.I \ lru.h \ + nativeWindowHandle.I nativeWindowHandle.h \ parasiteBuffer.I parasiteBuffer.h \ windowHandle.I windowHandle.h \ windowProperties.I windowProperties.h \ @@ -59,6 +60,7 @@ graphicsThreadingModel.cxx \ graphicsWindow.cxx graphicsWindowInputDevice.cxx \ graphicsDevice.cxx \ + nativeWindowHandle.cxx \ parasiteBuffer.cxx \ windowHandle.cxx \ windowProperties.cxx \ @@ -89,6 +91,7 @@ graphicsWindowInputDevice.I graphicsWindowInputDevice.h \ graphicsDevice.I graphicsDevice.h \ lru.h \ + nativeWindowHandle.I nativeWindowHandle.h \ parasiteBuffer.I parasiteBuffer.h \ windowHandle.I windowHandle.h \ windowProperties.I windowProperties.h \ diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index a2a94e5c45..e37f61f00d 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -23,6 +23,7 @@ #include "graphicsBuffer.h" #include "graphicsWindow.h" #include "graphicsDevice.h" +#include "nativeWindowHandle.h" #include "parasiteBuffer.h" #include "pandaSystem.h" #include "stereoDisplayRegion.h" @@ -416,6 +417,7 @@ init_libdisplay() { GraphicsPipe::init_type(); GraphicsStateGuardian::init_type(); GraphicsWindow::init_type(); + NativeWindowHandle::init_type(); ParasiteBuffer::init_type(); StandardMunger::init_type(); StereoDisplayRegion::init_type(); @@ -424,7 +426,6 @@ init_libdisplay() { #endif WindowHandle::init_type(); WindowHandle::OSHandle::init_type(); - WindowHandle::IntHandle::init_type(); #if defined(HAVE_THREADS) && defined(DO_PIPELINING) PandaSystem *ps = PandaSystem::get_global_ptr(); diff --git a/panda/src/display/display_composite2.cxx b/panda/src/display/display_composite2.cxx index e42b6ffa1b..13fa5fc158 100644 --- a/panda/src/display/display_composite2.cxx +++ b/panda/src/display/display_composite2.cxx @@ -4,6 +4,7 @@ #include "graphicsWindow.cxx" #include "graphicsWindowInputDevice.cxx" #include "lru.cxx" +#include "nativeWindowHandle.cxx" #include "parasiteBuffer.cxx" #include "standardMunger.cxx" #include "stencilRenderStates.cxx" diff --git a/panda/src/display/graphicsPipe.cxx b/panda/src/display/graphicsPipe.cxx index 55e0518920..84fce1fb82 100644 --- a/panda/src/display/graphicsPipe.cxx +++ b/panda/src/display/graphicsPipe.cxx @@ -148,28 +148,6 @@ get_display_information() { return _display_information; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsPipe::make_int_window_handle -// Access: Published -// 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 *GraphicsPipe:: -make_int_window_handle(size_t window) { - return NULL; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsPipe::lookup_cpu_data // Access: Public, Virtual diff --git a/panda/src/display/graphicsPipe.h b/panda/src/display/graphicsPipe.h index 8cef7ec2f3..8508d50f7a 100644 --- a/panda/src/display/graphicsPipe.h +++ b/panda/src/display/graphicsPipe.h @@ -101,7 +101,6 @@ PUBLISHED: virtual void lookup_cpu_data(); virtual string get_interface_name() const=0; - virtual WindowHandle *make_int_window_handle(size_t window); public: enum PreferredWindowThread { diff --git a/panda/src/display/nativeWindowHandle.I b/panda/src/display/nativeWindowHandle.I new file mode 100644 index 0000000000..0bea26e700 --- /dev/null +++ b/panda/src/display/nativeWindowHandle.I @@ -0,0 +1,98 @@ +// Filename: nativeWindowHandle.I +// Created by: drose (30Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::IntHandle::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NativeWindowHandle::IntHandle:: +IntHandle(size_t handle) : _handle(handle) { +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::IntHandle::get_handle +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE size_t NativeWindowHandle::IntHandle:: +get_handle() const { + return _handle; +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::SubprocessHandle::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NativeWindowHandle::SubprocessHandle:: +SubprocessHandle(const Filename &filename) : _filename(filename) { +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::SubprocessHandle::get_filename +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE const Filename &NativeWindowHandle::SubprocessHandle:: +get_filename() const { + return _filename; +} + +#if defined(HAVE_X11) && !defined(CPPPARSER) +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::X11Handle::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NativeWindowHandle::X11Handle:: +X11Handle(Window handle) : _handle(handle) { +} +#endif // HAVE_X11 + +#if defined(HAVE_X11) && !defined(CPPPARSER) +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::X11Handle::get_handle +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE Window NativeWindowHandle::X11Handle:: +get_handle() const { + return _handle; +} +#endif // HAVE_X11 + +#ifdef WIN32 +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::WinHandle::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE NativeWindowHandle::WinHandle:: +WinHandle(HWND handle) : _handle(handle) { +} +#endif // WIN32 + +#ifdef WIN32 +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::WinHandle::get_handle +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE HWND NativeWindowHandle::WinHandle:: +get_handle() const { + return _handle; +} +#endif // WIN32 diff --git a/panda/src/display/nativeWindowHandle.cxx b/panda/src/display/nativeWindowHandle.cxx new file mode 100644 index 0000000000..30f70e0c7b --- /dev/null +++ b/panda/src/display/nativeWindowHandle.cxx @@ -0,0 +1,167 @@ +// Filename: nativeWindowHandle.cxx +// Created by: drose (30Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "nativeWindowHandle.h" + +TypeHandle NativeWindowHandle::IntHandle::_type_handle; +TypeHandle NativeWindowHandle::SubprocessHandle::_type_handle; + +#if defined(HAVE_X11) && !defined(CPPPARSER) +TypeHandle NativeWindowHandle::X11Handle::_type_handle; +#endif +#ifdef WIN32 +TypeHandle NativeWindowHandle::WinHandle::_type_handle; +#endif + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::make_int +// Access: Published, Static +// Description: Constructs a new WindowHandle with an int value, +// which is understood to be either an HWND or a Window, +// cast to int. This method exists for the convenience +// of Python, which likes to deal with ints; C++ code +// should use one of the more specific make_x11() or +// make_win32() methods instead. +//////////////////////////////////////////////////////////////////// +PT(WindowHandle) NativeWindowHandle:: +make_int(size_t window) { + return new WindowHandle(new IntHandle(window)); +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::make_subprocess +// Access: Published, Static +// Description: Constructs a new WindowHandle that references a +// SubprocessWindowBuffer read in another process, with +// the named pipe filename that it uses for +// communication. +// +// This is (at present, and maybe always) useful only on +// the OS X platform, where parenting child windows is +// particularly problematic. +//////////////////////////////////////////////////////////////////// +PT(WindowHandle) NativeWindowHandle:: +make_subprocess(const Filename &filename) { + return new WindowHandle(new SubprocessHandle(filename)); +} + +#if defined(HAVE_X11) && !defined(CPPPARSER) +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::make_x11 +// Access: Published, Static +// Description: Constructs a new WindowHandle that references an +// X11 window. +//////////////////////////////////////////////////////////////////// +PT(WindowHandle) NativeWindowHandle:: +make_x11(Window window) { + return new WindowHandle(new X11Handle(window)); +} +#endif // HAVE_X11 + +#ifdef WIN32 +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::make_win +// Access: Published, Static +// Description: Constructs a new WindowHandle that references a +// window on Windows. +//////////////////////////////////////////////////////////////////// +PT(WindowHandle) NativeWindowHandle:: +make_win(HWND window) { + return new WindowHandle(new WinHandle(window)); +} +#endif // WIN32 + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::IntHandle::get_int_handle +// Access: Public, Virtual +// Description: Returns the OS-specific handle converted to an +// integer, if this is possible for the particular +// representation. Returns 0 if it is not. +//////////////////////////////////////////////////////////////////// +size_t NativeWindowHandle::IntHandle:: +get_int_handle() const { + return _handle; +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::IntHandle::output +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void NativeWindowHandle::IntHandle:: +output(ostream &out) const { + out << _handle; +} + +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::SubprocessHandle::output +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void NativeWindowHandle::SubprocessHandle:: +output(ostream &out) const { + out << _filename; +} + +#if defined(HAVE_X11) && !defined(CPPPARSER) +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::X11Handle::get_int_handle +// Access: Public, Virtual +// Description: Returns the OS-specific handle converted to an +// integer, if this is possible for the particular +// representation. Returns 0 if it is not. +//////////////////////////////////////////////////////////////////// +size_t NativeWindowHandle::X11Handle:: +get_int_handle() const { + return (size_t)_handle; +} +#endif // HAVE_X11 + +#if defined(HAVE_X11) && !defined(CPPPARSER) +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::X11Handle::output +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void NativeWindowHandle::X11Handle:: +output(ostream &out) const { + out << _handle; +} +#endif // HAVE_X11 + +#ifdef WIN32 +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::WinHandle::get_int_handle +// Access: Public, Virtual +// Description: Returns the OS-specific handle converted to an +// integer, if this is possible for the particular +// representation. Returns 0 if it is not. +//////////////////////////////////////////////////////////////////// +size_t NativeWindowHandle::WinHandle:: +get_int_handle() const { + return (size_t)_handle; +} +#endif // WIN32 + +#ifdef WIN32 +//////////////////////////////////////////////////////////////////// +// Function: NativeWindowHandle::WinHandle::output +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void NativeWindowHandle::WinHandle:: +output(ostream &out) const { + out << _handle; +} +#endif // WIN32 diff --git a/panda/src/display/nativeWindowHandle.h b/panda/src/display/nativeWindowHandle.h new file mode 100644 index 0000000000..2d255b2400 --- /dev/null +++ b/panda/src/display/nativeWindowHandle.h @@ -0,0 +1,199 @@ +// Filename: nativeWindowHandle.h +// Created by: drose (30Sep09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef NATIVEWINDOWHANDLE_H +#define NATIVEWINDOWHANDLE_H + +#include "pandabase.h" + +#include "typedReferenceCount.h" +#include "pointerTo.h" + +#ifdef HAVE_X11 +#include +#endif + +#ifdef WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +//////////////////////////////////////////////////////////////////// +// Class : NativeWindowHandle +// Description : This subclass of WindowHandle exists to allow simple +// creation of a WindowHandle of the appropriate type to +// the current OS. +// +// This class exists for name scoping only. Don't use +// the constructor directly; use one of the make_* +// methods. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA_DISPLAY NativeWindowHandle : public WindowHandle { +private: + INLINE NativeWindowHandle(); + INLINE NativeWindowHandle(const NativeWindowHandle ©); + +PUBLISHED: + static PT(WindowHandle) make_int(size_t window); + static PT(WindowHandle) make_subprocess(const Filename &filename); + +public: +#if defined(HAVE_X11) && !defined(CPPPARSER) + static PT(WindowHandle) make_x11(Window window); +#endif // HAVE_X11 + +#ifdef WIN32 + static PT(WindowHandle) make_win32(HWND window); +#endif // WIN32 + +public: + class IntHandle : public OSHandle { + public: + INLINE IntHandle(size_t handle); + virtual size_t get_int_handle() const; + virtual void output(ostream &out) const; + + INLINE size_t get_handle() const; + + private: + size_t _handle; + + public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + OSHandle::init_type(); + register_type(_type_handle, "NativeWindowHandle::IntHandle", + 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; + }; + + class SubprocessHandle : public OSHandle { + public: + INLINE SubprocessHandle(const Filename &filename); + virtual void output(ostream &out) const; + + INLINE const Filename &get_filename() const; + + private: + Filename _filename; + + public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + OSHandle::init_type(); + register_type(_type_handle, "NativeWindowHandle::SubprocessHandle", + 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; + }; + +#if defined(HAVE_X11) && !defined(CPPPARSER) + class X11Handle : public OSHandle { + public: + INLINE X11Handle(Window handle); + virtual size_t get_int_handle() const; + virtual void output(ostream &out) const; + + INLINE Window get_handle() const; + + private: + Window _handle; + + public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + OSHandle::init_type(); + register_type(_type_handle, "NativeWindowHandle::X11Handle", + 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; + }; +#endif // HAVE_X11 + + +#ifdef WIN32 + class EXPCL_PANDA_DISPLAY WinHandle : public OSHandle { + public: + INLINE WinHandle(HWND handle); + virtual size_t get_int_handle() 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, "NativeWindowHandle::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; + }; +#endif // WIN32 + +public: + static void init_type() { + IntHandle::init_type(); + SubprocessHandle::init_type(); +#if defined(HAVE_X11) && !defined(CPPPARSER) + X11Handle::init_type(); +#endif +#ifdef WIN32 + WinHandle::init_type(); +#endif + } + +}; + +#include "nativeWindowHandle.I" + +#endif diff --git a/panda/src/display/windowHandle.I b/panda/src/display/windowHandle.I index cb609cc708..d1035080cc 100644 --- a/panda/src/display/windowHandle.I +++ b/panda/src/display/windowHandle.I @@ -65,23 +65,3 @@ set_os_handle(OSHandle *os_handle) { INLINE WindowHandle::OSHandle:: OSHandle() { } - - -//////////////////////////////////////////////////////////////////// -// Function: WindowHandle::IntHandle::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE WindowHandle::IntHandle:: -IntHandle(size_t handle) : _handle(handle) { -} - -//////////////////////////////////////////////////////////////////// -// Function: WindowHandle::IntHandle::get_handle -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE size_t WindowHandle::IntHandle:: -get_handle() const { - return _handle; -} diff --git a/panda/src/display/windowHandle.cxx b/panda/src/display/windowHandle.cxx index e5f7be4ce7..11d4df75c4 100644 --- a/panda/src/display/windowHandle.cxx +++ b/panda/src/display/windowHandle.cxx @@ -16,7 +16,6 @@ TypeHandle WindowHandle::_type_handle; TypeHandle WindowHandle::OSHandle::_type_handle; -TypeHandle WindowHandle::IntHandle::_type_handle; //////////////////////////////////////////////////////////////////// // Function: WindowHandle::Destructor @@ -28,20 +27,18 @@ WindowHandle:: } //////////////////////////////////////////////////////////////////// -// Function: WindowHandle::get_string_handle +// Function: WindowHandle::get_int_handle // Access: Published -// Description: Returns the OS-specific handle in a string -// representation, whatever that means for a particular -// OS. Typically this is a pointer value, represented -// as a decimal integer. +// Description: Returns the OS-specific handle converted to an +// integer, if this is possible for the particular +// representation. Returns 0 if it is not. //////////////////////////////////////////////////////////////////// -string WindowHandle:: -get_string_handle() const { - ostringstream strm; +size_t WindowHandle:: +get_int_handle() const { if (_os_handle != NULL) { - _os_handle->format_string_handle(strm); + return _os_handle->get_int_handle(); } - return strm.str(); + return 0; } //////////////////////////////////////////////////////////////////// @@ -100,15 +97,15 @@ WindowHandle::OSHandle:: } //////////////////////////////////////////////////////////////////// -// Function: WindowHandle::OSHandle::format_string_handle +// Function: WindowHandle::OSHandle::get_int_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. +// Description: Returns the OS-specific handle converted to an +// integer, if this is possible for the particular +// representation. Returns 0 if it is not. //////////////////////////////////////////////////////////////////// -void WindowHandle::OSHandle:: -format_string_handle(ostream &out) const { +size_t WindowHandle::OSHandle:: +get_int_handle() const { + return 0; } //////////////////////////////////////////////////////////////////// @@ -120,26 +117,3 @@ void WindowHandle::OSHandle:: output(ostream &out) const { out << "(no type)"; } - -//////////////////////////////////////////////////////////////////// -// Function: WindowHandle::IntHandle::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 WindowHandle::IntHandle:: -format_string_handle(ostream &out) const { - out << _handle; -} - -//////////////////////////////////////////////////////////////////// -// Function: WindowHandle::IntHandle::output -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void WindowHandle::IntHandle:: -output(ostream &out) const { - out << _handle; -} diff --git a/panda/src/display/windowHandle.h b/panda/src/display/windowHandle.h index 2f1ac4f923..d1f00e4263 100644 --- a/panda/src/display/windowHandle.h +++ b/panda/src/display/windowHandle.h @@ -51,7 +51,7 @@ PUBLISHED: INLINE OSHandle *get_os_handle() const; INLINE void set_os_handle(OSHandle *os_handle); - string get_string_handle() const; + size_t get_int_handle() const; void output(ostream &out) const; @@ -64,7 +64,7 @@ PUBLISHED: PUBLISHED: virtual ~OSHandle(); - virtual void format_string_handle(ostream &out) const; + virtual size_t get_int_handle() const; virtual void output(ostream &out) const; public: @@ -85,41 +85,6 @@ PUBLISHED: static TypeHandle _type_handle; }; - // This class only exists for backward compatibility; it stores the - // 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 EXPCL_PANDA_DISPLAY IntHandle : public OSHandle { - PUBLISHED: - INLINE IntHandle(size_t handle); - virtual void format_string_handle(ostream &out) const; - virtual void output(ostream &out) const; - - INLINE size_t get_handle() const; - - private: - size_t _handle; - - public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - OSHandle::init_type(); - register_type(_type_handle, "WindowHandle::IntHandle", - 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; - }; - - - protected: // Callbacks for communication with the parent window. virtual void attach_child(WindowHandle *child); diff --git a/panda/src/display/windowProperties.I b/panda/src/display/windowProperties.I index f0620e7787..a4f05d2ec7 100644 --- a/panda/src/display/windowProperties.I +++ b/panda/src/display/windowProperties.I @@ -799,32 +799,6 @@ clear_mouse_mode() { _mouse_mode = M_absolute; } -//////////////////////////////////////////////////////////////////// -// Function: WindowProperties::set_parent_window -// Access: Published -// Description: Specifies the window that this window should be -// attached to. -// -// This is a deprecated variant on this method, and -// exists only for backward compatibility. Future code -// should use the version of set_parent_window() below -// that receives a WindowHandle object; that interface -// is much more robust. -// -// In this deprecated variant, the actual value for -// "parent" is platform-specific. On Windows, it is the -// HWND of the parent window, cast to an unsigned -// integer. On X11, it is the Window pointer of the -// parent window, similarly cast. On OSX, this is the -// NSWindow pointer, which doesn't appear to work at -// all. -//////////////////////////////////////////////////////////////////// -INLINE void WindowProperties:: -set_parent_window(size_t parent) { - PT(WindowHandle) handle = new WindowHandle(new WindowHandle::IntHandle(parent)); - set_parent_window(handle); -} - //////////////////////////////////////////////////////////////////// // Function: WindowProperties::set_parent_window // Access: Published diff --git a/panda/src/display/windowProperties.cxx b/panda/src/display/windowProperties.cxx index 32828bf6bd..d16e87c2c8 100644 --- a/panda/src/display/windowProperties.cxx +++ b/panda/src/display/windowProperties.cxx @@ -14,7 +14,9 @@ #include "windowProperties.h" #include "config_display.h" +#include "nativeWindowHandle.h" +WindowProperties *WindowProperties::_default_properties = NULL; //////////////////////////////////////////////////////////////////// // Function: WindowProperties::Constructor @@ -49,14 +51,14 @@ operator = (const WindowProperties ©) { } //////////////////////////////////////////////////////////////////// -// Function: WindowProperties::get_default +// Function: WindowProperties::get_config_properties // Access: Published, Static // Description: Returns a WindowProperties structure with all of the // default values filled in according to the user's // config file. //////////////////////////////////////////////////////////////////// WindowProperties WindowProperties:: -get_default() { +get_config_properties() { WindowProperties props; props.set_open(true); @@ -95,6 +97,56 @@ get_default() { return props; } +//////////////////////////////////////////////////////////////////// +// Function: WindowProperties::get_default +// Access: Published, Static +// Description: Returns the "default" WindowProperties. If +// set_default() has been called, this returns that +// WindowProperties structure; otherwise, this returns +// get_config_properties(). +//////////////////////////////////////////////////////////////////// +WindowProperties WindowProperties:: +get_default() { + if (_default_properties != NULL) { + return *_default_properties; + } else { + return get_config_properties(); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: WindowProperties::set_default +// Access: Published, Static +// Description: Replaces the "default" WindowProperties with the +// specified structure. The specified WindowProperties +// will be returned by future calls to get_default(), +// until clear_default() is called. +// +// Note that this completely replaces the default +// properties; it is not additive. +//////////////////////////////////////////////////////////////////// +void WindowProperties:: +set_default(const WindowProperties &default_properties) { + if (_default_properties == NULL) { + _default_properties = new WindowProperties; + } + (*_default_properties) = default_properties; +} + +//////////////////////////////////////////////////////////////////// +// Function: WindowProperties::clear_default +// Access: Published, Static +// Description: Returns the "default" WindowProperties to whatever +// is specified in the user's config file. +//////////////////////////////////////////////////////////////////// +void WindowProperties:: +clear_default() { + if (_default_properties != NULL) { + delete _default_properties; + _default_properties = NULL; + } +} + //////////////////////////////////////////////////////////////////// // Function: WindowProperties::size // Access: Published, Static @@ -155,6 +207,32 @@ clear() { _subprocess_window = Filename(); } +//////////////////////////////////////////////////////////////////// +// Function: WindowProperties::set_parent_window +// Access: Published +// Description: Specifies the window that this window should be +// attached to. +// +// This is a deprecated variant on this method, and +// exists only for backward compatibility. Future code +// should use the version of set_parent_window() below +// that receives a WindowHandle object; that interface +// is much more robust. +// +// In this deprecated variant, the actual value for +// "parent" is platform-specific. On Windows, it is the +// HWND of the parent window, cast to an unsigned +// integer. On X11, it is the Window pointer of the +// parent window, similarly cast. On OSX, this is the +// NSWindow pointer, which doesn't appear to work at +// all. +//////////////////////////////////////////////////////////////////// +void WindowProperties:: +set_parent_window(size_t parent) { + PT(WindowHandle) handle = NativeWindowHandle::make_int(parent); + set_parent_window(handle); +} + //////////////////////////////////////////////////////////////////// // Function: WindowProperties::add_properties // Access: Published diff --git a/panda/src/display/windowProperties.h b/panda/src/display/windowProperties.h index 30c0a9cc40..760a96f21e 100644 --- a/panda/src/display/windowProperties.h +++ b/panda/src/display/windowProperties.h @@ -45,7 +45,11 @@ PUBLISHED: void operator = (const WindowProperties ©); INLINE ~WindowProperties(); + static WindowProperties get_config_properties(); static WindowProperties get_default(); + static void set_default(const WindowProperties &default_properties); + static void clear_default(); + static WindowProperties size(int x_size, int y_size); bool operator == (const WindowProperties &other) const; @@ -131,7 +135,7 @@ PUBLISHED: INLINE bool has_z_order() const; INLINE void clear_z_order(); - INLINE void set_parent_window(size_t parent); + void set_parent_window(size_t parent); INLINE void set_parent_window(WindowHandle *parent_window); INLINE WindowHandle *get_parent_window() const; INLINE bool has_parent_window() const; @@ -197,6 +201,8 @@ private: unsigned int _flags; PT(WindowHandle) _parent_window; Filename _subprocess_window; + + static WindowProperties *_default_properties; }; EXPCL_PANDA_DISPLAY ostream & diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index 6975c6858e..d85c142749 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -25,7 +25,7 @@ #include "textEncoder.h" #include "throw_event.h" #include "lightReMutexHolder.h" -#include "x11GraphicsPipe.h" +#include "nativeWindowHandle.h" #include #include @@ -676,11 +676,11 @@ open_window() { egldisplay_cat.info() << "os_handle type " << os_handle->get_type() << "\n"; - if (os_handle->is_of_type(x11GraphicsPipe::x11Handle::get_class_type())) { - x11GraphicsPipe::x11Handle *x11_handle = DCAST(x11GraphicsPipe::x11Handle, os_handle); + if (os_handle->is_of_type(NativeWindowHandle::X11Handle::get_class_type())) { + NativeWindowHandle::X11Handle *x11_handle = DCAST(NativeWindowHandle::X11Handle, os_handle); parent_window = x11_handle->get_handle(); - } else if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { - WindowHandle::IntHandle *int_handle = DCAST(WindowHandle::IntHandle, os_handle); + } else if (os_handle->is_of_type(NativeWindowHandle::IntHandle::get_class_type())) { + NativeWindowHandle::IntHandle *int_handle = DCAST(NativeWindowHandle::IntHandle, os_handle); parent_window = (Window)int_handle->get_handle(); } } diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 97b7165c1c..e24985378c 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -26,6 +26,7 @@ #include "textEncoder.h" #include "throw_event.h" #include "lightReMutexHolder.h" +#include "nativeWindowHandle.h" #include #include @@ -206,11 +207,11 @@ open_window() { glxdisplay_cat.info() << "os_handle type " << os_handle->get_type() << "\n"; - if (os_handle->is_of_type(x11GraphicsPipe::x11Handle::get_class_type())) { - x11GraphicsPipe::x11Handle *x11_handle = DCAST(x11GraphicsPipe::x11Handle, os_handle); + if (os_handle->is_of_type(NativeWindowHandle::X11Handle::get_class_type())) { + NativeWindowHandle::X11Handle *x11_handle = DCAST(NativeWindowHandle::X11Handle, os_handle); parent_window = x11_handle->get_handle(); - } else if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { - WindowHandle::IntHandle *int_handle = DCAST(WindowHandle::IntHandle, os_handle); + } else if (os_handle->is_of_type(NativeWindowHandle::IntHandle::get_class_type())) { + NativeWindowHandle::IntHandle *int_handle = DCAST(NativeWindowHandle::IntHandle, os_handle); parent_window = (Window)int_handle->get_handle(); } } diff --git a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx index 7674a85c80..44d8b1aa0a 100644 --- a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx @@ -29,6 +29,7 @@ #include "textEncoder.h" #include "throw_event.h" #include "lightReMutexHolder.h" +#include "nativeWindowHandle.h" TypeHandle TinyXGraphicsWindow::_type_handle; @@ -521,11 +522,11 @@ open_window() { tinydisplay_cat.info() << "os_handle type " << os_handle->get_type() << "\n"; - if (os_handle->is_of_type(x11GraphicsPipe::x11Handle::get_class_type())) { - x11GraphicsPipe::x11Handle *x11_handle = DCAST(x11GraphicsPipe::x11Handle, os_handle); + if (os_handle->is_of_type(NativeWindowHandle::X11Handle::get_class_type())) { + NativeWindowHandle::X11Handle *x11_handle = DCAST(NativeWindowHandle::X11Handle, os_handle); parent_window = x11_handle->get_handle(); - } else if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { - WindowHandle::IntHandle *int_handle = DCAST(WindowHandle::IntHandle, os_handle); + } else if (os_handle->is_of_type(NativeWindowHandle::IntHandle::get_class_type())) { + NativeWindowHandle::IntHandle *int_handle = DCAST(NativeWindowHandle::IntHandle, os_handle); parent_window = (Window)int_handle->get_handle(); } } diff --git a/panda/src/windisplay/winGraphicsPipe.I b/panda/src/windisplay/winGraphicsPipe.I index 84f9d4a427..fd191e2429 100644 --- a/panda/src/windisplay/winGraphicsPipe.I +++ b/panda/src/windisplay/winGraphicsPipe.I @@ -13,21 +13,3 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// 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 3822204723..5a486897a9 100644 --- a/panda/src/windisplay/winGraphicsPipe.cxx +++ b/panda/src/windisplay/winGraphicsPipe.cxx @@ -1022,60 +1022,3 @@ 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 82aeebf6c6..96bdc0ed2c 100644 --- a/panda/src/windisplay/winGraphicsPipe.h +++ b/panda/src/windisplay/winGraphicsPipe.h @@ -39,40 +39,6 @@ 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 0453019c4c..7662017a8c 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -22,6 +22,7 @@ #include "clockObject.h" #include "config_util.h" #include "throw_event.h" +#include "nativeWindowHandle.h" #include @@ -878,11 +879,11 @@ 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())) { - WinGraphicsPipe::WinHandle *win_handle = DCAST(WinGraphicsPipe::WinHandle, os_handle); + if (os_handle->is_of_type(NativeWindowHandle::WinHandle::get_class_type())) { + WinGraphicsPipe::WinHandle *win_handle = DCAST(NativeWindowHandle::WinHandle, os_handle); _hparent = win_handle->get_handle(); - } else if (os_handle->is_of_type(WindowHandle::IntHandle::get_class_type())) { - WindowHandle::IntHandle *int_handle = DCAST(WindowHandle::IntHandle, os_handle); + } else if (os_handle->is_of_type(NativeWindowHandle::IntHandle::get_class_type())) { + WindowHandle::IntHandle *int_handle = DCAST(NativeWindowHandle::IntHandle, os_handle); _hparent = (HWND)int_handle->get_handle(); } } diff --git a/panda/src/x11display/config_x11display.cxx b/panda/src/x11display/config_x11display.cxx index 4264b2531a..b89f2d68db 100644 --- a/panda/src/x11display/config_x11display.cxx +++ b/panda/src/x11display/config_x11display.cxx @@ -78,6 +78,5 @@ init_libx11display() { initialized = true; x11GraphicsPipe::init_type(); - x11GraphicsPipe::x11Handle::init_type(); x11GraphicsWindow::init_type(); } diff --git a/panda/src/x11display/x11GraphicsPipe.I b/panda/src/x11display/x11GraphicsPipe.I index 62ee8f5d1e..1929746c14 100644 --- a/panda/src/x11display/x11GraphicsPipe.I +++ b/panda/src/x11display/x11GraphicsPipe.I @@ -70,22 +70,3 @@ get_hidden_cursor() { } return _hidden_cursor; } - -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::x11Handle::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE x11GraphicsPipe::x11Handle:: -x11Handle(Window handle) : _handle(handle) { -} - -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::x11Handle::get_handle -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Window x11GraphicsPipe::x11Handle:: -get_handle() const { - return _handle; -} diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index 397fc9d9d0..1e91fadaef 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -18,7 +18,6 @@ #include "frameBufferProperties.h" TypeHandle x11GraphicsPipe::_type_handle; -TypeHandle x11GraphicsPipe::x11Handle::_type_handle; bool x11GraphicsPipe::_error_handlers_installed = false; x11GraphicsPipe::ErrorHandlerFunc *x11GraphicsPipe::_prev_error_handler; @@ -132,40 +131,6 @@ x11GraphicsPipe:: } } -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::make_window_handle -// Access: Public -// Description: Constructs a new WindowHandle object that -// encapsulates a window with the indicated Window -// handle. -//////////////////////////////////////////////////////////////////// -WindowHandle *x11GraphicsPipe:: -make_window_handle(Window window) { - return new WindowHandle(new x11Handle(window)); -} - -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::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 *x11GraphicsPipe:: -make_int_window_handle(size_t window) { - return make_window_handle((Window)window); -} - //////////////////////////////////////////////////////////////////// // Function: x11GraphicsPipe::get_preferred_window_thread // Access: Public, Virtual @@ -289,26 +254,3 @@ io_error_handler(Display *display) { // anyway. Sigh. Very poor design on X's part. return 0; } - -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::x11Handle::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 x11GraphicsPipe::x11Handle:: -format_string_handle(ostream &out) const { - out << (size_t)_handle; -} - -//////////////////////////////////////////////////////////////////// -// Function: x11GraphicsPipe::x11Handle::output -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void x11GraphicsPipe::x11Handle:: -output(ostream &out) const { - out << (void *)_handle; -} diff --git a/panda/src/x11display/x11GraphicsPipe.h b/panda/src/x11display/x11GraphicsPipe.h index 5fd9fb4173..1774d30a6b 100644 --- a/panda/src/x11display/x11GraphicsPipe.h +++ b/panda/src/x11display/x11GraphicsPipe.h @@ -44,40 +44,6 @@ public: INLINE Cursor get_hidden_cursor(); - WindowHandle *make_window_handle(Window window); - virtual WindowHandle *make_int_window_handle(size_t window); - -public: - // Wraps a WindowHandle type for X11. - class x11Handle : public WindowHandle::OSHandle { - PUBLISHED: - INLINE x11Handle(Window handle); - virtual void format_string_handle(ostream &out) const; - virtual void output(ostream &out) const; - - INLINE Window get_handle() const; - - private: - Window _handle; - - public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - OSHandle::init_type(); - register_type(_type_handle, "x11GraphicsPipe::x11Handle", - 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; - }; - public: virtual PreferredWindowThread get_preferred_window_thread() const;