1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dcclient.h"
14 #include "wx/dcclient.h"
15 #include "wx/dcmemory.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
30 static GdkPixmap
*hatches
[num_hatches
];
31 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define RAD2DEG 57.2957795131
39 //-----------------------------------------------------------------------------
40 // temporary implementation of the missing GDK function
41 //-----------------------------------------------------------------------------
42 #include "gdk/gdkprivate.h"
43 void gdk_draw_bitmap (GdkDrawable
*drawable
,
53 GdkWindowPrivate
*drawable_private
;
54 GdkWindowPrivate
*src_private
;
55 GdkGCPrivate
*gc_private
;
57 g_return_if_fail (drawable
!= NULL
);
58 g_return_if_fail (src
!= NULL
);
59 g_return_if_fail (gc
!= NULL
);
61 drawable_private
= (GdkWindowPrivate
*) drawable
;
62 src_private
= (GdkWindowPrivate
*) src
;
63 if (drawable_private
->destroyed
|| src_private
->destroyed
)
66 gc_private
= (GdkGCPrivate
*) gc
;
68 if (width
== -1) width
= src_private
->width
;
69 if (height
== -1) height
= src_private
->height
;
71 XCopyPlane( drawable_private
->xdisplay
,
73 drawable_private
->xwindow
,
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
87 wxPaintDC::wxPaintDC(void)
89 m_penGC
= (GdkGC
*) NULL
;
90 m_brushGC
= (GdkGC
*) NULL
;
91 m_textGC
= (GdkGC
*) NULL
;
92 m_bgGC
= (GdkGC
*) NULL
;
93 m_cmap
= (GdkColormap
*) NULL
;
97 wxPaintDC::wxPaintDC( wxWindow
*window
)
99 m_penGC
= (GdkGC
*) NULL
;
100 m_brushGC
= (GdkGC
*) NULL
;
101 m_textGC
= (GdkGC
*) NULL
;
102 m_bgGC
= (GdkGC
*) NULL
;
103 m_cmap
= (GdkColormap
*) NULL
;
106 GtkWidget
*widget
= window
->m_wxwindow
;
108 m_window
= widget
->window
;
109 if (!m_window
) return;
110 if (window
->m_wxwindow
)
111 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
113 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
119 wxRegion update
= window
->GetUpdateRegion();
120 if (update
.Empty()) return;
122 gdk_gc_set_clip_region( m_penGC
, update
.GetRegion() );
123 gdk_gc_set_clip_region( m_brushGC
, update
.GetRegion() );
124 gdk_gc_set_clip_region( m_textGC
, update
.GetRegion() );
125 gdk_gc_set_clip_region( m_bgGC
, update
.GetRegion() );
128 wxPaintDC::~wxPaintDC(void)
133 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
134 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
136 wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" );
139 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
141 wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" );
145 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
149 if (m_pen
.GetStyle() != wxTRANSPARENT
)
151 gdk_draw_line( m_window
, m_penGC
,
152 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
155 CalcBoundingBox(x1
, y1
);
156 CalcBoundingBox(x2
, y2
);
159 void wxPaintDC::CrossHair( long x
, long y
)
163 if (m_pen
.GetStyle() != wxTRANSPARENT
)
168 long xx
= XLOG2DEV(x
);
169 long yy
= YLOG2DEV(y
);
170 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
171 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
175 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
179 long xx1
= XLOG2DEV(x1
);
180 long yy1
= YLOG2DEV(y1
);
181 long xx2
= XLOG2DEV(x2
);
182 long yy2
= YLOG2DEV(y2
);
183 long xxc
= XLOG2DEV((long)xc
);
184 long yyc
= YLOG2DEV((long)yc
);
185 double dx
= xx1
- xxc
;
186 double dy
= yy1
- yyc
;
187 double radius
= sqrt(dx
*dx
+dy
*dy
);
188 long r
= (long)radius
;
189 double radius1
, radius2
;
191 if (xx1
== xx2
&& yy1
== yy2
)
199 radius1
= radius2
= 0.0;
203 radius1
= (xx1
- xxc
== 0) ?
204 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
205 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
206 radius2
= (xx2
- xxc
== 0) ?
207 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
208 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
210 long alpha1
= long(radius1
* 64.0);
211 long alpha2
= long((radius2
- radius1
) * 64.0);
212 while (alpha2
<= 0) alpha2
+= 360*64;
213 while (alpha1
> 360*64) alpha1
-= 360*64;
215 if (m_brush
.GetStyle() != wxTRANSPARENT
)
216 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
218 if (m_pen
.GetStyle() != wxTRANSPARENT
)
219 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
221 CalcBoundingBox (x1
, y1
);
222 CalcBoundingBox (x2
, y2
);
225 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
229 long xx
= XLOG2DEV(x
);
230 long yy
= YLOG2DEV(y
);
231 long ww
= m_signX
* XLOG2DEVREL(width
);
232 long hh
= m_signY
* YLOG2DEVREL(height
);
234 // CMB: handle -ve width and/or height
235 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
236 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
238 long start
= long(sa
* 64.0);
239 long end
= long(ea
* 64.0);
240 if (m_brush
.GetStyle() != wxTRANSPARENT
)
241 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
243 if (m_pen
.GetStyle() != wxTRANSPARENT
)
244 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
246 CalcBoundingBox (x
, y
);
247 CalcBoundingBox (x
+ width
, y
+ height
);
250 void wxPaintDC::DrawPoint( long x
, long y
)
254 if (m_pen
.GetStyle() != wxTRANSPARENT
)
255 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
257 CalcBoundingBox (x
, y
);
260 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
264 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
267 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
269 for (int i
= 0; i
< n
-1; i
++)
271 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
272 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
273 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
274 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
275 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
277 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
281 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
285 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
287 wxNode
*node
= points
->First();
290 wxPoint
*pt
= (wxPoint
*)node
->Data();
291 CalcBoundingBox( pt
->x
+ xoffset
, pt
->y
+ yoffset
);
295 wxPoint
*point
= (wxPoint
*)node
->Data();
296 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
297 long x1
= XLOG2DEV(point
->x
+ xoffset
);
298 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
299 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and a waste again...
300 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
301 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
304 CalcBoundingBox( npoint
->x
+ xoffset
, npoint
->y
+ yoffset
);
308 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
314 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
316 for (i
= 0 ; i
< n
; i
++)
318 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
319 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
321 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
324 if (m_brush
.GetStyle() != wxTRANSPARENT
)
325 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
329 if (m_pen
.GetStyle() != wxTRANSPARENT
)
330 for (i
= 0 ; i
< n
; i
++)
332 gdk_draw_line( m_window
, m_penGC
,
335 gdkpoints
[(i
+1)%n
].x
,
336 gdkpoints
[(i
+1)%n
].y
);
342 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
346 int n
= lines
->Number();
349 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
350 wxNode
*node
= lines
->First();
354 wxPoint
*p
= (wxPoint
*) node
->Data();
355 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
356 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
360 CalcBoundingBox( p
->x
+ xoffset
, p
->y
+ yoffset
);
363 if (m_brush
.GetStyle() != wxTRANSPARENT
)
364 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
368 if (m_pen
.GetStyle() != wxTRANSPARENT
)
371 for (i
= 0 ; i
< n
; i
++)
373 gdk_draw_line( m_window
, m_penGC
,
376 gdkpoints
[(i
+1)%n
].x
,
377 gdkpoints
[(i
+1)%n
].y
);
383 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
387 long xx
= XLOG2DEV(x
);
388 long yy
= YLOG2DEV(y
);
389 long ww
= m_signX
* XLOG2DEVREL(width
);
390 long hh
= m_signY
* YLOG2DEVREL(height
);
392 // CMB: draw nothing if transformed w or h is 0
393 if (ww
== 0 || hh
== 0) return;
395 // CMB: handle -ve width and/or height
396 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
397 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
399 if (m_brush
.GetStyle() != wxTRANSPARENT
)
400 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
402 if (m_pen
.GetStyle() != wxTRANSPARENT
)
403 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
405 CalcBoundingBox( x
, y
);
406 CalcBoundingBox( x
+ width
, y
+ height
);
409 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
413 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
415 long xx
= XLOG2DEV(x
);
416 long yy
= YLOG2DEV(y
);
417 long ww
= m_signX
* XLOG2DEVREL(width
);
418 long hh
= m_signY
* YLOG2DEVREL(height
);
419 long rr
= XLOG2DEVREL((long)radius
);
421 // CMB: handle -ve width and/or height
422 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
423 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
425 // CMB: if radius is zero use DrawRectangle() instead to avoid
426 // X drawing errors with small radii
429 DrawRectangle( x
, y
, width
, height
);
433 // CMB: draw nothing if transformed w or h is 0
434 if (ww
== 0 || hh
== 0) return;
436 // CMB: adjust size if outline is drawn otherwise the result is
437 // 1 pixel too wide and high
438 if (m_pen
.GetStyle() != wxTRANSPARENT
)
444 // CMB: ensure dd is not larger than rectangle otherwise we
445 // get an hour glass shape
447 if (dd
> ww
) dd
= ww
;
448 if (dd
> hh
) dd
= hh
;
451 if (m_brush
.GetStyle() != wxTRANSPARENT
)
453 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
454 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
455 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
456 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
457 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
458 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
461 if (m_pen
.GetStyle() != wxTRANSPARENT
)
463 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
464 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
465 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
466 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
467 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
468 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
469 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
470 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
473 // this ignores the radius
474 CalcBoundingBox( x
, y
);
475 CalcBoundingBox( x
+ width
, y
+ height
);
478 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
482 long xx
= XLOG2DEV(x
);
483 long yy
= YLOG2DEV(y
);
484 long ww
= m_signX
* XLOG2DEVREL(width
);
485 long hh
= m_signY
* YLOG2DEVREL(height
);
487 // CMB: handle -ve width and/or height
488 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
489 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
491 if (m_brush
.GetStyle() != wxTRANSPARENT
)
492 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
494 if (m_pen
.GetStyle() != wxTRANSPARENT
)
495 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
497 CalcBoundingBox( x
, y
);
498 CalcBoundingBox( x
+ width
, y
+ height
);
501 bool wxPaintDC::CanDrawBitmap(void) const
506 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
510 if (!icon
.Ok()) return;
512 int xx
= XLOG2DEV(x
);
513 int yy
= YLOG2DEV(y
);
515 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
516 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
520 gdk_gc_set_clip_mask( m_penGC
, mask
);
521 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
524 GdkPixmap
*pm
= icon
.GetPixmap();
525 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
529 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
530 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
533 CalcBoundingBox( x
, y
);
534 int width
= icon
.GetWidth();
535 int height
= icon
.GetHeight();
536 CalcBoundingBox( x
+ width
, y
+ height
);
539 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
540 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
542 if (!Ok()) return FALSE
;
544 CalcBoundingBox( xdest
, ydest
);
545 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
547 wxClientDC
*csrc
= (wxClientDC
*)source
;
551 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
552 GdkPixmap
* pmap
= srcDC
->m_selected
.GetPixmap();
555 long xx
= XLOG2DEV(xdest
);
556 long yy
= YLOG2DEV(ydest
);
558 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
559 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
563 gdk_gc_set_clip_mask( m_textGC
, mask
);
564 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
567 gdk_draw_pixmap( m_window
, m_textGC
, pmap
,
568 source
->DeviceToLogicalX(xsrc
),
569 source
->DeviceToLogicalY(ysrc
),
572 source
->DeviceToLogicalXRel(width
),
573 source
->DeviceToLogicalYRel(height
) );
577 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
578 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
584 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
587 long xx
= XLOG2DEV(xdest
);
588 long yy
= YLOG2DEV(ydest
);
590 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
591 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
595 gdk_gc_set_clip_mask( m_textGC
, mask
);
596 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
599 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
600 source
->DeviceToLogicalX(xsrc
),
601 source
->DeviceToLogicalY(ysrc
),
604 source
->DeviceToLogicalXRel(width
),
605 source
->DeviceToLogicalYRel(height
) );
609 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
610 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
617 gdk_window_copy_area ( m_window
, m_textGC
,
618 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
620 source
->DeviceToLogicalX(xsrc
),
621 source
->DeviceToLogicalY(ysrc
),
622 source
->DeviceToLogicalXRel(width
),
623 source
->DeviceToLogicalYRel(height
) );
626 gdk_window_copy_area ( m_window, m_textGC,
627 XLOG2DEV(xdest), YLOG2DEV(ydest),
636 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
640 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
645 // CMB 21/5/98: draw text background if mode is wxSOLID
646 if (m_backgroundMode
== wxSOLID
)
648 long width
= gdk_string_width( font
, text
);
649 long height
= font
->ascent
+ font
->descent
;
650 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
651 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
652 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
654 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
656 // CMB 17/7/98: simple underline: ignores scaling and underlying
657 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
658 // properties (see wxXt implementation)
659 if (m_font
.GetUnderlined())
661 long width
= gdk_string_width( font
, text
);
662 long ul_y
= y
+ font
->ascent
;
663 if (font
->descent
> 0) ul_y
++;
664 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
668 GetTextExtent (text
, &w
, &h
);
669 CalcBoundingBox (x
+ w
, y
+ h
);
670 CalcBoundingBox (x
, y
);
673 bool wxPaintDC::CanGetTextExtent(void) const
678 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
679 long *descent
, long *externalLeading
,
680 wxFont
*theFont
, bool WXUNUSED(use16
) )
684 wxFont fontToUse
= m_font
;
685 if (theFont
) fontToUse
= *theFont
;
687 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
688 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
689 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
690 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
691 if (externalLeading
) (*externalLeading
) = 0; // ??
694 long wxPaintDC::GetCharWidth(void)
698 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
699 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
702 long wxPaintDC::GetCharHeight(void)
706 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
707 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
710 void wxPaintDC::Clear(void)
716 gdk_window_clear( m_window
);
721 GetSize( &width
, &height
);
722 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
726 void wxPaintDC::SetFont( const wxFont
&font
)
733 void wxPaintDC::SetPen( const wxPen
&pen
)
737 if (m_pen
== pen
) return;
741 if (!m_pen
.Ok()) return;
743 gint width
= m_pen
.GetWidth();
744 // CMB: if width is non-zero scale it with the dc
751 // X doesn't allow different width in x and y and so we take
753 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
757 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
758 switch (m_pen
.GetStyle())
760 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
761 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
762 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
763 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
764 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
767 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
768 switch (m_pen
.GetCap())
770 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
771 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
772 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
775 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
776 switch (m_pen
.GetJoin())
778 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
779 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
780 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
783 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
785 m_pen
.GetColour().CalcPixel( m_cmap
);
786 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
789 void wxPaintDC::SetBrush( const wxBrush
&brush
)
793 if (m_brush
== brush
) return;
797 if (!m_brush
.Ok()) return;
799 m_brush
.GetColour().CalcPixel( m_cmap
);
800 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
802 GdkFill fillStyle
= GDK_SOLID
;
803 switch (m_brush
.GetStyle())
809 fillStyle
= GDK_STIPPLED
;
812 gdk_gc_set_fill( m_brushGC
, fillStyle
);
814 if (m_brush
.GetStyle() == wxSTIPPLE
)
816 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
819 if (IS_HATCH(m_brush
.GetStyle()))
821 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
822 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
826 // CMB 21/7/98: Added SetBackground. Sets background brush
827 // for Clear() and bg colour for shapes filled with cross-hatch brush
828 void wxPaintDC::SetBackground( const wxBrush
&brush
)
832 if (m_backgroundBrush
== brush
) return;
834 m_backgroundBrush
= brush
;
836 if (!m_backgroundBrush
.Ok()) return;
838 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
839 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
840 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
841 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
842 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
844 GdkFill fillStyle
= GDK_SOLID
;
845 switch (m_backgroundBrush
.GetStyle())
851 fillStyle
= GDK_STIPPLED
;
854 gdk_gc_set_fill( m_bgGC
, fillStyle
);
856 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
858 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
861 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
863 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
864 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
868 void wxPaintDC::SetLogicalFunction( int function
)
870 if (m_logicalFunction
== function
) return;
871 GdkFunction mode
= GDK_COPY
;
874 case wxXOR
: mode
= GDK_INVERT
; break;
875 case wxINVERT
: mode
= GDK_INVERT
; break;
878 m_logicalFunction
= function
;
879 gdk_gc_set_function( m_penGC
, mode
);
880 gdk_gc_set_function( m_brushGC
, mode
);
881 gdk_gc_set_function( m_textGC
, mode
);
884 void wxPaintDC::SetTextForeground( const wxColour
&col
)
888 if (m_textForegroundColour
== col
) return;
890 m_textForegroundColour
= col
;
891 if (!m_textForegroundColour
.Ok()) return;
893 m_textForegroundColour
.CalcPixel( m_cmap
);
894 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
897 void wxPaintDC::SetTextBackground( const wxColour
&col
)
901 if (m_textBackgroundColour
== col
) return;
903 m_textBackgroundColour
= col
;
904 if (!m_textBackgroundColour
.Ok()) return;
906 m_textBackgroundColour
.CalcPixel( m_cmap
);
907 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
910 void wxPaintDC::SetBackgroundMode( int mode
)
912 m_backgroundMode
= mode
;
914 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
915 // transparent/solid background mode
916 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
918 gdk_gc_set_fill( m_brushGC
,
919 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
923 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
927 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
929 wxDC::SetClippingRegion( x
, y
, width
, height
);
932 rect
.x
= XLOG2DEV(x
);
933 rect
.y
= YLOG2DEV(y
);
934 rect
.width
= XLOG2DEVREL(width
);
935 rect
.height
= YLOG2DEVREL(height
);
936 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
937 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
938 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
939 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
942 void wxPaintDC::DestroyClippingRegion(void)
944 wxDC::DestroyClippingRegion();
946 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
947 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
948 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
949 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
952 void wxPaintDC::SetUpDC(void)
956 m_logicalFunction
= wxCOPY
;
957 m_penGC
= gdk_gc_new( m_window
);
958 m_brushGC
= gdk_gc_new( m_window
);
959 m_textGC
= gdk_gc_new( m_window
);
960 m_bgGC
= gdk_gc_new( m_window
);
962 wxColour
tmp_col( m_textForegroundColour
);
963 m_textForegroundColour
= wxNullColour
;
964 SetTextForeground( tmp_col
);
965 tmp_col
= m_textBackgroundColour
;
966 m_textBackgroundColour
= wxNullColour
;
967 SetTextBackground( tmp_col
);
969 wxPen
tmp_pen( m_pen
);
973 wxFont
tmp_font( m_font
);
977 wxBrush
tmp_brush( m_brush
);
978 m_brush
= wxNullBrush
;
979 SetBrush( tmp_brush
);
981 tmp_brush
= m_backgroundBrush
;
982 m_backgroundBrush
= wxNullBrush
;
983 SetBackground( tmp_brush
);
987 hatch_bitmap
= hatches
;
988 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
989 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
990 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
991 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
992 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
993 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
997 void wxPaintDC::Destroy(void)
999 if (m_penGC
) gdk_gc_unref( m_penGC
);
1000 m_penGC
= (GdkGC
*) NULL
;
1001 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
1002 m_brushGC
= (GdkGC
*) NULL
;
1003 if (m_textGC
) gdk_gc_unref( m_textGC
);
1004 m_textGC
= (GdkGC
*) NULL
;
1005 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
1006 m_bgGC
= (GdkGC
*) NULL
;
1009 GdkWindow
*wxPaintDC::GetWindow(void)
1014 // ----------------------------------- spline code ----------------------------------------
1016 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
1017 double a3
, double b3
, double a4
, double b4
);
1018 void wx_clear_stack(void);
1019 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
1020 double *y3
, double *x4
, double *y4
);
1021 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
1022 double x4
, double y4
);
1023 static bool wx_spline_add_point(double x
, double y
);
1024 static void wx_spline_draw_point_array(wxDC
*dc
);
1026 wxList wx_spline_point_list
;
1028 #define half(z1, z2) ((z1+z2)/2.0)
1031 /* iterative version */
1033 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
1036 register double xmid
, ymid
;
1037 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1040 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
1042 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
1043 xmid
= (double)half(x2
, x3
);
1044 ymid
= (double)half(y2
, y3
);
1045 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
1046 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
1047 wx_spline_add_point( x1
, y1
);
1048 wx_spline_add_point( xmid
, ymid
);
1050 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
1051 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
1052 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
1053 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
1058 /* utilities used by spline drawing routines */
1060 typedef struct wx_spline_stack_struct
{
1061 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1064 #define SPLINE_STACK_DEPTH 20
1065 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1066 static Stack
*wx_stack_top
;
1067 static int wx_stack_count
;
1069 void wx_clear_stack(void)
1071 wx_stack_top
= wx_spline_stack
;
1075 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1077 wx_stack_top
->x1
= x1
;
1078 wx_stack_top
->y1
= y1
;
1079 wx_stack_top
->x2
= x2
;
1080 wx_stack_top
->y2
= y2
;
1081 wx_stack_top
->x3
= x3
;
1082 wx_stack_top
->y3
= y3
;
1083 wx_stack_top
->x4
= x4
;
1084 wx_stack_top
->y4
= y4
;
1089 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1090 double *x3
, double *y3
, double *x4
, double *y4
)
1092 if (wx_stack_count
== 0)
1096 *x1
= wx_stack_top
->x1
;
1097 *y1
= wx_stack_top
->y1
;
1098 *x2
= wx_stack_top
->x2
;
1099 *y2
= wx_stack_top
->y2
;
1100 *x3
= wx_stack_top
->x3
;
1101 *y3
= wx_stack_top
->y3
;
1102 *x4
= wx_stack_top
->x4
;
1103 *y4
= wx_stack_top
->y4
;
1107 static bool wx_spline_add_point(double x
, double y
)
1109 wxPoint
*point
= new wxPoint
;
1112 wx_spline_point_list
.Append((wxObject
*)point
);
1116 static void wx_spline_draw_point_array(wxDC
*dc
)
1118 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1119 wxNode
*node
= wx_spline_point_list
.First();
1122 wxPoint
*point
= (wxPoint
*)node
->Data();
1125 node
= wx_spline_point_list
.First();
1129 void wxPaintDC::DrawSpline( wxList
*points
)
1132 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1133 double x1
, y1
, x2
, y2
;
1135 wxNode
*node
= points
->First();
1136 p
= (wxPoint
*)node
->Data();
1141 node
= node
->Next();
1142 p
= (wxPoint
*)node
->Data();
1146 cx1
= (double)((x1
+ x2
) / 2);
1147 cy1
= (double)((y1
+ y2
) / 2);
1148 cx2
= (double)((cx1
+ x2
) / 2);
1149 cy2
= (double)((cy1
+ y2
) / 2);
1151 wx_spline_add_point(x1
, y1
);
1153 while ((node
= node
->Next()) != NULL
)
1155 p
= (wxPoint
*)node
->Data();
1160 cx4
= (double)(x1
+ x2
) / 2;
1161 cy4
= (double)(y1
+ y2
) / 2;
1162 cx3
= (double)(x1
+ cx4
) / 2;
1163 cy3
= (double)(y1
+ cy4
) / 2;
1165 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1169 cx2
= (double)(cx1
+ x2
) / 2;
1170 cy2
= (double)(cy1
+ y2
) / 2;
1173 wx_spline_add_point( cx1
, cy1
);
1174 wx_spline_add_point( x2
, y2
);
1176 wx_spline_draw_point_array( this );