1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/nativewin.h 3 // Purpose: classes allowing to wrap a native window handle 4 // Author: Vadim Zeitlin 5 // Created: 2008-03-05 6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org> 7 // Licence: wxWindows licence 8 /////////////////////////////////////////////////////////////////////////////// 9 10 #ifndef _WX_NATIVEWIN_H_ 11 #define _WX_NATIVEWIN_H_ 12 13 #include "wx/toplevel.h" 14 15 // These symbols can be tested in the user code to see if the current wx port 16 // has support for creating wxNativeContainerWindow and wxNativeWindow from 17 // native windows. 18 // 19 // Be optimistic by default, we undefine them below if necessary. 20 #define wxHAS_NATIVE_CONTAINER_WINDOW 21 #define wxHAS_NATIVE_WINDOW 22 23 // we define the following typedefs for each of the platform supporting native 24 // windows wrapping: 25 // 26 // - wxNativeContainerWindowHandle is the toolkit-level handle of the native 27 // window, i.e. HWND/GdkWindow*/NSWindow 28 // 29 // - wxNativeContainerWindowId is the lowest level identifier of the native 30 // window, i.e. HWND/GdkNativeWindow/NSWindow (so it's the same as above for 31 // all platforms except GTK where we also can work with Window/XID) 32 // 33 // - wxNativeWindowHandle for child windows, i.e. HWND/GtkWidget*/NSControl 34 #if defined(__WXMSW__) 35 #include "wx/msw/wrapwin.h" 36 37 typedef HWND wxNativeContainerWindowId; 38 typedef HWND wxNativeContainerWindowHandle; 39 typedef HWND wxNativeWindowHandle; 40 #elif defined(__WXGTK__) 41 // GdkNativeWindow is guint32 under GDK/X11 and gpointer under GDK/WIN32 42 #ifdef __UNIX__ 43 typedef unsigned long wxNativeContainerWindowId; 44 #else 45 typedef void *wxNativeContainerWindowId; 46 #endif 47 typedef GdkWindow *wxNativeContainerWindowHandle; 48 typedef GtkWidget *wxNativeWindowHandle; 49 #elif defined(__WXOSX_COCOA__) 50 typedef NSView *wxNativeWindowHandle; 51 52 // no support for using native TLWs yet 53 #undef wxHAS_NATIVE_CONTAINER_WINDOW 54 #else 55 // no support for using native windows under this platform yet 56 #undef wxHAS_NATIVE_CONTAINER_WINDOW 57 #undef wxHAS_NATIVE_WINDOW 58 #endif 59 60 #ifdef wxHAS_NATIVE_WINDOW 61 62 // ---------------------------------------------------------------------------- 63 // wxNativeWindow: for using native windows inside wxWidgets windows 64 // ---------------------------------------------------------------------------- 65 66 class WXDLLIMPEXP_CORE wxNativeWindow : public wxWindow 67 { 68 public: 69 // Default ctor, Create() must be called later to really create the window. wxNativeWindow()70 wxNativeWindow() 71 { 72 Init(); 73 } 74 75 // Create a window from an existing native window handle. 76 // 77 // Notice that this ctor doesn't take the usual pos and size parameters, 78 // they're taken from the window handle itself. 79 // 80 // Use GetHandle() to check if the creation was successful, it will return 81 // 0 if the handle was invalid. wxNativeWindow(wxWindow * parent,wxWindowID winid,wxNativeWindowHandle handle)82 wxNativeWindow(wxWindow* parent, wxWindowID winid, wxNativeWindowHandle handle) 83 { 84 Init(); 85 86 Create(parent, winid, handle); 87 } 88 89 // Same as non-default ctor, but with a return code. 90 bool Create(wxWindow* parent, wxWindowID winid, wxNativeWindowHandle handle); 91 92 // By default the native window with which this wxWindow is associated is 93 // owned by the user code and needs to be destroyed by it in a platform 94 // specific way, however this function can be called to let wxNativeWindow 95 // dtor take care of destroying the native window instead of having to do 96 // it from the user code. Disown()97 void Disown() 98 { 99 wxCHECK_RET( m_ownedByUser, wxS("Can't disown more than once") ); 100 101 m_ownedByUser = false; 102 103 DoDisown(); 104 } 105 106 #ifdef __WXMSW__ 107 // Prevent the native window, not owned by us, from being destroyed by the 108 // base class dtor, unless Disown() had been called. 109 virtual ~wxNativeWindow(); 110 #endif // __WXMSW__ 111 112 private: Init()113 void Init() 114 { 115 m_ownedByUser = true; 116 } 117 118 // This is implemented in platform-specific code. 119 void DoDisown(); 120 121 // If the native widget owned by the user code. 122 bool m_ownedByUser; 123 124 wxDECLARE_NO_COPY_CLASS(wxNativeWindow); 125 }; 126 127 #endif // wxHAS_NATIVE_WINDOW 128 129 #ifdef wxHAS_NATIVE_CONTAINER_WINDOW 130 131 // ---------------------------------------------------------------------------- 132 // wxNativeContainerWindow: can be used for creating other wxWindows inside it 133 // ---------------------------------------------------------------------------- 134 135 class WXDLLIMPEXP_CORE wxNativeContainerWindow : public wxTopLevelWindow 136 { 137 public: 138 // default ctor, call Create() later wxNativeContainerWindow()139 wxNativeContainerWindow() { } 140 141 // create a window from an existing native window handle 142 // 143 // use GetHandle() to check if the creation was successful, it will return 144 // 0 if the handle was invalid wxNativeContainerWindow(wxNativeContainerWindowHandle handle)145 wxNativeContainerWindow(wxNativeContainerWindowHandle handle) 146 { 147 Create(handle); 148 } 149 150 // same as ctor above but with a return code 151 bool Create(wxNativeContainerWindowHandle handle); 152 153 #if defined(__WXGTK__) 154 // this is a convenient ctor for wxGTK applications which can also create 155 // the objects of this class from the really native window handles and not 156 // only the GdkWindow objects 157 // 158 // wxNativeContainerWindowId is Window (i.e. an XID, i.e. an int) under X11 159 // (when GDK_WINDOWING_X11 is defined) or HWND under Win32 wxNativeContainerWindow(wxNativeContainerWindowId winid)160 wxNativeContainerWindow(wxNativeContainerWindowId winid) { Create(winid); } 161 162 bool Create(wxNativeContainerWindowId winid); 163 #endif // wxGTK 164 165 // unlike for the normal windows, dtor will not destroy the native window 166 // as it normally doesn't belong to us 167 virtual ~wxNativeContainerWindow(); 168 169 170 // provide (trivial) implementation of the base class pure virtuals SetTitle(const wxString & WXUNUSED (title))171 virtual void SetTitle(const wxString& WXUNUSED(title)) wxOVERRIDE 172 { 173 wxFAIL_MSG( "not implemented for native windows" ); 174 } 175 GetTitle()176 virtual wxString GetTitle() const wxOVERRIDE 177 { 178 wxFAIL_MSG( "not implemented for native windows" ); 179 180 return wxString(); 181 } 182 WXUNUSED(maximize)183 virtual void Maximize(bool WXUNUSED(maximize) = true) wxOVERRIDE 184 { 185 wxFAIL_MSG( "not implemented for native windows" ); 186 } 187 IsMaximized()188 virtual bool IsMaximized() const wxOVERRIDE 189 { 190 wxFAIL_MSG( "not implemented for native windows" ); 191 192 return false; 193 } 194 WXUNUSED(iconize)195 virtual void Iconize(bool WXUNUSED(iconize) = true) wxOVERRIDE 196 { 197 wxFAIL_MSG( "not implemented for native windows" ); 198 } 199 IsIconized()200 virtual bool IsIconized() const wxOVERRIDE 201 { 202 // this is called by wxGTK implementation so don't assert 203 return false; 204 } 205 Restore()206 virtual void Restore() wxOVERRIDE 207 { 208 wxFAIL_MSG( "not implemented for native windows" ); 209 } 210 WXUNUSED(show)211 virtual bool ShowFullScreen(bool WXUNUSED(show), 212 long WXUNUSED(style) = wxFULLSCREEN_ALL) wxOVERRIDE 213 { 214 wxFAIL_MSG( "not implemented for native windows" ); 215 216 return false; 217 } 218 IsFullScreen()219 virtual bool IsFullScreen() const wxOVERRIDE 220 { 221 wxFAIL_MSG( "not implemented for native windows" ); 222 223 return false; 224 } 225 226 #ifdef __WXMSW__ 227 virtual bool IsShown() const wxOVERRIDE; 228 #endif // __WXMSW__ 229 230 // this is an implementation detail: called when the native window is 231 // destroyed by an outside agency; deletes the C++ object too but can in 232 // principle be overridden to something else (knowing that the window 233 // handle of this object and all of its children is invalid any more) 234 virtual void OnNativeDestroyed(); 235 236 protected: 237 #ifdef __WXMSW__ 238 virtual WXLRESULT 239 MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; 240 #endif // __WXMSW__ 241 242 private: 243 wxDECLARE_NO_COPY_CLASS(wxNativeContainerWindow); 244 }; 245 246 #endif // wxHAS_NATIVE_CONTAINER_WINDOW 247 248 #endif // _WX_NATIVEWIN_H_ 249 250