1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dcclient.cpp
3 // Purpose: wxWindowDCImpl implementation
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling, Chris Breeze
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
12 #include "wx/gtk/dcclient.h"
15 #include "wx/window.h"
17 #include "wx/dcmemory.h"
20 #include "wx/module.h"
23 #include "wx/fontutil.h"
25 #include "wx/gtk/private.h"
26 #include "wx/gtk/private/object.h"
27 #include "wx/private/textmeasure.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 GdkPixmap
* GetHatch(int style
)
68 wxASSERT(style
>= wxBRUSHSTYLE_FIRST_HATCH
&& style
<= wxBRUSHSTYLE_LAST_HATCH
);
69 const int i
= style
- wxBRUSHSTYLE_FIRST_HATCH
;
70 if (hatches
[i
] == NULL
)
72 // This macro creates a bitmap from an XBM file included above. Notice
73 // the need for the cast because gdk_bitmap_create_from_data() doesn't
74 // accept unsigned data but the arrays in XBM need to be unsigned to
75 // avoid warnings (and even errors in C+0x mode) from g++.
76 #define CREATE_FROM_XBM_DATA(name) \
77 gdk_bitmap_create_from_data \
80 reinterpret_cast<gchar *>(name ## _bits), \
87 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
88 hatches
[i
] = CREATE_FROM_XBM_DATA(bdiag
);
90 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
91 hatches
[i
] = CREATE_FROM_XBM_DATA(cdiag
);
93 case wxBRUSHSTYLE_CROSS_HATCH
:
94 hatches
[i
] = CREATE_FROM_XBM_DATA(cross
);
96 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
97 hatches
[i
] = CREATE_FROM_XBM_DATA(fdiag
);
99 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
100 hatches
[i
] = CREATE_FROM_XBM_DATA(horiz
);
102 case wxBRUSHSTYLE_VERTICAL_HATCH
:
103 hatches
[i
] = CREATE_FROM_XBM_DATA(verti
);
107 #undef CREATE_FROM_XBM_DATA
112 //-----------------------------------------------------------------------------
113 // Implement Pool of Graphic contexts. Creating them takes too much time.
114 //-----------------------------------------------------------------------------
144 #define GC_POOL_ALLOC_SIZE 100
146 static int wxGCPoolSize
= 0;
148 static wxGC
*wxGCPool
= NULL
;
150 static void wxInitGCPool()
152 // This really could wait until the first call to
153 // wxGetPoolGC, but we will make the first allocation
154 // now when other initialization is being performed.
156 // Set initial pool size.
157 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
159 // Allocate initial pool.
160 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
161 if (wxGCPool
== NULL
)
163 // If we cannot malloc, then fail with error
164 // when debug is enabled. If debug is not enabled,
165 // the problem will eventually get caught
167 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
171 // Zero initial pool.
172 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
175 static void wxCleanUpGCPool()
177 for (int i
= 0; i
< wxGCPoolSize
; i
++)
179 if (wxGCPool
[i
].m_gc
)
180 g_object_unref (wxGCPool
[i
].m_gc
);
188 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
192 // Look for an available GC.
193 for (int i
= 0; i
< wxGCPoolSize
; i
++)
195 if (!wxGCPool
[i
].m_gc
)
197 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
198 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
199 wxGCPool
[i
].m_type
= type
;
200 wxGCPool
[i
].m_used
= false;
202 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
204 wxGCPool
[i
].m_used
= true;
205 return wxGCPool
[i
].m_gc
;
209 // We did not find an available GC.
210 // We need to grow the GC pool.
211 pptr
= (wxGC
*)realloc(wxGCPool
,
212 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
215 // Initialize newly allocated pool.
217 memset(&wxGCPool
[wxGCPoolSize
], 0,
218 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
220 // Initialize entry we will return.
221 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
222 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
223 wxGCPool
[wxGCPoolSize
].m_type
= type
;
224 wxGCPool
[wxGCPoolSize
].m_used
= true;
226 // Set new value of pool size.
227 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
229 // Return newly allocated entry.
230 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
233 // The realloc failed. Fall through to error.
234 wxFAIL_MSG( wxT("No GC available") );
239 static void wxFreePoolGC( GdkGC
*gc
)
241 for (int i
= 0; i
< wxGCPoolSize
; i
++)
243 if (wxGCPool
[i
].m_gc
== gc
)
245 wxGCPool
[i
].m_used
= false;
250 wxFAIL_MSG( wxT("Wrong GC") );
253 //-----------------------------------------------------------------------------
255 //-----------------------------------------------------------------------------
257 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
259 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
) :
268 m_isScreenDC
= false;
274 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
277 wxASSERT_MSG( window
, wxT("DC needs a window") );
285 m_isScreenDC
= false;
286 m_font
= window
->GetFont();
288 GtkWidget
*widget
= window
->m_wxwindow
;
289 m_gdkwindow
= window
->GTKGetDrawingWindow();
291 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
292 // code should still be able to create wxClientDCs for them
295 widget
= window
->m_widget
;
297 wxCHECK_RET(widget
, "DC needs a widget");
299 m_gdkwindow
= widget
->window
;
300 if (!gtk_widget_get_has_window(widget
))
301 SetDeviceLocalOrigin(widget
->allocation
.x
, widget
->allocation
.y
);
304 m_context
= window
->GTKGetPangoDefaultContext();
305 m_layout
= pango_layout_new( m_context
);
306 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
308 // Window not realized ?
311 // Don't report problems as per MSW.
317 m_cmap
= gtk_widget_get_colormap(widget
);
321 /* this must be done after SetUpDC, bacause SetUpDC calls the
322 repective SetBrush, SetPen, SetBackground etc functions
323 to set up the DC. SetBackground call m_owner->SetBackground
324 and this might not be desired as the standard dc background
325 is white whereas a window might assume gray to be the
326 standard (as e.g. wxStatusBar) */
330 if (m_window
&& m_window
->m_wxwindow
&&
331 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
336 // origin in the upper right corner
337 m_deviceOriginX
= m_window
->GetClientSize().x
;
341 wxWindowDCImpl::~wxWindowDCImpl()
346 g_object_unref (m_layout
);
348 pango_font_description_free( m_fontdesc
);
351 void wxWindowDCImpl::SetUpDC( bool isMemDC
)
355 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
359 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
361 if (GetSelectedBitmap().GetDepth() == 1)
363 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
364 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
365 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
366 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
375 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
376 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
377 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
378 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
380 #if GTK_CHECK_VERSION(2,12,0)
381 // gdk_screen_get_rgba_colormap was added in 2.8, but this code is for
382 // compositing which requires 2.12
383 else if (gtk_check_version(2,12,0) == NULL
&&
384 m_cmap
== gdk_screen_get_rgba_colormap(gdk_colormap_get_screen(m_cmap
)))
386 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR_ALPHA
);
387 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR_ALPHA
);
388 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR_ALPHA
);
389 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR_ALPHA
);
394 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
395 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
396 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
397 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
401 /* background colour */
402 m_backgroundBrush
= *wxWHITE_BRUSH
;
403 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
404 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
407 m_textForegroundColour
.CalcPixel( m_cmap
);
408 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
410 m_textBackgroundColour
.CalcPixel( m_cmap
);
411 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
413 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
415 gdk_gc_set_colormap( m_textGC
, m_cmap
);
418 m_pen
.GetColour().CalcPixel( m_cmap
);
419 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
420 gdk_gc_set_background( m_penGC
, bg_col
);
422 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
425 m_brush
.GetColour().CalcPixel( m_cmap
);
426 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
427 gdk_gc_set_background( m_brushGC
, bg_col
);
429 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
432 gdk_gc_set_background( m_bgGC
, bg_col
);
433 gdk_gc_set_foreground( m_bgGC
, bg_col
);
435 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
438 gdk_gc_set_function( m_textGC
, GDK_COPY
);
439 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
440 gdk_gc_set_function( m_penGC
, GDK_COPY
);
443 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
444 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
445 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
446 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
449 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
451 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
453 m_window
->GetSize(width
, height
);
456 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
457 const wxColour
& col
, wxFloodFillStyle style
)
460 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
461 const wxColour
& col
, wxFloodFillStyle style
);
463 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
474 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
476 GdkImage
* image
= NULL
;
479 const int x
= LogicalToDeviceX(x1
);
480 const int y
= LogicalToDeviceY(y1
);
482 gdk_drawable_get_size(m_gdkwindow
, &rect
.width
, &rect
.height
);
483 if (rect
.Contains(x
, y
))
484 image
= gdk_drawable_get_image(m_gdkwindow
, x
, y
, 1, 1);
491 GdkColormap
* colormap
= gdk_image_get_colormap(image
);
492 const unsigned pixel
= gdk_image_get_pixel(image
, 0, 0);
493 if (colormap
== NULL
)
494 *col
= pixel
? m_textForegroundColour
: m_textBackgroundColour
;
498 gdk_colormap_query_color(colormap
, pixel
, &c
);
499 col
->Set(c
.red
>> 8, c
.green
>> 8, c
.blue
>> 8);
501 g_object_unref(image
);
505 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
507 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
509 if ( m_pen
.IsNonTransparent() )
512 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
514 CalcBoundingBox(x1
, y1
);
515 CalcBoundingBox(x2
, y2
);
519 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
521 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
523 if ( m_pen
.IsNonTransparent() )
527 GetOwner()->GetSize( &w
, &h
);
528 wxCoord xx
= XLOG2DEV(x
);
529 wxCoord yy
= YLOG2DEV(y
);
532 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
533 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
538 void wxWindowDCImpl::DrawingSetup(GdkGC
*& gc
, bool& originChanged
)
541 GdkPixmap
* pixmap
= NULL
;
542 const int style
= m_brush
.GetStyle();
544 if (style
== wxBRUSHSTYLE_STIPPLE
|| style
== wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
)
546 const wxBitmap
* stipple
= m_brush
.GetStipple();
549 if (style
== wxBRUSHSTYLE_STIPPLE
)
550 pixmap
= stipple
->GetPixmap();
551 else if (stipple
->GetMask())
553 pixmap
= stipple
->GetPixmap();
558 else if (m_brush
.IsHatch())
560 pixmap
= GetHatch(style
);
568 gdk_drawable_get_size(pixmap
, &w
, &h
);
569 origin_x
= m_deviceOriginX
% w
;
570 origin_y
= m_deviceOriginY
% h
;
573 originChanged
= origin_x
|| origin_y
;
575 gdk_gc_set_ts_origin(gc
, origin_x
, origin_y
);
578 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
579 wxCoord xc
, wxCoord yc
)
581 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
583 wxCoord xx1
= XLOG2DEV(x1
);
584 wxCoord yy1
= YLOG2DEV(y1
);
585 wxCoord xx2
= XLOG2DEV(x2
);
586 wxCoord yy2
= YLOG2DEV(y2
);
587 wxCoord xxc
= XLOG2DEV(xc
);
588 wxCoord yyc
= YLOG2DEV(yc
);
589 double dx
= xx1
- xxc
;
590 double dy
= yy1
- yyc
;
591 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
592 wxCoord r
= (wxCoord
)radius
;
593 double radius1
, radius2
;
595 if (xx1
== xx2
&& yy1
== yy2
)
600 else if ( wxIsNullDouble(radius
) )
607 radius1
= (xx1
- xxc
== 0) ?
608 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
609 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
610 radius2
= (xx2
- xxc
== 0) ?
611 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
612 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
614 wxCoord alpha1
= wxCoord(radius1
* 64.0);
615 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
616 while (alpha2
<= 0) alpha2
+= 360*64;
617 while (alpha1
> 360*64) alpha1
-= 360*64;
621 if ( m_brush
.IsNonTransparent() )
625 DrawingSetup(gc
, originChanged
);
627 gdk_draw_arc(m_gdkwindow
, gc
, true, xxc
-r
, yyc
-r
, 2*r
, 2*r
, alpha1
, alpha2
);
630 gdk_gc_set_ts_origin(gc
, 0, 0);
633 if ( m_pen
.IsNonTransparent() )
635 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
637 if ( m_brush
.IsNonTransparent() && (alpha2
- alpha1
!= 360*64) )
639 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
640 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
645 CalcBoundingBox (x1
, y1
);
646 CalcBoundingBox (x2
, y2
);
649 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
651 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
653 wxCoord xx
= XLOG2DEV(x
);
654 wxCoord yy
= YLOG2DEV(y
);
655 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
656 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
658 // CMB: handle -ve width and/or height
659 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
660 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
664 wxCoord start
= wxCoord(sa
* 64.0);
665 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
667 if ( m_brush
.IsNonTransparent() )
671 DrawingSetup(gc
, originChanged
);
673 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, start
, end
);
676 gdk_gc_set_ts_origin(gc
, 0, 0);
679 if ( m_pen
.IsNonTransparent() )
680 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
683 CalcBoundingBox (x
, y
);
684 CalcBoundingBox (x
+ width
, y
+ height
);
687 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
689 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
691 if ( m_pen
.IsNonTransparent() && m_gdkwindow
)
692 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
694 CalcBoundingBox (x
, y
);
697 void wxWindowDCImpl::DoDrawLines( int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
699 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
703 if ( m_pen
.IsTransparent() )
706 //Check, if scaling is necessary
708 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
710 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
711 const GdkPoint
* gpts
= reinterpret_cast<const GdkPoint
*>(points
);
712 GdkPoint
* gpts_alloc
= NULL
;
716 gpts_alloc
= new GdkPoint
[n
];
720 for (int i
= 0; i
< n
; i
++)
724 gpts_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
725 gpts_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
727 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
731 gdk_draw_lines( m_gdkwindow
, m_penGC
, (GdkPoint
*) gpts
, n
);
736 void wxWindowDCImpl::DoDrawPolygon( int n
, const wxPoint points
[],
737 wxCoord xoffset
, wxCoord yoffset
,
738 wxPolygonFillMode
WXUNUSED(fillStyle
) )
740 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
744 //Check, if scaling is necessary
746 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
748 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
749 const GdkPoint
* gdkpoints
= reinterpret_cast<const GdkPoint
*>(points
);
750 GdkPoint
* gdkpoints_alloc
= NULL
;
754 gdkpoints_alloc
= new GdkPoint
[n
];
755 gdkpoints
= gdkpoints_alloc
;
759 for (i
= 0 ; i
< n
; i
++)
763 gdkpoints_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
764 gdkpoints_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
766 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
771 if ( m_brush
.IsNonTransparent() )
775 DrawingSetup(gc
, originChanged
);
777 gdk_draw_polygon(m_gdkwindow
, gc
, true, (GdkPoint
*) gdkpoints
, n
);
780 gdk_gc_set_ts_origin(gc
, 0, 0);
783 if ( m_pen
.IsNonTransparent() )
786 for (i = 0 ; i < n ; i++)
788 gdk_draw_line( m_gdkwindow, m_penGC,
791 gdkpoints[(i+1)%n].x,
792 gdkpoints[(i+1)%n].y);
795 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, (GdkPoint
*) gdkpoints
, n
);
800 delete[] gdkpoints_alloc
;
803 void wxWindowDCImpl::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
805 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
807 wxCoord xx
= XLOG2DEV(x
);
808 wxCoord yy
= YLOG2DEV(y
);
809 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
810 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
812 // CMB: draw nothing if transformed w or h is 0
813 if (ww
== 0 || hh
== 0) return;
815 // CMB: handle -ve width and/or height
816 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
817 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
821 if ( m_brush
.IsNonTransparent() )
825 DrawingSetup(gc
, originChanged
);
827 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
);
830 gdk_gc_set_ts_origin(gc
, 0, 0);
833 if ( m_pen
.IsNonTransparent() )
835 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
836 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxPENSTYLE_SOLID
))
838 // Use 2 1-line rects instead
839 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
844 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
845 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
849 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
850 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
854 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
858 // Just use X11 for other cases
859 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
864 CalcBoundingBox( x
, y
);
865 CalcBoundingBox( x
+ width
, y
+ height
);
868 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
870 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
872 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
874 wxCoord xx
= XLOG2DEV(x
);
875 wxCoord yy
= YLOG2DEV(y
);
876 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
877 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
878 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
880 // CMB: handle -ve width and/or height
881 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
882 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
884 // CMB: if radius is zero use DrawRectangle() instead to avoid
885 // X drawing errors with small radii
888 DoDrawRectangle( x
, y
, width
, height
);
892 // CMB: draw nothing if transformed w or h is 0
893 if (ww
== 0 || hh
== 0) return;
895 // CMB: adjust size if outline is drawn otherwise the result is
896 // 1 pixel too wide and high
897 if ( m_pen
.IsNonTransparent() )
905 // CMB: ensure dd is not larger than rectangle otherwise we
906 // get an hour glass shape
908 if (dd
> ww
) dd
= ww
;
909 if (dd
> hh
) dd
= hh
;
912 if ( m_brush
.IsNonTransparent() )
916 DrawingSetup(gc
, originChanged
);
918 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
+rr
, yy
, ww
-dd
+1, hh
);
919 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
+rr
, ww
, hh
-dd
+1);
920 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, dd
, dd
, 90*64, 90*64);
921 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64);
922 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64);
923 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64);
926 gdk_gc_set_ts_origin(gc
, 0, 0);
929 if ( m_pen
.IsNonTransparent() )
931 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
932 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
933 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
934 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
935 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
936 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
937 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
938 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
942 // this ignores the radius
943 CalcBoundingBox( x
, y
);
944 CalcBoundingBox( x
+ width
, y
+ height
);
947 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
949 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
951 wxCoord xx
= XLOG2DEV(x
);
952 wxCoord yy
= YLOG2DEV(y
);
953 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
954 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
956 // CMB: handle -ve width and/or height
957 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
958 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
962 if ( m_brush
.IsNonTransparent() )
966 DrawingSetup(gc
, originChanged
);
968 // If the pen is transparent pen we increase the size
969 // for better compatibility with other platforms.
970 if (m_pen
.IsTransparent())
976 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, 0, 360*64);
979 gdk_gc_set_ts_origin(gc
, 0, 0);
982 if ( m_pen
.IsNonTransparent() )
983 gdk_draw_arc( m_gdkwindow
, m_penGC
, false, xx
, yy
, ww
, hh
, 0, 360*64 );
986 CalcBoundingBox( x
, y
);
987 CalcBoundingBox( x
+ width
, y
+ height
);
990 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
992 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
993 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
998 Scale(GdkPixbuf
* pixbuf
, int dst_w
, int dst_h
, double sx
, double sy
)
1000 GdkPixbuf
* pixbuf_scaled
= gdk_pixbuf_new(
1001 GDK_COLORSPACE_RGB
, gdk_pixbuf_get_has_alpha(pixbuf
), 8, dst_w
, dst_h
);
1002 gdk_pixbuf_scale(pixbuf
, pixbuf_scaled
,
1003 0, 0, dst_w
, dst_h
, 0, 0, sx
, sy
, GDK_INTERP_NEAREST
);
1004 return pixbuf_scaled
;
1007 // scale part of a pixmap using pixbuf scaling
1009 Scale(GdkPixmap
* pixmap
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1011 GdkPixbuf
* pixbuf
= gdk_pixbuf_get_from_drawable(
1012 NULL
, pixmap
, NULL
, x
, y
, 0, 0, w
, h
);
1013 GdkPixbuf
* pixbuf2
= Scale(pixbuf
, dst_w
, dst_h
, sx
, sy
);
1014 g_object_unref(pixbuf
);
1018 // scale part of a mask pixmap
1020 ScaleMask(GdkPixmap
* mask
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1022 GdkPixbuf
* pixbuf
= Scale(mask
, x
, y
, w
, h
, dst_w
, dst_h
, sx
, sy
);
1024 // convert black and white pixbuf back to a mono pixmap
1025 const unsigned out_rowstride
= (dst_w
+ 7) / 8;
1026 const size_t data_size
= out_rowstride
* size_t(dst_h
);
1027 char* data
= new char[data_size
];
1029 const guchar
* row
= gdk_pixbuf_get_pixels(pixbuf
);
1030 const int rowstride
= gdk_pixbuf_get_rowstride(pixbuf
);
1031 memset(data
, 0, data_size
);
1032 for (int j
= 0; j
< dst_h
; j
++, row
+= rowstride
, out
+= out_rowstride
)
1034 const guchar
* in
= row
;
1035 for (int i
= 0; i
< dst_w
; i
++, in
+= 3)
1037 out
[i
>> 3] |= 1 << (i
& 7);
1039 g_object_unref(pixbuf
);
1040 GdkPixmap
* pixmap
= gdk_bitmap_create_from_data(mask
, data
, dst_w
, dst_h
);
1045 // Make a new mask from part of a mask and a clip region.
1047 ClipMask(GdkPixmap
* mask
, GdkRegion
* clipRegion
, int x
, int y
, int dst_x
, int dst_y
, int w
, int h
)
1049 GdkGCValues gcValues
;
1050 gcValues
.foreground
.pixel
= 0;
1051 GdkGC
* gc
= gdk_gc_new_with_values(mask
, &gcValues
, GDK_GC_FOREGROUND
);
1052 GdkPixmap
* pixmap
= gdk_pixmap_new(mask
, w
, h
, 1);
1053 // clear new mask, so clipped areas will be masked
1054 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1055 gdk_gc_set_clip_region(gc
, clipRegion
);
1056 gdk_gc_set_clip_origin(gc
, -dst_x
, -dst_y
);
1057 // draw old mask onto new one, with clip
1058 gdk_draw_drawable(pixmap
, gc
, mask
, x
, y
, 0, 0, w
, h
);
1063 // make a color pixmap from part of a mono one, using text fg/bg colors
1065 wxWindowDCImpl::MonoToColor(GdkPixmap
* monoPixmap
, int x
, int y
, int w
, int h
) const
1067 GdkPixmap
* pixmap
= gdk_pixmap_new(m_gdkwindow
, w
, h
, -1);
1068 GdkGCValues gcValues
;
1069 gcValues
.foreground
.pixel
= m_textForegroundColour
.GetColor()->pixel
;
1070 gcValues
.background
.pixel
= m_textBackgroundColour
.GetColor()->pixel
;
1071 gcValues
.stipple
= monoPixmap
;
1072 gcValues
.fill
= GDK_OPAQUE_STIPPLED
;
1073 gcValues
.ts_x_origin
= -x
;
1074 gcValues
.ts_y_origin
= -y
;
1075 GdkGC
* gc
= gdk_gc_new_with_values(pixmap
, &gcValues
, GdkGCValuesMask(
1076 GDK_GC_FOREGROUND
| GDK_GC_BACKGROUND
| GDK_GC_STIPPLE
| GDK_GC_FILL
|
1077 GDK_GC_TS_X_ORIGIN
| GDK_GC_TS_Y_ORIGIN
));
1078 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1083 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
1084 wxCoord x
, wxCoord y
,
1087 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1088 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1090 if (!m_gdkwindow
) return;
1092 const int w
= bitmap
.GetWidth();
1093 const int h
= bitmap
.GetHeight();
1095 // notice that as the bitmap is not drawn upside down (or right to left)
1096 // even if the corresponding axis direction is inversed, we need to take it
1097 // into account when calculating its bounding box
1098 CalcBoundingBox(x
, y
);
1099 CalcBoundingBox(x
+ m_signX
*w
, y
+ m_signY
*h
);
1102 int xx
= LogicalToDeviceX(x
);
1103 const int yy
= LogicalToDeviceY(y
);
1104 const int ww
= LogicalToDeviceXRel(w
);
1105 const int hh
= LogicalToDeviceYRel(h
);
1107 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1110 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1111 // determine clip region overlap
1112 int overlap
= wxInRegion
;
1115 overlap
= m_currentClippingRegion
.Contains(xx
, yy
, ww
, hh
);
1116 if (overlap
== wxOutRegion
)
1120 const bool isScaled
= ww
!= w
|| hh
!= h
;
1121 const bool hasAlpha
= bitmap
.HasAlpha();
1122 GdkGC
* const use_gc
= m_penGC
;
1124 GdkPixmap
* mask
= NULL
;
1125 // mask does not work when drawing a pixbuf with alpha
1126 if (useMask
&& !hasAlpha
)
1128 wxMask
* m
= bitmap
.GetMask();
1133 GdkPixmap
* mask_new
= NULL
;
1138 mask
= ScaleMask(mask
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1141 if (overlap
== wxPartRegion
)
1143 // need a new mask that also masks the clipped area,
1144 // because gc can't have both a mask and a clip region
1145 mask
= ClipMask(mask
, clipRegion
, 0, 0, xx
, yy
, ww
, hh
);
1147 g_object_unref(mask_new
);
1150 gdk_gc_set_clip_mask(use_gc
, mask
);
1151 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1154 // determine whether to use pixmap or pixbuf
1155 GdkPixmap
* pixmap
= NULL
;
1156 GdkPixmap
* pixmap_new
= NULL
;
1157 GdkPixbuf
* pixbuf
= NULL
;
1158 GdkPixbuf
* pixbuf_new
= NULL
;
1159 if (bitmap
.HasPixmap())
1160 pixmap
= bitmap
.GetPixmap();
1161 if (pixmap
&& gdk_drawable_get_depth(pixmap
) == 1)
1163 if (gdk_drawable_get_depth(m_gdkwindow
) != 1)
1165 // convert mono pixmap to color using text fg/bg colors
1166 pixmap
= MonoToColor(pixmap
, 0, 0, w
, h
);
1167 pixmap_new
= pixmap
;
1170 else if (hasAlpha
|| pixmap
== NULL
)
1171 pixbuf
= bitmap
.GetPixbuf();
1176 pixbuf
= Scale(pixbuf
, ww
, hh
, m_scaleX
, m_scaleY
);
1178 pixbuf
= Scale(pixmap
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1180 pixbuf_new
= pixbuf
;
1185 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1186 0, 0, xx
, yy
, ww
, hh
, GDK_RGB_DITHER_NORMAL
, 0, 0);
1190 gdk_draw_drawable(m_gdkwindow
, use_gc
, pixmap
, 0, 0, xx
, yy
, ww
, hh
);
1194 g_object_unref(pixbuf_new
);
1196 g_object_unref(pixmap_new
);
1199 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1201 // Notice that we can only release the mask now, we can't do it before
1202 // the calls to gdk_draw_xxx() above as they crash with X error with
1203 // GTK+ up to 2.20.1 (i.e. it works with 2.20 but is known to not work
1204 // with 2.16.1 and below).
1206 g_object_unref(mask_new
);
1210 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1211 wxCoord width
, wxCoord height
,
1213 wxCoord xsrc
, wxCoord ysrc
,
1214 wxRasterOperationMode logical_func
,
1216 wxCoord xsrcMask
, wxCoord ysrcMask
)
1218 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1219 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1221 if (!m_gdkwindow
) return false;
1223 GdkDrawable
* srcDrawable
= NULL
;
1224 GdkPixmap
* mask
= NULL
;
1225 wxMemoryDC
* memDC
= wxDynamicCast(source
, wxMemoryDC
);
1228 const wxBitmap
& bitmap
= memDC
->GetSelectedBitmap();
1231 srcDrawable
= bitmap
.GetPixmap();
1234 wxMask
* m
= bitmap
.GetMask();
1241 wxDCImpl
* impl
= source
->GetImpl();
1242 wxWindowDCImpl
* gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1244 srcDrawable
= gtk_impl
->GetGDKWindow();
1245 if (srcDrawable
== NULL
)
1249 CalcBoundingBox(xdest
, ydest
);
1250 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1252 // source device coords
1253 int src_x
= source
->LogicalToDeviceX(xsrc
);
1254 int src_y
= source
->LogicalToDeviceY(ysrc
);
1255 int src_w
= source
->LogicalToDeviceXRel(width
);
1256 int src_h
= source
->LogicalToDeviceYRel(height
);
1258 // Clip source rect to source dc.
1259 // Only necessary when scaling, to avoid GDK errors when
1260 // converting to pixbuf, but no harm in always doing it.
1261 // If source rect changes, it also changes the dest rect.
1263 gdk_drawable_get_size(srcDrawable
, &clip
.width
, &clip
.height
);
1264 clip
.Intersect(wxRect(src_x
, src_y
, src_w
, src_h
));
1265 if (src_w
!= clip
.width
|| src_h
!= clip
.height
)
1267 if (clip
.width
== 0)
1271 src_h
= clip
.height
;
1272 width
= source
->DeviceToLogicalXRel(src_w
);
1273 height
= source
->DeviceToLogicalYRel(src_h
);
1274 if (src_x
!= clip
.x
|| src_y
!= clip
.y
)
1276 xdest
+= source
->DeviceToLogicalXRel(clip
.x
- src_x
);
1277 ydest
+= source
->DeviceToLogicalYRel(clip
.y
- src_y
);
1283 // destination device coords
1284 const int dst_x
= LogicalToDeviceX(xdest
);
1285 const int dst_y
= LogicalToDeviceY(ydest
);
1286 const int dst_w
= LogicalToDeviceXRel(width
);
1287 const int dst_h
= LogicalToDeviceYRel(height
);
1289 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1290 // determine dest clip region overlap
1291 int overlap
= wxInRegion
;
1294 overlap
= m_currentClippingRegion
.Contains(dst_x
, dst_y
, dst_w
, dst_h
);
1295 if (overlap
== wxOutRegion
)
1299 const bool isScaled
= src_w
!= dst_w
|| src_h
!= dst_h
;
1304 // get source to dest scale
1305 double usx
, usy
, lsx
, lsy
;
1306 source
->GetUserScale(&usx
, &usy
);
1307 source
->GetLogicalScale(&lsx
, &lsy
);
1308 scale_x
= m_scaleX
/ (usx
* lsx
);
1309 scale_y
= m_scaleY
/ (usy
* lsy
);
1312 GdkGC
* const use_gc
= m_penGC
;
1316 int srcMask_x
= src_x
;
1317 int srcMask_y
= src_y
;
1318 if (xsrcMask
!= -1 || ysrcMask
!= -1)
1320 srcMask_x
= source
->LogicalToDeviceX(xsrcMask
);
1321 srcMask_y
= source
->LogicalToDeviceY(ysrcMask
);
1323 GdkPixmap
* mask_new
= NULL
;
1326 mask
= ScaleMask(mask
, srcMask_x
, srcMask_y
,
1327 src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1332 if (overlap
== wxPartRegion
)
1334 // need a new mask that also masks the clipped area,
1335 // because gc can't have both a mask and a clip region
1336 mask
= ClipMask(mask
, clipRegion
,
1337 srcMask_x
, srcMask_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1339 g_object_unref(mask_new
);
1344 gdk_gc_set_clip_mask(use_gc
, mask
);
1345 gdk_gc_set_clip_origin(use_gc
, dst_x
- srcMask_x
, dst_y
- srcMask_y
);
1347 g_object_unref(mask_new
);
1350 GdkPixmap
* pixmap
= NULL
;
1351 if (gdk_drawable_get_depth(srcDrawable
) == 1 &&
1352 (gdk_drawable_get_depth(m_gdkwindow
) != 1 || isScaled
))
1354 // Convert mono pixmap to color using text fg/bg colors.
1355 // Scaling/drawing is simpler if this is done first.
1356 pixmap
= MonoToColor(srcDrawable
, src_x
, src_y
, src_w
, src_h
);
1357 srcDrawable
= pixmap
;
1362 const wxRasterOperationMode logical_func_save
= m_logicalFunction
;
1363 SetLogicalFunction(logical_func
);
1365 gdk_gc_set_subwindow(use_gc
, GDK_INCLUDE_INFERIORS
);
1369 GdkPixbuf
* pixbuf
= Scale(srcDrawable
,
1370 src_x
, src_y
, src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1371 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1372 0, 0, dst_x
, dst_y
, dst_w
, dst_h
, GDK_RGB_DITHER_NONE
, 0, 0);
1373 g_object_unref(pixbuf
);
1377 gdk_draw_drawable(m_gdkwindow
, use_gc
, srcDrawable
,
1378 src_x
, src_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1381 SetLogicalFunction(logical_func_save
);
1383 gdk_gc_set_subwindow(use_gc
, GDK_CLIP_BY_CHILDREN
);
1386 g_object_unref(pixmap
);
1388 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1393 void wxWindowDCImpl::DoDrawText(const wxString
& text
,
1397 DoDrawRotatedText(text
, xLogical
, yLogical
, 0);
1400 void wxWindowDCImpl::DoDrawRotatedText(const wxString
& text
, int xLogical
, int yLogical
, double angle
)
1402 if (!m_gdkwindow
|| text
.empty())
1405 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1407 pango_layout_set_text(m_layout
, wxGTK_CONV(text
), -1);
1408 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1410 const GdkColor
* bg_col
= NULL
;
1411 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1412 bg_col
= m_textBackgroundColour
.GetColor();
1414 PangoMatrix matrix
= PANGO_MATRIX_INIT
;
1415 if (!wxIsSameDouble(m_scaleX
, 1) || !wxIsSameDouble(m_scaleY
, 1) || !wxIsNullDouble(angle
))
1417 pango_matrix_scale(&matrix
, m_scaleX
, m_scaleY
);
1418 pango_matrix_rotate(&matrix
, angle
);
1419 pango_context_set_matrix(m_context
, &matrix
);
1420 pango_layout_context_changed(m_layout
);
1424 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1426 int x
= LogicalToDeviceX(xLogical
);
1427 int y
= LogicalToDeviceY(yLogical
);
1428 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1429 x
-= LogicalToDeviceXRel(w
);
1431 if (wxIsNullDouble(angle
))
1433 CalcBoundingBox(xLogical
, yLogical
);
1434 CalcBoundingBox(xLogical
+ w
, yLogical
+ h
);
1438 // To be compatible with MSW, the rotation axis must be in the old
1440 // Calculate the vertices of the rotated rectangle containing the text,
1441 // relative to the old top-left vertex.
1442 // the rectangle vertices are counted clockwise with the first one
1444 double x2
= w
* matrix
.xx
;
1445 double y2
= w
* matrix
.yx
;
1446 double x4
= h
* matrix
.xy
;
1447 double y4
= h
* matrix
.yy
;
1448 double x3
= x4
+ x2
;
1449 double y3
= y4
+ y2
;
1450 // Then we calculate max and min of the rotated rectangle.
1451 wxCoord maxX
= (wxCoord
)(dmax(dmax(0, x2
), dmax(x3
, x4
)) + 0.5),
1452 maxY
= (wxCoord
)(dmax(dmax(0, y2
), dmax(y3
, y4
)) + 0.5),
1453 minX
= (wxCoord
)(dmin(dmin(0, x2
), dmin(x3
, x4
)) - 0.5),
1454 minY
= (wxCoord
)(dmin(dmin(0, y2
), dmin(y3
, y4
)) - 0.5);
1457 CalcBoundingBox(DeviceToLogicalX(x
), DeviceToLogicalY(y
));
1458 CalcBoundingBox(DeviceToLogicalX(x
+ maxX
- minX
), DeviceToLogicalY(y
+ maxY
- minY
));
1461 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x
, y
, m_layout
, NULL
, bg_col
);
1463 pango_context_set_matrix(m_context
, NULL
);
1465 pango_layout_set_attributes(m_layout
, NULL
);
1468 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1469 wxCoord
*width
, wxCoord
*height
,
1470 wxCoord
*descent
, wxCoord
*externalLeading
,
1471 const wxFont
*theFont
) const
1473 // ensure we work with a valid font
1474 const wxFont
*fontToUse
;
1475 if ( !theFont
|| !theFont
->IsOk() )
1476 fontToUse
= &m_font
;
1478 fontToUse
= theFont
;
1480 wxCHECK_RET( fontToUse
->IsOk(), wxT("invalid font") );
1482 wxTextMeasure
txm(GetOwner(), fontToUse
);
1483 txm
.GetTextExtent(string
, width
, height
, descent
, externalLeading
);
1487 bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString
& text
,
1488 wxArrayInt
& widths
) const
1490 wxCHECK_MSG( m_font
.IsOk(), false, wxT("Invalid font") );
1492 wxTextMeasure
txm(GetOwner(), &m_font
);
1493 return txm
.GetPartialTextExtents(text
, widths
, m_scaleX
);
1497 wxCoord
wxWindowDCImpl::GetCharWidth() const
1499 pango_layout_set_text( m_layout
, "H", 1 );
1501 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1505 wxCoord
wxWindowDCImpl::GetCharHeight() const
1507 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1508 wxCHECK_MSG( metrics
, -1, wxT("failed to get pango font metrics") );
1510 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1511 pango_font_metrics_get_ascent (metrics
));
1512 pango_font_metrics_unref (metrics
);
1516 void wxWindowDCImpl::Clear()
1518 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1520 if (!m_gdkwindow
) return;
1523 DoGetSize( &width
, &height
);
1524 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1527 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1534 pango_font_description_free( m_fontdesc
);
1536 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1541 PangoContext
*oldContext
= m_context
;
1543 m_context
= m_window
->GTKGetPangoDefaultContext();
1545 // If we switch back/forth between different contexts
1546 // we also have to create a new layout. I think so,
1547 // at least, and it doesn't hurt to do it.
1548 if (oldContext
!= m_context
)
1551 g_object_unref (m_layout
);
1553 m_layout
= pango_layout_new( m_context
);
1557 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1561 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1563 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1565 if (m_pen
== pen
) return;
1569 if (!m_pen
.IsOk()) return;
1571 if (!m_gdkwindow
) return;
1573 gint width
= m_pen
.GetWidth();
1576 // CMB: if width is non-zero scale it with the dc
1581 // X doesn't allow different width in x and y and so we take
1584 ( fabs((double) XLOG2DEVREL(width
)) +
1585 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1589 // width can't be 0 or an internal GTK error occurs inside
1590 // gdk_gc_set_dashes() below
1595 static const wxGTKDash dotted
[] = {1, 1};
1596 static const wxGTKDash short_dashed
[] = {2, 2};
1597 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1598 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1600 // We express dash pattern in pen width unit, so we are
1601 // independent of zoom factor and so on...
1603 const wxGTKDash
*req_dash
;
1605 GdkLineStyle lineStyle
= GDK_LINE_ON_OFF_DASH
;
1606 switch (m_pen
.GetStyle())
1608 case wxPENSTYLE_USER_DASH
:
1609 req_nb_dash
= m_pen
.GetDashCount();
1610 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1612 case wxPENSTYLE_DOT
:
1616 case wxPENSTYLE_LONG_DASH
:
1618 req_dash
= wxCoord_dashed
;
1620 case wxPENSTYLE_SHORT_DASH
:
1622 req_dash
= short_dashed
;
1624 case wxPENSTYLE_DOT_DASH
:
1626 req_dash
= dotted_dashed
;
1629 case wxPENSTYLE_TRANSPARENT
:
1630 case wxPENSTYLE_STIPPLE_MASK_OPAQUE
:
1631 case wxPENSTYLE_STIPPLE
:
1632 case wxPENSTYLE_SOLID
:
1634 lineStyle
= GDK_LINE_SOLID
;
1640 if (req_dash
&& req_nb_dash
)
1642 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1645 for (int i
= 0; i
< req_nb_dash
; i
++)
1646 real_req_dash
[i
] = req_dash
[i
] * width
;
1647 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1648 delete[] real_req_dash
;
1652 // No Memory. We use non-scaled dash pattern...
1653 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1657 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1658 switch (m_pen
.GetCap())
1660 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1661 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1667 capStyle
= GDK_CAP_NOT_LAST
;
1672 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1673 switch (m_pen
.GetJoin())
1675 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1676 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1678 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1681 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1683 m_pen
.GetColour().CalcPixel( m_cmap
);
1684 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1687 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
1689 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1691 if (m_brush
== brush
) return;
1695 if (!m_brush
.IsOk()) return;
1697 if (!m_gdkwindow
) return;
1699 m_brush
.GetColour().CalcPixel( m_cmap
);
1700 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1702 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1704 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1706 if (m_brush
.GetStipple()->GetDepth() != 1)
1708 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1709 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1713 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1714 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1718 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1720 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1721 gdk_gc_set_stipple( m_textGC
, *m_brush
.GetStipple()->GetMask() );
1724 if (m_brush
.IsHatch())
1726 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1727 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
1731 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
1733 /* CMB 21/7/98: Added SetBackground. Sets background brush
1734 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1736 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1738 if (m_backgroundBrush
== brush
) return;
1740 m_backgroundBrush
= brush
;
1742 if (!m_backgroundBrush
.IsOk()) return;
1744 if (!m_gdkwindow
) return;
1746 wxColor color
= m_backgroundBrush
.GetColour();
1747 color
.CalcPixel(m_cmap
);
1748 const GdkColor
* gdkColor
= color
.GetColor();
1749 gdk_gc_set_background(m_brushGC
, gdkColor
);
1750 gdk_gc_set_background(m_penGC
, gdkColor
);
1751 gdk_gc_set_background(m_bgGC
, gdkColor
);
1752 gdk_gc_set_foreground(m_bgGC
, gdkColor
);
1755 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1757 if (m_backgroundBrush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
)
1759 const wxBitmap
* stipple
= m_backgroundBrush
.GetStipple();
1760 if (stipple
->IsOk())
1762 if (stipple
->GetDepth() != 1)
1764 gdk_gc_set_fill(m_bgGC
, GDK_TILED
);
1765 gdk_gc_set_tile(m_bgGC
, stipple
->GetPixmap());
1769 gdk_gc_set_fill(m_bgGC
, GDK_STIPPLED
);
1770 gdk_gc_set_stipple(m_bgGC
, stipple
->GetPixmap());
1774 else if (m_backgroundBrush
.IsHatch())
1776 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1777 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
1781 void wxWindowDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1783 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1785 if (m_logicalFunction
== function
)
1788 // VZ: shouldn't this be a CHECK?
1795 case wxXOR
: mode
= GDK_XOR
; break;
1796 case wxINVERT
: mode
= GDK_INVERT
; break;
1797 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1798 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1799 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1800 case wxSET
: mode
= GDK_SET
; break;
1801 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1802 case wxAND
: mode
= GDK_AND
; break;
1803 case wxOR
: mode
= GDK_OR
; break;
1804 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1805 case wxNAND
: mode
= GDK_NAND
; break;
1806 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1807 case wxCOPY
: mode
= GDK_COPY
; break;
1808 case wxNO_OP
: mode
= GDK_NOOP
; break;
1809 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1810 case wxNOR
: mode
= GDK_NOR
; break;
1812 wxFAIL_MSG("unknown mode");
1816 m_logicalFunction
= function
;
1818 gdk_gc_set_function( m_penGC
, mode
);
1819 gdk_gc_set_function( m_brushGC
, mode
);
1821 // to stay compatible with wxMSW, we don't apply ROPs to the text
1822 // operations (i.e. DrawText/DrawRotatedText).
1823 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1824 gdk_gc_set_function( m_textGC
, mode
);
1827 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
1829 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1831 // don't set m_textForegroundColour to an invalid colour as we'd crash
1832 // later then (we use m_textForegroundColour.GetColor() without checking
1834 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
1837 m_textForegroundColour
= col
;
1841 m_textForegroundColour
.CalcPixel( m_cmap
);
1842 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1846 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
1848 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1851 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
1854 m_textBackgroundColour
= col
;
1858 m_textBackgroundColour
.CalcPixel( m_cmap
);
1859 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1863 void wxWindowDCImpl::SetBackgroundMode( int mode
)
1865 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1867 m_backgroundMode
= mode
;
1870 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1872 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
1875 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1877 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1879 if (!m_gdkwindow
) return;
1882 rect
.x
= XLOG2DEV(x
);
1883 rect
.y
= YLOG2DEV(y
);
1884 rect
.width
= XLOG2DEVREL(width
);
1885 rect
.height
= YLOG2DEVREL(height
);
1887 if (m_window
&& m_window
->m_wxwindow
&&
1888 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
1890 rect
.x
-= rect
.width
;
1893 DoSetDeviceClippingRegion(wxRegion(rect
));
1896 void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion
®ion
)
1898 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1902 DestroyClippingRegion();
1906 if (!m_gdkwindow
) return;
1908 if (!m_currentClippingRegion
.IsNull())
1909 m_currentClippingRegion
.Intersect( region
);
1911 m_currentClippingRegion
.Union( region
);
1913 #if USE_PAINT_REGION
1914 if (!m_paintClippingRegion
.IsNull())
1915 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1918 wxCoord xx
, yy
, ww
, hh
;
1919 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1920 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1922 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
1923 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
1924 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
1925 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
1926 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
1929 void wxWindowDCImpl::DestroyClippingRegion()
1931 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1933 wxDCImpl::DestroyClippingRegion();
1935 m_currentClippingRegion
.Clear();
1937 #if USE_PAINT_REGION
1938 if (!m_paintClippingRegion
.IsEmpty())
1939 m_currentClippingRegion
.Union( m_paintClippingRegion
);
1942 if (!m_gdkwindow
) return;
1944 GdkRegion
* gdkRegion
= NULL
;
1945 if (!m_currentClippingRegion
.IsEmpty())
1946 gdkRegion
= m_currentClippingRegion
.GetRegion();
1948 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
1949 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
1950 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
1951 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
1954 void wxWindowDCImpl::Destroy()
1956 if (m_penGC
) wxFreePoolGC( m_penGC
);
1958 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
1960 if (m_textGC
) wxFreePoolGC( m_textGC
);
1962 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
1966 void wxWindowDCImpl::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1968 m_deviceOriginX
= x
;
1969 m_deviceOriginY
= y
;
1971 ComputeScaleAndOrigin();
1974 void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1976 m_signX
= (xLeftRight
? 1 : -1);
1977 m_signY
= (yBottomUp
? -1 : 1);
1979 if (m_window
&& m_window
->m_wxwindow
&&
1980 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
1983 ComputeScaleAndOrigin();
1986 void wxWindowDCImpl::ComputeScaleAndOrigin()
1988 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
1990 wxDCImpl::ComputeScaleAndOrigin();
1992 // if scale has changed call SetPen to recalulate the line width
1993 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
1995 // this is a bit artificial, but we need to force wxDC to think the pen
2003 // Resolution in pixels per logical inch
2004 wxSize
wxWindowDCImpl::GetPPI() const
2006 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2009 int wxWindowDCImpl::GetDepth() const
2011 return gdk_drawable_get_depth(m_gdkwindow
);
2014 //-----------------------------------------------------------------------------
2016 //-----------------------------------------------------------------------------
2018 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2020 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
2021 : wxWindowDCImpl( owner
)
2025 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2026 : wxWindowDCImpl( owner
, win
)
2028 wxCHECK_RET( win
, wxT("NULL window in wxClientDCImpl::wxClientDC") );
2030 #ifdef __WXUNIVERSAL__
2031 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2032 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2033 wxSize size
= win
->GetClientSize();
2034 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2039 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2041 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
2043 m_window
->GetClientSize(width
, height
);
2046 //-----------------------------------------------------------------------------
2048 //-----------------------------------------------------------------------------
2050 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2052 // Limit the paint region to the window size. Sometimes
2053 // the paint region is too big, and this risks X11 errors
2054 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2056 wxRect originalRect
= region
.GetBox();
2057 wxRect
rect(originalRect
);
2058 if (rect
.width
+ rect
.x
> sz
.x
)
2059 rect
.width
= sz
.x
- rect
.x
;
2060 if (rect
.height
+ rect
.y
> sz
.y
)
2061 rect
.height
= sz
.y
- rect
.y
;
2062 if (rect
!= originalRect
)
2064 region
= wxRegion(rect
);
2065 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2066 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2067 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2071 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
2072 : wxClientDCImpl( owner
)
2076 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2077 : wxClientDCImpl( owner
, win
)
2079 #if USE_PAINT_REGION
2080 if (!win
->m_clipPaintRegion
)
2083 wxSize sz
= win
->GetSize();
2084 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2085 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2087 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2090 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2091 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2093 if (sz
.x
<= 0 || sz
.y
<= 0)
2096 gdk_gc_set_clip_region( m_penGC
, region
);
2097 gdk_gc_set_clip_region( m_brushGC
, region
);
2098 gdk_gc_set_clip_region( m_textGC
, region
);
2099 gdk_gc_set_clip_region( m_bgGC
, region
);
2104 // ----------------------------------------------------------------------------
2106 // ----------------------------------------------------------------------------
2108 class wxDCModule
: public wxModule
2115 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2118 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2120 bool wxDCModule::OnInit()
2126 void wxDCModule::OnExit()
2130 for (int i
= wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
; i
--; )
2133 g_object_unref(hatches
[i
]);