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 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #define XLOG2DEV(x) LogicalToDeviceX(x)
39 #define XLOG2DEVREL(x) LogicalToDeviceXRel(x)
40 #define YLOG2DEV(y) LogicalToDeviceY(y)
41 #define YLOG2DEVREL(y) LogicalToDeviceYRel(y)
43 #define USE_PAINT_REGION 1
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
56 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
57 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
59 static GdkPixmap
* hatches
[wxLAST_HATCH
- wxFIRST_HATCH
+ 1];
61 extern GtkWidget
*wxGetRootWindow();
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 static const double RAD2DEG
= 180.0 / M_PI
;
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
74 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
76 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
78 static GdkPixmap
* GetHatch(int style
)
80 wxASSERT(style
>= wxFIRST_HATCH
&& style
<= wxLAST_HATCH
);
81 const int i
= style
- wxFIRST_HATCH
;
82 if (hatches
[i
] == NULL
)
86 case wxBDIAGONAL_HATCH
:
87 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
89 case wxCROSSDIAG_HATCH
:
90 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
93 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, cross_bits
, cross_width
, cross_height
);
95 case wxFDIAGONAL_HATCH
:
96 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
98 case wxHORIZONTAL_HATCH
:
99 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, horiz_bits
, horiz_width
, horiz_height
);
101 case wxVERTICAL_HATCH
:
102 hatches
[i
] = gdk_bitmap_create_from_data(NULL
, verti_bits
, verti_width
, verti_height
);
109 //-----------------------------------------------------------------------------
110 // temporary implementation of the missing GDK function
111 //-----------------------------------------------------------------------------
114 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
120 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
121 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
122 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
124 gint src_width
, src_height
;
125 gdk_drawable_get_size(src
, &src_width
, &src_height
);
127 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
129 GDK_WINDOW_XID(drawable
),
132 src_width
, src_height
,
137 //-----------------------------------------------------------------------------
138 // Implement Pool of Graphic contexts. Creating them takes too much time.
139 //-----------------------------------------------------------------------------
165 #define GC_POOL_ALLOC_SIZE 100
167 static int wxGCPoolSize
= 0;
169 static wxGC
*wxGCPool
= NULL
;
171 static void wxInitGCPool()
173 // This really could wait until the first call to
174 // wxGetPoolGC, but we will make the first allocation
175 // now when other initialization is being performed.
177 // Set initial pool size.
178 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
180 // Allocate initial pool.
181 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
182 if (wxGCPool
== NULL
)
184 // If we cannot malloc, then fail with error
185 // when debug is enabled. If debug is not enabled,
186 // the problem will eventually get caught
188 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
192 // Zero initial pool.
193 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
196 static void wxCleanUpGCPool()
198 for (int i
= 0; i
< wxGCPoolSize
; i
++)
200 if (wxGCPool
[i
].m_gc
)
201 g_object_unref (wxGCPool
[i
].m_gc
);
209 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
213 // Look for an available GC.
214 for (int i
= 0; i
< wxGCPoolSize
; i
++)
216 if (!wxGCPool
[i
].m_gc
)
218 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
219 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
220 wxGCPool
[i
].m_type
= type
;
221 wxGCPool
[i
].m_used
= false;
223 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
225 wxGCPool
[i
].m_used
= true;
226 return wxGCPool
[i
].m_gc
;
230 // We did not find an available GC.
231 // We need to grow the GC pool.
232 pptr
= (wxGC
*)realloc(wxGCPool
,
233 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
236 // Initialize newly allocated pool.
238 memset(&wxGCPool
[wxGCPoolSize
], 0,
239 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
241 // Initialize entry we will return.
242 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
243 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
244 wxGCPool
[wxGCPoolSize
].m_type
= type
;
245 wxGCPool
[wxGCPoolSize
].m_used
= true;
247 // Set new value of pool size.
248 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
250 // Return newly allocated entry.
251 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
254 // The realloc failed. Fall through to error.
255 wxFAIL_MSG( wxT("No GC available") );
257 return (GdkGC
*) NULL
;
260 static void wxFreePoolGC( GdkGC
*gc
)
262 for (int i
= 0; i
< wxGCPoolSize
; i
++)
264 if (wxGCPool
[i
].m_gc
== gc
)
266 wxGCPool
[i
].m_used
= false;
271 wxFAIL_MSG( wxT("Wrong GC") );
274 //-----------------------------------------------------------------------------
276 //-----------------------------------------------------------------------------
278 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGTKDCImpl
)
280 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
) :
283 m_gdkwindow
= (GdkWindow
*) NULL
;
284 m_penGC
= (GdkGC
*) NULL
;
285 m_brushGC
= (GdkGC
*) NULL
;
286 m_textGC
= (GdkGC
*) NULL
;
287 m_bgGC
= (GdkGC
*) NULL
;
288 m_cmap
= (GdkColormap
*) NULL
;
289 m_isScreenDC
= false;
290 m_context
= (PangoContext
*)NULL
;
291 m_layout
= (PangoLayout
*)NULL
;
292 m_fontdesc
= (PangoFontDescription
*)NULL
;
295 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
) :
298 wxASSERT_MSG( window
, wxT("DC needs a window") );
300 m_gdkwindow
= (GdkWindow
*) NULL
;
301 m_penGC
= (GdkGC
*) NULL
;
302 m_brushGC
= (GdkGC
*) NULL
;
303 m_textGC
= (GdkGC
*) NULL
;
304 m_bgGC
= (GdkGC
*) NULL
;
305 m_cmap
= (GdkColormap
*) NULL
;
306 m_isScreenDC
= false;
307 m_font
= window
->GetFont();
309 GtkWidget
*widget
= window
->m_wxwindow
;
311 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
312 // code should still be able to create wxClientDCs for them, so we will
313 // use the parent window here then.
316 window
= window
->GetParent();
317 widget
= window
->m_wxwindow
;
320 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
322 m_context
= window
->GtkGetPangoDefaultContext();
323 m_layout
= pango_layout_new( m_context
);
324 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
326 m_gdkwindow
= widget
->window
;
328 // Window not realized ?
331 // Don't report problems as per MSW.
337 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
341 /* this must be done after SetUpDC, bacause SetUpDC calls the
342 repective SetBrush, SetPen, SetBackground etc functions
343 to set up the DC. SetBackground call m_owner->SetBackground
344 and this might not be desired as the standard dc background
345 is white whereas a window might assume gray to be the
346 standard (as e.g. wxStatusBar) */
350 if (m_window
&& m_window
->m_wxwindow
&&
351 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
356 // origin in the upper right corner
357 m_deviceOriginX
= m_window
->GetClientSize().x
;
361 wxWindowDCImpl::~wxWindowDCImpl()
366 g_object_unref (m_layout
);
368 pango_font_description_free( m_fontdesc
);
371 void wxWindowDCImpl::SetUpDC( bool isMemDC
)
375 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
379 if ((isMemDC
) && (GetSelectedBitmap().IsOk()))
381 if (GetSelectedBitmap().GetDepth() == 1)
383 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_MONO
);
384 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_MONO
);
385 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_MONO
);
386 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_MONO
);
395 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_SCREEN
);
396 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_SCREEN
);
397 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_SCREEN
);
398 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_SCREEN
);
402 m_penGC
= wxGetPoolGC( m_gdkwindow
, wxPEN_COLOUR
);
403 m_brushGC
= wxGetPoolGC( m_gdkwindow
, wxBRUSH_COLOUR
);
404 m_textGC
= wxGetPoolGC( m_gdkwindow
, wxTEXT_COLOUR
);
405 m_bgGC
= wxGetPoolGC( m_gdkwindow
, wxBG_COLOUR
);
409 /* background colour */
410 m_backgroundBrush
= *wxWHITE_BRUSH
;
411 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
412 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
415 m_textForegroundColour
.CalcPixel( m_cmap
);
416 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
418 m_textBackgroundColour
.CalcPixel( m_cmap
);
419 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
421 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
423 gdk_gc_set_colormap( m_textGC
, m_cmap
);
426 m_pen
.GetColour().CalcPixel( m_cmap
);
427 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
428 gdk_gc_set_background( m_penGC
, bg_col
);
430 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
433 m_brush
.GetColour().CalcPixel( m_cmap
);
434 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
435 gdk_gc_set_background( m_brushGC
, bg_col
);
437 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
440 gdk_gc_set_background( m_bgGC
, bg_col
);
441 gdk_gc_set_foreground( m_bgGC
, bg_col
);
443 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
446 gdk_gc_set_function( m_textGC
, GDK_COPY
);
447 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
448 gdk_gc_set_function( m_penGC
, GDK_COPY
);
451 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
452 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
453 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
454 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
457 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
459 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
461 m_window
->GetSize(width
, height
);
464 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
465 const wxColour
& col
, int style
)
468 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
469 const wxColour
& col
, int style
);
471 return wxDoFloodFill( GetOwner(), x
, y
, col
, style
);
482 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
485 // Generic (and therefore rather inefficient) method.
486 // Could be improved.
488 wxBitmap
bitmap(1, 1);
489 memdc
.SelectObject(bitmap
);
490 memdc
.Blit(0, 0, 1, 1, GetOwner(), x1
, y1
);
491 memdc
.SelectObject(wxNullBitmap
);
493 wxImage image
= bitmap
.ConvertToImage();
494 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
496 #else // !wxUSE_IMAGE
502 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
505 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
507 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
509 if (m_pen
.GetStyle() != wxTRANSPARENT
)
512 gdk_draw_line( m_gdkwindow
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
514 CalcBoundingBox(x1
, y1
);
515 CalcBoundingBox(x2
, y2
);
519 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
521 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
523 if (m_pen
.GetStyle() != wxTRANSPARENT
)
527 GetOwner()->GetSize( &w
, &h
);
528 wxCoord xx
= XLOG2DEV(x
);
529 wxCoord yy
= YLOG2DEV(y
);
532 gdk_draw_line( m_gdkwindow
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
533 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
538 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
539 wxCoord xc
, wxCoord yc
)
541 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
543 wxCoord xx1
= XLOG2DEV(x1
);
544 wxCoord yy1
= YLOG2DEV(y1
);
545 wxCoord xx2
= XLOG2DEV(x2
);
546 wxCoord yy2
= YLOG2DEV(y2
);
547 wxCoord xxc
= XLOG2DEV(xc
);
548 wxCoord yyc
= YLOG2DEV(yc
);
549 double dx
= xx1
- xxc
;
550 double dy
= yy1
- yyc
;
551 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
552 wxCoord r
= (wxCoord
)radius
;
553 double radius1
, radius2
;
555 if (xx1
== xx2
&& yy1
== yy2
)
560 else if ( wxIsNullDouble(radius
) )
567 radius1
= (xx1
- xxc
== 0) ?
568 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
569 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
570 radius2
= (xx2
- xxc
== 0) ?
571 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
572 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
574 wxCoord alpha1
= wxCoord(radius1
* 64.0);
575 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
576 while (alpha2
<= 0) alpha2
+= 360*64;
577 while (alpha1
> 360*64) alpha1
-= 360*64;
581 if (m_brush
.GetStyle() != wxTRANSPARENT
)
583 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
585 gdk_gc_set_ts_origin( m_textGC
,
586 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
587 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
588 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
589 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
591 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
593 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
594 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
595 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
597 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
599 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
600 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
601 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
603 if (m_brush
.GetStyle() == wxSTIPPLE
)
605 gdk_gc_set_ts_origin( m_brushGC
,
606 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
607 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
608 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
609 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
613 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
617 if (m_pen
.GetStyle() != wxTRANSPARENT
)
619 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
621 if ((m_brush
.GetStyle() != wxTRANSPARENT
) && (alpha2
- alpha1
!= 360*64))
623 gdk_draw_line( m_gdkwindow
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
624 gdk_draw_line( m_gdkwindow
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
629 CalcBoundingBox (x1
, y1
);
630 CalcBoundingBox (x2
, y2
);
633 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
635 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
637 wxCoord xx
= XLOG2DEV(x
);
638 wxCoord yy
= YLOG2DEV(y
);
639 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
640 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
642 // CMB: handle -ve width and/or height
643 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
644 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
648 wxCoord start
= wxCoord(sa
* 64.0);
649 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
651 if (m_brush
.GetStyle() != wxTRANSPARENT
)
653 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
655 gdk_gc_set_ts_origin( m_textGC
,
656 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
657 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
658 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
659 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
661 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
663 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
664 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
665 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
667 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
669 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
670 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
671 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
673 if (m_brush
.GetStyle() == wxSTIPPLE
)
675 gdk_gc_set_ts_origin( m_brushGC
,
676 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
677 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
678 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
679 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
683 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
687 if (m_pen
.GetStyle() != wxTRANSPARENT
)
688 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
691 CalcBoundingBox (x
, y
);
692 CalcBoundingBox (x
+ width
, y
+ height
);
695 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
697 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
699 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_gdkwindow
)
700 gdk_draw_point( m_gdkwindow
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
702 CalcBoundingBox (x
, y
);
705 void wxWindowDCImpl::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
707 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
709 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
712 //Check, if scaling is necessary
714 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
716 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
717 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
720 gpts
= new GdkPoint
[n
];
722 for (int i
= 0; i
< n
; i
++)
726 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
727 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
729 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
733 gdk_draw_lines( m_gdkwindow
, m_penGC
, gpts
, n
);
739 void wxWindowDCImpl::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int 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 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
753 gdkpoints
= new GdkPoint
[n
];
756 for (i
= 0 ; i
< n
; i
++)
760 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
761 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
763 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
768 if (m_brush
.GetStyle() != wxTRANSPARENT
)
770 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
772 gdk_gc_set_ts_origin( m_textGC
,
773 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
774 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
775 gdk_draw_polygon( m_gdkwindow
, m_textGC
, TRUE
, gdkpoints
, n
);
776 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
778 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
780 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
781 gdk_draw_polygon( m_gdkwindow
, m_brushGC
, TRUE
, gdkpoints
, n
);
782 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
784 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
786 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
787 gdk_draw_polygon( m_gdkwindow
, m_brushGC
, TRUE
, gdkpoints
, n
);
788 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
790 if (m_brush
.GetStyle() == wxSTIPPLE
)
792 gdk_gc_set_ts_origin( m_brushGC
,
793 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
794 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
795 gdk_draw_polygon( m_gdkwindow
, m_brushGC
, TRUE
, gdkpoints
, n
);
796 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
800 gdk_draw_polygon( m_gdkwindow
, m_brushGC
, TRUE
, gdkpoints
, n
);
804 if (m_pen
.GetStyle() != wxTRANSPARENT
)
807 for (i = 0 ; i < n ; i++)
809 gdk_draw_line( m_gdkwindow, m_penGC,
812 gdkpoints[(i+1)%n].x,
813 gdkpoints[(i+1)%n].y);
816 gdk_draw_polygon( m_gdkwindow
, m_penGC
, FALSE
, gdkpoints
, n
);
825 void wxWindowDCImpl::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
827 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
829 wxCoord xx
= XLOG2DEV(x
);
830 wxCoord yy
= YLOG2DEV(y
);
831 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
832 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
834 // CMB: draw nothing if transformed w or h is 0
835 if (ww
== 0 || hh
== 0) return;
837 // CMB: handle -ve width and/or height
838 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
839 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
843 if (m_brush
.GetStyle() != wxTRANSPARENT
)
845 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
847 gdk_gc_set_ts_origin( m_textGC
,
848 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
849 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
850 gdk_draw_rectangle( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
851 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
853 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
855 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
856 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
857 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
859 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
861 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
862 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
863 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
865 if (m_brush
.GetStyle() == wxSTIPPLE
)
867 gdk_gc_set_ts_origin( m_brushGC
,
868 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
869 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
870 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
871 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
875 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
879 if (m_pen
.GetStyle() != wxTRANSPARENT
)
882 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
883 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxSOLID
))
885 // Use 2 1-line rects instead
886 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
891 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
892 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
896 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
897 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
901 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
906 // Just use X11 for other cases
907 gdk_draw_rectangle( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
912 CalcBoundingBox( x
, y
);
913 CalcBoundingBox( x
+ width
, y
+ height
);
916 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
918 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
920 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
922 wxCoord xx
= XLOG2DEV(x
);
923 wxCoord yy
= YLOG2DEV(y
);
924 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
925 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
926 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
928 // CMB: handle -ve width and/or height
929 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
930 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
932 // CMB: if radius is zero use DrawRectangle() instead to avoid
933 // X drawing errors with small radii
936 DoDrawRectangle( x
, y
, width
, height
);
940 // CMB: draw nothing if transformed w or h is 0
941 if (ww
== 0 || hh
== 0) return;
943 // CMB: adjust size if outline is drawn otherwise the result is
944 // 1 pixel too wide and high
945 if (m_pen
.GetStyle() != wxTRANSPARENT
)
953 // CMB: ensure dd is not larger than rectangle otherwise we
954 // get an hour glass shape
956 if (dd
> ww
) dd
= ww
;
957 if (dd
> hh
) dd
= hh
;
960 if (m_brush
.GetStyle() != wxTRANSPARENT
)
962 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
964 gdk_gc_set_ts_origin( m_textGC
,
965 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
966 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
967 gdk_draw_rectangle( m_gdkwindow
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
968 gdk_draw_rectangle( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
969 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
970 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
971 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
972 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
973 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
975 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
977 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
978 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
979 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
980 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
981 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
982 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
983 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
984 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
986 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
988 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
989 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
990 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
991 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
992 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
993 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
994 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
995 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
997 if (m_brush
.GetStyle() == wxSTIPPLE
)
999 gdk_gc_set_ts_origin( m_brushGC
,
1000 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1001 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1002 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
1003 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1004 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1005 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1006 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1007 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1008 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1012 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
1013 gdk_draw_rectangle( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
1014 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1015 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1016 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1017 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1021 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1023 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
1024 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
1025 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
1026 gdk_draw_line( m_gdkwindow
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
1027 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
1028 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
1029 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1030 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1034 // this ignores the radius
1035 CalcBoundingBox( x
, y
);
1036 CalcBoundingBox( x
+ width
, y
+ height
);
1039 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1041 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1043 wxCoord xx
= XLOG2DEV(x
);
1044 wxCoord yy
= YLOG2DEV(y
);
1045 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1046 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1048 // CMB: handle -ve width and/or height
1049 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1050 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1054 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1056 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1058 gdk_gc_set_ts_origin( m_textGC
,
1059 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1060 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1061 gdk_draw_arc( m_gdkwindow
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1062 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
1064 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1066 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
1067 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1068 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1070 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1072 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1073 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1074 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1076 if (m_brush
.GetStyle() == wxSTIPPLE
)
1078 gdk_gc_set_ts_origin( m_brushGC
,
1079 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1080 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1081 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1082 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1086 gdk_draw_arc( m_gdkwindow
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1090 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1091 gdk_draw_arc( m_gdkwindow
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1094 CalcBoundingBox( x
, y
);
1095 CalcBoundingBox( x
+ width
, y
+ height
);
1098 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1100 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1101 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1104 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
1105 wxCoord x
, wxCoord y
,
1108 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1110 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1112 bool is_mono
= bitmap
.GetDepth() == 1;
1114 // scale/translate size and position
1115 int xx
= XLOG2DEV(x
);
1116 int yy
= YLOG2DEV(y
);
1118 int w
= bitmap
.GetWidth();
1119 int h
= bitmap
.GetHeight();
1121 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1124 CalcBoundingBox( x
, y
);
1125 CalcBoundingBox( x
+ w
, y
+ h
);
1127 if (!m_gdkwindow
) return;
1129 int ww
= XLOG2DEVREL(w
);
1130 int hh
= YLOG2DEVREL(h
);
1132 // compare to current clipping region
1133 if (!m_currentClippingRegion
.IsNull())
1135 wxRegion
tmp( xx
,yy
,ww
,hh
);
1136 tmp
.Intersect( m_currentClippingRegion
);
1141 // scale bitmap if required
1142 wxBitmap use_bitmap
= bitmap
;
1143 if ((w
!= ww
) || (h
!= hh
))
1144 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1146 // apply mask if any
1147 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1148 if (useMask
&& use_bitmap
.GetMask())
1149 mask
= use_bitmap
.GetMask()->GetBitmap();
1151 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1153 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1157 if (!m_currentClippingRegion
.IsNull())
1160 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1161 GdkGC
*gc
= gdk_gc_new( new_mask
);
1163 gdk_gc_set_foreground( gc
, &col
);
1164 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1166 gdk_gc_set_background( gc
, &col
);
1168 gdk_gc_set_foreground( gc
, &col
);
1169 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1170 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1171 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1172 gdk_gc_set_stipple( gc
, mask
);
1173 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1175 g_object_unref (gc
);
1178 gdk_gc_set_clip_mask(use_gc
, mask
);
1179 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1182 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1183 // drawing a mono-bitmap (XBitmap) we use the current text GC
1186 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1187 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1188 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1189 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1190 gdk_wx_draw_bitmap(bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1192 gdk_draw_drawable(m_gdkwindow
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1194 g_object_unref (bitmap2
);
1195 g_object_unref (gc
);
1199 if (use_bitmap
.HasPixbuf())
1201 gdk_draw_pixbuf(m_gdkwindow
, use_gc
,
1202 use_bitmap
.GetPixbuf(),
1203 0, 0, xx
, yy
, -1, -1,
1204 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1208 gdk_draw_drawable(m_gdkwindow
, use_gc
,
1209 use_bitmap
.GetPixmap(),
1210 0, 0, xx
, yy
, -1, -1);
1214 // remove mask again if any
1217 gdk_gc_set_clip_mask(use_gc
, NULL
);
1218 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1219 if (!m_currentClippingRegion
.IsNull())
1220 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1221 if (new_mask
!= NULL
)
1222 g_object_unref(new_mask
);
1226 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1227 wxCoord width
, wxCoord height
,
1229 wxCoord xsrc
, wxCoord ysrc
,
1232 wxCoord xsrcMask
, wxCoord ysrcMask
)
1234 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1236 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1238 if (!m_gdkwindow
) return false;
1240 // transform the source DC coords to the device ones
1241 xsrc
= source
->LogicalToDeviceX(xsrc
);
1242 ysrc
= source
->LogicalToDeviceY(ysrc
);
1245 wxMemoryDC
*memDC
= wxDynamicCast(source
, wxMemoryDC
);
1248 selected
= memDC
->GetSelectedBitmap();
1249 if ( !selected
.IsOk() )
1253 bool use_bitmap_method
= false;
1254 bool is_mono
= false;
1256 if (xsrcMask
== -1 && ysrcMask
== -1)
1262 if (selected
.IsOk())
1264 is_mono
= (selected
.GetDepth() == 1);
1266 // we use the "XCopyArea" way to copy a memory dc into
1267 // a different window if the memory dc BOTH
1268 // a) doesn't have any mask or its mask isn't used
1272 if (useMask
&& (selected
.GetMask()))
1274 // we HAVE TO use the direct way for memory dcs
1275 // that have mask since the XCopyArea doesn't know
1277 use_bitmap_method
= true;
1281 // we HAVE TO use the direct way for memory dcs
1282 // that are bitmaps because XCopyArea doesn't cope
1283 // with different bit depths
1284 use_bitmap_method
= true;
1286 else if ((xsrc
== 0) && (ysrc
== 0) &&
1287 (width
== selected
.GetWidth()) &&
1288 (height
== selected
.GetHeight()))
1290 // we SHOULD use the direct way if all of the bitmap
1291 // in the memory dc is copied in which case XCopyArea
1292 // wouldn't be able able to boost performace by reducing
1293 // the area to be scaled
1294 use_bitmap_method
= true;
1298 CalcBoundingBox( xdest
, ydest
);
1299 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1301 // scale/translate size and position
1302 wxCoord xx
= XLOG2DEV(xdest
);
1303 wxCoord yy
= YLOG2DEV(ydest
);
1305 wxCoord ww
= XLOG2DEVREL(width
);
1306 wxCoord hh
= YLOG2DEVREL(height
);
1308 // compare to current clipping region
1309 if (!m_currentClippingRegion
.IsNull())
1311 wxRegion
tmp( xx
,yy
,ww
,hh
);
1312 tmp
.Intersect( m_currentClippingRegion
);
1317 int old_logical_func
= m_logicalFunction
;
1318 SetLogicalFunction( logical_func
);
1320 if (use_bitmap_method
)
1322 // scale/translate bitmap size
1323 wxCoord bm_width
= selected
.GetWidth();
1324 wxCoord bm_height
= selected
.GetHeight();
1326 // Get clip coords for the bitmap. If we don't
1327 // use wxBitmap::Rescale(), which can clip the
1328 // bitmap, these are the same as the original
1335 // interpret userscale of src too
1337 memDC
->GetUserScale(&xsc
,&ysc
);
1338 bm_width
= (int) (bm_width
/ xsc
);
1339 bm_height
= (int) (bm_height
/ ysc
);
1341 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1342 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1344 // Scale bitmap if required
1345 wxBitmap use_bitmap
= selected
;
1346 if ((selected
.GetWidth()!= bm_ww
) || ( selected
.GetHeight()!= bm_hh
))
1348 // This indicates that the blitting code below will get
1349 // a clipped bitmap and therefore needs to move the origin
1351 wxRegion
tmp( xx
,yy
,ww
,hh
);
1352 if (!m_currentClippingRegion
.IsNull())
1353 tmp
.Intersect( m_currentClippingRegion
);
1354 tmp
.GetBox(cx
,cy
,cw
,ch
);
1356 // Scale and clipped bitmap
1357 use_bitmap
= selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1360 // apply mask if any
1361 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1362 if (useMask
&& use_bitmap
.GetMask())
1363 mask
= use_bitmap
.GetMask()->GetBitmap();
1365 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1367 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1371 if (!m_currentClippingRegion
.IsNull())
1374 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1375 GdkGC
*gc
= gdk_gc_new( new_mask
);
1377 gdk_gc_set_foreground( gc
, &col
);
1378 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1379 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1381 gdk_gc_set_background( gc
, &col
);
1383 gdk_gc_set_foreground( gc
, &col
);
1384 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1385 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1386 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1387 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1388 gdk_gc_set_stipple( gc
, mask
);
1389 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1391 g_object_unref (gc
);
1394 gdk_gc_set_clip_mask(use_gc
, mask
);
1395 if (new_mask
!= NULL
)
1396 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1398 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1401 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1402 // drawing a mono-bitmap (XBitmap) we use the current text GC
1406 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1407 GdkGC
*gc
= gdk_gc_new( bitmap
);
1408 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1409 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1410 gdk_wx_draw_bitmap(bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0);
1412 gdk_draw_drawable(m_gdkwindow
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1414 g_object_unref (bitmap
);
1415 g_object_unref (gc
);
1419 // was: gdk_draw_drawable( m_gdkwindow, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1420 gdk_draw_drawable(m_gdkwindow
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1423 // remove mask again if any
1426 gdk_gc_set_clip_mask(use_gc
, NULL
);
1427 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1428 if (!m_currentClippingRegion
.IsNull())
1429 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1433 g_object_unref (new_mask
);
1435 else // use_bitmap_method
1437 if (selected
.IsOk() && ((width
!= ww
) || (height
!= hh
)))
1440 wxRegion
tmp( xx
,yy
,ww
,hh
);
1441 tmp
.Intersect( m_currentClippingRegion
);
1442 wxCoord cx
,cy
,cw
,ch
;
1443 tmp
.GetBox(cx
,cy
,cw
,ch
);
1446 wxBitmap bitmap
= selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1448 // draw scaled bitmap
1449 // was: gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1450 gdk_draw_drawable( m_gdkwindow
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1454 // No scaling and not a memory dc with a mask either
1455 GdkWindow
* window
= NULL
;
1456 wxDCImpl
*impl
= source
->GetImpl();
1457 wxWindowDCImpl
*gtk_impl
= wxDynamicCast(impl
, wxWindowDCImpl
);
1459 window
= gtk_impl
->GetGDKWindow();
1462 SetLogicalFunction( old_logical_func
);
1466 // copy including child window contents
1467 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1468 gdk_draw_drawable( m_gdkwindow
, m_penGC
,
1472 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1476 SetLogicalFunction( old_logical_func
);
1481 void wxWindowDCImpl::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1483 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1485 if (!m_gdkwindow
) return;
1487 if (text
.empty()) return;
1492 wxCHECK_RET( m_context
, wxT("no Pango context") );
1493 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1494 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1496 gdk_pango_context_set_colormap( m_context
, m_cmap
);
1498 bool underlined
= m_font
.IsOk() && m_font
.GetUnderlined();
1500 wxCharBuffer data
= wxGTK_CONV(text
);
1503 size_t datalen
= strlen(data
);
1505 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1506 // has been fixed and thus the hack implemented below should never be used
1507 static bool pangoOk
= !wx_pango_version_check(1, 16, 0);
1509 bool needshack
= underlined
&& !pangoOk
;
1513 // a PangoLayout which has leading/trailing spaces with underlined font
1514 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1515 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1516 // this behaviour. To workaround this problem, we use a special hack here
1517 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1518 // empty space characters and give them a dummy colour attribute.
1519 // This will force Pango to underline the leading/trailing spaces, too.
1521 wxCharBuffer
data_tmp(datalen
+ 6);
1522 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1523 memcpy(data_tmp
.data(), "\342\200\214", 3);
1524 // copy the user string
1525 memcpy(data_tmp
.data() + 3, data
, datalen
);
1526 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1527 memcpy(data_tmp
.data() + 3 + datalen
, "\342\200\214", 3);
1533 pango_layout_set_text(m_layout
, data
, datalen
);
1537 PangoAttrList
*attrs
= pango_attr_list_new();
1538 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1540 a
->end_index
= datalen
;
1541 pango_attr_list_insert(attrs
, a
);
1545 // dummy colour for the leading space
1546 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1549 pango_attr_list_insert(attrs
, a
);
1551 // dummy colour for the trailing space
1552 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1553 a
->start_index
= datalen
- 1;
1554 a
->end_index
= datalen
;
1555 pango_attr_list_insert(attrs
, a
);
1558 pango_layout_set_attributes(m_layout
, attrs
);
1559 pango_attr_list_unref(attrs
);
1563 const bool isScaled
= fabs(m_scaleY
- 1.0) > 0.00001;
1566 // If there is a user or actually any scale applied to
1567 // the device context, scale the font.
1569 // scale font description
1570 oldSize
= pango_font_description_get_size(m_fontdesc
);
1571 pango_font_description_set_size(m_fontdesc
, int(oldSize
* m_scaleY
));
1573 // actually apply scaled font
1574 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1578 pango_layout_get_pixel_size(m_layout
, &w
, &h
);
1579 if (m_backgroundMode
== wxSOLID
)
1581 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1582 gdk_draw_rectangle(m_gdkwindow
, m_textGC
, true, x
, y
, w
, h
);
1583 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1588 if (m_window
&& m_window
->GetLayoutDirection() == wxLayout_RightToLeft
)
1590 gdk_draw_layout(m_gdkwindow
, m_textGC
, x_rtl
, y
, m_layout
);
1594 // reset unscaled size
1595 pango_font_description_set_size( m_fontdesc
, oldSize
);
1597 // actually apply unscaled font
1598 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1602 // undo underline attributes setting:
1603 pango_layout_set_attributes(m_layout
, NULL
);
1606 CalcBoundingBox(x
+ int(w
/ m_scaleX
), y
+ int(h
/ m_scaleY
));
1607 CalcBoundingBox(x
, y
);
1611 // TODO: There is an example of rotating text with GTK2 that would probably be
1612 // a better approach here:
1613 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1615 void wxWindowDCImpl::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1618 if (!m_gdkwindow
|| text
.empty())
1621 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1623 if ( wxIsNullDouble(angle
) )
1625 DoDrawText(text
, x
, y
);
1632 // TODO: implement later without GdkFont for GTK 2.0
1633 DoGetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1635 // draw the string normally
1638 dc
.SelectObject(src
);
1639 dc
.SetFont(GetFont());
1640 dc
.SetBackground(*wxBLACK_BRUSH
);
1641 dc
.SetBrush(*wxBLACK_BRUSH
);
1643 dc
.SetTextForeground( *wxWHITE
);
1644 dc
.DrawText(text
, 0, 0);
1645 dc
.SelectObject(wxNullBitmap
);
1647 // Calculate the size of the rotated bounding box.
1648 double rad
= DegToRad(angle
);
1649 double dx
= cos(rad
),
1652 // the rectngle vertices are counted clockwise with the first one being at
1653 // (0, 0) (or, rather, at (x, y))
1655 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1658 double x3
= x4
+ x2
,
1662 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1663 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1664 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1665 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1668 wxImage image
= src
.ConvertToImage();
1670 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1671 m_textForegroundColour
.Green(),
1672 m_textForegroundColour
.Blue() );
1673 image
= image
.Rotate( rad
, wxPoint(0,0) );
1675 int i_angle
= (int) angle
;
1676 i_angle
= i_angle
% 360;
1680 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1681 xoffset
= image
.GetWidth();
1683 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1684 yoffset
= image
.GetHeight();
1686 if ((i_angle
>= 0) && (i_angle
< 90))
1687 yoffset
-= (int)( cos(rad
)*h
);
1688 if ((i_angle
>= 90) && (i_angle
< 180))
1689 xoffset
-= (int)( sin(rad
)*h
);
1690 if ((i_angle
>= 180) && (i_angle
< 270))
1691 yoffset
-= (int)( cos(rad
)*h
);
1692 if ((i_angle
>= 270) && (i_angle
< 360))
1693 xoffset
-= (int)( sin(rad
)*h
);
1695 int i_x
= x
- xoffset
;
1696 int i_y
= y
- yoffset
;
1699 DoDrawBitmap( src
, i_x
, i_y
, true );
1702 // it would be better to draw with non underlined font and draw the line
1703 // manually here (it would be more straight...)
1705 if ( m_font
.GetUnderlined() )
1707 gdk_draw_line( m_gdkwindow
, m_textGC
,
1708 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1709 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1713 // update the bounding box
1714 CalcBoundingBox(x
+ minX
, y
+ minY
);
1715 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1716 #else // !wxUSE_IMAGE
1721 #endif // wxUSE_IMAGE/!wxUSE_IMAGE
1724 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1725 wxCoord
*width
, wxCoord
*height
,
1726 wxCoord
*descent
, wxCoord
*externalLeading
,
1727 const wxFont
*theFont
) const
1735 if ( externalLeading
)
1736 *externalLeading
= 0;
1741 // ensure that theFont is always non-NULL
1742 if ( !theFont
|| !theFont
->IsOk() )
1743 theFont
= wx_const_cast(wxFont
*, &m_font
);
1745 // and use it if it's valid
1746 if ( theFont
->IsOk() )
1748 pango_layout_set_font_description
1751 theFont
->GetNativeFontInfo()->description
1755 // Set layout's text
1756 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1759 // hardly ideal, but what else can we do if conversion failed?
1763 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1768 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1769 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1770 int baseline
= pango_layout_iter_get_baseline(iter
);
1771 pango_layout_iter_free(iter
);
1772 *descent
= h
- PANGO_PIXELS(baseline
);
1775 *height
= (wxCoord
) h
;
1779 pango_layout_get_pixel_size( m_layout
, width
, height
);
1782 // Reset old font description
1783 if (theFont
->IsOk())
1784 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1788 bool wxWindowDCImpl::DoGetPartialTextExtents(const wxString
& text
,
1789 wxArrayInt
& widths
) const
1791 const size_t len
= text
.length();
1798 // Set layout's text
1799 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1802 // hardly ideal, but what else can we do if conversion failed?
1803 wxLogLastError(wxT("DoGetPartialTextExtents"));
1807 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1809 // Calculate the position of each character based on the widths of
1810 // the previous characters
1812 // Code borrowed from Scintilla's PlatGTK
1813 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1815 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1817 while (pango_layout_iter_next_cluster(iter
))
1819 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1820 int position
= PANGO_PIXELS(pos
.x
);
1821 widths
[i
++] = position
;
1824 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1825 pango_layout_iter_free(iter
);
1831 wxCoord
wxWindowDCImpl::GetCharWidth() const
1833 pango_layout_set_text( m_layout
, "H", 1 );
1835 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1839 wxCoord
wxWindowDCImpl::GetCharHeight() const
1841 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1842 wxCHECK_MSG( metrics
, -1, _T("failed to get pango font metrics") );
1844 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1845 pango_font_metrics_get_ascent (metrics
));
1846 pango_font_metrics_unref (metrics
);
1850 void wxWindowDCImpl::Clear()
1852 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1854 if (!m_gdkwindow
) return;
1857 DoGetSize( &width
, &height
);
1858 gdk_draw_rectangle( m_gdkwindow
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1861 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1868 pango_font_description_free( m_fontdesc
);
1870 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1875 PangoContext
*oldContext
= m_context
;
1877 m_context
= m_window
->GtkGetPangoDefaultContext();
1879 // If we switch back/forth between different contexts
1880 // we also have to create a new layout. I think so,
1881 // at least, and it doesn't hurt to do it.
1882 if (oldContext
!= m_context
)
1885 g_object_unref (m_layout
);
1887 m_layout
= pango_layout_new( m_context
);
1891 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1895 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1897 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1899 if (m_pen
== pen
) return;
1903 if (!m_pen
.IsOk()) return;
1905 if (!m_gdkwindow
) return;
1907 gint width
= m_pen
.GetWidth();
1910 // CMB: if width is non-zero scale it with the dc
1915 // X doesn't allow different width in x and y and so we take
1918 ( fabs((double) XLOG2DEVREL(width
)) +
1919 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1923 // width can't be 0 or an internal GTK error occurs inside
1924 // gdk_gc_set_dashes() below
1929 static const wxGTKDash dotted
[] = {1, 1};
1930 static const wxGTKDash short_dashed
[] = {2, 2};
1931 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1932 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1934 // We express dash pattern in pen width unit, so we are
1935 // independent of zoom factor and so on...
1937 const wxGTKDash
*req_dash
;
1939 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1940 switch (m_pen
.GetStyle())
1944 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1945 req_nb_dash
= m_pen
.GetDashCount();
1946 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1951 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1958 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1960 req_dash
= wxCoord_dashed
;
1965 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1967 req_dash
= short_dashed
;
1972 // lineStyle = GDK_LINE_DOUBLE_DASH;
1973 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1975 req_dash
= dotted_dashed
;
1980 case wxSTIPPLE_MASK_OPAQUE
:
1985 lineStyle
= GDK_LINE_SOLID
;
1986 req_dash
= (wxGTKDash
*)NULL
;
1992 if (req_dash
&& req_nb_dash
)
1994 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1997 for (int i
= 0; i
< req_nb_dash
; i
++)
1998 real_req_dash
[i
] = req_dash
[i
] * width
;
1999 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
2000 delete[] real_req_dash
;
2004 // No Memory. We use non-scaled dash pattern...
2005 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
2009 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
2010 switch (m_pen
.GetCap())
2012 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
2013 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
2020 capStyle
= GDK_CAP_NOT_LAST
;
2024 capStyle
= GDK_CAP_ROUND
;
2030 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
2031 switch (m_pen
.GetJoin())
2033 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
2034 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
2036 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
2039 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
2041 m_pen
.GetColour().CalcPixel( m_cmap
);
2042 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
2045 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
2047 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2049 if (m_brush
== brush
) return;
2053 if (!m_brush
.IsOk()) return;
2055 if (!m_gdkwindow
) return;
2057 m_brush
.GetColour().CalcPixel( m_cmap
);
2058 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
2060 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
2062 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->IsOk()))
2064 if (m_brush
.GetStipple()->GetDepth() != 1)
2066 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
2067 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2071 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2072 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2076 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2078 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2079 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2082 if (m_brush
.IsHatch())
2084 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2085 gdk_gc_set_stipple(m_brushGC
, GetHatch(m_brush
.GetStyle()));
2089 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
2091 /* CMB 21/7/98: Added SetBackground. Sets background brush
2092 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2094 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2096 if (m_backgroundBrush
== brush
) return;
2098 m_backgroundBrush
= brush
;
2100 if (!m_backgroundBrush
.IsOk()) return;
2102 if (!m_gdkwindow
) return;
2104 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2105 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2106 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2107 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2108 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2110 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2112 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->IsOk()))
2114 if (m_backgroundBrush
.GetStipple()->GetDepth() != 1)
2116 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2117 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2121 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2122 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2126 if (m_backgroundBrush
.IsHatch())
2128 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2129 gdk_gc_set_stipple(m_bgGC
, GetHatch(m_backgroundBrush
.GetStyle()));
2133 void wxWindowDCImpl::SetLogicalFunction( int function
)
2135 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2137 if (m_logicalFunction
== function
)
2140 // VZ: shouldn't this be a CHECK?
2147 case wxXOR
: mode
= GDK_XOR
; break;
2148 case wxINVERT
: mode
= GDK_INVERT
; break;
2149 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2150 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2151 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2152 case wxSET
: mode
= GDK_SET
; break;
2153 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2154 case wxAND
: mode
= GDK_AND
; break;
2155 case wxOR
: mode
= GDK_OR
; break;
2156 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2157 case wxNAND
: mode
= GDK_NAND
; break;
2158 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2159 case wxCOPY
: mode
= GDK_COPY
; break;
2160 case wxNO_OP
: mode
= GDK_NOOP
; break;
2161 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2163 // unsupported by GTK
2164 case wxNOR
: mode
= GDK_COPY
; break;
2166 wxFAIL_MSG( wxT("unsupported logical function") );
2170 m_logicalFunction
= function
;
2172 gdk_gc_set_function( m_penGC
, mode
);
2173 gdk_gc_set_function( m_brushGC
, mode
);
2175 // to stay compatible with wxMSW, we don't apply ROPs to the text
2176 // operations (i.e. DrawText/DrawRotatedText).
2177 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2178 gdk_gc_set_function( m_textGC
, mode
);
2181 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
2183 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2185 // don't set m_textForegroundColour to an invalid colour as we'd crash
2186 // later then (we use m_textForegroundColour.GetColor() without checking
2188 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
2191 m_textForegroundColour
= col
;
2195 m_textForegroundColour
.CalcPixel( m_cmap
);
2196 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2200 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
2202 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2205 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
2208 m_textBackgroundColour
= col
;
2212 m_textBackgroundColour
.CalcPixel( m_cmap
);
2213 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2217 void wxWindowDCImpl::SetBackgroundMode( int mode
)
2219 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2221 m_backgroundMode
= mode
;
2223 if (!m_gdkwindow
) return;
2225 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2226 // transparent/solid background mode
2228 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2230 gdk_gc_set_fill( m_brushGC
,
2231 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2235 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2237 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
2240 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2242 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2244 if (!m_gdkwindow
) return;
2247 rect
.x
= XLOG2DEV(x
);
2248 rect
.y
= YLOG2DEV(y
);
2249 rect
.width
= XLOG2DEVREL(width
);
2250 rect
.height
= YLOG2DEVREL(height
);
2252 if (m_window
&& m_window
->m_wxwindow
&&
2253 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2255 rect
.x
-= rect
.width
;
2258 if (!m_currentClippingRegion
.IsNull())
2259 m_currentClippingRegion
.Intersect( rect
);
2261 m_currentClippingRegion
.Union( rect
);
2263 #if USE_PAINT_REGION
2264 if (!m_paintClippingRegion
.IsNull())
2265 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2268 wxCoord xx
, yy
, ww
, hh
;
2269 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2271 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2273 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2276 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2277 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2278 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2279 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2282 void wxWindowDCImpl::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2284 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2288 DestroyClippingRegion();
2292 if (!m_gdkwindow
) return;
2294 if (!m_currentClippingRegion
.IsNull())
2295 m_currentClippingRegion
.Intersect( region
);
2297 m_currentClippingRegion
.Union( region
);
2299 #if USE_PAINT_REGION
2300 if (!m_paintClippingRegion
.IsNull())
2301 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2304 wxCoord xx
, yy
, ww
, hh
;
2305 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2307 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2309 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2312 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2313 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2314 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2315 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2318 void wxWindowDCImpl::DestroyClippingRegion()
2320 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2323 wxDCImpl::DestroyClippingRegion();
2325 wxDC::DestroyClippingRegion();
2328 m_currentClippingRegion
.Clear();
2330 #if USE_PAINT_REGION
2331 if (!m_paintClippingRegion
.IsEmpty())
2332 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2335 if (!m_gdkwindow
) return;
2337 if (m_currentClippingRegion
.IsEmpty())
2339 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2340 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2341 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2342 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2346 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2347 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2348 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2349 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2353 void wxWindowDCImpl::Destroy()
2355 if (m_penGC
) wxFreePoolGC( m_penGC
);
2356 m_penGC
= (GdkGC
*) NULL
;
2357 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2358 m_brushGC
= (GdkGC
*) NULL
;
2359 if (m_textGC
) wxFreePoolGC( m_textGC
);
2360 m_textGC
= (GdkGC
*) NULL
;
2361 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2362 m_bgGC
= (GdkGC
*) NULL
;
2365 void wxWindowDCImpl::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2367 m_deviceOriginX
= x
;
2368 m_deviceOriginY
= y
;
2370 ComputeScaleAndOrigin();
2373 void wxWindowDCImpl::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2375 m_signX
= (xLeftRight
? 1 : -1);
2376 m_signY
= (yBottomUp
? -1 : 1);
2378 if (m_window
&& m_window
->m_wxwindow
&&
2379 (m_window
->GetLayoutDirection() == wxLayout_RightToLeft
))
2382 ComputeScaleAndOrigin();
2385 void wxWindowDCImpl::ComputeScaleAndOrigin()
2387 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2390 wxDCImpl::ComputeScaleAndOrigin();
2392 wxDC::ComputeScaleAndOrigin();
2395 // if scale has changed call SetPen to recalulate the line width
2396 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2398 // this is a bit artificial, but we need to force wxDC to think the pen
2406 // Resolution in pixels per logical inch
2407 wxSize
wxWindowDCImpl::GetPPI() const
2409 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2412 int wxWindowDCImpl::GetDepth() const
2414 return gdk_drawable_get_depth(m_gdkwindow
);
2418 //-----------------------------------------------------------------------------
2420 //-----------------------------------------------------------------------------
2422 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2424 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
2425 : wxWindowDCImpl( owner
)
2429 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*win
)
2430 : wxWindowDCImpl( owner
, win
)
2432 wxCHECK_RET( win
, _T("NULL window in wxClientDCImpl::wxClientDC") );
2434 #ifdef __WXUNIVERSAL__
2435 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2436 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2437 wxSize size
= win
->GetClientSize();
2438 DoSetClippingRegion(0, 0, size
.x
, size
.y
);
2443 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2445 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
2447 m_window
->GetClientSize( width
, height
);
2450 //-----------------------------------------------------------------------------
2452 //-----------------------------------------------------------------------------
2454 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2456 // Limit the paint region to the window size. Sometimes
2457 // the paint region is too big, and this risks X11 errors
2458 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2460 wxRect originalRect
= region
.GetBox();
2461 wxRect
rect(originalRect
);
2462 if (rect
.width
+ rect
.x
> sz
.x
)
2463 rect
.width
= sz
.x
- rect
.x
;
2464 if (rect
.height
+ rect
.y
> sz
.y
)
2465 rect
.height
= sz
.y
- rect
.y
;
2466 if (rect
!= originalRect
)
2468 region
= wxRegion(rect
);
2469 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2470 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2471 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2475 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
2476 : wxClientDCImpl( owner
)
2480 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*win
)
2481 : wxClientDCImpl( owner
, win
)
2483 #if USE_PAINT_REGION
2484 if (!win
->m_clipPaintRegion
)
2487 wxSize sz
= win
->GetSize();
2488 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2489 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2491 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2494 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2495 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2497 if (sz
.x
<= 0 || sz
.y
<= 0)
2500 gdk_gc_set_clip_region( m_penGC
, region
);
2501 gdk_gc_set_clip_region( m_brushGC
, region
);
2502 gdk_gc_set_clip_region( m_textGC
, region
);
2503 gdk_gc_set_clip_region( m_bgGC
, region
);
2508 // ----------------------------------------------------------------------------
2510 // ----------------------------------------------------------------------------
2512 class wxDCModule
: public wxModule
2519 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2522 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2524 bool wxDCModule::OnInit()
2530 void wxDCModule::OnExit()
2534 for (int i
= wxLAST_HATCH
- wxFIRST_HATCH
; i
--; )
2537 g_object_unref(hatches
[i
]);