Panda3D
windowHandle.h
1 // Filename: windowHandle.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 
15 #ifndef WINDOWHANDLE_H
16 #define WINDOWHANDLE_H
17 
18 #include "pandabase.h"
19 
20 #include "typedReferenceCount.h"
21 #include "pointerTo.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : WindowHandle
25 // Description : This object represents a window on the desktop, not
26 // necessarily a Panda window. This structure can be
27 // assigned to a WindowProperties to indicate a parent
28 // window.
29 //
30 // It also has callbacks so the Panda window can
31 // communicate with its parent window, which is
32 // particularly important when running embedded in a
33 // browser.
34 //
35 // To create a WindowHandle, you would usually call one
36 // of the NativeWindowHandle::make_*() methods,
37 // depending on the kind of native window handle object
38 // you already have.
39 ////////////////////////////////////////////////////////////////////
40 class EXPCL_PANDA_DISPLAY WindowHandle : public TypedReferenceCount {
41 PUBLISHED:
42  class OSHandle;
43 
44  INLINE WindowHandle(OSHandle *os_handle);
45  INLINE WindowHandle(const WindowHandle &copy);
46  virtual ~WindowHandle();
47 
48  INLINE OSHandle *get_os_handle() const;
49  INLINE void set_os_handle(OSHandle *os_handle);
50 
51  void send_windows_message(unsigned int msg, int wparam, int lparam);
52 
53  size_t get_int_handle() const;
54 
55  void output(ostream &out) const;
56 
57 public:
58  // Callbacks for communication with the parent window.
59  virtual void attach_child(WindowHandle *child);
60  virtual void detach_child(WindowHandle *child);
61 
62  virtual void request_keyboard_focus(WindowHandle *child);
63  virtual void receive_windows_message(unsigned int msg, int wparam, int lparam);
64 
65 PUBLISHED:
66  // This internal pointer within WindowHandle stores the actual
67  // OS-specific window handle type, whatever type that is. It is
68  // subclassed for each OS.
69  class EXPCL_PANDA_DISPLAY OSHandle : public TypedReferenceCount {
70  protected:
71  INLINE OSHandle();
72 
73  PUBLISHED:
74  virtual ~OSHandle();
75  virtual size_t get_int_handle() const;
76  virtual void output(ostream &out) const;
77 
78  public:
79  static TypeHandle get_class_type() {
80  return _type_handle;
81  }
82  static void init_type() {
83  TypedReferenceCount::init_type();
84  register_type(_type_handle, "WindowHandle::OSHandle",
85  TypedReferenceCount::get_class_type());
86  }
87  virtual TypeHandle get_type() const {
88  return get_class_type();
89  }
90  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
91 
92  private:
93  static TypeHandle _type_handle;
94  };
95 
96 protected:
97  PT(OSHandle) _os_handle;
98 
99  PT(WindowHandle) _keyboard_window;
100 
101 public:
102  static TypeHandle get_class_type() {
103  return _type_handle;
104  }
105  static void init_type() {
106  TypedReferenceCount::init_type();
107  register_type(_type_handle, "WindowHandle",
108  TypedReferenceCount::get_class_type());
109  }
110  virtual TypeHandle get_type() const {
111  return get_class_type();
112  }
113  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
114 
115 private:
116  static TypeHandle _type_handle;
117 };
118 
119 #include "windowHandle.I"
120 
121 INLINE ostream &operator << (ostream &out, const WindowHandle &handle) {
122  handle.output(out);
123  return out;
124 }
125 
126 INLINE ostream &operator << (ostream &out, const WindowHandle::OSHandle &handle) {
127  handle.output(out);
128  return out;
129 }
130 
131 #endif
This object represents a window on the desktop, not necessarily a Panda window.
Definition: windowHandle.h:40
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85