Panda3D
nativeWindowHandle.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file nativeWindowHandle.h
10  * @author drose
11  * @date 2009-09-30
12  */
13 
14 #ifndef NATIVEWINDOWHANDLE_H
15 #define NATIVEWINDOWHANDLE_H
16 
17 #include "pandabase.h"
18 
19 #include "windowHandle.h"
20 #include "get_x11.h"
21 
22 #ifdef WIN32
23 #ifndef WIN32_LEAN_AND_MEAN
24 #define WIN32_LEAN_AND_MEAN 1
25 #endif
26 #include <windows.h>
27 #endif
28 
29 /**
30  * This subclass of WindowHandle exists to allow simple creation of a
31  * WindowHandle of the appropriate type to the current OS.
32  *
33  * This class exists for name scoping only. Don't use the constructor
34  * directly; use one of the make_* methods.
35  */
36 class EXPCL_PANDA_DISPLAY NativeWindowHandle final : public WindowHandle {
37 private:
38  INLINE NativeWindowHandle();
39  INLINE NativeWindowHandle(const NativeWindowHandle &copy);
40 
41 PUBLISHED:
42  static PT(WindowHandle) make_int(size_t window);
43  static PT(WindowHandle) make_subprocess(const Filename &filename);
44 
45 public:
46 #if defined(HAVE_X11) && !defined(CPPPARSER)
47  static PT(WindowHandle) make_x11(X11_Window window);
48 #endif // HAVE_X11
49 
50 #if defined(WIN32) && !defined(CPPPARSER)
51  static PT(WindowHandle) make_win(HWND window);
52 #endif // WIN32
53 
54 public:
55  class EXPCL_PANDA_DISPLAY IntHandle : public OSHandle {
56  public:
57  INLINE IntHandle(size_t handle);
58  virtual size_t get_int_handle() const;
59  virtual void output(std::ostream &out) const;
60 
61  INLINE size_t get_handle() const;
62 
63  private:
64  size_t _handle;
65 
66  public:
67  static TypeHandle get_class_type() {
68  return _type_handle;
69  }
70  static void init_type() {
71  OSHandle::init_type();
72  register_type(_type_handle, "NativeWindowHandle::IntHandle",
73  OSHandle::get_class_type());
74  }
75  virtual TypeHandle get_type() const {
76  return get_class_type();
77  }
78  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
79 
80  private:
81  static TypeHandle _type_handle;
82  };
83 
84  class EXPCL_PANDA_DISPLAY SubprocessHandle : public OSHandle {
85  public:
86  INLINE SubprocessHandle(const Filename &filename);
87  virtual void output(std::ostream &out) const;
88 
89  INLINE const Filename &get_filename() const;
90 
91  private:
92  Filename _filename;
93 
94  public:
95  static TypeHandle get_class_type() {
96  return _type_handle;
97  }
98  static void init_type() {
99  OSHandle::init_type();
100  register_type(_type_handle, "NativeWindowHandle::SubprocessHandle",
101  OSHandle::get_class_type());
102  }
103  virtual TypeHandle get_type() const {
104  return get_class_type();
105  }
106  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
107 
108  private:
109  static TypeHandle _type_handle;
110  };
111 
112 #if defined(HAVE_X11) && !defined(CPPPARSER)
113  class EXPCL_PANDA_DISPLAY X11Handle : public OSHandle {
114  public:
115  INLINE X11Handle(X11_Window handle);
116  virtual size_t get_int_handle() const;
117  virtual void output(std::ostream &out) const;
118 
119  INLINE X11_Window get_handle() const;
120 
121  private:
122  X11_Window _handle;
123 
124  public:
125  static TypeHandle get_class_type() {
126  return _type_handle;
127  }
128  static void init_type() {
129  OSHandle::init_type();
130  register_type(_type_handle, "NativeWindowHandle::X11Handle",
131  OSHandle::get_class_type());
132  }
133  virtual TypeHandle get_type() const {
134  return get_class_type();
135  }
136  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
137 
138  private:
139  static TypeHandle _type_handle;
140  };
141 #endif // HAVE_X11
142 
143 
144 #if defined(WIN32) && !defined(CPPPARSER)
145  class EXPCL_PANDA_DISPLAY WinHandle : public OSHandle {
146  public:
147  INLINE WinHandle(HWND handle);
148  virtual size_t get_int_handle() const;
149  virtual void output(std::ostream &out) const;
150 
151  INLINE HWND get_handle() const;
152 
153  private:
154  HWND _handle;
155 
156  public:
157  static TypeHandle get_class_type() {
158  return _type_handle;
159  }
160  static void init_type() {
161  OSHandle::init_type();
162  register_type(_type_handle, "NativeWindowHandle::WinHandle",
163  OSHandle::get_class_type());
164  }
165  virtual TypeHandle get_type() const {
166  return get_class_type();
167  }
168  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
169 
170  private:
171  static TypeHandle _type_handle;
172  };
173 #endif // WIN32
174 
175 public:
176  static TypeHandle get_class_type() {
177  return _type_handle;
178  }
179  static void init_type() {
180  WindowHandle::init_type();
181  register_type(_type_handle, "NativeWindowHandle",
182  WindowHandle::get_class_type());
183 
184  IntHandle::init_type();
185  SubprocessHandle::init_type();
186 #if defined(HAVE_X11) && !defined(CPPPARSER)
187  X11Handle::init_type();
188 #endif
189 #if defined(WIN32) && !defined(CPPPARSER)
190  WinHandle::init_type();
191 #endif
192  }
193  virtual TypeHandle get_type() const {
194  return get_class_type();
195  }
196  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
197 
198 private:
199  static TypeHandle _type_handle;
200 };
201 
202 #include "nativeWindowHandle.I"
203 
204 #endif
This object represents a window on the desktop, not necessarily a Panda window.
Definition: windowHandle.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
This subclass of WindowHandle exists to allow simple creation of a WindowHandle of the appropriate ty...
virtual size_t get_int_handle() const
Returns the OS-specific handle converted to an integer, if this is possible for the particular repres...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.