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
,
100 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
101 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
102 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
104 gint src_width
, src_height
;
105 gdk_drawable_get_size(src
, &src_width
, &src_height
);
106 if (width
== -1) width
= src_width
;
107 if (height
== -1) height
= src_height
;
109 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
111 GDK_WINDOW_XID(drawable
),
119 //-----------------------------------------------------------------------------
120 // Implement Pool of Graphic contexts. Creating them takes too much time.
121 //-----------------------------------------------------------------------------
147 #define GC_POOL_ALLOC_SIZE 100
149 static int wxGCPoolSize
= 0;
151 static wxGC
*wxGCPool
= NULL
;
153 static void wxInitGCPool()
155 // This really could wait until the first call to
156 // wxGetPoolGC, but we will make the first allocation
157 // now when other initialization is being performed.
159 // Set initial pool size.
160 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
162 // Allocate initial pool.
163 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
164 if (wxGCPool
== NULL
)
166 // If we cannot malloc, then fail with error
167 // when debug is enabled. If debug is not enabled,
168 // the problem will eventually get caught
170 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
174 // Zero initial pool.
175 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
178 static void wxCleanUpGCPool()
180 for (int i
= 0; i
< wxGCPoolSize
; i
++)
182 if (wxGCPool
[i
].m_gc
)
183 g_object_unref (wxGCPool
[i
].m_gc
);
191 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
195 // Look for an available GC.
196 for (int i
= 0; i
< wxGCPoolSize
; i
++)
198 if (!wxGCPool
[i
].m_gc
)
200 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
201 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
202 wxGCPool
[i
].m_type
= type
;
203 wxGCPool
[i
].m_used
= false;
205 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
207 wxGCPool
[i
].m_used
= true;
208 return wxGCPool
[i
].m_gc
;
212 // We did not find an available GC.
213 // We need to grow the GC pool.
214 pptr
= (wxGC
*)realloc(wxGCPool
,
215 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
218 // Initialize newly allocated pool.
220 memset(&wxGCPool
[wxGCPoolSize
], 0,
221 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
223 // Initialize entry we will return.
224 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
225 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
226 wxGCPool
[wxGCPoolSize
].m_type
= type
;
227 wxGCPool
[wxGCPoolSize
].m_used
= true;
229 // Set new value of pool size.
230 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
232 // Return newly allocated entry.
233 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
236 // The realloc failed. Fall through to error.
237 wxFAIL_MSG( wxT("No GC available") );
239 return (GdkGC
*) NULL
;
242 static void wxFreePoolGC( GdkGC
*gc
)
244 for (int i
= 0; i
< wxGCPoolSize
; i
++)
246 if (wxGCPool
[i
].m_gc
== gc
)
248 wxGCPool
[i
].m_used
= false;
253 wxFAIL_MSG( wxT("Wrong GC") );
256 //-----------------------------------------------------------------------------
258 //-----------------------------------------------------------------------------
261 IMPLEMENT_ABSTRACT_CLASS(wxGTKWindowImplDC
, wxGTKImplDC
)
263 IMPLEMENT_ABSTRACT_CLASS(wxWindowDC
, wxDC
)
267 wxGTKWindowImplDC::wxGTKWindowImplDC( wxDC
*owner
) :
270 wxWindowDC::wxWindowDC()
273 m_penGC
= (GdkGC
*) NULL
;
274 m_brushGC
= (GdkGC
*) NULL
;
275 m_textGC
= (GdkGC
*) NULL
;
276 m_bgGC
= (GdkGC
*) NULL
;
277 m_cmap
= (GdkColormap
*) NULL
;
278 m_isScreenDC
= false;
279 m_owningWindow
= (wxWindow
*)NULL
;
280 m_context
= (PangoContext
*)NULL
;
281 m_layout
= (PangoLayout
*)NULL
;
282 m_fontdesc
= (PangoFontDescription
*)NULL
;
286 wxGTKWindowImplDC::wxGTKWindowImplDC( wxDC
*owner
, wxWindow
*window
) :
289 wxWindowDC::wxWindowDC( wxWindow
*window
)
292 wxASSERT_MSG( window
, wxT("DC needs a window") );
294 m_penGC
= (GdkGC
*) NULL
;
295 m_brushGC
= (GdkGC
*) NULL
;
296 m_textGC
= (GdkGC
*) NULL
;
297 m_bgGC
= (GdkGC
*) NULL
;
298 m_cmap
= (GdkColormap
*) NULL
;
299 m_owningWindow
= (wxWindow
*)NULL
;
300 m_isScreenDC
= false;
301 m_font
= window
->GetFont();
303 GtkWidget
*widget
= window
->m_wxwindow
;
305 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
306 // code should still be able to create wxClientDCs for them, so we will
307 // use the parent window here then.
310 window
= window
->GetParent();
311 widget
= window
->m_wxwindow
;
314 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
316 m_context
= window
->GtkGetPangoDefaultContext();
317 m_layout
= pango_layout_new( m_context
);
318 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
320 GtkPizza
*pizza
= GTK_PIZZA( widget
);
321 m_window
= pizza
->bin_window
;
323 // Window not realized ?
326 // Don't report problems as per MSW.
332 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
336 /* this must be done after SetUpDC, bacause SetUpDC calls the
337 repective SetBrush, SetPen, SetBackground etc functions
338 to set up the DC. SetBackground call m_owner->SetBackground
339 and this might not be desired as the standard dc background
340 is white whereas a window might assume gray to be the
341 standard (as e.g. wxStatusBar) */
343 m_owningWindow
= window
;
345 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
346 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
351 // origin in the upper right corner
352 m_deviceOriginX
= m_owningWindow
->GetClientSize().x
;
356 wxGTKWindowImplDC::~wxGTKWindowImplDC()
361 g_object_unref (m_layout
);
363 pango_font_description_free( m_fontdesc
);
366 void wxGTKWindowImplDC::SetUpDC( bool isMemDC
)
370 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
376 wxGTKMemoryImplDC
*mem_dc
= (wxGTKMemoryImplDC
*) this;
377 if (mem_dc
->GetSelectedBitmap().GetDepth() == 1)
379 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
380 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
381 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
382 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
391 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
392 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
393 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
394 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
398 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
399 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
400 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
401 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
405 /* background colour */
406 m_backgroundBrush
= *wxWHITE_BRUSH
;
407 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
409 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
411 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
415 m_textForegroundColour
.CalcPixel( m_cmap
);
416 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
418 m_textBackgroundColour
.CalcPixel( m_cmap
);
419 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
421 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
423 gdk_gc_set_colormap( m_textGC
, m_cmap
);
426 m_pen
.GetColour().CalcPixel( m_cmap
);
427 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
428 gdk_gc_set_background( m_penGC
, bg_col
);
430 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
433 m_brush
.GetColour().CalcPixel( m_cmap
);
434 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
435 gdk_gc_set_background( m_brushGC
, bg_col
);
437 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
440 gdk_gc_set_background( m_bgGC
, bg_col
);
441 gdk_gc_set_foreground( m_bgGC
, bg_col
);
443 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
446 gdk_gc_set_function( m_textGC
, GDK_COPY
);
447 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
448 gdk_gc_set_function( m_penGC
, GDK_COPY
);
451 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
452 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
453 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
454 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
458 hatch_bitmap
= hatches
;
459 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
460 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
461 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
462 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
463 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
464 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
468 void wxGTKWindowImplDC::DoGetSize( int* width
, int* height
) const
470 wxCHECK_RET( m_owningWindow
, _T("GetSize() doesn't work without window") );
472 m_owningWindow
->GetSize(width
, height
);
475 bool wxGTKWindowImplDC::DoFloodFill(wxCoord x
, wxCoord y
,
476 const wxColour
& col
, int style
)
479 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
480 const wxColour
& col
, int style
);
482 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
488 bool wxGTKWindowImplDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
491 // Generic (and therefore rather inefficient) method.
492 // Could be improved.
494 wxBitmap
bitmap(1, 1);
495 memdc
.SelectObject(bitmap
);
496 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
497 memdc
.SelectObject(wxNullBitmap
);
499 wxImage image
= bitmap
.ConvertToImage();
500 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
502 #else // !wxUSE_IMAGE
504 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
507 void wxGTKWindowImplDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
509 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
511 if (m_pen
.GetStyle() != wxTRANSPARENT
)
514 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
516 CalcBoundingBox(x1
, y1
);
517 CalcBoundingBox(x2
, y2
);
521 void wxGTKWindowImplDC::DoCrossHair( wxCoord x
, wxCoord y
)
523 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
525 if (m_pen
.GetStyle() != wxTRANSPARENT
)
529 GetOwner()->GetSize( &w
, &h
);
530 wxCoord xx
= XLOG2DEV(x
);
531 wxCoord yy
= YLOG2DEV(y
);
534 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
535 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
540 void wxGTKWindowImplDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
541 wxCoord xc
, wxCoord yc
)
543 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
545 wxCoord xx1
= XLOG2DEV(x1
);
546 wxCoord yy1
= YLOG2DEV(y1
);
547 wxCoord xx2
= XLOG2DEV(x2
);
548 wxCoord yy2
= YLOG2DEV(y2
);
549 wxCoord xxc
= XLOG2DEV(xc
);
550 wxCoord yyc
= YLOG2DEV(yc
);
551 double dx
= xx1
- xxc
;
552 double dy
= yy1
- yyc
;
553 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
554 wxCoord r
= (wxCoord
)radius
;
555 double radius1
, radius2
;
557 if (xx1
== xx2
&& yy1
== yy2
)
562 else if ( wxIsNullDouble(radius
) )
569 radius1
= (xx1
- xxc
== 0) ?
570 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
571 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
572 radius2
= (xx2
- xxc
== 0) ?
573 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
574 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
576 wxCoord alpha1
= wxCoord(radius1
* 64.0);
577 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
578 while (alpha2
<= 0) alpha2
+= 360*64;
579 while (alpha1
> 360*64) alpha1
-= 360*64;
583 if (m_brush
.GetStyle() != wxTRANSPARENT
)
585 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
587 gdk_gc_set_ts_origin( m_textGC
,
588 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
589 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
590 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
591 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
593 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
595 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
601 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
602 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
603 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
605 if (m_brush
.GetStyle() == wxSTIPPLE
)
607 gdk_gc_set_ts_origin( m_brushGC
,
608 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
609 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
610 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
611 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
615 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
619 if (m_pen
.GetStyle() != wxTRANSPARENT
)
621 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
623 if ((m_brush
.GetStyle() != wxTRANSPARENT
) && (alpha2
- alpha1
!= 360*64))
625 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
626 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
631 CalcBoundingBox (x1
, y1
);
632 CalcBoundingBox (x2
, y2
);
635 void wxGTKWindowImplDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
637 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
639 wxCoord xx
= XLOG2DEV(x
);
640 wxCoord yy
= YLOG2DEV(y
);
641 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
642 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
644 // CMB: handle -ve width and/or height
645 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
646 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
650 wxCoord start
= wxCoord(sa
* 64.0);
651 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
653 if (m_brush
.GetStyle() != wxTRANSPARENT
)
655 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
657 gdk_gc_set_ts_origin( m_textGC
,
658 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
659 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
660 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
661 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
663 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
665 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
671 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
672 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
673 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
675 if (m_brush
.GetStyle() == wxSTIPPLE
)
677 gdk_gc_set_ts_origin( m_brushGC
,
678 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
679 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
680 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
681 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
685 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
689 if (m_pen
.GetStyle() != wxTRANSPARENT
)
690 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
693 CalcBoundingBox (x
, y
);
694 CalcBoundingBox (x
+ width
, y
+ height
);
697 void wxGTKWindowImplDC::DoDrawPoint( wxCoord x
, wxCoord y
)
699 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
701 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
702 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
704 CalcBoundingBox (x
, y
);
707 void wxGTKWindowImplDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
709 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
711 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
714 //Check, if scaling is necessary
716 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
718 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
719 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
722 gpts
= new GdkPoint
[n
];
724 for (int i
= 0; i
< n
; i
++)
728 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
729 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
731 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
735 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
741 void wxGTKWindowImplDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
743 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
747 //Check, if scaling is necessary
749 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
751 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
752 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
755 gdkpoints
= new GdkPoint
[n
];
758 for (i
= 0 ; i
< n
; i
++)
762 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
763 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
765 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
770 if (m_brush
.GetStyle() != wxTRANSPARENT
)
772 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
774 gdk_gc_set_ts_origin( m_textGC
,
775 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
776 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
777 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
778 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
780 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
782 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
783 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
784 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
786 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
788 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
789 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
790 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
792 if (m_brush
.GetStyle() == wxSTIPPLE
)
794 gdk_gc_set_ts_origin( m_brushGC
,
795 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
796 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
797 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
798 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
802 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
806 if (m_pen
.GetStyle() != wxTRANSPARENT
)
809 for (i = 0 ; i < n ; i++)
811 gdk_draw_line( m_window, m_penGC,
814 gdkpoints[(i+1)%n].x,
815 gdkpoints[(i+1)%n].y);
818 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gdkpoints
, n
);
827 void wxGTKWindowImplDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
829 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
831 wxCoord xx
= XLOG2DEV(x
);
832 wxCoord yy
= YLOG2DEV(y
);
833 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
834 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
836 // CMB: draw nothing if transformed w or h is 0
837 if (ww
== 0 || hh
== 0) return;
839 // CMB: handle -ve width and/or height
840 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
841 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
845 if (m_brush
.GetStyle() != wxTRANSPARENT
)
847 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
849 gdk_gc_set_ts_origin( m_textGC
,
850 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
851 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
852 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
853 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
855 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
857 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
863 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
864 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
865 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
867 if (m_brush
.GetStyle() == wxSTIPPLE
)
869 gdk_gc_set_ts_origin( m_brushGC
,
870 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
871 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
872 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
873 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
877 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
881 if (m_pen
.GetStyle() != wxTRANSPARENT
)
884 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
885 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxSOLID
))
887 // Use 2 1-line rects instead
888 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
893 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
894 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
898 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
899 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
903 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
908 // Just use X11 for other cases
909 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
914 CalcBoundingBox( x
, y
);
915 CalcBoundingBox( x
+ width
, y
+ height
);
918 void wxGTKWindowImplDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
920 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
922 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
924 wxCoord xx
= XLOG2DEV(x
);
925 wxCoord yy
= YLOG2DEV(y
);
926 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
927 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
928 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
930 // CMB: handle -ve width and/or height
931 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
932 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
934 // CMB: if radius is zero use DrawRectangle() instead to avoid
935 // X drawing errors with small radii
938 DoDrawRectangle( x
, y
, width
, height
);
942 // CMB: draw nothing if transformed w or h is 0
943 if (ww
== 0 || hh
== 0) return;
945 // CMB: adjust size if outline is drawn otherwise the result is
946 // 1 pixel too wide and high
947 if (m_pen
.GetStyle() != wxTRANSPARENT
)
955 // CMB: ensure dd is not larger than rectangle otherwise we
956 // get an hour glass shape
958 if (dd
> ww
) dd
= ww
;
959 if (dd
> hh
) dd
= hh
;
962 if (m_brush
.GetStyle() != wxTRANSPARENT
)
964 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
966 gdk_gc_set_ts_origin( m_textGC
,
967 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
968 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
969 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
970 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
971 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
972 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
973 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
974 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
975 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
977 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
979 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
980 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
981 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
982 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
983 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
984 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
985 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
986 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
988 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
990 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
991 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
992 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
993 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
994 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
995 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
996 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
997 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
999 if (m_brush
.GetStyle() == wxSTIPPLE
)
1001 gdk_gc_set_ts_origin( m_brushGC
,
1002 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1003 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1004 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
1005 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1006 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1007 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1008 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1009 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1010 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1014 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
1015 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1016 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1017 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1018 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1019 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1023 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1025 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
1026 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
1027 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
1028 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
1029 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1030 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1031 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1032 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1036 // this ignores the radius
1037 CalcBoundingBox( x
, y
);
1038 CalcBoundingBox( x
+ width
, y
+ height
);
1041 void wxGTKWindowImplDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1043 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1045 wxCoord xx
= XLOG2DEV(x
);
1046 wxCoord yy
= YLOG2DEV(y
);
1047 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1048 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1050 // CMB: handle -ve width and/or height
1051 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1052 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1056 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1058 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1060 gdk_gc_set_ts_origin( m_textGC
,
1061 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1062 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1063 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1064 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
1066 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1068 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1074 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1075 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1076 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1078 if (m_brush
.GetStyle() == wxSTIPPLE
)
1080 gdk_gc_set_ts_origin( m_brushGC
,
1081 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1082 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1083 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1084 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1088 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1092 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1093 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1096 CalcBoundingBox( x
, y
);
1097 CalcBoundingBox( x
+ width
, y
+ height
);
1100 void wxGTKWindowImplDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1102 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1103 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1106 void wxGTKWindowImplDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1107 wxCoord x
, wxCoord y
,
1110 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1112 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1114 bool is_mono
= bitmap
.GetDepth() == 1;
1116 // scale/translate size and position
1117 int xx
= XLOG2DEV(x
);
1118 int yy
= YLOG2DEV(y
);
1120 int w
= bitmap
.GetWidth();
1121 int h
= bitmap
.GetHeight();
1123 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1126 CalcBoundingBox( x
, y
);
1127 CalcBoundingBox( x
+ w
, y
+ h
);
1129 if (!m_window
) return;
1131 int ww
= XLOG2DEVREL(w
);
1132 int hh
= YLOG2DEVREL(h
);
1134 // compare to current clipping region
1135 if (!m_currentClippingRegion
.IsNull())
1137 wxRegion
tmp( xx
,yy
,ww
,hh
);
1138 tmp
.Intersect( m_currentClippingRegion
);
1143 // scale bitmap if required
1144 wxBitmap use_bitmap
= bitmap
;
1145 if ((w
!= ww
) || (h
!= hh
))
1146 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1148 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1149 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1150 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1151 // and also creates the mask as a side-effect:
1152 if (gtk_check_version(2,2,0))
1153 use_bitmap
.GetPixmap();
1155 // apply mask if any
1156 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1157 if (useMask
&& use_bitmap
.GetMask())
1158 mask
= use_bitmap
.GetMask()->GetBitmap();
1160 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1162 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1166 if (!m_currentClippingRegion
.IsNull())
1169 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1170 GdkGC
*gc
= gdk_gc_new( new_mask
);
1172 gdk_gc_set_foreground( gc
, &col
);
1173 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1175 gdk_gc_set_background( gc
, &col
);
1177 gdk_gc_set_foreground( gc
, &col
);
1178 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1179 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1180 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1181 gdk_gc_set_stipple( gc
, mask
);
1182 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1184 g_object_unref (gc
);
1187 gdk_gc_set_clip_mask(use_gc
, mask
);
1188 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1191 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1192 // drawing a mono-bitmap (XBitmap) we use the current text GC
1195 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1196 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1197 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1198 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1199 gdk_wx_draw_bitmap( bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1201 gdk_draw_drawable(m_window
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1203 g_object_unref (bitmap2
);
1204 g_object_unref (gc
);
1208 #if GTK_CHECK_VERSION(2,2,0)
1209 if (!gtk_check_version(2,2,0) && use_bitmap
.HasPixbuf())
1211 gdk_draw_pixbuf(m_window
, use_gc
,
1212 use_bitmap
.GetPixbuf(),
1213 0, 0, xx
, yy
, -1, -1,
1214 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1219 gdk_draw_drawable(m_window
, use_gc
,
1220 use_bitmap
.GetPixmap(),
1221 0, 0, xx
, yy
, -1, -1);
1225 // remove mask again if any
1228 gdk_gc_set_clip_mask(use_gc
, NULL
);
1229 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1230 if (!m_currentClippingRegion
.IsNull())
1231 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1232 if (new_mask
!= NULL
)
1233 g_object_unref(new_mask
);
1237 bool wxGTKWindowImplDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1238 wxCoord width
, wxCoord height
,
1240 wxCoord xsrc
, wxCoord ysrc
,
1243 wxCoord xsrcMask
, wxCoord ysrcMask
)
1245 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1247 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1249 if (!m_window
) return false;
1251 // transform the source DC coords to the device ones
1252 xsrc
= source
->LogicalToDeviceX(xsrc
);
1253 ysrc
= source
->LogicalToDeviceY(ysrc
);
1256 wxMemoryDC
*memDC
= wxDynamicCast(source
, wxMemoryDC
);
1259 selected
= memDC
->GetSelectedBitmap();
1260 if ( !selected
.IsOk() )
1264 bool use_bitmap_method
= false;
1265 bool is_mono
= false;
1267 if (xsrcMask
== -1 && ysrcMask
== -1)
1273 if (selected
.IsOk())
1275 is_mono
= (selected
.GetDepth() == 1);
1277 // we use the "XCopyArea" way to copy a memory dc into
1278 // a different window if the memory dc BOTH
1279 // a) doesn't have any mask or its mask isn't used
1283 if (useMask
&& (selected
.GetMask()))
1285 // we HAVE TO use the direct way for memory dcs
1286 // that have mask since the XCopyArea doesn't know
1288 use_bitmap_method
= true;
1292 // we HAVE TO use the direct way for memory dcs
1293 // that are bitmaps because XCopyArea doesn't cope
1294 // with different bit depths
1295 use_bitmap_method
= true;
1297 else if ((xsrc
== 0) && (ysrc
== 0) &&
1298 (width
== selected
.GetWidth()) &&
1299 (height
== selected
.GetHeight()))
1301 // we SHOULD use the direct way if all of the bitmap
1302 // in the memory dc is copied in which case XCopyArea
1303 // wouldn't be able able to boost performace by reducing
1304 // the area to be scaled
1305 use_bitmap_method
= true;
1309 CalcBoundingBox( xdest
, ydest
);
1310 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1312 // scale/translate size and position
1313 wxCoord xx
= XLOG2DEV(xdest
);
1314 wxCoord yy
= YLOG2DEV(ydest
);
1316 wxCoord ww
= XLOG2DEVREL(width
);
1317 wxCoord hh
= YLOG2DEVREL(height
);
1319 // compare to current clipping region
1320 if (!m_currentClippingRegion
.IsNull())
1322 wxRegion
tmp( xx
,yy
,ww
,hh
);
1323 tmp
.Intersect( m_currentClippingRegion
);
1328 int old_logical_func
= m_logicalFunction
;
1329 SetLogicalFunction( logical_func
);
1331 if (use_bitmap_method
)
1333 // scale/translate bitmap size
1334 wxCoord bm_width
= selected
.GetWidth();
1335 wxCoord bm_height
= selected
.GetHeight();
1337 // Get clip coords for the bitmap. If we don't
1338 // use wxBitmap::Rescale(), which can clip the
1339 // bitmap, these are the same as the original
1346 // interpret userscale of src too
1348 memDC
->GetUserScale(&xsc
,&ysc
);
1349 bm_width
= (int) (bm_width
/ xsc
);
1350 bm_height
= (int) (bm_height
/ ysc
);
1352 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1353 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1355 // Scale bitmap if required
1356 wxBitmap use_bitmap
= selected
;
1357 if ((selected
.GetWidth()!= bm_ww
) || ( selected
.GetHeight()!= bm_hh
))
1359 // This indicates that the blitting code below will get
1360 // a clipped bitmap and therefore needs to move the origin
1362 wxRegion
tmp( xx
,yy
,ww
,hh
);
1363 if (!m_currentClippingRegion
.IsNull())
1364 tmp
.Intersect( m_currentClippingRegion
);
1365 tmp
.GetBox(cx
,cy
,cw
,ch
);
1367 // Scale and clipped bitmap
1368 use_bitmap
= selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1371 // apply mask if any
1372 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1373 if (useMask
&& use_bitmap
.GetMask())
1374 mask
= use_bitmap
.GetMask()->GetBitmap();
1376 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1378 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1382 if (!m_currentClippingRegion
.IsNull())
1385 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1386 GdkGC
*gc
= gdk_gc_new( new_mask
);
1388 gdk_gc_set_foreground( gc
, &col
);
1389 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1390 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1392 gdk_gc_set_background( gc
, &col
);
1394 gdk_gc_set_foreground( gc
, &col
);
1395 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1396 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1397 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1398 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1399 gdk_gc_set_stipple( gc
, mask
);
1400 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1402 g_object_unref (gc
);
1405 gdk_gc_set_clip_mask(use_gc
, mask
);
1406 if (new_mask
!= NULL
)
1407 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1409 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1412 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1413 // drawing a mono-bitmap (XBitmap) we use the current text GC
1417 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1418 GdkGC
*gc
= gdk_gc_new( bitmap
);
1419 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1420 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1421 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1423 gdk_draw_drawable(m_window
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1425 g_object_unref (bitmap
);
1426 g_object_unref (gc
);
1430 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1431 gdk_draw_drawable(m_window
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1434 // remove mask again if any
1437 gdk_gc_set_clip_mask(use_gc
, NULL
);
1438 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1439 if (!m_currentClippingRegion
.IsNull())
1440 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1444 g_object_unref (new_mask
);
1446 else // use_bitmap_method
1448 if (selected
.IsOk() && ((width
!= ww
) || (height
!= hh
)))
1451 wxRegion
tmp( xx
,yy
,ww
,hh
);
1452 tmp
.Intersect( m_currentClippingRegion
);
1453 wxCoord cx
,cy
,cw
,ch
;
1454 tmp
.GetBox(cx
,cy
,cw
,ch
);
1457 wxBitmap bitmap
= selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1459 // draw scaled bitmap
1460 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1461 gdk_draw_drawable( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1465 // No scaling and not a memory dc with a mask either
1467 GdkWindow
* window
= NULL
;
1468 wxImplDC
*impl
= source
->GetImpl();
1469 wxGTKWindowImplDC
*gtk_impl
= wxDynamicCast(impl
, wxGTKWindowImplDC
);
1471 window
= gtk_impl
->GetGDKWindow();
1473 GdkWindow
* window
= source
->GetGDKWindow();
1478 // copy including child window contents
1479 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1480 gdk_draw_drawable( m_window
, m_penGC
,
1484 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1488 SetLogicalFunction( old_logical_func
);
1493 void wxGTKWindowImplDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1495 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1497 if (!m_window
) return;
1499 if (text
.empty()) return;
1504 wxCHECK_RET( m_context
, wxT("no Pango context") );
1505 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1506 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1508 gdk_pango_context_set_colormap( m_context
, m_cmap
);
1510 bool underlined
= m_font
.IsOk() && m_font
.GetUnderlined();
1512 const wxCharBuffer data
= wxGTK_CONV( text
);
1515 size_t datalen
= strlen(data
);
1517 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1518 // has been fixed and thus the hack implemented below should never be used
1519 static bool pangoOk
= !wx_pango_version_check(1, 16, 0);
1521 bool needshack
= underlined
&& !pangoOk
;
1522 char *hackstring
= NULL
;
1526 // a PangoLayout which has leading/trailing spaces with underlined font
1527 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1528 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1529 // this behaviour. To workaround this problem, we use a special hack here
1530 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1531 // empty space characters and give them a dummy colour attribute.
1532 // This will force Pango to underline the leading/trailing spaces, too.
1534 // need to realloc the string to prepend & append our special characters
1535 hackstring
= (char*)malloc((datalen
+7)*sizeof(char));
1537 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1538 strcpy(hackstring
, "\342\200\214");
1540 // copy the user string
1541 memcpy(&hackstring
[3], data
, datalen
);
1543 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1544 strcpy(&hackstring
[datalen
+3], "\342\200\214");
1546 // the special characters that we added require 6 additional bytes:
1549 pango_layout_set_text(m_layout
, hackstring
, datalen
);
1553 pango_layout_set_text(m_layout
, data
, datalen
);
1558 PangoAttrList
*attrs
= pango_attr_list_new();
1559 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1561 a
->end_index
= datalen
;
1562 pango_attr_list_insert(attrs
, a
);
1566 // dummy colour for the leading space
1567 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1570 pango_attr_list_insert(attrs
, a
);
1572 // dummy colour for the trailing space
1573 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1574 a
->start_index
= datalen
- 1;
1575 a
->end_index
= datalen
;
1576 pango_attr_list_insert(attrs
, a
);
1579 pango_layout_set_attributes(m_layout
, attrs
);
1580 pango_attr_list_unref(attrs
);
1585 if (fabs(m_scaleY
- 1.0) > 0.00001)
1587 // If there is a user or actually any scale applied to
1588 // the device context, scale the font.
1590 // scale font description
1591 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1592 double size
= oldSize
;
1593 size
= size
* m_scaleY
;
1594 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1596 // actually apply scaled font
1597 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1599 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1600 if ( m_backgroundMode
== wxSOLID
)
1602 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1603 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1604 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1608 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1609 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1611 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1613 // reset unscaled size
1614 pango_font_description_set_size( m_fontdesc
, oldSize
);
1616 // actually apply unscaled font
1617 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1621 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1622 if ( m_backgroundMode
== wxSOLID
)
1624 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1625 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1626 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1630 if (m_owningWindow
&& m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
)
1631 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1633 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1638 // undo underline attributes setting:
1639 pango_layout_set_attributes(m_layout
, NULL
);
1645 width
= wxCoord(width
/ m_scaleX
);
1646 height
= wxCoord(height
/ m_scaleY
);
1647 CalcBoundingBox (x
+ width
, y
+ height
);
1648 CalcBoundingBox (x
, y
);
1655 // TODO: There is an example of rotating text with GTK2 that would probably be
1656 // a better approach here:
1657 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1659 void wxGTKWindowImplDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1662 if (!m_window
|| text
.empty())
1665 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1667 if ( wxIsNullDouble(angle
) )
1669 DoDrawText(text
, x
, y
);
1676 // TODO: implement later without GdkFont for GTK 2.0
1677 DoGetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1679 // draw the string normally
1682 dc
.SelectObject(src
);
1683 dc
.SetFont(GetFont());
1684 dc
.SetBackground(*wxBLACK_BRUSH
);
1685 dc
.SetBrush(*wxBLACK_BRUSH
);
1687 dc
.SetTextForeground( *wxWHITE
);
1688 dc
.DrawText(text
, 0, 0);
1689 dc
.SelectObject(wxNullBitmap
);
1691 // Calculate the size of the rotated bounding box.
1692 double rad
= DegToRad(angle
);
1693 double dx
= cos(rad
),
1696 // the rectngle vertices are counted clockwise with the first one being at
1697 // (0, 0) (or, rather, at (x, y))
1699 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1702 double x3
= x4
+ x2
,
1706 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1707 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1708 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1709 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1712 wxImage image
= src
.ConvertToImage();
1714 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1715 m_textForegroundColour
.Green(),
1716 m_textForegroundColour
.Blue() );
1717 image
= image
.Rotate( rad
, wxPoint(0,0) );
1719 int i_angle
= (int) angle
;
1720 i_angle
= i_angle
% 360;
1724 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1725 xoffset
= image
.GetWidth();
1727 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1728 yoffset
= image
.GetHeight();
1730 if ((i_angle
>= 0) && (i_angle
< 90))
1731 yoffset
-= (int)( cos(rad
)*h
);
1732 if ((i_angle
>= 90) && (i_angle
< 180))
1733 xoffset
-= (int)( sin(rad
)*h
);
1734 if ((i_angle
>= 180) && (i_angle
< 270))
1735 yoffset
-= (int)( cos(rad
)*h
);
1736 if ((i_angle
>= 270) && (i_angle
< 360))
1737 xoffset
-= (int)( sin(rad
)*h
);
1739 int i_x
= x
- xoffset
;
1740 int i_y
= y
- yoffset
;
1743 DoDrawBitmap( src
, i_x
, i_y
, true );
1746 // it would be better to draw with non underlined font and draw the line
1747 // manually here (it would be more straight...)
1749 if ( m_font
.GetUnderlined() )
1751 gdk_draw_line( m_window
, m_textGC
,
1752 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1753 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1757 // update the bounding box
1758 CalcBoundingBox(x
+ minX
, y
+ minY
);
1759 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1760 #endif // wxUSE_IMAGE
1763 void wxGTKWindowImplDC::DoGetTextExtent(const wxString
&string
,
1764 wxCoord
*width
, wxCoord
*height
,
1765 wxCoord
*descent
, wxCoord
*externalLeading
,
1766 const wxFont
*theFont
) const
1774 if ( externalLeading
)
1775 *externalLeading
= 0;
1780 // ensure that theFont is always non-NULL
1781 if ( !theFont
|| !theFont
->IsOk() )
1782 theFont
= wx_const_cast(wxFont
*, &m_font
);
1784 // and use it if it's valid
1785 if ( theFont
->IsOk() )
1787 pango_layout_set_font_description
1790 theFont
->GetNativeFontInfo()->description
1794 // Set layout's text
1795 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1798 // hardly ideal, but what else can we do if conversion failed?
1802 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1807 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1808 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1809 int baseline
= pango_layout_iter_get_baseline(iter
);
1810 pango_layout_iter_free(iter
);
1811 *descent
= h
- PANGO_PIXELS(baseline
);
1814 *height
= (wxCoord
) h
;
1818 pango_layout_get_pixel_size( m_layout
, width
, height
);
1821 // Reset old font description
1822 if (theFont
->IsOk())
1823 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1827 bool wxGTKWindowImplDC::DoGetPartialTextExtents(const wxString
& text
,
1828 wxArrayInt
& widths
) const
1830 const size_t len
= text
.length();
1837 // Set layout's text
1838 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1841 // hardly ideal, but what else can we do if conversion failed?
1842 wxLogLastError(wxT("DoGetPartialTextExtents"));
1846 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1848 // Calculate the position of each character based on the widths of
1849 // the previous characters
1851 // Code borrowed from Scintilla's PlatGTK
1852 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1854 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1856 while (pango_layout_iter_next_cluster(iter
))
1858 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1859 int position
= PANGO_PIXELS(pos
.x
);
1860 widths
[i
++] = position
;
1863 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1864 pango_layout_iter_free(iter
);
1870 wxCoord
wxGTKWindowImplDC::GetCharWidth() const
1872 pango_layout_set_text( m_layout
, "H", 1 );
1874 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1878 wxCoord
wxGTKWindowImplDC::GetCharHeight() const
1880 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1881 wxCHECK_MSG( metrics
, -1, _T("failed to get pango font metrics") );
1883 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1884 pango_font_metrics_get_ascent (metrics
));
1885 pango_font_metrics_unref (metrics
);
1889 void wxGTKWindowImplDC::Clear()
1891 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1893 if (!m_window
) return;
1896 DoGetSize( &width
, &height
);
1897 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1900 void wxGTKWindowImplDC::SetFont( const wxFont
&font
)
1907 pango_font_description_free( m_fontdesc
);
1909 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1914 PangoContext
*oldContext
= m_context
;
1916 m_context
= m_owningWindow
->GtkGetPangoDefaultContext();
1918 // If we switch back/forth between different contexts
1919 // we also have to create a new layout. I think so,
1920 // at least, and it doesn't hurt to do it.
1921 if (oldContext
!= m_context
)
1924 g_object_unref (m_layout
);
1926 m_layout
= pango_layout_new( m_context
);
1930 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1934 void wxGTKWindowImplDC::SetPen( const wxPen
&pen
)
1936 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1938 if (m_pen
== pen
) return;
1942 if (!m_pen
.IsOk()) return;
1944 if (!m_window
) return;
1946 gint width
= m_pen
.GetWidth();
1949 // CMB: if width is non-zero scale it with the dc
1954 // X doesn't allow different width in x and y and so we take
1957 ( fabs((double) XLOG2DEVREL(width
)) +
1958 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1962 // width can't be 0 or an internal GTK error occurs inside
1963 // gdk_gc_set_dashes() below
1968 static const wxGTKDash dotted
[] = {1, 1};
1969 static const wxGTKDash short_dashed
[] = {2, 2};
1970 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1971 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1973 // We express dash pattern in pen width unit, so we are
1974 // independent of zoom factor and so on...
1976 const wxGTKDash
*req_dash
;
1978 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1979 switch (m_pen
.GetStyle())
1983 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1984 req_nb_dash
= m_pen
.GetDashCount();
1985 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1990 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1997 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1999 req_dash
= wxCoord_dashed
;
2004 lineStyle
= GDK_LINE_ON_OFF_DASH
;
2006 req_dash
= short_dashed
;
2011 // lineStyle = GDK_LINE_DOUBLE_DASH;
2012 lineStyle
= GDK_LINE_ON_OFF_DASH
;
2014 req_dash
= dotted_dashed
;
2019 case wxSTIPPLE_MASK_OPAQUE
:
2024 lineStyle
= GDK_LINE_SOLID
;
2025 req_dash
= (wxGTKDash
*)NULL
;
2031 if (req_dash
&& req_nb_dash
)
2033 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
2036 for (int i
= 0; i
< req_nb_dash
; i
++)
2037 real_req_dash
[i
] = req_dash
[i
] * width
;
2038 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
2039 delete[] real_req_dash
;
2043 // No Memory. We use non-scaled dash pattern...
2044 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
2048 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
2049 switch (m_pen
.GetCap())
2051 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
2052 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
2059 capStyle
= GDK_CAP_NOT_LAST
;
2063 capStyle
= GDK_CAP_ROUND
;
2069 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
2070 switch (m_pen
.GetJoin())
2072 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
2073 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
2075 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
2078 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
2080 m_pen
.GetColour().CalcPixel( m_cmap
);
2081 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
2084 void wxGTKWindowImplDC::SetBrush( const wxBrush
&brush
)
2086 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2088 if (m_brush
== brush
) return;
2092 if (!m_brush
.IsOk()) return;
2094 if (!m_window
) return;
2096 m_brush
.GetColour().CalcPixel( m_cmap
);
2097 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
2099 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
2101 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->IsOk()))
2103 if (m_brush
.GetStipple()->GetDepth() != 1)
2105 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
2106 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2110 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2111 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2115 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2117 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2118 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2121 if (m_brush
.IsHatch())
2123 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2124 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
2125 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
2129 void wxGTKWindowImplDC::SetBackground( const wxBrush
&brush
)
2131 /* CMB 21/7/98: Added SetBackground. Sets background brush
2132 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2134 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2136 if (m_backgroundBrush
== brush
) return;
2138 m_backgroundBrush
= brush
;
2140 if (!m_backgroundBrush
.IsOk()) return;
2142 if (!m_window
) return;
2144 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2145 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2146 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2147 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2148 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2150 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2152 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->IsOk()))
2154 if (m_backgroundBrush
.GetStipple()->GetDepth() != 1)
2156 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2157 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2161 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2162 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2166 if (m_backgroundBrush
.IsHatch())
2168 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2169 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2170 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2174 void wxGTKWindowImplDC::SetLogicalFunction( int function
)
2176 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2178 if (m_logicalFunction
== function
)
2181 // VZ: shouldn't this be a CHECK?
2188 case wxXOR
: mode
= GDK_XOR
; break;
2189 case wxINVERT
: mode
= GDK_INVERT
; break;
2190 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2191 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2192 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2193 case wxSET
: mode
= GDK_SET
; break;
2194 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2195 case wxAND
: mode
= GDK_AND
; break;
2196 case wxOR
: mode
= GDK_OR
; break;
2197 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2198 case wxNAND
: mode
= GDK_NAND
; break;
2199 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2200 case wxCOPY
: mode
= GDK_COPY
; break;
2201 case wxNO_OP
: mode
= GDK_NOOP
; break;
2202 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2204 // unsupported by GTK
2205 case wxNOR
: mode
= GDK_COPY
; break;
2207 wxFAIL_MSG( wxT("unsupported logical function") );
2211 m_logicalFunction
= function
;
2213 gdk_gc_set_function( m_penGC
, mode
);
2214 gdk_gc_set_function( m_brushGC
, mode
);
2216 // to stay compatible with wxMSW, we don't apply ROPs to the text
2217 // operations (i.e. DrawText/DrawRotatedText).
2218 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2219 gdk_gc_set_function( m_textGC
, mode
);
2222 void wxGTKWindowImplDC::SetTextForeground( const wxColour
&col
)
2224 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2226 // don't set m_textForegroundColour to an invalid colour as we'd crash
2227 // later then (we use m_textForegroundColour.GetColor() without checking
2229 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
2232 m_textForegroundColour
= col
;
2236 m_textForegroundColour
.CalcPixel( m_cmap
);
2237 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2241 void wxGTKWindowImplDC::SetTextBackground( const wxColour
&col
)
2243 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2246 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
2249 m_textBackgroundColour
= col
;
2253 m_textBackgroundColour
.CalcPixel( m_cmap
);
2254 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2258 void wxGTKWindowImplDC::SetBackgroundMode( int mode
)
2260 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2262 m_backgroundMode
= mode
;
2264 if (!m_window
) return;
2266 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2267 // transparent/solid background mode
2269 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2271 gdk_gc_set_fill( m_brushGC
,
2272 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2276 void wxGTKWindowImplDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2278 wxFAIL_MSG( wxT("wxGTKWindowImplDC::SetPalette not implemented") );
2281 void wxGTKWindowImplDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2283 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2285 if (!m_window
) return;
2288 rect
.x
= XLOG2DEV(x
);
2289 rect
.y
= YLOG2DEV(y
);
2290 rect
.width
= XLOG2DEVREL(width
);
2291 rect
.height
= YLOG2DEVREL(height
);
2293 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
2294 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
2296 rect
.x
-= rect
.width
;
2299 if (!m_currentClippingRegion
.IsNull())
2300 m_currentClippingRegion
.Intersect( rect
);
2302 m_currentClippingRegion
.Union( rect
);
2304 #if USE_PAINT_REGION
2305 if (!m_paintClippingRegion
.IsNull())
2306 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2309 wxCoord xx
, yy
, ww
, hh
;
2310 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2312 wxImplDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2314 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2317 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2318 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2319 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2320 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2323 void wxGTKWindowImplDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2325 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2329 DestroyClippingRegion();
2333 if (!m_window
) return;
2335 if (!m_currentClippingRegion
.IsNull())
2336 m_currentClippingRegion
.Intersect( region
);
2338 m_currentClippingRegion
.Union( region
);
2340 #if USE_PAINT_REGION
2341 if (!m_paintClippingRegion
.IsNull())
2342 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2345 wxCoord xx
, yy
, ww
, hh
;
2346 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2348 wxImplDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2350 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2353 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2354 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2355 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2356 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2359 void wxGTKWindowImplDC::DestroyClippingRegion()
2361 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2364 wxImplDC::DestroyClippingRegion();
2366 wxDC::DestroyClippingRegion();
2369 m_currentClippingRegion
.Clear();
2371 #if USE_PAINT_REGION
2372 if (!m_paintClippingRegion
.IsEmpty())
2373 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2376 if (!m_window
) return;
2378 if (m_currentClippingRegion
.IsEmpty())
2380 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2381 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2382 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2383 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2387 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2388 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2389 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2390 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2394 void wxGTKWindowImplDC::Destroy()
2396 if (m_penGC
) wxFreePoolGC( m_penGC
);
2397 m_penGC
= (GdkGC
*) NULL
;
2398 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2399 m_brushGC
= (GdkGC
*) NULL
;
2400 if (m_textGC
) wxFreePoolGC( m_textGC
);
2401 m_textGC
= (GdkGC
*) NULL
;
2402 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2403 m_bgGC
= (GdkGC
*) NULL
;
2406 void wxGTKWindowImplDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2408 m_deviceOriginX
= x
;
2409 m_deviceOriginY
= y
;
2411 ComputeScaleAndOrigin();
2414 void wxGTKWindowImplDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2416 m_signX
= (xLeftRight
? 1 : -1);
2417 m_signY
= (yBottomUp
? -1 : 1);
2419 if (m_owningWindow
&& m_owningWindow
->m_wxwindow
&&
2420 (m_owningWindow
->GetLayoutDirection() == wxLayout_RightToLeft
))
2423 ComputeScaleAndOrigin();
2426 void wxGTKWindowImplDC::ComputeScaleAndOrigin()
2428 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2431 wxImplDC::ComputeScaleAndOrigin();
2433 wxDC::ComputeScaleAndOrigin();
2436 // if scale has changed call SetPen to recalulate the line width
2437 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2439 // this is a bit artificial, but we need to force wxDC to think the pen
2447 // Resolution in pixels per logical inch
2448 wxSize
wxGTKWindowImplDC::GetPPI() const
2450 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2453 int wxGTKWindowImplDC::GetDepth() const
2455 return gdk_drawable_get_depth(m_window
);
2459 //-----------------------------------------------------------------------------
2461 //-----------------------------------------------------------------------------
2464 IMPLEMENT_ABSTRACT_CLASS(wxGTKClientImplDC
, wxGTKWindowImplDC
)
2466 IMPLEMENT_ABSTRACT_CLASS(wxClientDC
, wxWindowDC
)
2470 wxGTKClientImplDC::wxGTKClientImplDC( wxDC
*owner
)
2471 : wxGTKWindowImplDC( owner
)
2475 wxGTKClientImplDC::wxGTKClientImplDC( wxDC
*owner
, wxWindow
*win
)
2476 : wxGTKWindowImplDC( owner
, win
)
2478 wxClientDC::wxClientDC()
2482 wxClientDC::wxClientDC( wxWindow
*win
)
2487 wxCHECK_RET( win
, _T("NULL window in wxGTKClientImplDC::wxClientDC") );
2489 #ifdef __WXUNIVERSAL__
2490 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2491 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2492 wxSize size
= win
->GetClientSize();
2493 SetClippingRegion(wxPoint(0, 0), size
);
2494 #endif // __WXUNIVERSAL__
2497 void wxGTKClientImplDC::DoGetSize(int *width
, int *height
) const
2499 wxCHECK_RET( m_owningWindow
, _T("GetSize() doesn't work without window") );
2501 m_owningWindow
->GetClientSize( width
, height
);
2504 //-----------------------------------------------------------------------------
2506 //-----------------------------------------------------------------------------
2509 IMPLEMENT_ABSTRACT_CLASS(wxGTKPaintImplDC
, wxGTKClientImplDC
)
2511 IMPLEMENT_ABSTRACT_CLASS(wxPaintDC
, wxClientDC
)
2514 // Limit the paint region to the window size. Sometimes
2515 // the paint region is too big, and this risks X11 errors
2516 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2518 wxRect originalRect
= region
.GetBox();
2519 wxRect
rect(originalRect
);
2520 if (rect
.width
+ rect
.x
> sz
.x
)
2521 rect
.width
= sz
.x
- rect
.x
;
2522 if (rect
.height
+ rect
.y
> sz
.y
)
2523 rect
.height
= sz
.y
- rect
.y
;
2524 if (rect
!= originalRect
)
2526 region
= wxRegion(rect
);
2527 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2528 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2529 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2534 wxGTKPaintImplDC::wxGTKPaintImplDC( wxDC
*owner
)
2535 : wxGTKClientImplDC( owner
)
2539 wxGTKPaintImplDC::wxGTKPaintImplDC( wxDC
*owner
, wxWindow
*win
)
2540 : wxGTKClientImplDC( owner
, win
)
2542 wxPaintDC::wxPaintDC()
2547 wxPaintDC::wxPaintDC( wxWindow
*win
)
2551 #if USE_PAINT_REGION
2552 if (!win
->m_clipPaintRegion
)
2555 wxSize sz
= win
->GetSize();
2556 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2557 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2559 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2562 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2563 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2565 if (sz
.x
<= 0 || sz
.y
<= 0)
2568 gdk_gc_set_clip_region( m_penGC
, region
);
2569 gdk_gc_set_clip_region( m_brushGC
, region
);
2570 gdk_gc_set_clip_region( m_textGC
, region
);
2571 gdk_gc_set_clip_region( m_bgGC
, region
);
2573 #endif // USE_PAINT_REGION
2576 // ----------------------------------------------------------------------------
2578 // ----------------------------------------------------------------------------
2580 class wxDCModule
: public wxModule
2587 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2590 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2592 bool wxDCModule::OnInit()
2598 void wxDCModule::OnExit()