nativewin.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_NATIVEWIN_H_
  10. #define _WX_NATIVEWIN_H_
  11. #include "wx/toplevel.h"
  12. // this symbol can be tested in the user code to see if the current wx port has
  13. // support for creating wxNativeContainerWindow from native windows
  14. //
  15. // be optimistic by default, we undefine it below if we don't have it finally
  16. #define wxHAS_NATIVE_CONTAINER_WINDOW
  17. // we define the following typedefs for each of the platform supporting native
  18. // windows wrapping:
  19. //
  20. // - wxNativeContainerWindowHandle is the toolkit-level handle of the native
  21. // window, i.e. HWND/GdkWindow*/NSWindow
  22. //
  23. // - wxNativeContainerWindowId is the lowest level identifier of the native
  24. // window, i.e. HWND/GdkNativeWindow/NSWindow (so it's the same as above for
  25. // all platforms except GTK where we also can work with Window/XID)
  26. //
  27. // later we'll also have
  28. //
  29. // - wxNativeWindowHandle for child windows (which will be wrapped by
  30. // wxNativeWindow<T> class), it is HWND/GtkWidget*/ControlRef
  31. #if defined(__WXMSW__)
  32. #include "wx/msw/wrapwin.h"
  33. typedef HWND wxNativeContainerWindowId;
  34. typedef HWND wxNativeContainerWindowHandle;
  35. #elif defined(__WXGTK__)
  36. // GdkNativeWindow is guint32 under GDK/X11 and gpointer under GDK/WIN32
  37. #ifdef __UNIX__
  38. typedef unsigned long wxNativeContainerWindowId;
  39. #else
  40. typedef void *wxNativeContainerWindowId;
  41. #endif
  42. typedef GdkWindow *wxNativeContainerWindowHandle;
  43. #else
  44. // no support for using native windows under this platform yet
  45. #undef wxHAS_NATIVE_CONTAINER_WINDOW
  46. #endif
  47. #ifdef wxHAS_NATIVE_CONTAINER_WINDOW
  48. // ----------------------------------------------------------------------------
  49. // wxNativeContainerWindow: can be used for creating other wxWindows inside it
  50. // ----------------------------------------------------------------------------
  51. class WXDLLIMPEXP_CORE wxNativeContainerWindow : public wxTopLevelWindow
  52. {
  53. public:
  54. // default ctor, call Create() later
  55. wxNativeContainerWindow() { }
  56. // create a window from an existing native window handle
  57. //
  58. // use GetHandle() to check if the creation was successful, it will return
  59. // 0 if the handle was invalid
  60. wxNativeContainerWindow(wxNativeContainerWindowHandle handle)
  61. {
  62. Create(handle);
  63. }
  64. // same as ctor above but with a return code
  65. bool Create(wxNativeContainerWindowHandle handle);
  66. #if defined(__WXGTK__)
  67. // this is a convenient ctor for wxGTK applications which can also create
  68. // the objects of this class from the really native window handles and not
  69. // only the GdkWindow objects
  70. //
  71. // wxNativeContainerWindowId is Window (i.e. an XID, i.e. an int) under X11
  72. // (when GDK_WINDOWING_X11 is defined) or HWND under Win32
  73. wxNativeContainerWindow(wxNativeContainerWindowId winid) { Create(winid); }
  74. bool Create(wxNativeContainerWindowId winid);
  75. #endif // wxGTK
  76. // unlike for the normal windows, dtor will not destroy the native window
  77. // as it normally doesn't belong to us
  78. virtual ~wxNativeContainerWindow();
  79. // provide (trivial) implementation of the base class pure virtuals
  80. virtual void SetTitle(const wxString& WXUNUSED(title))
  81. {
  82. wxFAIL_MSG( "not implemented for native windows" );
  83. }
  84. virtual wxString GetTitle() const
  85. {
  86. wxFAIL_MSG( "not implemented for native windows" );
  87. return wxString();
  88. }
  89. virtual void Maximize(bool WXUNUSED(maximize) = true)
  90. {
  91. wxFAIL_MSG( "not implemented for native windows" );
  92. }
  93. virtual bool IsMaximized() const
  94. {
  95. wxFAIL_MSG( "not implemented for native windows" );
  96. return false;
  97. }
  98. virtual void Iconize(bool WXUNUSED(iconize) = true)
  99. {
  100. wxFAIL_MSG( "not implemented for native windows" );
  101. }
  102. virtual bool IsIconized() const
  103. {
  104. // this is called by wxGTK implementation so don't assert
  105. return false;
  106. }
  107. virtual void Restore()
  108. {
  109. wxFAIL_MSG( "not implemented for native windows" );
  110. }
  111. virtual bool ShowFullScreen(bool WXUNUSED(show),
  112. long WXUNUSED(style) = wxFULLSCREEN_ALL)
  113. {
  114. wxFAIL_MSG( "not implemented for native windows" );
  115. return false;
  116. }
  117. virtual bool IsFullScreen() const
  118. {
  119. wxFAIL_MSG( "not implemented for native windows" );
  120. return false;
  121. }
  122. #ifdef __WXMSW__
  123. virtual bool IsShown() const;
  124. #endif // __WXMSW__
  125. // this is an implementation detail: called when the native window is
  126. // destroyed by an outside agency; deletes the C++ object too but can in
  127. // principle be overridden to something else (knowing that the window
  128. // handle of this object and all of its children is invalid any more)
  129. virtual void OnNativeDestroyed();
  130. protected:
  131. #ifdef __WXMSW__
  132. virtual WXLRESULT
  133. MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  134. #endif // __WXMSW__
  135. private:
  136. wxDECLARE_NO_COPY_CLASS(wxNativeContainerWindow);
  137. };
  138. #endif // wxHAS_NATIVE_CONTAINER_WINDOW
  139. #endif // _WX_NATIVEWIN_H_