+ // CMB: adjust size if outline is drawn otherwise the result is
+ // 1 pixel too wide and high
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ {
+ ww--;
+ hh--;
+ }
+
+ if (m_gdkwindow)
+ {
+ // CMB: ensure dd is not larger than rectangle otherwise we
+ // get an hour glass shape
+ wxCoord dd = 2 * rr;
+ if (dd > ww) dd = ww;
+ if (dd > hh) dd = hh;
+ rr = dd / 2;
+
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ {
+ GdkGC* gc;
+ bool originChanged;
+ DrawingSetup(gc, originChanged);
+
+ gdk_draw_rectangle(m_gdkwindow, gc, true, xx+rr, yy, ww-dd+1, hh);
+ gdk_draw_rectangle(m_gdkwindow, gc, true, xx, yy+rr, ww, hh-dd+1);
+ gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, dd, dd, 90*64, 90*64);
+ gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy, dd, dd, 0, 90*64);
+ gdk_draw_arc(m_gdkwindow, gc, true, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64);
+ gdk_draw_arc(m_gdkwindow, gc, true, xx, yy+hh-dd, dd, dd, 180*64, 90*64);
+
+ if (originChanged)
+ gdk_gc_set_ts_origin(gc, 0, 0);
+ }
+
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ {
+ gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy, xx+ww-rr, yy );
+ gdk_draw_line( m_gdkwindow, m_penGC, xx+rr+1, yy+hh, xx+ww-rr, yy+hh );
+ gdk_draw_line( m_gdkwindow, m_penGC, xx, yy+rr+1, xx, yy+hh-rr );
+ gdk_draw_line( m_gdkwindow, m_penGC, xx+ww, yy+rr+1, xx+ww, yy+hh-rr );
+ gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
+ gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
+ gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
+ gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
+ }
+ }
+
+ // this ignores the radius
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+}
+
+void wxWindowDCImpl::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
+{
+ wxCHECK_RET( IsOk(), wxT("invalid window dc") );
+
+ wxCoord xx = XLOG2DEV(x);
+ wxCoord yy = YLOG2DEV(y);
+ wxCoord ww = m_signX * XLOG2DEVREL(width);
+ wxCoord hh = m_signY * YLOG2DEVREL(height);
+
+ // CMB: handle -ve width and/or height
+ if (ww < 0) { ww = -ww; xx = xx - ww; }
+ if (hh < 0) { hh = -hh; yy = yy - hh; }
+
+ if (m_gdkwindow)
+ {
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ {
+ GdkGC* gc;
+ bool originChanged;
+ DrawingSetup(gc, originChanged);
+
+ gdk_draw_arc(m_gdkwindow, gc, true, xx, yy, ww, hh, 0, 360*64);
+
+ if (originChanged)
+ gdk_gc_set_ts_origin(gc, 0, 0);
+ }
+
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_gdkwindow, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
+ }
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + width, y + height );
+}
+
+void wxWindowDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
+{
+ // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
+ DoDrawBitmap( (const wxBitmap&)icon, x, y, true );
+}
+
+void wxWindowDCImpl::DoDrawBitmap( const wxBitmap &bitmap,
+ wxCoord x, wxCoord y,
+ bool useMask )
+{
+ wxCHECK_RET( IsOk(), wxT("invalid window dc") );
+
+ wxCHECK_RET( bitmap.IsOk(), wxT("invalid bitmap") );
+
+ bool is_mono = bitmap.GetDepth() == 1;
+
+ // scale/translate size and position
+ int xx = XLOG2DEV(x);
+ int yy = YLOG2DEV(y);
+
+ int w = bitmap.GetWidth();
+ int h = bitmap.GetHeight();
+
+ if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft)
+ xx -= w;
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + w, y + h );
+
+ if (!m_gdkwindow) return;
+
+ int ww = XLOG2DEVREL(w);
+ int hh = YLOG2DEVREL(h);
+
+ // compare to current clipping region
+ if (!m_currentClippingRegion.IsNull())
+ {
+ wxRegion tmp( xx,yy,ww,hh );
+ tmp.Intersect( m_currentClippingRegion );
+ if (tmp.IsEmpty())
+ return;
+ }
+
+ // scale bitmap if required
+ wxBitmap use_bitmap = bitmap;
+ if ((w != ww) || (h != hh))
+ use_bitmap = use_bitmap.Rescale( 0, 0, ww, hh, ww, hh );
+
+ // apply mask if any
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (useMask && use_bitmap.GetMask())
+ mask = use_bitmap.GetMask()->GetBitmap();
+
+ GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
+
+ GdkBitmap *new_mask = (GdkBitmap*) NULL;
+
+ if (mask != NULL)
+ {
+ 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 );
+ mask = new_mask;
+ g_object_unref (gc);
+ }
+
+ gdk_gc_set_clip_mask(use_gc, mask);
+ gdk_gc_set_clip_origin(use_gc, 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.GetPixmap(), 0, 0);
+
+ gdk_draw_drawable(m_gdkwindow, use_gc, bitmap2, 0, 0, xx, yy, -1, -1);
+
+ g_object_unref (bitmap2);
+ g_object_unref (gc);
+ }
+ else
+ {
+ if (use_bitmap.HasPixbuf())
+ {
+ gdk_draw_pixbuf(m_gdkwindow, use_gc,
+ use_bitmap.GetPixbuf(),
+ 0, 0, xx, yy, -1, -1,
+ GDK_RGB_DITHER_NORMAL, xx, yy);
+ }
+ else
+ {
+ gdk_draw_drawable(m_gdkwindow, use_gc,
+ use_bitmap.GetPixmap(),
+ 0, 0, xx, yy, -1, -1);
+ }
+ }
+
+ // remove mask again if any
+ if (mask != NULL)
+ {
+ gdk_gc_set_clip_mask(use_gc, NULL);
+ gdk_gc_set_clip_origin(use_gc, 0, 0);
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
+ if (new_mask != NULL)
+ g_object_unref(new_mask);
+ }
+}
+
+bool wxWindowDCImpl::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( IsOk(), false, wxT("invalid window dc") );
+
+ wxCHECK_MSG( source, false, wxT("invalid source dc") );
+
+ if (!m_gdkwindow) return false;
+
+ // transform the source DC coords to the device ones
+ xsrc = source->LogicalToDeviceX(xsrc);
+ ysrc = source->LogicalToDeviceY(ysrc);
+
+ wxBitmap selected;
+ wxMemoryDC *memDC = wxDynamicCast(source, wxMemoryDC);
+ if ( memDC )
+ {
+ selected = memDC->GetSelectedBitmap();
+ if ( !selected.IsOk() )
+ return false;
+ }
+
+ bool use_bitmap_method = false;
+ bool is_mono = false;
+
+ if (xsrcMask == -1 && ysrcMask == -1)
+ {
+ xsrcMask = xsrc;
+ ysrcMask = ysrc;
+ }
+
+ if (selected.IsOk())
+ {
+ is_mono = (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 && (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 == selected.GetWidth()) &&
+ (height == 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;
+ }
+ }
+
+ 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 = selected.GetWidth();
+ wxCoord bm_height = 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 = selected;
+ if ((selected.GetWidth()!= bm_ww) || ( 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 );
+ if (!m_currentClippingRegion.IsNull())
+ tmp.Intersect( m_currentClippingRegion );
+ tmp.GetBox(cx,cy,cw,ch);
+
+ // Scale and clipped bitmap
+ use_bitmap = selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh);
+ }
+
+ // apply mask if any
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (useMask && use_bitmap.GetMask())
+ mask = use_bitmap.GetMask()->GetBitmap();
+
+ GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
+
+ GdkBitmap *new_mask = (GdkBitmap*) NULL;
+
+ if (mask != NULL)
+ {
+ 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 );
+ mask = new_mask;
+ g_object_unref (gc);
+ }
+
+ gdk_gc_set_clip_mask(use_gc, mask);
+ if (new_mask != NULL)
+ gdk_gc_set_clip_origin(use_gc, cx, cy);
+ else
+ gdk_gc_set_clip_origin(use_gc, 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.GetPixmap(), 0, 0);
+
+ gdk_draw_drawable(m_gdkwindow, use_gc, bitmap, xsrc, ysrc, cx, cy, cw, ch);
+
+ g_object_unref (bitmap);
+ g_object_unref (gc);
+ }
+ else
+ {
+ // was: gdk_draw_drawable( m_gdkwindow, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+ gdk_draw_drawable(m_gdkwindow, use_gc, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch);
+ }
+
+ // remove mask again if any
+ if (mask != NULL)
+ {
+ gdk_gc_set_clip_mask(use_gc, NULL);
+ gdk_gc_set_clip_origin(use_gc, 0, 0);
+ if (!m_currentClippingRegion.IsNull())
+ gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
+ }
+
+ if (new_mask)
+ g_object_unref (new_mask);
+ }
+ else // use_bitmap_method
+ {
+ if (selected.IsOk() && ((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 = selected.Rescale( cx-xx, cy-yy, cw, ch, ww, hh );
+
+ // draw scaled bitmap
+ // was: gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
+ gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, cx, cy, -1, -1 );
+ }
+ else
+ {
+ // No scaling and not a memory dc with a mask either
+ GdkWindow* window = NULL;
+ wxDCImpl *impl = source->GetImpl();
+ wxWindowDCImpl *gtk_impl = wxDynamicCast(impl, wxWindowDCImpl);
+ if (gtk_impl)
+ window = gtk_impl->GetGDKWindow();
+ if ( !window )
+ {
+ SetLogicalFunction( old_logical_func );
+ return false;
+ }
+
+ // copy including child window contents
+ gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
+ gdk_draw_drawable( m_gdkwindow, m_penGC,
+ window,
+ xsrc, ysrc, xx, yy,
+ width, height );
+ gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
+ }
+ }
+
+ SetLogicalFunction( old_logical_func );
+
+ return true;
+}
+
+void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET( IsOk(), wxT("invalid window dc") );
+
+ if (!m_gdkwindow) 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") );
+
+ gdk_pango_context_set_colormap( m_context, m_cmap );
+
+ bool underlined = m_font.IsOk() && m_font.GetUnderlined();
+
+ wxCharBuffer data = wxGTK_CONV(text);
+ if ( !data )
+ return;
+ size_t datalen = strlen(data);
+
+ // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
+ // has been fixed and thus the hack implemented below should never be used
+ static bool pangoOk = !wx_pango_version_check(1, 16, 0);
+
+ bool needshack = underlined && !pangoOk;
+
+ if (needshack)
+ {
+ // a PangoLayout which has leading/trailing spaces with underlined font
+ // is not correctly drawn by this pango version: Pango won't underline the spaces.
+ // This can be a problem; e.g. wxHTML rendering of underlined text relies on
+ // this behaviour. To workaround this problem, we use a special hack here
+ // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
+ // empty space characters and give them a dummy colour attribute.
+ // This will force Pango to underline the leading/trailing spaces, too.
+
+ wxCharBuffer data_tmp(datalen + 6);
+ // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ memcpy(data_tmp.data(), "\342\200\214", 3);
+ // copy the user string
+ memcpy(data_tmp.data() + 3, data, datalen);
+ // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ memcpy(data_tmp.data() + 3 + datalen, "\342\200\214", 3);
+
+ data = data_tmp;
+ datalen += 6;
+ }
+
+ pango_layout_set_text(m_layout, 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);
+
+ if (needshack)
+ {
+ // dummy colour for the leading space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = 0;
+ a->end_index = 1;
+ pango_attr_list_insert(attrs, a);
+
+ // dummy colour for the trailing space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = datalen - 1;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+ }
+
+ pango_layout_set_attributes(m_layout, attrs);
+ pango_attr_list_unref(attrs);
+ }
+
+ int oldSize = 0;
+ const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
+ if (isScaled)
+ {
+ // If there is a user or actually any scale applied to
+ // the device context, scale the font.
+
+ // scale font description
+ oldSize = pango_font_description_get_size(m_fontdesc);
+ pango_font_description_set_size(m_fontdesc, int(oldSize * m_scaleY));
+
+ // actually apply scaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+ }
+
+ int w, h;
+ pango_layout_get_pixel_size(m_layout, &w, &h);
+ if (m_backgroundMode == wxSOLID)