1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dcclient.cpp
3 // Purpose: wxWindowDCImpl implementation
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"
13 #include "wx/gtk/dcclient.h"
16 #include "wx/window.h"
18 #include "wx/dcmemory.h"
21 #include "wx/module.h"
24 #include "wx/fontutil.h"
26 #include "wx/gtk/private.h"
27 #include "wx/gtk/private/object.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 #define XLOG2DEV(x) LogicalToDeviceX(x)
34 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
35 #define YLOG2DEV(y) LogicalToDeviceY(y)
36 #define YLOG2DEVREL(y) LogicalToDeviceYRel(y)
38 #define USE_PAINT_REGION 1
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
51 static GdkPixmap
* hatches
[wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
+ 1];
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 static const double RAD2DEG
= 180.0 / M_PI
;
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
64 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
66 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
68 static GdkPixmap
* GetHatch(int style
)
70 wxASSERT(style
>= wxBRUSHSTYLE_FIRST_HATCH
&& style
<= wxBRUSHSTYLE_LAST_HATCH
);
71 const int i
= style
- wxBRUSHSTYLE_FIRST_HATCH
;
72 if (hatches
[i
] == NULL
)
74 // This macro creates a bitmap from an XBM file included above. Notice
75 // the need for the cast because gdk_bitmap_create_from_data() doesn't
76 // accept unsigned data but the arrays in XBM need to be unsigned to
77 // avoid warnings (and even errors in C+0x mode) from g++.
78 #define CREATE_FROM_XBM_DATA(name) \
79 gdk_bitmap_create_from_data \
82 reinterpret_cast<gchar *>(name ## _bits), \
89 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
90 hatches
[i
] = CREATE_FROM_XBM_DATA(bdiag
);
92 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
93 hatches
[i
] = CREATE_FROM_XBM_DATA(cdiag
);
95 case wxBRUSHSTYLE_CROSS_HATCH
:
96 hatches
[i
] = CREATE_FROM_XBM_DATA(cross
);
98 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
99 hatches
[i
] = CREATE_FROM_XBM_DATA(fdiag
);
101 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
102 hatches
[i
] = CREATE_FROM_XBM_DATA(horiz
);
104 case wxBRUSHSTYLE_VERTICAL_HATCH
:
105 hatches
[i
] = CREATE_FROM_XBM_DATA(verti
);
109 #undef CREATE_FROM_XBM_DATA
114 //-----------------------------------------------------------------------------
115 // Implement Pool of Graphic contexts. Creating them takes too much time.
116 //-----------------------------------------------------------------------------
146 #define GC_POOL_ALLOC_SIZE 100
148 static int wxGCPoolSize
= 0;
150 static wxGC
*wxGCPool
= NULL
;
152 static void wxInitGCPool()
154 // This really could wait until the first call to
155 // wxGetPoolGC, but we will make the first allocation
156 // now when other initialization is being performed.
158 // Set initial pool size.
159 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
161 // Allocate initial pool.
162 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
163 if (wxGCPool
== NULL
)
165 // If we cannot malloc, then fail with error
166 // when debug is enabled. If debug is not enabled,
167 // the problem will eventually get caught
169 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
173 // Zero initial pool.
174 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
177 static void wxCleanUpGCPool()
179 for (int i
= 0; i
< wxGCPoolSize
; i
++)
181 if (wxGCPool
[i
].m_gc
)
182 g_object_unref (wxGCPool
[i
].m_gc
);
190 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
194 // Look for an available GC.
195 for (int i
= 0; i
< wxGCPoolSize
; i
++)
197 if (!wxGCPool
[i
].m_gc
)
199 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
200 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
201 wxGCPool
[i
].m_type
= type
;
202 wxGCPool
[i
].m_used
= false;
204 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
206 wxGCPool
[i
].m_used
= true;
207 return wxGCPool
[i
].m_gc
;
211 // We did not find an available GC.
212 // We need to grow the GC pool.
213 pptr
= (wxGC
*)realloc(wxGCPool
,
214 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
217 // Initialize newly allocated pool.
219 memset(&wxGCPool
[wxGCPoolSize
], 0,
220 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
222 // Initialize entry we will return.
223 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
224 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
225 wxGCPool
[wxGCPoolSize
].m_type
= type
;
226 wxGCPool
[wxGCPoolSize
].m_used
= true;
228 // Set new value of pool size.
229 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
231 // Return newly allocated entry.
232 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
235 // The realloc failed. Fall through to error.
236 wxFAIL_MSG( wxT("No GC available") );
241 static void wxFreePoolGC( GdkGC
*gc
)
243 for (int i
= 0; i
< wxGCPoolSize
; i
++)
245 if (wxGCPool
[i
].m_gc
== gc
)
247 wxGCPool
[i
].m_used
= false;
252 wxFAIL_MSG( wxT("Wrong GC") );
255 //-----------------------------------------------------------------------------
257 //-----------------------------------------------------------------------------
259 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
261 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
) :
270 m_isScreenDC
= false;
276 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
279 wxASSERT_MSG( window
, wxT("DC needs a window") );
287 m_isScreenDC
= false;
288 m_font
= window
->GetFont();
290 GtkWidget
*widget
= window
->m_wxwindow
;
291 m_gdkwindow
= window
->GTKGetDrawingWindow();
293 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
294 // code should still be able to create wxClientDCs for them
297 widget
= window
->m_widget
;
299 wxCHECK_RET(widget
, "DC needs a widget");
301 m_gdkwindow
= widget
->window
;
302 if (!gtk_widget_get_has_window(widget
))
303 SetDeviceLocalOrigin(widget
->allocation
.x
, widget
->allocation
.y
);
306 m_context
= window
->GTKGetPangoDefaultContext();
307 m_layout
= pango_layout_new( m_context
);
308 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
310 // Window not realized ?
313 // Don't report problems as per MSW.
319 m_cmap
= gtk_widget_get_colormap(widget
);
323 /* this must be done after SetUpDC, bacause SetUpDC calls the
324 repective SetBrush, SetPen, SetBackground etc functions
325 to set up the DC. SetBackground call m_owner->SetBackground
326 and this might not be desired as the standard dc background
327 is white whereas a window might assume gray to be the
328 standard (as e.g. wxStatusBar) */
332 if (m_window
&& m_window
->m_wxwindow
&&
333 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
338 // origin in the upper right corner
339 m_deviceOriginX
= m_window
->GetClientSize().x
;
343 wxWindowDCImpl::~wxWindowDCImpl()
348 g_object_unref (m_layout
);
350 pango_font_description_free( m_fontdesc
);
353 void wxWindowDCImpl::SetUpDC( bool isMemDC
)
357 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
361 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
363 if (GetSelectedBitmap().GetDepth() == 1)
365 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
366 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
367 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
368 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
377 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
378 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
379 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
380 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
382 #if GTK_CHECK_VERSION(2,12,0)
383 // gdk_screen_get_rgba_colormap was added in 2.8, but this code is for
384 // compositing which requires 2.12
385 else if (gtk_check_version(2,12,0) == NULL
&&
386 m_cmap
== gdk_screen_get_rgba_colormap(gdk_colormap_get_screen(m_cmap
)))
388 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR_ALPHA
);
389 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR_ALPHA
);
390 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR_ALPHA
);
391 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR_ALPHA
);
396 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
397 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
398 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
399 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
403 /* background colour */
404 m_backgroundBrush
= *wxWHITE_BRUSH
;
405 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
406 const 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
, NULL
);
446 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
447 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
448 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
451 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
453 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
455 m_window
->GetSize(width
, height
);
458 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
459 const wxColour
& col
, wxFloodFillStyle style
)
462 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
463 const wxColour
& col
, wxFloodFillStyle style
);
465 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
476 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
478 GdkImage
* image
= NULL
;
481 const int x
= LogicalToDeviceX(x1
);
482 const int y
= LogicalToDeviceY(y1
);
484 gdk_drawable_get_size(m_gdkwindow
, &rect
.width
, &rect
.height
);
485 if (rect
.Contains(x
, y
))
486 image
= gdk_drawable_get_image(m_gdkwindow
, x
, y
, 1, 1);
493 GdkColormap
* colormap
= gdk_image_get_colormap(image
);
494 const unsigned pixel
= gdk_image_get_pixel(image
, 0, 0);
495 if (colormap
== NULL
)
496 *col
= pixel
? m_textForegroundColour
: m_textBackgroundColour
;
500 gdk_colormap_query_color(colormap
, pixel
, &c
);
501 col
->Set(c
.red
>> 8, c
.green
>> 8, c
.blue
>> 8);
503 g_object_unref(image
);
507 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
509 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
511 if ( m_pen
.IsNonTransparent() )
514 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
516 CalcBoundingBox(x1
, y1
);
517 CalcBoundingBox(x2
, y2
);
521 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
523 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
525 if ( m_pen
.IsNonTransparent() )
529 GetOwner()->GetSize( &w
, &h
);
530 wxCoord xx
= XLOG2DEV(x
);
531 wxCoord yy
= YLOG2DEV(y
);
534 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
535 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
540 void wxWindowDCImpl::DrawingSetup(GdkGC
*& gc
, bool& originChanged
)
543 GdkPixmap
* pixmap
= NULL
;
544 const int style
= m_brush
.GetStyle();
546 if (style
== wxBRUSHSTYLE_STIPPLE
|| style
== wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
)
548 const wxBitmap
* stipple
= m_brush
.GetStipple();
551 if (style
== wxBRUSHSTYLE_STIPPLE
)
552 pixmap
= stipple
->GetPixmap();
553 else if (stipple
->GetMask())
555 pixmap
= stipple
->GetPixmap();
560 else if (m_brush
.IsHatch())
562 pixmap
= GetHatch(style
);
570 gdk_drawable_get_size(pixmap
, &w
, &h
);
571 origin_x
= m_deviceOriginX
% w
;
572 origin_y
= m_deviceOriginY
% h
;
575 originChanged
= origin_x
|| origin_y
;
577 gdk_gc_set_ts_origin(gc
, origin_x
, origin_y
);
580 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
581 wxCoord xc
, wxCoord yc
)
583 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
585 wxCoord xx1
= XLOG2DEV(x1
);
586 wxCoord yy1
= YLOG2DEV(y1
);
587 wxCoord xx2
= XLOG2DEV(x2
);
588 wxCoord yy2
= YLOG2DEV(y2
);
589 wxCoord xxc
= XLOG2DEV(xc
);
590 wxCoord yyc
= YLOG2DEV(yc
);
591 double dx
= xx1
- xxc
;
592 double dy
= yy1
- yyc
;
593 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
594 wxCoord r
= (wxCoord
)radius
;
595 double radius1
, radius2
;
597 if (xx1
== xx2
&& yy1
== yy2
)
602 else if ( wxIsNullDouble(radius
) )
609 radius1
= (xx1
- xxc
== 0) ?
610 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
611 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
612 radius2
= (xx2
- xxc
== 0) ?
613 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
614 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
616 wxCoord alpha1
= wxCoord(radius1
* 64.0);
617 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
618 while (alpha2
<= 0) alpha2
+= 360*64;
619 while (alpha1
> 360*64) alpha1
-= 360*64;
623 if ( m_brush
.IsNonTransparent() )
627 DrawingSetup(gc
, originChanged
);
629 gdk_draw_arc(m_gdkwindow
, gc
, true, xxc
-r
, yyc
-r
, 2*r
, 2*r
, alpha1
, alpha2
);
632 gdk_gc_set_ts_origin(gc
, 0, 0);
635 if ( m_pen
.IsNonTransparent() )
637 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
639 if ( m_brush
.IsNonTransparent() && (alpha2
- alpha1
!= 360*64) )
641 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
642 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
647 CalcBoundingBox (x1
, y1
);
648 CalcBoundingBox (x2
, y2
);
651 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
653 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
655 wxCoord xx
= XLOG2DEV(x
);
656 wxCoord yy
= YLOG2DEV(y
);
657 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
658 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
660 // CMB: handle -ve width and/or height
661 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
662 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
666 wxCoord start
= wxCoord(sa
* 64.0);
667 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
669 if ( m_brush
.IsNonTransparent() )
673 DrawingSetup(gc
, originChanged
);
675 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, start
, end
);
678 gdk_gc_set_ts_origin(gc
, 0, 0);
681 if ( m_pen
.IsNonTransparent() )
682 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
685 CalcBoundingBox (x
, y
);
686 CalcBoundingBox (x
+ width
, y
+ height
);
689 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
691 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
693 if ( m_pen
.IsNonTransparent() && m_gdkwindow
)
694 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
696 CalcBoundingBox (x
, y
);
699 void wxWindowDCImpl::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
701 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
705 if ( m_pen
.IsTransparent() )
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_gdkwindow
, m_penGC
, gpts
, n
);
735 void wxWindowDCImpl::DoDrawPolygon( int n
, wxPoint points
[],
736 wxCoord xoffset
, wxCoord yoffset
,
737 wxPolygonFillMode
WXUNUSED(fillStyle
) )
739 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
743 //Check, if scaling is necessary
745 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
747 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
748 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
751 gdkpoints
= new GdkPoint
[n
];
754 for (i
= 0 ; i
< n
; i
++)
758 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
759 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
761 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
766 if ( m_brush
.IsNonTransparent() )
770 DrawingSetup(gc
, originChanged
);
772 gdk_draw_polygon(m_gdkwindow
, gc
, true, gdkpoints
, n
);
775 gdk_gc_set_ts_origin(gc
, 0, 0);
778 if ( m_pen
.IsNonTransparent() )
781 for (i = 0 ; i < n ; i++)
783 gdk_draw_line( m_gdkwindow, m_penGC,
786 gdkpoints[(i+1)%n].x,
787 gdkpoints[(i+1)%n].y);
790 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, gdkpoints
, n
);
799 void wxWindowDCImpl::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
801 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
803 wxCoord xx
= XLOG2DEV(x
);
804 wxCoord yy
= YLOG2DEV(y
);
805 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
806 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
808 // CMB: draw nothing if transformed w or h is 0
809 if (ww
== 0 || hh
== 0) return;
811 // CMB: handle -ve width and/or height
812 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
813 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
817 if ( m_brush
.IsNonTransparent() )
821 DrawingSetup(gc
, originChanged
);
823 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
);
826 gdk_gc_set_ts_origin(gc
, 0, 0);
829 if ( m_pen
.IsNonTransparent() )
831 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
832 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxPENSTYLE_SOLID
))
834 // Use 2 1-line rects instead
835 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
840 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
841 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
845 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
846 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
850 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
854 // Just use X11 for other cases
855 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
860 CalcBoundingBox( x
, y
);
861 CalcBoundingBox( x
+ width
, y
+ height
);
864 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
866 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
868 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
870 wxCoord xx
= XLOG2DEV(x
);
871 wxCoord yy
= YLOG2DEV(y
);
872 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
873 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
874 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
876 // CMB: handle -ve width and/or height
877 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
878 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
880 // CMB: if radius is zero use DrawRectangle() instead to avoid
881 // X drawing errors with small radii
884 DoDrawRectangle( x
, y
, width
, height
);
888 // CMB: draw nothing if transformed w or h is 0
889 if (ww
== 0 || hh
== 0) return;
891 // CMB: adjust size if outline is drawn otherwise the result is
892 // 1 pixel too wide and high
893 if ( m_pen
.IsNonTransparent() )
901 // CMB: ensure dd is not larger than rectangle otherwise we
902 // get an hour glass shape
904 if (dd
> ww
) dd
= ww
;
905 if (dd
> hh
) dd
= hh
;
908 if ( m_brush
.IsNonTransparent() )
912 DrawingSetup(gc
, originChanged
);
914 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
+rr
, yy
, ww
-dd
+1, hh
);
915 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
+rr
, ww
, hh
-dd
+1);
916 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, dd
, dd
, 90*64, 90*64);
917 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64);
918 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64);
919 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64);
922 gdk_gc_set_ts_origin(gc
, 0, 0);
925 if ( m_pen
.IsNonTransparent() )
927 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
928 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
929 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
930 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
931 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
932 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
933 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
934 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
938 // this ignores the radius
939 CalcBoundingBox( x
, y
);
940 CalcBoundingBox( x
+ width
, y
+ height
);
943 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
945 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
947 wxCoord xx
= XLOG2DEV(x
);
948 wxCoord yy
= YLOG2DEV(y
);
949 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
950 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
952 // CMB: handle -ve width and/or height
953 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
954 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
958 if ( m_brush
.IsNonTransparent() )
962 DrawingSetup(gc
, originChanged
);
964 // If the pen is transparent pen we increase the size
965 // for better compatibility with other platforms.
966 if (m_pen
.IsTransparent())
972 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, 0, 360*64);
975 gdk_gc_set_ts_origin(gc
, 0, 0);
978 if ( m_pen
.IsNonTransparent() )
979 gdk_draw_arc( m_gdkwindow
, m_penGC
, false, xx
, yy
, ww
, hh
, 0, 360*64 );
982 CalcBoundingBox( x
, y
);
983 CalcBoundingBox( x
+ width
, y
+ height
);
986 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
988 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
989 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
992 // scale a pixbuf, return new pixbuf, unref old one
994 Scale(GdkPixbuf
* pixbuf
, int dst_w
, int dst_h
, double sx
, double sy
)
996 GdkPixbuf
* pixbuf_scaled
= gdk_pixbuf_new(
997 GDK_COLORSPACE_RGB
, gdk_pixbuf_get_has_alpha(pixbuf
), 8, dst_w
, dst_h
);
998 gdk_pixbuf_scale(pixbuf
, pixbuf_scaled
,
999 0, 0, dst_w
, dst_h
, 0, 0, sx
, sy
, GDK_INTERP_NEAREST
);
1000 g_object_unref(pixbuf
);
1001 return pixbuf_scaled
;
1004 // scale part of a pixmap using pixbuf scaling, return pixbuf
1006 Scale(GdkPixmap
* pixmap
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1008 GdkPixbuf
* pixbuf
= gdk_pixbuf_get_from_drawable(
1009 NULL
, pixmap
, NULL
, x
, y
, 0, 0, w
, h
);
1010 return Scale(pixbuf
, dst_w
, dst_h
, sx
, sy
);
1013 // scale part of a mask pixmap, return new mask, unref old one
1015 ScaleMask(GdkPixmap
* mask
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1017 GdkPixbuf
* pixbuf
= Scale(mask
, x
, y
, w
, h
, dst_w
, dst_h
, sx
, sy
);
1019 // convert black and white pixbuf back to a mono pixmap
1020 const unsigned out_rowstride
= (dst_w
+ 7) / 8;
1021 const size_t data_size
= out_rowstride
* size_t(dst_h
);
1022 char* data
= new char[data_size
];
1024 const guchar
* row
= gdk_pixbuf_get_pixels(pixbuf
);
1025 const int rowstride
= gdk_pixbuf_get_rowstride(pixbuf
);
1026 memset(data
, 0, data_size
);
1027 for (int j
= 0; j
< dst_h
; j
++, row
+= rowstride
, out
+= out_rowstride
)
1029 const guchar
* in
= row
;
1030 for (int i
= 0; i
< dst_w
; i
++, in
+= 3)
1032 out
[i
>> 3] |= 1 << (i
& 7);
1034 g_object_unref(pixbuf
);
1035 GdkPixmap
* pixmap
= gdk_bitmap_create_from_data(mask
, data
, dst_w
, dst_h
);
1037 g_object_unref(mask
);
1041 // Make a new mask from part of a mask and a clip region.
1042 // Return new mask, unref old one.
1044 ClipMask(GdkPixmap
* mask
, GdkRegion
* clipRegion
, int x
, int y
, int dst_x
, int dst_y
, int w
, int h
)
1046 GdkGCValues gcValues
;
1047 gcValues
.foreground
.pixel
= 0;
1048 GdkGC
* gc
= gdk_gc_new_with_values(mask
, &gcValues
, GDK_GC_FOREGROUND
);
1049 GdkPixmap
* pixmap
= gdk_pixmap_new(mask
, w
, h
, 1);
1050 // clear new mask, so clipped areas will be masked
1051 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1052 gdk_gc_set_clip_region(gc
, clipRegion
);
1053 gdk_gc_set_clip_origin(gc
, -dst_x
, -dst_y
);
1054 // draw old mask onto new one, with clip
1055 gdk_draw_drawable(pixmap
, gc
, mask
, x
, y
, 0, 0, w
, h
);
1057 g_object_unref(mask
);
1061 // make a color pixmap from part of a mono one, using text fg/bg colors
1063 wxWindowDCImpl::MonoToColor(GdkPixmap
* monoPixmap
, int x
, int y
, int w
, int h
) const
1065 GdkPixmap
* pixmap
= gdk_pixmap_new(m_gdkwindow
, w
, h
, -1);
1066 GdkGCValues gcValues
;
1067 gcValues
.foreground
.pixel
= m_textForegroundColour
.GetColor()->pixel
;
1068 gcValues
.background
.pixel
= m_textBackgroundColour
.GetColor()->pixel
;
1069 gcValues
.stipple
= monoPixmap
;
1070 gcValues
.fill
= GDK_OPAQUE_STIPPLED
;
1071 gcValues
.ts_x_origin
= -x
;
1072 gcValues
.ts_y_origin
= -y
;
1073 GdkGC
* gc
= gdk_gc_new_with_values(pixmap
, &gcValues
, GdkGCValuesMask(
1074 GDK_GC_FOREGROUND
| GDK_GC_BACKGROUND
| GDK_GC_STIPPLE
| GDK_GC_FILL
|
1075 GDK_GC_TS_X_ORIGIN
| GDK_GC_TS_Y_ORIGIN
));
1076 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1081 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
1082 wxCoord x
, wxCoord y
,
1085 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1086 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1088 if (!m_gdkwindow
) return;
1090 const int w
= bitmap
.GetWidth();
1091 const int h
= bitmap
.GetHeight();
1093 // notice that as the bitmap is not drawn upside down (or right to left)
1094 // even if the corresponding axis direction is inversed, we need to take it
1095 // into account when calculating its bounding box
1096 CalcBoundingBox(x
, y
);
1097 CalcBoundingBox(x
+ m_signX
*w
, y
+ m_signY
*h
);
1100 int xx
= LogicalToDeviceX(x
);
1101 const int yy
= LogicalToDeviceY(y
);
1102 const int ww
= LogicalToDeviceXRel(w
);
1103 const int hh
= LogicalToDeviceYRel(h
);
1105 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1108 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1109 // determine clip region overlap
1110 int overlap
= wxInRegion
;
1113 overlap
= m_currentClippingRegion
.Contains(xx
, yy
, ww
, hh
);
1114 if (overlap
== wxOutRegion
)
1118 const bool isScaled
= ww
!= w
|| hh
!= h
;
1119 const bool hasAlpha
= bitmap
.HasAlpha();
1120 GdkGC
* const use_gc
= m_penGC
;
1122 GdkPixmap
* mask
= NULL
;
1123 // mask does not work when drawing a pixbuf with alpha
1124 if (useMask
&& !hasAlpha
)
1126 wxMask
* m
= bitmap
.GetMask();
1128 mask
= m
->GetBitmap();
1134 mask
= ScaleMask(mask
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1135 if (overlap
== wxPartRegion
)
1137 // need a new mask that also masks the clipped area,
1138 // because gc can't have both a mask and a clip region
1139 mask
= ClipMask(mask
, clipRegion
, 0, 0, xx
, yy
, ww
, hh
);
1141 gdk_gc_set_clip_mask(use_gc
, mask
);
1142 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1145 // determine whether to use pixmap or pixbuf
1146 GdkPixmap
* pixmap
= NULL
;
1147 GdkPixbuf
* pixbuf
= NULL
;
1148 if (bitmap
.HasPixmap())
1149 pixmap
= bitmap
.GetPixmap();
1150 if (pixmap
&& gdk_drawable_get_depth(pixmap
) == 1)
1152 // convert mono pixmap to color using text fg/bg colors
1153 pixmap
= MonoToColor(pixmap
, 0, 0, w
, h
);
1155 else if (hasAlpha
|| pixmap
== NULL
)
1158 pixbuf
= bitmap
.GetPixbuf();
1159 g_object_ref(pixbuf
);
1163 g_object_ref(pixmap
);
1169 pixbuf
= Scale(pixbuf
, ww
, hh
, m_scaleX
, m_scaleY
);
1171 pixbuf
= Scale(pixmap
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1176 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1177 0, 0, xx
, yy
, ww
, hh
, GDK_RGB_DITHER_NORMAL
, 0, 0);
1178 g_object_unref(pixbuf
);
1182 gdk_draw_drawable(m_gdkwindow
, use_gc
, pixmap
, 0, 0, xx
, yy
, ww
, hh
);
1186 g_object_unref(pixmap
);
1189 g_object_unref(mask
);
1190 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1194 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1195 wxCoord width
, wxCoord height
,
1197 wxCoord xsrc
, wxCoord ysrc
,
1198 wxRasterOperationMode logical_func
,
1200 wxCoord xsrcMask
, wxCoord ysrcMask
)
1202 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1203 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1205 if (!m_gdkwindow
) return false;
1207 GdkDrawable
* srcDrawable
= NULL
;
1208 GdkPixmap
* mask
= NULL
;
1209 wxMemoryDC
* memDC
= wxDynamicCast(source
, wxMemoryDC
);
1212 const wxBitmap
& bitmap
= memDC
->GetSelectedBitmap();
1215 srcDrawable
= bitmap
.GetPixmap();
1218 wxMask
* m
= bitmap
.GetMask();
1220 mask
= m
->GetBitmap();
1225 wxDCImpl
* impl
= source
->GetImpl();
1226 wxWindowDCImpl
* gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1228 srcDrawable
= gtk_impl
->GetGDKWindow();
1229 if (srcDrawable
== NULL
)
1233 CalcBoundingBox(xdest
, ydest
);
1234 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1236 // source device coords
1237 int src_x
= source
->LogicalToDeviceX(xsrc
);
1238 int src_y
= source
->LogicalToDeviceY(ysrc
);
1239 int src_w
= source
->LogicalToDeviceXRel(width
);
1240 int src_h
= source
->LogicalToDeviceYRel(height
);
1242 // Clip source rect to source dc.
1243 // Only necessary when scaling, to avoid GDK errors when
1244 // converting to pixbuf, but no harm in always doing it.
1245 // If source rect changes, it also changes the dest rect.
1247 gdk_drawable_get_size(srcDrawable
, &clip
.width
, &clip
.height
);
1248 clip
.Intersect(wxRect(src_x
, src_y
, src_w
, src_h
));
1249 if (src_w
!= clip
.width
|| src_h
!= clip
.height
)
1251 if (clip
.width
== 0)
1255 src_h
= clip
.height
;
1256 width
= source
->DeviceToLogicalXRel(src_w
);
1257 height
= source
->DeviceToLogicalYRel(src_h
);
1258 if (src_x
!= clip
.x
|| src_y
!= clip
.y
)
1260 xdest
+= source
->DeviceToLogicalXRel(clip
.x
- src_x
);
1261 ydest
+= source
->DeviceToLogicalYRel(clip
.y
- src_y
);
1267 // destination device coords
1268 const int dst_x
= LogicalToDeviceX(xdest
);
1269 const int dst_y
= LogicalToDeviceY(ydest
);
1270 const int dst_w
= LogicalToDeviceXRel(width
);
1271 const int dst_h
= LogicalToDeviceYRel(height
);
1273 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1274 // determine dest clip region overlap
1275 int overlap
= wxInRegion
;
1278 overlap
= m_currentClippingRegion
.Contains(dst_x
, dst_y
, dst_w
, dst_h
);
1279 if (overlap
== wxOutRegion
)
1283 const bool isScaled
= src_w
!= dst_w
|| src_h
!= dst_h
;
1288 // get source to dest scale
1289 double usx
, usy
, lsx
, lsy
;
1290 source
->GetUserScale(&usx
, &usy
);
1291 source
->GetLogicalScale(&lsx
, &lsy
);
1292 scale_x
= m_scaleX
/ (usx
* lsx
);
1293 scale_y
= m_scaleY
/ (usy
* lsy
);
1296 GdkGC
* const use_gc
= m_penGC
;
1301 int srcMask_x
= src_x
;
1302 int srcMask_y
= src_y
;
1303 if (xsrcMask
!= -1 || ysrcMask
!= -1)
1305 srcMask_x
= source
->LogicalToDeviceX(xsrcMask
);
1306 srcMask_y
= source
->LogicalToDeviceY(ysrcMask
);
1310 mask
= ScaleMask(mask
, srcMask_x
, srcMask_y
,
1311 src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1315 if (overlap
== wxPartRegion
)
1317 // need a new mask that also masks the clipped area,
1318 // because gc can't have both a mask and a clip region
1319 mask
= ClipMask(mask
, clipRegion
,
1320 srcMask_x
, srcMask_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1324 gdk_gc_set_clip_mask(use_gc
, mask
);
1325 gdk_gc_set_clip_origin(use_gc
, dst_x
- srcMask_x
, dst_y
- srcMask_y
);
1328 GdkPixmap
* pixmap
= NULL
;
1329 if (gdk_drawable_get_depth(srcDrawable
) == 1)
1331 // Convert mono pixmap to color using text fg/bg colors.
1332 // Scaling/drawing is simpler if this is done first.
1333 pixmap
= MonoToColor(srcDrawable
, src_x
, src_y
, src_w
, src_h
);
1334 srcDrawable
= pixmap
;
1339 const wxRasterOperationMode logical_func_save
= m_logicalFunction
;
1340 SetLogicalFunction(logical_func
);
1342 gdk_gc_set_subwindow(use_gc
, GDK_INCLUDE_INFERIORS
);
1346 GdkPixbuf
* pixbuf
= Scale(srcDrawable
,
1347 src_x
, src_y
, src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1348 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1349 0, 0, dst_x
, dst_y
, dst_w
, dst_h
, GDK_RGB_DITHER_NONE
, 0, 0);
1350 g_object_unref(pixbuf
);
1354 gdk_draw_drawable(m_gdkwindow
, use_gc
, srcDrawable
,
1355 src_x
, src_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1358 SetLogicalFunction(logical_func_save
);
1360 gdk_gc_set_subwindow(use_gc
, GDK_CLIP_BY_CHILDREN
);
1363 g_object_unref(pixmap
);
1366 g_object_unref(mask
);
1367 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1372 void wxWindowDCImpl::DoDrawText(const wxString
& text
,
1376 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1378 if (!m_gdkwindow
) return;
1380 if (text
.empty()) return;
1382 wxCoord x
= XLOG2DEV(xLogical
),
1383 y
= YLOG2DEV(yLogical
);
1385 wxCHECK_RET( m_context
, wxT("no Pango context") );
1386 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1387 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1389 gdk_pango_context_set_colormap( m_context
, m_cmap
); // not needed in gtk+ >= 2.6
1391 wxCharBuffer data
= wxGTK_CONV(text
);
1395 pango_layout_set_text(m_layout
, data
, data
.length());
1396 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1399 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1402 // If there is a user or actually any scale applied to
1403 // the device context, scale the font.
1405 // scale font description
1406 oldSize
= pango_font_description_get_size(m_fontdesc
);
1407 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1409 // actually apply scaled font
1410 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1414 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1418 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1421 const GdkColor
* bg_col
= NULL
;
1422 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1423 bg_col
= m_textBackgroundColour
.GetColor();
1425 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x_rtl
, y
, m_layout
, NULL
, bg_col
);
1429 // reset unscaled size
1430 pango_font_description_set_size( m_fontdesc
, oldSize
);
1432 // actually apply unscaled font
1433 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1437 // undo underline attributes setting:
1438 pango_layout_set_attributes(m_layout
, NULL
);
1441 CalcBoundingBox(xLogical
+ int(w
/ m_scaleX
), yLogical
+ int(h
/ m_scaleY
));
1442 CalcBoundingBox(xLogical
, yLogical
);
1445 // TODO: When GTK2.6 is required, merge DoDrawText and DoDrawRotatedText to
1446 // avoid code duplication
1447 void wxWindowDCImpl::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1449 if (!m_gdkwindow
|| text
.empty())
1452 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1458 pango_layout_set_text(m_layout
, wxGTK_CONV(text
), -1);
1459 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1461 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1464 //TODO: when Pango >= 1.6 is required, use pango_matrix_scale()
1465 // If there is a user or actually any scale applied to
1466 // the device context, scale the font.
1468 // scale font description
1469 oldSize
= pango_font_description_get_size(m_fontdesc
);
1470 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1472 // actually apply scaled font
1473 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1477 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1479 const GdkColor
* bg_col
= NULL
;
1480 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1481 bg_col
= m_textBackgroundColour
.GetColor();
1484 PangoMatrix matrix
= PANGO_MATRIX_INIT
;
1485 pango_matrix_rotate (&matrix
, angle
);
1486 pango_context_set_matrix (m_context
, &matrix
);
1487 pango_layout_context_changed (m_layout
);
1489 // To be compatible with MSW, the rotation axis must be in the old
1491 // Calculate the vertices of the rotated rectangle containing the text,
1492 // relative to the old top-left vertex.
1493 // We could use the matrix for this, but it's simpler with trignonometry.
1494 double rad
= DegToRad(angle
);
1495 // the rectangle vertices are counted clockwise with the first one
1497 double x2
= w
* cos(rad
);
1498 double y2
= -w
* sin(rad
); // y axis points to the bottom, hence minus
1499 double x4
= h
* sin(rad
);
1500 double y4
= h
* cos(rad
);
1501 double x3
= x4
+ x2
;
1502 double y3
= y4
+ y2
;
1503 // Then we calculate max and min of the rotated rectangle.
1504 wxCoord maxX
= (wxCoord
)(dmax(dmax(0, x2
), dmax(x3
, x4
)) + 0.5),
1505 maxY
= (wxCoord
)(dmax(dmax(0, y2
), dmax(y3
, y4
)) + 0.5),
1506 minX
= (wxCoord
)(dmin(dmin(0, x2
), dmin(x3
, x4
)) - 0.5),
1507 minY
= (wxCoord
)(dmin(dmin(0, y2
), dmin(y3
, y4
)) - 0.5);
1509 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x
+minX
, y
+minY
,
1510 m_layout
, NULL
, bg_col
);
1513 pango_layout_set_attributes(m_layout
, NULL
);
1515 // clean up the transformation matrix
1516 pango_context_set_matrix(m_context
, NULL
);
1520 // reset unscaled size
1521 pango_font_description_set_size( m_fontdesc
, oldSize
);
1523 // actually apply unscaled font
1524 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1527 CalcBoundingBox(x
+minX
, y
+minY
);
1528 CalcBoundingBox(x
+maxX
, y
+maxY
);
1532 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1533 wxCoord
*width
, wxCoord
*height
,
1534 wxCoord
*descent
, wxCoord
*externalLeading
,
1535 const wxFont
*theFont
) const
1543 if ( externalLeading
)
1544 *externalLeading
= 0;
1549 // ensure that theFont is always non-NULL
1550 if ( !theFont
|| !theFont
->IsOk() )
1553 // and use it if it's valid
1554 if ( theFont
->IsOk() )
1556 pango_layout_set_font_description
1559 theFont
->GetNativeFontInfo()->description
1563 // Set layout's text
1564 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1567 // hardly ideal, but what else can we do if conversion failed?
1571 pango_layout_set_text(m_layout
, dataUTF8
, -1);
1574 pango_layout_get_pixel_size(m_layout
, width
, &h
);
1577 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1578 int baseline
= pango_layout_iter_get_baseline(iter
);
1579 pango_layout_iter_free(iter
);
1580 *descent
= h
- PANGO_PIXELS(baseline
);
1585 // Reset old font description
1586 if (theFont
->IsOk())
1587 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1591 bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString
& text
,
1592 wxArrayInt
& widths
) const
1594 const size_t len
= text
.length();
1601 // Set layout's text
1602 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1605 // hardly ideal, but what else can we do if conversion failed?
1606 wxLogLastError(wxT("DoGetPartialTextExtents"));
1610 pango_layout_set_text(m_layout
, dataUTF8
, -1);
1612 // Calculate the position of each character based on the widths of
1613 // the previous characters
1615 // Code borrowed from Scintilla's PlatGTK
1616 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1618 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1620 while (pango_layout_iter_next_cluster(iter
))
1622 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1623 int position
= PANGO_PIXELS(pos
.x
);
1624 widths
[i
++] = position
;
1627 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1628 pango_layout_iter_free(iter
);
1634 wxCoord
wxWindowDCImpl::GetCharWidth() const
1636 pango_layout_set_text( m_layout
, "H", 1 );
1638 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1642 wxCoord
wxWindowDCImpl::GetCharHeight() const
1644 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1645 wxCHECK_MSG( metrics
, -1, wxT("failed to get pango font metrics") );
1647 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1648 pango_font_metrics_get_ascent (metrics
));
1649 pango_font_metrics_unref (metrics
);
1653 void wxWindowDCImpl::Clear()
1655 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1657 if (!m_gdkwindow
) return;
1660 DoGetSize( &width
, &height
);
1661 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1664 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1671 pango_font_description_free( m_fontdesc
);
1673 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1678 PangoContext
*oldContext
= m_context
;
1680 m_context
= m_window
->GTKGetPangoDefaultContext();
1682 // If we switch back/forth between different contexts
1683 // we also have to create a new layout. I think so,
1684 // at least, and it doesn't hurt to do it.
1685 if (oldContext
!= m_context
)
1688 g_object_unref (m_layout
);
1690 m_layout
= pango_layout_new( m_context
);
1694 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1698 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1700 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1702 if (m_pen
== pen
) return;
1706 if (!m_pen
.IsOk()) return;
1708 if (!m_gdkwindow
) return;
1710 gint width
= m_pen
.GetWidth();
1713 // CMB: if width is non-zero scale it with the dc
1718 // X doesn't allow different width in x and y and so we take
1721 ( fabs((double) XLOG2DEVREL(width
)) +
1722 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1726 // width can't be 0 or an internal GTK error occurs inside
1727 // gdk_gc_set_dashes() below
1732 static const wxGTKDash dotted
[] = {1, 1};
1733 static const wxGTKDash short_dashed
[] = {2, 2};
1734 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1735 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1737 // We express dash pattern in pen width unit, so we are
1738 // independent of zoom factor and so on...
1740 const wxGTKDash
*req_dash
;
1742 GdkLineStyle lineStyle
= GDK_LINE_ON_OFF_DASH
;
1743 switch (m_pen
.GetStyle())
1745 case wxPENSTYLE_USER_DASH
:
1746 req_nb_dash
= m_pen
.GetDashCount();
1747 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1749 case wxPENSTYLE_DOT
:
1753 case wxPENSTYLE_LONG_DASH
:
1755 req_dash
= wxCoord_dashed
;
1757 case wxPENSTYLE_SHORT_DASH
:
1759 req_dash
= short_dashed
;
1761 case wxPENSTYLE_DOT_DASH
:
1763 req_dash
= dotted_dashed
;
1766 case wxPENSTYLE_TRANSPARENT
:
1767 case wxPENSTYLE_STIPPLE_MASK_OPAQUE
:
1768 case wxPENSTYLE_STIPPLE
:
1769 case wxPENSTYLE_SOLID
:
1771 lineStyle
= GDK_LINE_SOLID
;
1777 if (req_dash
&& req_nb_dash
)
1779 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1782 for (int i
= 0; i
< req_nb_dash
; i
++)
1783 real_req_dash
[i
] = req_dash
[i
] * width
;
1784 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1785 delete[] real_req_dash
;
1789 // No Memory. We use non-scaled dash pattern...
1790 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1794 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1795 switch (m_pen
.GetCap())
1797 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1798 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1804 capStyle
= GDK_CAP_NOT_LAST
;
1809 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1810 switch (m_pen
.GetJoin())
1812 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1813 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1815 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1818 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1820 m_pen
.GetColour().CalcPixel( m_cmap
);
1821 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1824 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
1826 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1828 if (m_brush
== brush
) return;
1832 if (!m_brush
.IsOk()) return;
1834 if (!m_gdkwindow
) return;
1836 m_brush
.GetColour().CalcPixel( m_cmap
);
1837 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1839 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1841 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1843 if (m_brush
.GetStipple()->GetDepth() != 1)
1845 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1846 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1850 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1851 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1855 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1857 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1858 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1861 if (m_brush
.IsHatch())
1863 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1864 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
1868 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
1870 /* CMB 21/7/98: Added SetBackground. Sets background brush
1871 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1873 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1875 if (m_backgroundBrush
== brush
) return;
1877 m_backgroundBrush
= brush
;
1879 if (!m_backgroundBrush
.IsOk()) return;
1881 if (!m_gdkwindow
) return;
1883 wxColor color
= m_backgroundBrush
.GetColour();
1884 color
.CalcPixel(m_cmap
);
1885 const GdkColor
* gdkColor
= color
.GetColor();
1886 gdk_gc_set_background(m_brushGC
, gdkColor
);
1887 gdk_gc_set_background(m_penGC
, gdkColor
);
1888 gdk_gc_set_background(m_bgGC
, gdkColor
);
1889 gdk_gc_set_foreground(m_bgGC
, gdkColor
);
1892 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1894 if (m_backgroundBrush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
)
1896 const wxBitmap
* stipple
= m_backgroundBrush
.GetStipple();
1897 if (stipple
->IsOk())
1899 if (stipple
->GetDepth() != 1)
1901 gdk_gc_set_fill(m_bgGC
, GDK_TILED
);
1902 gdk_gc_set_tile(m_bgGC
, stipple
->GetPixmap());
1906 gdk_gc_set_fill(m_bgGC
, GDK_STIPPLED
);
1907 gdk_gc_set_stipple(m_bgGC
, stipple
->GetPixmap());
1911 else if (m_backgroundBrush
.IsHatch())
1913 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1914 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
1918 void wxWindowDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1920 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1922 if (m_logicalFunction
== function
)
1925 // VZ: shouldn't this be a CHECK?
1932 case wxXOR
: mode
= GDK_XOR
; break;
1933 case wxINVERT
: mode
= GDK_INVERT
; break;
1934 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1935 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1936 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1937 case wxSET
: mode
= GDK_SET
; break;
1938 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1939 case wxAND
: mode
= GDK_AND
; break;
1940 case wxOR
: mode
= GDK_OR
; break;
1941 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1942 case wxNAND
: mode
= GDK_NAND
; break;
1943 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1944 case wxCOPY
: mode
= GDK_COPY
; break;
1945 case wxNO_OP
: mode
= GDK_NOOP
; break;
1946 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1947 case wxNOR
: mode
= GDK_NOR
; break;
1949 wxFAIL_MSG("unknown mode");
1953 m_logicalFunction
= function
;
1955 gdk_gc_set_function( m_penGC
, mode
);
1956 gdk_gc_set_function( m_brushGC
, mode
);
1958 // to stay compatible with wxMSW, we don't apply ROPs to the text
1959 // operations (i.e. DrawText/DrawRotatedText).
1960 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1961 gdk_gc_set_function( m_textGC
, mode
);
1964 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
1966 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1968 // don't set m_textForegroundColour to an invalid colour as we'd crash
1969 // later then (we use m_textForegroundColour.GetColor() without checking
1971 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
1974 m_textForegroundColour
= col
;
1978 m_textForegroundColour
.CalcPixel( m_cmap
);
1979 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1983 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
1985 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1988 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
1991 m_textBackgroundColour
= col
;
1995 m_textBackgroundColour
.CalcPixel( m_cmap
);
1996 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2000 void wxWindowDCImpl::SetBackgroundMode( int mode
)
2002 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2004 m_backgroundMode
= mode
;
2007 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2009 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
2012 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2014 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2016 if (!m_gdkwindow
) return;
2019 rect
.x
= XLOG2DEV(x
);
2020 rect
.y
= YLOG2DEV(y
);
2021 rect
.width
= XLOG2DEVREL(width
);
2022 rect
.height
= YLOG2DEVREL(height
);
2024 if (m_window
&& m_window
->m_wxwindow
&&
2025 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2027 rect
.x
-= rect
.width
;
2030 DoSetDeviceClippingRegion(wxRegion(rect
));
2033 void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion
®ion
)
2035 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2039 DestroyClippingRegion();
2043 if (!m_gdkwindow
) return;
2045 if (!m_currentClippingRegion
.IsNull())
2046 m_currentClippingRegion
.Intersect( region
);
2048 m_currentClippingRegion
.Union( region
);
2050 #if USE_PAINT_REGION
2051 if (!m_paintClippingRegion
.IsNull())
2052 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2055 wxCoord xx
, yy
, ww
, hh
;
2056 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2057 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2059 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
2060 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2061 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2062 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2063 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2066 void wxWindowDCImpl::DestroyClippingRegion()
2068 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2070 wxDCImpl::DestroyClippingRegion();
2072 m_currentClippingRegion
.Clear();
2074 #if USE_PAINT_REGION
2075 if (!m_paintClippingRegion
.IsEmpty())
2076 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2079 if (!m_gdkwindow
) return;
2081 GdkRegion
* gdkRegion
= NULL
;
2082 if (!m_currentClippingRegion
.IsEmpty())
2083 gdkRegion
= m_currentClippingRegion
.GetRegion();
2085 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2086 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2087 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2088 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2091 void wxWindowDCImpl::Destroy()
2093 if (m_penGC
) wxFreePoolGC( m_penGC
);
2095 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2097 if (m_textGC
) wxFreePoolGC( m_textGC
);
2099 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2103 void wxWindowDCImpl::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2105 m_deviceOriginX
= x
;
2106 m_deviceOriginY
= y
;
2108 ComputeScaleAndOrigin();
2111 void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2113 m_signX
= (xLeftRight
? 1 : -1);
2114 m_signY
= (yBottomUp
? -1 : 1);
2116 if (m_window
&& m_window
->m_wxwindow
&&
2117 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2120 ComputeScaleAndOrigin();
2123 void wxWindowDCImpl::ComputeScaleAndOrigin()
2125 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2127 wxDCImpl::ComputeScaleAndOrigin();
2129 // if scale has changed call SetPen to recalulate the line width
2130 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2132 // this is a bit artificial, but we need to force wxDC to think the pen
2140 // Resolution in pixels per logical inch
2141 wxSize
wxWindowDCImpl::GetPPI() const
2143 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2146 int wxWindowDCImpl::GetDepth() const
2148 return gdk_drawable_get_depth(m_gdkwindow
);
2151 //-----------------------------------------------------------------------------
2153 //-----------------------------------------------------------------------------
2155 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2157 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
2158 : wxWindowDCImpl( owner
)
2162 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2163 : wxWindowDCImpl( owner
, win
)
2165 wxCHECK_RET( win
, wxT("NULL window in wxClientDCImpl::wxClientDC") );
2167 #ifdef __WXUNIVERSAL__
2168 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2169 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2170 wxSize size
= win
->GetClientSize();
2171 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2176 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2178 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
2180 m_window
->GetClientSize( width
, height
);
2183 //-----------------------------------------------------------------------------
2185 //-----------------------------------------------------------------------------
2187 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2189 // Limit the paint region to the window size. Sometimes
2190 // the paint region is too big, and this risks X11 errors
2191 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2193 wxRect originalRect
= region
.GetBox();
2194 wxRect
rect(originalRect
);
2195 if (rect
.width
+ rect
.x
> sz
.x
)
2196 rect
.width
= sz
.x
- rect
.x
;
2197 if (rect
.height
+ rect
.y
> sz
.y
)
2198 rect
.height
= sz
.y
- rect
.y
;
2199 if (rect
!= originalRect
)
2201 region
= wxRegion(rect
);
2202 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2203 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2204 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2208 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
2209 : wxClientDCImpl( owner
)
2213 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2214 : wxClientDCImpl( owner
, win
)
2216 #if USE_PAINT_REGION
2217 if (!win
->m_clipPaintRegion
)
2220 wxSize sz
= win
->GetSize();
2221 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2222 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2224 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2227 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2228 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2230 if (sz
.x
<= 0 || sz
.y
<= 0)
2233 gdk_gc_set_clip_region( m_penGC
, region
);
2234 gdk_gc_set_clip_region( m_brushGC
, region
);
2235 gdk_gc_set_clip_region( m_textGC
, region
);
2236 gdk_gc_set_clip_region( m_bgGC
, region
);
2241 // ----------------------------------------------------------------------------
2243 // ----------------------------------------------------------------------------
2245 class wxDCModule
: public wxModule
2252 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2255 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2257 bool wxDCModule::OnInit()
2263 void wxDCModule::OnExit()
2267 for (int i
= wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
; i
--; )
2270 g_object_unref(hatches
[i
]);