Panda3D
nativeWindowHandle.cxx
1 // Filename: nativeWindowHandle.cxx
2 // Created by: drose (30Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "nativeWindowHandle.h"
16 
17 TypeHandle NativeWindowHandle::_type_handle;
18 TypeHandle NativeWindowHandle::IntHandle::_type_handle;
19 TypeHandle NativeWindowHandle::SubprocessHandle::_type_handle;
20 
21 #if defined(HAVE_X11) && !defined(CPPPARSER)
22 TypeHandle NativeWindowHandle::X11Handle::_type_handle;
23 #endif
24 #if defined(WIN32) && !defined(CPPPARSER)
25 TypeHandle NativeWindowHandle::WinHandle::_type_handle;
26 #endif
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: NativeWindowHandle::make_int
30 // Access: Published, Static
31 // Description: Constructs a new WindowHandle with an int value,
32 // which is understood to be either an HWND or a Window,
33 // cast to int. This method exists for the convenience
34 // of Python, which likes to deal with ints; C++ code
35 // should use one of the more specific make_x11() or
36 // make_win32() methods instead.
37 ////////////////////////////////////////////////////////////////////
38 PT(WindowHandle) NativeWindowHandle::
39 make_int(size_t window) {
40  return new WindowHandle(new IntHandle(window));
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: NativeWindowHandle::make_subprocess
45 // Access: Published, Static
46 // Description: Constructs a new WindowHandle that references a
47 // SubprocessWindowBuffer read in another process, with
48 // the named pipe filename that it uses for
49 // communication.
50 //
51 // This is (at present, and maybe always) useful only on
52 // the OS X platform, where parenting child windows is
53 // particularly problematic.
54 ////////////////////////////////////////////////////////////////////
55 PT(WindowHandle) NativeWindowHandle::
56 make_subprocess(const Filename &filename) {
57  return new WindowHandle(new SubprocessHandle(filename));
58 }
59 
60 #if defined(HAVE_X11) && !defined(CPPPARSER)
61 ////////////////////////////////////////////////////////////////////
62 // Function: NativeWindowHandle::make_x11
63 // Access: Published, Static
64 // Description: Constructs a new WindowHandle that references an
65 // X11 window.
66 ////////////////////////////////////////////////////////////////////
67 PT(WindowHandle) NativeWindowHandle::
68 make_x11(X11_Window window) {
69  return new WindowHandle(new X11Handle(window));
70 }
71 #endif // HAVE_X11
72 
73 #if defined(WIN32) && !defined(CPPPARSER)
74 ////////////////////////////////////////////////////////////////////
75 // Function: NativeWindowHandle::make_win
76 // Access: Published, Static
77 // Description: Constructs a new WindowHandle that references a
78 // window on Windows.
79 ////////////////////////////////////////////////////////////////////
80 PT(WindowHandle) NativeWindowHandle::
81 make_win(HWND window) {
82  return new WindowHandle(new WinHandle(window));
83 }
84 #endif // WIN32
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: NativeWindowHandle::IntHandle::get_int_handle
88 // Access: Public, Virtual
89 // Description: Returns the OS-specific handle converted to an
90 // integer, if this is possible for the particular
91 // representation. Returns 0 if it is not.
92 ////////////////////////////////////////////////////////////////////
94 get_int_handle() const {
95  return _handle;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: NativeWindowHandle::IntHandle::output
100 // Access: Public
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 void NativeWindowHandle::IntHandle::
104 output(ostream &out) const {
105  out << "(" << _handle << ")";
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: NativeWindowHandle::SubprocessHandle::output
110 // Access: Public
111 // Description:
112 ////////////////////////////////////////////////////////////////////
113 void NativeWindowHandle::SubprocessHandle::
114 output(ostream &out) const {
115  out << "(" << _filename << ")";
116 }
117 
118 #if defined(HAVE_X11) && !defined(CPPPARSER)
119 ////////////////////////////////////////////////////////////////////
120 // Function: NativeWindowHandle::X11Handle::get_int_handle
121 // Access: Public, Virtual
122 // Description: Returns the OS-specific handle converted to an
123 // integer, if this is possible for the particular
124 // representation. Returns 0 if it is not.
125 ////////////////////////////////////////////////////////////////////
126 size_t NativeWindowHandle::X11Handle::
127 get_int_handle() const {
128  return (size_t)_handle;
129 }
130 #endif // HAVE_X11
131 
132 #if defined(HAVE_X11) && !defined(CPPPARSER)
133 ////////////////////////////////////////////////////////////////////
134 // Function: NativeWindowHandle::X11Handle::output
135 // Access: Public
136 // Description:
137 ////////////////////////////////////////////////////////////////////
138 void NativeWindowHandle::X11Handle::
139 output(ostream &out) const {
140  out << _handle;
141 }
142 #endif // HAVE_X11
143 
144 #if defined(WIN32) && !defined(CPPPARSER)
145 ////////////////////////////////////////////////////////////////////
146 // Function: NativeWindowHandle::WinHandle::get_int_handle
147 // Access: Public, Virtual
148 // Description: Returns the OS-specific handle converted to an
149 // integer, if this is possible for the particular
150 // representation. Returns 0 if it is not.
151 ////////////////////////////////////////////////////////////////////
152 size_t NativeWindowHandle::WinHandle::
153 get_int_handle() const {
154  return (size_t)_handle;
155 }
156 #endif // WIN32
157 
158 #if defined(WIN32) && !defined(CPPPARSER)
159 ////////////////////////////////////////////////////////////////////
160 // Function: NativeWindowHandle::WinHandle::output
161 // Access: Public
162 // Description:
163 ////////////////////////////////////////////////////////////////////
164 void NativeWindowHandle::WinHandle::
165 output(ostream &out) const {
166  out << _handle;
167 }
168 #endif // WIN32
This object represents a window on the desktop, not necessarily a Panda window.
Definition: windowHandle.h:40
virtual size_t get_int_handle() const
Returns the OS-specific handle converted to an integer, if this is possible for the particular repres...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85