m_bgGC = (GdkGC *) NULL;
m_cmap = (GdkColormap *) NULL;
m_owner = (wxWindow *)NULL;
+ m_isMemDC = FALSE;
+ m_font = window->GetFont();
- if (!window)
- return;
+ wxASSERT_MSG( window, _T("DC needs a window") );
GtkWidget *widget = window->m_wxwindow;
- if (!widget)
- return;
+
+ wxASSERT_MSG( widget, _T("DC needs a widget") );
m_window = widget->window;
/* not realized ? */
if (!m_window)
{
- /* force realization */
- gtk_widget_realize( widget );
- m_window = widget->window;
+ /* don't report problems */
+ m_ok = TRUE;
+
+ return;
}
- /* still not realized ? */
- if (!m_window)
- return;
-
if (window->m_wxwindow)
m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
else
m_cmap = gtk_widget_get_colormap( window->m_widget );
-
- m_isMemDC = FALSE;
SetUpDC();
if (m_pen.GetStyle() != wxTRANSPARENT)
{
- gdk_draw_line( m_window, m_penGC,
- XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
+ if (m_window)
+ gdk_draw_line( m_window, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
CalcBoundingBox(x1, y1);
CalcBoundingBox(x2, y2);
GetSize( &w, &h );
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
- gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
- gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
+ if (m_window)
+ {
+ gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
+ gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
+ }
}
}
while (alpha2 <= 0) alpha2 += 360*64;
while (alpha1 > 360*64) alpha1 -= 360*64;
- if (m_brush.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
+ if (m_window)
+ {
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
- if (m_pen.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
+ }
CalcBoundingBox (x1, y1);
CalcBoundingBox (x2, y2);
if (ww < 0) { ww = -ww; xx = xx - ww; }
if (hh < 0) { hh = -hh; yy = yy - hh; }
- long start = long(sa * 64.0);
- long end = long(ea * 64.0);
- if (m_brush.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
+ if (m_window)
+ {
+ long start = long(sa * 64.0);
+ long end = long(ea * 64.0);
+
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
- if (m_pen.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
+ }
CalcBoundingBox (x, y);
CalcBoundingBox (x + width, y + height);
{
wxCHECK_RET( Ok(), _T("invalid window dc") );
- if (m_pen.GetStyle() != wxTRANSPARENT)
+ if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
CalcBoundingBox (x, y);
long x2 = XLOG2DEV(points[i+1].x + xoffset);
long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
long y2 = YLOG2DEV(points[i+1].y + yoffset);
- gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
+ if (m_window)
+ gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset );
}
// To do: Fillstyle
- if (m_pen.GetStyle() != wxTRANSPARENT)
+ if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
+ {
for (i = 0 ; i < n ; i++)
{
gdk_draw_line( m_window, m_penGC,
gdkpoints[(i+1)%n].x,
gdkpoints[(i+1)%n].y);
}
+ }
delete[] gdkpoints;
}
if (ww < 0) { ww = -ww; xx = xx - ww; }
if (hh < 0) { hh = -hh; yy = yy - hh; }
- if (m_brush.GetStyle() != wxTRANSPARENT)
- gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
+ if (m_window)
+ {
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
- if (m_pen.GetStyle() != wxTRANSPARENT)
- gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
+ }
CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
hh--;
}
- // CMB: ensure dd is not larger than rectangle otherwise we
- // get an hour glass shape
- long dd = 2 * rr;
- if (dd > ww) dd = ww;
- if (dd > hh) dd = hh;
- rr = dd / 2;
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
+ if (m_window)
{
- gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
- gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
- }
+ // CMB: ensure dd is not larger than rectangle otherwise we
+ // get an hour glass shape
+ long dd = 2 * rr;
+ if (dd > ww) dd = ww;
+ if (dd > hh) dd = hh;
+ rr = dd / 2;
+
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ {
+ gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
+ gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
+ }
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
- gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
- gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
- gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
- gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
- gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
- gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
- gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ {
+ gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
+ gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
+ gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
+ gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
+ }
}
// this ignores the radius
if (ww < 0) { ww = -ww; xx = xx - ww; }
if (hh < 0) { hh = -hh; yy = yy - hh; }
- if (m_brush.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
+ if (m_window)
+ {
+ if (m_brush.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
- if (m_pen.GetStyle() != wxTRANSPARENT)
- gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
+ if (m_pen.GetStyle() != wxTRANSPARENT)
+ gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
+ }
CalcBoundingBox( x - width, y - height );
CalcBoundingBox( x + width, y + height );
int w = bitmap.GetWidth();
int h = bitmap.GetHeight();
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + w, y + h );
+
+ if (!m_window) return;
+
int ww = XLOG2DEVREL(w);
int hh = YLOG2DEVREL(h);
gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
gdk_gc_set_clip_origin( m_penGC, 0, 0 );
}
-
- CalcBoundingBox( x, y );
- CalcBoundingBox( x + w, y + h );
}
bool wxWindowDC::DoBlit( long xdest, long ydest, long width, long height,
wxCHECK_MSG( source, FALSE, _T("invalid source dc") );
+ if (!m_window) return FALSE;
+
wxClientDC *srcDC = (wxClientDC*)source;
wxMemoryDC *memDC = (wxMemoryDC*)source;
{
wxCHECK_RET( Ok(), _T("invalid window dc") );
+ if (!m_window) return;
+
GdkFont *font = m_font.GetInternalFont( m_scaleY );
x = XLOG2DEV(x);
{
wxCHECK_RET( Ok(), _T("invalid window dc") );
+ 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
if (!m_pen.Ok()) return;
+ if (!m_window) return;
+
gint width = m_pen.GetWidth();
- // CMB: if width is non-zero scale it with the dc
if (width <= 0)
{
+ // CMB: if width is non-zero scale it with the dc
width = 1;
}
else
width = (int)w;
}
+ const static char dotted[] = {1, 1};
+ const static char short_dashed[] = {2, 2};
+ const static char long_dashed[] = {2, 4};
+ const static char 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 char *req_dash;
+
GdkLineStyle lineStyle = GDK_LINE_SOLID;
switch (m_pen.GetStyle())
{
- case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; }
- case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
- case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
- case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
- case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; }
+ case wxUSER_DASH:
+ {
+ lineStyle = GDK_LINE_ON_OFF_DASH;
+ req_nb_dash = m_pen.GetDashCount();
+ req_dash = 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 = long_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:
+ case wxSOLID:
+ default:
+ {
+ lineStyle = GDK_LINE_SOLID;
+ req_dash = (wxDash*)NULL;
+ req_nb_dash = 0;
+ break;
+ }
}
+#if (GTK_MINOR_VERSION > 0)
+ if (req_dash && req_nb_dash)
+ {
+ char *real_req_dash = new char[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, (char*)req_dash, req_nb_dash );
+ }
+ }
+#endif
+
GdkCapStyle capStyle = GDK_CAP_ROUND;
switch (m_pen.GetCap())
{
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() );
if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
{
if (m_brush.GetStipple()->GetPixmap())
- gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
+ gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
else
gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() );
}
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_fill( m_bgGC, fillStyle );
- if (m_backgroundBrush.GetStyle() == wxSTIPPLE)
+ if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
{
- gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
+ if (m_brush.GetStipple()->GetPixmap())
+ gdk_gc_set_tile( m_bgGC, m_brush.GetStipple()->GetPixmap() );
+ else
+ gdk_gc_set_stipple( m_bgGC, m_brush.GetStipple()->GetBitmap() );
}
if (IS_HATCH(m_backgroundBrush.GetStyle()))
wxCHECK_RET( Ok(), _T("invalid window dc") );
if (m_logicalFunction == function) return;
-
+
GdkFunction mode = GDK_COPY;
switch (function)
{
- case wxXOR: mode = GDK_INVERT; break;
- case wxINVERT: mode = GDK_XOR; break;
-#if (GDK_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;
-/* ? wxSRC_INVERT GDK_AND_REVERSE, GDK_OR_REVERSE, GDK_OR_INVERT */
+ 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 wxSRC_AND:
+ case wxAND: mode = GDK_AND; break;
+ case wxSRC_OR:
+ 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;
#endif
- default: break;
+ default:
+ {
+ wxFAIL_MSG( _T("unsupported logical function") );
+ break;
+ }
}
m_logicalFunction = function;
+
+ if (!m_window) return;
+
gdk_gc_set_function( m_penGC, mode );
gdk_gc_set_function( m_brushGC, mode );
gdk_gc_set_function( m_textGC, mode );
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() );
}
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() );
}
m_backgroundMode = mode;
+ if (!m_window) return;
+
// CMB 21/7/98: fill style of cross-hatch brushes is affected by
// transparent/solid background mode
wxDC::DoSetClippingRegion( x, y, width, height );
+ if (!m_window) return;
+
GdkRectangle rect;
rect.x = XLOG2DEV(x);
rect.y = YLOG2DEV(y);
return;
}
+ if (!m_window) return;
+
gdk_gc_set_clip_region( m_penGC, region.GetRegion() );
gdk_gc_set_clip_region( m_brushGC, region.GetRegion() );
gdk_gc_set_clip_region( m_textGC, region.GetRegion() );
wxDC::DestroyClippingRegion();
+ if (!m_window) return;
+
gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
m_brush = wxNullBrush;
SetBrush( tmp_brush );
+/*
tmp_brush = m_backgroundBrush;
m_backgroundBrush = wxNullBrush;
SetBackground( tmp_brush );
+*/
+ tmp_brush = m_backgroundBrush;
+ m_backgroundBrush = wxNullBrush;
+ SetBackground( *wxWHITE_BRUSH );
+ m_backgroundBrush = tmp_brush;
if (!hatch_bitmap)
{
m_bgGC = (GdkGC*) NULL;
}
+void wxWindowDC::ComputeScaleAndOrigin()
+{
+ /* CMB: copy scale to see if it changes */
+ double origScaleX = m_scaleX;
+ double origScaleY = m_scaleY;
+
+ wxDC::ComputeScaleAndOrigin();
+
+ /* CMB: if scale has changed call SetPen to recalulate the line width */
+ if ((m_scaleX != origScaleX || m_scaleY != origScaleY) &&
+ (m_pen.Ok()))
+ {
+ /* this is a bit artificial, but we need to force wxDC to think
+ the pen has changed */
+ wxPen pen = m_pen;
+ m_pen = wxNullPen;
+ SetPen( pen );
+ }
+}
+
// Resolution in pixels per logical inch
wxSize wxWindowDC::GetPPI() const
{