1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dcclient.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XCopyPlane XCOPYPLANE
17 #include "wx/dcclient.h"
21 #include "wx/dcmemory.h"
22 #include "wx/math.h" // for floating-point functions
26 #include "wx/module.h"
27 #include "wx/fontutil.h"
29 #include "wx/gtk/win_gtk.h"
30 #include "wx/gtk/private.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #define USE_PAINT_REGION 1
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
52 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
53 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
56 static GdkPixmap
*hatches
[num_hatches
];
57 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
59 extern GtkWidget
*wxGetRootWindow();
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 const double RAD2DEG
= 180.0 / M_PI
;
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
72 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
74 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
76 //-----------------------------------------------------------------------------
77 // temporary implementation of the missing GDK function
78 //-----------------------------------------------------------------------------
80 #include "gdk/gdkprivate.h"
83 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
93 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
94 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
95 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
97 gint src_width
, src_height
;
98 gdk_drawable_get_size(src
, &src_width
, &src_height
);
99 if (width
== -1) width
= src_width
;
100 if (height
== -1) height
= src_height
;
102 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
104 GDK_WINDOW_XID(drawable
),
112 //-----------------------------------------------------------------------------
113 // Implement Pool of Graphic contexts. Creating them takes too much time.
114 //-----------------------------------------------------------------------------
140 #define GC_POOL_ALLOC_SIZE 100
142 static int wxGCPoolSize
= 0;
144 static wxGC
*wxGCPool
= NULL
;
146 static void wxInitGCPool()
148 // This really could wait until the first call to
149 // wxGetPoolGC, but we will make the first allocation
150 // now when other initialization is being performed.
152 // Set initial pool size.
153 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
155 // Allocate initial pool.
156 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
157 if (wxGCPool
== NULL
)
159 // If we cannot malloc, then fail with error
160 // when debug is enabled. If debug is not enabled,
161 // the problem will eventually get caught
163 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
167 // Zero initial pool.
168 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
171 static void wxCleanUpGCPool()
173 for (int i
= 0; i
< wxGCPoolSize
; i
++)
175 if (wxGCPool
[i
].m_gc
)
176 g_object_unref (wxGCPool
[i
].m_gc
);
184 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
188 // Look for an available GC.
189 for (int i
= 0; i
< wxGCPoolSize
; i
++)
191 if (!wxGCPool
[i
].m_gc
)
193 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
194 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
195 wxGCPool
[i
].m_type
= type
;
196 wxGCPool
[i
].m_used
= false;
198 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
200 wxGCPool
[i
].m_used
= true;
201 return wxGCPool
[i
].m_gc
;
205 // We did not find an available GC.
206 // We need to grow the GC pool.
207 pptr
= (wxGC
*)realloc(wxGCPool
,
208 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
211 // Initialize newly allocated pool.
213 memset(&wxGCPool
[wxGCPoolSize
], 0,
214 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
216 // Initialize entry we will return.
217 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
218 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
219 wxGCPool
[wxGCPoolSize
].m_type
= type
;
220 wxGCPool
[wxGCPoolSize
].m_used
= true;
222 // Set new value of pool size.
223 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
225 // Return newly allocated entry.
226 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
229 // The realloc failed. Fall through to error.
230 wxFAIL_MSG( wxT("No GC available") );
232 return (GdkGC
*) NULL
;
235 static void wxFreePoolGC( GdkGC
*gc
)
237 for (int i
= 0; i
< wxGCPoolSize
; i
++)
239 if (wxGCPool
[i
].m_gc
== gc
)
241 wxGCPool
[i
].m_used
= false;
246 wxFAIL_MSG( wxT("Wrong GC") );
249 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
253 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
255 wxWindowDC::wxWindowDC()
257 m_penGC
= (GdkGC
*) NULL
;
258 m_brushGC
= (GdkGC
*) NULL
;
259 m_textGC
= (GdkGC
*) NULL
;
260 m_bgGC
= (GdkGC
*) NULL
;
261 m_cmap
= (GdkColormap
*) NULL
;
263 m_isScreenDC
= false;
264 m_owner
= (wxWindow
*)NULL
;
265 m_context
= (PangoContext
*)NULL
;
266 m_layout
= (PangoLayout
*)NULL
;
267 m_fontdesc
= (PangoFontDescription
*)NULL
;
270 wxWindowDC::wxWindowDC( wxWindow
*window
)
272 wxASSERT_MSG( window
, wxT("DC needs a window") );
274 m_penGC
= (GdkGC
*) NULL
;
275 m_brushGC
= (GdkGC
*) NULL
;
276 m_textGC
= (GdkGC
*) NULL
;
277 m_bgGC
= (GdkGC
*) NULL
;
278 m_cmap
= (GdkColormap
*) NULL
;
279 m_owner
= (wxWindow
*)NULL
;
281 m_isScreenDC
= false;
282 m_font
= window
->GetFont();
284 GtkWidget
*widget
= window
->m_wxwindow
;
286 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
287 // code should still be able to create wxClientDCs for them, so we will
288 // use the parent window here then.
291 window
= window
->GetParent();
292 widget
= window
->m_wxwindow
;
295 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
297 m_context
= window
->GtkGetPangoDefaultContext();
298 m_layout
= pango_layout_new( m_context
);
299 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
301 GtkPizza
*pizza
= GTK_PIZZA( widget
);
302 m_window
= pizza
->bin_window
;
304 // Window not realized ?
307 // Don't report problems as per MSW.
313 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
317 /* this must be done after SetUpDC, bacause SetUpDC calls the
318 repective SetBrush, SetPen, SetBackground etc functions
319 to set up the DC. SetBackground call m_owner->SetBackground
320 and this might not be desired as the standard dc background
321 is white whereas a window might assume gray to be the
322 standard (as e.g. wxStatusBar) */
327 wxWindowDC::~wxWindowDC()
332 g_object_unref (m_layout
);
334 pango_font_description_free( m_fontdesc
);
337 void wxWindowDC::SetUpDC()
341 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
345 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
346 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
347 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
348 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
351 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
353 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
354 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
355 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
356 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
360 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
361 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
362 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
363 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
366 /* background colour */
367 m_backgroundBrush
= *wxWHITE_BRUSH
;
368 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
370 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
372 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
376 m_textForegroundColour
.CalcPixel( m_cmap
);
377 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
379 m_textBackgroundColour
.CalcPixel( m_cmap
);
380 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
382 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
385 m_pen
.GetColour().CalcPixel( m_cmap
);
386 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
387 gdk_gc_set_background( m_penGC
, bg_col
);
389 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
392 m_brush
.GetColour().CalcPixel( m_cmap
);
393 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
394 gdk_gc_set_background( m_brushGC
, bg_col
);
396 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
399 gdk_gc_set_background( m_bgGC
, bg_col
);
400 gdk_gc_set_foreground( m_bgGC
, bg_col
);
402 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
405 gdk_gc_set_function( m_textGC
, GDK_COPY
);
406 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
407 gdk_gc_set_function( m_penGC
, GDK_COPY
);
410 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
411 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
412 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
413 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
417 hatch_bitmap
= hatches
;
418 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
419 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
420 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
421 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
422 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
423 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
427 void wxWindowDC::DoGetSize( int* width
, int* height
) const
429 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
431 m_owner
->GetSize(width
, height
);
434 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
435 const wxColour
& col
, int style
);
437 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
438 const wxColour
& col
, int style
)
440 return wxDoFloodFill(this, x
, y
, col
, style
);
443 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
445 // Generic (and therefore rather inefficient) method.
446 // Could be improved.
448 wxBitmap
bitmap(1, 1);
449 memdc
.SelectObject(bitmap
);
450 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
451 memdc
.SelectObject(wxNullBitmap
);
453 wxImage image
= bitmap
.ConvertToImage();
454 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
458 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
460 wxCHECK_RET( Ok(), wxT("invalid window dc") );
462 if (m_pen
.GetStyle() != wxTRANSPARENT
)
465 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
467 CalcBoundingBox(x1
, y1
);
468 CalcBoundingBox(x2
, y2
);
472 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
474 wxCHECK_RET( Ok(), wxT("invalid window dc") );
476 if (m_pen
.GetStyle() != wxTRANSPARENT
)
481 wxCoord xx
= XLOG2DEV(x
);
482 wxCoord yy
= YLOG2DEV(y
);
485 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
486 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
491 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
492 wxCoord xc
, wxCoord yc
)
494 wxCHECK_RET( Ok(), wxT("invalid window dc") );
496 wxCoord xx1
= XLOG2DEV(x1
);
497 wxCoord yy1
= YLOG2DEV(y1
);
498 wxCoord xx2
= XLOG2DEV(x2
);
499 wxCoord yy2
= YLOG2DEV(y2
);
500 wxCoord xxc
= XLOG2DEV(xc
);
501 wxCoord yyc
= YLOG2DEV(yc
);
502 double dx
= xx1
- xxc
;
503 double dy
= yy1
- yyc
;
504 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
505 wxCoord r
= (wxCoord
)radius
;
506 double radius1
, radius2
;
508 if (xx1
== xx2
&& yy1
== yy2
)
513 else if ( wxIsNullDouble(radius
) )
520 radius1
= (xx1
- xxc
== 0) ?
521 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
522 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
523 radius2
= (xx2
- xxc
== 0) ?
524 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
525 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
527 wxCoord alpha1
= wxCoord(radius1
* 64.0);
528 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
529 while (alpha2
<= 0) alpha2
+= 360*64;
530 while (alpha1
> 360*64) alpha1
-= 360*64;
534 if (m_brush
.GetStyle() != wxTRANSPARENT
)
536 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
538 gdk_gc_set_ts_origin( m_textGC
,
539 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
540 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
541 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
542 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
544 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
546 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
547 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
548 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
550 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
552 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
553 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
554 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
556 if (m_brush
.GetStyle() == wxSTIPPLE
)
558 gdk_gc_set_ts_origin( m_brushGC
,
559 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
560 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
561 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
562 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
566 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
570 if (m_pen
.GetStyle() != wxTRANSPARENT
)
572 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
574 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
575 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
579 CalcBoundingBox (x1
, y1
);
580 CalcBoundingBox (x2
, y2
);
583 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
585 wxCHECK_RET( Ok(), wxT("invalid window dc") );
587 wxCoord xx
= XLOG2DEV(x
);
588 wxCoord yy
= YLOG2DEV(y
);
589 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
590 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
592 // CMB: handle -ve width and/or height
593 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
594 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
598 wxCoord start
= wxCoord(sa
* 64.0);
599 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
601 if (m_brush
.GetStyle() != wxTRANSPARENT
)
603 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
605 gdk_gc_set_ts_origin( m_textGC
,
606 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
607 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
608 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
609 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
611 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
613 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
614 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
615 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
617 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
619 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
620 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
621 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
623 if (m_brush
.GetStyle() == wxSTIPPLE
)
625 gdk_gc_set_ts_origin( m_brushGC
,
626 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
627 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
628 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
629 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
633 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
637 if (m_pen
.GetStyle() != wxTRANSPARENT
)
638 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
641 CalcBoundingBox (x
, y
);
642 CalcBoundingBox (x
+ width
, y
+ height
);
645 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
647 wxCHECK_RET( Ok(), wxT("invalid window dc") );
649 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
650 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
652 CalcBoundingBox (x
, y
);
655 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
657 wxCHECK_RET( Ok(), wxT("invalid window dc") );
659 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
662 //Check, if scaling is necessary
664 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
666 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
667 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
670 gpts
= new GdkPoint
[n
];
672 for (int i
= 0; i
< n
; i
++)
676 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
677 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
679 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
683 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
689 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
691 wxCHECK_RET( Ok(), wxT("invalid window dc") );
695 //Check, if scaling is necessary
697 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
699 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
700 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
703 gdkpoints
= new GdkPoint
[n
];
706 for (i
= 0 ; i
< n
; i
++)
710 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
711 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
713 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
718 if (m_brush
.GetStyle() != wxTRANSPARENT
)
720 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
722 gdk_gc_set_ts_origin( m_textGC
,
723 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
724 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
725 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
726 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
728 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
730 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
731 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
732 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
734 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
736 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
737 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
738 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
740 if (m_brush
.GetStyle() == wxSTIPPLE
)
742 gdk_gc_set_ts_origin( m_brushGC
,
743 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
744 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
745 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
746 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
750 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
754 if (m_pen
.GetStyle() != wxTRANSPARENT
)
757 for (i = 0 ; i < n ; i++)
759 gdk_draw_line( m_window, m_penGC,
762 gdkpoints[(i+1)%n].x,
763 gdkpoints[(i+1)%n].y);
766 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gdkpoints
, n
);
775 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
777 wxCHECK_RET( Ok(), wxT("invalid window dc") );
779 wxCoord xx
= XLOG2DEV(x
);
780 wxCoord yy
= YLOG2DEV(y
);
781 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
782 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
784 // CMB: draw nothing if transformed w or h is 0
785 if (ww
== 0 || hh
== 0) return;
787 // CMB: handle -ve width and/or height
788 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
789 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
793 if (m_brush
.GetStyle() != wxTRANSPARENT
)
795 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
797 gdk_gc_set_ts_origin( m_textGC
,
798 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
799 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
800 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
801 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
803 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
805 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
806 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
807 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
809 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
811 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
812 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
813 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
815 if (m_brush
.GetStyle() == wxSTIPPLE
)
817 gdk_gc_set_ts_origin( m_brushGC
,
818 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
819 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
820 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
821 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
825 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
829 if (m_pen
.GetStyle() != wxTRANSPARENT
)
830 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
833 CalcBoundingBox( x
, y
);
834 CalcBoundingBox( x
+ width
, y
+ height
);
837 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
839 wxCHECK_RET( Ok(), wxT("invalid window dc") );
841 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
843 wxCoord xx
= XLOG2DEV(x
);
844 wxCoord yy
= YLOG2DEV(y
);
845 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
846 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
847 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
849 // CMB: handle -ve width and/or height
850 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
851 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
853 // CMB: if radius is zero use DrawRectangle() instead to avoid
854 // X drawing errors with small radii
857 DrawRectangle( x
, y
, width
, height
);
861 // CMB: draw nothing if transformed w or h is 0
862 if (ww
== 0 || hh
== 0) return;
864 // CMB: adjust size if outline is drawn otherwise the result is
865 // 1 pixel too wide and high
866 if (m_pen
.GetStyle() != wxTRANSPARENT
)
874 // CMB: ensure dd is not larger than rectangle otherwise we
875 // get an hour glass shape
877 if (dd
> ww
) dd
= ww
;
878 if (dd
> hh
) dd
= hh
;
881 if (m_brush
.GetStyle() != wxTRANSPARENT
)
883 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
885 gdk_gc_set_ts_origin( m_textGC
,
886 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
887 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
888 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
889 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
890 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
891 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
892 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
893 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
894 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
896 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
898 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
899 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
900 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
901 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
902 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
903 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
904 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
905 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
907 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
909 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
910 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
911 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
912 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
913 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
914 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
915 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
916 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
918 if (m_brush
.GetStyle() == wxSTIPPLE
)
920 gdk_gc_set_ts_origin( m_brushGC
,
921 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
922 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
923 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
924 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
925 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
926 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
927 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
928 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
929 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
933 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
934 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
935 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
936 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
937 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
938 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
942 if (m_pen
.GetStyle() != wxTRANSPARENT
)
944 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
945 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
946 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
947 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
948 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
949 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
950 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
951 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
955 // this ignores the radius
956 CalcBoundingBox( x
, y
);
957 CalcBoundingBox( x
+ width
, y
+ height
);
960 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
962 wxCHECK_RET( Ok(), wxT("invalid window dc") );
964 wxCoord xx
= XLOG2DEV(x
);
965 wxCoord yy
= YLOG2DEV(y
);
966 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
967 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
969 // CMB: handle -ve width and/or height
970 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
971 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
975 if (m_brush
.GetStyle() != wxTRANSPARENT
)
977 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
979 gdk_gc_set_ts_origin( m_textGC
,
980 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
981 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
982 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
983 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
985 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
987 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
988 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
989 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
991 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
993 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
994 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
995 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
997 if (m_brush
.GetStyle() == wxSTIPPLE
)
999 gdk_gc_set_ts_origin( m_brushGC
,
1000 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1001 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1002 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1003 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1007 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1011 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1012 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1015 CalcBoundingBox( x
, y
);
1016 CalcBoundingBox( x
+ width
, y
+ height
);
1019 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1021 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1022 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1025 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1026 wxCoord x
, wxCoord y
,
1029 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1031 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1033 bool is_mono
= bitmap
.GetDepth() == 1;
1035 // scale/translate size and position
1036 int xx
= XLOG2DEV(x
);
1037 int yy
= YLOG2DEV(y
);
1039 int w
= bitmap
.GetWidth();
1040 int h
= bitmap
.GetHeight();
1042 CalcBoundingBox( x
, y
);
1043 CalcBoundingBox( x
+ w
, y
+ h
);
1045 if (!m_window
) return;
1047 int ww
= XLOG2DEVREL(w
);
1048 int hh
= YLOG2DEVREL(h
);
1050 // compare to current clipping region
1051 if (!m_currentClippingRegion
.IsNull())
1053 wxRegion
tmp( xx
,yy
,ww
,hh
);
1054 tmp
.Intersect( m_currentClippingRegion
);
1059 // scale bitmap if required
1060 wxBitmap use_bitmap
= bitmap
;
1061 if ((w
!= ww
) || (h
!= hh
))
1062 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1064 #if !GTK_CHECK_VERSION(2,2,0)
1065 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1066 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1067 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1068 // and also creates the mask as a side-effect:
1069 use_bitmap
.GetPixmap();
1072 // apply mask if any
1073 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1074 if (useMask
&& use_bitmap
.GetMask())
1075 mask
= use_bitmap
.GetMask()->GetBitmap();
1077 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1079 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1083 if (!m_currentClippingRegion
.IsNull())
1086 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1087 GdkGC
*gc
= gdk_gc_new( new_mask
);
1089 gdk_gc_set_foreground( gc
, &col
);
1090 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1092 gdk_gc_set_background( gc
, &col
);
1094 gdk_gc_set_foreground( gc
, &col
);
1095 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1096 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1097 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1098 gdk_gc_set_stipple( gc
, mask
);
1099 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1101 g_object_unref (gc
);
1104 gdk_gc_set_clip_mask(use_gc
, mask
);
1105 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1108 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1109 // drawing a mono-bitmap (XBitmap) we use the current text GC
1112 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1113 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1114 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1115 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1116 gdk_wx_draw_bitmap( bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1118 gdk_draw_drawable(m_window
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1120 g_object_unref (bitmap2
);
1121 g_object_unref (gc
);
1125 #if GTK_CHECK_VERSION(2,2,0)
1126 if (!gtk_check_version(2,2,0) && use_bitmap
.HasPixbuf())
1128 gdk_draw_pixbuf(m_window
, use_gc
,
1129 use_bitmap
.GetPixbuf(),
1130 0, 0, xx
, yy
, -1, -1,
1131 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1136 gdk_draw_drawable(m_window
, use_gc
,
1137 use_bitmap
.GetPixmap(),
1138 0, 0, xx
, yy
, -1, -1);
1142 // remove mask again if any
1145 gdk_gc_set_clip_mask(use_gc
, NULL
);
1146 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1147 if (!m_currentClippingRegion
.IsNull())
1148 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1149 if (new_mask
!= NULL
)
1150 g_object_unref(new_mask
);
1154 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1155 wxCoord width
, wxCoord height
,
1157 wxCoord xsrc
, wxCoord ysrc
,
1160 wxCoord xsrcMask
, wxCoord ysrcMask
)
1162 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
1164 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1166 if (!m_window
) return false;
1168 // transform the source DC coords to the device ones
1169 xsrc
= source
->XLOG2DEV(xsrc
);
1170 ysrc
= source
->YLOG2DEV(ysrc
);
1172 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1173 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1175 bool use_bitmap_method
= false;
1176 bool is_mono
= false;
1178 if (xsrcMask
== -1 && ysrcMask
== -1)
1184 if (srcDC
->m_isMemDC
)
1186 if (!memDC
->m_selected
.Ok()) return false;
1188 is_mono
= (memDC
->m_selected
.GetDepth() == 1);
1190 // we use the "XCopyArea" way to copy a memory dc into
1191 // a different window if the memory dc BOTH
1192 // a) doesn't have any mask or its mask isn't used
1196 if (useMask
&& (memDC
->m_selected
.GetMask()))
1198 // we HAVE TO use the direct way for memory dcs
1199 // that have mask since the XCopyArea doesn't know
1201 use_bitmap_method
= true;
1205 // we HAVE TO use the direct way for memory dcs
1206 // that are bitmaps because XCopyArea doesn't cope
1207 // with different bit depths
1208 use_bitmap_method
= true;
1210 else if ((xsrc
== 0) && (ysrc
== 0) &&
1211 (width
== memDC
->m_selected
.GetWidth()) &&
1212 (height
== memDC
->m_selected
.GetHeight()))
1214 // we SHOULD use the direct way if all of the bitmap
1215 // in the memory dc is copied in which case XCopyArea
1216 // wouldn't be able able to boost performace by reducing
1217 // the area to be scaled
1218 use_bitmap_method
= true;
1222 CalcBoundingBox( xdest
, ydest
);
1223 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1225 // scale/translate size and position
1226 wxCoord xx
= XLOG2DEV(xdest
);
1227 wxCoord yy
= YLOG2DEV(ydest
);
1229 wxCoord ww
= XLOG2DEVREL(width
);
1230 wxCoord hh
= YLOG2DEVREL(height
);
1232 // compare to current clipping region
1233 if (!m_currentClippingRegion
.IsNull())
1235 wxRegion
tmp( xx
,yy
,ww
,hh
);
1236 tmp
.Intersect( m_currentClippingRegion
);
1241 int old_logical_func
= m_logicalFunction
;
1242 SetLogicalFunction( logical_func
);
1244 if (use_bitmap_method
)
1246 // scale/translate bitmap size
1247 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1248 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1250 // Get clip coords for the bitmap. If we don't
1251 // use wxBitmap::Rescale(), which can clip the
1252 // bitmap, these are the same as the original
1259 // interpret userscale of src too
1261 memDC
->GetUserScale(&xsc
,&ysc
);
1262 bm_width
= (int) (bm_width
/ xsc
);
1263 bm_height
= (int) (bm_height
/ ysc
);
1265 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1266 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1268 // Scale bitmap if required
1269 wxBitmap use_bitmap
= memDC
->m_selected
;
1270 if ((memDC
->m_selected
.GetWidth()!= bm_ww
) || ( memDC
->m_selected
.GetHeight()!= bm_hh
))
1272 // This indicates that the blitting code below will get
1273 // a clipped bitmap and therefore needs to move the origin
1275 wxRegion
tmp( xx
,yy
,ww
,hh
);
1276 tmp
.Intersect( m_currentClippingRegion
);
1277 tmp
.GetBox(cx
,cy
,cw
,ch
);
1279 // Scale and clipped bitmap
1280 use_bitmap
= memDC
->m_selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1283 // apply mask if any
1284 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1285 if (useMask
&& use_bitmap
.GetMask())
1286 mask
= use_bitmap
.GetMask()->GetBitmap();
1288 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1290 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1294 if (!m_currentClippingRegion
.IsNull())
1297 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1298 GdkGC
*gc
= gdk_gc_new( new_mask
);
1300 gdk_gc_set_foreground( gc
, &col
);
1301 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1302 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1304 gdk_gc_set_background( gc
, &col
);
1306 gdk_gc_set_foreground( gc
, &col
);
1307 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1308 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1309 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1310 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1311 gdk_gc_set_stipple( gc
, mask
);
1312 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1314 g_object_unref (gc
);
1317 gdk_gc_set_clip_mask(use_gc
, mask
);
1318 if (new_mask
!= NULL
)
1319 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1321 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1324 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1325 // drawing a mono-bitmap (XBitmap) we use the current text GC
1329 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1330 GdkGC
*gc
= gdk_gc_new( bitmap
);
1331 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1332 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1333 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1335 gdk_draw_drawable(m_window
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1337 g_object_unref (bitmap
);
1338 g_object_unref (gc
);
1342 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1343 gdk_draw_drawable(m_window
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1346 // remove mask again if any
1349 gdk_gc_set_clip_mask(use_gc
, NULL
);
1350 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1351 if (!m_currentClippingRegion
.IsNull())
1352 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1356 g_object_unref (new_mask
);
1358 else // use_bitmap_method
1360 if ((width
!= ww
) || (height
!= hh
))
1363 wxRegion
tmp( xx
,yy
,ww
,hh
);
1364 tmp
.Intersect( m_currentClippingRegion
);
1365 wxCoord cx
,cy
,cw
,ch
;
1366 tmp
.GetBox(cx
,cy
,cw
,ch
);
1369 wxBitmap bitmap
= memDC
->m_selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1371 // draw scaled bitmap
1372 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1373 gdk_draw_drawable( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1377 // No scaling and not a memory dc with a mask either
1379 // copy including child window contents
1380 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1381 gdk_draw_drawable( m_window
, m_penGC
,
1385 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1389 SetLogicalFunction( old_logical_func
);
1394 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1396 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1398 if (!m_window
) return;
1400 if (text
.empty()) return;
1405 wxCHECK_RET( m_context
, wxT("no Pango context") );
1406 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1407 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1409 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1411 const wxCharBuffer data
= wxGTK_CONV( text
);
1414 const size_t datalen
= strlen(data
);
1415 pango_layout_set_text( m_layout
, data
, datalen
);
1419 PangoAttrList
*attrs
= pango_attr_list_new();
1420 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1422 a
->end_index
= datalen
;
1423 pango_attr_list_insert(attrs
, a
);
1424 pango_layout_set_attributes(m_layout
, attrs
);
1425 pango_attr_list_unref(attrs
);
1430 if (fabs(m_scaleY
- 1.0) > 0.00001)
1432 // If there is a user or actually any scale applied to
1433 // the device context, scale the font.
1435 // scale font description
1436 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1437 double size
= oldSize
;
1438 size
= size
* m_scaleY
;
1439 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1441 // actually apply scaled font
1442 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1444 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1445 if ( m_backgroundMode
== wxSOLID
)
1447 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1448 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1449 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1453 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1455 // reset unscaled size
1456 pango_font_description_set_size( m_fontdesc
, oldSize
);
1458 // actually apply unscaled font
1459 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1463 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1464 if ( m_backgroundMode
== wxSOLID
)
1466 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1467 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1468 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1471 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1476 // undo underline attributes setting:
1477 pango_layout_set_attributes(m_layout
, NULL
);
1483 width
= wxCoord(width
/ m_scaleX
);
1484 height
= wxCoord(height
/ m_scaleY
);
1485 CalcBoundingBox (x
+ width
, y
+ height
);
1486 CalcBoundingBox (x
, y
);
1490 // TODO: There is an example of rotating text with GTK2 that would probably be
1491 // a better approach here:
1492 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1494 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1496 if (!m_window
|| text
.empty())
1499 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1501 if ( wxIsNullDouble(angle
) )
1503 DrawText(text
, x
, y
);
1510 // TODO: implement later without GdkFont for GTK 2.0
1511 GetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1513 // draw the string normally
1516 dc
.SelectObject(src
);
1517 dc
.SetFont(GetFont());
1518 dc
.SetBackground(*wxBLACK_BRUSH
);
1519 dc
.SetBrush(*wxBLACK_BRUSH
);
1521 dc
.SetTextForeground( *wxWHITE
);
1522 dc
.DrawText(text
, 0, 0);
1523 dc
.SelectObject(wxNullBitmap
);
1525 // Calculate the size of the rotated bounding box.
1526 double rad
= DegToRad(angle
);
1527 double dx
= cos(rad
),
1530 // the rectngle vertices are counted clockwise with the first one being at
1531 // (0, 0) (or, rather, at (x, y))
1533 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1536 double x3
= x4
+ x2
,
1540 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1541 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1542 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1543 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1546 wxImage image
= src
.ConvertToImage();
1548 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1549 m_textForegroundColour
.Green(),
1550 m_textForegroundColour
.Blue() );
1551 image
= image
.Rotate( rad
, wxPoint(0,0) );
1553 int i_angle
= (int) angle
;
1554 i_angle
= i_angle
% 360;
1558 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1559 xoffset
= image
.GetWidth();
1561 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1562 yoffset
= image
.GetHeight();
1564 if ((i_angle
>= 0) && (i_angle
< 90))
1565 yoffset
-= (int)( cos(rad
)*h
);
1566 if ((i_angle
>= 90) && (i_angle
< 180))
1567 xoffset
-= (int)( sin(rad
)*h
);
1568 if ((i_angle
>= 180) && (i_angle
< 270))
1569 yoffset
-= (int)( cos(rad
)*h
);
1570 if ((i_angle
>= 270) && (i_angle
< 360))
1571 xoffset
-= (int)( sin(rad
)*h
);
1573 int i_x
= x
- xoffset
;
1574 int i_y
= y
- yoffset
;
1577 DoDrawBitmap( src
, i_x
, i_y
, true );
1580 // it would be better to draw with non underlined font and draw the line
1581 // manually here (it would be more straight...)
1583 if ( m_font
.GetUnderlined() )
1585 gdk_draw_line( m_window
, m_textGC
,
1586 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1587 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1591 // update the bounding box
1592 CalcBoundingBox(x
+ minX
, y
+ minY
);
1593 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1596 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1597 wxCoord
*width
, wxCoord
*height
,
1598 wxCoord
*descent
, wxCoord
*externalLeading
,
1599 wxFont
*theFont
) const
1607 if ( externalLeading
)
1608 *externalLeading
= 0;
1613 // ensure that theFont is always non-NULL
1614 if ( !theFont
|| !theFont
->Ok() )
1615 theFont
= wx_const_cast(wxFont
*, &m_font
);
1617 // and use it if it's valid
1618 if ( theFont
->Ok() )
1620 pango_layout_set_font_description
1623 theFont
->GetNativeFontInfo()->description
1627 // Set layout's text
1628 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1631 // hardly ideal, but what else can we do if conversion failed?
1635 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1640 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1641 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1642 int baseline
= pango_layout_iter_get_baseline(iter
);
1643 pango_layout_iter_free(iter
);
1644 *descent
= h
- PANGO_PIXELS(baseline
);
1647 *height
= (wxCoord
) h
;
1651 pango_layout_get_pixel_size( m_layout
, width
, height
);
1654 // Reset old font description
1656 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1659 wxCoord
wxWindowDC::GetCharWidth() const
1661 pango_layout_set_text( m_layout
, "H", 1 );
1663 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1667 wxCoord
wxWindowDC::GetCharHeight() const
1669 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, NULL
);
1670 return PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) + pango_font_metrics_get_ascent (metrics
));
1673 void wxWindowDC::Clear()
1675 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1677 if (!m_window
) return;
1679 // VZ: the code below results in infinite recursion and crashes when
1680 // dc.Clear() is done from OnPaint() so I disable it for now.
1681 // I don't know what the correct fix is but Clear() surely should not
1682 // reenter OnPaint()!
1684 /* - we either are a memory dc or have a window as the
1685 owner. anything else shouldn't happen.
1686 - we don't use gdk_window_clear() as we don't set
1687 the window's background colour anymore. it is too
1688 much pain to keep the DC's and the window's back-
1689 ground colour in synch. */
1700 GetSize( &width
, &height
);
1701 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1706 GetSize( &width
, &height
);
1707 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1711 void wxWindowDC::SetFont( const wxFont
&font
)
1718 pango_font_description_free( m_fontdesc
);
1720 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1725 PangoContext
*oldContext
= m_context
;
1727 m_context
= m_owner
->GtkGetPangoDefaultContext();
1729 // If we switch back/forth between different contexts
1730 // we also have to create a new layout. I think so,
1731 // at least, and it doesn't hurt to do it.
1732 if (oldContext
!= m_context
)
1735 g_object_unref (m_layout
);
1737 m_layout
= pango_layout_new( m_context
);
1741 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1745 void wxWindowDC::SetPen( const wxPen
&pen
)
1747 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1749 if (m_pen
== pen
) return;
1753 if (!m_pen
.Ok()) return;
1755 if (!m_window
) return;
1757 gint width
= m_pen
.GetWidth();
1760 // CMB: if width is non-zero scale it with the dc
1765 // X doesn't allow different width in x and y and so we take
1768 ( fabs((double) XLOG2DEVREL(width
)) +
1769 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1773 // width can't be 0 or an internal GTK error occurs inside
1774 // gdk_gc_set_dashes() below
1779 static const wxGTKDash dotted
[] = {1, 1};
1780 static const wxGTKDash short_dashed
[] = {2, 2};
1781 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1782 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1784 // We express dash pattern in pen width unit, so we are
1785 // independent of zoom factor and so on...
1787 const wxGTKDash
*req_dash
;
1789 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1790 switch (m_pen
.GetStyle())
1794 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1795 req_nb_dash
= m_pen
.GetDashCount();
1796 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1801 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1808 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1810 req_dash
= wxCoord_dashed
;
1815 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1817 req_dash
= short_dashed
;
1822 // lineStyle = GDK_LINE_DOUBLE_DASH;
1823 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1825 req_dash
= dotted_dashed
;
1830 case wxSTIPPLE_MASK_OPAQUE
:
1835 lineStyle
= GDK_LINE_SOLID
;
1836 req_dash
= (wxGTKDash
*)NULL
;
1842 if (req_dash
&& req_nb_dash
)
1844 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1847 for (int i
= 0; i
< req_nb_dash
; i
++)
1848 real_req_dash
[i
] = req_dash
[i
] * width
;
1849 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1850 delete[] real_req_dash
;
1854 // No Memory. We use non-scaled dash pattern...
1855 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1859 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1860 switch (m_pen
.GetCap())
1862 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1863 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1870 capStyle
= GDK_CAP_NOT_LAST
;
1874 capStyle
= GDK_CAP_ROUND
;
1880 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1881 switch (m_pen
.GetJoin())
1883 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1884 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1886 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1889 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1891 m_pen
.GetColour().CalcPixel( m_cmap
);
1892 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1895 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1897 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1899 if (m_brush
== brush
) return;
1903 if (!m_brush
.Ok()) return;
1905 if (!m_window
) return;
1907 m_brush
.GetColour().CalcPixel( m_cmap
);
1908 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1910 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1912 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1914 if (m_brush
.GetStipple()->GetDepth() != 1)
1916 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1917 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1921 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1922 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1926 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1928 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1929 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1932 if (m_brush
.IsHatch())
1934 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1935 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1936 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
1940 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1942 /* CMB 21/7/98: Added SetBackground. Sets background brush
1943 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1945 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1947 if (m_backgroundBrush
== brush
) return;
1949 m_backgroundBrush
= brush
;
1951 if (!m_backgroundBrush
.Ok()) return;
1953 if (!m_window
) return;
1955 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1956 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
1957 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
1958 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1959 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1961 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1963 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
1965 if (m_backgroundBrush
.GetStipple()->GetDepth() != 1)
1967 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
1968 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
1972 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1973 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
1977 if (m_backgroundBrush
.IsHatch())
1979 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1980 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
1981 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
1985 void wxWindowDC::SetLogicalFunction( int function
)
1987 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1989 if (m_logicalFunction
== function
)
1992 // VZ: shouldn't this be a CHECK?
1999 case wxXOR
: mode
= GDK_XOR
; break;
2000 case wxINVERT
: mode
= GDK_INVERT
; break;
2001 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2002 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2003 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2004 case wxSET
: mode
= GDK_SET
; break;
2005 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2006 case wxAND
: mode
= GDK_AND
; break;
2007 case wxOR
: mode
= GDK_OR
; break;
2008 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2009 case wxNAND
: mode
= GDK_NAND
; break;
2010 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2011 case wxCOPY
: mode
= GDK_COPY
; break;
2012 case wxNO_OP
: mode
= GDK_NOOP
; break;
2013 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2015 // unsupported by GTK
2016 case wxNOR
: mode
= GDK_COPY
; break;
2018 wxFAIL_MSG( wxT("unsupported logical function") );
2022 m_logicalFunction
= function
;
2024 gdk_gc_set_function( m_penGC
, mode
);
2025 gdk_gc_set_function( m_brushGC
, mode
);
2027 // to stay compatible with wxMSW, we don't apply ROPs to the text
2028 // operations (i.e. DrawText/DrawRotatedText).
2029 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2030 gdk_gc_set_function( m_textGC
, mode
);
2033 void wxWindowDC::SetTextForeground( const wxColour
&col
)
2035 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2037 // don't set m_textForegroundColour to an invalid colour as we'd crash
2038 // later then (we use m_textForegroundColour.GetColor() without checking
2040 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2043 m_textForegroundColour
= col
;
2047 m_textForegroundColour
.CalcPixel( m_cmap
);
2048 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2052 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2054 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2057 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2060 m_textBackgroundColour
= col
;
2064 m_textBackgroundColour
.CalcPixel( m_cmap
);
2065 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2069 void wxWindowDC::SetBackgroundMode( int mode
)
2071 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2073 m_backgroundMode
= mode
;
2075 if (!m_window
) return;
2077 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2078 // transparent/solid background mode
2080 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2082 gdk_gc_set_fill( m_brushGC
,
2083 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2087 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2089 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
2092 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2094 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2096 if (!m_window
) return;
2099 rect
.x
= XLOG2DEV(x
);
2100 rect
.y
= YLOG2DEV(y
);
2101 rect
.width
= XLOG2DEVREL(width
);
2102 rect
.height
= YLOG2DEVREL(height
);
2104 if (!m_currentClippingRegion
.IsNull())
2105 m_currentClippingRegion
.Intersect( rect
);
2107 m_currentClippingRegion
.Union( rect
);
2109 #if USE_PAINT_REGION
2110 if (!m_paintClippingRegion
.IsNull())
2111 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2114 wxCoord xx
, yy
, ww
, hh
;
2115 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2116 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2118 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2119 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2120 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2121 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2124 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2126 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2130 DestroyClippingRegion();
2134 if (!m_window
) return;
2136 if (!m_currentClippingRegion
.IsNull())
2137 m_currentClippingRegion
.Intersect( region
);
2139 m_currentClippingRegion
.Union( region
);
2141 #if USE_PAINT_REGION
2142 if (!m_paintClippingRegion
.IsNull())
2143 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2146 wxCoord xx
, yy
, ww
, hh
;
2147 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2148 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2150 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2151 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2152 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2153 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2156 void wxWindowDC::DestroyClippingRegion()
2158 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2160 wxDC::DestroyClippingRegion();
2162 m_currentClippingRegion
.Clear();
2164 #if USE_PAINT_REGION
2165 if (!m_paintClippingRegion
.IsEmpty())
2166 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2169 if (!m_window
) return;
2171 if (m_currentClippingRegion
.IsEmpty())
2173 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2174 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2175 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2176 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2180 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2181 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2182 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2183 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2187 void wxWindowDC::Destroy()
2189 if (m_penGC
) wxFreePoolGC( m_penGC
);
2190 m_penGC
= (GdkGC
*) NULL
;
2191 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2192 m_brushGC
= (GdkGC
*) NULL
;
2193 if (m_textGC
) wxFreePoolGC( m_textGC
);
2194 m_textGC
= (GdkGC
*) NULL
;
2195 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2196 m_bgGC
= (GdkGC
*) NULL
;
2199 void wxWindowDC::ComputeScaleAndOrigin()
2201 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2203 wxDC::ComputeScaleAndOrigin();
2205 // if scale has changed call SetPen to recalulate the line width
2206 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.Ok() )
2208 // this is a bit artificial, but we need to force wxDC to think the pen
2216 // Resolution in pixels per logical inch
2217 wxSize
wxWindowDC::GetPPI() const
2219 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2222 int wxWindowDC::GetDepth() const
2224 return gdk_drawable_get_depth(m_window
);
2228 //-----------------------------------------------------------------------------
2230 //-----------------------------------------------------------------------------
2232 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2234 // Limit the paint region to the window size. Sometimes
2235 // the paint region is too big, and this risks X11 errors
2236 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2238 wxRect originalRect
= region
.GetBox();
2239 wxRect
rect(originalRect
);
2240 if (rect
.width
+ rect
.x
> sz
.x
)
2241 rect
.width
= sz
.x
- rect
.x
;
2242 if (rect
.height
+ rect
.y
> sz
.y
)
2243 rect
.height
= sz
.y
- rect
.y
;
2244 if (rect
!= originalRect
)
2246 region
= wxRegion(rect
);
2247 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2248 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2249 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2253 wxPaintDC::wxPaintDC( wxWindow
*win
)
2256 #if USE_PAINT_REGION
2257 if (!win
->m_clipPaintRegion
)
2260 wxSize sz
= win
->GetSize();
2261 m_paintClippingRegion
= win
->GetUpdateRegion();
2262 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2264 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2267 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2268 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2270 if (sz
.x
<= 0 || sz
.y
<= 0)
2273 gdk_gc_set_clip_region( m_penGC
, region
);
2274 gdk_gc_set_clip_region( m_brushGC
, region
);
2275 gdk_gc_set_clip_region( m_textGC
, region
);
2276 gdk_gc_set_clip_region( m_bgGC
, region
);
2278 #endif // USE_PAINT_REGION
2281 //-----------------------------------------------------------------------------
2283 //-----------------------------------------------------------------------------
2285 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2287 wxClientDC::wxClientDC( wxWindow
*win
)
2290 wxCHECK_RET( win
, _T("NULL window in wxClientDC::wxClientDC") );
2292 #ifdef __WXUNIVERSAL__
2293 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2294 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2295 wxSize size
= win
->GetClientSize();
2296 SetClippingRegion(wxPoint(0, 0), size
);
2297 #endif // __WXUNIVERSAL__
2300 void wxClientDC::DoGetSize(int *width
, int *height
) const
2302 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2304 m_owner
->GetClientSize( width
, height
);
2307 // ----------------------------------------------------------------------------
2309 // ----------------------------------------------------------------------------
2311 class wxDCModule
: public wxModule
2318 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2321 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2323 bool wxDCModule::OnInit()
2329 void wxDCModule::OnExit()