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 GdkPixmap
* GetHatch(int style
)
69 wxASSERT(style
>= wxBRUSHSTYLE_FIRST_HATCH
&& style
<= wxBRUSHSTYLE_LAST_HATCH
);
70 const int i
= style
- wxBRUSHSTYLE_FIRST_HATCH
;
71 if (hatches
[i
] == NULL
)
73 // This macro creates a bitmap from an XBM file included above. Notice
74 // the need for the cast because gdk_bitmap_create_from_data() doesn't
75 // accept unsigned data but the arrays in XBM need to be unsigned to
76 // avoid warnings (and even errors in C+0x mode) from g++.
77 #define CREATE_FROM_XBM_DATA(name) \
78 gdk_bitmap_create_from_data \
81 reinterpret_cast<gchar *>(name ## _bits), \
88 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
89 hatches
[i
] = CREATE_FROM_XBM_DATA(bdiag
);
91 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
92 hatches
[i
] = CREATE_FROM_XBM_DATA(cdiag
);
94 case wxBRUSHSTYLE_CROSS_HATCH
:
95 hatches
[i
] = CREATE_FROM_XBM_DATA(cross
);
97 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
98 hatches
[i
] = CREATE_FROM_XBM_DATA(fdiag
);
100 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
101 hatches
[i
] = CREATE_FROM_XBM_DATA(horiz
);
103 case wxBRUSHSTYLE_VERTICAL_HATCH
:
104 hatches
[i
] = CREATE_FROM_XBM_DATA(verti
);
108 #undef CREATE_FROM_XBM_DATA
113 //-----------------------------------------------------------------------------
114 // Implement Pool of Graphic contexts. Creating them takes too much time.
115 //-----------------------------------------------------------------------------
145 #define GC_POOL_ALLOC_SIZE 100
147 static int wxGCPoolSize
= 0;
149 static wxGC
*wxGCPool
= NULL
;
151 static void wxInitGCPool()
153 // This really could wait until the first call to
154 // wxGetPoolGC, but we will make the first allocation
155 // now when other initialization is being performed.
157 // Set initial pool size.
158 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
160 // Allocate initial pool.
161 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
162 if (wxGCPool
== NULL
)
164 // If we cannot malloc, then fail with error
165 // when debug is enabled. If debug is not enabled,
166 // the problem will eventually get caught
168 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
172 // Zero initial pool.
173 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
176 static void wxCleanUpGCPool()
178 for (int i
= 0; i
< wxGCPoolSize
; i
++)
180 if (wxGCPool
[i
].m_gc
)
181 g_object_unref (wxGCPool
[i
].m_gc
);
189 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
193 // Look for an available GC.
194 for (int i
= 0; i
< wxGCPoolSize
; i
++)
196 if (!wxGCPool
[i
].m_gc
)
198 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
199 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
200 wxGCPool
[i
].m_type
= type
;
201 wxGCPool
[i
].m_used
= false;
203 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
205 wxGCPool
[i
].m_used
= true;
206 return wxGCPool
[i
].m_gc
;
210 // We did not find an available GC.
211 // We need to grow the GC pool.
212 pptr
= (wxGC
*)realloc(wxGCPool
,
213 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
216 // Initialize newly allocated pool.
218 memset(&wxGCPool
[wxGCPoolSize
], 0,
219 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
221 // Initialize entry we will return.
222 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
223 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
224 wxGCPool
[wxGCPoolSize
].m_type
= type
;
225 wxGCPool
[wxGCPoolSize
].m_used
= true;
227 // Set new value of pool size.
228 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
230 // Return newly allocated entry.
231 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
234 // The realloc failed. Fall through to error.
235 wxFAIL_MSG( wxT("No GC available") );
240 static void wxFreePoolGC( GdkGC
*gc
)
242 for (int i
= 0; i
< wxGCPoolSize
; i
++)
244 if (wxGCPool
[i
].m_gc
== gc
)
246 wxGCPool
[i
].m_used
= false;
251 wxFAIL_MSG( wxT("Wrong GC") );
254 //-----------------------------------------------------------------------------
256 //-----------------------------------------------------------------------------
258 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
260 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
) :
269 m_isScreenDC
= false;
275 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
278 wxASSERT_MSG( window
, wxT("DC needs a window") );
286 m_isScreenDC
= false;
287 m_font
= window
->GetFont();
289 GtkWidget
*widget
= window
->m_wxwindow
;
290 m_gdkwindow
= window
->GTKGetDrawingWindow();
292 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
293 // code should still be able to create wxClientDCs for them
296 widget
= window
->m_widget
;
298 wxCHECK_RET(widget
, "DC needs a widget");
300 m_gdkwindow
= widget
->window
;
301 if (!gtk_widget_get_has_window(widget
))
302 SetDeviceLocalOrigin(widget
->allocation
.x
, widget
->allocation
.y
);
305 m_context
= window
->GTKGetPangoDefaultContext();
306 m_layout
= pango_layout_new( m_context
);
307 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
309 // Window not realized ?
312 // Don't report problems as per MSW.
318 m_cmap
= gtk_widget_get_colormap(widget
);
322 /* this must be done after SetUpDC, bacause SetUpDC calls the
323 repective SetBrush, SetPen, SetBackground etc functions
324 to set up the DC. SetBackground call m_owner->SetBackground
325 and this might not be desired as the standard dc background
326 is white whereas a window might assume gray to be the
327 standard (as e.g. wxStatusBar) */
331 if (m_window
&& m_window
->m_wxwindow
&&
332 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
337 // origin in the upper right corner
338 m_deviceOriginX
= m_window
->GetClientSize().x
;
342 wxWindowDCImpl::~wxWindowDCImpl()
347 g_object_unref (m_layout
);
349 pango_font_description_free( m_fontdesc
);
352 void wxWindowDCImpl::SetUpDC( bool isMemDC
)
356 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
360 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
362 if (GetSelectedBitmap().GetDepth() == 1)
364 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
365 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
366 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
367 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
376 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
377 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
378 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
379 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
381 #if GTK_CHECK_VERSION(2,12,0)
382 // gdk_screen_get_rgba_colormap was added in 2.8, but this code is for
383 // compositing which requires 2.12
384 else if (gtk_check_version(2,12,0) == NULL
&&
385 m_cmap
== gdk_screen_get_rgba_colormap(gdk_colormap_get_screen(m_cmap
)))
387 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR_ALPHA
);
388 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR_ALPHA
);
389 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR_ALPHA
);
390 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR_ALPHA
);
395 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
396 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
397 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
398 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
402 /* background colour */
403 m_backgroundBrush
= *wxWHITE_BRUSH
;
404 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
405 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
408 m_textForegroundColour
.CalcPixel( m_cmap
);
409 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
411 m_textBackgroundColour
.CalcPixel( m_cmap
);
412 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
414 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
416 gdk_gc_set_colormap( m_textGC
, m_cmap
);
419 m_pen
.GetColour().CalcPixel( m_cmap
);
420 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
421 gdk_gc_set_background( m_penGC
, bg_col
);
423 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
426 m_brush
.GetColour().CalcPixel( m_cmap
);
427 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
428 gdk_gc_set_background( m_brushGC
, bg_col
);
430 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
433 gdk_gc_set_background( m_bgGC
, bg_col
);
434 gdk_gc_set_foreground( m_bgGC
, bg_col
);
436 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
439 gdk_gc_set_function( m_textGC
, GDK_COPY
);
440 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
441 gdk_gc_set_function( m_penGC
, GDK_COPY
);
444 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
445 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
446 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
447 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
450 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
452 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
454 m_window
->GetSize(width
, height
);
457 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
458 const wxColour
& col
, wxFloodFillStyle style
)
461 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
462 const wxColour
& col
, wxFloodFillStyle style
);
464 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
475 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
477 GdkImage
* image
= NULL
;
480 const int x
= LogicalToDeviceX(x1
);
481 const int y
= LogicalToDeviceY(y1
);
483 gdk_drawable_get_size(m_gdkwindow
, &rect
.width
, &rect
.height
);
484 if (rect
.Contains(x
, y
))
485 image
= gdk_drawable_get_image(m_gdkwindow
, x
, y
, 1, 1);
492 GdkColormap
* colormap
= gdk_image_get_colormap(image
);
493 const unsigned pixel
= gdk_image_get_pixel(image
, 0, 0);
494 if (colormap
== NULL
)
495 *col
= pixel
? m_textForegroundColour
: m_textBackgroundColour
;
499 gdk_colormap_query_color(colormap
, pixel
, &c
);
500 col
->Set(c
.red
>> 8, c
.green
>> 8, c
.blue
>> 8);
502 g_object_unref(image
);
506 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
508 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
510 if ( m_pen
.IsNonTransparent() )
513 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
515 CalcBoundingBox(x1
, y1
);
516 CalcBoundingBox(x2
, y2
);
520 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
522 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
524 if ( m_pen
.IsNonTransparent() )
528 GetOwner()->GetSize( &w
, &h
);
529 wxCoord xx
= XLOG2DEV(x
);
530 wxCoord yy
= YLOG2DEV(y
);
533 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
534 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
539 void wxWindowDCImpl::DrawingSetup(GdkGC
*& gc
, bool& originChanged
)
542 GdkPixmap
* pixmap
= NULL
;
543 const int style
= m_brush
.GetStyle();
545 if (style
== wxBRUSHSTYLE_STIPPLE
|| style
== wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
)
547 const wxBitmap
* stipple
= m_brush
.GetStipple();
550 if (style
== wxBRUSHSTYLE_STIPPLE
)
551 pixmap
= stipple
->GetPixmap();
552 else if (stipple
->GetMask())
554 pixmap
= stipple
->GetPixmap();
559 else if (m_brush
.IsHatch())
561 pixmap
= GetHatch(style
);
569 gdk_drawable_get_size(pixmap
, &w
, &h
);
570 origin_x
= m_deviceOriginX
% w
;
571 origin_y
= m_deviceOriginY
% h
;
574 originChanged
= origin_x
|| origin_y
;
576 gdk_gc_set_ts_origin(gc
, origin_x
, origin_y
);
579 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
580 wxCoord xc
, wxCoord yc
)
582 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
584 wxCoord xx1
= XLOG2DEV(x1
);
585 wxCoord yy1
= YLOG2DEV(y1
);
586 wxCoord xx2
= XLOG2DEV(x2
);
587 wxCoord yy2
= YLOG2DEV(y2
);
588 wxCoord xxc
= XLOG2DEV(xc
);
589 wxCoord yyc
= YLOG2DEV(yc
);
590 double dx
= xx1
- xxc
;
591 double dy
= yy1
- yyc
;
592 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
593 wxCoord r
= (wxCoord
)radius
;
594 double radius1
, radius2
;
596 if (xx1
== xx2
&& yy1
== yy2
)
601 else if ( wxIsNullDouble(radius
) )
608 radius1
= (xx1
- xxc
== 0) ?
609 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
610 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
611 radius2
= (xx2
- xxc
== 0) ?
612 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
613 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
615 wxCoord alpha1
= wxCoord(radius1
* 64.0);
616 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
617 while (alpha2
<= 0) alpha2
+= 360*64;
618 while (alpha1
> 360*64) alpha1
-= 360*64;
622 if ( m_brush
.IsNonTransparent() )
626 DrawingSetup(gc
, originChanged
);
628 gdk_draw_arc(m_gdkwindow
, gc
, true, xxc
-r
, yyc
-r
, 2*r
, 2*r
, alpha1
, alpha2
);
631 gdk_gc_set_ts_origin(gc
, 0, 0);
634 if ( m_pen
.IsNonTransparent() )
636 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
638 if ( m_brush
.IsNonTransparent() && (alpha2
- alpha1
!= 360*64) )
640 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
641 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
646 CalcBoundingBox (x1
, y1
);
647 CalcBoundingBox (x2
, y2
);
650 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
652 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
654 wxCoord xx
= XLOG2DEV(x
);
655 wxCoord yy
= YLOG2DEV(y
);
656 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
657 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
659 // CMB: handle -ve width and/or height
660 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
661 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
665 wxCoord start
= wxCoord(sa
* 64.0);
666 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
668 if ( m_brush
.IsNonTransparent() )
672 DrawingSetup(gc
, originChanged
);
674 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, start
, end
);
677 gdk_gc_set_ts_origin(gc
, 0, 0);
680 if ( m_pen
.IsNonTransparent() )
681 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
684 CalcBoundingBox (x
, y
);
685 CalcBoundingBox (x
+ width
, y
+ height
);
688 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
690 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
692 if ( m_pen
.IsNonTransparent() && m_gdkwindow
)
693 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
695 CalcBoundingBox (x
, y
);
698 void wxWindowDCImpl::DoDrawLines( int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
700 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
704 if ( m_pen
.IsTransparent() )
707 //Check, if scaling is necessary
709 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
711 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
712 const GdkPoint
* gpts
= reinterpret_cast<const GdkPoint
*>(points
);
713 GdkPoint
* gpts_alloc
= NULL
;
717 gpts_alloc
= new GdkPoint
[n
];
721 for (int i
= 0; i
< n
; i
++)
725 gpts_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
726 gpts_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
728 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
732 gdk_draw_lines( m_gdkwindow
, m_penGC
, (GdkPoint
*) gpts
, n
);
737 void wxWindowDCImpl::DoDrawPolygon( int n
, const wxPoint points
[],
738 wxCoord xoffset
, wxCoord yoffset
,
739 wxPolygonFillMode
WXUNUSED(fillStyle
) )
741 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
745 //Check, if scaling is necessary
747 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
749 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
750 const GdkPoint
* gdkpoints
= reinterpret_cast<const GdkPoint
*>(points
);
751 GdkPoint
* gdkpoints_alloc
= NULL
;
755 gdkpoints_alloc
= new GdkPoint
[n
];
756 gdkpoints
= gdkpoints_alloc
;
760 for (i
= 0 ; i
< n
; i
++)
764 gdkpoints_alloc
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
765 gdkpoints_alloc
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
767 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
772 if ( m_brush
.IsNonTransparent() )
776 DrawingSetup(gc
, originChanged
);
778 gdk_draw_polygon(m_gdkwindow
, gc
, true, (GdkPoint
*) gdkpoints
, n
);
781 gdk_gc_set_ts_origin(gc
, 0, 0);
784 if ( m_pen
.IsNonTransparent() )
787 for (i = 0 ; i < n ; i++)
789 gdk_draw_line( m_gdkwindow, m_penGC,
792 gdkpoints[(i+1)%n].x,
793 gdkpoints[(i+1)%n].y);
796 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, (GdkPoint
*) gdkpoints
, n
);
801 delete[] gdkpoints_alloc
;
804 void wxWindowDCImpl::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
806 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
808 wxCoord xx
= XLOG2DEV(x
);
809 wxCoord yy
= YLOG2DEV(y
);
810 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
811 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
813 // CMB: draw nothing if transformed w or h is 0
814 if (ww
== 0 || hh
== 0) return;
816 // CMB: handle -ve width and/or height
817 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
818 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
822 if ( m_brush
.IsNonTransparent() )
826 DrawingSetup(gc
, originChanged
);
828 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
);
831 gdk_gc_set_ts_origin(gc
, 0, 0);
834 if ( m_pen
.IsNonTransparent() )
836 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
837 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxPENSTYLE_SOLID
))
839 // Use 2 1-line rects instead
840 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
845 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
846 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
850 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
851 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
855 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
859 // Just use X11 for other cases
860 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
865 CalcBoundingBox( x
, y
);
866 CalcBoundingBox( x
+ width
, y
+ height
);
869 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
871 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
873 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
875 wxCoord xx
= XLOG2DEV(x
);
876 wxCoord yy
= YLOG2DEV(y
);
877 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
878 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
879 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
881 // CMB: handle -ve width and/or height
882 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
883 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
885 // CMB: if radius is zero use DrawRectangle() instead to avoid
886 // X drawing errors with small radii
889 DoDrawRectangle( x
, y
, width
, height
);
893 // CMB: draw nothing if transformed w or h is 0
894 if (ww
== 0 || hh
== 0) return;
896 // CMB: adjust size if outline is drawn otherwise the result is
897 // 1 pixel too wide and high
898 if ( m_pen
.IsNonTransparent() )
906 // CMB: ensure dd is not larger than rectangle otherwise we
907 // get an hour glass shape
909 if (dd
> ww
) dd
= ww
;
910 if (dd
> hh
) dd
= hh
;
913 if ( m_brush
.IsNonTransparent() )
917 DrawingSetup(gc
, originChanged
);
919 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
+rr
, yy
, ww
-dd
+1, hh
);
920 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
+rr
, ww
, hh
-dd
+1);
921 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, dd
, dd
, 90*64, 90*64);
922 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64);
923 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64);
924 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64);
927 gdk_gc_set_ts_origin(gc
, 0, 0);
930 if ( m_pen
.IsNonTransparent() )
932 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
933 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
934 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
935 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
936 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
937 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
938 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
939 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
943 // this ignores the radius
944 CalcBoundingBox( x
, y
);
945 CalcBoundingBox( x
+ width
, y
+ height
);
948 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
950 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
952 wxCoord xx
= XLOG2DEV(x
);
953 wxCoord yy
= YLOG2DEV(y
);
954 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
955 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
957 // CMB: handle -ve width and/or height
958 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
959 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
963 if ( m_brush
.IsNonTransparent() )
967 DrawingSetup(gc
, originChanged
);
969 // If the pen is transparent pen we increase the size
970 // for better compatibility with other platforms.
971 if (m_pen
.IsTransparent())
977 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, 0, 360*64);
980 gdk_gc_set_ts_origin(gc
, 0, 0);
983 if ( m_pen
.IsNonTransparent() )
984 gdk_draw_arc( m_gdkwindow
, m_penGC
, false, xx
, yy
, ww
, hh
, 0, 360*64 );
987 CalcBoundingBox( x
, y
);
988 CalcBoundingBox( x
+ width
, y
+ height
);
991 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
993 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
994 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
999 Scale(GdkPixbuf
* pixbuf
, int dst_w
, int dst_h
, double sx
, double sy
)
1001 GdkPixbuf
* pixbuf_scaled
= gdk_pixbuf_new(
1002 GDK_COLORSPACE_RGB
, gdk_pixbuf_get_has_alpha(pixbuf
), 8, dst_w
, dst_h
);
1003 gdk_pixbuf_scale(pixbuf
, pixbuf_scaled
,
1004 0, 0, dst_w
, dst_h
, 0, 0, sx
, sy
, GDK_INTERP_NEAREST
);
1005 return pixbuf_scaled
;
1008 // scale part of a pixmap using pixbuf scaling
1010 Scale(GdkPixmap
* pixmap
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1012 GdkPixbuf
* pixbuf
= gdk_pixbuf_get_from_drawable(
1013 NULL
, pixmap
, NULL
, x
, y
, 0, 0, w
, h
);
1014 GdkPixbuf
* pixbuf2
= Scale(pixbuf
, dst_w
, dst_h
, sx
, sy
);
1015 g_object_unref(pixbuf
);
1019 // scale part of a mask pixmap
1021 ScaleMask(GdkPixmap
* mask
, int x
, int y
, int w
, int h
, int dst_w
, int dst_h
, double sx
, double sy
)
1023 GdkPixbuf
* pixbuf
= Scale(mask
, x
, y
, w
, h
, dst_w
, dst_h
, sx
, sy
);
1025 // convert black and white pixbuf back to a mono pixmap
1026 const unsigned out_rowstride
= (dst_w
+ 7) / 8;
1027 const size_t data_size
= out_rowstride
* size_t(dst_h
);
1028 char* data
= new char[data_size
];
1030 const guchar
* row
= gdk_pixbuf_get_pixels(pixbuf
);
1031 const int rowstride
= gdk_pixbuf_get_rowstride(pixbuf
);
1032 memset(data
, 0, data_size
);
1033 for (int j
= 0; j
< dst_h
; j
++, row
+= rowstride
, out
+= out_rowstride
)
1035 const guchar
* in
= row
;
1036 for (int i
= 0; i
< dst_w
; i
++, in
+= 3)
1038 out
[i
>> 3] |= 1 << (i
& 7);
1040 g_object_unref(pixbuf
);
1041 GdkPixmap
* pixmap
= gdk_bitmap_create_from_data(mask
, data
, dst_w
, dst_h
);
1046 // Make a new mask from part of a mask and a clip region.
1048 ClipMask(GdkPixmap
* mask
, GdkRegion
* clipRegion
, int x
, int y
, int dst_x
, int dst_y
, int w
, int h
)
1050 GdkGCValues gcValues
;
1051 gcValues
.foreground
.pixel
= 0;
1052 GdkGC
* gc
= gdk_gc_new_with_values(mask
, &gcValues
, GDK_GC_FOREGROUND
);
1053 GdkPixmap
* pixmap
= gdk_pixmap_new(mask
, w
, h
, 1);
1054 // clear new mask, so clipped areas will be masked
1055 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1056 gdk_gc_set_clip_region(gc
, clipRegion
);
1057 gdk_gc_set_clip_origin(gc
, -dst_x
, -dst_y
);
1058 // draw old mask onto new one, with clip
1059 gdk_draw_drawable(pixmap
, gc
, mask
, x
, y
, 0, 0, w
, h
);
1064 // make a color pixmap from part of a mono one, using text fg/bg colors
1066 wxWindowDCImpl::MonoToColor(GdkPixmap
* monoPixmap
, int x
, int y
, int w
, int h
) const
1068 GdkPixmap
* pixmap
= gdk_pixmap_new(m_gdkwindow
, w
, h
, -1);
1069 GdkGCValues gcValues
;
1070 gcValues
.foreground
.pixel
= m_textForegroundColour
.GetColor()->pixel
;
1071 gcValues
.background
.pixel
= m_textBackgroundColour
.GetColor()->pixel
;
1072 gcValues
.stipple
= monoPixmap
;
1073 gcValues
.fill
= GDK_OPAQUE_STIPPLED
;
1074 gcValues
.ts_x_origin
= -x
;
1075 gcValues
.ts_y_origin
= -y
;
1076 GdkGC
* gc
= gdk_gc_new_with_values(pixmap
, &gcValues
, GdkGCValuesMask(
1077 GDK_GC_FOREGROUND
| GDK_GC_BACKGROUND
| GDK_GC_STIPPLE
| GDK_GC_FILL
|
1078 GDK_GC_TS_X_ORIGIN
| GDK_GC_TS_Y_ORIGIN
));
1079 gdk_draw_rectangle(pixmap
, gc
, true, 0, 0, w
, h
);
1084 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
1085 wxCoord x
, wxCoord y
,
1088 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1089 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1091 if (!m_gdkwindow
) return;
1093 const int w
= bitmap
.GetWidth();
1094 const int h
= bitmap
.GetHeight();
1096 // notice that as the bitmap is not drawn upside down (or right to left)
1097 // even if the corresponding axis direction is inversed, we need to take it
1098 // into account when calculating its bounding box
1099 CalcBoundingBox(x
, y
);
1100 CalcBoundingBox(x
+ m_signX
*w
, y
+ m_signY
*h
);
1103 int xx
= LogicalToDeviceX(x
);
1104 const int yy
= LogicalToDeviceY(y
);
1105 const int ww
= LogicalToDeviceXRel(w
);
1106 const int hh
= LogicalToDeviceYRel(h
);
1108 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1111 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1112 // determine clip region overlap
1113 int overlap
= wxInRegion
;
1116 overlap
= m_currentClippingRegion
.Contains(xx
, yy
, ww
, hh
);
1117 if (overlap
== wxOutRegion
)
1121 const bool isScaled
= ww
!= w
|| hh
!= h
;
1122 const bool hasAlpha
= bitmap
.HasAlpha();
1123 GdkGC
* const use_gc
= m_penGC
;
1125 GdkPixmap
* mask
= NULL
;
1126 // mask does not work when drawing a pixbuf with alpha
1127 if (useMask
&& !hasAlpha
)
1129 wxMask
* m
= bitmap
.GetMask();
1134 GdkPixmap
* mask_new
= NULL
;
1139 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 g_object_unref(mask_new
);
1151 gdk_gc_set_clip_mask(use_gc
, mask
);
1152 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1155 // determine whether to use pixmap or pixbuf
1156 GdkPixmap
* pixmap
= NULL
;
1157 GdkPixmap
* pixmap_new
= NULL
;
1158 GdkPixbuf
* pixbuf
= NULL
;
1159 GdkPixbuf
* pixbuf_new
= NULL
;
1160 if (bitmap
.HasPixmap())
1161 pixmap
= bitmap
.GetPixmap();
1162 if (pixmap
&& gdk_drawable_get_depth(pixmap
) == 1)
1164 if (gdk_drawable_get_depth(m_gdkwindow
) != 1)
1166 // convert mono pixmap to color using text fg/bg colors
1167 pixmap
= MonoToColor(pixmap
, 0, 0, w
, h
);
1168 pixmap_new
= pixmap
;
1171 else if (hasAlpha
|| pixmap
== NULL
)
1172 pixbuf
= bitmap
.GetPixbuf();
1177 pixbuf
= Scale(pixbuf
, ww
, hh
, m_scaleX
, m_scaleY
);
1179 pixbuf
= Scale(pixmap
, 0, 0, w
, h
, ww
, hh
, m_scaleX
, m_scaleY
);
1181 pixbuf_new
= pixbuf
;
1186 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1187 0, 0, xx
, yy
, ww
, hh
, GDK_RGB_DITHER_NORMAL
, 0, 0);
1191 gdk_draw_drawable(m_gdkwindow
, use_gc
, pixmap
, 0, 0, xx
, yy
, ww
, hh
);
1195 g_object_unref(pixbuf_new
);
1197 g_object_unref(pixmap_new
);
1200 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1202 // Notice that we can only release the mask now, we can't do it before
1203 // the calls to gdk_draw_xxx() above as they crash with X error with
1204 // GTK+ up to 2.20.1 (i.e. it works with 2.20 but is known to not work
1205 // with 2.16.1 and below).
1207 g_object_unref(mask_new
);
1211 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1212 wxCoord width
, wxCoord height
,
1214 wxCoord xsrc
, wxCoord ysrc
,
1215 wxRasterOperationMode logical_func
,
1217 wxCoord xsrcMask
, wxCoord ysrcMask
)
1219 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1220 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1222 if (!m_gdkwindow
) return false;
1224 GdkDrawable
* srcDrawable
= NULL
;
1225 GdkPixmap
* mask
= NULL
;
1226 wxMemoryDC
* memDC
= wxDynamicCast(source
, wxMemoryDC
);
1229 const wxBitmap
& bitmap
= memDC
->GetSelectedBitmap();
1232 srcDrawable
= bitmap
.GetPixmap();
1235 wxMask
* m
= bitmap
.GetMask();
1242 wxDCImpl
* impl
= source
->GetImpl();
1243 wxWindowDCImpl
* gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1245 srcDrawable
= gtk_impl
->GetGDKWindow();
1246 if (srcDrawable
== NULL
)
1250 CalcBoundingBox(xdest
, ydest
);
1251 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1253 // source device coords
1254 int src_x
= source
->LogicalToDeviceX(xsrc
);
1255 int src_y
= source
->LogicalToDeviceY(ysrc
);
1256 int src_w
= source
->LogicalToDeviceXRel(width
);
1257 int src_h
= source
->LogicalToDeviceYRel(height
);
1259 // Clip source rect to source dc.
1260 // Only necessary when scaling, to avoid GDK errors when
1261 // converting to pixbuf, but no harm in always doing it.
1262 // If source rect changes, it also changes the dest rect.
1264 gdk_drawable_get_size(srcDrawable
, &clip
.width
, &clip
.height
);
1265 clip
.Intersect(wxRect(src_x
, src_y
, src_w
, src_h
));
1266 if (src_w
!= clip
.width
|| src_h
!= clip
.height
)
1268 if (clip
.width
== 0)
1272 src_h
= clip
.height
;
1273 width
= source
->DeviceToLogicalXRel(src_w
);
1274 height
= source
->DeviceToLogicalYRel(src_h
);
1275 if (src_x
!= clip
.x
|| src_y
!= clip
.y
)
1277 xdest
+= source
->DeviceToLogicalXRel(clip
.x
- src_x
);
1278 ydest
+= source
->DeviceToLogicalYRel(clip
.y
- src_y
);
1284 // destination device coords
1285 const int dst_x
= LogicalToDeviceX(xdest
);
1286 const int dst_y
= LogicalToDeviceY(ydest
);
1287 const int dst_w
= LogicalToDeviceXRel(width
);
1288 const int dst_h
= LogicalToDeviceYRel(height
);
1290 GdkRegion
* const clipRegion
= m_currentClippingRegion
.GetRegion();
1291 // determine dest clip region overlap
1292 int overlap
= wxInRegion
;
1295 overlap
= m_currentClippingRegion
.Contains(dst_x
, dst_y
, dst_w
, dst_h
);
1296 if (overlap
== wxOutRegion
)
1300 const bool isScaled
= src_w
!= dst_w
|| src_h
!= dst_h
;
1305 // get source to dest scale
1306 double usx
, usy
, lsx
, lsy
;
1307 source
->GetUserScale(&usx
, &usy
);
1308 source
->GetLogicalScale(&lsx
, &lsy
);
1309 scale_x
= m_scaleX
/ (usx
* lsx
);
1310 scale_y
= m_scaleY
/ (usy
* lsy
);
1313 GdkGC
* const use_gc
= m_penGC
;
1317 int srcMask_x
= src_x
;
1318 int srcMask_y
= src_y
;
1319 if (xsrcMask
!= -1 || ysrcMask
!= -1)
1321 srcMask_x
= source
->LogicalToDeviceX(xsrcMask
);
1322 srcMask_y
= source
->LogicalToDeviceY(ysrcMask
);
1324 GdkPixmap
* mask_new
= NULL
;
1327 mask
= ScaleMask(mask
, srcMask_x
, srcMask_y
,
1328 src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1333 if (overlap
== wxPartRegion
)
1335 // need a new mask that also masks the clipped area,
1336 // because gc can't have both a mask and a clip region
1337 mask
= ClipMask(mask
, clipRegion
,
1338 srcMask_x
, srcMask_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1340 g_object_unref(mask_new
);
1345 gdk_gc_set_clip_mask(use_gc
, mask
);
1346 gdk_gc_set_clip_origin(use_gc
, dst_x
- srcMask_x
, dst_y
- srcMask_y
);
1348 g_object_unref(mask_new
);
1351 GdkPixmap
* pixmap
= NULL
;
1352 if (gdk_drawable_get_depth(srcDrawable
) == 1 &&
1353 (gdk_drawable_get_depth(m_gdkwindow
) != 1 || isScaled
))
1355 // Convert mono pixmap to color using text fg/bg colors.
1356 // Scaling/drawing is simpler if this is done first.
1357 pixmap
= MonoToColor(srcDrawable
, src_x
, src_y
, src_w
, src_h
);
1358 srcDrawable
= pixmap
;
1363 const wxRasterOperationMode logical_func_save
= m_logicalFunction
;
1364 SetLogicalFunction(logical_func
);
1366 gdk_gc_set_subwindow(use_gc
, GDK_INCLUDE_INFERIORS
);
1370 GdkPixbuf
* pixbuf
= Scale(srcDrawable
,
1371 src_x
, src_y
, src_w
, src_h
, dst_w
, dst_h
, scale_x
, scale_y
);
1372 gdk_draw_pixbuf(m_gdkwindow
, use_gc
, pixbuf
,
1373 0, 0, dst_x
, dst_y
, dst_w
, dst_h
, GDK_RGB_DITHER_NONE
, 0, 0);
1374 g_object_unref(pixbuf
);
1378 gdk_draw_drawable(m_gdkwindow
, use_gc
, srcDrawable
,
1379 src_x
, src_y
, dst_x
, dst_y
, dst_w
, dst_h
);
1382 SetLogicalFunction(logical_func_save
);
1384 gdk_gc_set_subwindow(use_gc
, GDK_CLIP_BY_CHILDREN
);
1387 g_object_unref(pixmap
);
1389 gdk_gc_set_clip_region(use_gc
, clipRegion
);
1394 void wxWindowDCImpl::DoDrawText(const wxString
& text
,
1398 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1400 if (!m_gdkwindow
) return;
1402 if (text
.empty()) return;
1404 wxCoord x
= XLOG2DEV(xLogical
),
1405 y
= YLOG2DEV(yLogical
);
1407 wxCHECK_RET( m_context
, wxT("no Pango context") );
1408 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1410 wxCharBuffer data
= wxGTK_CONV(text
);
1414 pango_layout_set_text(m_layout
, data
, data
.length());
1415 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1418 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1420 PangoMatrix matrix
= PANGO_MATRIX_INIT
;
1421 pango_matrix_scale(&matrix
, m_scaleX
, m_scaleY
);
1422 pango_context_set_matrix(m_context
, &matrix
);
1423 pango_layout_context_changed(m_layout
);
1427 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1430 const GdkColor
* bg_col
= NULL
;
1431 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1432 bg_col
= m_textBackgroundColour
.GetColor();
1434 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x_rtl
, y
, m_layout
, NULL
, bg_col
);
1436 pango_context_set_matrix(m_context
, NULL
);
1439 // undo underline attributes setting:
1440 pango_layout_set_attributes(m_layout
, NULL
);
1443 CalcBoundingBox(xLogical
+ int(w
/ m_scaleX
), yLogical
+ int(h
/ m_scaleY
));
1444 CalcBoundingBox(xLogical
, yLogical
);
1447 // TODO: When GTK2.6 is required, merge DoDrawText and DoDrawRotatedText to
1448 // avoid code duplication
1449 void wxWindowDCImpl::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1451 if (!m_gdkwindow
|| text
.empty())
1454 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1459 pango_layout_set_text(m_layout
, wxGTK_CONV(text
), -1);
1460 const bool setAttrs
= m_font
.GTKSetPangoAttrs(m_layout
);
1463 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1465 const GdkColor
* bg_col
= NULL
;
1466 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1467 bg_col
= m_textBackgroundColour
.GetColor();
1470 PangoMatrix matrix
= PANGO_MATRIX_INIT
;
1471 pango_matrix_scale(&matrix
, m_scaleX
, m_scaleY
);
1472 pango_matrix_rotate (&matrix
, angle
);
1473 pango_context_set_matrix (m_context
, &matrix
);
1474 pango_layout_context_changed (m_layout
);
1476 // To be compatible with MSW, the rotation axis must be in the old
1478 // Calculate the vertices of the rotated rectangle containing the text,
1479 // relative to the old top-left vertex.
1480 // the rectangle vertices are counted clockwise with the first one
1482 double x2
= w
* matrix
.xx
;
1483 double y2
= w
* matrix
.yx
;
1484 double x4
= h
* matrix
.xy
;
1485 double y4
= h
* matrix
.yy
;
1486 double x3
= x4
+ x2
;
1487 double y3
= y4
+ y2
;
1488 // Then we calculate max and min of the rotated rectangle.
1489 wxCoord maxX
= (wxCoord
)(dmax(dmax(0, x2
), dmax(x3
, x4
)) + 0.5),
1490 maxY
= (wxCoord
)(dmax(dmax(0, y2
), dmax(y3
, y4
)) + 0.5),
1491 minX
= (wxCoord
)(dmin(dmin(0, x2
), dmin(x3
, x4
)) - 0.5),
1492 minY
= (wxCoord
)(dmin(dmin(0, y2
), dmin(y3
, y4
)) - 0.5);
1494 gdk_draw_layout_with_colors(m_gdkwindow
, m_textGC
, x
+minX
, y
+minY
,
1495 m_layout
, NULL
, bg_col
);
1498 pango_layout_set_attributes(m_layout
, NULL
);
1500 // clean up the transformation matrix
1501 pango_context_set_matrix(m_context
, NULL
);
1503 CalcBoundingBox(x
+minX
, y
+minY
);
1504 CalcBoundingBox(x
+maxX
, y
+maxY
);
1507 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1508 wxCoord
*width
, wxCoord
*height
,
1509 wxCoord
*descent
, wxCoord
*externalLeading
,
1510 const wxFont
*theFont
) const
1512 // ensure we work with a valid font
1513 const wxFont
*fontToUse
;
1514 if ( !theFont
|| !theFont
->IsOk() )
1515 fontToUse
= &m_font
;
1517 fontToUse
= theFont
;
1519 wxCHECK_RET( fontToUse
->IsOk(), wxT("invalid font") );
1521 wxTextMeasure
txm(GetOwner(), fontToUse
);
1522 txm
.GetTextExtent(string
, width
, height
, descent
, externalLeading
);
1526 bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString
& text
,
1527 wxArrayInt
& widths
) const
1529 wxCHECK_MSG( m_font
.IsOk(), false, wxT("Invalid font") );
1531 wxTextMeasure
txm(GetOwner(), &m_font
);
1532 return txm
.GetPartialTextExtents(text
, widths
, m_scaleX
);
1536 wxCoord
wxWindowDCImpl::GetCharWidth() const
1538 pango_layout_set_text( m_layout
, "H", 1 );
1540 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1544 wxCoord
wxWindowDCImpl::GetCharHeight() const
1546 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1547 wxCHECK_MSG( metrics
, -1, wxT("failed to get pango font metrics") );
1549 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1550 pango_font_metrics_get_ascent (metrics
));
1551 pango_font_metrics_unref (metrics
);
1555 void wxWindowDCImpl::Clear()
1557 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1559 if (!m_gdkwindow
) return;
1562 DoGetSize( &width
, &height
);
1563 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1566 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1573 pango_font_description_free( m_fontdesc
);
1575 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1580 PangoContext
*oldContext
= m_context
;
1582 m_context
= m_window
->GTKGetPangoDefaultContext();
1584 // If we switch back/forth between different contexts
1585 // we also have to create a new layout. I think so,
1586 // at least, and it doesn't hurt to do it.
1587 if (oldContext
!= m_context
)
1590 g_object_unref (m_layout
);
1592 m_layout
= pango_layout_new( m_context
);
1596 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1600 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1602 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1604 if (m_pen
== pen
) return;
1608 if (!m_pen
.IsOk()) return;
1610 if (!m_gdkwindow
) return;
1612 gint width
= m_pen
.GetWidth();
1615 // CMB: if width is non-zero scale it with the dc
1620 // X doesn't allow different width in x and y and so we take
1623 ( fabs((double) XLOG2DEVREL(width
)) +
1624 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1628 // width can't be 0 or an internal GTK error occurs inside
1629 // gdk_gc_set_dashes() below
1634 static const wxGTKDash dotted
[] = {1, 1};
1635 static const wxGTKDash short_dashed
[] = {2, 2};
1636 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1637 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1639 // We express dash pattern in pen width unit, so we are
1640 // independent of zoom factor and so on...
1642 const wxGTKDash
*req_dash
;
1644 GdkLineStyle lineStyle
= GDK_LINE_ON_OFF_DASH
;
1645 switch (m_pen
.GetStyle())
1647 case wxPENSTYLE_USER_DASH
:
1648 req_nb_dash
= m_pen
.GetDashCount();
1649 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1651 case wxPENSTYLE_DOT
:
1655 case wxPENSTYLE_LONG_DASH
:
1657 req_dash
= wxCoord_dashed
;
1659 case wxPENSTYLE_SHORT_DASH
:
1661 req_dash
= short_dashed
;
1663 case wxPENSTYLE_DOT_DASH
:
1665 req_dash
= dotted_dashed
;
1668 case wxPENSTYLE_TRANSPARENT
:
1669 case wxPENSTYLE_STIPPLE_MASK_OPAQUE
:
1670 case wxPENSTYLE_STIPPLE
:
1671 case wxPENSTYLE_SOLID
:
1673 lineStyle
= GDK_LINE_SOLID
;
1679 if (req_dash
&& req_nb_dash
)
1681 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1684 for (int i
= 0; i
< req_nb_dash
; i
++)
1685 real_req_dash
[i
] = req_dash
[i
] * width
;
1686 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1687 delete[] real_req_dash
;
1691 // No Memory. We use non-scaled dash pattern...
1692 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1696 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1697 switch (m_pen
.GetCap())
1699 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1700 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1706 capStyle
= GDK_CAP_NOT_LAST
;
1711 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1712 switch (m_pen
.GetJoin())
1714 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1715 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1717 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1720 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1722 m_pen
.GetColour().CalcPixel( m_cmap
);
1723 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1726 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
1728 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1730 if (m_brush
== brush
) return;
1734 if (!m_brush
.IsOk()) return;
1736 if (!m_gdkwindow
) return;
1738 m_brush
.GetColour().CalcPixel( m_cmap
);
1739 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1741 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1743 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1745 if (m_brush
.GetStipple()->GetDepth() != 1)
1747 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1748 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1752 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1753 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1757 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1759 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1760 gdk_gc_set_stipple( m_textGC
, *m_brush
.GetStipple()->GetMask() );
1763 if (m_brush
.IsHatch())
1765 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1766 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
1770 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
1772 /* CMB 21/7/98: Added SetBackground. Sets background brush
1773 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1775 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1777 if (m_backgroundBrush
== brush
) return;
1779 m_backgroundBrush
= brush
;
1781 if (!m_backgroundBrush
.IsOk()) return;
1783 if (!m_gdkwindow
) return;
1785 wxColor color
= m_backgroundBrush
.GetColour();
1786 color
.CalcPixel(m_cmap
);
1787 const GdkColor
* gdkColor
= color
.GetColor();
1788 gdk_gc_set_background(m_brushGC
, gdkColor
);
1789 gdk_gc_set_background(m_penGC
, gdkColor
);
1790 gdk_gc_set_background(m_bgGC
, gdkColor
);
1791 gdk_gc_set_foreground(m_bgGC
, gdkColor
);
1794 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1796 if (m_backgroundBrush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
)
1798 const wxBitmap
* stipple
= m_backgroundBrush
.GetStipple();
1799 if (stipple
->IsOk())
1801 if (stipple
->GetDepth() != 1)
1803 gdk_gc_set_fill(m_bgGC
, GDK_TILED
);
1804 gdk_gc_set_tile(m_bgGC
, stipple
->GetPixmap());
1808 gdk_gc_set_fill(m_bgGC
, GDK_STIPPLED
);
1809 gdk_gc_set_stipple(m_bgGC
, stipple
->GetPixmap());
1813 else if (m_backgroundBrush
.IsHatch())
1815 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1816 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
1820 void wxWindowDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1822 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1824 if (m_logicalFunction
== function
)
1827 // VZ: shouldn't this be a CHECK?
1834 case wxXOR
: mode
= GDK_XOR
; break;
1835 case wxINVERT
: mode
= GDK_INVERT
; break;
1836 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1837 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1838 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1839 case wxSET
: mode
= GDK_SET
; break;
1840 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1841 case wxAND
: mode
= GDK_AND
; break;
1842 case wxOR
: mode
= GDK_OR
; break;
1843 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1844 case wxNAND
: mode
= GDK_NAND
; break;
1845 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1846 case wxCOPY
: mode
= GDK_COPY
; break;
1847 case wxNO_OP
: mode
= GDK_NOOP
; break;
1848 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1849 case wxNOR
: mode
= GDK_NOR
; break;
1851 wxFAIL_MSG("unknown mode");
1855 m_logicalFunction
= function
;
1857 gdk_gc_set_function( m_penGC
, mode
);
1858 gdk_gc_set_function( m_brushGC
, mode
);
1860 // to stay compatible with wxMSW, we don't apply ROPs to the text
1861 // operations (i.e. DrawText/DrawRotatedText).
1862 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1863 gdk_gc_set_function( m_textGC
, mode
);
1866 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
1868 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1870 // don't set m_textForegroundColour to an invalid colour as we'd crash
1871 // later then (we use m_textForegroundColour.GetColor() without checking
1873 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
1876 m_textForegroundColour
= col
;
1880 m_textForegroundColour
.CalcPixel( m_cmap
);
1881 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1885 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
1887 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1890 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
1893 m_textBackgroundColour
= col
;
1897 m_textBackgroundColour
.CalcPixel( m_cmap
);
1898 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1902 void wxWindowDCImpl::SetBackgroundMode( int mode
)
1904 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1906 m_backgroundMode
= mode
;
1909 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1911 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
1914 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1916 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1918 if (!m_gdkwindow
) return;
1921 rect
.x
= XLOG2DEV(x
);
1922 rect
.y
= YLOG2DEV(y
);
1923 rect
.width
= XLOG2DEVREL(width
);
1924 rect
.height
= YLOG2DEVREL(height
);
1926 if (m_window
&& m_window
->m_wxwindow
&&
1927 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
1929 rect
.x
-= rect
.width
;
1932 DoSetDeviceClippingRegion(wxRegion(rect
));
1935 void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion
®ion
)
1937 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1941 DestroyClippingRegion();
1945 if (!m_gdkwindow
) return;
1947 if (!m_currentClippingRegion
.IsNull())
1948 m_currentClippingRegion
.Intersect( region
);
1950 m_currentClippingRegion
.Union( region
);
1952 #if USE_PAINT_REGION
1953 if (!m_paintClippingRegion
.IsNull())
1954 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1957 wxCoord xx
, yy
, ww
, hh
;
1958 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1959 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1961 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
1962 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
1963 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
1964 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
1965 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
1968 void wxWindowDCImpl::DestroyClippingRegion()
1970 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1972 wxDCImpl::DestroyClippingRegion();
1974 m_currentClippingRegion
.Clear();
1976 #if USE_PAINT_REGION
1977 if (!m_paintClippingRegion
.IsEmpty())
1978 m_currentClippingRegion
.Union( m_paintClippingRegion
);
1981 if (!m_gdkwindow
) return;
1983 GdkRegion
* gdkRegion
= NULL
;
1984 if (!m_currentClippingRegion
.IsEmpty())
1985 gdkRegion
= m_currentClippingRegion
.GetRegion();
1987 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
1988 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
1989 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
1990 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
1993 void wxWindowDCImpl::Destroy()
1995 if (m_penGC
) wxFreePoolGC( m_penGC
);
1997 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
1999 if (m_textGC
) wxFreePoolGC( m_textGC
);
2001 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2005 void wxWindowDCImpl::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2007 m_deviceOriginX
= x
;
2008 m_deviceOriginY
= y
;
2010 ComputeScaleAndOrigin();
2013 void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2015 m_signX
= (xLeftRight
? 1 : -1);
2016 m_signY
= (yBottomUp
? -1 : 1);
2018 if (m_window
&& m_window
->m_wxwindow
&&
2019 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2022 ComputeScaleAndOrigin();
2025 void wxWindowDCImpl::ComputeScaleAndOrigin()
2027 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2029 wxDCImpl::ComputeScaleAndOrigin();
2031 // if scale has changed call SetPen to recalulate the line width
2032 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2034 // this is a bit artificial, but we need to force wxDC to think the pen
2042 // Resolution in pixels per logical inch
2043 wxSize
wxWindowDCImpl::GetPPI() const
2045 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2048 int wxWindowDCImpl::GetDepth() const
2050 return gdk_drawable_get_depth(m_gdkwindow
);
2053 //-----------------------------------------------------------------------------
2055 //-----------------------------------------------------------------------------
2057 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2059 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
2060 : wxWindowDCImpl( owner
)
2064 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2065 : wxWindowDCImpl( owner
, win
)
2067 wxCHECK_RET( win
, wxT("NULL window in wxClientDCImpl::wxClientDC") );
2069 #ifdef __WXUNIVERSAL__
2070 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2071 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2072 wxSize size
= win
->GetClientSize();
2073 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2078 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2080 wxCHECK_RET( m_window
, wxT("GetSize() doesn't work without window") );
2082 m_window
->GetClientSize(width
, height
);
2085 //-----------------------------------------------------------------------------
2087 //-----------------------------------------------------------------------------
2089 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2091 // Limit the paint region to the window size. Sometimes
2092 // the paint region is too big, and this risks X11 errors
2093 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2095 wxRect originalRect
= region
.GetBox();
2096 wxRect
rect(originalRect
);
2097 if (rect
.width
+ rect
.x
> sz
.x
)
2098 rect
.width
= sz
.x
- rect
.x
;
2099 if (rect
.height
+ rect
.y
> sz
.y
)
2100 rect
.height
= sz
.y
- rect
.y
;
2101 if (rect
!= originalRect
)
2103 region
= wxRegion(rect
);
2104 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2105 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2106 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2110 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
2111 : wxClientDCImpl( owner
)
2115 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2116 : wxClientDCImpl( owner
, win
)
2118 #if USE_PAINT_REGION
2119 if (!win
->m_clipPaintRegion
)
2122 wxSize sz
= win
->GetSize();
2123 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2124 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2126 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2129 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2130 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2132 if (sz
.x
<= 0 || sz
.y
<= 0)
2135 gdk_gc_set_clip_region( m_penGC
, region
);
2136 gdk_gc_set_clip_region( m_brushGC
, region
);
2137 gdk_gc_set_clip_region( m_textGC
, region
);
2138 gdk_gc_set_clip_region( m_bgGC
, region
);
2143 // ----------------------------------------------------------------------------
2145 // ----------------------------------------------------------------------------
2147 class wxDCModule
: public wxModule
2154 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2157 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2159 bool wxDCModule::OnInit()
2165 void wxDCModule::OnExit()
2169 for (int i
= wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
; i
--; )
2172 g_object_unref(hatches
[i
]);