+ if (!m_window) return;
+
+ /* - we either are a memory dc or have a window as the
+ owner. anything else shouldn't happen.
+ - we don't use gdk_window_clear() as we don't set
+ the window's background colour anymore. it is too
+ much pain to keep the DC's and the window's back-
+ ground colour in synch. */
+
+ if (m_owner)
+ {
+ int width,height;
+ m_owner->GetSize( &width, &height );
+ gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
+ return;
+ }
+
+ if (m_isMemDC)
+ {
+ int width,height;
+ GetSize( &width, &height );
+ gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
+ return;
+ }
+}
+
+void wxWindowDC::SetFont( const wxFont &font )
+{
+ m_font = font;
+#ifdef __WXGTK20__
+ // fix fontdesc?
+#endif
+}
+
+void wxWindowDC::SetPen( const wxPen &pen )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_pen == pen) return;
+
+ m_pen = pen;
+
+ if (!m_pen.Ok()) return;
+
+ if (!m_window) return;
+
+ gint width = m_pen.GetWidth();
+ if (width <= 0)
+ {
+ // CMB: if width is non-zero scale it with the dc
+ width = 1;
+ }
+ else
+ {
+ // X doesn't allow different width in x and y and so we take
+ // the average
+ double w = 0.5 +
+ ( fabs((double) XLOG2DEVREL(width)) +
+ fabs((double) YLOG2DEVREL(width)) ) / 2.0;
+ width = (int)w;
+ }
+
+ static const wxGTKDash dotted[] = {1, 1};
+ static const wxGTKDash short_dashed[] = {2, 2};
+ static const wxGTKDash wxCoord_dashed[] = {2, 4};
+ static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3};
+
+ // We express dash pattern in pen width unit, so we are
+ // independent of zoom factor and so on...
+ int req_nb_dash;
+ const wxGTKDash *req_dash;
+
+ GdkLineStyle lineStyle = GDK_LINE_SOLID;
+ switch (m_pen.GetStyle())
+ {
+ case wxUSER_DASH:
+ {
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = m_pen.GetDashCount();
+ req_dash = (wxGTKDash*)m_pen.GetDash();
+ break;
+ }
+ case wxDOT:
+ {
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = 2;
+ req_dash = dotted;
+ break;
+ }
+ case wxLONG_DASH:
+ {
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = 2;
+ req_dash = wxCoord_dashed;
+ break;
+ }
+ case wxSHORT_DASH:
+ {
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = 2;
+ req_dash = short_dashed;
+ break;
+ }
+ case wxDOT_DASH:
+ {
+// lineStyle = GDK_LINE_DOUBLE_DASH;
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = 4;
+ req_dash = dotted_dashed;
+ break;
+ }
+
+ case wxTRANSPARENT:
+ case wxSTIPPLE_MASK_OPAQUE:
+ case wxSTIPPLE:
+ case wxSOLID:
+ default:
+ {
+ lineStyle = GDK_LINE_SOLID;
+ req_dash = (wxGTKDash*)NULL;
+ req_nb_dash = 0;
+ break;
+ }
+ }
+
+#if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
+ if (req_dash && req_nb_dash)
+ {
+ wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash];
+ if (real_req_dash)
+ {
+ for (int i = 0; i < req_nb_dash; i++)
+ real_req_dash[i] = req_dash[i] * width;
+ gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash );
+ delete[] real_req_dash;
+ }
+ else
+ {
+ // No Memory. We use non-scaled dash pattern...
+ gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash );
+ }
+ }
+#endif
+
+ GdkCapStyle capStyle = GDK_CAP_ROUND;
+ switch (m_pen.GetCap())
+ {
+ case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
+ case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
+ case wxCAP_ROUND:
+ default:
+ {
+ if (width <= 1)
+ {
+ width = 0;
+ capStyle = GDK_CAP_NOT_LAST;
+ }
+ else
+ {
+ capStyle = GDK_CAP_ROUND;
+ }
+ break;
+ }
+ }
+
+ GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
+ switch (m_pen.GetJoin())
+ {
+ case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
+ case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
+ case wxJOIN_ROUND:
+ default: { joinStyle = GDK_JOIN_ROUND; break; }
+ }
+
+ gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
+
+ m_pen.GetColour().CalcPixel( m_cmap );
+ gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
+}
+
+void wxWindowDC::SetBrush( const wxBrush &brush )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_brush == brush) return;
+
+ m_brush = brush;
+
+ if (!m_brush.Ok()) return;
+
+ if (!m_window) return;
+
+ m_brush.GetColour().CalcPixel( m_cmap );
+ gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
+
+ gdk_gc_set_fill( m_brushGC, GDK_SOLID );
+
+ if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
+ {
+ if (m_brush.GetStipple()->GetPixmap())
+ {
+ gdk_gc_set_fill( m_brushGC, GDK_TILED );
+ gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
+ }
+ else
+ {
+ gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
+ gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() );
+ }
+ }
+
+ if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
+ {
+ gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED);
+ gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() );
+ }
+
+ if (IS_HATCH(m_brush.GetStyle()))
+ {
+ gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
+ int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
+ gdk_gc_set_stipple( m_brushGC, hatches[num] );
+ }
+}
+
+void wxWindowDC::SetBackground( const wxBrush &brush )
+{
+ /* CMB 21/7/98: Added SetBackground. Sets background brush
+ * for Clear() and bg colour for shapes filled with cross-hatch brush */
+
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_backgroundBrush == brush) return;
+
+ m_backgroundBrush = brush;
+
+ if (!m_backgroundBrush.Ok()) return;
+
+ if (!m_window) return;
+
+ m_backgroundBrush.GetColour().CalcPixel( m_cmap );
+ gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
+ gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
+ gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
+ gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
+
+ gdk_gc_set_fill( m_bgGC, GDK_SOLID );
+
+ if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
+ {
+ if (m_backgroundBrush.GetStipple()->GetPixmap())
+ {
+ gdk_gc_set_fill( m_bgGC, GDK_TILED );
+ gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
+ }
+ else
+ {
+ gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
+ gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() );
+ }
+ }
+
+ if (IS_HATCH(m_backgroundBrush.GetStyle()))
+ {
+ gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
+ int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
+ gdk_gc_set_stipple( m_bgGC, hatches[num] );
+ }
+}
+
+void wxWindowDC::SetLogicalFunction( int function )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_logicalFunction == function)
+ return;
+
+ // VZ: shouldn't this be a CHECK?
+ if (!m_window)
+ return;
+
+ GdkFunction mode = GDK_COPY;
+ switch (function)
+ {
+ case wxXOR: mode = GDK_XOR; break;
+ case wxINVERT: mode = GDK_INVERT; break;
+#if (GTK_MINOR_VERSION > 0)
+ case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
+ case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
+ case wxCLEAR: mode = GDK_CLEAR; break;
+ case wxSET: mode = GDK_SET; break;
+ case wxOR_INVERT: mode = GDK_OR_INVERT; break;
+ case wxAND: mode = GDK_AND; break;
+ case wxOR: mode = GDK_OR; break;
+ case wxEQUIV: mode = GDK_EQUIV; break;
+ case wxNAND: mode = GDK_NAND; break;
+ case wxAND_INVERT: mode = GDK_AND_INVERT; break;
+ case wxCOPY: mode = GDK_COPY; break;
+ case wxNO_OP: mode = GDK_NOOP; break;
+ case wxSRC_INVERT: mode = GDK_COPY_INVERT; break;
+
+ // unsupported by GTK
+ case wxNOR: mode = GDK_COPY; break;
+#endif
+ default:
+ {
+ wxFAIL_MSG( wxT("unsupported logical function") );
+ break;
+ }
+ }
+
+ m_logicalFunction = function;
+
+ gdk_gc_set_function( m_penGC, mode );
+ gdk_gc_set_function( m_brushGC, mode );
+
+ // to stay compatible with wxMSW, we don't apply ROPs to the text
+ // operations (i.e. DrawText/DrawRotatedText).
+ // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
+ gdk_gc_set_function( m_textGC, mode );
+}
+
+void wxWindowDC::SetTextForeground( const wxColour &col )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_textForegroundColour == col) return;
+
+ m_textForegroundColour = col;
+ if (!m_textForegroundColour.Ok()) return;
+
+ if (!m_window) return;
+
+ m_textForegroundColour.CalcPixel( m_cmap );
+ gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
+}
+
+void wxWindowDC::SetTextBackground( const wxColour &col )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_textBackgroundColour == col) return;
+
+ m_textBackgroundColour = col;
+ if (!m_textBackgroundColour.Ok()) return;
+
+ if (!m_window) return;
+
+ m_textBackgroundColour.CalcPixel( m_cmap );
+ gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
+}
+
+void wxWindowDC::SetBackgroundMode( int mode )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ m_backgroundMode = mode;
+
+ if (!m_window) return;
+
+ // CMB 21/7/98: fill style of cross-hatch brushes is affected by
+ // transparent/solid background mode
+
+ if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
+ {
+ gdk_gc_set_fill( m_brushGC,
+ (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
+ }
+}
+
+void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
+{
+ wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
+}
+
+void wxWindowDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (!m_window) return;
+
+ wxRect rect;
+ rect.x = XLOG2DEV(x);
+ rect.y = YLOG2DEV(y);
+ rect.width = XLOG2DEVREL(width);
+ rect.height = YLOG2DEVREL(height);
+
+ if (!m_currentClippingRegion.IsNull())
+ m_currentClippingRegion.Intersect( rect );
+ else
+ m_currentClippingRegion.Union( rect );
+
+#if USE_PAINT_REGION
+ if (!m_paintClippingRegion.IsNull())
+ m_currentClippingRegion.Intersect( m_paintClippingRegion );
+#endif
+
+ wxCoord xx, yy, ww, hh;
+ m_currentClippingRegion.GetBox( xx, yy, ww, hh );
+ wxDC::DoSetClippingRegion( xx, yy, ww, hh );
+
+ gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
+}
+
+void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (region.Empty())
+ {
+ DestroyClippingRegion();
+ return;
+ }
+
+ if (!m_window) return;
+
+ if (!m_currentClippingRegion.IsNull())
+ m_currentClippingRegion.Intersect( region );
+ else
+ m_currentClippingRegion.Union( region );
+
+#if USE_PAINT_REGION
+ if (!m_paintClippingRegion.IsNull())
+ m_currentClippingRegion.Intersect( m_paintClippingRegion );
+#endif
+
+ wxCoord xx, yy, ww, hh;
+ m_currentClippingRegion.GetBox( xx, yy, ww, hh );
+ wxDC::DoSetClippingRegion( xx, yy, ww, hh );
+
+ gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
+ gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );