1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dcclient.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XCopyPlane XCOPYPLANE
17 #include "wx/gtk/dcclient.h"
20 #include "wx/window.h"
22 #include "wx/dcmemory.h"
25 #include "wx/module.h"
28 #include "wx/fontutil.h"
30 #include "wx/gtk/private.h"
34 #if wxUSE_GRAPHICS_CONTEXT
35 #include "wx/graphics.h"
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 #define XLOG2DEV(x) LogicalToDeviceX(x)
44 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
45 #define YLOG2DEV(y) LogicalToDeviceY(y)
46 #define YLOG2DEVREL(y) LogicalToDeviceYRel(y)
48 #define USE_PAINT_REGION 1
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
61 static GdkPixmap
* hatches
[wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
+ 1];
63 extern GtkWidget
*wxGetRootWindow();
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 static const double RAD2DEG
= 180.0 / M_PI
;
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
76 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
78 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
80 static GdkPixmap
* GetHatch(int style
)
82 wxASSERT(style
>= wxBRUSHSTYLE_FIRST_HATCH
&& style
<= wxBRUSHSTYLE_LAST_HATCH
);
83 const int i
= style
- wxBRUSHSTYLE_FIRST_HATCH
;
84 if (hatches
[i
] == NULL
)
88 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
89 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
91 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
92 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
94 case wxBRUSHSTYLE_CROSS_HATCH
:
95 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, cross_bits
, cross_width
, cross_height
);
97 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
98 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
100 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
101 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, horiz_bits
, horiz_width
, horiz_height
);
103 case wxBRUSHSTYLE_VERTICAL_HATCH
:
104 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, verti_bits
, verti_width
, verti_height
);
111 //-----------------------------------------------------------------------------
112 // temporary implementation of the missing GDK function
113 //-----------------------------------------------------------------------------
116 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
122 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
123 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
124 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
126 gint src_width
, src_height
;
127 gdk_drawable_get_size(src
, &src_width
, &src_height
);
129 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
131 GDK_WINDOW_XID(drawable
),
134 src_width
, src_height
,
139 //-----------------------------------------------------------------------------
140 // Implement Pool of Graphic contexts. Creating them takes too much time.
141 //-----------------------------------------------------------------------------
167 #define GC_POOL_ALLOC_SIZE 100
169 static int wxGCPoolSize
= 0;
171 static wxGC
*wxGCPool
= NULL
;
173 static void wxInitGCPool()
175 // This really could wait until the first call to
176 // wxGetPoolGC, but we will make the first allocation
177 // now when other initialization is being performed.
179 // Set initial pool size.
180 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
182 // Allocate initial pool.
183 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
184 if (wxGCPool
== NULL
)
186 // If we cannot malloc, then fail with error
187 // when debug is enabled. If debug is not enabled,
188 // the problem will eventually get caught
190 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
194 // Zero initial pool.
195 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
198 static void wxCleanUpGCPool()
200 for (int i
= 0; i
< wxGCPoolSize
; i
++)
202 if (wxGCPool
[i
].m_gc
)
203 g_object_unref (wxGCPool
[i
].m_gc
);
211 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
215 // Look for an available GC.
216 for (int i
= 0; i
< wxGCPoolSize
; i
++)
218 if (!wxGCPool
[i
].m_gc
)
220 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
221 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
222 wxGCPool
[i
].m_type
= type
;
223 wxGCPool
[i
].m_used
= false;
225 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
227 wxGCPool
[i
].m_used
= true;
228 return wxGCPool
[i
].m_gc
;
232 // We did not find an available GC.
233 // We need to grow the GC pool.
234 pptr
= (wxGC
*)realloc(wxGCPool
,
235 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
238 // Initialize newly allocated pool.
240 memset(&wxGCPool
[wxGCPoolSize
], 0,
241 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
243 // Initialize entry we will return.
244 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
245 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
246 wxGCPool
[wxGCPoolSize
].m_type
= type
;
247 wxGCPool
[wxGCPoolSize
].m_used
= true;
249 // Set new value of pool size.
250 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
252 // Return newly allocated entry.
253 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
256 // The realloc failed. Fall through to error.
257 wxFAIL_MSG( wxT("No GC available") );
259 return (GdkGC
*) NULL
;
262 static void wxFreePoolGC( GdkGC
*gc
)
264 for (int i
= 0; i
< wxGCPoolSize
; i
++)
266 if (wxGCPool
[i
].m_gc
== gc
)
268 wxGCPool
[i
].m_used
= false;
273 wxFAIL_MSG( wxT("Wrong GC") );
276 //-----------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------
280 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
282 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
) :
285 m_gdkwindow
= (GdkWindow
*) NULL
;
286 m_penGC
= (GdkGC
*) NULL
;
287 m_brushGC
= (GdkGC
*) NULL
;
288 m_textGC
= (GdkGC
*) NULL
;
289 m_bgGC
= (GdkGC
*) NULL
;
290 m_cmap
= (GdkColormap
*) NULL
;
291 m_isScreenDC
= false;
292 m_context
= (PangoContext
*)NULL
;
293 m_layout
= (PangoLayout
*)NULL
;
294 m_fontdesc
= (PangoFontDescription
*)NULL
;
297 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
300 wxASSERT_MSG( window
, wxT("DC needs a window") );
302 m_gdkwindow
= (GdkWindow
*) NULL
;
303 m_penGC
= (GdkGC
*) NULL
;
304 m_brushGC
= (GdkGC
*) NULL
;
305 m_textGC
= (GdkGC
*) NULL
;
306 m_bgGC
= (GdkGC
*) NULL
;
307 m_cmap
= (GdkColormap
*) NULL
;
308 m_isScreenDC
= false;
309 m_font
= window
->GetFont();
311 GtkWidget
*widget
= window
->m_wxwindow
;
313 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
314 // code should still be able to create wxClientDCs for them, so we will
315 // use the parent window here then.
318 window
= window
->GetParent();
319 widget
= window
->m_wxwindow
;
322 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
324 m_context
= window
->GtkGetPangoDefaultContext();
325 m_layout
= pango_layout_new( m_context
);
326 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
328 m_gdkwindow
= widget
->window
;
330 // Window not realized ?
333 // Don't report problems as per MSW.
339 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
343 /* this must be done after SetUpDC, bacause SetUpDC calls the
344 repective SetBrush, SetPen, SetBackground etc functions
345 to set up the DC. SetBackground call m_owner->SetBackground
346 and this might not be desired as the standard dc background
347 is white whereas a window might assume gray to be the
348 standard (as e.g. wxStatusBar) */
352 if (m_window
&& m_window
->m_wxwindow
&&
353 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
358 // origin in the upper right corner
359 m_deviceOriginX
= m_window
->GetClientSize().x
;
363 wxWindowDCImpl::~wxWindowDCImpl()
368 g_object_unref (m_layout
);
370 pango_font_description_free( m_fontdesc
);
373 #if wxUSE_GRAPHICS_CONTEXT
374 wxGraphicsContext
* wxWindowDCImpl::CreateGraphicsContext()
376 wxWindowDC
*windowdc
= (wxWindowDC
*) GetOwner();
377 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext( *windowdc
);
381 void wxWindowDCImpl::SetUpDC( bool isMemDC
)
385 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
389 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
391 if (GetSelectedBitmap().GetDepth() == 1)
393 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
394 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
395 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
396 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
405 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
406 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
407 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
408 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
412 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
413 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
414 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
415 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
419 /* background colour */
420 m_backgroundBrush
= *wxWHITE_BRUSH
;
421 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
422 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
425 m_textForegroundColour
.CalcPixel( m_cmap
);
426 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
428 m_textBackgroundColour
.CalcPixel( m_cmap
);
429 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
431 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
433 gdk_gc_set_colormap( m_textGC
, m_cmap
);
436 m_pen
.GetColour().CalcPixel( m_cmap
);
437 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
438 gdk_gc_set_background( m_penGC
, bg_col
);
440 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
443 m_brush
.GetColour().CalcPixel( m_cmap
);
444 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
445 gdk_gc_set_background( m_brushGC
, bg_col
);
447 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
450 gdk_gc_set_background( m_bgGC
, bg_col
);
451 gdk_gc_set_foreground( m_bgGC
, bg_col
);
453 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
456 gdk_gc_set_function( m_textGC
, GDK_COPY
);
457 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
458 gdk_gc_set_function( m_penGC
, GDK_COPY
);
461 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
462 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
463 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
464 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
467 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
469 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
471 m_window
->GetSize(width
, height
);
474 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
475 const wxColour
& col
, int style
)
478 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
479 const wxColour
& col
, int style
);
481 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
492 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
495 // Generic (and therefore rather inefficient) method.
496 // Could be improved.
498 wxBitmap
bitmap(1, 1);
499 memdc
.SelectObject(bitmap
);
500 memdc
.Blit(0, 0, 1, 1, GetOwner(), x1
, y1
);
501 memdc
.SelectObject(wxNullBitmap
);
503 wxImage image
= bitmap
.ConvertToImage();
504 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
506 #else // !wxUSE_IMAGE
512 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
515 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
517 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
519 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
522 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
524 CalcBoundingBox(x1
, y1
);
525 CalcBoundingBox(x2
, y2
);
529 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
531 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
533 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
537 GetOwner()->GetSize( &w
, &h
);
538 wxCoord xx
= XLOG2DEV(x
);
539 wxCoord yy
= YLOG2DEV(y
);
542 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
543 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
548 void wxWindowDCImpl::DrawingSetup(GdkGC
*& gc
, bool& originChanged
)
551 GdkPixmap
* pixmap
= NULL
;
552 const int style
= m_brush
.GetStyle();
554 if (style
== wxBRUSHSTYLE_STIPPLE
|| style
== wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
)
556 const wxBitmap
* stipple
= m_brush
.GetStipple();
559 if (style
== wxBRUSHSTYLE_STIPPLE
)
560 pixmap
= stipple
->GetPixmap();
561 else if (stipple
->GetMask())
563 pixmap
= stipple
->GetPixmap();
568 else if (m_brush
.IsHatch())
570 pixmap
= GetHatch(style
);
578 gdk_drawable_get_size(pixmap
, &w
, &h
);
579 origin_x
= m_deviceOriginX
% w
;
580 origin_y
= m_deviceOriginY
% h
;
583 originChanged
= origin_x
|| origin_y
;
585 gdk_gc_set_ts_origin(gc
, origin_x
, origin_y
);
588 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
589 wxCoord xc
, wxCoord yc
)
591 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
593 wxCoord xx1
= XLOG2DEV(x1
);
594 wxCoord yy1
= YLOG2DEV(y1
);
595 wxCoord xx2
= XLOG2DEV(x2
);
596 wxCoord yy2
= YLOG2DEV(y2
);
597 wxCoord xxc
= XLOG2DEV(xc
);
598 wxCoord yyc
= YLOG2DEV(yc
);
599 double dx
= xx1
- xxc
;
600 double dy
= yy1
- yyc
;
601 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
602 wxCoord r
= (wxCoord
)radius
;
603 double radius1
, radius2
;
605 if (xx1
== xx2
&& yy1
== yy2
)
610 else if ( wxIsNullDouble(radius
) )
617 radius1
= (xx1
- xxc
== 0) ?
618 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
619 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
620 radius2
= (xx2
- xxc
== 0) ?
621 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
622 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
624 wxCoord alpha1
= wxCoord(radius1
* 64.0);
625 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
626 while (alpha2
<= 0) alpha2
+= 360*64;
627 while (alpha1
> 360*64) alpha1
-= 360*64;
631 if (m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
635 DrawingSetup(gc
, originChanged
);
637 gdk_draw_arc(m_gdkwindow
, gc
, true, xxc
-r
, yyc
-r
, 2*r
, 2*r
, alpha1
, alpha2
);
640 gdk_gc_set_ts_origin(gc
, 0, 0);
643 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
645 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
647 if ((m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
) && (alpha2
- alpha1
!= 360*64))
649 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
650 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
655 CalcBoundingBox (x1
, y1
);
656 CalcBoundingBox (x2
, y2
);
659 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
661 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
663 wxCoord xx
= XLOG2DEV(x
);
664 wxCoord yy
= YLOG2DEV(y
);
665 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
666 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
668 // CMB: handle -ve width and/or height
669 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
670 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
674 wxCoord start
= wxCoord(sa
* 64.0);
675 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
677 if (m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
681 DrawingSetup(gc
, originChanged
);
683 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, start
, end
);
686 gdk_gc_set_ts_origin(gc
, 0, 0);
689 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
690 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
693 CalcBoundingBox (x
, y
);
694 CalcBoundingBox (x
+ width
, y
+ height
);
697 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
699 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
701 if ((m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
) && m_gdkwindow
)
702 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
704 CalcBoundingBox (x
, y
);
707 void wxWindowDCImpl::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
709 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
711 if (m_pen
.GetStyle() == wxPENSTYLE_TRANSPARENT
) return;
714 //Check, if scaling is necessary
716 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
718 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
719 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
722 gpts
= new GdkPoint
[n
];
724 for (int i
= 0; i
< n
; i
++)
728 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
729 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
731 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
735 gdk_draw_lines( m_gdkwindow
, m_penGC
, gpts
, n
);
741 void wxWindowDCImpl::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
743 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
747 //Check, if scaling is necessary
749 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
751 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
752 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
755 gdkpoints
= new GdkPoint
[n
];
758 for (i
= 0 ; i
< n
; i
++)
762 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
763 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
765 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
770 if (m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
774 DrawingSetup(gc
, originChanged
);
776 gdk_draw_polygon(m_gdkwindow
, gc
, true, gdkpoints
, n
);
779 gdk_gc_set_ts_origin(gc
, 0, 0);
782 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
785 for (i = 0 ; i < n ; i++)
787 gdk_draw_line( m_gdkwindow, m_penGC,
790 gdkpoints[(i+1)%n].x,
791 gdkpoints[(i+1)%n].y);
794 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, gdkpoints
, n
);
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
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
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
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
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
);
860 // Just use X11 for other cases
861 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
866 CalcBoundingBox( x
, y
);
867 CalcBoundingBox( x
+ width
, y
+ height
);
870 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
872 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
874 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
876 wxCoord xx
= XLOG2DEV(x
);
877 wxCoord yy
= YLOG2DEV(y
);
878 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
879 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
880 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
882 // CMB: handle -ve width and/or height
883 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
884 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
886 // CMB: if radius is zero use DrawRectangle() instead to avoid
887 // X drawing errors with small radii
890 DoDrawRectangle( x
, y
, width
, height
);
894 // CMB: draw nothing if transformed w or h is 0
895 if (ww
== 0 || hh
== 0) return;
897 // CMB: adjust size if outline is drawn otherwise the result is
898 // 1 pixel too wide and high
899 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
907 // CMB: ensure dd is not larger than rectangle otherwise we
908 // get an hour glass shape
910 if (dd
> ww
) dd
= ww
;
911 if (dd
> hh
) dd
= hh
;
914 if (m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
918 DrawingSetup(gc
, originChanged
);
920 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
+rr
, yy
, ww
-dd
+1, hh
);
921 gdk_draw_rectangle(m_gdkwindow
, gc
, true, xx
, yy
+rr
, ww
, hh
-dd
+1);
922 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, dd
, dd
, 90*64, 90*64);
923 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64);
924 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64);
925 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64);
928 gdk_gc_set_ts_origin(gc
, 0, 0);
931 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
933 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
934 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
935 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
936 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
937 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
938 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
939 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
940 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
944 // this ignores the radius
945 CalcBoundingBox( x
, y
);
946 CalcBoundingBox( x
+ width
, y
+ height
);
949 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
951 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
953 wxCoord xx
= XLOG2DEV(x
);
954 wxCoord yy
= YLOG2DEV(y
);
955 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
956 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
958 // CMB: handle -ve width and/or height
959 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
960 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
964 if (m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
968 DrawingSetup(gc
, originChanged
);
970 gdk_draw_arc(m_gdkwindow
, gc
, true, xx
, yy
, ww
, hh
, 0, 360*64);
973 gdk_gc_set_ts_origin(gc
, 0, 0);
976 if (m_pen
.GetStyle() != wxPENSTYLE_TRANSPARENT
)
977 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
980 CalcBoundingBox( x
, y
);
981 CalcBoundingBox( x
+ width
, y
+ height
);
984 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
986 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
987 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
990 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
991 wxCoord x
, wxCoord y
,
994 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
996 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
998 bool is_mono
= bitmap
.GetDepth() == 1;
1000 // scale/translate size and position
1001 int xx
= XLOG2DEV(x
);
1002 int yy
= YLOG2DEV(y
);
1004 int w
= bitmap
.GetWidth();
1005 int h
= bitmap
.GetHeight();
1007 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1010 CalcBoundingBox( x
, y
);
1011 CalcBoundingBox( x
+ w
, y
+ h
);
1013 if (!m_gdkwindow
) return;
1015 int ww
= XLOG2DEVREL(w
);
1016 int hh
= YLOG2DEVREL(h
);
1018 // compare to current clipping region
1019 if (!m_currentClippingRegion
.IsNull())
1021 wxRegion
tmp( xx
,yy
,ww
,hh
);
1022 tmp
.Intersect( m_currentClippingRegion
);
1027 // scale bitmap if required
1028 wxBitmap use_bitmap
= bitmap
;
1029 if ((w
!= ww
) || (h
!= hh
))
1030 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1032 // apply mask if any
1033 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1034 if (useMask
&& use_bitmap
.GetMask())
1035 mask
= use_bitmap
.GetMask()->GetBitmap();
1037 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1039 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1043 if (!m_currentClippingRegion
.IsNull())
1046 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1047 GdkGC
*gc
= gdk_gc_new( new_mask
);
1049 gdk_gc_set_foreground( gc
, &col
);
1050 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1052 gdk_gc_set_background( gc
, &col
);
1054 gdk_gc_set_foreground( gc
, &col
);
1055 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1056 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1057 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1058 gdk_gc_set_stipple( gc
, mask
);
1059 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1061 g_object_unref (gc
);
1064 gdk_gc_set_clip_mask(use_gc
, mask
);
1065 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1068 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1069 // drawing a mono-bitmap (XBitmap) we use the current text GC
1072 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1073 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1074 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1075 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1076 gdk_wx_draw_bitmap(bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1078 gdk_draw_drawable(m_gdkwindow
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1080 g_object_unref (bitmap2
);
1081 g_object_unref (gc
);
1085 if (use_bitmap
.HasPixbuf())
1087 gdk_draw_pixbuf(m_gdkwindow
, use_gc
,
1088 use_bitmap
.GetPixbuf(),
1089 0, 0, xx
, yy
, -1, -1,
1090 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1094 gdk_draw_drawable(m_gdkwindow
, use_gc
,
1095 use_bitmap
.GetPixmap(),
1096 0, 0, xx
, yy
, -1, -1);
1100 // remove mask again if any
1103 gdk_gc_set_clip_mask(use_gc
, NULL
);
1104 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1105 if (!m_currentClippingRegion
.IsNull())
1106 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1107 if (new_mask
!= NULL
)
1108 g_object_unref(new_mask
);
1112 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1113 wxCoord width
, wxCoord height
,
1115 wxCoord xsrc
, wxCoord ysrc
,
1118 wxCoord xsrcMask
, wxCoord ysrcMask
)
1120 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1122 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1124 if (!m_gdkwindow
) return false;
1126 // transform the source DC coords to the device ones
1127 xsrc
= source
->LogicalToDeviceX(xsrc
);
1128 ysrc
= source
->LogicalToDeviceY(ysrc
);
1131 wxMemoryDC
*memDC
= wxDynamicCast(source
, wxMemoryDC
);
1134 selected
= memDC
->GetSelectedBitmap();
1135 if ( !selected
.IsOk() )
1139 bool use_bitmap_method
= false;
1140 bool is_mono
= false;
1142 if (xsrcMask
== -1 && ysrcMask
== -1)
1148 if (selected
.IsOk())
1150 is_mono
= (selected
.GetDepth() == 1);
1152 // we use the "XCopyArea" way to copy a memory dc into
1153 // a different window if the memory dc BOTH
1154 // a) doesn't have any mask or its mask isn't used
1158 if (useMask
&& (selected
.GetMask()))
1160 // we HAVE TO use the direct way for memory dcs
1161 // that have mask since the XCopyArea doesn't know
1163 use_bitmap_method
= true;
1167 // we HAVE TO use the direct way for memory dcs
1168 // that are bitmaps because XCopyArea doesn't cope
1169 // with different bit depths
1170 use_bitmap_method
= true;
1172 else if ((xsrc
== 0) && (ysrc
== 0) &&
1173 (width
== selected
.GetWidth()) &&
1174 (height
== selected
.GetHeight()))
1176 // we SHOULD use the direct way if all of the bitmap
1177 // in the memory dc is copied in which case XCopyArea
1178 // wouldn't be able able to boost performace by reducing
1179 // the area to be scaled
1180 use_bitmap_method
= true;
1184 CalcBoundingBox( xdest
, ydest
);
1185 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1187 // scale/translate size and position
1188 wxCoord xx
= XLOG2DEV(xdest
);
1189 wxCoord yy
= YLOG2DEV(ydest
);
1191 wxCoord ww
= XLOG2DEVREL(width
);
1192 wxCoord hh
= YLOG2DEVREL(height
);
1194 // compare to current clipping region
1195 if (!m_currentClippingRegion
.IsNull())
1197 wxRegion
tmp( xx
,yy
,ww
,hh
);
1198 tmp
.Intersect( m_currentClippingRegion
);
1203 int old_logical_func
= m_logicalFunction
;
1204 SetLogicalFunction( logical_func
);
1206 if (use_bitmap_method
)
1208 // scale/translate bitmap size
1209 wxCoord bm_width
= selected
.GetWidth();
1210 wxCoord bm_height
= selected
.GetHeight();
1212 // Get clip coords for the bitmap. If we don't
1213 // use wxBitmap::Rescale(), which can clip the
1214 // bitmap, these are the same as the original
1221 // interpret userscale of src too
1223 memDC
->GetUserScale(&xsc
,&ysc
);
1224 bm_width
= (int) (bm_width
/ xsc
);
1225 bm_height
= (int) (bm_height
/ ysc
);
1227 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1228 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1230 // Scale bitmap if required
1231 wxBitmap use_bitmap
= selected
;
1232 if ((selected
.GetWidth()!= bm_ww
) || ( selected
.GetHeight()!= bm_hh
))
1234 // This indicates that the blitting code below will get
1235 // a clipped bitmap and therefore needs to move the origin
1237 wxRegion
tmp( xx
,yy
,ww
,hh
);
1238 if (!m_currentClippingRegion
.IsNull())
1239 tmp
.Intersect( m_currentClippingRegion
);
1240 tmp
.GetBox(cx
,cy
,cw
,ch
);
1242 // Scale and clipped bitmap
1243 use_bitmap
= selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1246 // apply mask if any
1247 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1248 if (useMask
&& use_bitmap
.GetMask())
1249 mask
= use_bitmap
.GetMask()->GetBitmap();
1251 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1253 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1257 if (!m_currentClippingRegion
.IsNull())
1260 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1261 GdkGC
*gc
= gdk_gc_new( new_mask
);
1263 gdk_gc_set_foreground( gc
, &col
);
1264 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1265 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1267 gdk_gc_set_background( gc
, &col
);
1269 gdk_gc_set_foreground( gc
, &col
);
1270 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1271 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1272 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1273 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1274 gdk_gc_set_stipple( gc
, mask
);
1275 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1277 g_object_unref (gc
);
1280 gdk_gc_set_clip_mask(use_gc
, mask
);
1281 if (new_mask
!= NULL
)
1282 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1284 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1287 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1288 // drawing a mono-bitmap (XBitmap) we use the current text GC
1292 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1293 GdkGC
*gc
= gdk_gc_new( bitmap
);
1294 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1295 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1296 gdk_wx_draw_bitmap(bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1298 gdk_draw_drawable(m_gdkwindow
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1300 g_object_unref (bitmap
);
1301 g_object_unref (gc
);
1305 // was: gdk_draw_drawable( m_gdkwindow, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1306 gdk_draw_drawable(m_gdkwindow
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1309 // remove mask again if any
1312 gdk_gc_set_clip_mask(use_gc
, NULL
);
1313 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1314 if (!m_currentClippingRegion
.IsNull())
1315 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1319 g_object_unref (new_mask
);
1321 else // use_bitmap_method
1323 if (selected
.IsOk() && ((width
!= ww
) || (height
!= hh
)))
1326 wxRegion
tmp( xx
,yy
,ww
,hh
);
1327 tmp
.Intersect( m_currentClippingRegion
);
1328 wxCoord cx
,cy
,cw
,ch
;
1329 tmp
.GetBox(cx
,cy
,cw
,ch
);
1332 wxBitmap bitmap
= selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1334 // draw scaled bitmap
1335 // was: gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1336 gdk_draw_drawable( m_gdkwindow
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1340 // No scaling and not a memory dc with a mask either
1341 GdkWindow
* window
= NULL
;
1342 wxDCImpl
*impl
= source
->GetImpl();
1343 wxWindowDCImpl
*gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1345 window
= gtk_impl
->GetGDKWindow();
1348 SetLogicalFunction( old_logical_func
);
1352 // copy including child window contents
1353 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1354 gdk_draw_drawable( m_gdkwindow
, m_penGC
,
1358 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1362 SetLogicalFunction( old_logical_func
);
1367 void wxWindowDCImpl::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1369 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1371 if (!m_gdkwindow
) return;
1373 if (text
.empty()) return;
1378 wxCHECK_RET( m_context
, wxT("no Pango context") );
1379 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1380 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1382 gdk_pango_context_set_colormap( m_context
, m_cmap
);
1384 bool underlined
= m_font
.IsOk() && m_font
.GetUnderlined();
1386 wxCharBuffer data
= wxGTK_CONV(text
);
1389 size_t datalen
= strlen(data
);
1391 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1392 // has been fixed and thus the hack implemented below should never be used
1393 static bool pangoOk
= !wx_pango_version_check(1, 16, 0);
1395 bool needshack
= underlined
&& !pangoOk
;
1399 // a PangoLayout which has leading/trailing spaces with underlined font
1400 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1401 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1402 // this behaviour. To workaround this problem, we use a special hack here
1403 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1404 // empty space characters and give them a dummy colour attribute.
1405 // This will force Pango to underline the leading/trailing spaces, too.
1407 wxCharBuffer
data_tmp(datalen
+ 6);
1408 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1409 memcpy(data_tmp
.data(), "\342\200\214", 3);
1410 // copy the user string
1411 memcpy(data_tmp
.data() + 3, data
, datalen
);
1412 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1413 memcpy(data_tmp
.data() + 3 + datalen
, "\342\200\214", 3);
1419 pango_layout_set_text(m_layout
, data
, datalen
);
1423 PangoAttrList
*attrs
= pango_attr_list_new();
1424 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1426 a
->end_index
= datalen
;
1427 pango_attr_list_insert(attrs
, a
);
1431 // dummy colour for the leading space
1432 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1435 pango_attr_list_insert(attrs
, a
);
1437 // dummy colour for the trailing space
1438 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1439 a
->start_index
= datalen
- 1;
1440 a
->end_index
= datalen
;
1441 pango_attr_list_insert(attrs
, a
);
1444 pango_layout_set_attributes(m_layout
, attrs
);
1445 pango_attr_list_unref(attrs
);
1449 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1452 // If there is a user or actually any scale applied to
1453 // the device context, scale the font.
1455 // scale font description
1456 oldSize
= pango_font_description_get_size(m_fontdesc
);
1457 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1459 // actually apply scaled font
1460 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1464 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1465 if (m_backgroundMode
== wxBRUSHSTYLE_SOLID
)
1467 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1468 gdk_draw_rectangle(m_gdkwindow
, m_textGC
, true, x
, y
, w
, h
);
1469 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1474 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1476 gdk_draw_layout(m_gdkwindow
, m_textGC
, x_rtl
, y
, m_layout
);
1480 // reset unscaled size
1481 pango_font_description_set_size( m_fontdesc
, oldSize
);
1483 // actually apply unscaled font
1484 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1488 // undo underline attributes setting:
1489 pango_layout_set_attributes(m_layout
, NULL
);
1492 CalcBoundingBox(x
+ int(w
/ m_scaleX
), y
+ int(h
/ m_scaleY
));
1493 CalcBoundingBox(x
, y
);
1497 // TODO: There is an example of rotating text with GTK2 that would probably be
1498 // a better approach here:
1499 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1501 void wxWindowDCImpl::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1504 if (!m_gdkwindow
|| text
.empty())
1507 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1509 if ( wxIsNullDouble(angle
) )
1511 DoDrawText(text
, x
, y
);
1518 // TODO: implement later without GdkFont for GTK 2.0
1519 DoGetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1521 // draw the string normally
1524 dc
.SelectObject(src
);
1525 dc
.SetFont(GetFont());
1526 dc
.SetBackground(*wxBLACK_BRUSH
);
1527 dc
.SetBrush(*wxBLACK_BRUSH
);
1529 dc
.SetTextForeground( *wxWHITE
);
1530 dc
.DrawText(text
, 0, 0);
1531 dc
.SelectObject(wxNullBitmap
);
1533 // Calculate the size of the rotated bounding box.
1534 double rad
= DegToRad(angle
);
1535 double dx
= cos(rad
),
1538 // the rectngle vertices are counted clockwise with the first one being at
1539 // (0, 0) (or, rather, at (x, y))
1541 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1544 double x3
= x4
+ x2
,
1548 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1549 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1550 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1551 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1554 wxImage image
= src
.ConvertToImage();
1556 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1557 m_textForegroundColour
.Green(),
1558 m_textForegroundColour
.Blue() );
1559 image
= image
.Rotate( rad
, wxPoint(0,0) );
1561 int i_angle
= (int) angle
;
1562 i_angle
= i_angle
% 360;
1566 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1567 xoffset
= image
.GetWidth();
1569 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1570 yoffset
= image
.GetHeight();
1572 if ((i_angle
>= 0) && (i_angle
< 90))
1573 yoffset
-= (int)( cos(rad
)*h
);
1574 if ((i_angle
>= 90) && (i_angle
< 180))
1575 xoffset
-= (int)( sin(rad
)*h
);
1576 if ((i_angle
>= 180) && (i_angle
< 270))
1577 yoffset
-= (int)( cos(rad
)*h
);
1578 if ((i_angle
>= 270) && (i_angle
< 360))
1579 xoffset
-= (int)( sin(rad
)*h
);
1581 int i_x
= x
- xoffset
;
1582 int i_y
= y
- yoffset
;
1585 DoDrawBitmap( src
, i_x
, i_y
, true );
1588 // it would be better to draw with non underlined font and draw the line
1589 // manually here (it would be more straight...)
1591 if ( m_font
.GetUnderlined() )
1593 gdk_draw_line( m_gdkwindow
, m_textGC
,
1594 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1595 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1599 // update the bounding box
1600 CalcBoundingBox(x
+ minX
, y
+ minY
);
1601 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1602 #else // !wxUSE_IMAGE
1607 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
1610 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1611 wxCoord
*width
, wxCoord
*height
,
1612 wxCoord
*descent
, wxCoord
*externalLeading
,
1613 const wxFont
*theFont
) const
1621 if ( externalLeading
)
1622 *externalLeading
= 0;
1627 // ensure that theFont is always non-NULL
1628 if ( !theFont
|| !theFont
->IsOk() )
1631 // and use it if it's valid
1632 if ( theFont
->IsOk() )
1634 pango_layout_set_font_description
1637 theFont
->GetNativeFontInfo()->description
1641 // Set layout's text
1642 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1645 // hardly ideal, but what else can we do if conversion failed?
1649 pango_layout_set_text(m_layout
, dataUTF8
, -1);
1652 pango_layout_get_pixel_size(m_layout
, width
, &h
);
1655 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1656 int baseline
= pango_layout_iter_get_baseline(iter
);
1657 pango_layout_iter_free(iter
);
1658 *descent
= h
- PANGO_PIXELS(baseline
);
1663 // Reset old font description
1664 if (theFont
->IsOk())
1665 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1669 bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString
& text
,
1670 wxArrayInt
& widths
) const
1672 const size_t len
= text
.length();
1679 // Set layout's text
1680 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1683 // hardly ideal, but what else can we do if conversion failed?
1684 wxLogLastError(wxT("DoGetPartialTextExtents"));
1688 pango_layout_set_text(m_layout
, dataUTF8
, -1);
1690 // Calculate the position of each character based on the widths of
1691 // the previous characters
1693 // Code borrowed from Scintilla's PlatGTK
1694 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1696 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1698 while (pango_layout_iter_next_cluster(iter
))
1700 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1701 int position
= PANGO_PIXELS(pos
.x
);
1702 widths
[i
++] = position
;
1705 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1706 pango_layout_iter_free(iter
);
1712 wxCoord
wxWindowDCImpl::GetCharWidth() const
1714 pango_layout_set_text( m_layout
, "H", 1 );
1716 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1720 wxCoord
wxWindowDCImpl::GetCharHeight() const
1722 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1723 wxCHECK_MSG( metrics
, -1, _T("failed to get pango font metrics") );
1725 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1726 pango_font_metrics_get_ascent (metrics
));
1727 pango_font_metrics_unref (metrics
);
1731 void wxWindowDCImpl::Clear()
1733 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1735 if (!m_gdkwindow
) return;
1738 DoGetSize( &width
, &height
);
1739 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1742 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1749 pango_font_description_free( m_fontdesc
);
1751 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1756 PangoContext
*oldContext
= m_context
;
1758 m_context
= m_window
->GtkGetPangoDefaultContext();
1760 // If we switch back/forth between different contexts
1761 // we also have to create a new layout. I think so,
1762 // at least, and it doesn't hurt to do it.
1763 if (oldContext
!= m_context
)
1766 g_object_unref (m_layout
);
1768 m_layout
= pango_layout_new( m_context
);
1772 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1776 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1778 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1780 if (m_pen
== pen
) return;
1784 if (!m_pen
.IsOk()) return;
1786 if (!m_gdkwindow
) return;
1788 gint width
= m_pen
.GetWidth();
1791 // CMB: if width is non-zero scale it with the dc
1796 // X doesn't allow different width in x and y and so we take
1799 ( fabs((double) XLOG2DEVREL(width
)) +
1800 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1804 // width can't be 0 or an internal GTK error occurs inside
1805 // gdk_gc_set_dashes() below
1810 static const wxGTKDash dotted
[] = {1, 1};
1811 static const wxGTKDash short_dashed
[] = {2, 2};
1812 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1813 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1815 // We express dash pattern in pen width unit, so we are
1816 // independent of zoom factor and so on...
1818 const wxGTKDash
*req_dash
;
1820 GdkLineStyle lineStyle
= GDK_LINE_ON_OFF_DASH
;
1821 switch (m_pen
.GetStyle())
1823 case wxPENSTYLE_USER_DASH
:
1824 req_nb_dash
= m_pen
.GetDashCount();
1825 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1827 case wxPENSTYLE_DOT
:
1831 case wxPENSTYLE_LONG_DASH
:
1833 req_dash
= wxCoord_dashed
;
1835 case wxPENSTYLE_SHORT_DASH
:
1837 req_dash
= short_dashed
;
1839 case wxPENSTYLE_DOT_DASH
:
1841 req_dash
= dotted_dashed
;
1844 case wxPENSTYLE_TRANSPARENT
:
1845 case wxPENSTYLE_STIPPLE_MASK_OPAQUE
:
1846 case wxPENSTYLE_STIPPLE
:
1847 case wxPENSTYLE_SOLID
:
1849 lineStyle
= GDK_LINE_SOLID
;
1850 req_dash
= (wxGTKDash
*)NULL
;
1855 if (req_dash
&& req_nb_dash
)
1857 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1860 for (int i
= 0; i
< req_nb_dash
; i
++)
1861 real_req_dash
[i
] = req_dash
[i
] * width
;
1862 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1863 delete[] real_req_dash
;
1867 // No Memory. We use non-scaled dash pattern...
1868 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1872 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1873 switch (m_pen
.GetCap())
1875 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1876 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1882 capStyle
= GDK_CAP_NOT_LAST
;
1887 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1888 switch (m_pen
.GetJoin())
1890 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1891 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1893 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1896 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1898 m_pen
.GetColour().CalcPixel( m_cmap
);
1899 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1902 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
1904 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1906 if (m_brush
== brush
) return;
1910 if (!m_brush
.IsOk()) return;
1912 if (!m_gdkwindow
) return;
1914 m_brush
.GetColour().CalcPixel( m_cmap
);
1915 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1917 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1919 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1921 if (m_brush
.GetStipple()->GetDepth() != 1)
1923 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1924 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1928 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1929 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1933 if ((m_brush
.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1935 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1936 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1939 if (m_brush
.IsHatch())
1941 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1942 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
1946 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
1948 /* CMB 21/7/98: Added SetBackground. Sets background brush
1949 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1951 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1953 if (m_backgroundBrush
== brush
) return;
1955 m_backgroundBrush
= brush
;
1957 if (!m_backgroundBrush
.IsOk()) return;
1959 if (!m_gdkwindow
) return;
1961 wxColor color
= m_backgroundBrush
.GetColour();
1962 color
.CalcPixel(m_cmap
);
1963 const GdkColor
* gdkColor
= color
.GetColor();
1964 gdk_gc_set_background(m_brushGC
, gdkColor
);
1965 gdk_gc_set_background(m_penGC
, gdkColor
);
1966 gdk_gc_set_background(m_bgGC
, gdkColor
);
1967 gdk_gc_set_foreground(m_bgGC
, gdkColor
);
1970 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1972 if (m_backgroundBrush
.GetStyle() == wxBRUSHSTYLE_STIPPLE
)
1974 const wxBitmap
* stipple
= m_backgroundBrush
.GetStipple();
1975 if (stipple
->IsOk())
1977 if (stipple
->GetDepth() != 1)
1979 gdk_gc_set_fill(m_bgGC
, GDK_TILED
);
1980 gdk_gc_set_tile(m_bgGC
, stipple
->GetPixmap());
1984 gdk_gc_set_fill(m_bgGC
, GDK_STIPPLED
);
1985 gdk_gc_set_stipple(m_bgGC
, stipple
->GetPixmap());
1989 else if (m_backgroundBrush
.IsHatch())
1991 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1992 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
1996 void wxWindowDCImpl::SetLogicalFunction( int function
)
1998 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2000 if (m_logicalFunction
== function
)
2003 // VZ: shouldn't this be a CHECK?
2010 case wxXOR
: mode
= GDK_XOR
; break;
2011 case wxINVERT
: mode
= GDK_INVERT
; break;
2012 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2013 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2014 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2015 case wxSET
: mode
= GDK_SET
; break;
2016 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2017 case wxAND
: mode
= GDK_AND
; break;
2018 case wxOR
: mode
= GDK_OR
; break;
2019 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2020 case wxNAND
: mode
= GDK_NAND
; break;
2021 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2022 case wxCOPY
: mode
= GDK_COPY
; break;
2023 case wxNO_OP
: mode
= GDK_NOOP
; break;
2024 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2026 // unsupported by GTK
2027 case wxNOR
: mode
= GDK_COPY
; break;
2029 wxFAIL_MSG( wxT("unsupported logical function") );
2033 m_logicalFunction
= function
;
2035 gdk_gc_set_function( m_penGC
, mode
);
2036 gdk_gc_set_function( m_brushGC
, mode
);
2038 // to stay compatible with wxMSW, we don't apply ROPs to the text
2039 // operations (i.e. DrawText/DrawRotatedText).
2040 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2041 gdk_gc_set_function( m_textGC
, mode
);
2044 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
2046 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2048 // don't set m_textForegroundColour to an invalid colour as we'd crash
2049 // later then (we use m_textForegroundColour.GetColor() without checking
2051 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
2054 m_textForegroundColour
= col
;
2058 m_textForegroundColour
.CalcPixel( m_cmap
);
2059 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2063 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
2065 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2068 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
2071 m_textBackgroundColour
= col
;
2075 m_textBackgroundColour
.CalcPixel( m_cmap
);
2076 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2080 void wxWindowDCImpl::SetBackgroundMode( int mode
)
2082 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2084 m_backgroundMode
= mode
;
2086 if (!m_gdkwindow
) return;
2088 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2089 // transparent/solid background mode
2091 if (m_brush
.GetStyle() != wxBRUSHSTYLE_SOLID
&& m_brush
.GetStyle() != wxBRUSHSTYLE_TRANSPARENT
)
2093 gdk_gc_set_fill( m_brushGC
,
2094 (m_backgroundMode
== wxBRUSHSTYLE_TRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2098 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2100 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
2103 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2105 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2107 if (!m_gdkwindow
) return;
2110 rect
.x
= XLOG2DEV(x
);
2111 rect
.y
= YLOG2DEV(y
);
2112 rect
.width
= XLOG2DEVREL(width
);
2113 rect
.height
= YLOG2DEVREL(height
);
2115 if (m_window
&& m_window
->m_wxwindow
&&
2116 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2118 rect
.x
-= rect
.width
;
2121 if (!m_currentClippingRegion
.IsNull())
2122 m_currentClippingRegion
.Intersect( rect
);
2124 m_currentClippingRegion
.Union( rect
);
2126 #if USE_PAINT_REGION
2127 if (!m_paintClippingRegion
.IsNull())
2128 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2131 wxCoord xx
, yy
, ww
, hh
;
2132 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2134 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2136 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2139 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
2140 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2141 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2142 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2143 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2146 void wxWindowDCImpl::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2148 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2152 DestroyClippingRegion();
2156 if (!m_gdkwindow
) return;
2158 if (!m_currentClippingRegion
.IsNull())
2159 m_currentClippingRegion
.Intersect( region
);
2161 m_currentClippingRegion
.Union( region
);
2163 #if USE_PAINT_REGION
2164 if (!m_paintClippingRegion
.IsNull())
2165 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2168 wxCoord xx
, yy
, ww
, hh
;
2169 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2171 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2173 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2176 GdkRegion
* gdkRegion
= m_currentClippingRegion
.GetRegion();
2177 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2178 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2179 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2180 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2183 void wxWindowDCImpl::DestroyClippingRegion()
2185 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2188 wxDCImpl::DestroyClippingRegion();
2190 wxDC::DestroyClippingRegion();
2193 m_currentClippingRegion
.Clear();
2195 #if USE_PAINT_REGION
2196 if (!m_paintClippingRegion
.IsEmpty())
2197 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2200 if (!m_gdkwindow
) return;
2202 GdkRegion
* gdkRegion
= NULL
;
2203 if (!m_currentClippingRegion
.IsEmpty())
2204 gdkRegion
= m_currentClippingRegion
.GetRegion();
2206 gdk_gc_set_clip_region(m_penGC
, gdkRegion
);
2207 gdk_gc_set_clip_region(m_brushGC
, gdkRegion
);
2208 gdk_gc_set_clip_region(m_textGC
, gdkRegion
);
2209 gdk_gc_set_clip_region(m_bgGC
, gdkRegion
);
2212 void wxWindowDCImpl::Destroy()
2214 if (m_penGC
) wxFreePoolGC( m_penGC
);
2215 m_penGC
= (GdkGC
*) NULL
;
2216 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2217 m_brushGC
= (GdkGC
*) NULL
;
2218 if (m_textGC
) wxFreePoolGC( m_textGC
);
2219 m_textGC
= (GdkGC
*) NULL
;
2220 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2221 m_bgGC
= (GdkGC
*) NULL
;
2224 void wxWindowDCImpl::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2226 m_deviceOriginX
= x
;
2227 m_deviceOriginY
= y
;
2229 ComputeScaleAndOrigin();
2232 void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2234 m_signX
= (xLeftRight
? 1 : -1);
2235 m_signY
= (yBottomUp
? -1 : 1);
2237 if (m_window
&& m_window
->m_wxwindow
&&
2238 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2241 ComputeScaleAndOrigin();
2244 void wxWindowDCImpl::ComputeScaleAndOrigin()
2246 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2249 wxDCImpl::ComputeScaleAndOrigin();
2251 wxDC::ComputeScaleAndOrigin();
2254 // if scale has changed call SetPen to recalulate the line width
2255 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2257 // this is a bit artificial, but we need to force wxDC to think the pen
2265 // Resolution in pixels per logical inch
2266 wxSize
wxWindowDCImpl::GetPPI() const
2268 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2271 int wxWindowDCImpl::GetDepth() const
2273 return gdk_drawable_get_depth(m_gdkwindow
);
2277 //-----------------------------------------------------------------------------
2279 //-----------------------------------------------------------------------------
2281 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2283 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
2284 : wxWindowDCImpl( owner
)
2288 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2289 : wxWindowDCImpl( owner
, win
)
2291 wxCHECK_RET( win
, _T("NULL window in wxClientDCImpl::wxClientDC") );
2293 #ifdef __WXUNIVERSAL__
2294 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2295 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2296 wxSize size
= win
->GetClientSize();
2297 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2302 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2304 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
2306 m_window
->GetClientSize( width
, height
);
2309 //-----------------------------------------------------------------------------
2311 //-----------------------------------------------------------------------------
2313 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2315 // Limit the paint region to the window size. Sometimes
2316 // the paint region is too big, and this risks X11 errors
2317 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2319 wxRect originalRect
= region
.GetBox();
2320 wxRect
rect(originalRect
);
2321 if (rect
.width
+ rect
.x
> sz
.x
)
2322 rect
.width
= sz
.x
- rect
.x
;
2323 if (rect
.height
+ rect
.y
> sz
.y
)
2324 rect
.height
= sz
.y
- rect
.y
;
2325 if (rect
!= originalRect
)
2327 region
= wxRegion(rect
);
2328 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2329 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2330 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2334 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
2335 : wxClientDCImpl( owner
)
2339 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2340 : wxClientDCImpl( owner
, win
)
2342 #if USE_PAINT_REGION
2343 if (!win
->m_clipPaintRegion
)
2346 wxSize sz
= win
->GetSize();
2347 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2348 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2350 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2353 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2354 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2356 if (sz
.x
<= 0 || sz
.y
<= 0)
2359 gdk_gc_set_clip_region( m_penGC
, region
);
2360 gdk_gc_set_clip_region( m_brushGC
, region
);
2361 gdk_gc_set_clip_region( m_textGC
, region
);
2362 gdk_gc_set_clip_region( m_bgGC
, region
);
2367 // ----------------------------------------------------------------------------
2369 // ----------------------------------------------------------------------------
2371 class wxDCModule
: public wxModule
2378 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2381 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2383 bool wxDCModule::OnInit()
2389 void wxDCModule::OnExit()
2393 for (int i
= wxBRUSHSTYLE_LAST_HATCH
- wxBRUSHSTYLE_FIRST_HATCH
; i
--; )
2396 g_object_unref(hatches
[i
]);