nativeWindowHandle.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // Filename: nativeWindowHandle.h
  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. #ifndef NATIVEWINDOWHANDLE_H
  15. #define NATIVEWINDOWHANDLE_H
  16. #include "pandabase.h"
  17. #include "windowHandle.h"
  18. #ifdef HAVE_X11
  19. #include <X11/Xlib.h>
  20. #endif
  21. #ifdef WIN32
  22. #ifndef WIN32_LEAN_AND_MEAN
  23. #define WIN32_LEAN_AND_MEAN 1
  24. #endif
  25. #include <windows.h>
  26. #endif
  27. ////////////////////////////////////////////////////////////////////
  28. // Class : NativeWindowHandle
  29. // Description : This subclass of WindowHandle exists to allow simple
  30. // creation of a WindowHandle of the appropriate type to
  31. // the current OS.
  32. //
  33. // This class exists for name scoping only. Don't use
  34. // the constructor directly; use one of the make_*
  35. // methods.
  36. ////////////////////////////////////////////////////////////////////
  37. class EXPCL_PANDA_DISPLAY NativeWindowHandle : public WindowHandle {
  38. private:
  39. INLINE NativeWindowHandle();
  40. INLINE NativeWindowHandle(const NativeWindowHandle &copy);
  41. PUBLISHED:
  42. static PT(WindowHandle) make_int(size_t window);
  43. static PT(WindowHandle) make_subprocess(const Filename &filename);
  44. public:
  45. #if defined(HAVE_X11) && !defined(CPPPARSER)
  46. static PT(WindowHandle) make_x11(Window window);
  47. #endif // HAVE_X11
  48. #if defined(WIN32) && !defined(CPPPARSER)
  49. static PT(WindowHandle) make_win(HWND window);
  50. #endif // WIN32
  51. public:
  52. class EXPCL_PANDA_DISPLAY IntHandle : public OSHandle {
  53. public:
  54. INLINE IntHandle(size_t handle);
  55. virtual size_t get_int_handle() const;
  56. virtual void output(ostream &out) const;
  57. INLINE size_t get_handle() const;
  58. private:
  59. size_t _handle;
  60. public:
  61. static TypeHandle get_class_type() {
  62. return _type_handle;
  63. }
  64. static void init_type() {
  65. OSHandle::init_type();
  66. register_type(_type_handle, "NativeWindowHandle::IntHandle",
  67. OSHandle::get_class_type());
  68. }
  69. virtual TypeHandle get_type() const {
  70. return get_class_type();
  71. }
  72. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  73. private:
  74. static TypeHandle _type_handle;
  75. };
  76. class EXPCL_PANDA_DISPLAY SubprocessHandle : public OSHandle {
  77. public:
  78. INLINE SubprocessHandle(const Filename &filename);
  79. virtual void output(ostream &out) const;
  80. INLINE const Filename &get_filename() const;
  81. private:
  82. Filename _filename;
  83. public:
  84. static TypeHandle get_class_type() {
  85. return _type_handle;
  86. }
  87. static void init_type() {
  88. OSHandle::init_type();
  89. register_type(_type_handle, "NativeWindowHandle::SubprocessHandle",
  90. OSHandle::get_class_type());
  91. }
  92. virtual TypeHandle get_type() const {
  93. return get_class_type();
  94. }
  95. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  96. private:
  97. static TypeHandle _type_handle;
  98. };
  99. #if defined(HAVE_X11) && !defined(CPPPARSER)
  100. class EXPCL_PANDA_DISPLAY X11Handle : public OSHandle {
  101. public:
  102. INLINE X11Handle(Window handle);
  103. virtual size_t get_int_handle() const;
  104. virtual void output(ostream &out) const;
  105. INLINE Window get_handle() const;
  106. private:
  107. Window _handle;
  108. public:
  109. static TypeHandle get_class_type() {
  110. return _type_handle;
  111. }
  112. static void init_type() {
  113. OSHandle::init_type();
  114. register_type(_type_handle, "NativeWindowHandle::X11Handle",
  115. OSHandle::get_class_type());
  116. }
  117. virtual TypeHandle get_type() const {
  118. return get_class_type();
  119. }
  120. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  121. private:
  122. static TypeHandle _type_handle;
  123. };
  124. #endif // HAVE_X11
  125. #if defined(WIN32) && !defined(CPPPARSER)
  126. class EXPCL_PANDA_DISPLAY WinHandle : public OSHandle {
  127. public:
  128. INLINE WinHandle(HWND handle);
  129. virtual size_t get_int_handle() const;
  130. virtual void output(ostream &out) const;
  131. INLINE HWND get_handle() const;
  132. private:
  133. HWND _handle;
  134. public:
  135. static TypeHandle get_class_type() {
  136. return _type_handle;
  137. }
  138. static void init_type() {
  139. OSHandle::init_type();
  140. register_type(_type_handle, "NativeWindowHandle::WinHandle",
  141. OSHandle::get_class_type());
  142. }
  143. virtual TypeHandle get_type() const {
  144. return get_class_type();
  145. }
  146. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  147. private:
  148. static TypeHandle _type_handle;
  149. };
  150. #endif // WIN32
  151. public:
  152. static TypeHandle get_class_type() {
  153. return _type_handle;
  154. }
  155. static void init_type() {
  156. WindowHandle::init_type();
  157. register_type(_type_handle, "NativeWindowHandle",
  158. WindowHandle::get_class_type());
  159. IntHandle::init_type();
  160. SubprocessHandle::init_type();
  161. #if defined(HAVE_X11) && !defined(CPPPARSER)
  162. X11Handle::init_type();
  163. #endif
  164. #if defined(WIN32) && !defined(CPPPARSER)
  165. WinHandle::init_type();
  166. #endif
  167. }
  168. virtual TypeHandle get_type() const {
  169. return get_class_type();
  170. }
  171. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  172. private:
  173. static TypeHandle _type_handle;
  174. };
  175. #include "nativeWindowHandle.I"
  176. #endif