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/dcclient.h"
20 #include "wx/window.h"
22 #include "wx/dcmemory.h"
23 #include "wx/math.h" // for floating-point functions
25 #include "wx/module.h"
28 #include "wx/fontutil.h"
29 #include "wx/scrolwin.h"
31 #include "wx/gtk/win_gtk.h"
32 #include "wx/gtk/private.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #define USE_PAINT_REGION 1
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
54 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
55 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
58 static GdkPixmap
*hatches
[num_hatches
];
59 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
61 extern GtkWidget
*wxGetRootWindow();
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 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 //-----------------------------------------------------------------------------
79 // temporary implementation of the missing GDK function
80 //-----------------------------------------------------------------------------
82 #include "gdk/gdkprivate.h"
85 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
95 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
96 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
97 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
99 gint src_width
, src_height
;
100 gdk_drawable_get_size(src
, &src_width
, &src_height
);
101 if (width
== -1) width
= src_width
;
102 if (height
== -1) height
= src_height
;
104 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
106 GDK_WINDOW_XID(drawable
),
114 //-----------------------------------------------------------------------------
115 // Implement Pool of Graphic contexts. Creating them takes too much time.
116 //-----------------------------------------------------------------------------
142 #define GC_POOL_ALLOC_SIZE 100
144 static int wxGCPoolSize
= 0;
146 static wxGC
*wxGCPool
= NULL
;
148 static void wxInitGCPool()
150 // This really could wait until the first call to
151 // wxGetPoolGC, but we will make the first allocation
152 // now when other initialization is being performed.
154 // Set initial pool size.
155 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
157 // Allocate initial pool.
158 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
159 if (wxGCPool
== NULL
)
161 // If we cannot malloc, then fail with error
162 // when debug is enabled. If debug is not enabled,
163 // the problem will eventually get caught
165 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
169 // Zero initial pool.
170 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
173 static void wxCleanUpGCPool()
175 for (int i
= 0; i
< wxGCPoolSize
; i
++)
177 if (wxGCPool
[i
].m_gc
)
178 g_object_unref (wxGCPool
[i
].m_gc
);
186 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
190 // Look for an available GC.
191 for (int i
= 0; i
< wxGCPoolSize
; i
++)
193 if (!wxGCPool
[i
].m_gc
)
195 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
196 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
197 wxGCPool
[i
].m_type
= type
;
198 wxGCPool
[i
].m_used
= false;
200 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
202 wxGCPool
[i
].m_used
= true;
203 return wxGCPool
[i
].m_gc
;
207 // We did not find an available GC.
208 // We need to grow the GC pool.
209 pptr
= (wxGC
*)realloc(wxGCPool
,
210 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
213 // Initialize newly allocated pool.
215 memset(&wxGCPool
[wxGCPoolSize
], 0,
216 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
218 // Initialize entry we will return.
219 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
220 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
221 wxGCPool
[wxGCPoolSize
].m_type
= type
;
222 wxGCPool
[wxGCPoolSize
].m_used
= true;
224 // Set new value of pool size.
225 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
227 // Return newly allocated entry.
228 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
231 // The realloc failed. Fall through to error.
232 wxFAIL_MSG( wxT("No GC available") );
234 return (GdkGC
*) NULL
;
237 static void wxFreePoolGC( GdkGC
*gc
)
239 for (int i
= 0; i
< wxGCPoolSize
; i
++)
241 if (wxGCPool
[i
].m_gc
== gc
)
243 wxGCPool
[i
].m_used
= false;
248 wxFAIL_MSG( wxT("Wrong GC") );
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
256 IMPLEMENT_DYNAMIC_CLASS(wxGTKWindowImplDC
, wxGTKImplDC
)
258 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
261 wxGTKWindowImplDC::wxGTKWindowImplDC()
263 m_penGC
= (GdkGC
*) NULL
;
264 m_brushGC
= (GdkGC
*) NULL
;
265 m_textGC
= (GdkGC
*) NULL
;
266 m_bgGC
= (GdkGC
*) NULL
;
267 m_cmap
= (GdkColormap
*) NULL
;
269 m_isScreenDC
= false;
270 m_owner
= (wxWindow
*)NULL
;
271 m_context
= (PangoContext
*)NULL
;
272 m_layout
= (PangoLayout
*)NULL
;
273 m_fontdesc
= (PangoFontDescription
*)NULL
;
276 wxGTKWindowImplDC::wxGTKWindowImplDC( wxWindow
*window
)
278 wxASSERT_MSG( window
, wxT("DC needs a window") );
280 m_penGC
= (GdkGC
*) NULL
;
281 m_brushGC
= (GdkGC
*) NULL
;
282 m_textGC
= (GdkGC
*) NULL
;
283 m_bgGC
= (GdkGC
*) NULL
;
284 m_cmap
= (GdkColormap
*) NULL
;
285 m_owner
= (wxWindow
*)NULL
;
287 m_isScreenDC
= false;
288 m_font
= window
->GetFont();
290 GtkWidget
*widget
= window
->m_wxwindow
;
292 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
293 // code should still be able to create wxClientDCs for them, so we will
294 // use the parent window here then.
297 window
= window
->GetParent();
298 widget
= window
->m_wxwindow
;
301 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
303 m_context
= window
->GtkGetPangoDefaultContext();
304 m_layout
= pango_layout_new( m_context
);
305 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
307 GtkPizza
*pizza
= GTK_PIZZA( widget
);
308 m_window
= pizza
->bin_window
;
310 // Window not realized ?
313 // Don't report problems as per MSW.
319 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
323 /* this must be done after SetUpDC, bacause SetUpDC calls the
324 repective SetBrush, SetPen, SetBackground etc functions
325 to set up the DC. SetBackground call m_owner->SetBackground
326 and this might not be desired as the standard dc background
327 is white whereas a window might assume gray to be the
328 standard (as e.g. wxStatusBar) */
332 if (m_owner
&& m_owner
->m_wxwindow
&& (m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
))
337 // origin in the upper right corner
338 m_deviceOriginX
= m_owner
->GetClientSize().x
;
342 wxGTKWindowImplDC::~wxGTKWindowImplDC()
347 g_object_unref (m_layout
);
349 pango_font_description_free( m_fontdesc
);
352 void wxGTKWindowImplDC::SetUpDC()
356 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
360 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
361 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
362 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
363 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
366 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
368 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
369 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
370 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
371 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
375 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
376 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
377 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
378 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
381 /* background colour */
382 m_backgroundBrush
= *wxWHITE_BRUSH
;
383 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
385 const GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
387 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
391 m_textForegroundColour
.CalcPixel( m_cmap
);
392 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
394 m_textBackgroundColour
.CalcPixel( m_cmap
);
395 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
397 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
399 gdk_gc_set_colormap( m_textGC
, m_cmap
);
402 m_pen
.GetColour().CalcPixel( m_cmap
);
403 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
404 gdk_gc_set_background( m_penGC
, bg_col
);
406 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
409 m_brush
.GetColour().CalcPixel( m_cmap
);
410 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
411 gdk_gc_set_background( m_brushGC
, bg_col
);
413 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
416 gdk_gc_set_background( m_bgGC
, bg_col
);
417 gdk_gc_set_foreground( m_bgGC
, bg_col
);
419 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
422 gdk_gc_set_function( m_textGC
, GDK_COPY
);
423 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
424 gdk_gc_set_function( m_penGC
, GDK_COPY
);
427 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
428 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
429 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
430 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
434 hatch_bitmap
= hatches
;
435 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
436 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
437 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
438 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
439 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
440 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
444 void wxGTKWindowImplDC::DoGetSize( int* width
, int* height
) const
446 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
448 m_owner
->GetSize(width
, height
);
451 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
452 const wxColour
& col
, int style
);
454 bool wxGTKWindowImplDC::DoFloodFill(wxCoord x
, wxCoord y
,
455 const wxColour
& col
, int style
)
457 return wxDoFloodFill(this, x
, y
, col
, style
);
460 bool wxGTKWindowImplDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
462 // Generic (and therefore rather inefficient) method.
463 // Could be improved.
465 wxBitmap
bitmap(1, 1);
466 memdc
.SelectObject(bitmap
);
467 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
468 memdc
.SelectObject(wxNullBitmap
);
470 wxImage image
= bitmap
.ConvertToImage();
471 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
475 void wxGTKWindowImplDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
477 wxCHECK_RET( Ok(), wxT("invalid window dc") );
479 if (m_pen
.GetStyle() != wxTRANSPARENT
)
482 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
484 CalcBoundingBox(x1
, y1
);
485 CalcBoundingBox(x2
, y2
);
489 void wxGTKWindowImplDC::DoCrossHair( wxCoord x
, wxCoord y
)
491 wxCHECK_RET( Ok(), wxT("invalid window dc") );
493 if (m_pen
.GetStyle() != wxTRANSPARENT
)
498 wxCoord xx
= XLOG2DEV(x
);
499 wxCoord yy
= YLOG2DEV(y
);
502 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
503 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
508 void wxGTKWindowImplDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
509 wxCoord xc
, wxCoord yc
)
511 wxCHECK_RET( Ok(), wxT("invalid window dc") );
513 wxCoord xx1
= XLOG2DEV(x1
);
514 wxCoord yy1
= YLOG2DEV(y1
);
515 wxCoord xx2
= XLOG2DEV(x2
);
516 wxCoord yy2
= YLOG2DEV(y2
);
517 wxCoord xxc
= XLOG2DEV(xc
);
518 wxCoord yyc
= YLOG2DEV(yc
);
519 double dx
= xx1
- xxc
;
520 double dy
= yy1
- yyc
;
521 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
522 wxCoord r
= (wxCoord
)radius
;
523 double radius1
, radius2
;
525 if (xx1
== xx2
&& yy1
== yy2
)
530 else if ( wxIsNullDouble(radius
) )
537 radius1
= (xx1
- xxc
== 0) ?
538 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
539 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
540 radius2
= (xx2
- xxc
== 0) ?
541 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
542 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
544 wxCoord alpha1
= wxCoord(radius1
* 64.0);
545 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
546 while (alpha2
<= 0) alpha2
+= 360*64;
547 while (alpha1
> 360*64) alpha1
-= 360*64;
551 if (m_brush
.GetStyle() != wxTRANSPARENT
)
553 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
555 gdk_gc_set_ts_origin( m_textGC
,
556 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
557 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
558 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
559 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
561 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
563 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
564 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
565 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
567 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
569 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
570 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
571 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
573 if (m_brush
.GetStyle() == wxSTIPPLE
)
575 gdk_gc_set_ts_origin( m_brushGC
,
576 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
577 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
578 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
579 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
583 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
587 if (m_pen
.GetStyle() != wxTRANSPARENT
)
589 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
591 if ((m_brush
.GetStyle() != wxTRANSPARENT
) && (alpha2
- alpha1
!= 360*64))
593 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
594 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
599 CalcBoundingBox (x1
, y1
);
600 CalcBoundingBox (x2
, y2
);
603 void wxGTKWindowImplDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
605 wxCHECK_RET( Ok(), wxT("invalid window dc") );
607 wxCoord xx
= XLOG2DEV(x
);
608 wxCoord yy
= YLOG2DEV(y
);
609 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
610 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
612 // CMB: handle -ve width and/or height
613 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
614 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
618 wxCoord start
= wxCoord(sa
* 64.0);
619 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
621 if (m_brush
.GetStyle() != wxTRANSPARENT
)
623 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
625 gdk_gc_set_ts_origin( m_textGC
,
626 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
627 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
628 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
629 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
631 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
633 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
634 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
635 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
637 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
639 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
640 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
641 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
643 if (m_brush
.GetStyle() == wxSTIPPLE
)
645 gdk_gc_set_ts_origin( m_brushGC
,
646 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
647 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
648 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
649 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
653 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
657 if (m_pen
.GetStyle() != wxTRANSPARENT
)
658 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
661 CalcBoundingBox (x
, y
);
662 CalcBoundingBox (x
+ width
, y
+ height
);
665 void wxGTKWindowImplDC::DoDrawPoint( wxCoord x
, wxCoord y
)
667 wxCHECK_RET( Ok(), wxT("invalid window dc") );
669 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
670 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
672 CalcBoundingBox (x
, y
);
675 void wxGTKWindowImplDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
677 wxCHECK_RET( Ok(), wxT("invalid window dc") );
679 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
682 //Check, if scaling is necessary
684 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
686 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
687 GdkPoint
* gpts
= reinterpret_cast<GdkPoint
*>(points
);
690 gpts
= new GdkPoint
[n
];
692 for (int i
= 0; i
< n
; i
++)
696 gpts
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
697 gpts
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
699 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
703 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
709 void wxGTKWindowImplDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
711 wxCHECK_RET( Ok(), wxT("invalid window dc") );
715 //Check, if scaling is necessary
717 xoffset
!= 0 || yoffset
!= 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
719 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
720 GdkPoint
* gdkpoints
= reinterpret_cast<GdkPoint
*>(points
);
723 gdkpoints
= new GdkPoint
[n
];
726 for (i
= 0 ; i
< n
; i
++)
730 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
731 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
733 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
738 if (m_brush
.GetStyle() != wxTRANSPARENT
)
740 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
742 gdk_gc_set_ts_origin( m_textGC
,
743 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
744 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
745 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
746 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
748 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
750 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
751 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
752 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
754 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
756 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
757 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
758 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
760 if (m_brush
.GetStyle() == wxSTIPPLE
)
762 gdk_gc_set_ts_origin( m_brushGC
,
763 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
764 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
765 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
766 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
770 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
774 if (m_pen
.GetStyle() != wxTRANSPARENT
)
777 for (i = 0 ; i < n ; i++)
779 gdk_draw_line( m_window, m_penGC,
782 gdkpoints[(i+1)%n].x,
783 gdkpoints[(i+1)%n].y);
786 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gdkpoints
, n
);
795 void wxGTKWindowImplDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
797 wxCHECK_RET( Ok(), wxT("invalid window dc") );
799 wxCoord xx
= XLOG2DEV(x
);
800 wxCoord yy
= YLOG2DEV(y
);
801 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
802 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
804 // CMB: draw nothing if transformed w or h is 0
805 if (ww
== 0 || hh
== 0) return;
807 // CMB: handle -ve width and/or height
808 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
809 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
813 if (m_brush
.GetStyle() != wxTRANSPARENT
)
815 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
817 gdk_gc_set_ts_origin( m_textGC
,
818 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
819 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
820 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
821 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
823 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
825 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
826 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
827 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
829 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
831 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
832 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
833 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
835 if (m_brush
.GetStyle() == wxSTIPPLE
)
837 gdk_gc_set_ts_origin( m_brushGC
,
838 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
839 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
840 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
841 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
845 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
849 if (m_pen
.GetStyle() != wxTRANSPARENT
)
852 if ((m_pen
.GetWidth() == 2) && (m_pen
.GetCap() == wxCAP_ROUND
) &&
853 (m_pen
.GetJoin() == wxJOIN_ROUND
) && (m_pen
.GetStyle() == wxSOLID
))
855 // Use 2 1-line rects instead
856 gdk_gc_set_line_attributes( m_penGC
, 1, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
861 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
+1, yy
, ww
-2, hh
-2 );
862 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
-1, ww
, hh
);
866 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-2, hh
-2 );
867 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
-1, yy
-1, ww
, hh
);
871 gdk_gc_set_line_attributes( m_penGC
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
876 // Just use X11 for other cases
877 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
882 CalcBoundingBox( x
, y
);
883 CalcBoundingBox( x
+ width
, y
+ height
);
886 void wxGTKWindowImplDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
888 wxCHECK_RET( Ok(), wxT("invalid window dc") );
890 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
892 wxCoord xx
= XLOG2DEV(x
);
893 wxCoord yy
= YLOG2DEV(y
);
894 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
895 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
896 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
898 // CMB: handle -ve width and/or height
899 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
900 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
902 // CMB: if radius is zero use DrawRectangle() instead to avoid
903 // X drawing errors with small radii
906 DrawRectangle( x
, y
, width
, height
);
910 // CMB: draw nothing if transformed w or h is 0
911 if (ww
== 0 || hh
== 0) return;
913 // CMB: adjust size if outline is drawn otherwise the result is
914 // 1 pixel too wide and high
915 if (m_pen
.GetStyle() != wxTRANSPARENT
)
923 // CMB: ensure dd is not larger than rectangle otherwise we
924 // get an hour glass shape
926 if (dd
> ww
) dd
= ww
;
927 if (dd
> hh
) dd
= hh
;
930 if (m_brush
.GetStyle() != wxTRANSPARENT
)
932 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
934 gdk_gc_set_ts_origin( m_textGC
,
935 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
936 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
937 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
938 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
939 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
940 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
941 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
942 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
943 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
945 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
947 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
948 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
949 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
950 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
951 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
952 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
953 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
954 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
956 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
958 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
959 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
960 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
961 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
962 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
963 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
964 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
965 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
967 if (m_brush
.GetStyle() == wxSTIPPLE
)
969 gdk_gc_set_ts_origin( m_brushGC
,
970 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
971 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
972 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
973 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
974 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
975 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
976 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
977 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
978 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
982 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
983 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
984 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
985 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
986 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
987 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
991 if (m_pen
.GetStyle() != wxTRANSPARENT
)
993 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
994 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
995 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
996 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
997 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
998 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
999 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
1000 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
1004 // this ignores the radius
1005 CalcBoundingBox( x
, y
);
1006 CalcBoundingBox( x
+ width
, y
+ height
);
1009 void wxGTKWindowImplDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1011 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1013 wxCoord xx
= XLOG2DEV(x
);
1014 wxCoord yy
= YLOG2DEV(y
);
1015 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1016 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1018 // CMB: handle -ve width and/or height
1019 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1020 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1024 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1026 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1028 gdk_gc_set_ts_origin( m_textGC
,
1029 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1030 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1031 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1032 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
1034 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1036 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
1037 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1038 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1040 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1042 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1043 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1044 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1046 if (m_brush
.GetStyle() == wxSTIPPLE
)
1048 gdk_gc_set_ts_origin( m_brushGC
,
1049 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1050 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1051 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1052 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1056 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1060 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1061 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1064 CalcBoundingBox( x
, y
);
1065 CalcBoundingBox( x
+ width
, y
+ height
);
1068 void wxGTKWindowImplDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1070 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1071 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1074 void wxGTKWindowImplDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1075 wxCoord x
, wxCoord y
,
1078 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1080 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1082 bool is_mono
= bitmap
.GetDepth() == 1;
1084 // scale/translate size and position
1085 int xx
= XLOG2DEV(x
);
1086 int yy
= YLOG2DEV(y
);
1088 int w
= bitmap
.GetWidth();
1089 int h
= bitmap
.GetHeight();
1091 if (m_owner
&& m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
)
1094 CalcBoundingBox( x
, y
);
1095 CalcBoundingBox( x
+ w
, y
+ h
);
1097 if (!m_window
) return;
1099 int ww
= XLOG2DEVREL(w
);
1100 int hh
= YLOG2DEVREL(h
);
1102 // compare to current clipping region
1103 if (!m_currentClippingRegion
.IsNull())
1105 wxRegion
tmp( xx
,yy
,ww
,hh
);
1106 tmp
.Intersect( m_currentClippingRegion
);
1111 // scale bitmap if required
1112 wxBitmap use_bitmap
= bitmap
;
1113 if ((w
!= ww
) || (h
!= hh
))
1114 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1116 #if !GTK_CHECK_VERSION(2,2,0)
1117 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1118 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1119 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1120 // and also creates the mask as a side-effect:
1121 use_bitmap
.GetPixmap();
1124 // apply mask if any
1125 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1126 if (useMask
&& use_bitmap
.GetMask())
1127 mask
= use_bitmap
.GetMask()->GetBitmap();
1129 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1131 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1135 if (!m_currentClippingRegion
.IsNull())
1138 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1139 GdkGC
*gc
= gdk_gc_new( new_mask
);
1141 gdk_gc_set_foreground( gc
, &col
);
1142 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1144 gdk_gc_set_background( gc
, &col
);
1146 gdk_gc_set_foreground( gc
, &col
);
1147 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1148 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1149 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1150 gdk_gc_set_stipple( gc
, mask
);
1151 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1153 g_object_unref (gc
);
1156 gdk_gc_set_clip_mask(use_gc
, mask
);
1157 gdk_gc_set_clip_origin(use_gc
, xx
, yy
);
1160 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1161 // drawing a mono-bitmap (XBitmap) we use the current text GC
1164 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1165 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1166 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1167 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1168 gdk_wx_draw_bitmap( bitmap2
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1170 gdk_draw_drawable(m_window
, use_gc
, bitmap2
, 0, 0, xx
, yy
, -1, -1);
1172 g_object_unref (bitmap2
);
1173 g_object_unref (gc
);
1177 #if GTK_CHECK_VERSION(2,2,0)
1178 if (!gtk_check_version(2,2,0) && use_bitmap
.HasPixbuf())
1180 gdk_draw_pixbuf(m_window
, use_gc
,
1181 use_bitmap
.GetPixbuf(),
1182 0, 0, xx
, yy
, -1, -1,
1183 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1188 gdk_draw_drawable(m_window
, use_gc
,
1189 use_bitmap
.GetPixmap(),
1190 0, 0, xx
, yy
, -1, -1);
1194 // remove mask again if any
1197 gdk_gc_set_clip_mask(use_gc
, NULL
);
1198 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1199 if (!m_currentClippingRegion
.IsNull())
1200 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1201 if (new_mask
!= NULL
)
1202 g_object_unref(new_mask
);
1206 bool wxGTKWindowImplDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1207 wxCoord width
, wxCoord height
,
1209 wxCoord xsrc
, wxCoord ysrc
,
1212 wxCoord xsrcMask
, wxCoord ysrcMask
)
1214 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
1216 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1218 if (!m_window
) return false;
1220 // transform the source DC coords to the device ones
1221 xsrc
= source
->LogicalToDeviceX(xsrc
);
1222 ysrc
= source
->LogicalToDeviceY(ysrc
);
1225 wxMemoryDC
*memDC
= wxDynamicCast(source
, wxMemoryDC
);
1228 selected
= memDC
->GetSelectedBitmap();
1229 if ( !selected
.IsOk() )
1233 bool use_bitmap_method
= false;
1234 bool is_mono
= false;
1236 if (xsrcMask
== -1 && ysrcMask
== -1)
1244 is_mono
= (selected
.GetDepth() == 1);
1246 // we use the "XCopyArea" way to copy a memory dc into
1247 // a different window if the memory dc BOTH
1248 // a) doesn't have any mask or its mask isn't used
1252 if (useMask
&& (selected
.GetMask()))
1254 // we HAVE TO use the direct way for memory dcs
1255 // that have mask since the XCopyArea doesn't know
1257 use_bitmap_method
= true;
1261 // we HAVE TO use the direct way for memory dcs
1262 // that are bitmaps because XCopyArea doesn't cope
1263 // with different bit depths
1264 use_bitmap_method
= true;
1266 else if ((xsrc
== 0) && (ysrc
== 0) &&
1267 (width
== selected
.GetWidth()) &&
1268 (height
== selected
.GetHeight()))
1270 // we SHOULD use the direct way if all of the bitmap
1271 // in the memory dc is copied in which case XCopyArea
1272 // wouldn't be able able to boost performace by reducing
1273 // the area to be scaled
1274 use_bitmap_method
= true;
1278 CalcBoundingBox( xdest
, ydest
);
1279 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1281 // scale/translate size and position
1282 wxCoord xx
= XLOG2DEV(xdest
);
1283 wxCoord yy
= YLOG2DEV(ydest
);
1285 wxCoord ww
= XLOG2DEVREL(width
);
1286 wxCoord hh
= YLOG2DEVREL(height
);
1288 // compare to current clipping region
1289 if (!m_currentClippingRegion
.IsNull())
1291 wxRegion
tmp( xx
,yy
,ww
,hh
);
1292 tmp
.Intersect( m_currentClippingRegion
);
1297 int old_logical_func
= m_logicalFunction
;
1298 SetLogicalFunction( logical_func
);
1300 if (use_bitmap_method
)
1302 // scale/translate bitmap size
1303 wxCoord bm_width
= selected
.GetWidth();
1304 wxCoord bm_height
= selected
.GetHeight();
1306 // Get clip coords for the bitmap. If we don't
1307 // use wxBitmap::Rescale(), which can clip the
1308 // bitmap, these are the same as the original
1315 // interpret userscale of src too
1317 memDC
->GetUserScale(&xsc
,&ysc
);
1318 bm_width
= (int) (bm_width
/ xsc
);
1319 bm_height
= (int) (bm_height
/ ysc
);
1321 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1322 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1324 // Scale bitmap if required
1325 wxBitmap use_bitmap
= selected
;
1326 if ((selected
.GetWidth()!= bm_ww
) || ( selected
.GetHeight()!= bm_hh
))
1328 // This indicates that the blitting code below will get
1329 // a clipped bitmap and therefore needs to move the origin
1331 wxRegion
tmp( xx
,yy
,ww
,hh
);
1332 if (!m_currentClippingRegion
.IsNull())
1333 tmp
.Intersect( m_currentClippingRegion
);
1334 tmp
.GetBox(cx
,cy
,cw
,ch
);
1336 // Scale and clipped bitmap
1337 use_bitmap
= selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1340 // apply mask if any
1341 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1342 if (useMask
&& use_bitmap
.GetMask())
1343 mask
= use_bitmap
.GetMask()->GetBitmap();
1345 GdkGC
* use_gc
= is_mono
? m_textGC
: m_penGC
;
1347 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1351 if (!m_currentClippingRegion
.IsNull())
1354 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1355 GdkGC
*gc
= gdk_gc_new( new_mask
);
1357 gdk_gc_set_foreground( gc
, &col
);
1358 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1359 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1361 gdk_gc_set_background( gc
, &col
);
1363 gdk_gc_set_foreground( gc
, &col
);
1364 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1365 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1366 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1367 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1368 gdk_gc_set_stipple( gc
, mask
);
1369 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1371 g_object_unref (gc
);
1374 gdk_gc_set_clip_mask(use_gc
, mask
);
1375 if (new_mask
!= NULL
)
1376 gdk_gc_set_clip_origin(use_gc
, cx
, cy
);
1378 gdk_gc_set_clip_origin(use_gc
, cx
- xsrcMask
, cy
- ysrcMask
);
1381 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1382 // drawing a mono-bitmap (XBitmap) we use the current text GC
1386 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1387 GdkGC
*gc
= gdk_gc_new( bitmap
);
1388 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1389 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1390 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetPixmap(), 0, 0, 0, 0, -1, -1 );
1392 gdk_draw_drawable(m_window
, use_gc
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1394 g_object_unref (bitmap
);
1395 g_object_unref (gc
);
1399 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1400 gdk_draw_drawable(m_window
, use_gc
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1403 // remove mask again if any
1406 gdk_gc_set_clip_mask(use_gc
, NULL
);
1407 gdk_gc_set_clip_origin(use_gc
, 0, 0);
1408 if (!m_currentClippingRegion
.IsNull())
1409 gdk_gc_set_clip_region(use_gc
, m_currentClippingRegion
.GetRegion());
1413 g_object_unref (new_mask
);
1415 else // use_bitmap_method
1417 if (selected
.Ok() && ((width
!= ww
) || (height
!= hh
)))
1420 wxRegion
tmp( xx
,yy
,ww
,hh
);
1421 tmp
.Intersect( m_currentClippingRegion
);
1422 wxCoord cx
,cy
,cw
,ch
;
1423 tmp
.GetBox(cx
,cy
,cw
,ch
);
1426 wxBitmap bitmap
= selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1428 // draw scaled bitmap
1429 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1430 gdk_draw_drawable( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1434 // No scaling and not a memory dc with a mask either
1436 GdkWindow
* window
= source
->GetGDKWindow();
1440 // copy including child window contents
1441 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1442 gdk_draw_drawable( m_window
, m_penGC
,
1446 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1450 SetLogicalFunction( old_logical_func
);
1455 void wxGTKWindowImplDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1457 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1459 if (!m_window
) return;
1461 if (text
.empty()) return;
1466 wxCHECK_RET( m_context
, wxT("no Pango context") );
1467 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1468 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1470 gdk_pango_context_set_colormap( m_context
, m_cmap
);
1472 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1474 const wxCharBuffer data
= wxGTK_CONV( text
);
1477 size_t datalen
= strlen(data
);
1479 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1480 // has been fixed and thus the hack implemented below should never be used
1481 static bool pangoOk
= !wx_pango_version_check(1, 16, 0);
1483 bool needshack
= underlined
&& !pangoOk
;
1484 char *hackstring
= NULL
;
1488 // a PangoLayout which has leading/trailing spaces with underlined font
1489 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1490 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1491 // this behaviour. To workaround this problem, we use a special hack here
1492 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1493 // empty space characters and give them a dummy colour attribute.
1494 // This will force Pango to underline the leading/trailing spaces, too.
1496 // need to realloc the string to prepend & append our special characters
1497 hackstring
= (char*)malloc((datalen
+7)*sizeof(char));
1499 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1500 strcpy(hackstring
, "\342\200\214");
1502 // copy the user string
1503 memcpy(&hackstring
[3], data
, datalen
);
1505 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1506 strcpy(&hackstring
[datalen
+3], "\342\200\214");
1508 // the special characters that we added require 6 additional bytes:
1511 pango_layout_set_text(m_layout
, hackstring
, datalen
);
1515 pango_layout_set_text(m_layout
, data
, datalen
);
1520 PangoAttrList
*attrs
= pango_attr_list_new();
1521 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1523 a
->end_index
= datalen
;
1524 pango_attr_list_insert(attrs
, a
);
1528 // dummy colour for the leading space
1529 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1532 pango_attr_list_insert(attrs
, a
);
1534 // dummy colour for the trailing space
1535 a
= pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1536 a
->start_index
= datalen
- 1;
1537 a
->end_index
= datalen
;
1538 pango_attr_list_insert(attrs
, a
);
1541 pango_layout_set_attributes(m_layout
, attrs
);
1542 pango_attr_list_unref(attrs
);
1547 if (fabs(m_scaleY
- 1.0) > 0.00001)
1549 // If there is a user or actually any scale applied to
1550 // the device context, scale the font.
1552 // scale font description
1553 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1554 double size
= oldSize
;
1555 size
= size
* m_scaleY
;
1556 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1558 // actually apply scaled font
1559 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1561 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1562 if ( m_backgroundMode
== wxSOLID
)
1564 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1565 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1566 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1570 if (m_owner
&& m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
)
1571 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1573 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1575 // reset unscaled size
1576 pango_font_description_set_size( m_fontdesc
, oldSize
);
1578 // actually apply unscaled font
1579 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1583 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1584 if ( m_backgroundMode
== wxSOLID
)
1586 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1587 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1588 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1592 if (m_owner
&& m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
)
1593 gdk_draw_layout( m_window
, m_textGC
, x
-w
, y
, m_layout
);
1595 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1600 // undo underline attributes setting:
1601 pango_layout_set_attributes(m_layout
, NULL
);
1607 width
= wxCoord(width
/ m_scaleX
);
1608 height
= wxCoord(height
/ m_scaleY
);
1609 CalcBoundingBox (x
+ width
, y
+ height
);
1610 CalcBoundingBox (x
, y
);
1617 // TODO: There is an example of rotating text with GTK2 that would probably be
1618 // a better approach here:
1619 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1621 void wxGTKWindowImplDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1623 if (!m_window
|| text
.empty())
1626 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1628 if ( wxIsNullDouble(angle
) )
1630 DrawText(text
, x
, y
);
1637 // TODO: implement later without GdkFont for GTK 2.0
1638 GetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1640 // draw the string normally
1643 dc
.SelectObject(src
);
1644 dc
.SetFont(GetFont());
1645 dc
.SetBackground(*wxBLACK_BRUSH
);
1646 dc
.SetBrush(*wxBLACK_BRUSH
);
1648 dc
.SetTextForeground( *wxWHITE
);
1649 dc
.DrawText(text
, 0, 0);
1650 dc
.SelectObject(wxNullBitmap
);
1652 // Calculate the size of the rotated bounding box.
1653 double rad
= DegToRad(angle
);
1654 double dx
= cos(rad
),
1657 // the rectngle vertices are counted clockwise with the first one being at
1658 // (0, 0) (or, rather, at (x, y))
1660 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1663 double x3
= x4
+ x2
,
1667 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1668 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1669 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1670 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1673 wxImage image
= src
.ConvertToImage();
1675 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1676 m_textForegroundColour
.Green(),
1677 m_textForegroundColour
.Blue() );
1678 image
= image
.Rotate( rad
, wxPoint(0,0) );
1680 int i_angle
= (int) angle
;
1681 i_angle
= i_angle
% 360;
1685 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1686 xoffset
= image
.GetWidth();
1688 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1689 yoffset
= image
.GetHeight();
1691 if ((i_angle
>= 0) && (i_angle
< 90))
1692 yoffset
-= (int)( cos(rad
)*h
);
1693 if ((i_angle
>= 90) && (i_angle
< 180))
1694 xoffset
-= (int)( sin(rad
)*h
);
1695 if ((i_angle
>= 180) && (i_angle
< 270))
1696 yoffset
-= (int)( cos(rad
)*h
);
1697 if ((i_angle
>= 270) && (i_angle
< 360))
1698 xoffset
-= (int)( sin(rad
)*h
);
1700 int i_x
= x
- xoffset
;
1701 int i_y
= y
- yoffset
;
1704 DoDrawBitmap( src
, i_x
, i_y
, true );
1707 // it would be better to draw with non underlined font and draw the line
1708 // manually here (it would be more straight...)
1710 if ( m_font
.GetUnderlined() )
1712 gdk_draw_line( m_window
, m_textGC
,
1713 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1714 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1718 // update the bounding box
1719 CalcBoundingBox(x
+ minX
, y
+ minY
);
1720 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1723 void wxGTKWindowImplDC::DoGetTextExtent(const wxString
&string
,
1724 wxCoord
*width
, wxCoord
*height
,
1725 wxCoord
*descent
, wxCoord
*externalLeading
,
1726 const wxFont
*theFont
) const
1734 if ( externalLeading
)
1735 *externalLeading
= 0;
1740 // ensure that theFont is always non-NULL
1741 if ( !theFont
|| !theFont
->Ok() )
1742 theFont
= wx_const_cast(wxFont
*, &m_font
);
1744 // and use it if it's valid
1745 if ( theFont
->Ok() )
1747 pango_layout_set_font_description
1750 theFont
->GetNativeFontInfo()->description
1754 // Set layout's text
1755 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(string
, *theFont
);
1758 // hardly ideal, but what else can we do if conversion failed?
1762 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1767 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1768 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1769 int baseline
= pango_layout_iter_get_baseline(iter
);
1770 pango_layout_iter_free(iter
);
1771 *descent
= h
- PANGO_PIXELS(baseline
);
1774 *height
= (wxCoord
) h
;
1778 pango_layout_get_pixel_size( m_layout
, width
, height
);
1781 // Reset old font description
1782 if (theFont
->IsOk())
1783 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1787 bool wxGTKWindowImplDC::DoGetPartialTextExtents(const wxString
& text
,
1788 wxArrayInt
& widths
) const
1790 const size_t len
= text
.length();
1797 // Set layout's text
1798 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(text
, m_font
);
1801 // hardly ideal, but what else can we do if conversion failed?
1802 wxLogLastError(wxT("DoGetPartialTextExtents"));
1806 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1808 // Calculate the position of each character based on the widths of
1809 // the previous characters
1811 // Code borrowed from Scintilla's PlatGTK
1812 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1814 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1816 while (pango_layout_iter_next_cluster(iter
))
1818 pango_layout_iter_get_cluster_extents(iter
, NULL
, &pos
);
1819 int position
= PANGO_PIXELS(pos
.x
);
1820 widths
[i
++] = position
;
1823 widths
[i
++] = PANGO_PIXELS(pos
.x
+ pos
.width
);
1824 pango_layout_iter_free(iter
);
1830 wxCoord
wxGTKWindowImplDC::GetCharWidth() const
1832 pango_layout_set_text( m_layout
, "H", 1 );
1834 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1838 wxCoord
wxGTKWindowImplDC::GetCharHeight() const
1840 PangoFontMetrics
*metrics
= pango_context_get_metrics (m_context
, m_fontdesc
, pango_context_get_language(m_context
));
1841 wxCHECK_MSG( metrics
, -1, _T("failed to get pango font metrics") );
1843 wxCoord h
= PANGO_PIXELS (pango_font_metrics_get_descent (metrics
) +
1844 pango_font_metrics_get_ascent (metrics
));
1845 pango_font_metrics_unref (metrics
);
1849 void wxGTKWindowImplDC::Clear()
1851 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1853 if (!m_window
) return;
1855 // VZ: the code below results in infinite recursion and crashes when
1856 // dc.Clear() is done from OnPaint() so I disable it for now.
1857 // I don't know what the correct fix is but Clear() surely should not
1858 // reenter OnPaint()!
1860 /* - we either are a memory dc or have a window as the
1861 owner. anything else shouldn't happen.
1862 - we don't use gdk_window_clear() as we don't set
1863 the window's background colour anymore. it is too
1864 much pain to keep the DC's and the window's back-
1865 ground colour in synch. */
1876 GetSize( &width
, &height
);
1877 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1882 GetSize( &width
, &height
);
1883 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1887 void wxGTKWindowImplDC::SetFont( const wxFont
&font
)
1894 pango_font_description_free( m_fontdesc
);
1896 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1901 PangoContext
*oldContext
= m_context
;
1903 m_context
= m_owner
->GtkGetPangoDefaultContext();
1905 // If we switch back/forth between different contexts
1906 // we also have to create a new layout. I think so,
1907 // at least, and it doesn't hurt to do it.
1908 if (oldContext
!= m_context
)
1911 g_object_unref (m_layout
);
1913 m_layout
= pango_layout_new( m_context
);
1917 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1921 void wxGTKWindowImplDC::SetPen( const wxPen
&pen
)
1923 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1925 if (m_pen
== pen
) return;
1929 if (!m_pen
.Ok()) return;
1931 if (!m_window
) return;
1933 gint width
= m_pen
.GetWidth();
1936 // CMB: if width is non-zero scale it with the dc
1941 // X doesn't allow different width in x and y and so we take
1944 ( fabs((double) XLOG2DEVREL(width
)) +
1945 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1949 // width can't be 0 or an internal GTK error occurs inside
1950 // gdk_gc_set_dashes() below
1955 static const wxGTKDash dotted
[] = {1, 1};
1956 static const wxGTKDash short_dashed
[] = {2, 2};
1957 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1958 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1960 // We express dash pattern in pen width unit, so we are
1961 // independent of zoom factor and so on...
1963 const wxGTKDash
*req_dash
;
1965 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1966 switch (m_pen
.GetStyle())
1970 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1971 req_nb_dash
= m_pen
.GetDashCount();
1972 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1977 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1984 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1986 req_dash
= wxCoord_dashed
;
1991 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1993 req_dash
= short_dashed
;
1998 // lineStyle = GDK_LINE_DOUBLE_DASH;
1999 lineStyle
= GDK_LINE_ON_OFF_DASH
;
2001 req_dash
= dotted_dashed
;
2006 case wxSTIPPLE_MASK_OPAQUE
:
2011 lineStyle
= GDK_LINE_SOLID
;
2012 req_dash
= (wxGTKDash
*)NULL
;
2018 if (req_dash
&& req_nb_dash
)
2020 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
2023 for (int i
= 0; i
< req_nb_dash
; i
++)
2024 real_req_dash
[i
] = req_dash
[i
] * width
;
2025 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
2026 delete[] real_req_dash
;
2030 // No Memory. We use non-scaled dash pattern...
2031 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
2035 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
2036 switch (m_pen
.GetCap())
2038 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
2039 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
2046 capStyle
= GDK_CAP_NOT_LAST
;
2050 capStyle
= GDK_CAP_ROUND
;
2056 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
2057 switch (m_pen
.GetJoin())
2059 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
2060 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
2062 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
2065 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
2067 m_pen
.GetColour().CalcPixel( m_cmap
);
2068 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
2071 void wxGTKWindowImplDC::SetBrush( const wxBrush
&brush
)
2073 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2075 if (m_brush
== brush
) return;
2079 if (!m_brush
.Ok()) return;
2081 if (!m_window
) return;
2083 m_brush
.GetColour().CalcPixel( m_cmap
);
2084 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
2086 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
2088 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
2090 if (m_brush
.GetStipple()->GetDepth() != 1)
2092 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
2093 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2097 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2098 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2102 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2104 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2105 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2108 if (m_brush
.IsHatch())
2110 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2111 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
2112 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
2116 void wxGTKWindowImplDC::SetBackground( const wxBrush
&brush
)
2118 /* CMB 21/7/98: Added SetBackground. Sets background brush
2119 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2121 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2123 if (m_backgroundBrush
== brush
) return;
2125 m_backgroundBrush
= brush
;
2127 if (!m_backgroundBrush
.Ok()) return;
2129 if (!m_window
) return;
2131 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2132 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2133 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2134 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2135 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2137 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2139 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
2141 if (m_backgroundBrush
.GetStipple()->GetDepth() != 1)
2143 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2144 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2148 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2149 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2153 if (m_backgroundBrush
.IsHatch())
2155 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2156 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2157 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2161 void wxGTKWindowImplDC::SetLogicalFunction( int function
)
2163 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2165 if (m_logicalFunction
== function
)
2168 // VZ: shouldn't this be a CHECK?
2175 case wxXOR
: mode
= GDK_XOR
; break;
2176 case wxINVERT
: mode
= GDK_INVERT
; break;
2177 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2178 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2179 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2180 case wxSET
: mode
= GDK_SET
; break;
2181 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2182 case wxAND
: mode
= GDK_AND
; break;
2183 case wxOR
: mode
= GDK_OR
; break;
2184 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2185 case wxNAND
: mode
= GDK_NAND
; break;
2186 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2187 case wxCOPY
: mode
= GDK_COPY
; break;
2188 case wxNO_OP
: mode
= GDK_NOOP
; break;
2189 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2191 // unsupported by GTK
2192 case wxNOR
: mode
= GDK_COPY
; break;
2194 wxFAIL_MSG( wxT("unsupported logical function") );
2198 m_logicalFunction
= function
;
2200 gdk_gc_set_function( m_penGC
, mode
);
2201 gdk_gc_set_function( m_brushGC
, mode
);
2203 // to stay compatible with wxMSW, we don't apply ROPs to the text
2204 // operations (i.e. DrawText/DrawRotatedText).
2205 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2206 gdk_gc_set_function( m_textGC
, mode
);
2209 void wxGTKWindowImplDC::SetTextForeground( const wxColour
&col
)
2211 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2213 // don't set m_textForegroundColour to an invalid colour as we'd crash
2214 // later then (we use m_textForegroundColour.GetColor() without checking
2216 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2219 m_textForegroundColour
= col
;
2223 m_textForegroundColour
.CalcPixel( m_cmap
);
2224 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2228 void wxGTKWindowImplDC::SetTextBackground( const wxColour
&col
)
2230 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2233 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2236 m_textBackgroundColour
= col
;
2240 m_textBackgroundColour
.CalcPixel( m_cmap
);
2241 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2245 void wxGTKWindowImplDC::SetBackgroundMode( int mode
)
2247 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2249 m_backgroundMode
= mode
;
2251 if (!m_window
) return;
2253 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2254 // transparent/solid background mode
2256 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2258 gdk_gc_set_fill( m_brushGC
,
2259 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2263 void wxGTKWindowImplDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2265 wxFAIL_MSG( wxT("wxGTKWindowImplDC::SetPalette not implemented") );
2268 void wxGTKWindowImplDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2270 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2272 if (!m_window
) return;
2275 rect
.x
= XLOG2DEV(x
);
2276 rect
.y
= YLOG2DEV(y
);
2277 rect
.width
= XLOG2DEVREL(width
);
2278 rect
.height
= YLOG2DEVREL(height
);
2280 if (m_owner
&& m_owner
->m_wxwindow
&& (m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
))
2282 rect
.x
-= rect
.width
;
2285 if (!m_currentClippingRegion
.IsNull())
2286 m_currentClippingRegion
.Intersect( rect
);
2288 m_currentClippingRegion
.Union( rect
);
2290 #if USE_PAINT_REGION
2291 if (!m_paintClippingRegion
.IsNull())
2292 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2295 wxCoord xx
, yy
, ww
, hh
;
2296 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2297 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2299 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2300 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2301 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2302 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2305 void wxGTKWindowImplDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2307 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2311 DestroyClippingRegion();
2315 if (!m_window
) return;
2317 if (!m_currentClippingRegion
.IsNull())
2318 m_currentClippingRegion
.Intersect( region
);
2320 m_currentClippingRegion
.Union( region
);
2322 #if USE_PAINT_REGION
2323 if (!m_paintClippingRegion
.IsNull())
2324 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2327 wxCoord xx
, yy
, ww
, hh
;
2328 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2329 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2331 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2332 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2333 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2334 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2337 void wxGTKWindowImplDC::DestroyClippingRegion()
2339 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2341 wxDC::DestroyClippingRegion();
2343 m_currentClippingRegion
.Clear();
2345 #if USE_PAINT_REGION
2346 if (!m_paintClippingRegion
.IsEmpty())
2347 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2350 if (!m_window
) return;
2352 if (m_currentClippingRegion
.IsEmpty())
2354 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2355 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2356 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2357 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2361 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2362 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2363 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2364 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2368 void wxGTKWindowImplDC::Destroy()
2370 if (m_penGC
) wxFreePoolGC( m_penGC
);
2371 m_penGC
= (GdkGC
*) NULL
;
2372 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2373 m_brushGC
= (GdkGC
*) NULL
;
2374 if (m_textGC
) wxFreePoolGC( m_textGC
);
2375 m_textGC
= (GdkGC
*) NULL
;
2376 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2377 m_bgGC
= (GdkGC
*) NULL
;
2380 void wxGTKWindowImplDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
2382 m_deviceOriginX
= x
;
2383 m_deviceOriginY
= y
;
2385 ComputeScaleAndOrigin();
2388 void wxGTKWindowImplDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
2390 m_signX
= (xLeftRight
? 1 : -1);
2391 m_signY
= (yBottomUp
? -1 : 1);
2393 if (m_owner
&& m_owner
->m_wxwindow
&& (m_owner
->GetLayoutDirection() == wxLayout_RightToLeft
))
2396 ComputeScaleAndOrigin();
2399 void wxGTKWindowImplDC::ComputeScaleAndOrigin()
2401 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2403 wxDC::ComputeScaleAndOrigin();
2405 // if scale has changed call SetPen to recalulate the line width
2406 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.Ok() )
2408 // this is a bit artificial, but we need to force wxDC to think the pen
2416 // Resolution in pixels per logical inch
2417 wxSize
wxGTKWindowImplDC::GetPPI() const
2419 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2422 int wxGTKWindowImplDC::GetDepth() const
2424 return gdk_drawable_get_depth(m_window
);
2428 //-----------------------------------------------------------------------------
2430 //-----------------------------------------------------------------------------
2433 IMPLEMENT_DYNAMIC_CLASS(wxGTKPaintImplDC
, wxGTKClientImplDC
)
2435 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2438 // Limit the paint region to the window size. Sometimes
2439 // the paint region is too big, and this risks X11 errors
2440 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2442 wxRect originalRect
= region
.GetBox();
2443 wxRect
rect(originalRect
);
2444 if (rect
.width
+ rect
.x
> sz
.x
)
2445 rect
.width
= sz
.x
- rect
.x
;
2446 if (rect
.height
+ rect
.y
> sz
.y
)
2447 rect
.height
= sz
.y
- rect
.y
;
2448 if (rect
!= originalRect
)
2450 region
= wxRegion(rect
);
2451 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2452 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2453 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2457 wxGTKPaintImplDC::wxGTKPaintImplDC( wxWindow
*win
)
2458 : wxGTKClientImplDC( win
)
2460 #if USE_PAINT_REGION
2461 if (!win
->m_clipPaintRegion
)
2464 wxSize sz
= win
->GetSize();
2465 m_paintClippingRegion
= win
->m_nativeUpdateRegion
;
2466 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2468 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2471 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2472 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2474 if (sz
.x
<= 0 || sz
.y
<= 0)
2477 gdk_gc_set_clip_region( m_penGC
, region
);
2478 gdk_gc_set_clip_region( m_brushGC
, region
);
2479 gdk_gc_set_clip_region( m_textGC
, region
);
2480 gdk_gc_set_clip_region( m_bgGC
, region
);
2482 #endif // USE_PAINT_REGION
2485 //-----------------------------------------------------------------------------
2487 //-----------------------------------------------------------------------------
2490 IMPLEMENT_DYNAMIC_CLASS(wxGTKClientImplDC
, wxGTKWindowImplDC
)
2492 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2495 wxGTKClientImplDC::wxGTKClientImplDC( wxWindow
*win
)
2496 : wxGTKWindowImplDC( win
)
2498 wxCHECK_RET( win
, _T("NULL window in wxGTKClientImplDC::wxClientDC") );
2500 #ifdef __WXUNIVERSAL__
2501 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2502 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2503 wxSize size
= win
->GetClientSize();
2504 SetClippingRegion(wxPoint(0, 0), size
);
2505 #endif // __WXUNIVERSAL__
2508 void wxGTKClientImplDC::DoGetSize(int *width
, int *height
) const
2510 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2512 m_owner
->GetClientSize( width
, height
);
2515 // ----------------------------------------------------------------------------
2517 // ----------------------------------------------------------------------------
2519 class wxDCModule
: public wxModule
2526 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2529 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2531 bool wxDCModule::OnInit()
2537 void wxDCModule::OnExit()