1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/dcclient.cpp
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"
17 #include "wx/module.h"
19 #include "wx/gtk/win_gtk.h"
21 #include <math.h> // for floating-point functions
25 #include <gdk/gdkprivate.h>
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 #define USE_PAINT_REGION 1
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
46 static GdkPixmap
*hatches
[num_hatches
];
47 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
49 extern GtkWidget
*wxRootWindow
;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 const double RAD2DEG
= 180.0 / M_PI
;
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
62 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
64 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
66 //-----------------------------------------------------------------------------
67 // temporary implementation of the missing GDK function
68 //-----------------------------------------------------------------------------
70 #include "gdk/gdkprivate.h"
72 void gdk_wx_draw_bitmap (GdkDrawable
*drawable
,
83 gint src_width
, src_height
;
85 GdkWindowPrivate
*drawable_private
;
86 GdkWindowPrivate
*src_private
;
87 GdkGCPrivate
*gc_private
;
90 g_return_if_fail (drawable
!= NULL
);
91 g_return_if_fail (src
!= NULL
);
92 g_return_if_fail (gc
!= NULL
);
95 if (GDK_WINDOW_DESTROYED(drawable
) || GDK_WINDOW_DESTROYED(src
))
98 gdk_drawable_get_size(src
, &src_width
, &src_height
);
100 drawable_private
= (GdkWindowPrivate
*) drawable
;
101 src_private
= (GdkWindowPrivate
*) src
;
102 if (drawable_private
->destroyed
|| src_private
->destroyed
)
105 src_width
= src_private
->width
;
106 src_height
= src_private
->height
;
108 gc_private
= (GdkGCPrivate
*) gc
;
111 if (width
== -1) width
= src_width
;
112 if (height
== -1) height
= src_height
;
115 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
117 GDK_WINDOW_XID(drawable
),
124 XCopyPlane( drawable_private
->xdisplay
,
125 src_private
->xwindow
,
126 drawable_private
->xwindow
,
135 //-----------------------------------------------------------------------------
136 // Implement Pool of Graphic contexts. Creating them takes too much time.
137 //-----------------------------------------------------------------------------
139 #define GC_POOL_SIZE 200
165 static wxGC wxGCPool
[GC_POOL_SIZE
];
167 static void wxInitGCPool()
169 memset( wxGCPool
, 0, GC_POOL_SIZE
*sizeof(wxGC
) );
172 static void wxCleanUpGCPool()
174 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
176 if (wxGCPool
[i
].m_gc
)
177 gdk_gc_unref( wxGCPool
[i
].m_gc
);
181 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
183 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
185 if (!wxGCPool
[i
].m_gc
)
187 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
188 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
189 wxGCPool
[i
].m_type
= type
;
190 wxGCPool
[i
].m_used
= FALSE
;
192 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
194 wxGCPool
[i
].m_used
= TRUE
;
195 return wxGCPool
[i
].m_gc
;
199 wxFAIL_MSG( wxT("No GC available") );
201 return (GdkGC
*) NULL
;
204 static void wxFreePoolGC( GdkGC
*gc
)
206 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
208 if (wxGCPool
[i
].m_gc
== gc
)
210 wxGCPool
[i
].m_used
= FALSE
;
215 wxFAIL_MSG( wxT("Wrong GC") );
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
224 wxWindowDC::wxWindowDC()
226 m_penGC
= (GdkGC
*) NULL
;
227 m_brushGC
= (GdkGC
*) NULL
;
228 m_textGC
= (GdkGC
*) NULL
;
229 m_bgGC
= (GdkGC
*) NULL
;
230 m_cmap
= (GdkColormap
*) NULL
;
232 m_isScreenDC
= FALSE
;
233 m_owner
= (wxWindow
*)NULL
;
235 m_context
= (PangoContext
*)NULL
;
236 m_fontdesc
= (PangoFontDescription
*)NULL
;
240 wxWindowDC::wxWindowDC( wxWindow
*window
)
242 m_penGC
= (GdkGC
*) NULL
;
243 m_brushGC
= (GdkGC
*) NULL
;
244 m_textGC
= (GdkGC
*) NULL
;
245 m_bgGC
= (GdkGC
*) NULL
;
246 m_cmap
= (GdkColormap
*) NULL
;
247 m_owner
= (wxWindow
*)NULL
;
249 m_isScreenDC
= FALSE
;
250 m_font
= window
->GetFont();
252 wxASSERT_MSG( window
, wxT("DC needs a window") );
254 GtkWidget
*widget
= window
->m_wxwindow
;
256 // some controls don't have m_wxwindow - like wxStaticBox, but the user
257 // code should still be able to create wxClientDCs for them, so we will
258 // use the parent window here then
261 window
= window
->GetParent();
262 widget
= window
->m_wxwindow
;
265 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
268 m_context
= gtk_widget_get_pango_context( widget
);
269 m_fontdesc
= widget
->style
->font_desc
;
272 GtkPizza
*pizza
= GTK_PIZZA( widget
);
273 m_window
= pizza
->bin_window
;
278 /* don't report problems */
284 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
288 /* this must be done after SetUpDC, bacause SetUpDC calls the
289 repective SetBrush, SetPen, SetBackground etc functions
290 to set up the DC. SetBackground call m_owner->SetBackground
291 and this might not be desired as the standard dc background
292 is white whereas a window might assume gray to be the
293 standard (as e.g. wxStatusBar) */
298 wxWindowDC::~wxWindowDC()
303 void wxWindowDC::SetUpDC()
307 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
311 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
312 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
313 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
314 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
317 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
319 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
320 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
321 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
322 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
326 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
327 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
328 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
329 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
332 /* background colour */
333 m_backgroundBrush
= *wxWHITE_BRUSH
;
334 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
335 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
338 m_textForegroundColour
.CalcPixel( m_cmap
);
339 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
341 m_textBackgroundColour
.CalcPixel( m_cmap
);
342 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
344 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
347 m_pen
.GetColour().CalcPixel( m_cmap
);
348 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
349 gdk_gc_set_background( m_penGC
, bg_col
);
351 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
354 m_brush
.GetColour().CalcPixel( m_cmap
);
355 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
356 gdk_gc_set_background( m_brushGC
, bg_col
);
358 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
361 gdk_gc_set_background( m_bgGC
, bg_col
);
362 gdk_gc_set_foreground( m_bgGC
, bg_col
);
364 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
367 gdk_gc_set_function( m_textGC
, GDK_COPY
);
368 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
369 gdk_gc_set_function( m_penGC
, GDK_COPY
);
372 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
373 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
374 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
375 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
379 hatch_bitmap
= hatches
;
380 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
381 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
382 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
383 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
384 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
385 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
389 void wxWindowDC::DoFloodFill( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
390 const wxColour
&WXUNUSED(col
), int WXUNUSED(style
) )
392 wxFAIL_MSG( wxT("wxWindowDC::DoFloodFill not implemented") );
395 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
397 // Generic (and therefore rather inefficient) method.
398 // Could be improved.
400 wxBitmap
bitmap(1, 1);
401 memdc
.SelectObject(bitmap
);
402 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
403 memdc
.SelectObject(wxNullBitmap
);
404 wxImage
image(bitmap
);
405 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
409 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
411 wxCHECK_RET( Ok(), wxT("invalid window dc") );
413 if (m_pen
.GetStyle() != wxTRANSPARENT
)
416 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
418 CalcBoundingBox(x1
, y1
);
419 CalcBoundingBox(x2
, y2
);
423 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
425 wxCHECK_RET( Ok(), wxT("invalid window dc") );
427 if (m_pen
.GetStyle() != wxTRANSPARENT
)
432 wxCoord xx
= XLOG2DEV(x
);
433 wxCoord yy
= YLOG2DEV(y
);
436 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
437 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
442 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
443 wxCoord xc
, wxCoord yc
)
445 wxCHECK_RET( Ok(), wxT("invalid window dc") );
447 wxCoord xx1
= XLOG2DEV(x1
);
448 wxCoord yy1
= YLOG2DEV(y1
);
449 wxCoord xx2
= XLOG2DEV(x2
);
450 wxCoord yy2
= YLOG2DEV(y2
);
451 wxCoord xxc
= XLOG2DEV(xc
);
452 wxCoord yyc
= YLOG2DEV(yc
);
453 double dx
= xx1
- xxc
;
454 double dy
= yy1
- yyc
;
455 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
456 wxCoord r
= (wxCoord
)radius
;
457 double radius1
, radius2
;
459 if (xx1
== xx2
&& yy1
== yy2
)
467 radius1
= radius2
= 0.0;
471 radius1
= (xx1
- xxc
== 0) ?
472 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
473 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
474 radius2
= (xx2
- xxc
== 0) ?
475 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
476 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
478 wxCoord alpha1
= wxCoord(radius1
* 64.0);
479 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
480 while (alpha2
<= 0) alpha2
+= 360*64;
481 while (alpha1
> 360*64) alpha1
-= 360*64;
485 if (m_brush
.GetStyle() != wxTRANSPARENT
)
487 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
489 gdk_gc_set_ts_origin( m_textGC
,
490 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
491 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
492 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
493 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
495 if (m_brush
.GetStyle() == wxSTIPPLE
)
497 gdk_gc_set_ts_origin( m_brushGC
,
498 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
499 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
500 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
501 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
505 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
509 if (m_pen
.GetStyle() != wxTRANSPARENT
)
510 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
513 CalcBoundingBox (x1
, y1
);
514 CalcBoundingBox (x2
, y2
);
517 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
519 wxCHECK_RET( Ok(), wxT("invalid window dc") );
521 wxCoord xx
= XLOG2DEV(x
);
522 wxCoord yy
= YLOG2DEV(y
);
523 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
524 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
526 // CMB: handle -ve width and/or height
527 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
528 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
532 wxCoord start
= wxCoord(sa
* 64.0);
533 wxCoord end
= wxCoord(ea
* 64.0);
535 if (m_brush
.GetStyle() != wxTRANSPARENT
)
537 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
539 gdk_gc_set_ts_origin( m_textGC
,
540 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
541 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
542 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
543 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
545 if (m_brush
.GetStyle() == wxSTIPPLE
)
547 gdk_gc_set_ts_origin( m_brushGC
,
548 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
549 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
550 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
551 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
555 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
559 if (m_pen
.GetStyle() != wxTRANSPARENT
)
560 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
563 CalcBoundingBox (x
, y
);
564 CalcBoundingBox (x
+ width
, y
+ height
);
567 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
569 wxCHECK_RET( Ok(), wxT("invalid window dc") );
571 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
572 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
574 CalcBoundingBox (x
, y
);
577 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
579 wxCHECK_RET( Ok(), wxT("invalid window dc") );
581 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
584 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
586 for (int i
= 0; i
< n
-1; i
++)
588 wxCoord x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
589 wxCoord x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
590 wxCoord y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
591 wxCoord y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
594 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
596 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
600 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
602 wxCHECK_RET( Ok(), wxT("invalid window dc") );
606 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
608 for (i
= 0 ; i
< n
; i
++)
610 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
611 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
613 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
618 if (m_brush
.GetStyle() != wxTRANSPARENT
)
620 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
622 gdk_gc_set_ts_origin( m_textGC
,
623 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
624 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
625 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
626 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
628 if (m_brush
.GetStyle() == wxSTIPPLE
)
630 gdk_gc_set_ts_origin( m_brushGC
,
631 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
632 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
633 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
634 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
638 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
642 if (m_pen
.GetStyle() != wxTRANSPARENT
)
644 for (i
= 0 ; i
< n
; i
++)
646 gdk_draw_line( m_window
, m_penGC
,
649 gdkpoints
[(i
+1)%n
].x
,
650 gdkpoints
[(i
+1)%n
].y
);
658 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
660 wxCHECK_RET( Ok(), wxT("invalid window dc") );
662 wxCoord xx
= XLOG2DEV(x
);
663 wxCoord yy
= YLOG2DEV(y
);
664 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
665 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
667 // CMB: draw nothing if transformed w or h is 0
668 if (ww
== 0 || hh
== 0) return;
670 // CMB: handle -ve width and/or height
671 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
672 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
676 if (m_brush
.GetStyle() != wxTRANSPARENT
)
678 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
680 gdk_gc_set_ts_origin( m_textGC
,
681 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
682 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
683 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
684 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
686 else if (m_brush
.GetStyle() == wxSTIPPLE
)
688 gdk_gc_set_ts_origin( m_brushGC
,
689 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
690 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
691 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
692 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
696 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
700 if (m_pen
.GetStyle() != wxTRANSPARENT
)
701 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
704 CalcBoundingBox( x
, y
);
705 CalcBoundingBox( x
+ width
, y
+ height
);
708 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
710 wxCHECK_RET( Ok(), wxT("invalid window dc") );
712 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
714 wxCoord xx
= XLOG2DEV(x
);
715 wxCoord yy
= YLOG2DEV(y
);
716 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
717 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
718 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
720 // CMB: handle -ve width and/or height
721 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
722 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
724 // CMB: if radius is zero use DrawRectangle() instead to avoid
725 // X drawing errors with small radii
728 DrawRectangle( x
, y
, width
, height
);
732 // CMB: draw nothing if transformed w or h is 0
733 if (ww
== 0 || hh
== 0) return;
735 // CMB: adjust size if outline is drawn otherwise the result is
736 // 1 pixel too wide and high
737 if (m_pen
.GetStyle() != wxTRANSPARENT
)
745 // CMB: ensure dd is not larger than rectangle otherwise we
746 // get an hour glass shape
748 if (dd
> ww
) dd
= ww
;
749 if (dd
> hh
) dd
= hh
;
752 if (m_brush
.GetStyle() != wxTRANSPARENT
)
754 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
756 gdk_gc_set_ts_origin( m_textGC
,
757 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
758 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
759 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
760 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
761 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
762 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
763 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
764 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
765 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
767 else if (m_brush
.GetStyle() == wxSTIPPLE
)
769 gdk_gc_set_ts_origin( m_brushGC
,
770 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
771 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
772 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
773 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
774 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
775 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
776 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
777 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
778 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
782 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
783 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
784 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
785 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
786 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
787 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
791 if (m_pen
.GetStyle() != wxTRANSPARENT
)
793 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
794 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
795 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
796 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
797 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
798 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
799 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
800 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
804 // this ignores the radius
805 CalcBoundingBox( x
, y
);
806 CalcBoundingBox( x
+ width
, y
+ height
);
809 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
811 wxCHECK_RET( Ok(), wxT("invalid window dc") );
813 wxCoord xx
= XLOG2DEV(x
);
814 wxCoord yy
= YLOG2DEV(y
);
815 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
816 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
818 // CMB: handle -ve width and/or height
819 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
820 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
824 if (m_brush
.GetStyle() != wxTRANSPARENT
)
826 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
828 gdk_gc_set_ts_origin( m_textGC
,
829 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
830 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
831 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
832 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
834 else if (m_brush
.GetStyle() == wxSTIPPLE
)
836 gdk_gc_set_ts_origin( m_brushGC
,
837 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
838 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
839 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
840 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
844 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
848 if (m_pen
.GetStyle() != wxTRANSPARENT
)
849 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
852 CalcBoundingBox( x
- width
, y
- height
);
853 CalcBoundingBox( x
+ width
, y
+ height
);
856 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
858 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
859 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
862 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
863 wxCoord x
, wxCoord y
,
866 wxCHECK_RET( Ok(), wxT("invalid window dc") );
868 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
870 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
872 /* scale/translate size and position */
873 int xx
= XLOG2DEV(x
);
874 int yy
= YLOG2DEV(y
);
876 int w
= bitmap
.GetWidth();
877 int h
= bitmap
.GetHeight();
879 CalcBoundingBox( x
, y
);
880 CalcBoundingBox( x
+ w
, y
+ h
);
882 if (!m_window
) return;
884 int ww
= XLOG2DEVREL(w
);
885 int hh
= YLOG2DEVREL(h
);
887 /* compare to current clipping region */
888 if (!m_currentClippingRegion
.IsNull())
890 wxRegion
tmp( xx
,yy
,ww
,hh
);
891 tmp
.Intersect( m_currentClippingRegion
);
896 /* scale bitmap if required */
898 if ((w
!= ww
) || (h
!= hh
))
900 wxImage
image( bitmap
);
901 image
.Rescale( ww
, hh
);
903 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
905 use_bitmap
= image
.ConvertToBitmap();
912 /* apply mask if any */
913 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
914 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
918 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
919 if (!m_currentClippingRegion
.IsNull())
922 new_mask
= gdk_pixmap_new( wxRootWindow
->window
, ww
, hh
, 1 );
923 GdkGC
*gc
= gdk_gc_new( new_mask
);
925 gdk_gc_set_foreground( gc
, &col
);
926 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
928 gdk_gc_set_background( gc
, &col
);
930 gdk_gc_set_foreground( gc
, &col
);
931 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
932 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
933 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
934 gdk_gc_set_stipple( gc
, mask
);
935 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
942 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
944 gdk_gc_set_clip_mask( m_textGC
, mask
);
945 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
950 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
952 gdk_gc_set_clip_mask( m_penGC
, mask
);
953 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
956 gdk_bitmap_unref( new_mask
);
959 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
960 drawing a mono-bitmap (XBitmap) we use the current text GC */
962 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
964 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
966 /* remove mask again if any */
971 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
972 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
973 if (!m_currentClippingRegion
.IsNull())
974 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
978 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
979 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
980 if (!m_currentClippingRegion
.IsNull())
981 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
986 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
987 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
988 int logical_func
, bool useMask
)
990 /* this is the nth try to get this utterly useless function to
991 work. it now completely ignores the scaling or translation
992 of the source dc, but scales correctly on the target dc and
993 knows about possible mask information in a memory dc. */
995 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid window dc") );
997 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
999 if (!m_window
) return FALSE
;
1001 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1002 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1004 bool use_bitmap_method
= FALSE
;
1005 bool is_mono
= FALSE
;
1007 if (srcDC
->m_isMemDC
)
1009 if (!memDC
->m_selected
.Ok()) return FALSE
;
1011 /* we use the "XCopyArea" way to copy a memory dc into
1012 y different window if the memory dc BOTH
1013 a) doesn't have any mask or its mask isn't used
1017 if (useMask
&& (memDC
->m_selected
.GetMask()))
1019 /* we HAVE TO use the direct way for memory dcs
1020 that have mask since the XCopyArea doesn't know
1022 use_bitmap_method
= TRUE
;
1024 else if (memDC
->m_selected
.GetDepth() == 1)
1026 /* we HAVE TO use the direct way for memory dcs
1027 that are bitmaps because XCopyArea doesn't cope
1028 with different bit depths */
1030 use_bitmap_method
= TRUE
;
1032 else if ((xsrc
== 0) && (ysrc
== 0) &&
1033 (width
== memDC
->m_selected
.GetWidth()) &&
1034 (height
== memDC
->m_selected
.GetHeight()))
1036 /* we SHOULD use the direct way if all of the bitmap
1037 in the memory dc is copied in which case XCopyArea
1038 wouldn't be able able to boost performace by reducing
1039 the area to be scaled */
1040 use_bitmap_method
= TRUE
;
1044 use_bitmap_method
= FALSE
;
1048 CalcBoundingBox( xdest
, ydest
);
1049 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1051 /* scale/translate size and position */
1052 wxCoord xx
= XLOG2DEV(xdest
);
1053 wxCoord yy
= YLOG2DEV(ydest
);
1055 wxCoord ww
= XLOG2DEVREL(width
);
1056 wxCoord hh
= YLOG2DEVREL(height
);
1058 /* compare to current clipping region */
1059 if (!m_currentClippingRegion
.IsNull())
1061 wxRegion
tmp( xx
,yy
,ww
,hh
);
1062 tmp
.Intersect( m_currentClippingRegion
);
1067 int old_logical_func
= m_logicalFunction
;
1068 SetLogicalFunction( logical_func
);
1070 if (use_bitmap_method
)
1072 /* scale/translate bitmap size */
1073 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1074 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1076 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1077 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1079 /* scale bitmap if required */
1080 wxBitmap use_bitmap
;
1082 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1084 wxImage
image( memDC
->m_selected
);
1085 image
= image
.Scale( bm_ww
, bm_hh
);
1088 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1090 use_bitmap
= image
.ConvertToBitmap();
1094 use_bitmap
= memDC
->m_selected
;
1097 /* apply mask if any */
1098 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1099 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1101 if (useMask
&& mask
)
1103 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1104 if (!m_currentClippingRegion
.IsNull())
1107 new_mask
= gdk_pixmap_new( wxRootWindow
->window
, bm_ww
, bm_hh
, 1 );
1108 GdkGC
*gc
= gdk_gc_new( new_mask
);
1110 gdk_gc_set_foreground( gc
, &col
);
1111 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1113 gdk_gc_set_background( gc
, &col
);
1115 gdk_gc_set_foreground( gc
, &col
);
1116 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1117 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1118 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1119 gdk_gc_set_stipple( gc
, mask
);
1120 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1127 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1129 gdk_gc_set_clip_mask( m_textGC
, mask
);
1130 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1135 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1137 gdk_gc_set_clip_mask( m_penGC
, mask
);
1138 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1141 gdk_bitmap_unref( new_mask
);
1144 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1145 drawing a mono-bitmap (XBitmap) we use the current text GC */
1148 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1150 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1152 /* remove mask again if any */
1153 if (useMask
&& mask
)
1157 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1158 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1159 if (!m_currentClippingRegion
.IsNull())
1160 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1164 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1165 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1166 if (!m_currentClippingRegion
.IsNull())
1167 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1171 else /* use_bitmap_method */
1173 if ((width
!= ww
) || (height
!= hh
))
1175 /* draw source window into a bitmap as we cannot scale
1176 a window in contrast to a bitmap. this would actually
1177 work with memory dcs as well, but we'd lose the mask
1178 information and waste one step in this process since
1179 a memory already has a bitmap. all this is slightly
1180 inefficient as we could take an XImage directly from
1181 an X window, but we'd then also have to care that
1182 the window is not outside the screen (in which case
1183 we'd get a BadMatch or what not).
1184 Is a double XGetImage and combined XGetPixel and
1185 XPutPixel really faster? I'm not sure. look at wxXt
1186 for a different implementation of the same problem. */
1188 wxBitmap
bitmap( width
, height
);
1190 /* copy including child window contents */
1191 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1192 gdk_window_copy_area( bitmap
.GetPixmap(), m_penGC
, 0, 0,
1194 xsrc
, ysrc
, width
, height
);
1195 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1198 wxImage
image( bitmap
);
1199 image
= image
.Scale( ww
, hh
);
1201 /* convert to bitmap */
1202 bitmap
= image
.ConvertToBitmap();
1204 /* draw scaled bitmap */
1205 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1210 /* No scaling and not a memory dc with a mask either */
1212 /* copy including child window contents */
1213 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1214 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1216 xsrc
, ysrc
, width
, height
);
1217 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1221 SetLogicalFunction( old_logical_func
);
1225 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1227 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1229 if (!m_window
) return;
1231 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1233 wxCHECK_RET( font
, wxT("invalid font") );
1236 wxCHECK_RET( m_context
, wxT("no Pango context") );
1243 /* FIXME: the layout engine should probably be abstracted at a higher level in wxDC... */
1244 PangoLayout
*layout
= pango_layout_new(m_context
);
1245 pango_layout_set_font_description(layout
, m_fontdesc
);
1247 wxWX2MBbuf data
= text
.mb_str(wxConvUTF8
);
1248 pango_layout_set_text(layout
, data
, strlen(data
));
1250 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1251 PangoRectangle rect
;
1252 pango_layout_line_get_extents(line
, NULL
, &rect
);
1253 wxCoord width
= rect
.width
;
1254 wxCoord height
= rect
.height
;
1255 gdk_draw_layout( m_window
, m_textGC
, x
, y
, layout
);
1257 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1258 wxCoord height
= font
->ascent
+ font
->descent
;
1259 /* CMB 21/5/98: draw text background if mode is wxSOLID */
1260 if (m_backgroundMode
== wxSOLID
)
1262 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1263 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1264 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1266 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1269 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1270 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1271 properties (see wxXt implementation) */
1272 if (m_font
.GetUnderlined())
1274 wxCoord ul_y
= y
+ font
->ascent
;
1275 if (font
->descent
> 0) ul_y
++;
1276 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1280 g_object_unref( G_OBJECT( layout
) );
1283 width
= wxCoord(width
/ m_scaleX
);
1284 height
= wxCoord(height
/ m_scaleY
);
1285 CalcBoundingBox (x
+ width
, y
+ height
);
1286 CalcBoundingBox (x
, y
);
1289 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1293 DrawText(text
, x
, y
);
1297 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1299 if (!m_window
) return;
1301 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1303 wxCHECK_RET( font
, wxT("invalid font") );
1305 // the size of the text
1306 wxCoord w
= gdk_string_width( font
, text
.mbc_str() );
1307 wxCoord h
= font
->ascent
+ font
->descent
;
1309 // draw the string normally
1312 dc
.SelectObject(src
);
1313 dc
.SetFont(GetFont());
1314 dc
.SetBackground(*wxWHITE_BRUSH
);
1315 dc
.SetBrush(*wxBLACK_BRUSH
);
1317 dc
.DrawText(text
, 0, 0);
1318 dc
.SetFont(wxNullFont
);
1319 dc
.SelectObject(wxNullBitmap
);
1321 // Calculate the size of the rotated bounding box.
1322 double rad
= DegToRad(angle
);
1323 double dx
= cos(rad
),
1326 // the rectngle vertices are counted clockwise with the first one being at
1327 // (0, 0) (or, rather, at (x, y))
1329 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1332 double x3
= x4
+ x2
,
1336 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1337 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1338 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1339 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1341 // prepare to blit-with-rotate the bitmap to the DC
1344 GdkColor
*colText
= m_textForegroundColour
.GetColor(),
1345 *colBack
= m_textBackgroundColour
.GetColor();
1347 bool textColSet
= TRUE
;
1349 unsigned char *data
= image
.GetData();
1351 // paint pixel by pixel
1352 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1354 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1356 // transform source coords to dest coords
1357 double r
= sqrt((double)srcX
*srcX
+ srcY
*srcY
);
1358 double angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1359 wxCoord dstX
= (wxCoord
)(r
*cos(angleOrig
) + 0.5),
1360 dstY
= (wxCoord
)(r
*sin(angleOrig
) + 0.5);
1363 bool textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1364 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1366 // change colour if needed
1367 if ( textPixel
!= textColSet
)
1369 gdk_gc_set_foreground( m_textGC
, textPixel
? colText
1372 textColSet
= textPixel
;
1375 // don't use DrawPoint() because it uses the current pen
1376 // colour, and we don't need it here
1377 gdk_draw_point( m_window
, m_textGC
,
1378 XLOG2DEV(x
+ dstX
), YLOG2DEV(y
+ dstY
) );
1383 // it would be better to draw with non underlined font and draw the line
1384 // manually here (it would be more straight...)
1386 if ( m_font
.GetUnderlined() )
1388 gdk_draw_line( m_window
, m_textGC
,
1389 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1390 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1394 // restore the font colour
1395 gdk_gc_set_foreground( m_textGC
, colText
);
1397 // update the bounding box
1398 CalcBoundingBox(x
+ minX
, y
+ minY
);
1399 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1402 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1403 wxCoord
*width
, wxCoord
*height
,
1404 wxCoord
*descent
, wxCoord
*externalLeading
,
1405 wxFont
*theFont
) const
1407 wxFont fontToUse
= m_font
;
1408 if (theFont
) fontToUse
= *theFont
;
1410 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1411 if (width
) (*width
) = wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1412 if (height
) (*height
) = wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1413 if (descent
) (*descent
) = wxCoord(font
->descent
/ m_scaleY
);
1414 if (externalLeading
) (*externalLeading
) = 0; // ??
1417 wxCoord
wxWindowDC::GetCharWidth() const
1419 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1420 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1422 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1425 wxCoord
wxWindowDC::GetCharHeight() const
1427 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1428 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1430 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1433 void wxWindowDC::Clear()
1435 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1437 if (!m_window
) return;
1439 /* - we either are a memory dc or have a window as the
1440 owner. anything else shouldn't happen.
1441 - we don't use gdk_window_clear() as we don't set
1442 the window's background colour anymore. it is too
1443 much pain to keep the DC's and the window's back-
1444 ground colour in synch. */
1449 m_owner
->GetSize( &width
, &height
);
1450 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1457 GetSize( &width
, &height
);
1458 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1463 void wxWindowDC::SetFont( const wxFont
&font
)
1471 void wxWindowDC::SetPen( const wxPen
&pen
)
1473 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1475 if (m_pen
== pen
) return;
1479 if (!m_pen
.Ok()) return;
1481 if (!m_window
) return;
1483 gint width
= m_pen
.GetWidth();
1486 // CMB: if width is non-zero scale it with the dc
1491 // X doesn't allow different width in x and y and so we take
1494 ( fabs((double) XLOG2DEVREL(width
)) +
1495 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1499 static const wxGTKDash dotted
[] = {1, 1};
1500 static const wxGTKDash short_dashed
[] = {2, 2};
1501 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1502 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1504 // We express dash pattern in pen width unit, so we are
1505 // independent of zoom factor and so on...
1507 const wxGTKDash
*req_dash
;
1509 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1510 switch (m_pen
.GetStyle())
1514 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1515 req_nb_dash
= m_pen
.GetDashCount();
1516 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1521 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1528 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1530 req_dash
= wxCoord_dashed
;
1535 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1537 req_dash
= short_dashed
;
1542 // lineStyle = GDK_LINE_DOUBLE_DASH;
1543 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1545 req_dash
= dotted_dashed
;
1550 case wxSTIPPLE_MASK_OPAQUE
:
1555 lineStyle
= GDK_LINE_SOLID
;
1556 req_dash
= (wxGTKDash
*)NULL
;
1562 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
1563 if (req_dash
&& req_nb_dash
)
1565 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1568 for (int i
= 0; i
< req_nb_dash
; i
++)
1569 real_req_dash
[i
] = req_dash
[i
] * width
;
1570 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1571 delete[] real_req_dash
;
1575 // No Memory. We use non-scaled dash pattern...
1576 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1581 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1582 switch (m_pen
.GetCap())
1584 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1585 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1592 capStyle
= GDK_CAP_NOT_LAST
;
1596 capStyle
= GDK_CAP_ROUND
;
1602 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1603 switch (m_pen
.GetJoin())
1605 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1606 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1608 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1611 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1613 m_pen
.GetColour().CalcPixel( m_cmap
);
1614 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1617 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1619 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1621 if (m_brush
== brush
) return;
1625 if (!m_brush
.Ok()) return;
1627 if (!m_window
) return;
1629 m_brush
.GetColour().CalcPixel( m_cmap
);
1630 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1632 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1634 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1636 if (m_brush
.GetStipple()->GetPixmap())
1638 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1639 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1643 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1644 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
1648 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1650 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1651 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1654 if (IS_HATCH(m_brush
.GetStyle()))
1656 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1657 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1658 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
1662 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1664 /* CMB 21/7/98: Added SetBackground. Sets background brush
1665 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1667 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1669 if (m_backgroundBrush
== brush
) return;
1671 m_backgroundBrush
= brush
;
1673 if (!m_backgroundBrush
.Ok()) return;
1675 if (!m_window
) return;
1677 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1678 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
1679 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
1680 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1681 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1683 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1685 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
1687 if (m_backgroundBrush
.GetStipple()->GetPixmap())
1689 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
1690 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
1694 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1695 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
1699 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
1701 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1702 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
1703 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
1707 void wxWindowDC::SetLogicalFunction( int function
)
1709 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1711 if (m_logicalFunction
== function
)
1714 // VZ: shouldn't this be a CHECK?
1718 GdkFunction mode
= GDK_COPY
;
1721 case wxXOR
: mode
= GDK_XOR
; break;
1722 case wxINVERT
: mode
= GDK_INVERT
; break;
1723 #if (GTK_MINOR_VERSION > 0)
1724 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1725 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1726 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1727 case wxSET
: mode
= GDK_SET
; break;
1728 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1729 case wxAND
: mode
= GDK_AND
; break;
1730 case wxOR
: mode
= GDK_OR
; break;
1731 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1732 case wxNAND
: mode
= GDK_NAND
; break;
1733 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1734 case wxCOPY
: mode
= GDK_COPY
; break;
1735 case wxNO_OP
: mode
= GDK_NOOP
; break;
1736 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1738 // unsupported by GTK
1739 case wxNOR
: mode
= GDK_COPY
; break;
1743 wxFAIL_MSG( wxT("unsupported logical function") );
1748 m_logicalFunction
= function
;
1750 gdk_gc_set_function( m_penGC
, mode
);
1751 gdk_gc_set_function( m_brushGC
, mode
);
1753 // to stay compatible with wxMSW, we don't apply ROPs to the text
1754 // operations (i.e. DrawText/DrawRotatedText).
1755 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1756 gdk_gc_set_function( m_textGC
, mode
);
1759 void wxWindowDC::SetTextForeground( const wxColour
&col
)
1761 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1763 if (m_textForegroundColour
== col
) return;
1765 m_textForegroundColour
= col
;
1766 if (!m_textForegroundColour
.Ok()) return;
1768 if (!m_window
) return;
1770 m_textForegroundColour
.CalcPixel( m_cmap
);
1771 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1774 void wxWindowDC::SetTextBackground( const wxColour
&col
)
1776 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1778 if (m_textBackgroundColour
== col
) return;
1780 m_textBackgroundColour
= col
;
1781 if (!m_textBackgroundColour
.Ok()) return;
1783 if (!m_window
) return;
1785 m_textBackgroundColour
.CalcPixel( m_cmap
);
1786 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1789 void wxWindowDC::SetBackgroundMode( int mode
)
1791 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1793 m_backgroundMode
= mode
;
1795 if (!m_window
) return;
1797 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
1798 // transparent/solid background mode
1800 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
1802 gdk_gc_set_fill( m_brushGC
,
1803 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
1807 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1809 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
1812 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1814 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1816 if (!m_window
) return;
1819 rect
.x
= XLOG2DEV(x
);
1820 rect
.y
= YLOG2DEV(y
);
1821 rect
.width
= XLOG2DEVREL(width
);
1822 rect
.height
= YLOG2DEVREL(height
);
1824 if (!m_currentClippingRegion
.IsNull())
1825 m_currentClippingRegion
.Intersect( rect
);
1827 m_currentClippingRegion
.Union( rect
);
1829 #if USE_PAINT_REGION
1830 if (!m_paintClippingRegion
.IsNull())
1831 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1834 wxCoord xx
, yy
, ww
, hh
;
1835 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1836 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1838 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1839 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
1840 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1841 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
1844 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1846 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1850 DestroyClippingRegion();
1854 if (!m_window
) return;
1856 if (!m_currentClippingRegion
.IsNull())
1857 m_currentClippingRegion
.Intersect( region
);
1859 m_currentClippingRegion
.Union( region
);
1861 #if USE_PAINT_REGION
1862 if (!m_paintClippingRegion
.IsNull())
1863 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1866 wxCoord xx
, yy
, ww
, hh
;
1867 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1868 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1870 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1871 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
1872 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1873 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
1876 void wxWindowDC::DestroyClippingRegion()
1878 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1880 wxDC::DestroyClippingRegion();
1882 m_currentClippingRegion
.Clear();
1884 #if USE_PAINT_REGION
1885 if (!m_paintClippingRegion
.IsEmpty())
1886 m_currentClippingRegion
.Union( m_paintClippingRegion
);
1889 if (!m_window
) return;
1891 if (m_currentClippingRegion
.IsEmpty())
1893 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
1894 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
1895 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
1896 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
1900 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1901 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
1902 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1903 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
1907 void wxWindowDC::Destroy()
1909 if (m_penGC
) wxFreePoolGC( m_penGC
);
1910 m_penGC
= (GdkGC
*) NULL
;
1911 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
1912 m_brushGC
= (GdkGC
*) NULL
;
1913 if (m_textGC
) wxFreePoolGC( m_textGC
);
1914 m_textGC
= (GdkGC
*) NULL
;
1915 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
1916 m_bgGC
= (GdkGC
*) NULL
;
1919 void wxWindowDC::ComputeScaleAndOrigin()
1921 /* CMB: copy scale to see if it changes */
1922 double origScaleX
= m_scaleX
;
1923 double origScaleY
= m_scaleY
;
1925 wxDC::ComputeScaleAndOrigin();
1927 /* CMB: if scale has changed call SetPen to recalulate the line width */
1928 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
1931 /* this is a bit artificial, but we need to force wxDC to think
1932 the pen has changed */
1939 // Resolution in pixels per logical inch
1940 wxSize
wxWindowDC::GetPPI() const
1942 return wxSize(100, 100);
1945 int wxWindowDC::GetDepth() const
1947 wxFAIL_MSG(wxT("not implemented"));
1953 // ----------------------------------- spline code ----------------------------------------
1955 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
1956 double a3
, double b3
, double a4
, double b4
);
1957 void wx_clear_stack();
1958 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
1959 double *y3
, double *x4
, double *y4
);
1960 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
1961 double x4
, double y4
);
1962 static bool wx_spline_add_point(double x
, double y
);
1963 static void wx_spline_draw_point_array(wxDC
*dc
);
1965 wxList wx_spline_point_list
;
1967 #define half(z1, z2) ((z1+z2)/2.0)
1970 /* iterative version */
1972 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
1975 register double xmid
, ymid
;
1976 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1979 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
1981 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
1982 xmid
= (double)half(x2
, x3
);
1983 ymid
= (double)half(y2
, y3
);
1984 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
1985 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
1986 wx_spline_add_point( x1
, y1
);
1987 wx_spline_add_point( xmid
, ymid
);
1989 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
1990 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
1991 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
1992 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
1997 /* utilities used by spline drawing routines */
1999 typedef struct wx_spline_stack_struct
{
2000 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
2003 #define SPLINE_STACK_DEPTH 20
2004 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
2005 static Stack
*wx_stack_top
;
2006 static int wx_stack_count
;
2008 void wx_clear_stack()
2010 wx_stack_top
= wx_spline_stack
;
2014 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
2016 wx_stack_top
->x1
= x1
;
2017 wx_stack_top
->y1
= y1
;
2018 wx_stack_top
->x2
= x2
;
2019 wx_stack_top
->y2
= y2
;
2020 wx_stack_top
->x3
= x3
;
2021 wx_stack_top
->y3
= y3
;
2022 wx_stack_top
->x4
= x4
;
2023 wx_stack_top
->y4
= y4
;
2028 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
2029 double *x3
, double *y3
, double *x4
, double *y4
)
2031 if (wx_stack_count
== 0)
2035 *x1
= wx_stack_top
->x1
;
2036 *y1
= wx_stack_top
->y1
;
2037 *x2
= wx_stack_top
->x2
;
2038 *y2
= wx_stack_top
->y2
;
2039 *x3
= wx_stack_top
->x3
;
2040 *y3
= wx_stack_top
->y3
;
2041 *x4
= wx_stack_top
->x4
;
2042 *y4
= wx_stack_top
->y4
;
2046 static bool wx_spline_add_point(double x
, double y
)
2048 wxPoint
*point
= new wxPoint
;
2051 wx_spline_point_list
.Append((wxObject
*)point
);
2055 static void wx_spline_draw_point_array(wxDC
*dc
)
2057 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
2058 wxNode
*node
= wx_spline_point_list
.First();
2061 wxPoint
*point
= (wxPoint
*)node
->Data();
2064 node
= wx_spline_point_list
.First();
2068 void wxWindowDC::DoDrawSpline( wxList
*points
)
2070 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2073 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
2074 double x1
, y1
, x2
, y2
;
2076 wxNode
*node
= points
->First();
2077 p
= (wxPoint
*)node
->Data();
2082 node
= node
->Next();
2083 p
= (wxPoint
*)node
->Data();
2087 cx1
= (double)((x1
+ x2
) / 2);
2088 cy1
= (double)((y1
+ y2
) / 2);
2089 cx2
= (double)((cx1
+ x2
) / 2);
2090 cy2
= (double)((cy1
+ y2
) / 2);
2092 wx_spline_add_point(x1
, y1
);
2094 while ((node
= node
->Next()) != NULL
)
2096 p
= (wxPoint
*)node
->Data();
2101 cx4
= (double)(x1
+ x2
) / 2;
2102 cy4
= (double)(y1
+ y2
) / 2;
2103 cx3
= (double)(x1
+ cx4
) / 2;
2104 cy3
= (double)(y1
+ cy4
) / 2;
2106 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
2110 cx2
= (double)(cx1
+ x2
) / 2;
2111 cy2
= (double)(cy1
+ y2
) / 2;
2114 wx_spline_add_point( cx1
, cy1
);
2115 wx_spline_add_point( x2
, y2
);
2117 wx_spline_draw_point_array( this );
2120 #endif // wxUSE_SPLINE
2122 //-----------------------------------------------------------------------------
2124 //-----------------------------------------------------------------------------
2126 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxWindowDC
)
2128 wxPaintDC::wxPaintDC()
2133 wxPaintDC::wxPaintDC( wxWindow
*win
)
2136 #if USE_PAINT_REGION
2137 if (!win
->m_clipPaintRegion
)
2140 m_paintClippingRegion
= win
->GetUpdateRegion();
2141 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2144 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2146 gdk_gc_set_clip_region( m_penGC
, region
);
2147 gdk_gc_set_clip_region( m_brushGC
, region
);
2148 gdk_gc_set_clip_region( m_textGC
, region
);
2149 gdk_gc_set_clip_region( m_bgGC
, region
);
2154 //-----------------------------------------------------------------------------
2156 //-----------------------------------------------------------------------------
2158 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
,wxWindowDC
)
2160 wxClientDC::wxClientDC()
2165 wxClientDC::wxClientDC( wxWindow
*win
)
2170 // ----------------------------------------------------------------------------
2172 // ----------------------------------------------------------------------------
2174 class wxDCModule
: public wxModule
2181 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2184 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2186 bool wxDCModule::OnInit()
2192 void wxDCModule::OnExit()