+ /* this is the nth try to get this utterly useless function to
+ work. it now completely ignores the scaling or translation
+ of the source dc, but scales correctly on the target dc and
+ knows about possible mask information in a memory dc. */
+
+ wxCHECK_MSG( Ok(), FALSE, wxT("invalid window dc") );
+
+ wxCHECK_MSG( source, FALSE, wxT("invalid source dc") );
+
+ if (!m_window) return FALSE;
+
+ wxClientDC *srcDC = (wxClientDC*)source;
+ wxMemoryDC *memDC = (wxMemoryDC*)source;
+
+ bool use_bitmap_method = FALSE;
+ bool is_mono = FALSE;
+
+ if (srcDC->m_isMemDC)
+ {
+ if (!memDC->m_selected.Ok()) return FALSE;
+
+ /* we use the "XCopyArea" way to copy a memory dc into
+ y 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 (memDC->m_selected.GetDepth() == 1)
+ {
+ /* we HAVE TO use the direct way for memory dcs
+ that are bitmaps because XCopyArea doesn't cope
+ with different bit depths */
+ is_mono = TRUE;
+ 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();
+
+ wxCoord bm_ww = XLOG2DEVREL( bm_width );
+ wxCoord bm_hh = YLOG2DEVREL( bm_height );
+
+ /* scale bitmap if required */
+ wxBitmap use_bitmap;
+
+ if ((bm_width != bm_ww) || (bm_height != bm_hh))
+ {
+ wxImage image( memDC->m_selected );
+ image = image.Scale( bm_ww, bm_hh );
+
+ if (is_mono)
+ use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ else
+ use_bitmap = image.ConvertToBitmap();
+ }
+ else
+ {
+ use_bitmap = memDC->m_selected;
+ }
+
+ /* apply mask if any */
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
+
+ if (useMask && mask)
+ {
+ GdkBitmap *new_mask = (GdkBitmap*) NULL;
+ if (!m_currentClippingRegion.IsNull())
+ {
+ GdkColor col;
+ new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_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, 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() );
+ 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, bm_ww, bm_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 );
+ }
+ if (new_mask)
+ gdk_bitmap_unref( new_mask );
+ }
+
+ /* 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)
+ gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
+ else
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+
+ /* 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() );
+ }
+ }
+ }
+ else /* use_bitmap_method */
+ {
+ if ((width != ww) || (height != hh))
+ {
+ /* draw source window into a bitmap as we cannot scale
+ a window in contrast to a bitmap. this would actually
+ work with memory dcs as well, but we'd lose the mask
+ information and waste one step in this process since
+ a memory already has a bitmap. all this is slightly
+ inefficient as we could take an XImage directly from
+ an X window, but we'd then also have to care that
+ the window is not outside the screen (in which case
+ we'd get a BadMatch or what not).
+ Is a double XGetImage and combined XGetPixel and
+ XPutPixel really faster? I'm not sure. look at wxXt
+ for a different implementation of the same problem. */
+
+ wxBitmap bitmap( width, height );
+
+ /* copy including child window contents */
+ gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
+ gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0,
+ srcDC->GetWindow(),
+ xsrc, ysrc, width, height );
+ gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
+
+ /* scale image */
+ wxImage image( bitmap );
+ image = image.Scale( ww, hh );
+
+ /* convert to bitmap */
+ bitmap = image.ConvertToBitmap();
+
+ /* draw scaled bitmap */
+ gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -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;
+
+ GdkFont *font = m_font.GetInternalFont( m_scaleY );
+
+ wxCHECK_RET( font, wxT("invalid font") );
+
+#ifdef __WXGTK20__
+ wxCHECK_RET( m_context, wxT("no Pango context") );
+#endif
+
+ x = XLOG2DEV(x);
+ y = YLOG2DEV(y);
+
+#ifdef __WXGTK20__
+ /* FIXME: the layout engine should probably be abstracted at a higher level in wxDC... */
+ PangoLayout *layout = pango_layout_new(m_context);
+ pango_layout_set_font_description(layout, m_fontdesc);
+ {
+ wxWX2MBbuf data = text.mb_str(wxConvUTF8);
+ pango_layout_set_text(layout, data, strlen(data));
+ }
+ PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
+ PangoRectangle rect;
+ pango_layout_line_get_extents(line, NULL, &rect);
+ wxCoord width = rect.width;
+ wxCoord height = rect.height;
+ gdk_draw_layout( m_window, m_textGC, x, y, layout );
+#else
+ wxCoord width = gdk_string_width( font, text.mbc_str() );
+ wxCoord height = font->ascent + font->descent;
+ /* CMB 21/5/98: draw text background if mode is wxSOLID */
+ if (m_backgroundMode == wxSOLID)
+ {
+ gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
+ gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
+ gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
+ }
+ gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
+#endif
+
+ /* CMB 17/7/98: simple underline: ignores scaling and underlying
+ X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
+ properties (see wxXt implementation) */
+ if (m_font.GetUnderlined())
+ {
+ wxCoord ul_y = y + font->ascent;
+ if (font->descent > 0) ul_y++;
+ gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
+ }
+
+#ifdef __WXGTK20__
+ g_object_unref( G_OBJECT( layout ) );
+#endif
+
+ width = wxCoord(width / m_scaleX);
+ height = wxCoord(height / m_scaleY);
+ CalcBoundingBox (x + width, y + height);
+ CalcBoundingBox (x, y);