Add wxNativeWindow allowing to easily embed native widgets in wx.

Implement the class for wxMSW, wxGTK and wxOSX/Cocoa, show it in the widgets
sample and add documentation for it.
This commit is contained in:
Vadim Zeitlin
2015-08-03 17:47:09 +02:00
parent ce95913319
commit 9bc3ab1ea7
24 changed files with 757 additions and 7 deletions

View File

@@ -12,11 +12,13 @@
#include "wx/toplevel.h"
// this symbol can be tested in the user code to see if the current wx port has
// support for creating wxNativeContainerWindow from native windows
// These symbols can be tested in the user code to see if the current wx port
// has support for creating wxNativeContainerWindow and wxNativeWindow from
// native windows.
//
// be optimistic by default, we undefine it below if we don't have it finally
// Be optimistic by default, we undefine them below if necessary.
#define wxHAS_NATIVE_CONTAINER_WINDOW
#define wxHAS_NATIVE_WINDOW
// we define the following typedefs for each of the platform supporting native
// windows wrapping:
@@ -28,16 +30,16 @@
// window, i.e. HWND/GdkNativeWindow/NSWindow (so it's the same as above for
// all platforms except GTK where we also can work with Window/XID)
//
// later we'll also have
//
// - wxNativeWindowHandle for child windows (which will be wrapped by
// wxNativeWindow<T> class), it is HWND/GtkWidget*/ControlRef
// - wxNativeWindowHandle for child windows, i.e. HWND/GtkWidget*/NSControl
#if defined(__WXMSW__)
#include "wx/msw/wrapwin.h"
typedef HWND wxNativeContainerWindowId;
typedef HWND wxNativeContainerWindowHandle;
typedef HWND wxNativeWindowHandle;
#elif defined(__WXGTK__)
#include <gtk/gtk.h>
// GdkNativeWindow is guint32 under GDK/X11 and gpointer under GDK/WIN32
#ifdef __UNIX__
typedef unsigned long wxNativeContainerWindowId;
@@ -45,11 +47,51 @@
typedef void *wxNativeContainerWindowId;
#endif
typedef GdkWindow *wxNativeContainerWindowHandle;
typedef GtkWidget *wxNativeWindowHandle;
#elif defined(__WXOSX_COCOA__)
typedef NSView *wxNativeWindowHandle;
// no support for using native TLWs yet
#undef wxHAS_NATIVE_CONTAINER_WINDOW
#else
// no support for using native windows under this platform yet
#undef wxHAS_NATIVE_CONTAINER_WINDOW
#undef wxHAS_NATIVE_WINDOW
#endif
#ifdef wxHAS_NATIVE_WINDOW
// ----------------------------------------------------------------------------
// wxNativeWindow: for using native windows inside wxWidgets windows
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxNativeWindow : public wxWindow
{
public:
// Default ctor, Create() must be called later to really create the window.
wxNativeWindow() { }
// Create a window from an existing native window handle.
//
// Notice that this ctor doesn't take the usual pos and size parameters,
// they're taken from the window handle itself.
//
// Use GetHandle() to check if the creation was successful, it will return
// 0 if the handle was invalid.
wxNativeWindow(wxWindow* parent, wxWindowID winid, wxNativeWindowHandle handle)
{
Create(parent, winid, handle);
}
// Same as non-default ctor, but with a return code.
bool Create(wxWindow* parent, wxWindowID winid, wxNativeWindowHandle handle);
private:
wxDECLARE_NO_COPY_CLASS(wxNativeWindow);
};
#endif // wxHAS_NATIVE_WINDOW
#ifdef wxHAS_NATIVE_CONTAINER_WINDOW
// ----------------------------------------------------------------------------