]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement SetShape() for wxPopupWindow in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Oct 2011 12:45:56 +0000 (12:45 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Oct 2011 12:45:56 +0000 (12:45 +0000)
Move SetShape() implementation from wxTopLevelWindow to wxNonOwnedWindow so
that wxPopupWindow, which also inherits from the latter, could use it as well.

This makes it possible to have popup windows with irregular shapes in wxGTK as
well as in wxMSW and wxOSX.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

Makefile.in
build/bakefiles/files.bkl
include/wx/gtk/nonownedwnd.h [new file with mode: 0644]
include/wx/gtk/toplevel.h
include/wx/nonownedwnd.h
src/gtk/nonownedwnd.cpp [new file with mode: 0644]
src/gtk/toplevel.cpp

index 6c5ce7a4030d146fff733181b08ab49dd4db7f7f..fb031f6d7cb4b328222b6655ab6b6062f374e9de 100644 (file)
@@ -2607,6 +2607,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_LOWLEVEL_HDR =  \
        wx/gtk/font.h \
        wx/gtk/filehistory.h \
        wx/gtk/minifram.h \
+       wx/gtk/nonownedwnd.h \
        wx/gtk/pen.h \
        wx/gtk/popupwin.h \
        wx/gtk/private/win_gtk.h \
@@ -5042,6 +5043,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS =  \
        monodll_gtk_font.o \
        monodll_gtk_sockgtk.o \
        monodll_gtk_minifram.o \
+       monodll_gtk_nonownedwnd.o \
        monodll_gtk_pen.o \
        monodll_gtk_popupwin.o \
        monodll_private.o \
@@ -5924,6 +5926,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_1 =  \
        monodll_gtk_font.o \
        monodll_gtk_sockgtk.o \
        monodll_gtk_minifram.o \
+       monodll_gtk_nonownedwnd.o \
        monodll_gtk_pen.o \
        monodll_gtk_popupwin.o \
        monodll_private.o \
@@ -6994,6 +6997,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_2 =  \
        monolib_gtk_font.o \
        monolib_gtk_sockgtk.o \
        monolib_gtk_minifram.o \
+       monolib_gtk_nonownedwnd.o \
        monolib_gtk_pen.o \
        monolib_gtk_popupwin.o \
        monolib_private.o \
@@ -7876,6 +7880,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_3 =  \
        monolib_gtk_font.o \
        monolib_gtk_sockgtk.o \
        monolib_gtk_minifram.o \
+       monolib_gtk_nonownedwnd.o \
        monolib_gtk_pen.o \
        monolib_gtk_popupwin.o \
        monolib_private.o \
@@ -9125,6 +9130,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_4 =  \
        coredll_gtk_font.o \
        coredll_gtk_sockgtk.o \
        coredll_gtk_minifram.o \
+       coredll_gtk_nonownedwnd.o \
        coredll_gtk_pen.o \
        coredll_gtk_popupwin.o \
        coredll_private.o \
@@ -10007,6 +10013,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_5 =  \
        coredll_gtk_font.o \
        coredll_gtk_sockgtk.o \
        coredll_gtk_minifram.o \
+       coredll_gtk_nonownedwnd.o \
        coredll_gtk_pen.o \
        coredll_gtk_popupwin.o \
        coredll_private.o \
@@ -10717,6 +10724,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_6 =  \
        corelib_gtk_font.o \
        corelib_gtk_sockgtk.o \
        corelib_gtk_minifram.o \
+       corelib_gtk_nonownedwnd.o \
        corelib_gtk_pen.o \
        corelib_gtk_popupwin.o \
        corelib_private.o \
@@ -11599,6 +11607,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_7 =  \
        corelib_gtk_font.o \
        corelib_gtk_sockgtk.o \
        corelib_gtk_minifram.o \
+       corelib_gtk_nonownedwnd.o \
        corelib_gtk_pen.o \
        corelib_gtk_popupwin.o \
        corelib_private.o \
@@ -18081,6 +18090,9 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monodll_gtk_minifram.o: $(srcdir)/src/gtk/minifram.cpp $(MONODLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/minifram.cpp
 
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monodll_gtk_nonownedwnd.o: $(srcdir)/src/gtk/nonownedwnd.cpp $(MONODLL_ODEP)
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/nonownedwnd.cpp
+
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monodll_gtk_pen.o: $(srcdir)/src/gtk/pen.cpp $(MONODLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/pen.cpp
 
@@ -23451,6 +23463,9 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monolib_gtk_minifram.o: $(srcdir)/src/gtk/minifram.cpp $(MONOLIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/minifram.cpp
 
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monolib_gtk_nonownedwnd.o: $(srcdir)/src/gtk/nonownedwnd.cpp $(MONOLIB_ODEP)
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/nonownedwnd.cpp
+
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monolib_gtk_pen.o: $(srcdir)/src/gtk/pen.cpp $(MONOLIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/pen.cpp
 
@@ -28980,6 +28995,9 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@coredll_gtk_minifram.o: $(srcdir)/src/gtk/minifram.cpp $(COREDLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/gtk/minifram.cpp
 
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@coredll_gtk_nonownedwnd.o: $(srcdir)/src/gtk/nonownedwnd.cpp $(COREDLL_ODEP)
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/gtk/nonownedwnd.cpp
+
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@coredll_gtk_pen.o: $(srcdir)/src/gtk/pen.cpp $(COREDLL_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/gtk/pen.cpp
 
@@ -32991,6 +33009,9 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@corelib_gtk_minifram.o: $(srcdir)/src/gtk/minifram.cpp $(CORELIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/gtk/minifram.cpp
 
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@corelib_gtk_nonownedwnd.o: $(srcdir)/src/gtk/nonownedwnd.cpp $(CORELIB_ODEP)
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/gtk/nonownedwnd.cpp
+
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@corelib_gtk_pen.o: $(srcdir)/src/gtk/pen.cpp $(CORELIB_ODEP)
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/gtk/pen.cpp
 
index 96b214b1bb7dd0726e6c76d1e172df7ef37faa4a..1e73c713048c83286d4e901f433f126976c2c1c9 100644 (file)
@@ -1094,6 +1094,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     src/gtk/font.cpp
     src/gtk/sockgtk.cpp
     src/gtk/minifram.cpp
+    src/gtk/nonownedwnd.cpp
     src/gtk/pen.cpp
     src/gtk/popupwin.cpp
     src/gtk/private.cpp
@@ -1131,6 +1132,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/gtk/font.h
     wx/gtk/filehistory.h
     wx/gtk/minifram.h
+    wx/gtk/nonownedwnd.h
     wx/gtk/pen.h
     wx/gtk/popupwin.h
     wx/gtk/private/win_gtk.h
diff --git a/include/wx/gtk/nonownedwnd.h b/include/wx/gtk/nonownedwnd.h
new file mode 100644 (file)
index 0000000..a722e27
--- /dev/null
@@ -0,0 +1,35 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/gtk/nonownedwnd.h
+// Purpose:     wxGTK-specific wxNonOwnedWindow declaration.
+// Author:      Vadim Zeitlin
+// Created:     2011-10-12
+// RCS-ID:      $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
+// Copyright:   (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_GTK_NONOWNEDWND_H_
+#define _WX_GTK_NONOWNEDWND_H_
+
+// ----------------------------------------------------------------------------
+// wxNonOwnedWindow contains code common to wx{Popup,TopLevel}Window in wxGTK.
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxNonOwnedWindow : public wxNonOwnedWindowBase
+{
+public:
+    wxNonOwnedWindow() { }
+
+    virtual bool SetShape(const wxRegion& region);
+
+    // Overridden to actually set the shape when the window becomes realized.
+    virtual void GTKHandleRealized();
+
+private:
+    // If valid, defines the custom shape of the window.
+    wxRegion m_shape;
+
+    wxDECLARE_NO_COPY_CLASS(wxNonOwnedWindow);
+};
+
+#endif // _WX_GTK_NONOWNEDWND_H_
index a84cf8a87e1a09ed0f3d9bc8bc5c65d347f9c71a..d7b19d6409bd1d0e4fd590cd31052192e3c814f1 100644 (file)
@@ -57,8 +57,6 @@ public:
     virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
     virtual bool IsFullScreen() const { return m_fsIsShowing; };
 
-    virtual bool SetShape(const wxRegion& region);
-
     virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
 
     virtual void SetWindowStyleFlag( long style );
@@ -113,9 +111,6 @@ public:
     // size of WM decorations
     wxSize m_decorSize;
 
-    // shape of the frame
-    wxRegion m_shape;
-
     // private gtk_timeout_add result for mimicing wxUSER_ATTENTION_INFO and
     // wxUSER_ATTENTION_ERROR difference, -2 for no hint, -1 for ERROR hint, rest for GtkTimeout handle.
     int m_urgency_hint;
index 80294197651be125bf688b5072b7f8ccc3bb079e..6f32d2304e92ef77b8deab5d89c2cf3b8d97d72c 100644 (file)
@@ -30,14 +30,15 @@ public:
 
 #if defined(__WXDFB__)
     #include "wx/dfb/nonownedwnd.h"
+#elif defined(__WXGTK__)
+    #include "wx/gtk/nonownedwnd.h"
 #elif defined(__WXMAC__)
     #include "wx/osx/nonownedwnd.h"
 #elif defined(__WXMSW__)
     #include "wx/msw/nonownedwnd.h"
 #else
     // No special class needed in other ports, they can derive both wxTLW and
-    // wxPopupWindow directly from wxWindow and don't implement SetShape() (at
-    // least at this level, wxGTK does do it in wxTLW).
+    // wxPopupWindow directly from wxWindow and don't implement SetShape().
     class wxNonOwnedWindow : public wxNonOwnedWindowBase
     {
     };
diff --git a/src/gtk/nonownedwnd.cpp b/src/gtk/nonownedwnd.cpp
new file mode 100644 (file)
index 0000000..20f0525
--- /dev/null
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        src/gtk/nonownedwnd.cpp
+// Purpose:     wxGTK implementation of wxNonOwnedWindow.
+// Author:      Vadim Zeitlin
+// Created:     2011-10-12
+// RCS-ID:      $Id: wxhead.cpp,v 1.11 2010-04-22 12:44:51 zeitlin Exp $
+// Copyright:   (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// for compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/string.h"
+#endif // WX_PRECOMP
+
+#include "wx/gtk/private.h"
+
+#include <gdk/gdk.h>
+
+namespace
+{
+
+// helper
+bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
+{
+    if (window)
+    {
+        if (region.IsEmpty())
+        {
+            gdk_window_shape_combine_mask(window, NULL, 0, 0);
+        }
+        else
+        {
+            gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0);
+            return true;
+        }
+    }
+    return false;
+}
+
+} // anonymous namespace
+
+
+// ============================================================================
+// wxNonOwnedWindow implementation
+// ============================================================================
+
+void wxNonOwnedWindow::GTKHandleRealized()
+{
+    wxNonOwnedWindowBase::GTKHandleRealized();
+
+    if (HasFlag(wxFRAME_SHAPED))
+        SetShape(m_shape);
+}
+
+bool wxNonOwnedWindow::SetShape(const wxRegion& region)
+{
+    wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
+                 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
+
+    if ( gtk_widget_get_realized(m_widget) )
+    {
+        if ( m_wxwindow )
+            do_shape_combine_region(gtk_widget_get_window(m_wxwindow), region);
+
+        return do_shape_combine_region(gtk_widget_get_window(m_widget), region);
+    }
+    else // not realized yet
+    {
+        // store the shape to set, it will be really set once we're realized
+        m_shape = region;
+
+        // we don't know if we're going to succeed or fail, be optimistic by
+        // default
+        return true;
+    }
+}
index eed18cf06c087a2d55c3787eb972f2426d4f0fdb..1e1c3bcc399313892ce7610e64fb6650b94801b6 100644 (file)
@@ -328,9 +328,6 @@ void wxTopLevelWindowGTK::GTKHandleRealized()
     const wxIconBundle& icons = GetIcons();
     if (icons.GetIconCount())
         SetIcons(icons);
-
-    if (HasFlag(wxFRAME_SHAPED))
-        SetShape(m_shape); // it will really set the window shape now
 }
 
 //-----------------------------------------------------------------------------
@@ -1321,48 +1318,6 @@ void wxTopLevelWindowGTK::RemoveGrab()
 }
 
 
-// helper
-static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
-{
-    if (window)
-    {
-        if (region.IsEmpty())
-        {
-            gdk_window_shape_combine_mask(window, NULL, 0, 0);
-        }
-        else
-        {
-            gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0);
-            return true;
-        }
-    }
-    return false;
-}
-
-
-bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
-{
-    wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
-                 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
-
-    if ( gtk_widget_get_realized(m_widget) )
-    {
-        if ( m_wxwindow )
-            do_shape_combine_region(gtk_widget_get_window(m_wxwindow), region);
-
-        return do_shape_combine_region(gtk_widget_get_window(m_widget), region);
-    }
-    else // not realized yet
-    {
-        // store the shape to set, it will be really set once we're realized
-        m_shape = region;
-
-        // we don't know if we're going to succeed or fail, be optimistic by
-        // default
-        return true;
-    }
-}
-
 bool wxTopLevelWindowGTK::IsActive()
 {
     return (this == (wxTopLevelWindowGTK*)g_activeFrame);