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
);
120 wxRegion update = window->GetUpdateRegion();
121 if (update.Empty()) return;
123 gdk_gc_set_clip_region( m_penGC, update.GetRegion() );
124 gdk_gc_set_clip_region( m_brushGC, update.GetRegion() );
125 gdk_gc_set_clip_region( m_textGC, update.GetRegion() );
126 gdk_gc_set_clip_region( m_bgGC, update.GetRegion() );
130 wxWindowDC::~wxWindowDC(void)
135 void wxWindowDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
136 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
138 wxFAIL_MSG( "wxWindowDC::FloodFill not implemented" );
141 bool wxWindowDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
143 wxFAIL_MSG( "wxWindowDC::GetPixel not implemented" );
147 void wxWindowDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
151 if (m_pen
.GetStyle() != wxTRANSPARENT
)
153 gdk_draw_line( m_window
, m_penGC
,
154 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
157 CalcBoundingBox(x1
, y1
);
158 CalcBoundingBox(x2
, y2
);
161 void wxWindowDC::CrossHair( long x
, long y
)
165 if (m_pen
.GetStyle() != wxTRANSPARENT
)
170 long xx
= XLOG2DEV(x
);
171 long yy
= YLOG2DEV(y
);
172 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
173 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
177 void wxWindowDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
181 long xx1
= XLOG2DEV(x1
);
182 long yy1
= YLOG2DEV(y1
);
183 long xx2
= XLOG2DEV(x2
);
184 long yy2
= YLOG2DEV(y2
);
185 long xxc
= XLOG2DEV((long)xc
);
186 long yyc
= YLOG2DEV((long)yc
);
187 double dx
= xx1
- xxc
;
188 double dy
= yy1
- yyc
;
189 double radius
= sqrt(dx
*dx
+dy
*dy
);
190 long r
= (long)radius
;
191 double radius1
, radius2
;
193 if (xx1
== xx2
&& yy1
== yy2
)
201 radius1
= radius2
= 0.0;
205 radius1
= (xx1
- xxc
== 0) ?
206 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
207 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
208 radius2
= (xx2
- xxc
== 0) ?
209 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
210 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
212 long alpha1
= long(radius1
* 64.0);
213 long alpha2
= long((radius2
- radius1
) * 64.0);
214 while (alpha2
<= 0) alpha2
+= 360*64;
215 while (alpha1
> 360*64) alpha1
-= 360*64;
217 if (m_brush
.GetStyle() != wxTRANSPARENT
)
218 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
220 if (m_pen
.GetStyle() != wxTRANSPARENT
)
221 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
223 CalcBoundingBox (x1
, y1
);
224 CalcBoundingBox (x2
, y2
);
227 void wxWindowDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
231 long xx
= XLOG2DEV(x
);
232 long yy
= YLOG2DEV(y
);
233 long ww
= m_signX
* XLOG2DEVREL(width
);
234 long hh
= m_signY
* YLOG2DEVREL(height
);
236 // CMB: handle -ve width and/or height
237 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
238 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
240 long start
= long(sa
* 64.0);
241 long end
= long(ea
* 64.0);
242 if (m_brush
.GetStyle() != wxTRANSPARENT
)
243 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
245 if (m_pen
.GetStyle() != wxTRANSPARENT
)
246 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
248 CalcBoundingBox (x
, y
);
249 CalcBoundingBox (x
+ width
, y
+ height
);
252 void wxWindowDC::DrawPoint( long x
, long y
)
256 if (m_pen
.GetStyle() != wxTRANSPARENT
)
257 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
259 CalcBoundingBox (x
, y
);
262 void wxWindowDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
266 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
269 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
271 for (int i
= 0; i
< n
-1; i
++)
273 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
274 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
275 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
276 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
277 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
279 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
283 void wxWindowDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
287 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
289 wxNode
*node
= points
->First();
292 wxPoint
*pt
= (wxPoint
*)node
->Data();
293 CalcBoundingBox( pt
->x
+ xoffset
, pt
->y
+ yoffset
);
297 wxPoint
*point
= (wxPoint
*)node
->Data();
298 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
299 long x1
= XLOG2DEV(point
->x
+ xoffset
);
300 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
301 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and a waste again...
302 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
303 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
306 CalcBoundingBox( npoint
->x
+ xoffset
, npoint
->y
+ yoffset
);
310 void wxWindowDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
316 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
318 for (i
= 0 ; i
< n
; i
++)
320 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
321 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
323 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
326 if (m_brush
.GetStyle() != wxTRANSPARENT
)
327 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
331 if (m_pen
.GetStyle() != wxTRANSPARENT
)
332 for (i
= 0 ; i
< n
; i
++)
334 gdk_draw_line( m_window
, m_penGC
,
337 gdkpoints
[(i
+1)%n
].x
,
338 gdkpoints
[(i
+1)%n
].y
);
344 void wxWindowDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
348 int n
= lines
->Number();
351 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
352 wxNode
*node
= lines
->First();
356 wxPoint
*p
= (wxPoint
*) node
->Data();
357 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
358 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
362 CalcBoundingBox( p
->x
+ xoffset
, p
->y
+ yoffset
);
365 if (m_brush
.GetStyle() != wxTRANSPARENT
)
366 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
370 if (m_pen
.GetStyle() != wxTRANSPARENT
)
373 for (i
= 0 ; i
< n
; i
++)
375 gdk_draw_line( m_window
, m_penGC
,
378 gdkpoints
[(i
+1)%n
].x
,
379 gdkpoints
[(i
+1)%n
].y
);
385 void wxWindowDC::DrawRectangle( long x
, long y
, long width
, long height
)
389 long xx
= XLOG2DEV(x
);
390 long yy
= YLOG2DEV(y
);
391 long ww
= m_signX
* XLOG2DEVREL(width
);
392 long hh
= m_signY
* YLOG2DEVREL(height
);
394 // CMB: draw nothing if transformed w or h is 0
395 if (ww
== 0 || hh
== 0) return;
397 // CMB: handle -ve width and/or height
398 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
399 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
401 if (m_brush
.GetStyle() != wxTRANSPARENT
)
402 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
404 if (m_pen
.GetStyle() != wxTRANSPARENT
)
405 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
407 CalcBoundingBox( x
, y
);
408 CalcBoundingBox( x
+ width
, y
+ height
);
411 void wxWindowDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
415 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
417 long xx
= XLOG2DEV(x
);
418 long yy
= YLOG2DEV(y
);
419 long ww
= m_signX
* XLOG2DEVREL(width
);
420 long hh
= m_signY
* YLOG2DEVREL(height
);
421 long rr
= XLOG2DEVREL((long)radius
);
423 // CMB: handle -ve width and/or height
424 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
425 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
427 // CMB: if radius is zero use DrawRectangle() instead to avoid
428 // X drawing errors with small radii
431 DrawRectangle( x
, y
, width
, height
);
435 // CMB: draw nothing if transformed w or h is 0
436 if (ww
== 0 || hh
== 0) return;
438 // CMB: adjust size if outline is drawn otherwise the result is
439 // 1 pixel too wide and high
440 if (m_pen
.GetStyle() != wxTRANSPARENT
)
446 // CMB: ensure dd is not larger than rectangle otherwise we
447 // get an hour glass shape
449 if (dd
> ww
) dd
= ww
;
450 if (dd
> hh
) dd
= hh
;
453 if (m_brush
.GetStyle() != wxTRANSPARENT
)
455 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
456 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
457 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
458 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
459 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
460 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
463 if (m_pen
.GetStyle() != wxTRANSPARENT
)
465 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
466 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
467 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
468 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
469 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
470 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
471 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
472 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
475 // this ignores the radius
476 CalcBoundingBox( x
, y
);
477 CalcBoundingBox( x
+ width
, y
+ height
);
480 void wxWindowDC::DrawEllipse( long x
, long y
, long width
, long height
)
484 long xx
= XLOG2DEV(x
);
485 long yy
= YLOG2DEV(y
);
486 long ww
= m_signX
* XLOG2DEVREL(width
);
487 long hh
= m_signY
* YLOG2DEVREL(height
);
489 // CMB: handle -ve width and/or height
490 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
491 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
493 if (m_brush
.GetStyle() != wxTRANSPARENT
)
494 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
496 if (m_pen
.GetStyle() != wxTRANSPARENT
)
497 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
499 CalcBoundingBox( x
, y
);
500 CalcBoundingBox( x
+ width
, y
+ height
);
503 bool wxWindowDC::CanDrawBitmap(void) const
508 void wxWindowDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
512 if (!icon
.Ok()) return;
514 int xx
= XLOG2DEV(x
);
515 int yy
= YLOG2DEV(y
);
517 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
518 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
522 gdk_gc_set_clip_mask( m_penGC
, mask
);
523 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
526 GdkPixmap
*pm
= icon
.GetPixmap();
527 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
531 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
532 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
535 CalcBoundingBox( x
, y
);
536 int width
= icon
.GetWidth();
537 int height
= icon
.GetHeight();
538 CalcBoundingBox( x
+ width
, y
+ height
);
541 bool wxWindowDC::Blit( long xdest
, long ydest
, long width
, long height
,
542 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
544 if (!Ok()) return FALSE
;
546 CalcBoundingBox( xdest
, ydest
);
547 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
549 wxClientDC
*csrc
= (wxClientDC
*)source
;
553 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
554 GdkPixmap
* pmap
= srcDC
->m_selected
.GetPixmap();
557 long xx
= XLOG2DEV(xdest
);
558 long yy
= YLOG2DEV(ydest
);
560 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
561 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
565 gdk_gc_set_clip_mask( m_textGC
, mask
);
566 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
569 gdk_draw_pixmap( m_window
, m_textGC
, pmap
,
570 source
->DeviceToLogicalX(xsrc
),
571 source
->DeviceToLogicalY(ysrc
),
574 source
->DeviceToLogicalXRel(width
),
575 source
->DeviceToLogicalYRel(height
) );
579 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
580 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
586 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
589 long xx
= XLOG2DEV(xdest
);
590 long yy
= YLOG2DEV(ydest
);
592 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
593 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
597 gdk_gc_set_clip_mask( m_textGC
, mask
);
598 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
601 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
602 source
->DeviceToLogicalX(xsrc
),
603 source
->DeviceToLogicalY(ysrc
),
606 source
->DeviceToLogicalXRel(width
),
607 source
->DeviceToLogicalYRel(height
) );
611 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
612 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
619 gdk_window_copy_area ( m_window
, m_textGC
,
620 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
622 source
->DeviceToLogicalX(xsrc
),
623 source
->DeviceToLogicalY(ysrc
),
624 source
->DeviceToLogicalXRel(width
),
625 source
->DeviceToLogicalYRel(height
) );
628 gdk_window_copy_area ( m_window, m_textGC,
629 XLOG2DEV(xdest), YLOG2DEV(ydest),
638 void wxWindowDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
642 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
647 // CMB 21/5/98: draw text background if mode is wxSOLID
648 if (m_backgroundMode
== wxSOLID
)
650 long width
= gdk_string_width( font
, text
);
651 long height
= font
->ascent
+ font
->descent
;
652 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
653 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
654 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
656 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
658 // CMB 17/7/98: simple underline: ignores scaling and underlying
659 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
660 // properties (see wxXt implementation)
661 if (m_font
.GetUnderlined())
663 long width
= gdk_string_width( font
, text
);
664 long ul_y
= y
+ font
->ascent
;
665 if (font
->descent
> 0) ul_y
++;
666 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
670 GetTextExtent (text
, &w
, &h
);
671 CalcBoundingBox (x
+ w
, y
+ h
);
672 CalcBoundingBox (x
, y
);
675 bool wxWindowDC::CanGetTextExtent(void) const
680 void wxWindowDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
681 long *descent
, long *externalLeading
,
682 wxFont
*theFont
, bool WXUNUSED(use16
) )
686 wxFont fontToUse
= m_font
;
687 if (theFont
) fontToUse
= *theFont
;
689 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
690 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
691 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
692 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
693 if (externalLeading
) (*externalLeading
) = 0; // ??
696 long wxWindowDC::GetCharWidth(void)
700 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
701 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
704 long wxWindowDC::GetCharHeight(void)
708 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
709 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
712 void wxWindowDC::Clear(void)
718 gdk_window_clear( m_window
);
723 GetSize( &width
, &height
);
724 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
728 void wxWindowDC::SetFont( const wxFont
&font
)
735 void wxWindowDC::SetPen( const wxPen
&pen
)
739 if (m_pen
== pen
) return;
743 if (!m_pen
.Ok()) return;
745 gint width
= m_pen
.GetWidth();
746 // CMB: if width is non-zero scale it with the dc
753 // X doesn't allow different width in x and y and so we take
755 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
759 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
760 switch (m_pen
.GetStyle())
762 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
763 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
764 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
765 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
766 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
769 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
770 switch (m_pen
.GetCap())
772 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
773 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
774 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
777 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
778 switch (m_pen
.GetJoin())
780 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
781 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
782 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
785 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
787 m_pen
.GetColour().CalcPixel( m_cmap
);
788 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
791 void wxWindowDC::SetBrush( const wxBrush
&brush
)
795 if (m_brush
== brush
) return;
799 if (!m_brush
.Ok()) return;
801 m_brush
.GetColour().CalcPixel( m_cmap
);
802 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
804 GdkFill fillStyle
= GDK_SOLID
;
805 switch (m_brush
.GetStyle())
811 fillStyle
= GDK_STIPPLED
;
814 gdk_gc_set_fill( m_brushGC
, fillStyle
);
816 if (m_brush
.GetStyle() == wxSTIPPLE
)
818 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
821 if (IS_HATCH(m_brush
.GetStyle()))
823 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
824 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
828 // CMB 21/7/98: Added SetBackground. Sets background brush
829 // for Clear() and bg colour for shapes filled with cross-hatch brush
830 void wxWindowDC::SetBackground( const wxBrush
&brush
)
834 if (m_backgroundBrush
== brush
) return;
836 m_backgroundBrush
= brush
;
838 if (!m_backgroundBrush
.Ok()) return;
840 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
841 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
842 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
843 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
844 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
846 GdkFill fillStyle
= GDK_SOLID
;
847 switch (m_backgroundBrush
.GetStyle())
853 fillStyle
= GDK_STIPPLED
;
856 gdk_gc_set_fill( m_bgGC
, fillStyle
);
858 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
860 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
863 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
865 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
866 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
870 void wxWindowDC::SetLogicalFunction( int function
)
872 if (m_logicalFunction
== function
) return;
873 GdkFunction mode
= GDK_COPY
;
876 case wxXOR
: mode
= GDK_INVERT
; break;
877 case wxINVERT
: mode
= GDK_INVERT
; break;
880 m_logicalFunction
= function
;
881 gdk_gc_set_function( m_penGC
, mode
);
882 gdk_gc_set_function( m_brushGC
, mode
);
883 gdk_gc_set_function( m_textGC
, mode
);
886 void wxWindowDC::SetTextForeground( const wxColour
&col
)
890 if (m_textForegroundColour
== col
) return;
892 m_textForegroundColour
= col
;
893 if (!m_textForegroundColour
.Ok()) return;
895 m_textForegroundColour
.CalcPixel( m_cmap
);
896 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
899 void wxWindowDC::SetTextBackground( const wxColour
&col
)
903 if (m_textBackgroundColour
== col
) return;
905 m_textBackgroundColour
= col
;
906 if (!m_textBackgroundColour
.Ok()) return;
908 m_textBackgroundColour
.CalcPixel( m_cmap
);
909 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
912 void wxWindowDC::SetBackgroundMode( int mode
)
914 m_backgroundMode
= mode
;
916 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
917 // transparent/solid background mode
918 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
920 gdk_gc_set_fill( m_brushGC
,
921 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
925 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
929 void wxWindowDC::SetClippingRegion( long x
, long y
, long width
, long height
)
931 wxDC::SetClippingRegion( x
, y
, width
, height
);
934 rect
.x
= XLOG2DEV(x
);
935 rect
.y
= YLOG2DEV(y
);
936 rect
.width
= XLOG2DEVREL(width
);
937 rect
.height
= YLOG2DEVREL(height
);
938 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
939 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
940 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
941 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
944 void wxWindowDC::DestroyClippingRegion(void)
946 wxDC::DestroyClippingRegion();
948 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
949 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
950 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
951 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
954 void wxWindowDC::SetUpDC(void)
958 m_logicalFunction
= wxCOPY
;
959 m_penGC
= gdk_gc_new( m_window
);
960 m_brushGC
= gdk_gc_new( m_window
);
961 m_textGC
= gdk_gc_new( m_window
);
962 m_bgGC
= gdk_gc_new( m_window
);
964 wxColour
tmp_col( m_textForegroundColour
);
965 m_textForegroundColour
= wxNullColour
;
966 SetTextForeground( tmp_col
);
967 tmp_col
= m_textBackgroundColour
;
968 m_textBackgroundColour
= wxNullColour
;
969 SetTextBackground( tmp_col
);
971 wxPen
tmp_pen( m_pen
);
975 wxFont
tmp_font( m_font
);
979 wxBrush
tmp_brush( m_brush
);
980 m_brush
= wxNullBrush
;
981 SetBrush( tmp_brush
);
983 tmp_brush
= m_backgroundBrush
;
984 m_backgroundBrush
= wxNullBrush
;
985 SetBackground( tmp_brush
);
989 hatch_bitmap
= hatches
;
990 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
991 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
992 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
993 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
994 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
995 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
999 void wxWindowDC::Destroy(void)
1001 if (m_penGC
) gdk_gc_unref( m_penGC
);
1002 m_penGC
= (GdkGC
*) NULL
;
1003 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
1004 m_brushGC
= (GdkGC
*) NULL
;
1005 if (m_textGC
) gdk_gc_unref( m_textGC
);
1006 m_textGC
= (GdkGC
*) NULL
;
1007 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
1008 m_bgGC
= (GdkGC
*) NULL
;
1011 GdkWindow
*wxWindowDC::GetWindow(void)
1016 // ----------------------------------- spline code ----------------------------------------
1018 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
1019 double a3
, double b3
, double a4
, double b4
);
1020 void wx_clear_stack(void);
1021 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
1022 double *y3
, double *x4
, double *y4
);
1023 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
1024 double x4
, double y4
);
1025 static bool wx_spline_add_point(double x
, double y
);
1026 static void wx_spline_draw_point_array(wxDC
*dc
);
1028 wxList wx_spline_point_list
;
1030 #define half(z1, z2) ((z1+z2)/2.0)
1033 /* iterative version */
1035 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
1038 register double xmid
, ymid
;
1039 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1042 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
1044 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
1045 xmid
= (double)half(x2
, x3
);
1046 ymid
= (double)half(y2
, y3
);
1047 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
1048 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
1049 wx_spline_add_point( x1
, y1
);
1050 wx_spline_add_point( xmid
, ymid
);
1052 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
1053 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
1054 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
1055 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
1060 /* utilities used by spline drawing routines */
1062 typedef struct wx_spline_stack_struct
{
1063 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1066 #define SPLINE_STACK_DEPTH 20
1067 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1068 static Stack
*wx_stack_top
;
1069 static int wx_stack_count
;
1071 void wx_clear_stack(void)
1073 wx_stack_top
= wx_spline_stack
;
1077 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1079 wx_stack_top
->x1
= x1
;
1080 wx_stack_top
->y1
= y1
;
1081 wx_stack_top
->x2
= x2
;
1082 wx_stack_top
->y2
= y2
;
1083 wx_stack_top
->x3
= x3
;
1084 wx_stack_top
->y3
= y3
;
1085 wx_stack_top
->x4
= x4
;
1086 wx_stack_top
->y4
= y4
;
1091 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1092 double *x3
, double *y3
, double *x4
, double *y4
)
1094 if (wx_stack_count
== 0)
1098 *x1
= wx_stack_top
->x1
;
1099 *y1
= wx_stack_top
->y1
;
1100 *x2
= wx_stack_top
->x2
;
1101 *y2
= wx_stack_top
->y2
;
1102 *x3
= wx_stack_top
->x3
;
1103 *y3
= wx_stack_top
->y3
;
1104 *x4
= wx_stack_top
->x4
;
1105 *y4
= wx_stack_top
->y4
;
1109 static bool wx_spline_add_point(double x
, double y
)
1111 wxPoint
*point
= new wxPoint
;
1114 wx_spline_point_list
.Append((wxObject
*)point
);
1118 static void wx_spline_draw_point_array(wxDC
*dc
)
1120 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1121 wxNode
*node
= wx_spline_point_list
.First();
1124 wxPoint
*point
= (wxPoint
*)node
->Data();
1127 node
= wx_spline_point_list
.First();
1131 void wxWindowDC::DrawSpline( wxList
*points
)
1134 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1135 double x1
, y1
, x2
, y2
;
1137 wxNode
*node
= points
->First();
1138 p
= (wxPoint
*)node
->Data();
1143 node
= node
->Next();
1144 p
= (wxPoint
*)node
->Data();
1148 cx1
= (double)((x1
+ x2
) / 2);
1149 cy1
= (double)((y1
+ y2
) / 2);
1150 cx2
= (double)((cx1
+ x2
) / 2);
1151 cy2
= (double)((cy1
+ y2
) / 2);
1153 wx_spline_add_point(x1
, y1
);
1155 while ((node
= node
->Next()) != NULL
)
1157 p
= (wxPoint
*)node
->Data();
1162 cx4
= (double)(x1
+ x2
) / 2;
1163 cy4
= (double)(y1
+ y2
) / 2;
1164 cx3
= (double)(x1
+ cx4
) / 2;
1165 cy3
= (double)(y1
+ cy4
) / 2;
1167 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1171 cx2
= (double)(cx1
+ x2
) / 2;
1172 cy2
= (double)(cy1
+ y2
) / 2;
1175 wx_spline_add_point( cx1
, cy1
);
1176 wx_spline_add_point( x2
, y2
);
1178 wx_spline_draw_point_array( this );
1182 //-----------------------------------------------------------------------------
1184 //-----------------------------------------------------------------------------
1186 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxWindowDC
)
1188 wxPaintDC::wxPaintDC(void)
1193 wxPaintDC::wxPaintDC( wxWindow
*win
)
1198 //-----------------------------------------------------------------------------
1200 //-----------------------------------------------------------------------------
1202 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
,wxWindowDC
)
1204 wxClientDC::wxClientDC(void)
1209 wxClientDC::wxClientDC( wxWindow
*win
)