remove wxGraphicsContext dependency for transparent background support

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2012-02-11 19:39:23 +00:00
parent 400930d344
commit ac900e6ba5
2 changed files with 41 additions and 39 deletions

View File

@@ -361,6 +361,14 @@ static inline gint wx_gdk_window_get_width(GdkWindow* window)
} }
#define gdk_window_get_width wx_gdk_window_get_width #define gdk_window_get_width wx_gdk_window_get_width
#if GTK_CHECK_VERSION(2,10,0)
static inline void wx_gdk_cairo_set_source_window(cairo_t* cr, GdkWindow* window, gdouble x, gdouble y)
{
gdk_cairo_set_source_pixmap(cr, window, x, y);
}
#define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
#endif
#endif // !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) #endif // !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)

View File

@@ -48,11 +48,6 @@ using namespace wxGTKImpl;
#include <gdk/gdkkeysyms-compat.h> #include <gdk/gdkkeysyms-compat.h>
#endif #endif
#if wxUSE_GRAPHICS_CONTEXT
#include "wx/graphics.h"
#include "wx/scopedptr.h"
#endif // wxUSE_GRAPHICS_CONTEXT
// gdk_window_set_composited() is only supported since 2.12 // gdk_window_set_composited() is only supported since 2.12
#define wxGTK_VERSION_REQUIRED_FOR_COMPOSITING 2,12,0 #define wxGTK_VERSION_REQUIRED_FOR_COMPOSITING 2,12,0
#define wxGTK_HAS_COMPOSITING_SUPPORT GTK_CHECK_VERSION(2,12,0) #define wxGTK_HAS_COMPOSITING_SUPPORT GTK_CHECK_VERSION(2,12,0)
@@ -3703,7 +3698,9 @@ void wxWindowGTK::GtkSendPaintEvents()
m_updateRegion.Clear(); m_updateRegion.Clear();
return; return;
} }
#if wxGTK_HAS_COMPOSITING_SUPPORT
cairo_t* cr = NULL;
#endif
// Clip to paint region in wxClientDC // Clip to paint region in wxClientDC
m_clipPaintRegion = true; m_clipPaintRegion = true;
@@ -3735,23 +3732,26 @@ void wxWindowGTK::GtkSendPaintEvents()
switch ( GetBackgroundStyle() ) switch ( GetBackgroundStyle() )
{ {
#if wxUSE_GRAPHICS_CONTEXT
case wxBG_STYLE_TRANSPARENT: case wxBG_STYLE_TRANSPARENT:
#if wxGTK_HAS_COMPOSITING_SUPPORT
if (IsTransparentBackgroundSupported())
{ {
// Set a transparent background, so that overlaying in parent // Set a transparent background, so that overlaying in parent
// might indeed let see through where this child did not // might indeed let see through where this child did not
// explicitly paint. // explicitly paint.
// NB: it works also for top level windows (but this is the // NB: it works also for top level windows (but this is the
// windows manager which then does the compositing job) // windows manager which then does the compositing job)
wxScopedPtr<wxGraphicsContext> gc (wxGraphicsContext::Create( this )); cr = gdk_cairo_create(m_wxwindow->window);
cairo_t *cairo_context = (cairo_t *)gc->GetNativeContext(); gdk_cairo_region(cr, m_nativeUpdateRegion.GetRegion());
cairo_clip(cr);
gc->Clip (m_nativeUpdateRegion); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
cairo_set_operator (cairo_context, CAIRO_OPERATOR_CLEAR); cairo_paint(cr);
cairo_paint (cairo_context); cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
break; cairo_surface_flush(cairo_get_target(cr));
} }
#endif // wxUSE_GRAPHICS_CONTEXT #endif // wxGTK_HAS_COMPOSITING_SUPPORT
break;
case wxBG_STYLE_ERASE: case wxBG_STYLE_ERASE:
{ {
@@ -3829,11 +3829,9 @@ void wxWindowGTK::GtkSendPaintEvents()
paint_event.SetEventObject( this ); paint_event.SetEventObject( this );
HandleWindowEvent( paint_event ); HandleWindowEvent( paint_event );
#if wxUSE_GRAPHICS_CONTEXT #if wxGTK_HAS_COMPOSITING_SUPPORT
if (IsTransparentBackgroundSupported())
{ // now composite children which need it { // now composite children which need it
wxScopedPtr<wxGraphicsContext> gc (wxGraphicsContext::Create( this ));
cairo_t *cairo_context = (cairo_t *)gc->GetNativeContext();
// Overlay all our composite children on top of the painted area // Overlay all our composite children on top of the painted area
wxWindowList::compatibility_iterator node; wxWindowList::compatibility_iterator node;
for ( node = m_children.GetFirst(); node ; node = node->GetNext() ) for ( node = m_children.GetFirst(); node ; node = node->GetNext() )
@@ -3841,26 +3839,28 @@ void wxWindowGTK::GtkSendPaintEvents()
wxWindow *compositeChild = node->GetData(); wxWindow *compositeChild = node->GetData();
if (compositeChild->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT) if (compositeChild->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT)
{ {
if (cr == NULL)
{
cr = gdk_cairo_create(m_wxwindow->window);
gdk_cairo_region(cr, m_nativeUpdateRegion.GetRegion());
cairo_clip(cr);
}
GtkWidget *child = compositeChild->m_wxwindow; GtkWidget *child = compositeChild->m_wxwindow;
GtkAllocation alloc;
gtk_widget_get_allocation(child, &alloc);
// The source data is the (composited) child // The source data is the (composited) child
gdk_cairo_set_source_pixmap (cairo_context, child->window, gdk_cairo_set_source_window(
child->allocation.x, cr, gtk_widget_get_window(child), alloc.x, alloc.y);
child->allocation.y);
// Draw no more than our expose event intersects our child cairo_paint(cr);
gc->Clip (m_nativeUpdateRegion);
gc->Clip (child->allocation.x, child->allocation.y,
child->allocation.width, child->allocation.height);
cairo_set_operator (cairo_context, CAIRO_OPERATOR_OVER);
cairo_paint (cairo_context);
gc->ResetClip ();
} }
} }
if (cr)
cairo_destroy(cr);
} }
#endif // wxUSE_GRAPHICS_CONTEXT #endif // wxGTK_HAS_COMPOSITING_SUPPORT
m_clipPaintRegion = false; m_clipPaintRegion = false;
@@ -4110,7 +4110,7 @@ bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style)
bool wxWindowGTK::IsTransparentBackgroundSupported(wxString* reason) const bool wxWindowGTK::IsTransparentBackgroundSupported(wxString* reason) const
{ {
#if wxGTK_HAS_COMPOSITING_SUPPORT && wxUSE_GRAPHICS_CONTEXT #if wxGTK_HAS_COMPOSITING_SUPPORT
if (gtk_check_version(wxGTK_VERSION_REQUIRED_FOR_COMPOSITING) != NULL) if (gtk_check_version(wxGTK_VERSION_REQUIRED_FOR_COMPOSITING) != NULL)
{ {
if (reason) if (reason)
@@ -4140,18 +4140,12 @@ bool wxWindowGTK::IsTransparentBackgroundSupported(wxString* reason) const
} }
return true; return true;
#elif !wxGTK_HAS_COMPOSITING_SUPPORT #else
if (reason) if (reason)
{ {
*reason = _("This program was compiled with a too old version of GTK+, " *reason = _("This program was compiled with a too old version of GTK+, "
"please rebuild with GTK+ 2.12 or newer."); "please rebuild with GTK+ 2.12 or newer.");
} }
#elif !wxUSE_GRAPHICS_CONTEXT
if (reason)
{
*reason = _("wxUSE_GRAPHICS_CONTEXT required for compositing window, "
"please rebuild wxWidgets with support for it.");
}
#endif // wxGTK_HAS_COMPOSITING_SUPPORT/!wxGTK_HAS_COMPOSITING_SUPPORT #endif // wxGTK_HAS_COMPOSITING_SUPPORT/!wxGTK_HAS_COMPOSITING_SUPPORT
return false; return false;