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"
28 #include "wx/private/textmeasure.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 #define XLOG2DEV(x) LogicalToDeviceX(x)
35 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
36 #define YLOG2DEV(y) LogicalToDeviceY(y)
37 #define YLOG2DEVREL(y) LogicalToDeviceYRel(y)
39 #define USE_PAINT_REGION 1
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
52 static GdkPixmap
* hatches
[wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
+ 1];
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static const double RAD2DEG
= 180.0 / M_PI
;
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 static inline double dmax(double a
, double b
) { return a
> b ? a
: b
; }
65 static inline double dmin(double a
, double b
) { return a
< b ? a
: b
; }
67 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
69 static GdkPixmap
* GetHatch(int style
)
71 wxASSERT(style
>= wxBRUSHSTYLE_FIRST_HATCH
&& style
<= wxBRUSHSTYLE_LAST_HATCH
);
72 const int i
= style
- wxBRUSHSTYLE_FIRST_HATCH
;
73 if (hatches
[i
] == NULL
)
75 // This macro creates a bitmap from an XBM file included above. Notice
76 // the need for the cast because gdk_bitmap_create_from_data() doesn't
77 // accept unsigned data but the arrays in XBM need to be unsigned to
78 // avoid warnings (and even errors in C+0x mode) from g++.
79 #define CREATE_FROM_XBM_DATA(name) \
80 gdk_bitmap_create_from_data \
83 reinterpret_cast<gchar *>(name ## _bits), \
90 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
91 hatches
[i
] = CREATE_FROM_XBM_DATA(bdiag
);
93 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
94 hatches
[i
] = CREATE_FROM_XBM_DATA(cdiag
);
96 case wxBRUSHSTYLE_CROSS_HATCH
:
97 hatches
[i
] = CREATE_FROM_XBM_DATA(cross
);
99 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
100 hatches
[i
] = CREATE_FROM_XBM_DATA(fdiag
);
102 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
103 hatches
[i
] = CREATE_FROM_XBM_DATA(horiz
);
105 case wxBRUSHSTYLE_VERTICAL_HATCH
:
106 hatches
[i
] = CREATE_FROM_XBM_DATA(verti
);
110 #undef CREATE_FROM_XBM_DATA
115 //-----------------------------------------------------------------------------
116 // Implement Pool of Graphic contexts. Creating them takes too much time.
117 //-----------------------------------------------------------------------------
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") );
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 //-----------------------------------------------------------------------------
260 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
262 wxWindowDCImpl
::wxWindowDCImpl( wxDC
*owner
) :
271 m_isScreenDC
= false;
277 wxWindowDCImpl
::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
280 wxASSERT_MSG( window
, wxT("DC needs a window") );
288 m_isScreenDC
= false;
289 m_font
= window
->GetFont();
291 GtkWidget
*widget
= window
->m_wxwindow
;
292 m_gdkwindow
= window
->GTKGetDrawingWindow();
294 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
295 // code should still be able to create wxClientDCs for them
298 widget
= window
->m_widget
;
300 wxCHECK_RET(widget
, "DC needs a widget");
302 m_gdkwindow
= widget
->window
;
303 if (!gtk_widget_get_has_window(widget
))
304 SetDeviceLocalOrigin(widget
->allocation
.x
, widget
->allocation
.y
);
307 m_context
= window
->GTKGetPangoDefaultContext();
308 m_layout
= pango_layout_new( m_context
);
309 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
311 // Window not realized ?
314 // Don't report problems as per MSW.
320 m_cmap
= gtk_widget_get_colormap(widget
);
324 /* this must be done after SetUpDC, bacause SetUpDC calls the
325 repective SetBrush, SetPen, SetBackground etc functions
326 to set up the DC. SetBackground call m_owner->SetBackground
327 and this might not be desired as the standard dc background
328 is white whereas a window might assume gray to be the
329 standard (as e.g. wxStatusBar) */
333 if (m_window
&& m_window
->m_wxwindow
&&
334 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
339 // origin in the upper right corner
340 m_deviceOriginX
= m_window
->GetClientSize().x
;
344 wxWindowDCImpl
::~wxWindowDCImpl()
349 g_object_unref (m_layout
);
351 pango_font_description_free( m_fontdesc
);
354 void wxWindowDCImpl
::SetUpDC( bool isMemDC
)
358 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
362 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
364 if (GetSelectedBitmap().GetDepth() == 1)
366 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
367 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
368 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
369 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
378 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
379 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
380 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
381 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
383 #if GTK_CHECK_VERSION(2,12,0)
384 // gdk_screen_get_rgba_colormap was added in 2.8, but this code is for
385 // compositing which requires 2.12
386 else if (gtk_check_version(2,12,0) == NULL
&&
387 m_cmap
== gdk_screen_get_rgba_colormap(gdk_colormap_get_screen(m_cmap
)))
389 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR_ALPHA
);
390 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR_ALPHA
);
391 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR_ALPHA
);
392 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR_ALPHA
);
397 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
398 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
399 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
400 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
404 /* background colour */
405 m_backgroundBrush
= *wxWHITE_BRUSH
;
406 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
407 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
410 m_textForegroundColour
.CalcPixel( m_cmap
);
411 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
413 m_textBackgroundColour
.CalcPixel( m_cmap
);
414 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
416 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
418 gdk_gc_set_colormap( m_textGC
, m_cmap
);
421 m_pen
.GetColour().CalcPixel( m_cmap
);
422 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
423 gdk_gc_set_background( m_penGC
, bg_col
);
425 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
428 m_brush
.GetColour().CalcPixel( m_cmap
);
429 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
430 gdk_gc_set_background( m_brushGC
, bg_col
);
432 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
435 gdk_gc_set_background( m_bgGC
, bg_col
);
436 gdk_gc_set_foreground( m_bgGC
, bg_col
);
438 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
441 gdk_gc_set_function( m_textGC
, GDK_COPY
);
442 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
443 gdk_gc_set_function( m_penGC
, GDK_COPY
);
446 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
447 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
448 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
449 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
452 void wxWindowDCImpl
::DoGetSize( int* width
, int* height
) const
454 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
456 m_window
->GetSize(width
, height
);
459 bool wxWindowDCImpl
::DoFloodFill(wxCoord x
, wxCoord y
,
460 const wxColour
& col
, wxFloodFillStyle style
)
463 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
464 const wxColour
& col
, wxFloodFillStyle style
);
466 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
477 bool wxWindowDCImpl
::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
479 GdkImage
* image
= NULL
;
482 const int x
= LogicalToDeviceX(x1
);
483 const int y
= LogicalToDeviceY(y1
);
485 gdk_drawable_get_size(m_gdkwindow
, &rect
.width
, &rect
.height
);
486 if (rect
.Contains(x
, y
))
487 image
= gdk_drawable_get_image(m_gdkwindow
, x
, y
, 1, 1);
494 GdkColormap
* colormap
= gdk_image_get_colormap(image
);
495 const unsigned pixel
= gdk_image_get_pixel(image
, 0, 0);
496 if (colormap
== NULL
)
497 *col
= pixel ? m_textForegroundColour
: m_textBackgroundColour
;
501 gdk_colormap_query_color(colormap
, pixel
, &c
);
502 col
->Set(c
.red
>> 8, c
.green
>> 8, c
.blue
>> 8);
504 g_object_unref(image
);
508 void wxWindowDCImpl
::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
510 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
512 if ( m_pen
.IsNonTransparent() )
515 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
517 CalcBoundingBox(x1
, y1
);
518 CalcBoundingBox(x2
, y2
);
522 void wxWindowDCImpl
::DoCrossHair( wxCoord x
, wxCoord y
)
524 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
526 if ( m_pen
.IsNonTransparent() )
530 GetOwner()->GetSize( &w
, &h
);
531 wxCoord xx
= XLOG2DEV(x
);
532 wxCoord yy
= YLOG2DEV(y
);
535 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
536 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
541 void wxWindowDCImpl
::DrawingSetup(GdkGC
*& gc
, bool& originChanged
)
544 GdkPixmap
* pixmap
= NULL
;
545 const int style
= m_brush
.GetStyle();
547 if (style
== wxBRUSHSTYLE_STIPPLE
|| style
== wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
)
549 const wxBitmap
* stipple
= m_brush
.GetStipple();
552 if (style
== wxBRUSHSTYLE_STIPPLE
)
553 pixmap
= stipple
->GetPixmap();
554 else if (stipple
->GetMask())
556 pixmap
= stipple
->GetPixmap();
561 else if (m_brush
.IsHatch())
563 pixmap
= GetHatch(style
);
571 gdk_drawable_get_size(pixmap
, &w
, &h
);
572 origin_x
= m_deviceOriginX
% w
;
573 origin_y
= m_deviceOriginY
% h
;
576 originChanged
= origin_x
|| origin_y
;
578 gdk_gc_set_ts_origin(gc
, origin_x
, origin_y
);
581 void wxWindowDCImpl
::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
582 wxCoord xc
, wxCoord yc
)
584 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
586 wxCoord xx1
= XLOG2DEV(x1
);
587 wxCoord yy1
= YLOG2DEV(y1
);
588 wxCoord xx2
= XLOG2DEV(x2
);
589 wxCoord yy2
= YLOG2DEV(y2
);
590 wxCoord xxc
= XLOG2DEV(xc
);
591 wxCoord yyc
= YLOG2DEV(yc
);
592 double dx
= xx1
- xxc
;
593 double dy
= yy1
- yyc
;
594 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
595 wxCoord r
= (wxCoord
)radius
;
596 double radius1
, radius2
;
598 if (xx1
== xx2
&& yy1
== yy2
)
603 else if ( wxIsNullDouble(radius
) )
610 radius1
= (xx1
- xxc
== 0) ?
611 (yy1
- yyc
< 0) ?
90.0 : -90.0 :
612 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
613 radius2
= (xx2
- xxc
== 0) ?
614 (yy2
- yyc
< 0) ?
90.0 : -90.0 :
615 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
617 wxCoord alpha1
= wxCoord(radius1
* 64.0);
618 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
619 while (alpha2
<= 0) alpha2
+= 360*64;
620 while (alpha1
> 360*64) alpha1
-= 360*64;
624 if ( m_brush
.IsNonTransparent() )
628 DrawingSetup(gc
, originChanged
);
630 gdk_draw_arc(m_gdkwindow
, gc
, true, xxc
-r
, yyc
-r
, 2*r
, 2*r
, alpha1
, alpha2
);
633 gdk_gc_set_ts_origin(gc
, 0, 0);
636 if ( m_pen
.IsNonTransparent() )
638 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
640 if ( m_brush
.IsNonTransparent() && (alpha2
- alpha1
!= 360*64) )
642 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
643 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
648 CalcBoundingBox (x1
, y1
);
649 CalcBoundingBox (x2
, y2
);
652 void wxWindowDCImpl
::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
654 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
656 wxCoord xx
= XLOG2DEV(x
);
657 wxCoord yy
= YLOG2DEV(y
);
658 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
659 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
661 // CMB: handle -ve width and/or height
662 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
663 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
667 wxCoord start
= wxCoord(sa
* 64.0);
668 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
670 if ( m_brush
.IsNonTransparent() )
674 DrawingSetup(gc
, originChanged
);
676 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, start
, end
);
679 gdk_gc_set_ts_origin(gc
, 0, 0);
682 if ( m_pen
.IsNonTransparent() )
683 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
686 CalcBoundingBox (x
, y
);
687 CalcBoundingBox (x
+ width
, y
+ height
);
690 void wxWindowDCImpl
::DoDrawPoint( wxCoord x
, wxCoord y
)
692 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
694 if ( m_pen
.IsNonTransparent() && m_gdkwindow
)
695 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
697 CalcBoundingBox (x
, y
);
700 void wxWindowDCImpl
::DoDrawLines( int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
702 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
706 if ( m_pen
.IsTransparent() )
709 //Check, if scaling is necessary
711 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
713 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
714 const GdkPoint
* gpts
= reinterpret_cast<const GdkPoint
*>(points
);
715 GdkPoint
* gpts_alloc
= NULL
;
719 gpts_alloc
= new GdkPoint
[n
];
723 for (int i
= 0; i
< n
; i
++)
727 gpts_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
728 gpts_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
730 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
734 gdk_draw_lines( m_gdkwindow
, m_penGC
, gpts
, n
);
739 void wxWindowDCImpl
::DoDrawPolygon( int n
, const wxPoint points
[],
740 wxCoord xoffset
, wxCoord yoffset
,
741 wxPolygonFillMode
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 const GdkPoint
* gdkpoints
= reinterpret_cast<const GdkPoint
*>(points
);
753 GdkPoint
* gdkpoints_alloc
= NULL
;
757 gdkpoints_alloc
= new GdkPoint
[n
];
758 gdkpoints
= gdkpoints_alloc
;
762 for (i
= 0 ; i
< n
; i
++)
766 gdkpoints_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
767 gdkpoints_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
769 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
774 if ( m_brush
.IsNonTransparent() )
778 DrawingSetup(gc
, originChanged
);
780 gdk_draw_polygon(m_gdkwindow
, gc
, true, gdkpoints
, n
);
783 gdk_gc_set_ts_origin(gc
, 0, 0);
786 if ( m_pen
.IsNonTransparent() )
789 for (i = 0 ; i < n ; i++)
791 gdk_draw_line( m_gdkwindow, m_penGC,
794 gdkpoints[(i+1)%n].x,
795 gdkpoints[(i+1)%n].y);
798 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, gdkpoints
, n
);
803 delete[] gdkpoints_alloc
;
806 void wxWindowDCImpl
::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
808 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
810 wxCoord xx
= XLOG2DEV(x
);
811 wxCoord yy
= YLOG2DEV(y
);
812 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
813 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
815 // CMB: draw nothing if transformed w or h is 0
816 if (ww
== 0 || hh
== 0) return;
818 // CMB: handle -ve width and/or height
819 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
820 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
824 if ( m_brush
.IsNonTransparent() )
828 DrawingSetup(gc
, originChanged
);
830 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
);
833 gdk_gc_set_ts_origin(gc
, 0, 0);
836 if ( m_pen
.IsNonTransparent() )
838 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
839 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxPENSTYLE_SOLID
))
841 // Use 2 1-line rects instead
842 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
847 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
848 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
852 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
853 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
857 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
861 // Just use X11 for other cases
862 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
867 CalcBoundingBox( x
, y
);
868 CalcBoundingBox( x
+ width
, y
+ height
);
871 void wxWindowDCImpl
::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
873 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
875 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
877 wxCoord xx
= XLOG2DEV(x
);
878 wxCoord yy
= YLOG2DEV(y
);
879 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
880 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
881 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
883 // CMB: handle -ve width and/or height
884 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
885 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
887 // CMB: if radius is zero use DrawRectangle() instead to avoid
888 // X drawing errors with small radii
891 DoDrawRectangle( x
, y
, width
, height
);
895 // CMB: draw nothing if transformed w or h is 0
896 if (ww
== 0 || hh
== 0) return;
898 // CMB: adjust size if outline is drawn otherwise the result is
899 // 1 pixel too wide and high
900 if ( m_pen
.IsNonTransparent() )
908 // CMB: ensure dd is not larger than rectangle otherwise we
909 // get an hour glass shape
911 if (dd
> ww
) dd
= ww
;
912 if (dd
> hh
) dd
= hh
;
915 if ( m_brush
.IsNonTransparent() )
919 DrawingSetup(gc
, originChanged
);
921 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
+rr
, yy
, ww
-dd
+1, hh
);
922 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
+rr
, ww
, hh
-dd
+1);
923 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, dd
, dd
, 90*64, 90*64);
924 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64);
925 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64);
926 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64);
929 gdk_gc_set_ts_origin(gc
, 0, 0);
932 if ( m_pen
.IsNonTransparent() )
934 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
935 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
936 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
937 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
938 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
939 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
940 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
941 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
945 // this ignores the radius
946 CalcBoundingBox( x
, y
);
947 CalcBoundingBox( x
+ width
, y
+ height
);
950 void wxWindowDCImpl
::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
952 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
954 wxCoord xx
= XLOG2DEV(x
);
955 wxCoord yy
= YLOG2DEV(y
);
956 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
957 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
959 // CMB: handle -ve width and/or height
960 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
961 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
965 if ( m_brush
.IsNonTransparent() )
969 DrawingSetup(gc
, originChanged
);
971 // If the pen is transparent pen we increase the size
972 // for better compatibility with other platforms.
973 if (m_pen
.IsTransparent())
979 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, 0, 360*64);
982 gdk_gc_set_ts_origin(gc
, 0, 0);
985 if ( m_pen
.IsNonTransparent() )
986 gdk_draw_arc( m_gdkwindow
, m_penGC
, false, xx
, yy
, ww
, hh
, 0, 360*64 );
989 CalcBoundingBox( x
, y
);
990 CalcBoundingBox( x
+ width
, y
+ height
);
993 void wxWindowDCImpl
::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
995 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
996 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
999 // scale a pixbuf, return new pixbuf, unref old one
1001 Scale(GdkPixbuf
* pixbuf
, int dst_w
, int dst_h
, double sx
, double sy
)
1003 GdkPixbuf
* pixbuf_scaled
= gdk_pixbuf_new(
1004 GDK_COLORSPACE_RGB
, gdk_pixbuf_get_has_alpha(pixbuf
), 8, dst_w
, dst_h
);
1005 gdk_pixbuf_scale(pixbuf
, pixbuf_scaled
,
1006 0, 0, dst_w
, dst_h
, 0, 0, sx
, sy
, GDK_INTERP_NEAREST
);
1007 g_object_unref(pixbuf
);
1008 return pixbuf_scaled
;
1011 // scale part of a pixmap using pixbuf scaling, return pixbuf
1013 Scale(GdkPixmap
* pixmap
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1015 GdkPixbuf
* pixbuf
= gdk_pixbuf_get_from_drawable(
1016 NULL
, pixmap
, NULL
, x
, y
, 0, 0, w
, h
);
1017 return Scale(pixbuf
, dst_w
, dst_h
, sx
, sy
);
1020 // scale part of a mask pixmap, return new mask, unref old one
1022 ScaleMask(GdkPixmap
* mask
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1024 GdkPixbuf
* pixbuf
= Scale(mask
, x
, y
, w
, h
, dst_w
, dst_h
, sx
, sy
);
1026 // convert black and white pixbuf back to a mono pixmap
1027 const unsigned out_rowstride
= (dst_w
+ 7) / 8;
1028 const size_t data_size
= out_rowstride
* size_t(dst_h
);
1029 char* data
= new char[data_size
];
1031 const guchar
* row
= gdk_pixbuf_get_pixels(pixbuf
);
1032 const int rowstride
= gdk_pixbuf_get_rowstride(pixbuf
);
1033 memset(data
, 0, data_size
);
1034 for (int j
= 0; j
< dst_h
; j
++, row
+= rowstride
, out
+= out_rowstride
)
1036 const guchar
* in
= row
;
1037 for (int i
= 0; i
< dst_w
; i
++, in
+= 3)
1039 out
[i
>> 3] |= 1 << (i
& 7);
1041 g_object_unref(pixbuf
);
1042 GdkPixmap
* pixmap
= gdk_bitmap_create_from_data(mask
, data
, dst_w
, dst_h
);
1044 g_object_unref(mask
);
1048 // Make a new mask from part of a mask and a clip region.
1049 // Return new mask, unref old one.
1051 ClipMask(GdkPixmap
* mask
, GdkRegion
* clipRegion
, int x
, int y
, int dst_x
, int dst_y
, int w
, int h
)
1053 GdkGCValues gcValues
;
1054 gcValues
.foreground
.pixel
= 0;
1055 GdkGC
* gc
= gdk_gc_new_with_values(mask
, &gcValues
, GDK_GC_FOREGROUND
);
1056 GdkPixmap
* pixmap
= gdk_pixmap_new(mask
, w
, h
, 1);
1057 // clear new mask, so clipped areas will be masked
1058 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1059 gdk_gc_set_clip_region(gc
, clipRegion
);
1060 gdk_gc_set_clip_origin(gc
, -dst_x
, -dst_y
);
1061 // draw old mask onto new one, with clip
1062 gdk_draw_drawable(pixmap
, gc
, mask
, x
, y
, 0, 0, w
, h
);
1064 g_object_unref(mask
);
1068 // make a color pixmap from part of a mono one, using text fg/bg colors
1070 wxWindowDCImpl
::MonoToColor(GdkPixmap
* monoPixmap
, int x
, int y
, int w
, int h
) const
1072 GdkPixmap
* pixmap
= gdk_pixmap_new(m_gdkwindow
, w
, h
, -1);
1073 GdkGCValues gcValues
;
1074 gcValues
.foreground
.pixel
= m_textForegroundColour
.GetColor()->pixel
;
1075 gcValues
.background
.pixel
= m_textBackgroundColour
.GetColor()->pixel
;
1076 gcValues
.stipple
= monoPixmap
;
1077 gcValues
.fill
= GDK_OPAQUE_STIPPLED
;
1078 gcValues
.ts_x_origin
= -x
;
1079 gcValues
.ts_y_origin
= -y
;
1080 GdkGC
* gc
= gdk_gc_new_with_values(pixmap
, &gcValues
, GdkGCValuesMask(
1081 GDK_GC_FOREGROUND
| GDK_GC_BACKGROUND
| GDK_GC_STIPPLE
| GDK_GC_FILL
|
1082 GDK_GC_TS_X_ORIGIN
| GDK_GC_TS_Y_ORIGIN
));
1083 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1088 void wxWindowDCImpl
::DoDrawBitmap( const wxBitmap
&bitmap
,
1089 wxCoord x
, wxCoord y
,
1092 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1093 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1095 if (!m_gdkwindow
) return;
1097 const int w
= bitmap
.GetWidth();
1098 const int h
= bitmap
.GetHeight();
1100 // notice that as the bitmap is not drawn upside down (or right to left)
1101 // even if the corresponding axis direction is inversed, we need to take it
1102 // into account when calculating its bounding box
1103 CalcBoundingBox(x
, y
);
1104 CalcBoundingBox(x
+ m_signX
*w
, y
+ m_signY
*h
);
1107 int xx
= LogicalToDeviceX(x
);
1108 const int yy
= LogicalToDeviceY(y
);
1109 const int ww
= LogicalToDeviceXRel(w
);
1110 const int hh
= LogicalToDeviceYRel(h
);
1112 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1115 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1116 // determine clip region overlap
1117 int overlap
= wxInRegion
;
1120 overlap
= m_currentClippingRegion
.Contains(xx
, yy
, ww
, hh
);
1121 if (overlap
== wxOutRegion
)
1125 const bool isScaled
= ww
!= w
|| hh
!= h
;
1126 const bool hasAlpha
= bitmap
.HasAlpha();
1127 GdkGC
* const use_gc
= m_penGC
;
1129 GdkPixmap
* mask
= NULL
;
1130 // mask does not work when drawing a pixbuf with alpha
1131 if (useMask
&& !hasAlpha
)
1133 wxMask
* m
= bitmap
.GetMask();
1135 mask
= m
->GetBitmap();
1141 mask
= ScaleMask(mask
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1142 if (overlap
== wxPartRegion
)
1144 // need a new mask that also masks the clipped area,
1145 // because gc can't have both a mask and a clip region
1146 mask
= ClipMask(mask
, clipRegion
, 0, 0, xx
, yy
, ww
, hh
);
1148 gdk_gc_set_clip_mask(use_gc
, mask
);
1149 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1152 // determine whether to use pixmap or pixbuf
1153 GdkPixmap
* pixmap
= NULL
;
1154 GdkPixbuf
* pixbuf
= NULL
;
1155 if (bitmap
.HasPixmap())
1156 pixmap
= bitmap
.GetPixmap();
1157 if (pixmap
&& gdk_drawable_get_depth(pixmap
) == 1)
1159 // convert mono pixmap to color using text fg/bg colors
1160 pixmap
= MonoToColor(pixmap
, 0, 0, w
, h
);
1162 else if (hasAlpha
|| pixmap
== NULL
)
1165 pixbuf
= bitmap
.GetPixbuf();
1166 g_object_ref(pixbuf
);
1170 g_object_ref(pixmap
);
1176 pixbuf
= Scale(pixbuf
, ww
, hh
, m_scaleX
, m_scaleY
);
1178 pixbuf
= Scale(pixmap
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1183 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1184 0, 0, xx
, yy
, ww
, hh
, GDK_RGB_DITHER_NORMAL
, 0, 0);
1185 g_object_unref(pixbuf
);
1189 gdk_draw_drawable(m_gdkwindow
, use_gc
, pixmap
, 0, 0, xx
, yy
, ww
, hh
);
1193 g_object_unref(pixmap
);
1196 g_object_unref(mask
);
1197 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1201 bool wxWindowDCImpl
::DoBlit( wxCoord xdest
, wxCoord ydest
,
1202 wxCoord width
, wxCoord height
,
1204 wxCoord xsrc
, wxCoord ysrc
,
1205 wxRasterOperationMode logical_func
,
1207 wxCoord xsrcMask
, wxCoord ysrcMask
)
1209 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1210 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1212 if (!m_gdkwindow
) return false;
1214 GdkDrawable
* srcDrawable
= NULL
;
1215 GdkPixmap
* mask
= NULL
;
1216 wxMemoryDC
* memDC
= wxDynamicCast(source
, wxMemoryDC
);
1219 const wxBitmap
& bitmap
= memDC
->GetSelectedBitmap();
1222 srcDrawable
= bitmap
.GetPixmap();
1225 wxMask
* m
= bitmap
.GetMask();
1227 mask
= m
->GetBitmap();
1232 wxDCImpl
* impl
= source
->GetImpl();
1233 wxWindowDCImpl
* gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1235 srcDrawable
= gtk_impl
->GetGDKWindow();
1236 if (srcDrawable
== NULL
)
1240 CalcBoundingBox(xdest
, ydest
);
1241 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1243 // source device coords
1244 int src_x
= source
->LogicalToDeviceX(xsrc
);
1245 int src_y
= source
->LogicalToDeviceY(ysrc
);
1246 int src_w
= source
->LogicalToDeviceXRel(width
);
1247 int src_h
= source
->LogicalToDeviceYRel(height
);
1249 // Clip source rect to source dc.
1250 // Only necessary when scaling, to avoid GDK errors when
1251 // converting to pixbuf, but no harm in always doing it.
1252 // If source rect changes, it also changes the dest rect.
1254 gdk_drawable_get_size(srcDrawable
, &clip
.width
, &clip
.height
);
1255 clip
.Intersect(wxRect(src_x
, src_y
, src_w
, src_h
));
1256 if (src_w
!= clip
.width
|| src_h
!= clip
.height
)
1258 if (clip
.width
== 0)
1262 src_h
= clip
.height
;
1263 width
= source
->DeviceToLogicalXRel(src_w
);
1264 height
= source
->DeviceToLogicalYRel(src_h
);
1265 if (src_x
!= clip
.x
|| src_y
!= clip
.y
)
1267 xdest
+= source
->DeviceToLogicalXRel(clip
.x
- src_x
);
1268 ydest
+= source
->DeviceToLogicalYRel(clip
.y
- src_y
);
1274 // destination device coords
1275 const int dst_x
= LogicalToDeviceX(xdest
);
1276 const int dst_y
= LogicalToDeviceY(ydest
);
1277 const int dst_w
= LogicalToDeviceXRel(width
);
1278 const int dst_h
= LogicalToDeviceYRel(height
);
1280 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1281 // determine dest clip region overlap
1282 int overlap
= wxInRegion
;
1285 overlap
= m_currentClippingRegion
.Contains(dst_x
, dst_y
, dst_w
, dst_h
);
1286 if (overlap
== wxOutRegion
)
1290 const bool isScaled
= src_w
!= dst_w
|| src_h
!= dst_h
;
1295 // get source to dest scale
1296 double usx
, usy
, lsx
, lsy
;
1297 source
->GetUserScale(&usx
, &usy
);
1298 source
->GetLogicalScale(&lsx
, &lsy
);
1299 scale_x
= m_scaleX
/ (usx
* lsx
);
1300 scale_y
= m_scaleY
/ (usy
* lsy
);
1303 GdkGC
* const use_gc
= m_penGC
;
1308 int srcMask_x
= src_x
;
1309 int srcMask_y
= src_y
;
1310 if (xsrcMask
!= -1 || ysrcMask
!= -1)
1312 srcMask_x
= source
->LogicalToDeviceX(xsrcMask
);
1313 srcMask_y
= source
->LogicalToDeviceY(ysrcMask
);
1317 mask
= ScaleMask(mask
, srcMask_x
, srcMask_y
,
1318 src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1322 if (overlap
== wxPartRegion
)
1324 // need a new mask that also masks the clipped area,
1325 // because gc can't have both a mask and a clip region
1326 mask
= ClipMask(mask
, clipRegion
,
1327 srcMask_x
, srcMask_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1331 gdk_gc_set_clip_mask(use_gc
, mask
);
1332 gdk_gc_set_clip_origin(use_gc
, dst_x
- srcMask_x
, dst_y
- srcMask_y
);
1335 GdkPixmap
* pixmap
= NULL
;
1336 if (gdk_drawable_get_depth(srcDrawable
) == 1)
1338 // Convert mono pixmap to color using text fg/bg colors.
1339 // Scaling/drawing is simpler if this is done first.
1340 pixmap
= MonoToColor(srcDrawable
, src_x
, src_y
, src_w
, src_h
);
1341 srcDrawable
= pixmap
;
1346 const wxRasterOperationMode logical_func_save
= m_logicalFunction
;
1347 SetLogicalFunction(logical_func
);
1349 gdk_gc_set_subwindow(use_gc
, GDK_INCLUDE_INFERIORS
);
1353 GdkPixbuf
* pixbuf
= Scale(srcDrawable
,
1354 src_x
, src_y
, src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1355 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1356 0, 0, dst_x
, dst_y
, dst_w
, dst_h
, GDK_RGB_DITHER_NONE
, 0, 0);
1357 g_object_unref(pixbuf
);
1361 gdk_draw_drawable(m_gdkwindow
, use_gc
, srcDrawable
,
1362 src_x
, src_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1365 SetLogicalFunction(logical_func_save
);
1367 gdk_gc_set_subwindow(use_gc
, GDK_CLIP_BY_CHILDREN
);
1370 g_object_unref(pixmap
);
1373 g_object_unref(mask
);
1374 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1379 void wxWindowDCImpl
::DoDrawText(const wxString
& text
,
1383 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1385 if (!m_gdkwindow
) return;
1387 if (text
.empty()) return;
1389 wxCoord x
= XLOG2DEV(xLogical
),
1390 y
= YLOG2DEV(yLogical
);
1392 wxCHECK_RET( m_context
, wxT("no Pango context") );
1393 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1394 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1396 gdk_pango_context_set_colormap( m_context
, m_cmap
); // not needed in gtk+ >= 2.6
1398 wxCharBuffer data
= wxGTK_CONV(text
);
1402 pango_layout_set_text(m_layout
, data
, data
.length());
1403 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1406 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1409 // If there is a user or actually any scale applied to
1410 // the device context, scale the font.
1412 // scale font description
1413 oldSize
= pango_font_description_get_size(m_fontdesc
);
1414 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1416 // actually apply scaled font
1417 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1421 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1425 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1428 const GdkColor
* bg_col
= NULL
;
1429 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1430 bg_col
= m_textBackgroundColour
.GetColor();
1432 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x_rtl
, y
, m_layout
, NULL
, bg_col
);
1436 // reset unscaled size
1437 pango_font_description_set_size( m_fontdesc
, oldSize
);
1439 // actually apply unscaled font
1440 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1444 // undo underline attributes setting:
1445 pango_layout_set_attributes(m_layout
, NULL
);
1448 CalcBoundingBox(xLogical
+ int(w
/ m_scaleX
), yLogical
+ int(h
/ m_scaleY
));
1449 CalcBoundingBox(xLogical
, yLogical
);
1452 // TODO: When GTK2.6 is required, merge DoDrawText and DoDrawRotatedText to
1453 // avoid code duplication
1454 void wxWindowDCImpl
::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1456 if (!m_gdkwindow
|| text
.empty())
1459 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1464 pango_layout_set_text(m_layout
, wxGTK_CONV(text
), -1);
1465 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1467 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1470 //TODO: when Pango >= 1.6 is required, use pango_matrix_scale()
1471 // If there is a user or actually any scale applied to
1472 // the device context, scale the font.
1474 // scale font description
1475 oldSize
= pango_font_description_get_size(m_fontdesc
);
1476 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1478 // actually apply scaled font
1479 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1483 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1485 const GdkColor
* bg_col
= NULL
;
1486 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1487 bg_col
= m_textBackgroundColour
.GetColor();
1490 PangoMatrix matrix
= PANGO_MATRIX_INIT
;
1491 pango_matrix_rotate (&matrix
, angle
);
1492 pango_context_set_matrix (m_context
, &matrix
);
1493 pango_layout_context_changed (m_layout
);
1495 // To be compatible with MSW, the rotation axis must be in the old
1497 // Calculate the vertices of the rotated rectangle containing the text,
1498 // relative to the old top-left vertex.
1499 // We could use the matrix for this, but it's simpler with trignonometry.
1500 double rad
= DegToRad(angle
);
1501 // the rectangle vertices are counted clockwise with the first one
1503 double x2
= w
* cos(rad
);
1504 double y2
= -w
* sin(rad
); // y axis points to the bottom, hence minus
1505 double x4
= h
* sin(rad
);
1506 double y4
= h
* cos(rad
);
1507 double x3
= x4
+ x2
;
1508 double y3
= y4
+ y2
;
1509 // Then we calculate max and min of the rotated rectangle.
1510 wxCoord maxX
= (wxCoord
)(dmax(dmax(0, x2
), dmax(x3
, x4
)) + 0.5),
1511 maxY
= (wxCoord
)(dmax(dmax(0, y2
), dmax(y3
, y4
)) + 0.5),
1512 minX
= (wxCoord
)(dmin(dmin(0, x2
), dmin(x3
, x4
)) - 0.5),
1513 minY
= (wxCoord
)(dmin(dmin(0, y2
), dmin(y3
, y4
)) - 0.5);
1515 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x
+minX
, y
+minY
,
1516 m_layout
, NULL
, bg_col
);
1519 pango_layout_set_attributes(m_layout
, NULL
);
1521 // clean up the transformation matrix
1522 pango_context_set_matrix(m_context
, NULL
);
1526 // reset unscaled size
1527 pango_font_description_set_size( m_fontdesc
, oldSize
);
1529 // actually apply unscaled font
1530 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1533 CalcBoundingBox(x
+minX
, y
+minY
);
1534 CalcBoundingBox(x
+maxX
, y
+maxY
);
1537 void wxWindowDCImpl
::DoGetTextExtent(const wxString
&string
,
1538 wxCoord
*width
, wxCoord
*height
,
1539 wxCoord
*descent
, wxCoord
*externalLeading
,
1540 const wxFont
*theFont
) const
1542 // ensure we work with a valid font
1543 const wxFont
*fontToUse
;
1544 if ( !theFont
|| !theFont
->IsOk() )
1545 fontToUse
= &m_font
;
1547 fontToUse
= theFont
;
1549 wxCHECK_RET( fontToUse
->IsOk(), wxT("invalid font") );
1551 wxTextMeasure
txm(GetOwner(), fontToUse
);
1552 txm
.GetTextExtent(string
, width
, height
, descent
, externalLeading
);
1556 bool wxWindowDCImpl
::DoGetPartialTextExtents(const wxString
& text
,
1557 wxArrayInt
& widths
) const
1559 wxCHECK_MSG( m_font
.IsOk(), false, wxT("Invalid font") );
1561 wxTextMeasure
txm(GetOwner(), &m_font
);
1562 return txm
.GetPartialTextExtents(text
, widths
, m_scaleX
);
1566 wxCoord wxWindowDCImpl
::GetCharWidth() const
1568 pango_layout_set_text( m_layout
, "H", 1 );
1570 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1574 wxCoord wxWindowDCImpl
::GetCharHeight() const
1576 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1577 wxCHECK_MSG( metrics
, -1, wxT("failed to get pango font metrics") );
1579 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1580 pango_font_metrics_get_ascent (metrics
));
1581 pango_font_metrics_unref (metrics
);
1585 void wxWindowDCImpl
::Clear()
1587 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1589 if (!m_gdkwindow
) return;
1592 DoGetSize( &width
, &height
);
1593 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1596 void wxWindowDCImpl
::SetFont( const wxFont
&font
)
1603 pango_font_description_free( m_fontdesc
);
1605 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1610 PangoContext
*oldContext
= m_context
;
1612 m_context
= m_window
->GTKGetPangoDefaultContext();
1614 // If we switch back/forth between different contexts
1615 // we also have to create a new layout. I think so,
1616 // at least, and it doesn't hurt to do it.
1617 if (oldContext
!= m_context
)
1620 g_object_unref (m_layout
);
1622 m_layout
= pango_layout_new( m_context
);
1626 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1630 void wxWindowDCImpl
::SetPen( const wxPen
&pen
)
1632 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1634 if (m_pen
== pen
) return;
1638 if (!m_pen
.IsOk()) return;
1640 if (!m_gdkwindow
) return;
1642 gint width
= m_pen
.GetWidth();
1645 // CMB: if width is non-zero scale it with the dc
1650 // X doesn't allow different width in x and y and so we take
1653 ( fabs((double) XLOG2DEVREL(width
)) +
1654 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1658 // width can't be 0 or an internal GTK error occurs inside
1659 // gdk_gc_set_dashes() below
1664 static const wxGTKDash dotted
[] = {1, 1};
1665 static const wxGTKDash short_dashed
[] = {2, 2};
1666 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1667 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1669 // We express dash pattern in pen width unit, so we are
1670 // independent of zoom factor and so on...
1672 const wxGTKDash
*req_dash
;
1674 GdkLineStyle lineStyle
= GDK_LINE_ON_OFF_DASH
;
1675 switch (m_pen
.GetStyle())
1677 case wxPENSTYLE_USER_DASH
:
1678 req_nb_dash
= m_pen
.GetDashCount();
1679 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1681 case wxPENSTYLE_DOT
:
1685 case wxPENSTYLE_LONG_DASH
:
1687 req_dash
= wxCoord_dashed
;
1689 case wxPENSTYLE_SHORT_DASH
:
1691 req_dash
= short_dashed
;
1693 case wxPENSTYLE_DOT_DASH
:
1695 req_dash
= dotted_dashed
;
1698 case wxPENSTYLE_TRANSPARENT
:
1699 case wxPENSTYLE_STIPPLE_MASK_OPAQUE
:
1700 case wxPENSTYLE_STIPPLE
:
1701 case wxPENSTYLE_SOLID
:
1703 lineStyle
= GDK_LINE_SOLID
;
1709 if (req_dash
&& req_nb_dash
)
1711 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1714 for (int i
= 0; i
< req_nb_dash
; i
++)
1715 real_req_dash
[i
] = req_dash
[i
] * width
;
1716 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1717 delete[] real_req_dash
;
1721 // No Memory. We use non-scaled dash pattern...
1722 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1726 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1727 switch (m_pen
.GetCap())
1729 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1730 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1736 capStyle
= GDK_CAP_NOT_LAST
;
1741 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1742 switch (m_pen
.GetJoin())
1744 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1745 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1747 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1750 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1752 m_pen
.GetColour().CalcPixel( m_cmap
);
1753 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1756 void wxWindowDCImpl
::SetBrush( const wxBrush
&brush
)
1758 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1760 if (m_brush
== brush
) return;
1764 if (!m_brush
.IsOk()) return;
1766 if (!m_gdkwindow
) return;
1768 m_brush
.GetColour().CalcPixel( m_cmap
);
1769 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1771 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1773 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1775 if (m_brush
.GetStipple()->GetDepth() != 1)
1777 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1778 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1782 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1783 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1787 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1789 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1790 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1793 if (m_brush
.IsHatch())
1795 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1796 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
1800 void wxWindowDCImpl
::SetBackground( const wxBrush
&brush
)
1802 /* CMB 21/7/98: Added SetBackground. Sets background brush
1803 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1805 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1807 if (m_backgroundBrush
== brush
) return;
1809 m_backgroundBrush
= brush
;
1811 if (!m_backgroundBrush
.IsOk()) return;
1813 if (!m_gdkwindow
) return;
1815 wxColor color
= m_backgroundBrush
.GetColour();
1816 color
.CalcPixel(m_cmap
);
1817 const GdkColor
* gdkColor
= color
.GetColor();
1818 gdk_gc_set_background(m_brushGC
, gdkColor
);
1819 gdk_gc_set_background(m_penGC
, gdkColor
);
1820 gdk_gc_set_background(m_bgGC
, gdkColor
);
1821 gdk_gc_set_foreground(m_bgGC
, gdkColor
);
1824 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1826 if (m_backgroundBrush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
)
1828 const wxBitmap
* stipple
= m_backgroundBrush
.GetStipple();
1829 if (stipple
->IsOk())
1831 if (stipple
->GetDepth() != 1)
1833 gdk_gc_set_fill(m_bgGC
, GDK_TILED
);
1834 gdk_gc_set_tile(m_bgGC
, stipple
->GetPixmap());
1838 gdk_gc_set_fill(m_bgGC
, GDK_STIPPLED
);
1839 gdk_gc_set_stipple(m_bgGC
, stipple
->GetPixmap());
1843 else if (m_backgroundBrush
.IsHatch())
1845 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1846 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
1850 void wxWindowDCImpl
::SetLogicalFunction( wxRasterOperationMode function
)
1852 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1854 if (m_logicalFunction
== function
)
1857 // VZ: shouldn't this be a CHECK?
1864 case wxXOR
: mode
= GDK_XOR
; break;
1865 case wxINVERT
: mode
= GDK_INVERT
; break;
1866 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1867 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1868 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1869 case wxSET
: mode
= GDK_SET
; break;
1870 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1871 case wxAND
: mode
= GDK_AND
; break;
1872 case wxOR
: mode
= GDK_OR
; break;
1873 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1874 case wxNAND
: mode
= GDK_NAND
; break;
1875 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1876 case wxCOPY
: mode
= GDK_COPY
; break;
1877 case wxNO_OP
: mode
= GDK_NOOP
; break;
1878 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1879 case wxNOR
: mode
= GDK_NOR
; break;
1881 wxFAIL_MSG("unknown mode");
1885 m_logicalFunction
= function
;
1887 gdk_gc_set_function( m_penGC
, mode
);
1888 gdk_gc_set_function( m_brushGC
, mode
);
1890 // to stay compatible with wxMSW, we don't apply ROPs to the text
1891 // operations (i.e. DrawText/DrawRotatedText).
1892 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1893 gdk_gc_set_function( m_textGC
, mode
);
1896 void wxWindowDCImpl
::SetTextForeground( const wxColour
&col
)
1898 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1900 // don't set m_textForegroundColour to an invalid colour as we'd crash
1901 // later then (we use m_textForegroundColour.GetColor() without checking
1903 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
1906 m_textForegroundColour
= col
;
1910 m_textForegroundColour
.CalcPixel( m_cmap
);
1911 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1915 void wxWindowDCImpl
::SetTextBackground( const wxColour
&col
)
1917 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1920 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
1923 m_textBackgroundColour
= col
;
1927 m_textBackgroundColour
.CalcPixel( m_cmap
);
1928 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1932 void wxWindowDCImpl
::SetBackgroundMode( int mode
)
1934 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1936 m_backgroundMode
= mode
;
1939 void wxWindowDCImpl
::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1941 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
1944 void wxWindowDCImpl
::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1946 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1948 if (!m_gdkwindow
) return;
1951 rect
.x
= XLOG2DEV(x
);
1952 rect
.y
= YLOG2DEV(y
);
1953 rect
.width
= XLOG2DEVREL(width
);
1954 rect
.height
= YLOG2DEVREL(height
);
1956 if (m_window
&& m_window
->m_wxwindow
&&
1957 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
1959 rect
.x
-= rect
.width
;
1962 DoSetDeviceClippingRegion(wxRegion(rect
));
1965 void wxWindowDCImpl
::DoSetDeviceClippingRegion( const wxRegion
®ion
)
1967 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1971 DestroyClippingRegion();
1975 if (!m_gdkwindow
) return;
1977 if (!m_currentClippingRegion
.IsNull())
1978 m_currentClippingRegion
.Intersect( region
);
1980 m_currentClippingRegion
.Union( region
);
1982 #if USE_PAINT_REGION
1983 if (!m_paintClippingRegion
.IsNull())
1984 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1987 wxCoord xx
, yy
, ww
, hh
;
1988 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1989 wxGTKDCImpl
::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1991 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
1992 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
1993 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
1994 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
1995 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
1998 void wxWindowDCImpl
::DestroyClippingRegion()
2000 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2002 wxDCImpl
::DestroyClippingRegion();
2004 m_currentClippingRegion
.Clear();
2006 #if USE_PAINT_REGION
2007 if (!m_paintClippingRegion
.IsEmpty())
2008 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2011 if (!m_gdkwindow
) return;
2013 GdkRegion
* gdkRegion
= NULL
;
2014 if (!m_currentClippingRegion
.IsEmpty())
2015 gdkRegion
= m_currentClippingRegion
.GetRegion();
2017 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2018 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2019 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2020 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2023 void wxWindowDCImpl
::Destroy()
2025 if (m_penGC
) wxFreePoolGC( m_penGC
);
2027 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2029 if (m_textGC
) wxFreePoolGC( m_textGC
);
2031 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2035 void wxWindowDCImpl
::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2037 m_deviceOriginX
= x
;
2038 m_deviceOriginY
= y
;
2040 ComputeScaleAndOrigin();
2043 void wxWindowDCImpl
::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2045 m_signX
= (xLeftRight ?
1 : -1);
2046 m_signY
= (yBottomUp ?
-1 : 1);
2048 if (m_window
&& m_window
->m_wxwindow
&&
2049 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2052 ComputeScaleAndOrigin();
2055 void wxWindowDCImpl
::ComputeScaleAndOrigin()
2057 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2059 wxDCImpl
::ComputeScaleAndOrigin();
2061 // if scale has changed call SetPen to recalulate the line width
2062 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2064 // this is a bit artificial, but we need to force wxDC to think the pen
2072 // Resolution in pixels per logical inch
2073 wxSize wxWindowDCImpl
::GetPPI() const
2075 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2078 int wxWindowDCImpl
::GetDepth() const
2080 return gdk_drawable_get_depth(m_gdkwindow
);
2083 //-----------------------------------------------------------------------------
2085 //-----------------------------------------------------------------------------
2087 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2089 wxClientDCImpl
::wxClientDCImpl( wxDC
*owner
)
2090 : wxWindowDCImpl( owner
)
2094 wxClientDCImpl
::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2095 : wxWindowDCImpl( owner
, win
)
2097 wxCHECK_RET( win
, wxT("NULL window in wxClientDCImpl::wxClientDC") );
2099 #ifdef __WXUNIVERSAL__
2100 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2101 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2102 wxSize size
= win
->GetClientSize();
2103 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2108 void wxClientDCImpl
::DoGetSize(int *width
, int *height
) const
2110 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
2112 m_window
->GetClientSize(width
, height
);
2115 //-----------------------------------------------------------------------------
2117 //-----------------------------------------------------------------------------
2119 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2121 // Limit the paint region to the window size. Sometimes
2122 // the paint region is too big, and this risks X11 errors
2123 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2125 wxRect originalRect
= region
.GetBox();
2126 wxRect
rect(originalRect
);
2127 if (rect
.width
+ rect
.x
> sz
.x
)
2128 rect
.width
= sz
.x
- rect
.x
;
2129 if (rect
.height
+ rect
.y
> sz
.y
)
2130 rect
.height
= sz
.y
- rect
.y
;
2131 if (rect
!= originalRect
)
2133 region
= wxRegion(rect
);
2134 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2135 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2136 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2140 wxPaintDCImpl
::wxPaintDCImpl( wxDC
*owner
)
2141 : wxClientDCImpl( owner
)
2145 wxPaintDCImpl
::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2146 : wxClientDCImpl( owner
, win
)
2148 #if USE_PAINT_REGION
2149 if (!win
->m_clipPaintRegion
)
2152 wxSize sz
= win
->GetSize();
2153 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2154 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2156 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2159 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2160 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2162 if (sz
.x
<= 0 || sz
.y
<= 0)
2165 gdk_gc_set_clip_region( m_penGC
, region
);
2166 gdk_gc_set_clip_region( m_brushGC
, region
);
2167 gdk_gc_set_clip_region( m_textGC
, region
);
2168 gdk_gc_set_clip_region( m_bgGC
, region
);
2173 // ----------------------------------------------------------------------------
2175 // ----------------------------------------------------------------------------
2177 class wxDCModule
: public wxModule
2184 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2187 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2189 bool wxDCModule
::OnInit()
2195 void wxDCModule
::OnExit()
2199 for (int i
= wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
; i
--; )
2202 g_object_unref(hatches
[i
]);