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(wxWindowDC
,wxDC
)
87 wxWindowDC::wxWindowDC(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 wxWindowDC::wxWindowDC( 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
);
121 wxWindowDC::~wxWindowDC(void)
126 void wxWindowDC::FloodFill( long WXUNUSED(x
), long WXUNUSED(y
),
127 const wxColour
&WXUNUSED(col
), int WXUNUSED(style
) )
129 wxFAIL_MSG( "wxWindowDC::FloodFill not implemented" );
132 bool wxWindowDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
134 wxFAIL_MSG( "wxWindowDC::GetPixel not implemented" );
138 void wxWindowDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
142 if (m_pen
.GetStyle() != wxTRANSPARENT
)
144 gdk_draw_line( m_window
, m_penGC
,
145 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
147 CalcBoundingBox(x1
, y1
);
148 CalcBoundingBox(x2
, y2
);
152 void wxWindowDC::CrossHair( long x
, long y
)
156 if (m_pen
.GetStyle() != wxTRANSPARENT
)
161 long xx
= XLOG2DEV(x
);
162 long yy
= YLOG2DEV(y
);
163 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
164 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
168 void wxWindowDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
172 long xx1
= XLOG2DEV(x1
);
173 long yy1
= YLOG2DEV(y1
);
174 long xx2
= XLOG2DEV(x2
);
175 long yy2
= YLOG2DEV(y2
);
176 long xxc
= XLOG2DEV((long)xc
);
177 long yyc
= YLOG2DEV((long)yc
);
178 double dx
= xx1
- xxc
;
179 double dy
= yy1
- yyc
;
180 double radius
= sqrt(dx
*dx
+dy
*dy
);
181 long r
= (long)radius
;
182 double radius1
, radius2
;
184 if (xx1
== xx2
&& yy1
== yy2
)
192 radius1
= radius2
= 0.0;
196 radius1
= (xx1
- xxc
== 0) ?
197 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
198 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
199 radius2
= (xx2
- xxc
== 0) ?
200 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
201 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
203 long alpha1
= long(radius1
* 64.0);
204 long alpha2
= long((radius2
- radius1
) * 64.0);
205 while (alpha2
<= 0) alpha2
+= 360*64;
206 while (alpha1
> 360*64) alpha1
-= 360*64;
208 if (m_brush
.GetStyle() != wxTRANSPARENT
)
209 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
211 if (m_pen
.GetStyle() != wxTRANSPARENT
)
212 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
214 CalcBoundingBox (x1
, y1
);
215 CalcBoundingBox (x2
, y2
);
218 void wxWindowDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
222 long xx
= XLOG2DEV(x
);
223 long yy
= YLOG2DEV(y
);
224 long ww
= m_signX
* XLOG2DEVREL(width
);
225 long hh
= m_signY
* YLOG2DEVREL(height
);
227 // CMB: handle -ve width and/or height
228 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
229 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
231 long start
= long(sa
* 64.0);
232 long end
= long(ea
* 64.0);
233 if (m_brush
.GetStyle() != wxTRANSPARENT
)
234 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
236 if (m_pen
.GetStyle() != wxTRANSPARENT
)
237 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
239 CalcBoundingBox (x
, y
);
240 CalcBoundingBox (x
+ width
, y
+ height
);
243 void wxWindowDC::DrawPoint( long x
, long y
)
247 if (m_pen
.GetStyle() != wxTRANSPARENT
)
248 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
250 CalcBoundingBox (x
, y
);
253 void wxWindowDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
257 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
260 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
262 for (int i
= 0; i
< n
-1; i
++)
264 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
265 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
266 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
267 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
268 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
270 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
274 void wxWindowDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
278 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
280 wxNode
*node
= points
->First();
283 wxPoint
*pt
= (wxPoint
*)node
->Data();
284 CalcBoundingBox( pt
->x
+ xoffset
, pt
->y
+ yoffset
);
288 wxPoint
*point
= (wxPoint
*)node
->Data();
289 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
290 long x1
= XLOG2DEV(point
->x
+ xoffset
);
291 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
292 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and a waste again...
293 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
294 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
297 CalcBoundingBox( npoint
->x
+ xoffset
, npoint
->y
+ yoffset
);
301 void wxWindowDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
307 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
309 for (i
= 0 ; i
< n
; i
++)
311 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
312 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
314 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
317 if (m_brush
.GetStyle() != wxTRANSPARENT
)
318 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
322 if (m_pen
.GetStyle() != wxTRANSPARENT
)
323 for (i
= 0 ; i
< n
; i
++)
325 gdk_draw_line( m_window
, m_penGC
,
328 gdkpoints
[(i
+1)%n
].x
,
329 gdkpoints
[(i
+1)%n
].y
);
335 void wxWindowDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
339 int n
= lines
->Number();
342 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
343 wxNode
*node
= lines
->First();
347 wxPoint
*p
= (wxPoint
*) node
->Data();
348 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
349 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
353 CalcBoundingBox( p
->x
+ xoffset
, p
->y
+ yoffset
);
356 if (m_brush
.GetStyle() != wxTRANSPARENT
)
357 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
361 if (m_pen
.GetStyle() != wxTRANSPARENT
)
364 for (i
= 0 ; i
< n
; i
++)
366 gdk_draw_line( m_window
, m_penGC
,
369 gdkpoints
[(i
+1)%n
].x
,
370 gdkpoints
[(i
+1)%n
].y
);
376 void wxWindowDC::DrawRectangle( long x
, long y
, long width
, long height
)
380 long xx
= XLOG2DEV(x
);
381 long yy
= YLOG2DEV(y
);
382 long ww
= m_signX
* XLOG2DEVREL(width
);
383 long hh
= m_signY
* YLOG2DEVREL(height
);
385 // CMB: draw nothing if transformed w or h is 0
386 if (ww
== 0 || hh
== 0) return;
388 // CMB: handle -ve width and/or height
389 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
390 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
392 if (m_brush
.GetStyle() != wxTRANSPARENT
)
393 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
395 if (m_pen
.GetStyle() != wxTRANSPARENT
)
396 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
398 CalcBoundingBox( x
, y
);
399 CalcBoundingBox( x
+ width
, y
+ height
);
402 void wxWindowDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
406 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
408 long xx
= XLOG2DEV(x
);
409 long yy
= YLOG2DEV(y
);
410 long ww
= m_signX
* XLOG2DEVREL(width
);
411 long hh
= m_signY
* YLOG2DEVREL(height
);
412 long rr
= XLOG2DEVREL((long)radius
);
414 // CMB: handle -ve width and/or height
415 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
416 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
418 // CMB: if radius is zero use DrawRectangle() instead to avoid
419 // X drawing errors with small radii
422 DrawRectangle( x
, y
, width
, height
);
426 // CMB: draw nothing if transformed w or h is 0
427 if (ww
== 0 || hh
== 0) return;
429 // CMB: adjust size if outline is drawn otherwise the result is
430 // 1 pixel too wide and high
431 if (m_pen
.GetStyle() != wxTRANSPARENT
)
437 // CMB: ensure dd is not larger than rectangle otherwise we
438 // get an hour glass shape
440 if (dd
> ww
) dd
= ww
;
441 if (dd
> hh
) dd
= hh
;
444 if (m_brush
.GetStyle() != wxTRANSPARENT
)
446 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
447 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
448 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
449 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
450 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
451 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
454 if (m_pen
.GetStyle() != wxTRANSPARENT
)
456 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
457 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
458 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
459 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
460 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
461 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
462 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
463 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
466 // this ignores the radius
467 CalcBoundingBox( x
, y
);
468 CalcBoundingBox( x
+ width
, y
+ height
);
471 void wxWindowDC::DrawEllipse( long x
, long y
, long width
, long height
)
475 long xx
= XLOG2DEV(x
);
476 long yy
= YLOG2DEV(y
);
477 long ww
= m_signX
* XLOG2DEVREL(width
);
478 long hh
= m_signY
* YLOG2DEVREL(height
);
480 // CMB: handle -ve width and/or height
481 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
482 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
484 if (m_brush
.GetStyle() != wxTRANSPARENT
)
485 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
487 if (m_pen
.GetStyle() != wxTRANSPARENT
)
488 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
490 CalcBoundingBox( x
- width
, y
- height
);
491 CalcBoundingBox( x
+ width
, y
+ height
);
494 bool wxWindowDC::CanDrawBitmap(void) const
499 void wxWindowDC::DrawIcon( const wxIcon
&icon
, long x
, long y
)
503 if (!icon
.Ok()) return;
505 int xx
= XLOG2DEV(x
);
506 int yy
= YLOG2DEV(y
);
508 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
509 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
513 gdk_gc_set_clip_mask( m_penGC
, mask
);
514 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
517 GdkPixmap
*pm
= icon
.GetPixmap();
518 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
522 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
523 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
526 CalcBoundingBox( x
, y
);
527 int width
= icon
.GetWidth();
528 int height
= icon
.GetHeight();
529 CalcBoundingBox( x
+ width
, y
+ height
);
532 void wxWindowDC::DrawBitmap( const wxBitmap
&bitmap
, long x
, long y
, bool useMask
)
536 if (!bitmap
.Ok()) return;
538 int xx
= XLOG2DEV(x
);
539 int yy
= YLOG2DEV(y
);
541 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
542 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
546 gdk_gc_set_clip_mask( m_penGC
, mask
);
547 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
550 GdkPixmap
*pm
= bitmap
.GetPixmap();
551 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
555 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
556 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
559 CalcBoundingBox( x
, y
);
560 int width
= bitmap
.GetWidth();
561 int height
= bitmap
.GetHeight();
562 CalcBoundingBox( x
+ width
, y
+ height
);
565 bool wxWindowDC::Blit( long xdest
, long ydest
, long width
, long height
,
566 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
568 if (!Ok()) return FALSE
;
570 CalcBoundingBox( xdest
, ydest
);
571 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
573 wxClientDC
*csrc
= (wxClientDC
*)source
;
577 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
578 GdkPixmap
* pmap
= srcDC
->m_selected
.GetPixmap();
581 long xx
= XLOG2DEV(xdest
);
582 long yy
= YLOG2DEV(ydest
);
584 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
585 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
589 gdk_gc_set_clip_mask( m_textGC
, mask
);
590 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
593 gdk_draw_pixmap( m_window
, m_textGC
, pmap
,
594 source
->DeviceToLogicalX(xsrc
),
595 source
->DeviceToLogicalY(ysrc
),
598 source
->DeviceToLogicalXRel(width
),
599 source
->DeviceToLogicalYRel(height
) );
603 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
604 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
610 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
613 long xx
= XLOG2DEV(xdest
);
614 long yy
= YLOG2DEV(ydest
);
616 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
617 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
621 gdk_gc_set_clip_mask( m_textGC
, mask
);
622 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
625 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
626 source
->DeviceToLogicalX(xsrc
),
627 source
->DeviceToLogicalY(ysrc
),
630 source
->DeviceToLogicalXRel(width
),
631 source
->DeviceToLogicalYRel(height
) );
635 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
636 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
643 gdk_window_copy_area ( m_window
, m_textGC
,
644 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
646 source
->DeviceToLogicalX(xsrc
),
647 source
->DeviceToLogicalY(ysrc
),
648 source
->DeviceToLogicalXRel(width
),
649 source
->DeviceToLogicalYRel(height
) );
652 gdk_window_copy_area ( m_window, m_textGC,
653 XLOG2DEV(xdest), YLOG2DEV(ydest),
662 void wxWindowDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
666 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
671 // CMB 21/5/98: draw text background if mode is wxSOLID
672 if (m_backgroundMode
== wxSOLID
)
674 long width
= gdk_string_width( font
, text
);
675 long height
= font
->ascent
+ font
->descent
;
676 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
677 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
678 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
680 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
682 // CMB 17/7/98: simple underline: ignores scaling and underlying
683 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
684 // properties (see wxXt implementation)
685 if (m_font
.GetUnderlined())
687 long width
= gdk_string_width( font
, text
);
688 long ul_y
= y
+ font
->ascent
;
689 if (font
->descent
> 0) ul_y
++;
690 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
694 GetTextExtent (text
, &w
, &h
);
695 CalcBoundingBox (x
+ w
, y
+ h
);
696 CalcBoundingBox (x
, y
);
699 bool wxWindowDC::CanGetTextExtent(void) const
704 void wxWindowDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
705 long *descent
, long *externalLeading
,
706 wxFont
*theFont
, bool WXUNUSED(use16
) )
710 wxFont fontToUse
= m_font
;
711 if (theFont
) fontToUse
= *theFont
;
713 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
714 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
715 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
716 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
717 if (externalLeading
) (*externalLeading
) = 0; // ??
720 long wxWindowDC::GetCharWidth(void)
724 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
725 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
728 long wxWindowDC::GetCharHeight(void)
732 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
733 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
736 void wxWindowDC::Clear(void)
742 gdk_window_clear( m_window
);
747 GetSize( &width
, &height
);
748 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
752 void wxWindowDC::SetFont( const wxFont
&font
)
759 void wxWindowDC::SetPen( const wxPen
&pen
)
763 if (m_pen
== pen
) return;
767 if (!m_pen
.Ok()) return;
769 gint width
= m_pen
.GetWidth();
770 // CMB: if width is non-zero scale it with the dc
777 // X doesn't allow different width in x and y and so we take
779 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
783 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
784 switch (m_pen
.GetStyle())
786 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
787 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
788 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
789 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
790 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
793 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
794 switch (m_pen
.GetCap())
796 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
797 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
798 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
801 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
802 switch (m_pen
.GetJoin())
804 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
805 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
806 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
809 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
811 m_pen
.GetColour().CalcPixel( m_cmap
);
812 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
815 void wxWindowDC::SetBrush( const wxBrush
&brush
)
819 if (m_brush
== brush
) return;
823 if (!m_brush
.Ok()) return;
825 m_brush
.GetColour().CalcPixel( m_cmap
);
826 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
828 GdkFill fillStyle
= GDK_SOLID
;
829 switch (m_brush
.GetStyle())
835 fillStyle
= GDK_STIPPLED
;
838 gdk_gc_set_fill( m_brushGC
, fillStyle
);
840 if (m_brush
.GetStyle() == wxSTIPPLE
)
842 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
845 if (IS_HATCH(m_brush
.GetStyle()))
847 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
848 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
852 // CMB 21/7/98: Added SetBackground. Sets background brush
853 // for Clear() and bg colour for shapes filled with cross-hatch brush
854 void wxWindowDC::SetBackground( const wxBrush
&brush
)
858 if (m_backgroundBrush
== brush
) return;
860 m_backgroundBrush
= brush
;
862 if (!m_backgroundBrush
.Ok()) return;
864 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
865 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
866 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
867 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
868 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
870 GdkFill fillStyle
= GDK_SOLID
;
871 switch (m_backgroundBrush
.GetStyle())
877 fillStyle
= GDK_STIPPLED
;
880 gdk_gc_set_fill( m_bgGC
, fillStyle
);
882 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
884 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
887 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
889 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
890 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
894 void wxWindowDC::SetLogicalFunction( int function
)
896 if (m_logicalFunction
== function
) return;
897 GdkFunction mode
= GDK_COPY
;
900 case wxXOR
: mode
= GDK_INVERT
; break;
901 case wxINVERT
: mode
= GDK_INVERT
; break;
904 m_logicalFunction
= function
;
905 gdk_gc_set_function( m_penGC
, mode
);
906 gdk_gc_set_function( m_brushGC
, mode
);
907 gdk_gc_set_function( m_textGC
, mode
);
910 void wxWindowDC::SetTextForeground( const wxColour
&col
)
914 if (m_textForegroundColour
== col
) return;
916 m_textForegroundColour
= col
;
917 if (!m_textForegroundColour
.Ok()) return;
919 m_textForegroundColour
.CalcPixel( m_cmap
);
920 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
923 void wxWindowDC::SetTextBackground( const wxColour
&col
)
927 if (m_textBackgroundColour
== col
) return;
929 m_textBackgroundColour
= col
;
930 if (!m_textBackgroundColour
.Ok()) return;
932 m_textBackgroundColour
.CalcPixel( m_cmap
);
933 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
936 void wxWindowDC::SetBackgroundMode( int mode
)
938 m_backgroundMode
= mode
;
940 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
941 // transparent/solid background mode
942 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
944 gdk_gc_set_fill( m_brushGC
,
945 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
949 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
953 void wxWindowDC::SetClippingRegion( long x
, long y
, long width
, long height
)
955 wxDC::SetClippingRegion( x
, y
, width
, height
);
958 rect
.x
= XLOG2DEV(x
);
959 rect
.y
= YLOG2DEV(y
);
960 rect
.width
= XLOG2DEVREL(width
);
961 rect
.height
= YLOG2DEVREL(height
);
962 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
963 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
964 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
965 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
968 void wxWindowDC::SetClippingRegion( const wxRegion
®ion
)
972 DestroyClippingRegion();
976 gdk_gc_set_clip_region( m_penGC
, region
.GetRegion() );
977 gdk_gc_set_clip_region( m_brushGC
, region
.GetRegion() );
978 gdk_gc_set_clip_region( m_textGC
, region
.GetRegion() );
979 gdk_gc_set_clip_region( m_bgGC
, region
.GetRegion() );
982 void wxWindowDC::DestroyClippingRegion(void)
984 wxDC::DestroyClippingRegion();
986 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
987 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
988 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
989 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
992 void wxWindowDC::SetUpDC(void)
996 m_logicalFunction
= wxCOPY
;
997 m_penGC
= gdk_gc_new( m_window
);
998 m_brushGC
= gdk_gc_new( m_window
);
999 m_textGC
= gdk_gc_new( m_window
);
1000 m_bgGC
= gdk_gc_new( m_window
);
1002 wxColour
tmp_col( m_textForegroundColour
);
1003 m_textForegroundColour
= wxNullColour
;
1004 SetTextForeground( tmp_col
);
1005 tmp_col
= m_textBackgroundColour
;
1006 m_textBackgroundColour
= wxNullColour
;
1007 SetTextBackground( tmp_col
);
1009 wxPen
tmp_pen( m_pen
);
1013 wxFont
tmp_font( m_font
);
1014 m_font
= wxNullFont
;
1015 SetFont( tmp_font
);
1017 wxBrush
tmp_brush( m_brush
);
1018 m_brush
= wxNullBrush
;
1019 SetBrush( tmp_brush
);
1021 tmp_brush
= m_backgroundBrush
;
1022 m_backgroundBrush
= wxNullBrush
;
1023 SetBackground( tmp_brush
);
1027 hatch_bitmap
= hatches
;
1028 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
1029 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
1030 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
1031 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
1032 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
1033 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
1037 void wxWindowDC::Destroy(void)
1039 if (m_penGC
) gdk_gc_unref( m_penGC
);
1040 m_penGC
= (GdkGC
*) NULL
;
1041 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
1042 m_brushGC
= (GdkGC
*) NULL
;
1043 if (m_textGC
) gdk_gc_unref( m_textGC
);
1044 m_textGC
= (GdkGC
*) NULL
;
1045 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
1046 m_bgGC
= (GdkGC
*) NULL
;
1049 GdkWindow
*wxWindowDC::GetWindow(void)
1054 // ----------------------------------- spline code ----------------------------------------
1056 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
1057 double a3
, double b3
, double a4
, double b4
);
1058 void wx_clear_stack(void);
1059 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
1060 double *y3
, double *x4
, double *y4
);
1061 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
1062 double x4
, double y4
);
1063 static bool wx_spline_add_point(double x
, double y
);
1064 static void wx_spline_draw_point_array(wxDC
*dc
);
1066 wxList wx_spline_point_list
;
1068 #define half(z1, z2) ((z1+z2)/2.0)
1071 /* iterative version */
1073 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
1076 register double xmid
, ymid
;
1077 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1080 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
1082 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
1083 xmid
= (double)half(x2
, x3
);
1084 ymid
= (double)half(y2
, y3
);
1085 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
1086 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
1087 wx_spline_add_point( x1
, y1
);
1088 wx_spline_add_point( xmid
, ymid
);
1090 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
1091 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
1092 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
1093 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
1098 /* utilities used by spline drawing routines */
1100 typedef struct wx_spline_stack_struct
{
1101 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1104 #define SPLINE_STACK_DEPTH 20
1105 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1106 static Stack
*wx_stack_top
;
1107 static int wx_stack_count
;
1109 void wx_clear_stack(void)
1111 wx_stack_top
= wx_spline_stack
;
1115 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1117 wx_stack_top
->x1
= x1
;
1118 wx_stack_top
->y1
= y1
;
1119 wx_stack_top
->x2
= x2
;
1120 wx_stack_top
->y2
= y2
;
1121 wx_stack_top
->x3
= x3
;
1122 wx_stack_top
->y3
= y3
;
1123 wx_stack_top
->x4
= x4
;
1124 wx_stack_top
->y4
= y4
;
1129 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1130 double *x3
, double *y3
, double *x4
, double *y4
)
1132 if (wx_stack_count
== 0)
1136 *x1
= wx_stack_top
->x1
;
1137 *y1
= wx_stack_top
->y1
;
1138 *x2
= wx_stack_top
->x2
;
1139 *y2
= wx_stack_top
->y2
;
1140 *x3
= wx_stack_top
->x3
;
1141 *y3
= wx_stack_top
->y3
;
1142 *x4
= wx_stack_top
->x4
;
1143 *y4
= wx_stack_top
->y4
;
1147 static bool wx_spline_add_point(double x
, double y
)
1149 wxPoint
*point
= new wxPoint
;
1152 wx_spline_point_list
.Append((wxObject
*)point
);
1156 static void wx_spline_draw_point_array(wxDC
*dc
)
1158 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1159 wxNode
*node
= wx_spline_point_list
.First();
1162 wxPoint
*point
= (wxPoint
*)node
->Data();
1165 node
= wx_spline_point_list
.First();
1169 void wxWindowDC::DrawSpline( wxList
*points
)
1172 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1173 double x1
, y1
, x2
, y2
;
1175 wxNode
*node
= points
->First();
1176 p
= (wxPoint
*)node
->Data();
1181 node
= node
->Next();
1182 p
= (wxPoint
*)node
->Data();
1186 cx1
= (double)((x1
+ x2
) / 2);
1187 cy1
= (double)((y1
+ y2
) / 2);
1188 cx2
= (double)((cx1
+ x2
) / 2);
1189 cy2
= (double)((cy1
+ y2
) / 2);
1191 wx_spline_add_point(x1
, y1
);
1193 while ((node
= node
->Next()) != NULL
)
1195 p
= (wxPoint
*)node
->Data();
1200 cx4
= (double)(x1
+ x2
) / 2;
1201 cy4
= (double)(y1
+ y2
) / 2;
1202 cx3
= (double)(x1
+ cx4
) / 2;
1203 cy3
= (double)(y1
+ cy4
) / 2;
1205 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1209 cx2
= (double)(cx1
+ x2
) / 2;
1210 cy2
= (double)(cy1
+ y2
) / 2;
1213 wx_spline_add_point( cx1
, cy1
);
1214 wx_spline_add_point( x2
, y2
);
1216 wx_spline_draw_point_array( this );
1220 //-----------------------------------------------------------------------------
1222 //-----------------------------------------------------------------------------
1224 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxWindowDC
)
1226 wxPaintDC::wxPaintDC(void)
1231 wxPaintDC::wxPaintDC( wxWindow
*win
)
1236 //-----------------------------------------------------------------------------
1238 //-----------------------------------------------------------------------------
1240 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
,wxWindowDC
)
1242 wxClientDC::wxClientDC(void)
1247 wxClientDC::wxClientDC( wxWindow
*win
)