]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
18 #include "wx/dcmemory.h"
20 #include "wx/module.h"
22 #include "wx/fontutil.h"
24 #include "wx/gtk/win_gtk.h"
26 #include "wx/math.h" // for floating-point functions
30 #include <gdk/gdkprivate.h>
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define USE_PAINT_REGION 1
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
51 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
52 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
55 static GdkPixmap
*hatches
[num_hatches
];
56 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
58 extern GtkWidget
*wxGetRootWindow();
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 const double RAD2DEG
= 180.0 / M_PI
;
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
71 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
73 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
75 //-----------------------------------------------------------------------------
76 // temporary implementation of the missing GDK function
77 //-----------------------------------------------------------------------------
79 #include "gdk/gdkprivate.h"
81 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
91 wxCHECK_RET( drawable
, _T("NULL drawable in gdk_wx_draw_bitmap") );
92 wxCHECK_RET( src
, _T("NULL src in gdk_wx_draw_bitmap") );
93 wxCHECK_RET( gc
, _T("NULL gc in gdk_wx_draw_bitmap") );
96 gint src_width
, src_height
;
97 gdk_drawable_get_size(src
, &src_width
, &src_height
);
98 if (width
== -1) width
= src_width
;
99 if (height
== -1) height
= src_height
;
101 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
103 GDK_WINDOW_XID(drawable
),
110 GdkWindowPrivate
*drawable_private
;
111 GdkWindowPrivate
*src_private
;
112 GdkGCPrivate
*gc_private
;
114 drawable_private
= (GdkWindowPrivate
*) drawable
;
115 src_private
= (GdkWindowPrivate
*) src
;
116 if (drawable_private
->destroyed
|| src_private
->destroyed
)
119 gint src_width
= src_private
->width
;
120 gint src_height
= src_private
->height
;
122 gc_private
= (GdkGCPrivate
*) gc
;
124 if (width
== -1) width
= src_width
;
125 if (height
== -1) height
= src_height
;
127 XCopyPlane( drawable_private
->xdisplay
,
128 src_private
->xwindow
,
129 drawable_private
->xwindow
,
138 //-----------------------------------------------------------------------------
139 // Implement Pool of Graphic contexts. Creating them takes too much time.
140 //-----------------------------------------------------------------------------
166 #define GC_POOL_ALLOC_SIZE 100
168 static int wxGCPoolSize
= 0;
170 static wxGC
*wxGCPool
= NULL
;
172 static void wxInitGCPool()
174 // This really could wait until the first call to
175 // wxGetPoolGC, but we will make the first allocation
176 // now when other initialization is being performed.
178 // Set initial pool size.
179 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
181 // Allocate initial pool.
182 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
183 if (wxGCPool
== NULL
)
185 // If we cannot malloc, then fail with error
186 // when debug is enabled. If debug is not enabled,
187 // the problem will eventually get caught
189 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
193 // Zero initial pool.
194 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
197 static void wxCleanUpGCPool()
199 for (int i
= 0; i
< wxGCPoolSize
; i
++)
201 if (wxGCPool
[i
].m_gc
)
202 gdk_gc_unref( wxGCPool
[i
].m_gc
);
210 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
214 // Look for an available GC.
215 for (int i
= 0; i
< wxGCPoolSize
; i
++)
217 if (!wxGCPool
[i
].m_gc
)
219 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
220 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
221 wxGCPool
[i
].m_type
= type
;
222 wxGCPool
[i
].m_used
= false;
224 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
226 wxGCPool
[i
].m_used
= true;
227 return wxGCPool
[i
].m_gc
;
231 // We did not find an available GC.
232 // We need to grow the GC pool.
233 pptr
= (wxGC
*)realloc(wxGCPool
,
234 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
237 // Initialize newly allocated pool.
239 memset(&wxGCPool
[wxGCPoolSize
], 0,
240 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
242 // Initialize entry we will return.
243 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
244 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
245 wxGCPool
[wxGCPoolSize
].m_type
= type
;
246 wxGCPool
[wxGCPoolSize
].m_used
= true;
248 // Set new value of pool size.
249 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
251 // Return newly allocated entry.
252 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
255 // The realloc failed. Fall through to error.
256 wxFAIL_MSG( wxT("No GC available") );
258 return (GdkGC
*) NULL
;
261 static void wxFreePoolGC( GdkGC
*gc
)
263 for (int i
= 0; i
< wxGCPoolSize
; i
++)
265 if (wxGCPool
[i
].m_gc
== gc
)
267 wxGCPool
[i
].m_used
= false;
272 wxFAIL_MSG( wxT("Wrong GC") );
275 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
279 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
281 wxWindowDC::wxWindowDC()
283 m_penGC
= (GdkGC
*) NULL
;
284 m_brushGC
= (GdkGC
*) NULL
;
285 m_textGC
= (GdkGC
*) NULL
;
286 m_bgGC
= (GdkGC
*) NULL
;
287 m_cmap
= (GdkColormap
*) NULL
;
289 m_isScreenDC
= false;
290 m_owner
= (wxWindow
*)NULL
;
292 m_context
= (PangoContext
*)NULL
;
293 m_layout
= (PangoLayout
*)NULL
;
294 m_fontdesc
= (PangoFontDescription
*)NULL
;
298 wxWindowDC::wxWindowDC( wxWindow
*window
)
300 wxASSERT_MSG( window
, wxT("DC needs a window") );
302 m_penGC
= (GdkGC
*) NULL
;
303 m_brushGC
= (GdkGC
*) NULL
;
304 m_textGC
= (GdkGC
*) NULL
;
305 m_bgGC
= (GdkGC
*) NULL
;
306 m_cmap
= (GdkColormap
*) NULL
;
307 m_owner
= (wxWindow
*)NULL
;
309 m_isScreenDC
= false;
310 m_font
= window
->GetFont();
312 GtkWidget
*widget
= window
->m_wxwindow
;
314 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
315 // code should still be able to create wxClientDCs for them, so we will
316 // use the parent window here then.
319 window
= window
->GetParent();
320 widget
= window
->m_wxwindow
;
323 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
326 m_context
= window
->GtkGetPangoDefaultContext();
327 m_layout
= pango_layout_new( m_context
);
328 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
331 GtkPizza
*pizza
= GTK_PIZZA( widget
);
332 m_window
= pizza
->bin_window
;
334 // Window not realized ?
337 // Don't report problems as per MSW.
343 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
347 /* this must be done after SetUpDC, bacause SetUpDC calls the
348 repective SetBrush, SetPen, SetBackground etc functions
349 to set up the DC. SetBackground call m_owner->SetBackground
350 and this might not be desired as the standard dc background
351 is white whereas a window might assume gray to be the
352 standard (as e.g. wxStatusBar) */
357 wxWindowDC::~wxWindowDC()
363 g_object_unref( G_OBJECT( m_layout
) );
365 pango_font_description_free( m_fontdesc
);
369 void wxWindowDC::SetUpDC()
373 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
377 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
378 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
379 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
380 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
383 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
385 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
386 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
387 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
388 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
392 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
393 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
394 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
395 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
398 /* background colour */
399 m_backgroundBrush
= *wxWHITE_BRUSH
;
400 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
401 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
404 m_textForegroundColour
.CalcPixel( m_cmap
);
405 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
407 m_textBackgroundColour
.CalcPixel( m_cmap
);
408 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
410 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
413 m_pen
.GetColour().CalcPixel( m_cmap
);
414 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
415 gdk_gc_set_background( m_penGC
, bg_col
);
417 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
420 m_brush
.GetColour().CalcPixel( m_cmap
);
421 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
422 gdk_gc_set_background( m_brushGC
, bg_col
);
424 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
427 gdk_gc_set_background( m_bgGC
, bg_col
);
428 gdk_gc_set_foreground( m_bgGC
, bg_col
);
430 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
433 gdk_gc_set_function( m_textGC
, GDK_COPY
);
434 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
435 gdk_gc_set_function( m_penGC
, GDK_COPY
);
438 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
439 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
440 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
441 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
445 hatch_bitmap
= hatches
;
446 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
447 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
448 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
449 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
450 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
451 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
455 void wxWindowDC::DoGetSize( int* width
, int* height
) const
457 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
459 m_owner
->GetSize(width
, height
);
462 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
463 const wxColour
& col
, int style
);
465 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
466 const wxColour
& col
, int style
)
468 return wxDoFloodFill(this, x
, y
, col
, style
);
471 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
473 // Generic (and therefore rather inefficient) method.
474 // Could be improved.
476 wxBitmap
bitmap(1, 1);
477 memdc
.SelectObject(bitmap
);
478 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
479 memdc
.SelectObject(wxNullBitmap
);
481 wxImage image
= bitmap
.ConvertToImage();
482 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
486 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
488 wxCHECK_RET( Ok(), wxT("invalid window dc") );
490 if (m_pen
.GetStyle() != wxTRANSPARENT
)
493 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
495 CalcBoundingBox(x1
, y1
);
496 CalcBoundingBox(x2
, y2
);
500 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
502 wxCHECK_RET( Ok(), wxT("invalid window dc") );
504 if (m_pen
.GetStyle() != wxTRANSPARENT
)
509 wxCoord xx
= XLOG2DEV(x
);
510 wxCoord yy
= YLOG2DEV(y
);
513 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
514 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
519 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
520 wxCoord xc
, wxCoord yc
)
522 wxCHECK_RET( Ok(), wxT("invalid window dc") );
524 wxCoord xx1
= XLOG2DEV(x1
);
525 wxCoord yy1
= YLOG2DEV(y1
);
526 wxCoord xx2
= XLOG2DEV(x2
);
527 wxCoord yy2
= YLOG2DEV(y2
);
528 wxCoord xxc
= XLOG2DEV(xc
);
529 wxCoord yyc
= YLOG2DEV(yc
);
530 double dx
= xx1
- xxc
;
531 double dy
= yy1
- yyc
;
532 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
533 wxCoord r
= (wxCoord
)radius
;
534 double radius1
, radius2
;
536 if (xx1
== xx2
&& yy1
== yy2
)
541 else if ( wxIsNullDouble(radius
) )
548 radius1
= (xx1
- xxc
== 0) ?
549 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
550 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
551 radius2
= (xx2
- xxc
== 0) ?
552 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
553 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
555 wxCoord alpha1
= wxCoord(radius1
* 64.0);
556 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
557 while (alpha2
<= 0) alpha2
+= 360*64;
558 while (alpha1
> 360*64) alpha1
-= 360*64;
562 if (m_brush
.GetStyle() != wxTRANSPARENT
)
564 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
566 gdk_gc_set_ts_origin( m_textGC
,
567 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
568 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
569 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
570 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
572 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
574 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
575 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
576 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
578 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
580 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
581 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
582 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
584 if (m_brush
.GetStyle() == wxSTIPPLE
)
586 gdk_gc_set_ts_origin( m_brushGC
,
587 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
588 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
589 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
590 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
594 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
598 if (m_pen
.GetStyle() != wxTRANSPARENT
)
600 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
602 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
603 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
607 CalcBoundingBox (x1
, y1
);
608 CalcBoundingBox (x2
, y2
);
611 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
613 wxCHECK_RET( Ok(), wxT("invalid window dc") );
615 wxCoord xx
= XLOG2DEV(x
);
616 wxCoord yy
= YLOG2DEV(y
);
617 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
618 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
620 // CMB: handle -ve width and/or height
621 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
622 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
626 wxCoord start
= wxCoord(sa
* 64.0);
627 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
629 if (m_brush
.GetStyle() != wxTRANSPARENT
)
631 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
633 gdk_gc_set_ts_origin( m_textGC
,
634 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
635 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
636 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
637 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
639 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
641 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
642 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
643 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
645 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
647 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
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 );
651 if (m_brush
.GetStyle() == wxSTIPPLE
)
653 gdk_gc_set_ts_origin( m_brushGC
,
654 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
655 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
656 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
657 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
661 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
665 if (m_pen
.GetStyle() != wxTRANSPARENT
)
666 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
669 CalcBoundingBox (x
, y
);
670 CalcBoundingBox (x
+ width
, y
+ height
);
673 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
675 wxCHECK_RET( Ok(), wxT("invalid window dc") );
677 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
678 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
680 CalcBoundingBox (x
, y
);
683 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
685 wxCHECK_RET( Ok(), wxT("invalid window dc") );
687 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
690 GdkPoint
*gpts
= new GdkPoint
[n
];
693 wxFAIL_MSG( wxT("Cannot allocate PolyLine") );
697 for (int i
= 0; i
< n
; i
++)
699 wxCoord x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
700 wxCoord y1
= YLOG2DEV(points
[i
].y
+ yoffset
);
702 CalcBoundingBox( x1
+ xoffset
, y1
+ yoffset
);
709 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
714 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
716 wxCHECK_RET( Ok(), wxT("invalid window dc") );
720 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
722 for (i
= 0 ; i
< n
; i
++)
724 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
725 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
727 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
732 if (m_brush
.GetStyle() != wxTRANSPARENT
)
734 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
736 gdk_gc_set_ts_origin( m_textGC
,
737 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
738 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
739 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
740 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
742 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
744 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
745 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
746 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
748 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
750 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
751 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
752 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
754 if (m_brush
.GetStyle() == wxSTIPPLE
)
756 gdk_gc_set_ts_origin( m_brushGC
,
757 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
758 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
759 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
760 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
764 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
768 if (m_pen
.GetStyle() != wxTRANSPARENT
)
771 for (i = 0 ; i < n ; i++)
773 gdk_draw_line( m_window, m_penGC,
776 gdkpoints[(i+1)%n].x,
777 gdkpoints[(i+1)%n].y);
780 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gdkpoints
, n
);
788 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
790 wxCHECK_RET( Ok(), wxT("invalid window dc") );
792 wxCoord xx
= XLOG2DEV(x
);
793 wxCoord yy
= YLOG2DEV(y
);
794 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
795 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
797 // CMB: draw nothing if transformed w or h is 0
798 if (ww
== 0 || hh
== 0) return;
800 // CMB: handle -ve width and/or height
801 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
802 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
806 if (m_brush
.GetStyle() != wxTRANSPARENT
)
808 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
810 gdk_gc_set_ts_origin( m_textGC
,
811 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
812 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
813 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
814 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
816 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
818 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
819 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
820 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
822 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
824 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
825 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
826 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
828 if (m_brush
.GetStyle() == wxSTIPPLE
)
830 gdk_gc_set_ts_origin( m_brushGC
,
831 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
832 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
833 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
834 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
838 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
842 if (m_pen
.GetStyle() != wxTRANSPARENT
)
843 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
846 CalcBoundingBox( x
, y
);
847 CalcBoundingBox( x
+ width
, y
+ height
);
850 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
852 wxCHECK_RET( Ok(), wxT("invalid window dc") );
854 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
856 wxCoord xx
= XLOG2DEV(x
);
857 wxCoord yy
= YLOG2DEV(y
);
858 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
859 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
860 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
862 // CMB: handle -ve width and/or height
863 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
864 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
866 // CMB: if radius is zero use DrawRectangle() instead to avoid
867 // X drawing errors with small radii
870 DrawRectangle( x
, y
, width
, height
);
874 // CMB: draw nothing if transformed w or h is 0
875 if (ww
== 0 || hh
== 0) return;
877 // CMB: adjust size if outline is drawn otherwise the result is
878 // 1 pixel too wide and high
879 if (m_pen
.GetStyle() != wxTRANSPARENT
)
887 // CMB: ensure dd is not larger than rectangle otherwise we
888 // get an hour glass shape
890 if (dd
> ww
) dd
= ww
;
891 if (dd
> hh
) dd
= hh
;
894 if (m_brush
.GetStyle() != wxTRANSPARENT
)
896 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
898 gdk_gc_set_ts_origin( m_textGC
,
899 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
900 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
901 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
902 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
903 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
904 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
905 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
906 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
907 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
909 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
911 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
912 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
913 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
914 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
915 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
916 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
917 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
918 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
920 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
922 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
923 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
924 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
925 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
926 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
927 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
928 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
929 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
931 if (m_brush
.GetStyle() == wxSTIPPLE
)
933 gdk_gc_set_ts_origin( m_brushGC
,
934 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
935 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
936 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
937 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
938 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
939 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
940 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
941 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
942 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
946 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
947 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
948 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
949 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
950 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
951 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
955 if (m_pen
.GetStyle() != wxTRANSPARENT
)
957 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
958 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
959 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
960 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
961 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
962 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
963 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
964 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
968 // this ignores the radius
969 CalcBoundingBox( x
, y
);
970 CalcBoundingBox( x
+ width
, y
+ height
);
973 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
975 wxCHECK_RET( Ok(), wxT("invalid window dc") );
977 wxCoord xx
= XLOG2DEV(x
);
978 wxCoord yy
= YLOG2DEV(y
);
979 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
980 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
982 // CMB: handle -ve width and/or height
983 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
984 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
988 if (m_brush
.GetStyle() != wxTRANSPARENT
)
990 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
992 gdk_gc_set_ts_origin( m_textGC
,
993 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
994 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
995 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
996 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
998 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1000 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
1001 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1002 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1004 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1006 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1007 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1008 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1010 if (m_brush
.GetStyle() == wxSTIPPLE
)
1012 gdk_gc_set_ts_origin( m_brushGC
,
1013 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1014 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1015 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1016 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1020 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1024 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1025 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1028 CalcBoundingBox( x
, y
);
1029 CalcBoundingBox( x
+ width
, y
+ height
);
1032 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1034 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1035 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1038 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1039 wxCoord x
, wxCoord y
,
1042 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1044 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1046 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1048 // scale/translate size and position
1049 int xx
= XLOG2DEV(x
);
1050 int yy
= YLOG2DEV(y
);
1052 int w
= bitmap
.GetWidth();
1053 int h
= bitmap
.GetHeight();
1055 CalcBoundingBox( x
, y
);
1056 CalcBoundingBox( x
+ w
, y
+ h
);
1058 if (!m_window
) return;
1060 int ww
= XLOG2DEVREL(w
);
1061 int hh
= YLOG2DEVREL(h
);
1063 // compare to current clipping region
1064 if (!m_currentClippingRegion
.IsNull())
1066 wxRegion
tmp( xx
,yy
,ww
,hh
);
1067 tmp
.Intersect( m_currentClippingRegion
);
1072 // scale bitmap if required
1073 wxBitmap use_bitmap
= bitmap
;
1074 if ((w
!= ww
) || (h
!= hh
))
1075 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1077 #if !GTK_CHECK_VERSION(2,2,0)
1078 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1079 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1080 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1081 // and also creates the mask as a side-effect:
1082 use_bitmap
.GetPixmap();
1085 // apply mask if any
1086 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1087 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1089 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1091 if (useMask
&& mask
)
1093 if (!m_currentClippingRegion
.IsNull())
1096 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1097 GdkGC
*gc
= gdk_gc_new( new_mask
);
1099 gdk_gc_set_foreground( gc
, &col
);
1100 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1102 gdk_gc_set_background( gc
, &col
);
1104 gdk_gc_set_foreground( gc
, &col
);
1105 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1106 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1107 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1108 gdk_gc_set_stipple( gc
, mask
);
1109 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1116 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1118 gdk_gc_set_clip_mask( m_textGC
, mask
);
1119 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1124 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1126 gdk_gc_set_clip_mask( m_penGC
, mask
);
1127 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1131 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1132 // drawing a mono-bitmap (XBitmap) we use the current text GC
1136 GdkPixmap
*bitmap2
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1137 GdkGC
*gc
= gdk_gc_new( bitmap2
);
1138 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1139 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1140 gdk_wx_draw_bitmap( bitmap2
, gc
, use_bitmap
.GetBitmap(), 0, 0, 0, 0, -1, -1 );
1142 gdk_draw_drawable( m_window
, m_textGC
, bitmap2
, 0, 0, xx
, yy
, -1, -1 );
1144 gdk_bitmap_unref( bitmap2
);
1147 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
1152 #if GTK_CHECK_VERSION(2,2,0)
1153 if (!gtk_check_version(2,2,0) && use_bitmap
.HasPixbuf())
1155 gdk_draw_pixbuf(m_window
, m_penGC
,
1156 use_bitmap
.GetPixbuf(),
1157 0, 0, xx
, yy
, -1, -1,
1158 GDK_RGB_DITHER_NORMAL
, xx
, yy
);
1163 gdk_draw_pixmap(m_window
, m_penGC
,
1164 use_bitmap
.GetPixmap(),
1165 0, 0, xx
, yy
, -1, -1);
1169 // remove mask again if any
1170 if (useMask
&& mask
)
1174 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1175 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1176 if (!m_currentClippingRegion
.IsNull())
1177 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1181 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1182 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1183 if (!m_currentClippingRegion
.IsNull())
1184 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1189 gdk_bitmap_unref( new_mask
);
1192 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1193 wxCoord width
, wxCoord height
,
1195 wxCoord xsrc
, wxCoord ysrc
,
1198 wxCoord xsrcMask
, wxCoord ysrcMask
)
1200 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
1202 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1204 if (!m_window
) return false;
1206 // transform the source DC coords to the device ones
1207 xsrc
= source
->XLOG2DEV(xsrc
);
1208 ysrc
= source
->YLOG2DEV(ysrc
);
1210 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1211 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1213 bool use_bitmap_method
= false;
1214 bool is_mono
= false;
1216 if (xsrcMask
== -1 && ysrcMask
== -1)
1222 if (srcDC
->m_isMemDC
)
1224 if (!memDC
->m_selected
.Ok()) return false;
1226 is_mono
= (memDC
->m_selected
.GetDepth() == 1);
1228 // we use the "XCopyArea" way to copy a memory dc into
1229 // a different window if the memory dc BOTH
1230 // a) doesn't have any mask or its mask isn't used
1234 if (useMask
&& (memDC
->m_selected
.GetMask()))
1236 // we HAVE TO use the direct way for memory dcs
1237 // that have mask since the XCopyArea doesn't know
1239 use_bitmap_method
= true;
1243 // we HAVE TO use the direct way for memory dcs
1244 // that are bitmaps because XCopyArea doesn't cope
1245 // with different bit depths
1246 use_bitmap_method
= true;
1248 else if ((xsrc
== 0) && (ysrc
== 0) &&
1249 (width
== memDC
->m_selected
.GetWidth()) &&
1250 (height
== memDC
->m_selected
.GetHeight()))
1252 // we SHOULD use the direct way if all of the bitmap
1253 // in the memory dc is copied in which case XCopyArea
1254 // wouldn't be able able to boost performace by reducing
1255 // the area to be scaled
1256 use_bitmap_method
= true;
1260 use_bitmap_method
= false;
1264 CalcBoundingBox( xdest
, ydest
);
1265 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1267 // scale/translate size and position
1268 wxCoord xx
= XLOG2DEV(xdest
);
1269 wxCoord yy
= YLOG2DEV(ydest
);
1271 wxCoord ww
= XLOG2DEVREL(width
);
1272 wxCoord hh
= YLOG2DEVREL(height
);
1274 // compare to current clipping region
1275 if (!m_currentClippingRegion
.IsNull())
1277 wxRegion
tmp( xx
,yy
,ww
,hh
);
1278 tmp
.Intersect( m_currentClippingRegion
);
1283 int old_logical_func
= m_logicalFunction
;
1284 SetLogicalFunction( logical_func
);
1286 if (use_bitmap_method
)
1288 // scale/translate bitmap size
1289 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1290 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1292 // Get clip coords for the bitmap. If we don't
1293 // use wxBitmap::Rescale(), which can clip the
1294 // bitmap, these are the same as the original
1301 // interpret userscale of src too
1303 memDC
->GetUserScale(&xsc
,&ysc
);
1304 bm_width
= (int) (bm_width
/ xsc
);
1305 bm_height
= (int) (bm_height
/ ysc
);
1307 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1308 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1310 // Scale bitmap if required
1311 wxBitmap use_bitmap
;
1312 if ((memDC
->m_selected
.GetWidth()!= bm_ww
) || ( memDC
->m_selected
.GetHeight()!= bm_hh
))
1314 // This indicates that the blitting code below will get
1315 // a clipped bitmap and therefore needs to move the origin
1317 wxRegion
tmp( xx
,yy
,ww
,hh
);
1318 tmp
.Intersect( m_currentClippingRegion
);
1319 tmp
.GetBox(cx
,cy
,cw
,ch
);
1321 // Scale and clipped bitmap
1322 use_bitmap
= memDC
->m_selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1326 // Don't scale bitmap
1327 use_bitmap
= memDC
->m_selected
;
1330 // apply mask if any
1331 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1332 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1334 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1336 if (useMask
&& mask
)
1338 if (!m_currentClippingRegion
.IsNull())
1341 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1342 GdkGC
*gc
= gdk_gc_new( new_mask
);
1344 gdk_gc_set_foreground( gc
, &col
);
1345 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1346 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1348 gdk_gc_set_background( gc
, &col
);
1350 gdk_gc_set_foreground( gc
, &col
);
1351 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1352 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1353 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1354 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1355 gdk_gc_set_stipple( gc
, mask
);
1356 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1364 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1365 gdk_gc_set_clip_origin( m_textGC
, cx
, cy
);
1369 gdk_gc_set_clip_mask( m_textGC
, mask
);
1370 gdk_gc_set_clip_origin( m_textGC
, cx
-xsrcMask
, cy
-ysrcMask
);
1377 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1378 gdk_gc_set_clip_origin( m_penGC
, cx
, cy
);
1382 gdk_gc_set_clip_mask( m_penGC
, mask
);
1383 gdk_gc_set_clip_origin( m_penGC
, cx
-xsrcMask
, cy
-ysrcMask
);
1388 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1389 // drawing a mono-bitmap (XBitmap) we use the current text GC
1394 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1395 GdkGC
*gc
= gdk_gc_new( bitmap
);
1396 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1397 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1398 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetBitmap(), 0, 0, 0, 0, -1, -1 );
1400 gdk_draw_drawable( m_window
, m_textGC
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1402 gdk_bitmap_unref( bitmap
);
1405 // was: gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
1406 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1411 // was: gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1412 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1415 // remove mask again if any
1416 if (useMask
&& mask
)
1420 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1421 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1422 if (!m_currentClippingRegion
.IsNull())
1423 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1427 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1428 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1429 if (!m_currentClippingRegion
.IsNull())
1430 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1435 gdk_bitmap_unref( new_mask
);
1437 else // use_bitmap_method
1439 if ((width
!= ww
) || (height
!= hh
))
1442 wxRegion
tmp( xx
,yy
,ww
,hh
);
1443 tmp
.Intersect( m_currentClippingRegion
);
1444 wxCoord cx
,cy
,cw
,ch
;
1445 tmp
.GetBox(cx
,cy
,cw
,ch
);
1448 wxBitmap bitmap
= memDC
->m_selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1450 // draw scaled bitmap
1451 // was: gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1452 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1456 // No scaling and not a memory dc with a mask either
1458 // copy including child window contents
1459 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1460 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1462 xsrc
, ysrc
, width
, height
);
1463 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1467 SetLogicalFunction( old_logical_func
);
1472 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1474 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1476 if (!m_window
) return;
1478 if (text
.empty()) return;
1481 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1483 wxCHECK_RET( font
, wxT("invalid font") );
1490 wxCHECK_RET( m_context
, wxT("no Pango context") );
1491 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1492 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1494 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1497 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1499 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1502 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1504 size_t datalen
= strlen((const char*)data
);
1505 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1509 PangoAttrList
*attrs
= pango_attr_list_new();
1510 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1512 a
->end_index
= datalen
;
1513 pango_attr_list_insert(attrs
, a
);
1514 pango_layout_set_attributes(m_layout
, attrs
);
1515 pango_attr_list_unref(attrs
);
1520 if (fabs(m_scaleY
- 1.0) > 0.00001)
1522 // If there is a user or actually any scale applied to
1523 // the device context, scale the font.
1525 // scale font description
1526 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1527 double size
= oldSize
;
1528 size
= size
* m_scaleY
;
1529 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1531 // actually apply scaled font
1532 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1534 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1535 if ( m_backgroundMode
== wxSOLID
)
1537 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1538 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1539 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1543 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1545 // reset unscaled size
1546 pango_font_description_set_size( m_fontdesc
, oldSize
);
1548 // actually apply unscaled font
1549 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1553 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1554 if ( m_backgroundMode
== wxSOLID
)
1556 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1557 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1558 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1561 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1566 // undo underline attributes setting:
1567 pango_layout_set_attributes(m_layout
, NULL
);
1574 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1575 wxCoord height
= font
->ascent
+ font
->descent
;
1577 if ( m_backgroundMode
== wxSOLID
)
1579 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1580 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1581 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1583 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1585 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1586 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1587 properties (see wxXt implementation) */
1588 if (m_font
.GetUnderlined())
1590 wxCoord ul_y
= y
+ font
->ascent
;
1591 if (font
->descent
> 0) ul_y
++;
1592 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1594 #endif // GTK+ 2.0/1.x
1596 width
= wxCoord(width
/ m_scaleX
);
1597 height
= wxCoord(height
/ m_scaleY
);
1598 CalcBoundingBox (x
+ width
, y
+ height
);
1599 CalcBoundingBox (x
, y
);
1603 // TODO: There is an example of rotating text with GTK2 that would probably be
1604 // a better approach here:
1605 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1607 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1609 if ( wxIsNullDouble(angle
) )
1611 DrawText(text
, x
, y
);
1615 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1617 if (!m_window
) return;
1623 // implement later without GdkFont for GTK 2.0
1624 GetTextExtent(text
, &w
, &h
, NULL
,NULL
, &m_font
);
1627 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1629 wxCHECK_RET( font
, wxT("invalid font") );
1631 // the size of the text
1632 w
= gdk_string_width( font
, text
.mbc_str() );
1633 h
= font
->ascent
+ font
->descent
;
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_window
, 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
);
1718 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1719 wxCoord
*width
, wxCoord
*height
,
1720 wxCoord
*descent
, wxCoord
*externalLeading
,
1721 wxFont
*theFont
) const
1729 if ( externalLeading
)
1730 *externalLeading
= 0;
1738 // Set new font description
1740 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1742 // Set layout's text
1744 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1745 const char *dataUTF8
= (const char *)data
;
1747 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1751 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1752 const char *dataUTF8
= (const char *)data
;
1757 // hardly ideal, but what else can we do if conversion failed?
1761 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1766 pango_layout_get_pixel_size( m_layout
, width
, &h
);
1767 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1768 int baseline
= pango_layout_iter_get_baseline(iter
);
1769 pango_layout_iter_free(iter
);
1770 *descent
= h
- PANGO_PIXELS(baseline
);
1773 *height
= (wxCoord
) h
;
1777 pango_layout_get_pixel_size( m_layout
, width
, height
);
1780 // Reset old font description
1782 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1784 wxFont fontToUse
= m_font
;
1786 fontToUse
= *theFont
;
1788 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1793 *width
= wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1795 *height
= wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1797 *descent
= wxCoord(font
->descent
/ m_scaleY
);
1801 wxCoord
wxWindowDC::GetCharWidth() const
1804 pango_layout_set_text( m_layout
, "H", 1 );
1806 pango_layout_get_pixel_size( m_layout
, &w
, NULL
);
1809 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1810 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1812 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1816 wxCoord
wxWindowDC::GetCharHeight() const
1819 pango_layout_set_text( m_layout
, "H", 1 );
1821 pango_layout_get_pixel_size( m_layout
, NULL
, &h
);
1824 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1825 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1827 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1831 void wxWindowDC::Clear()
1833 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1835 if (!m_window
) return;
1837 // VZ: the code below results in infinite recursion and crashes when
1838 // dc.Clear() is done from OnPaint() so I disable it for now.
1839 // I don't know what the correct fix is but Clear() surely should not
1840 // reenter OnPaint()!
1842 /* - we either are a memory dc or have a window as the
1843 owner. anything else shouldn't happen.
1844 - we don't use gdk_window_clear() as we don't set
1845 the window's background colour anymore. it is too
1846 much pain to keep the DC's and the window's back-
1847 ground colour in synch. */
1858 GetSize( &width
, &height
);
1859 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1864 GetSize( &width
, &height
);
1865 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1869 void wxWindowDC::SetFont( const wxFont
&font
)
1877 pango_font_description_free( m_fontdesc
);
1879 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1884 PangoContext
*oldContext
= m_context
;
1886 m_context
= m_owner
->GtkGetPangoDefaultContext();
1888 // If we switch back/forth between different contexts
1889 // we also have to create a new layout. I think so,
1890 // at least, and it doesn't hurt to do it.
1891 if (oldContext
!= m_context
)
1894 g_object_unref( G_OBJECT( m_layout
) );
1896 m_layout
= pango_layout_new( m_context
);
1900 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1905 void wxWindowDC::SetPen( const wxPen
&pen
)
1907 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1909 if (m_pen
== pen
) return;
1913 if (!m_pen
.Ok()) return;
1915 if (!m_window
) return;
1917 gint width
= m_pen
.GetWidth();
1920 // CMB: if width is non-zero scale it with the dc
1925 // X doesn't allow different width in x and y and so we take
1928 ( fabs((double) XLOG2DEVREL(width
)) +
1929 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1933 // width can't be 0 or an internal GTK error occurs inside
1934 // gdk_gc_set_dashes() below
1939 static const wxGTKDash dotted
[] = {1, 1};
1940 static const wxGTKDash short_dashed
[] = {2, 2};
1941 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1942 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1944 // We express dash pattern in pen width unit, so we are
1945 // independent of zoom factor and so on...
1947 const wxGTKDash
*req_dash
;
1949 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1950 switch (m_pen
.GetStyle())
1954 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1955 req_nb_dash
= m_pen
.GetDashCount();
1956 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1961 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1968 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1970 req_dash
= wxCoord_dashed
;
1975 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1977 req_dash
= short_dashed
;
1982 // lineStyle = GDK_LINE_DOUBLE_DASH;
1983 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1985 req_dash
= dotted_dashed
;
1990 case wxSTIPPLE_MASK_OPAQUE
:
1995 lineStyle
= GDK_LINE_SOLID
;
1996 req_dash
= (wxGTKDash
*)NULL
;
2002 if (req_dash
&& req_nb_dash
)
2004 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
2007 for (int i
= 0; i
< req_nb_dash
; i
++)
2008 real_req_dash
[i
] = req_dash
[i
] * width
;
2009 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
2010 delete[] real_req_dash
;
2014 // No Memory. We use non-scaled dash pattern...
2015 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
2019 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
2020 switch (m_pen
.GetCap())
2022 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
2023 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
2030 capStyle
= GDK_CAP_NOT_LAST
;
2034 capStyle
= GDK_CAP_ROUND
;
2040 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
2041 switch (m_pen
.GetJoin())
2043 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
2044 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
2046 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
2049 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
2051 m_pen
.GetColour().CalcPixel( m_cmap
);
2052 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
2055 void wxWindowDC::SetBrush( const wxBrush
&brush
)
2057 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2059 if (m_brush
== brush
) return;
2063 if (!m_brush
.Ok()) return;
2065 if (!m_window
) return;
2067 m_brush
.GetColour().CalcPixel( m_cmap
);
2068 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
2070 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
2072 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
2074 if (m_brush
.GetStipple()->GetPixmap())
2076 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
2077 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2081 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2082 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
2086 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2088 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2089 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2092 if (m_brush
.IsHatch())
2094 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2095 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
2096 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
2100 void wxWindowDC::SetBackground( const wxBrush
&brush
)
2102 /* CMB 21/7/98: Added SetBackground. Sets background brush
2103 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2105 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2107 if (m_backgroundBrush
== brush
) return;
2109 m_backgroundBrush
= brush
;
2111 if (!m_backgroundBrush
.Ok()) return;
2113 if (!m_window
) return;
2115 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2116 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2117 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2118 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2119 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2121 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2123 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
2125 if (m_backgroundBrush
.GetStipple()->GetPixmap())
2127 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2128 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2132 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2133 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
2137 if (m_backgroundBrush
.IsHatch())
2139 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2140 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2141 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2145 void wxWindowDC::SetLogicalFunction( int function
)
2147 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2149 if (m_logicalFunction
== function
)
2152 // VZ: shouldn't this be a CHECK?
2159 case wxXOR
: mode
= GDK_XOR
; break;
2160 case wxINVERT
: mode
= GDK_INVERT
; break;
2161 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2162 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2163 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2164 case wxSET
: mode
= GDK_SET
; break;
2165 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2166 case wxAND
: mode
= GDK_AND
; break;
2167 case wxOR
: mode
= GDK_OR
; break;
2168 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2169 case wxNAND
: mode
= GDK_NAND
; break;
2170 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2171 case wxCOPY
: mode
= GDK_COPY
; break;
2172 case wxNO_OP
: mode
= GDK_NOOP
; break;
2173 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2175 // unsupported by GTK
2176 case wxNOR
: mode
= GDK_COPY
; break;
2178 wxFAIL_MSG( wxT("unsupported logical function") );
2182 m_logicalFunction
= function
;
2184 gdk_gc_set_function( m_penGC
, mode
);
2185 gdk_gc_set_function( m_brushGC
, mode
);
2187 // to stay compatible with wxMSW, we don't apply ROPs to the text
2188 // operations (i.e. DrawText/DrawRotatedText).
2189 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2190 gdk_gc_set_function( m_textGC
, mode
);
2193 void wxWindowDC::SetTextForeground( const wxColour
&col
)
2195 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2197 // don't set m_textForegroundColour to an invalid colour as we'd crash
2198 // later then (we use m_textForegroundColour.GetColor() without checking
2200 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2203 m_textForegroundColour
= col
;
2207 m_textForegroundColour
.CalcPixel( m_cmap
);
2208 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2212 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2214 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2217 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2220 m_textBackgroundColour
= col
;
2224 m_textBackgroundColour
.CalcPixel( m_cmap
);
2225 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2229 void wxWindowDC::SetBackgroundMode( int mode
)
2231 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2233 m_backgroundMode
= mode
;
2235 if (!m_window
) return;
2237 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2238 // transparent/solid background mode
2240 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2242 gdk_gc_set_fill( m_brushGC
,
2243 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2247 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2249 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
2252 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2254 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2256 if (!m_window
) return;
2259 rect
.x
= XLOG2DEV(x
);
2260 rect
.y
= YLOG2DEV(y
);
2261 rect
.width
= XLOG2DEVREL(width
);
2262 rect
.height
= YLOG2DEVREL(height
);
2264 if (!m_currentClippingRegion
.IsNull())
2265 m_currentClippingRegion
.Intersect( rect
);
2267 m_currentClippingRegion
.Union( rect
);
2269 #if USE_PAINT_REGION
2270 if (!m_paintClippingRegion
.IsNull())
2271 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2274 wxCoord xx
, yy
, ww
, hh
;
2275 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2276 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2278 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2279 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2280 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2281 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2284 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2286 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2290 DestroyClippingRegion();
2294 if (!m_window
) return;
2296 if (!m_currentClippingRegion
.IsNull())
2297 m_currentClippingRegion
.Intersect( region
);
2299 m_currentClippingRegion
.Union( region
);
2301 #if USE_PAINT_REGION
2302 if (!m_paintClippingRegion
.IsNull())
2303 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2306 wxCoord xx
, yy
, ww
, hh
;
2307 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2308 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2310 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2311 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2312 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2313 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2316 void wxWindowDC::DestroyClippingRegion()
2318 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2320 wxDC::DestroyClippingRegion();
2322 m_currentClippingRegion
.Clear();
2324 #if USE_PAINT_REGION
2325 if (!m_paintClippingRegion
.IsEmpty())
2326 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2329 if (!m_window
) return;
2331 if (m_currentClippingRegion
.IsEmpty())
2333 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2334 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2335 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2336 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2340 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2341 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2342 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2343 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2347 void wxWindowDC::Destroy()
2349 if (m_penGC
) wxFreePoolGC( m_penGC
);
2350 m_penGC
= (GdkGC
*) NULL
;
2351 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2352 m_brushGC
= (GdkGC
*) NULL
;
2353 if (m_textGC
) wxFreePoolGC( m_textGC
);
2354 m_textGC
= (GdkGC
*) NULL
;
2355 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2356 m_bgGC
= (GdkGC
*) NULL
;
2359 void wxWindowDC::ComputeScaleAndOrigin()
2361 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2363 wxDC::ComputeScaleAndOrigin();
2365 // if scale has changed call SetPen to recalulate the line width
2366 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.Ok() )
2368 // this is a bit artificial, but we need to force wxDC to think the pen
2376 // Resolution in pixels per logical inch
2377 wxSize
wxWindowDC::GetPPI() const
2379 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2382 int wxWindowDC::GetDepth() const
2385 return gdk_drawable_get_depth(m_window
);
2387 wxFAIL_MSG(wxT("not implemented"));
2394 //-----------------------------------------------------------------------------
2396 //-----------------------------------------------------------------------------
2398 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2400 // Limit the paint region to the window size. Sometimes
2401 // the paint region is too big, and this risks X11 errors
2402 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2404 wxRect originalRect
= region
.GetBox();
2405 wxRect
rect(originalRect
);
2406 if (rect
.width
+ rect
.x
> sz
.x
)
2407 rect
.width
= sz
.x
- rect
.x
;
2408 if (rect
.height
+ rect
.y
> sz
.y
)
2409 rect
.height
= sz
.y
- rect
.y
;
2410 if (rect
!= originalRect
)
2412 region
= wxRegion(rect
);
2413 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2414 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2415 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2419 wxPaintDC::wxPaintDC( wxWindow
*win
)
2422 #if USE_PAINT_REGION
2423 if (!win
->m_clipPaintRegion
)
2426 wxSize sz
= win
->GetSize();
2427 m_paintClippingRegion
= win
->GetUpdateRegion();
2428 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2430 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2433 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2434 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2436 if (sz
.x
<= 0 || sz
.y
<= 0)
2439 gdk_gc_set_clip_region( m_penGC
, region
);
2440 gdk_gc_set_clip_region( m_brushGC
, region
);
2441 gdk_gc_set_clip_region( m_textGC
, region
);
2442 gdk_gc_set_clip_region( m_bgGC
, region
);
2444 #endif // USE_PAINT_REGION
2447 //-----------------------------------------------------------------------------
2449 //-----------------------------------------------------------------------------
2451 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2453 wxClientDC::wxClientDC( wxWindow
*win
)
2456 wxCHECK_RET( win
, _T("NULL window in wxClientDC::wxClientDC") );
2458 #ifdef __WXUNIVERSAL__
2459 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2460 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2461 wxSize size
= win
->GetClientSize();
2462 SetClippingRegion(wxPoint(0, 0), size
);
2463 #endif // __WXUNIVERSAL__
2466 void wxClientDC::DoGetSize(int *width
, int *height
) const
2468 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2470 m_owner
->GetClientSize( width
, height
);
2473 // ----------------------------------------------------------------------------
2475 // ----------------------------------------------------------------------------
2477 class wxDCModule
: public wxModule
2484 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2487 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2489 bool wxDCModule::OnInit()
2495 void wxDCModule::OnExit()