+ if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
+
+ GdkBitmap *new_mask = (GdkBitmap*) NULL;
+
+ if (useMask && mask)
+ {
+ if (!m_currentClippingRegion.IsNull())
+ {
+ GdkColor col;
+ new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 );
+ GdkGC *gc = gdk_gc_new( new_mask );
+ col.pixel = 0;
+ gdk_gc_set_foreground( gc, &col );
+ gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
+ col.pixel = 0;
+ gdk_gc_set_background( gc, &col );
+ col.pixel = 1;
+ gdk_gc_set_foreground( gc, &col );
+ gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_origin( gc, -xx, -yy );
+ gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
+ gdk_gc_set_stipple( gc, mask );
+ gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
+ gdk_gc_unref( gc );
+ }
+
+ if (is_mono)
+ {
+ if (new_mask)
+ gdk_gc_set_clip_mask( m_textGC, new_mask );
+ else
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, xx, yy );
+ }
+ else
+ {
+ if (new_mask)
+ gdk_gc_set_clip_mask( m_penGC, new_mask );
+ else
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, xx, yy );
+ }
+ }
+
+ // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ // drawing a mono-bitmap (XBitmap) we use the current text GC
+ if (is_mono)
+ {
+ GdkPixmap *bitmap2 = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, -1 );
+ GdkGC *gc = gdk_gc_new( bitmap2 );
+ gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
+ gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
+ gdk_wx_draw_bitmap( bitmap2, gc, use_bitmap.GetBitmap(), 0, 0, 0, 0, -1, -1 );
+
+ gdk_draw_drawable( m_window, m_textGC, bitmap2, 0, 0, xx, yy, -1, -1 );
+
+ gdk_bitmap_unref( bitmap2 );
+ gdk_gc_unref( gc );
+ }
+ else
+ {
+#if GTK_CHECK_VERSION(2,2,0)
+ if (!gtk_check_version(2,2,0) && use_bitmap.HasPixbuf())
+ {
+ gdk_draw_pixbuf(m_window, m_penGC,
+ use_bitmap.GetPixbuf(),
+ 0, 0, xx, yy, -1, -1,
+ GDK_RGB_DITHER_NORMAL, xx, yy);
+ }
+ else
+#endif
+ {
+ gdk_draw_pixmap(m_window, m_penGC,
+ use_bitmap.GetPixmap(),
+ 0, 0, xx, yy, -1, -1);
+ }
+ }
+
+ // remove mask again if any
+ if (useMask && mask)
+ {
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
+ }
+ }
+
+ if (new_mask)
+ gdk_bitmap_unref( new_mask );
+}
+
+bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
+ wxCoord width, wxCoord height,
+ wxDC *source,
+ wxCoord xsrc, wxCoord ysrc,
+ int logical_func,
+ bool useMask,
+ wxCoord xsrcMask, wxCoord ysrcMask )
+{
+ wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
+
+ wxCHECK_MSG( source, false, wxT("invalid source dc") );
+
+ if (!m_window) return false;
+
+ // transform the source DC coords to the device ones
+ xsrc = source->XLOG2DEV(xsrc);
+ ysrc = source->YLOG2DEV(ysrc);
+
+ wxClientDC *srcDC = (wxClientDC*)source;
+ wxMemoryDC *memDC = (wxMemoryDC*)source;
+
+ bool use_bitmap_method = false;
+ bool is_mono = false;
+
+ if (xsrcMask == -1 && ysrcMask == -1)
+ {
+ xsrcMask = xsrc;
+ ysrcMask = ysrc;
+ }
+
+ if (srcDC->m_isMemDC)
+ {
+ if (!memDC->m_selected.Ok()) return false;
+
+ is_mono = (memDC->m_selected.GetDepth() == 1);
+
+ // we use the "XCopyArea" way to copy a memory dc into
+ // a different window if the memory dc BOTH
+ // a) doesn't have any mask or its mask isn't used
+ // b) it is clipped
+ // c) is not 1-bit
+
+ if (useMask && (memDC->m_selected.GetMask()))
+ {
+ // we HAVE TO use the direct way for memory dcs
+ // that have mask since the XCopyArea doesn't know
+ // about masks
+ use_bitmap_method = true;
+ }
+ else if (is_mono)
+ {
+ // we HAVE TO use the direct way for memory dcs
+ // that are bitmaps because XCopyArea doesn't cope
+ // with different bit depths
+ use_bitmap_method = true;
+ }
+ else if ((xsrc == 0) && (ysrc == 0) &&
+ (width == memDC->m_selected.GetWidth()) &&
+ (height == memDC->m_selected.GetHeight()))
+ {
+ // we SHOULD use the direct way if all of the bitmap
+ // in the memory dc is copied in which case XCopyArea
+ // wouldn't be able able to boost performace by reducing
+ // the area to be scaled
+ use_bitmap_method = true;
+ }
+ else
+ {
+ use_bitmap_method = false;
+ }
+ }
+
+ CalcBoundingBox( xdest, ydest );
+ CalcBoundingBox( xdest + width, ydest + height );
+
+ // scale/translate size and position
+ wxCoord xx = XLOG2DEV(xdest);
+ wxCoord yy = YLOG2DEV(ydest);
+
+ wxCoord ww = XLOG2DEVREL(width);
+ wxCoord hh = YLOG2DEVREL(height);
+
+ // compare to current clipping region
+ if (!m_currentClippingRegion.IsNull())
+ {
+ wxRegion tmp( xx,yy,ww,hh );
+ tmp.Intersect( m_currentClippingRegion );
+ if (tmp.IsEmpty())
+ return true;
+ }
+
+ int old_logical_func = m_logicalFunction;
+ SetLogicalFunction( logical_func );
+
+ if (use_bitmap_method)
+ {
+ // scale/translate bitmap size
+ wxCoord bm_width = memDC->m_selected.GetWidth();
+ wxCoord bm_height = memDC->m_selected.GetHeight();
+
+ // Get clip coords for the bitmap. If we don't
+ // use wxBitmap::Rescale(), which can clip the
+ // bitmap, these are the same as the original
+ // coordinates
+ wxCoord cx = xx;
+ wxCoord cy = yy;
+ wxCoord cw = ww;
+ wxCoord ch = hh;
+
+ // interpret userscale of src too
+ double xsc,ysc;
+ memDC->GetUserScale(&xsc,&ysc);
+ bm_width = (int) (bm_width / xsc);
+ bm_height = (int) (bm_height / ysc);
+
+ wxCoord bm_ww = XLOG2DEVREL( bm_width );
+ wxCoord bm_hh = YLOG2DEVREL( bm_height );
+
+ // Scale bitmap if required
+ wxBitmap use_bitmap;
+ if ((memDC->m_selected.GetWidth()!= bm_ww) || ( memDC->m_selected.GetHeight()!= bm_hh))
+ {
+ // This indicates that the blitting code below will get
+ // a clipped bitmap and therefore needs to move the origin
+ // accordingly
+ wxRegion tmp( xx,yy,ww,hh );
+ tmp.Intersect( m_currentClippingRegion );
+ tmp.GetBox(cx,cy,cw,ch);
+
+ // Scale and clipped bitmap
+ use_bitmap = memDC->m_selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh);
+ }
+ else
+ {
+ // Don't scale bitmap
+ use_bitmap = memDC->m_selected;
+ }
+
+ // apply mask if any
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
+
+ GdkBitmap *new_mask = (GdkBitmap*) NULL;
+
+ if (useMask && mask)
+ {
+ if (!m_currentClippingRegion.IsNull())
+ {
+ GdkColor col;
+ new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 );
+ GdkGC *gc = gdk_gc_new( new_mask );
+ col.pixel = 0;
+ gdk_gc_set_foreground( gc, &col );
+ gdk_gc_set_ts_origin( gc, -xsrcMask, -ysrcMask);
+ gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
+ col.pixel = 0;
+ gdk_gc_set_background( gc, &col );
+ col.pixel = 1;
+ gdk_gc_set_foreground( gc, &col );
+ gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
+ // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
+ gdk_gc_set_clip_origin( gc, -cx, -cy );
+ gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
+ gdk_gc_set_stipple( gc, mask );
+ gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
+ gdk_gc_unref( gc );
+ }
+
+ if (is_mono)
+ {
+ if (new_mask)
+ {
+ gdk_gc_set_clip_mask( m_textGC, new_mask );
+ gdk_gc_set_clip_origin( m_textGC, cx, cy );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, cx-xsrcMask, cy-ysrcMask );
+ }
+ }
+ else
+ {
+ if (new_mask)
+ {
+ gdk_gc_set_clip_mask( m_penGC, new_mask );
+ gdk_gc_set_clip_origin( m_penGC, cx, cy );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, cx-xsrcMask, cy-ysrcMask );
+ }
+ }
+ }
+
+ // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ // drawing a mono-bitmap (XBitmap) we use the current text GC
+
+ if (is_mono)
+ {
+ GdkPixmap *bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, -1 );
+ GdkGC *gc = gdk_gc_new( bitmap );
+ gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
+ gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
+ gdk_wx_draw_bitmap( bitmap, gc, use_bitmap.GetBitmap(), 0, 0, 0, 0, -1, -1 );
+
+ gdk_draw_drawable( m_window, m_textGC, bitmap, xsrc, ysrc, cx, cy, cw, ch );
+
+ gdk_bitmap_unref( bitmap );
+ gdk_gc_unref( gc );
+ }
+ else
+ {
+ // was: gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch );
+ }
+
+ // remove mask again if any
+ if (useMask && mask)
+ {
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
+ }
+ }
+
+ if (new_mask)
+ gdk_bitmap_unref( new_mask );
+ }
+ else // use_bitmap_method
+ {
+ if ((width != ww) || (height != hh))
+ {
+ // get clip coords
+ wxRegion tmp( xx,yy,ww,hh );
+ tmp.Intersect( m_currentClippingRegion );
+ wxCoord cx,cy,cw,ch;
+ tmp.GetBox(cx,cy,cw,ch);
+
+ // rescale bitmap
+ wxBitmap bitmap = memDC->m_selected.Rescale( cx-xx, cy-yy, cw, ch, ww, hh );
+
+ // draw scaled bitmap
+ // was: gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
+ gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, cx, cy, -1, -1 );
+ }
+ else
+ {
+ // No scaling and not a memory dc with a mask either
+
+ // copy including child window contents
+ gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
+ gdk_window_copy_area( m_window, m_penGC, xx, yy,
+ srcDC->GetWindow(),
+ xsrc, ysrc, width, height );
+ gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
+ }
+ }
+
+ SetLogicalFunction( old_logical_func );
+
+ return true;
+}
+
+void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (!m_window) return;
+
+ if (text.empty()) return;
+
+ x = XLOG2DEV(x);
+ y = YLOG2DEV(y);
+
+ wxCHECK_RET( m_context, wxT("no Pango context") );
+ wxCHECK_RET( m_layout, wxT("no Pango layout") );
+ wxCHECK_RET( m_fontdesc, wxT("no Pango font description") );
+
+ bool underlined = m_font.Ok() && m_font.GetUnderlined();
+
+#if wxUSE_UNICODE
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
+#else
+ const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
+ if ( !wdata )
+ return;
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
+#endif
+ size_t datalen = strlen((const char*)data);
+ pango_layout_set_text( m_layout, (const char*) data, datalen);
+
+ if (underlined)
+ {
+ PangoAttrList *attrs = pango_attr_list_new();
+ PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+ a->start_index = 0;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+ pango_layout_set_attributes(m_layout, attrs);
+ pango_attr_list_unref(attrs);
+ }
+
+ int w,h;
+
+ if (fabs(m_scaleY - 1.0) > 0.00001)
+ {
+ // If there is a user or actually any scale applied to
+ // the device context, scale the font.
+
+ // scale font description
+ gint oldSize = pango_font_description_get_size( m_fontdesc );
+ double size = oldSize;
+ size = size * m_scaleY;
+ pango_font_description_set_size( m_fontdesc, (gint)size );
+
+ // actually apply scaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+
+ pango_layout_get_pixel_size( m_layout, &w, &h );
+ if ( m_backgroundMode == wxSOLID )
+ {
+ gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
+ gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
+ gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
+ }
+
+ // Draw layout.
+ gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
+
+ // reset unscaled size
+ pango_font_description_set_size( m_fontdesc, oldSize );
+
+ // actually apply unscaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+ }
+ else
+ {
+ pango_layout_get_pixel_size( m_layout, &w, &h );
+ if ( m_backgroundMode == wxSOLID )
+ {
+ gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
+ gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
+ gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
+ }
+ // Draw layout.
+ gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
+ }
+
+ if (underlined)
+ {
+ // undo underline attributes setting:
+ pango_layout_set_attributes(m_layout, NULL);
+ }
+
+ wxCoord width = w;
+ wxCoord height = h;
+
+ width = wxCoord(width / m_scaleX);
+ height = wxCoord(height / m_scaleY);
+ CalcBoundingBox (x + width, y + height);
+ CalcBoundingBox (x, y);
+}
+
+
+// TODO: There is an example of rotating text with GTK2 that would probably be
+// a better approach here:
+// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
+
+void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
+{
+ if ( wxIsNullDouble(angle) )