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"
20 #include "wx/window.h"
22 #include "wx/dcmemory.h"
23 #include "wx/math.h" // for floating-point functions
25 #include "wx/module.h"
28 #include "wx/fontutil.h"
29 #include "wx/scrolwin.h"
31 #include "wx/gtk/win_gtk.h"
32 #include "wx/gtk/private.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #define XLOG2DEV(x) LogicalToDeviceX(x)
41 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
42 #define YLOG2DEV(y) LogicalToDeviceY(y)
43 #define YLOG2DEVREL(y) LogicalToDeviceYRel(y)
45 #define USE_PAINT_REGION 1
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
59 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
60 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
63 static GdkPixmap
*hatches
[num_hatches
];
64 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
66 extern GtkWidget
*wxGetRootWindow();
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 const double RAD2DEG
= 180.0 / M_PI
;
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
79 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
81 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
83 //-----------------------------------------------------------------------------
84 // temporary implementation of the missing GDK function
85 //-----------------------------------------------------------------------------
87 #include "gdk/gdkprivate.h"
90 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
96 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
97 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
98 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
100 gint src_width
, src_height
;
101 gdk_drawable_get_size(src
, &src_width
, &src_height
);
103 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
105 GDK_WINDOW_XID(drawable
),
108 src_width
, src_height
,
113 //-----------------------------------------------------------------------------
114 // Implement Pool of Graphic contexts. Creating them takes too much time.
115 //-----------------------------------------------------------------------------
141 #define GC_POOL_ALLOC_SIZE 100
143 static int wxGCPoolSize
= 0;
145 static wxGC
*wxGCPool
= NULL
;
147 static void wxInitGCPool()
149 // This really could wait until the first call to
150 // wxGetPoolGC, but we will make the first allocation
151 // now when other initialization is being performed.
153 // Set initial pool size.
154 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
156 // Allocate initial pool.
157 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
158 if (wxGCPool
== NULL
)
160 // If we cannot malloc, then fail with error
161 // when debug is enabled. If debug is not enabled,
162 // the problem will eventually get caught
164 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
168 // Zero initial pool.
169 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
172 static void wxCleanUpGCPool()
174 for (int i
= 0; i
< wxGCPoolSize
; i
++)
176 if (wxGCPool
[i
].m_gc
)
177 g_object_unref (wxGCPool
[i
].m_gc
);
185 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
189 // Look for an available GC.
190 for (int i
= 0; i
< wxGCPoolSize
; i
++)
192 if (!wxGCPool
[i
].m_gc
)
194 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
195 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
196 wxGCPool
[i
].m_type
= type
;
197 wxGCPool
[i
].m_used
= false;
199 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
201 wxGCPool
[i
].m_used
= true;
202 return wxGCPool
[i
].m_gc
;
206 // We did not find an available GC.
207 // We need to grow the GC pool.
208 pptr
= (wxGC
*)realloc(wxGCPool
,
209 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
212 // Initialize newly allocated pool.
214 memset(&wxGCPool
[wxGCPoolSize
], 0,
215 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
217 // Initialize entry we will return.
218 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
219 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
220 wxGCPool
[wxGCPoolSize
].m_type
= type
;
221 wxGCPool
[wxGCPoolSize
].m_used
= true;
223 // Set new value of pool size.
224 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
226 // Return newly allocated entry.
227 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
230 // The realloc failed. Fall through to error.
231 wxFAIL_MSG( wxT("No GC available") );
233 return (GdkGC
*) NULL
;
236 static void wxFreePoolGC( GdkGC
*gc
)
238 for (int i
= 0; i
< wxGCPoolSize
; i
++)
240 if (wxGCPool
[i
].m_gc
== gc
)
242 wxGCPool
[i
].m_used
= false;
247 wxFAIL_MSG( wxT("Wrong GC") );
250 //-----------------------------------------------------------------------------
252 //-----------------------------------------------------------------------------
255 IMPLEMENT_ABSTRACT_CLASS(wxGTKWindowImplDC
, wxGTKImplDC
)
257 IMPLEMENT_ABSTRACT_CLASS(wxWindowDC
, wxDC
)
261 wxGTKWindowImplDC::wxGTKWindowImplDC( wxDC
*owner
) :
264 wxWindowDC::wxWindowDC()
267 m_penGC
= (GdkGC
*) NULL
;
268 m_brushGC
= (GdkGC
*) NULL
;
269 m_textGC
= (GdkGC
*) NULL
;
270 m_bgGC
= (GdkGC
*) NULL
;
271 m_cmap
= (GdkColormap
*) NULL
;
272 m_isScreenDC
= false;
273 m_owningWindow
= (wxWindow
*)NULL
;
274 m_context
= (PangoContext
*)NULL
;
275 m_layout
= (PangoLayout
*)NULL
;
276 m_fontdesc
= (PangoFontDescription
*)NULL
;
280 wxGTKWindowImplDC::wxGTKWindowImplDC( wxDC
*owner
, wxWindow
*window
) :
283 wxWindowDC::wxWindowDC( wxWindow
*window
)
286 wxASSERT_MSG( window
, wxT("DC needs a window") );
288 m_penGC
= (GdkGC
*) NULL
;
289 m_brushGC
= (GdkGC
*) NULL
;
290 m_textGC
= (GdkGC
*) NULL
;
291 m_bgGC
= (GdkGC
*) NULL
;
292 m_cmap
= (GdkColormap
*) NULL
;
293 m_owningWindow
= (wxWindow
*)NULL
;
294 m_isScreenDC
= false;
295 m_font
= window
->GetFont();
297 GtkWidget
*widget
= window
->m_wxwindow
;
299 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
300 // code should still be able to create wxClientDCs for them, so we will
301 // use the parent window here then.
304 window
= window
->GetParent();
305 widget
= window
->m_wxwindow
;
308 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
310 m_context
= window
->GtkGetPangoDefaultContext();
311 m_layout
= pango_layout_new( m_context
);
312 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
314 GtkPizza
*pizza
= GTK_PIZZA( widget
);
315 m_window
= pizza
->bin_window
;
317 // Window not realized ?
320 // Don't report problems as per MSW.
326 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
330 /* this must be done after SetUpDC, bacause SetUpDC calls the
331 repective SetBrush, SetPen, SetBackground etc functions
332 to set up the DC. SetBackground call m_owner->SetBackground
333 and this might not be desired as the standard dc background
334 is white whereas a window might assume gray to be the
335 standard (as e.g. wxStatusBar) */
337 m_owningWindow
= window
;
339 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
340 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
345 // origin in the upper right corner
346 m_deviceOriginX
= m_owningWindow
->GetClientSize().x
;
350 wxGTKWindowImplDC::~wxGTKWindowImplDC()
355 g_object_unref (m_layout
);
357 pango_font_description_free( m_fontdesc
);
360 void wxGTKWindowImplDC::SetUpDC( bool isMemDC
)
364 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
370 wxGTKMemoryImplDC
*mem_dc
= (wxGTKMemoryImplDC
*) this;
371 if (mem_dc
->GetSelectedBitmap().GetDepth() == 1)
373 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
374 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
375 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
376 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
385 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
386 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
387 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
388 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
392 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
393 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
394 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
395 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
399 /* background colour */
400 m_backgroundBrush
= *wxWHITE_BRUSH
;
401 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
403 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
405 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
409 m_textForegroundColour
.CalcPixel( m_cmap
);
410 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
412 m_textBackgroundColour
.CalcPixel( m_cmap
);
413 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
415 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
417 gdk_gc_set_colormap( m_textGC
, m_cmap
);
420 m_pen
.GetColour().CalcPixel( m_cmap
);
421 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
422 gdk_gc_set_background( m_penGC
, bg_col
);
424 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
427 m_brush
.GetColour().CalcPixel( m_cmap
);
428 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
429 gdk_gc_set_background( m_brushGC
, bg_col
);
431 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
434 gdk_gc_set_background( m_bgGC
, bg_col
);
435 gdk_gc_set_foreground( m_bgGC
, bg_col
);
437 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
440 gdk_gc_set_function( m_textGC
, GDK_COPY
);
441 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
442 gdk_gc_set_function( m_penGC
, GDK_COPY
);
445 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
446 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
447 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
448 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
452 hatch_bitmap
= hatches
;
453 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
454 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
455 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
456 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
457 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
458 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
462 void wxGTKWindowImplDC::DoGetSize( int* width
, int* height
) const
464 wxCHECK_RET( m_owningWindow
, _T("GetSize() doesn't work without window") );
466 m_owningWindow
->GetSize(width
, height
);
469 bool wxGTKWindowImplDC::DoFloodFill(wxCoord x
, wxCoord y
,
470 const wxColour
& col
, int style
)
473 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
474 const wxColour
& col
, int style
);
476 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
482 bool wxGTKWindowImplDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
485 // Generic (and therefore rather inefficient) method.
486 // Could be improved.
488 wxBitmap
bitmap(1, 1);
489 memdc
.SelectObject(bitmap
);
490 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
491 memdc
.SelectObject(wxNullBitmap
);
493 wxImage image
= bitmap
.ConvertToImage();
494 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
496 #else // !wxUSE_IMAGE
498 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
501 void wxGTKWindowImplDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
503 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
505 if (m_pen
.GetStyle() != wxTRANSPARENT
)
508 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
510 CalcBoundingBox(x1
, y1
);
511 CalcBoundingBox(x2
, y2
);
515 void wxGTKWindowImplDC::DoCrossHair( wxCoord x
, wxCoord y
)
517 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
519 if (m_pen
.GetStyle() != wxTRANSPARENT
)
523 GetOwner()->GetSize( &w
, &h
);
524 wxCoord xx
= XLOG2DEV(x
);
525 wxCoord yy
= YLOG2DEV(y
);
528 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
529 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
534 void wxGTKWindowImplDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
535 wxCoord xc
, wxCoord yc
)
537 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
539 wxCoord xx1
= XLOG2DEV(x1
);
540 wxCoord yy1
= YLOG2DEV(y1
);
541 wxCoord xx2
= XLOG2DEV(x2
);
542 wxCoord yy2
= YLOG2DEV(y2
);
543 wxCoord xxc
= XLOG2DEV(xc
);
544 wxCoord yyc
= YLOG2DEV(yc
);
545 double dx
= xx1
- xxc
;
546 double dy
= yy1
- yyc
;
547 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
548 wxCoord r
= (wxCoord
)radius
;
549 double radius1
, radius2
;
551 if (xx1
== xx2
&& yy1
== yy2
)
556 else if ( wxIsNullDouble(radius
) )
563 radius1
= (xx1
- xxc
== 0) ?
564 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
565 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
566 radius2
= (xx2
- xxc
== 0) ?
567 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
568 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
570 wxCoord alpha1
= wxCoord(radius1
* 64.0);
571 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
572 while (alpha2
<= 0) alpha2
+= 360*64;
573 while (alpha1
> 360*64) alpha1
-= 360*64;
577 if (m_brush
.GetStyle() != wxTRANSPARENT
)
579 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
581 gdk_gc_set_ts_origin( m_textGC
,
582 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
583 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
584 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
585 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
587 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
589 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
590 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
591 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
593 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
595 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
596 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
597 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
599 if (m_brush
.GetStyle() == wxSTIPPLE
)
601 gdk_gc_set_ts_origin( m_brushGC
,
602 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
603 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
604 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
605 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
609 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
613 if (m_pen
.GetStyle() != wxTRANSPARENT
)
615 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
617 if ((m_brush
.GetStyle() != wxTRANSPARENT
) && (alpha2
- alpha1
!= 360*64))
619 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
620 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
625 CalcBoundingBox (x1
, y1
);
626 CalcBoundingBox (x2
, y2
);
629 void wxGTKWindowImplDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
631 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
633 wxCoord xx
= XLOG2DEV(x
);
634 wxCoord yy
= YLOG2DEV(y
);
635 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
636 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
638 // CMB: handle -ve width and/or height
639 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
640 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
644 wxCoord start
= wxCoord(sa
* 64.0);
645 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
647 if (m_brush
.GetStyle() != wxTRANSPARENT
)
649 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
651 gdk_gc_set_ts_origin( m_textGC
,
652 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
653 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
654 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
655 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
657 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
659 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
660 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
661 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
663 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
665 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
666 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
667 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
669 if (m_brush
.GetStyle() == wxSTIPPLE
)
671 gdk_gc_set_ts_origin( m_brushGC
,
672 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
673 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
674 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
675 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
679 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
683 if (m_pen
.GetStyle() != wxTRANSPARENT
)
684 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
687 CalcBoundingBox (x
, y
);
688 CalcBoundingBox (x
+ width
, y
+ height
);
691 void wxGTKWindowImplDC::DoDrawPoint( wxCoord x
, wxCoord y
)
693 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
695 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
696 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
698 CalcBoundingBox (x
, y
);
701 void wxGTKWindowImplDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
703 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
705 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
708 //Check, if scaling is necessary
710 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
712 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
713 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
716 gpts
= new GdkPoint
[n
];
718 for (int i
= 0; i
< n
; i
++)
722 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
723 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
725 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
729 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
735 void wxGTKWindowImplDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
737 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
741 //Check, if scaling is necessary
743 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
745 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
746 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
749 gdkpoints
= new GdkPoint
[n
];
752 for (i
= 0 ; i
< n
; i
++)
756 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
757 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
759 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
764 if (m_brush
.GetStyle() != wxTRANSPARENT
)
766 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
768 gdk_gc_set_ts_origin( m_textGC
,
769 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
770 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
771 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
772 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
774 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
776 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
777 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
778 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
780 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
782 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
783 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
784 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
786 if (m_brush
.GetStyle() == wxSTIPPLE
)
788 gdk_gc_set_ts_origin( m_brushGC
,
789 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
790 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
791 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
792 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
796 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
800 if (m_pen
.GetStyle() != wxTRANSPARENT
)
803 for (i = 0 ; i < n ; i++)
805 gdk_draw_line( m_window, m_penGC,
808 gdkpoints[(i+1)%n].x,
809 gdkpoints[(i+1)%n].y);
812 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gdkpoints
, n
);
821 void wxGTKWindowImplDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
823 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
825 wxCoord xx
= XLOG2DEV(x
);
826 wxCoord yy
= YLOG2DEV(y
);
827 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
828 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
830 // CMB: draw nothing if transformed w or h is 0
831 if (ww
== 0 || hh
== 0) return;
833 // CMB: handle -ve width and/or height
834 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
835 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
839 if (m_brush
.GetStyle() != wxTRANSPARENT
)
841 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
843 gdk_gc_set_ts_origin( m_textGC
,
844 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
845 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
846 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
847 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
849 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
851 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
852 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
853 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
855 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
857 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
858 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
859 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
861 if (m_brush
.GetStyle() == wxSTIPPLE
)
863 gdk_gc_set_ts_origin( m_brushGC
,
864 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
865 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
866 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
867 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
871 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
875 if (m_pen
.GetStyle() != wxTRANSPARENT
)
878 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
879 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxSOLID
))
881 // Use 2 1-line rects instead
882 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
887 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
888 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
892 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
893 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
897 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
902 // Just use X11 for other cases
903 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
908 CalcBoundingBox( x
, y
);
909 CalcBoundingBox( x
+ width
, y
+ height
);
912 void wxGTKWindowImplDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
914 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
916 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
918 wxCoord xx
= XLOG2DEV(x
);
919 wxCoord yy
= YLOG2DEV(y
);
920 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
921 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
922 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
924 // CMB: handle -ve width and/or height
925 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
926 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
928 // CMB: if radius is zero use DrawRectangle() instead to avoid
929 // X drawing errors with small radii
932 DoDrawRectangle( x
, y
, width
, height
);
936 // CMB: draw nothing if transformed w or h is 0
937 if (ww
== 0 || hh
== 0) return;
939 // CMB: adjust size if outline is drawn otherwise the result is
940 // 1 pixel too wide and high
941 if (m_pen
.GetStyle() != wxTRANSPARENT
)
949 // CMB: ensure dd is not larger than rectangle otherwise we
950 // get an hour glass shape
952 if (dd
> ww
) dd
= ww
;
953 if (dd
> hh
) dd
= hh
;
956 if (m_brush
.GetStyle() != wxTRANSPARENT
)
958 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
960 gdk_gc_set_ts_origin( m_textGC
,
961 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
962 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
963 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
964 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
965 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
966 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
967 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
968 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
969 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
971 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
973 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
974 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
975 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
976 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
977 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
978 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
979 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
980 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
982 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
984 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
985 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
986 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
987 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
988 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
989 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
990 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
991 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
993 if (m_brush
.GetStyle() == wxSTIPPLE
)
995 gdk_gc_set_ts_origin( m_brushGC
,
996 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
997 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
998 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
999 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1000 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1001 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1002 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1003 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1004 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1008 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
1009 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1010 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1011 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1012 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1013 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1017 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1019 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
1020 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
1021 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
1022 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
1023 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1024 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1025 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1026 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1030 // this ignores the radius
1031 CalcBoundingBox( x
, y
);
1032 CalcBoundingBox( x
+ width
, y
+ height
);
1035 void wxGTKWindowImplDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1037 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1039 wxCoord xx
= XLOG2DEV(x
);
1040 wxCoord yy
= YLOG2DEV(y
);
1041 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1042 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1044 // CMB: handle -ve width and/or height
1045 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1046 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1050 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1052 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1054 gdk_gc_set_ts_origin( m_textGC
,
1055 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1056 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1057 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1058 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
1060 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1062 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
1063 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1064 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1066 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1068 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1069 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1070 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1072 if (m_brush
.GetStyle() == wxSTIPPLE
)
1074 gdk_gc_set_ts_origin( m_brushGC
,
1075 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1076 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1077 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1078 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1082 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1086 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1087 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1090 CalcBoundingBox( x
, y
);
1091 CalcBoundingBox( x
+ width
, y
+ height
);
1094 void wxGTKWindowImplDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1096 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1097 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1100 void wxGTKWindowImplDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1101 wxCoord x
, wxCoord y
,
1104 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1106 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1108 bool is_mono
= bitmap
.GetDepth() == 1;
1110 // scale/translate size and position
1111 int xx
= XLOG2DEV(x
);
1112 int yy
= YLOG2DEV(y
);
1114 int w
= bitmap
.GetWidth();
1115 int h
= bitmap
.GetHeight();
1117 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1120 CalcBoundingBox( x
, y
);
1121 CalcBoundingBox( x
+ w
, y
+ h
);
1123 if (!m_window
) return;
1125 int ww
= XLOG2DEVREL(w
);
1126 int hh
= YLOG2DEVREL(h
);
1128 // compare to current clipping region
1129 if (!m_currentClippingRegion
.IsNull())
1131 wxRegion
tmp( xx
,yy
,ww
,hh
);
1132 tmp
.Intersect( m_currentClippingRegion
);
1137 // scale bitmap if required
1138 wxBitmap use_bitmap
= bitmap
;
1139 if ((w
!= ww
) || (h
!= hh
))
1140 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1142 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1143 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1144 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1145 // and also creates the mask as a side-effect:
1146 if (gtk_check_version(2,2,0))
1147 use_bitmap
.GetPixmap();
1149 // apply mask if any
1150 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1151 if (useMask
&& use_bitmap
.GetMask())
1152 mask
= use_bitmap
.GetMask()->GetBitmap();
1154 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1156 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1160 if (!m_currentClippingRegion
.IsNull())
1163 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1164 GdkGC
*gc
= gdk_gc_new( new_mask
);
1166 gdk_gc_set_foreground( gc
, &col
);
1167 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1169 gdk_gc_set_background( gc
, &col
);
1171 gdk_gc_set_foreground( gc
, &col
);
1172 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1173 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1174 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1175 gdk_gc_set_stipple( gc
, mask
);
1176 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1178 g_object_unref (gc
);
1181 gdk_gc_set_clip_mask(use_gc
, mask
);
1182 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1185 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1186 // drawing a mono-bitmap (XBitmap) we use the current text GC
1189 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1190 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1191 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1192 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1193 gdk_wx_draw_bitmap(bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1195 gdk_draw_drawable(m_window
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1197 g_object_unref (bitmap2
);
1198 g_object_unref (gc
);
1202 #if GTK_CHECK_VERSION(2,2,0)
1203 if (!gtk_check_version(2,2,0) && use_bitmap
.HasPixbuf())
1205 gdk_draw_pixbuf(m_window
, use_gc
,
1206 use_bitmap
.GetPixbuf(),
1207 0, 0, xx
, yy
, -1, -1,
1208 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1213 gdk_draw_drawable(m_window
, use_gc
,
1214 use_bitmap
.GetPixmap(),
1215 0, 0, xx
, yy
, -1, -1);
1219 // remove mask again if any
1222 gdk_gc_set_clip_mask(use_gc
, NULL
);
1223 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1224 if (!m_currentClippingRegion
.IsNull())
1225 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1226 if (new_mask
!= NULL
)
1227 g_object_unref(new_mask
);
1231 bool wxGTKWindowImplDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1232 wxCoord width
, wxCoord height
,
1234 wxCoord xsrc
, wxCoord ysrc
,
1237 wxCoord xsrcMask
, wxCoord ysrcMask
)
1239 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1241 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1243 if (!m_window
) return false;
1245 // transform the source DC coords to the device ones
1246 xsrc
= source
->LogicalToDeviceX(xsrc
);
1247 ysrc
= source
->LogicalToDeviceY(ysrc
);
1250 wxMemoryDC
*memDC
= wxDynamicCast(source
, wxMemoryDC
);
1253 selected
= memDC
->GetSelectedBitmap();
1254 if ( !selected
.IsOk() )
1258 bool use_bitmap_method
= false;
1259 bool is_mono
= false;
1261 if (xsrcMask
== -1 && ysrcMask
== -1)
1267 if (selected
.IsOk())
1269 is_mono
= (selected
.GetDepth() == 1);
1271 // we use the "XCopyArea" way to copy a memory dc into
1272 // a different window if the memory dc BOTH
1273 // a) doesn't have any mask or its mask isn't used
1277 if (useMask
&& (selected
.GetMask()))
1279 // we HAVE TO use the direct way for memory dcs
1280 // that have mask since the XCopyArea doesn't know
1282 use_bitmap_method
= true;
1286 // we HAVE TO use the direct way for memory dcs
1287 // that are bitmaps because XCopyArea doesn't cope
1288 // with different bit depths
1289 use_bitmap_method
= true;
1291 else if ((xsrc
== 0) && (ysrc
== 0) &&
1292 (width
== selected
.GetWidth()) &&
1293 (height
== selected
.GetHeight()))
1295 // we SHOULD use the direct way if all of the bitmap
1296 // in the memory dc is copied in which case XCopyArea
1297 // wouldn't be able able to boost performace by reducing
1298 // the area to be scaled
1299 use_bitmap_method
= true;
1303 CalcBoundingBox( xdest
, ydest
);
1304 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1306 // scale/translate size and position
1307 wxCoord xx
= XLOG2DEV(xdest
);
1308 wxCoord yy
= YLOG2DEV(ydest
);
1310 wxCoord ww
= XLOG2DEVREL(width
);
1311 wxCoord hh
= YLOG2DEVREL(height
);
1313 // compare to current clipping region
1314 if (!m_currentClippingRegion
.IsNull())
1316 wxRegion
tmp( xx
,yy
,ww
,hh
);
1317 tmp
.Intersect( m_currentClippingRegion
);
1322 int old_logical_func
= m_logicalFunction
;
1323 SetLogicalFunction( logical_func
);
1325 if (use_bitmap_method
)
1327 // scale/translate bitmap size
1328 wxCoord bm_width
= selected
.GetWidth();
1329 wxCoord bm_height
= selected
.GetHeight();
1331 // Get clip coords for the bitmap. If we don't
1332 // use wxBitmap::Rescale(), which can clip the
1333 // bitmap, these are the same as the original
1340 // interpret userscale of src too
1342 memDC
->GetUserScale(&xsc
,&ysc
);
1343 bm_width
= (int) (bm_width
/ xsc
);
1344 bm_height
= (int) (bm_height
/ ysc
);
1346 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1347 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1349 // Scale bitmap if required
1350 wxBitmap use_bitmap
= selected
;
1351 if ((selected
.GetWidth()!= bm_ww
) || ( selected
.GetHeight()!= bm_hh
))
1353 // This indicates that the blitting code below will get
1354 // a clipped bitmap and therefore needs to move the origin
1356 wxRegion
tmp( xx
,yy
,ww
,hh
);
1357 if (!m_currentClippingRegion
.IsNull())
1358 tmp
.Intersect( m_currentClippingRegion
);
1359 tmp
.GetBox(cx
,cy
,cw
,ch
);
1361 // Scale and clipped bitmap
1362 use_bitmap
= selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1365 // apply mask if any
1366 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1367 if (useMask
&& use_bitmap
.GetMask())
1368 mask
= use_bitmap
.GetMask()->GetBitmap();
1370 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1372 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1376 if (!m_currentClippingRegion
.IsNull())
1379 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1380 GdkGC
*gc
= gdk_gc_new( new_mask
);
1382 gdk_gc_set_foreground( gc
, &col
);
1383 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1384 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1386 gdk_gc_set_background( gc
, &col
);
1388 gdk_gc_set_foreground( gc
, &col
);
1389 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1390 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1391 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1392 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1393 gdk_gc_set_stipple( gc
, mask
);
1394 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1396 g_object_unref (gc
);
1399 gdk_gc_set_clip_mask(use_gc
, mask
);
1400 if (new_mask
!= NULL
)
1401 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1403 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1406 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1407 // drawing a mono-bitmap (XBitmap) we use the current text GC
1411 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1412 GdkGC
*gc
= gdk_gc_new( bitmap
);
1413 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1414 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1415 gdk_wx_draw_bitmap(bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1417 gdk_draw_drawable(m_window
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1419 g_object_unref (bitmap
);
1420 g_object_unref (gc
);
1424 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1425 gdk_draw_drawable(m_window
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1428 // remove mask again if any
1431 gdk_gc_set_clip_mask(use_gc
, NULL
);
1432 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1433 if (!m_currentClippingRegion
.IsNull())
1434 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1438 g_object_unref (new_mask
);
1440 else // use_bitmap_method
1442 if (selected
.IsOk() && ((width
!= ww
) || (height
!= hh
)))
1445 wxRegion
tmp( xx
,yy
,ww
,hh
);
1446 tmp
.Intersect( m_currentClippingRegion
);
1447 wxCoord cx
,cy
,cw
,ch
;
1448 tmp
.GetBox(cx
,cy
,cw
,ch
);
1451 wxBitmap bitmap
= selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1453 // draw scaled bitmap
1454 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1455 gdk_draw_drawable( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1459 // No scaling and not a memory dc with a mask either
1461 GdkWindow
* window
= NULL
;
1462 wxImplDC
*impl
= source
->GetImpl();
1463 wxGTKWindowImplDC
*gtk_impl
= wxDynamicCast(impl
, wxGTKWindowImplDC
);
1465 window
= gtk_impl
->GetGDKWindow();
1467 GdkWindow
* window
= source
->GetGDKWindow();
1472 // copy including child window contents
1473 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1474 gdk_draw_drawable( m_window
, m_penGC
,
1478 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1482 SetLogicalFunction( old_logical_func
);
1487 void wxGTKWindowImplDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1489 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1491 if (!m_window
) return;
1493 if (text
.empty()) return;
1498 wxCHECK_RET( m_context
, wxT("no Pango context") );
1499 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1500 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1502 gdk_pango_context_set_colormap( m_context
, m_cmap
);
1504 bool underlined
= m_font
.IsOk() && m_font
.GetUnderlined();
1506 const wxCharBuffer data
= wxGTK_CONV( text
);
1509 size_t datalen
= strlen(data
);
1511 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1512 // has been fixed and thus the hack implemented below should never be used
1513 static bool pangoOk
= !wx_pango_version_check(1, 16, 0);
1515 bool needshack
= underlined
&& !pangoOk
;
1516 char *hackstring
= NULL
;
1520 // a PangoLayout which has leading/trailing spaces with underlined font
1521 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1522 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1523 // this behaviour. To workaround this problem, we use a special hack here
1524 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1525 // empty space characters and give them a dummy colour attribute.
1526 // This will force Pango to underline the leading/trailing spaces, too.
1528 // need to realloc the string to prepend & append our special characters
1529 hackstring
= (char*)malloc((datalen
+7)*sizeof(char));
1531 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1532 strcpy(hackstring
, "\342\200\214");
1534 // copy the user string
1535 memcpy(&hackstring
[3], data
, datalen
);
1537 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1538 strcpy(&hackstring
[datalen
+3], "\342\200\214");
1540 // the special characters that we added require 6 additional bytes:
1543 pango_layout_set_text(m_layout
, hackstring
, datalen
);
1547 pango_layout_set_text(m_layout
, data
, datalen
);
1552 PangoAttrList
*attrs
= pango_attr_list_new();
1553 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1555 a
->end_index
= datalen
;
1556 pango_attr_list_insert(attrs
, a
);
1560 // dummy colour for the leading space
1561 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1564 pango_attr_list_insert(attrs
, a
);
1566 // dummy colour for the trailing space
1567 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1568 a
->start_index
= datalen
- 1;
1569 a
->end_index
= datalen
;
1570 pango_attr_list_insert(attrs
, a
);
1573 pango_layout_set_attributes(m_layout
, attrs
);
1574 pango_attr_list_unref(attrs
);
1579 if (fabs(m_scaleY
- 1.0) > 0.00001)
1581 // If there is a user or actually any scale applied to
1582 // the device context, scale the font.
1584 // scale font description
1585 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1586 double size
= oldSize
;
1587 size
= size
* m_scaleY
;
1588 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1590 // actually apply scaled font
1591 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1593 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1594 if ( m_backgroundMode
== wxSOLID
)
1596 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1597 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1598 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1602 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1603 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1605 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1607 // reset unscaled size
1608 pango_font_description_set_size( m_fontdesc
, oldSize
);
1610 // actually apply unscaled font
1611 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1615 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1616 if ( m_backgroundMode
== wxSOLID
)
1618 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1619 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1620 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1624 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1625 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1627 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1632 // undo underline attributes setting:
1633 pango_layout_set_attributes(m_layout
, NULL
);
1639 width
= wxCoord(width
/ m_scaleX
);
1640 height
= wxCoord(height
/ m_scaleY
);
1641 CalcBoundingBox (x
+ width
, y
+ height
);
1642 CalcBoundingBox (x
, y
);
1649 // TODO: There is an example of rotating text with GTK2 that would probably be
1650 // a better approach here:
1651 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1653 void wxGTKWindowImplDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1656 if (!m_window
|| text
.empty())
1659 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1661 if ( wxIsNullDouble(angle
) )
1663 DoDrawText(text
, x
, y
);
1670 // TODO: implement later without GdkFont for GTK 2.0
1671 DoGetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1673 // draw the string normally
1676 dc
.SelectObject(src
);
1677 dc
.SetFont(GetFont());
1678 dc
.SetBackground(*wxBLACK_BRUSH
);
1679 dc
.SetBrush(*wxBLACK_BRUSH
);
1681 dc
.SetTextForeground( *wxWHITE
);
1682 dc
.DrawText(text
, 0, 0);
1683 dc
.SelectObject(wxNullBitmap
);
1685 // Calculate the size of the rotated bounding box.
1686 double rad
= DegToRad(angle
);
1687 double dx
= cos(rad
),
1690 // the rectngle vertices are counted clockwise with the first one being at
1691 // (0, 0) (or, rather, at (x, y))
1693 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1696 double x3
= x4
+ x2
,
1700 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1701 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1702 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1703 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1706 wxImage image
= src
.ConvertToImage();
1708 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1709 m_textForegroundColour
.Green(),
1710 m_textForegroundColour
.Blue() );
1711 image
= image
.Rotate( rad
, wxPoint(0,0) );
1713 int i_angle
= (int) angle
;
1714 i_angle
= i_angle
% 360;
1718 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1719 xoffset
= image
.GetWidth();
1721 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1722 yoffset
= image
.GetHeight();
1724 if ((i_angle
>= 0) && (i_angle
< 90))
1725 yoffset
-= (int)( cos(rad
)*h
);
1726 if ((i_angle
>= 90) && (i_angle
< 180))
1727 xoffset
-= (int)( sin(rad
)*h
);
1728 if ((i_angle
>= 180) && (i_angle
< 270))
1729 yoffset
-= (int)( cos(rad
)*h
);
1730 if ((i_angle
>= 270) && (i_angle
< 360))
1731 xoffset
-= (int)( sin(rad
)*h
);
1733 int i_x
= x
- xoffset
;
1734 int i_y
= y
- yoffset
;
1737 DoDrawBitmap( src
, i_x
, i_y
, true );
1740 // it would be better to draw with non underlined font and draw the line
1741 // manually here (it would be more straight...)
1743 if ( m_font
.GetUnderlined() )
1745 gdk_draw_line( m_window
, m_textGC
,
1746 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1747 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1751 // update the bounding box
1752 CalcBoundingBox(x
+ minX
, y
+ minY
);
1753 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1754 #endif // wxUSE_IMAGE
1757 void wxGTKWindowImplDC::DoGetTextExtent(const wxString
&string
,
1758 wxCoord
*width
, wxCoord
*height
,
1759 wxCoord
*descent
, wxCoord
*externalLeading
,
1760 const wxFont
*theFont
) const
1768 if ( externalLeading
)
1769 *externalLeading
= 0;
1774 // ensure that theFont is always non-NULL
1775 if ( !theFont
|| !theFont
->IsOk() )
1776 theFont
= wx_const_cast(wxFont
*, &m_font
);
1778 // and use it if it's valid
1779 if ( theFont
->IsOk() )
1781 pango_layout_set_font_description
1784 theFont
->GetNativeFontInfo()->description
1788 // Set layout's text
1789 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1792 // hardly ideal, but what else can we do if conversion failed?
1796 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1801 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1802 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1803 int baseline
= pango_layout_iter_get_baseline(iter
);
1804 pango_layout_iter_free(iter
);
1805 *descent
= h
- PANGO_PIXELS(baseline
);
1808 *height
= (wxCoord
) h
;
1812 pango_layout_get_pixel_size( m_layout
, width
, height
);
1815 // Reset old font description
1816 if (theFont
->IsOk())
1817 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1821 bool wxGTKWindowImplDC::DoGetPartialTextExtents(const wxString
& text
,
1822 wxArrayInt
& widths
) const
1824 const size_t len
= text
.length();
1831 // Set layout's text
1832 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1835 // hardly ideal, but what else can we do if conversion failed?
1836 wxLogLastError(wxT("DoGetPartialTextExtents"));
1840 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1842 // Calculate the position of each character based on the widths of
1843 // the previous characters
1845 // Code borrowed from Scintilla's PlatGTK
1846 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1848 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1850 while (pango_layout_iter_next_cluster(iter
))
1852 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1853 int position
= PANGO_PIXELS(pos
.x
);
1854 widths
[i
++] = position
;
1857 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1858 pango_layout_iter_free(iter
);
1864 wxCoord
wxGTKWindowImplDC::GetCharWidth() const
1866 pango_layout_set_text( m_layout
, "H", 1 );
1868 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1872 wxCoord
wxGTKWindowImplDC::GetCharHeight() const
1874 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1875 wxCHECK_MSG( metrics
, -1, _T("failed to get pango font metrics") );
1877 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1878 pango_font_metrics_get_ascent (metrics
));
1879 pango_font_metrics_unref (metrics
);
1883 void wxGTKWindowImplDC::Clear()
1885 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1887 if (!m_window
) return;
1890 DoGetSize( &width
, &height
);
1891 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1894 void wxGTKWindowImplDC::SetFont( const wxFont
&font
)
1901 pango_font_description_free( m_fontdesc
);
1903 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1908 PangoContext
*oldContext
= m_context
;
1910 m_context
= m_owningWindow
->GtkGetPangoDefaultContext();
1912 // If we switch back/forth between different contexts
1913 // we also have to create a new layout. I think so,
1914 // at least, and it doesn't hurt to do it.
1915 if (oldContext
!= m_context
)
1918 g_object_unref (m_layout
);
1920 m_layout
= pango_layout_new( m_context
);
1924 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1928 void wxGTKWindowImplDC::SetPen( const wxPen
&pen
)
1930 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1932 if (m_pen
== pen
) return;
1936 if (!m_pen
.IsOk()) return;
1938 if (!m_window
) return;
1940 gint width
= m_pen
.GetWidth();
1943 // CMB: if width is non-zero scale it with the dc
1948 // X doesn't allow different width in x and y and so we take
1951 ( fabs((double) XLOG2DEVREL(width
)) +
1952 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1956 // width can't be 0 or an internal GTK error occurs inside
1957 // gdk_gc_set_dashes() below
1962 static const wxGTKDash dotted
[] = {1, 1};
1963 static const wxGTKDash short_dashed
[] = {2, 2};
1964 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1965 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1967 // We express dash pattern in pen width unit, so we are
1968 // independent of zoom factor and so on...
1970 const wxGTKDash
*req_dash
;
1972 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1973 switch (m_pen
.GetStyle())
1977 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1978 req_nb_dash
= m_pen
.GetDashCount();
1979 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1984 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1991 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1993 req_dash
= wxCoord_dashed
;
1998 lineStyle
= GDK_LINE_ON_OFF_DASH
;
2000 req_dash
= short_dashed
;
2005 // lineStyle = GDK_LINE_DOUBLE_DASH;
2006 lineStyle
= GDK_LINE_ON_OFF_DASH
;
2008 req_dash
= dotted_dashed
;
2013 case wxSTIPPLE_MASK_OPAQUE
:
2018 lineStyle
= GDK_LINE_SOLID
;
2019 req_dash
= (wxGTKDash
*)NULL
;
2025 if (req_dash
&& req_nb_dash
)
2027 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
2030 for (int i
= 0; i
< req_nb_dash
; i
++)
2031 real_req_dash
[i
] = req_dash
[i
] * width
;
2032 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
2033 delete[] real_req_dash
;
2037 // No Memory. We use non-scaled dash pattern...
2038 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
2042 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
2043 switch (m_pen
.GetCap())
2045 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
2046 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
2053 capStyle
= GDK_CAP_NOT_LAST
;
2057 capStyle
= GDK_CAP_ROUND
;
2063 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
2064 switch (m_pen
.GetJoin())
2066 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
2067 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
2069 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
2072 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
2074 m_pen
.GetColour().CalcPixel( m_cmap
);
2075 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
2078 void wxGTKWindowImplDC::SetBrush( const wxBrush
&brush
)
2080 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2082 if (m_brush
== brush
) return;
2086 if (!m_brush
.IsOk()) return;
2088 if (!m_window
) return;
2090 m_brush
.GetColour().CalcPixel( m_cmap
);
2091 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
2093 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
2095 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->IsOk()))
2097 if (m_brush
.GetStipple()->GetDepth() != 1)
2099 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
2100 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2104 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2105 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2109 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2111 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2112 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2115 if (m_brush
.IsHatch())
2117 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2118 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
2119 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
2123 void wxGTKWindowImplDC::SetBackground( const wxBrush
&brush
)
2125 /* CMB 21/7/98: Added SetBackground. Sets background brush
2126 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2128 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2130 if (m_backgroundBrush
== brush
) return;
2132 m_backgroundBrush
= brush
;
2134 if (!m_backgroundBrush
.IsOk()) return;
2136 if (!m_window
) return;
2138 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2139 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2140 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2141 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2142 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2144 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2146 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->IsOk()))
2148 if (m_backgroundBrush
.GetStipple()->GetDepth() != 1)
2150 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2151 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2155 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2156 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2160 if (m_backgroundBrush
.IsHatch())
2162 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2163 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2164 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2168 void wxGTKWindowImplDC::SetLogicalFunction( int function
)
2170 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2172 if (m_logicalFunction
== function
)
2175 // VZ: shouldn't this be a CHECK?
2182 case wxXOR
: mode
= GDK_XOR
; break;
2183 case wxINVERT
: mode
= GDK_INVERT
; break;
2184 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2185 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2186 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2187 case wxSET
: mode
= GDK_SET
; break;
2188 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2189 case wxAND
: mode
= GDK_AND
; break;
2190 case wxOR
: mode
= GDK_OR
; break;
2191 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2192 case wxNAND
: mode
= GDK_NAND
; break;
2193 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2194 case wxCOPY
: mode
= GDK_COPY
; break;
2195 case wxNO_OP
: mode
= GDK_NOOP
; break;
2196 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2198 // unsupported by GTK
2199 case wxNOR
: mode
= GDK_COPY
; break;
2201 wxFAIL_MSG( wxT("unsupported logical function") );
2205 m_logicalFunction
= function
;
2207 gdk_gc_set_function( m_penGC
, mode
);
2208 gdk_gc_set_function( m_brushGC
, mode
);
2210 // to stay compatible with wxMSW, we don't apply ROPs to the text
2211 // operations (i.e. DrawText/DrawRotatedText).
2212 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2213 gdk_gc_set_function( m_textGC
, mode
);
2216 void wxGTKWindowImplDC::SetTextForeground( const wxColour
&col
)
2218 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2220 // don't set m_textForegroundColour to an invalid colour as we'd crash
2221 // later then (we use m_textForegroundColour.GetColor() without checking
2223 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
2226 m_textForegroundColour
= col
;
2230 m_textForegroundColour
.CalcPixel( m_cmap
);
2231 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2235 void wxGTKWindowImplDC::SetTextBackground( const wxColour
&col
)
2237 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2240 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
2243 m_textBackgroundColour
= col
;
2247 m_textBackgroundColour
.CalcPixel( m_cmap
);
2248 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2252 void wxGTKWindowImplDC::SetBackgroundMode( int mode
)
2254 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2256 m_backgroundMode
= mode
;
2258 if (!m_window
) return;
2260 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2261 // transparent/solid background mode
2263 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2265 gdk_gc_set_fill( m_brushGC
,
2266 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2270 void wxGTKWindowImplDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2272 wxFAIL_MSG( wxT("wxGTKWindowImplDC::SetPalette not implemented") );
2275 void wxGTKWindowImplDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2277 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2279 if (!m_window
) return;
2282 rect
.x
= XLOG2DEV(x
);
2283 rect
.y
= YLOG2DEV(y
);
2284 rect
.width
= XLOG2DEVREL(width
);
2285 rect
.height
= YLOG2DEVREL(height
);
2287 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
2288 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
2290 rect
.x
-= rect
.width
;
2293 if (!m_currentClippingRegion
.IsNull())
2294 m_currentClippingRegion
.Intersect( rect
);
2296 m_currentClippingRegion
.Union( rect
);
2298 #if USE_PAINT_REGION
2299 if (!m_paintClippingRegion
.IsNull())
2300 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2303 wxCoord xx
, yy
, ww
, hh
;
2304 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2306 wxImplDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2308 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2311 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2312 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2313 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2314 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2317 void wxGTKWindowImplDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2319 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2323 DestroyClippingRegion();
2327 if (!m_window
) return;
2329 if (!m_currentClippingRegion
.IsNull())
2330 m_currentClippingRegion
.Intersect( region
);
2332 m_currentClippingRegion
.Union( region
);
2334 #if USE_PAINT_REGION
2335 if (!m_paintClippingRegion
.IsNull())
2336 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2339 wxCoord xx
, yy
, ww
, hh
;
2340 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2342 wxImplDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2344 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2347 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2348 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2349 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2350 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2353 void wxGTKWindowImplDC::DestroyClippingRegion()
2355 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2358 wxImplDC::DestroyClippingRegion();
2360 wxDC::DestroyClippingRegion();
2363 m_currentClippingRegion
.Clear();
2365 #if USE_PAINT_REGION
2366 if (!m_paintClippingRegion
.IsEmpty())
2367 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2370 if (!m_window
) return;
2372 if (m_currentClippingRegion
.IsEmpty())
2374 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2375 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2376 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2377 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2381 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2382 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2383 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2384 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2388 void wxGTKWindowImplDC::Destroy()
2390 if (m_penGC
) wxFreePoolGC( m_penGC
);
2391 m_penGC
= (GdkGC
*) NULL
;
2392 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2393 m_brushGC
= (GdkGC
*) NULL
;
2394 if (m_textGC
) wxFreePoolGC( m_textGC
);
2395 m_textGC
= (GdkGC
*) NULL
;
2396 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2397 m_bgGC
= (GdkGC
*) NULL
;
2400 void wxGTKWindowImplDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2402 m_deviceOriginX
= x
;
2403 m_deviceOriginY
= y
;
2405 ComputeScaleAndOrigin();
2408 void wxGTKWindowImplDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2410 m_signX
= (xLeftRight
? 1 : -1);
2411 m_signY
= (yBottomUp
? -1 : 1);
2413 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
2414 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
2417 ComputeScaleAndOrigin();
2420 void wxGTKWindowImplDC::ComputeScaleAndOrigin()
2422 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2425 wxImplDC::ComputeScaleAndOrigin();
2427 wxDC::ComputeScaleAndOrigin();
2430 // if scale has changed call SetPen to recalulate the line width
2431 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2433 // this is a bit artificial, but we need to force wxDC to think the pen
2441 // Resolution in pixels per logical inch
2442 wxSize
wxGTKWindowImplDC::GetPPI() const
2444 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2447 int wxGTKWindowImplDC::GetDepth() const
2449 return gdk_drawable_get_depth(m_window
);
2453 //-----------------------------------------------------------------------------
2455 //-----------------------------------------------------------------------------
2458 IMPLEMENT_ABSTRACT_CLASS(wxGTKClientImplDC
, wxGTKWindowImplDC
)
2460 IMPLEMENT_ABSTRACT_CLASS(wxClientDC
, wxWindowDC
)
2464 wxGTKClientImplDC::wxGTKClientImplDC( wxDC
*owner
)
2465 : wxGTKWindowImplDC( owner
)
2469 wxGTKClientImplDC::wxGTKClientImplDC( wxDC
*owner
, wxWindow
*win
)
2470 : wxGTKWindowImplDC( owner
, win
)
2472 wxClientDC::wxClientDC()
2476 wxClientDC::wxClientDC( wxWindow
*win
)
2481 wxCHECK_RET( win
, _T("NULL window in wxGTKClientImplDC::wxClientDC") );
2483 #ifdef __WXUNIVERSAL__
2484 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2485 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2486 wxSize size
= win
->GetClientSize();
2487 SetClippingRegion(wxPoint(0, 0), size
);
2488 #endif // __WXUNIVERSAL__
2491 void wxGTKClientImplDC::DoGetSize(int *width
, int *height
) const
2493 wxCHECK_RET( m_owningWindow
, _T("GetSize() doesn't work without window") );
2495 m_owningWindow
->GetClientSize( width
, height
);
2498 //-----------------------------------------------------------------------------
2500 //-----------------------------------------------------------------------------
2503 IMPLEMENT_ABSTRACT_CLASS(wxGTKPaintImplDC
, wxGTKClientImplDC
)
2505 IMPLEMENT_ABSTRACT_CLASS(wxPaintDC
, wxClientDC
)
2508 // Limit the paint region to the window size. Sometimes
2509 // the paint region is too big, and this risks X11 errors
2510 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2512 wxRect originalRect
= region
.GetBox();
2513 wxRect
rect(originalRect
);
2514 if (rect
.width
+ rect
.x
> sz
.x
)
2515 rect
.width
= sz
.x
- rect
.x
;
2516 if (rect
.height
+ rect
.y
> sz
.y
)
2517 rect
.height
= sz
.y
- rect
.y
;
2518 if (rect
!= originalRect
)
2520 region
= wxRegion(rect
);
2521 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2522 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2523 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2528 wxGTKPaintImplDC::wxGTKPaintImplDC( wxDC
*owner
)
2529 : wxGTKClientImplDC( owner
)
2533 wxGTKPaintImplDC::wxGTKPaintImplDC( wxDC
*owner
, wxWindow
*win
)
2534 : wxGTKClientImplDC( owner
, win
)
2536 wxPaintDC::wxPaintDC()
2541 wxPaintDC::wxPaintDC( wxWindow
*win
)
2545 #if USE_PAINT_REGION
2546 if (!win
->m_clipPaintRegion
)
2549 wxSize sz
= win
->GetSize();
2550 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2551 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2553 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2556 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2557 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2559 if (sz
.x
<= 0 || sz
.y
<= 0)
2562 gdk_gc_set_clip_region( m_penGC
, region
);
2563 gdk_gc_set_clip_region( m_brushGC
, region
);
2564 gdk_gc_set_clip_region( m_textGC
, region
);
2565 gdk_gc_set_clip_region( m_bgGC
, region
);
2567 #endif // USE_PAINT_REGION
2570 // ----------------------------------------------------------------------------
2572 // ----------------------------------------------------------------------------
2574 class wxDCModule
: public wxModule
2581 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2584 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2586 bool wxDCModule::OnInit()
2592 void wxDCModule::OnExit()