1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/dcclient.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling, Chris Breeze
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
13 #define XCopyPlane XCOPYPLANE
18 #include "wx/math.h" // for floating-point functions
20 #include "wx/module.h"
23 #include "wx/fontutil.h"
25 #include "wx/gtk1/win_gtk.h"
26 #include "wx/gtk1/dcclient.h"
27 #include "wx/gtk1/dcmemory.h"
31 #include <gdk/gdkprivate.h>
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #define USE_PAINT_REGION 1
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
52 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
53 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
56 static GdkPixmap
*hatches
[num_hatches
];
57 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
59 extern GtkWidget
*wxGetRootWindow();
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 const double RAD2DEG
= 180.0 / M_PI
;
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
72 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
74 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
76 //-----------------------------------------------------------------------------
77 // temporary implementation of the missing GDK function
78 //-----------------------------------------------------------------------------
80 #include "gdk/gdkprivate.h"
82 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
92 wxCHECK_RET( drawable
, wxT("NULL drawable in gdk_wx_draw_bitmap") );
93 wxCHECK_RET( src
, wxT("NULL src in gdk_wx_draw_bitmap") );
94 wxCHECK_RET( gc
, wxT("NULL gc in gdk_wx_draw_bitmap") );
96 GdkWindowPrivate
*drawable_private
;
97 GdkWindowPrivate
*src_private
;
98 GdkGCPrivate
*gc_private
;
100 drawable_private
= (GdkWindowPrivate
*) drawable
;
101 src_private
= (GdkWindowPrivate
*) src
;
102 if (drawable_private
->destroyed
|| src_private
->destroyed
)
105 gint src_width
= src_private
->width
;
106 gint src_height
= src_private
->height
;
108 gc_private
= (GdkGCPrivate
*) gc
;
110 if (width
== -1) width
= src_width
;
111 if (height
== -1) height
= src_height
;
113 XCopyPlane( drawable_private
->xdisplay
,
114 src_private
->xwindow
,
115 drawable_private
->xwindow
,
123 //-----------------------------------------------------------------------------
124 // Implement Pool of Graphic contexts. Creating them takes too much time.
125 //-----------------------------------------------------------------------------
151 #define GC_POOL_ALLOC_SIZE 100
153 static int wxGCPoolSize
= 0;
155 static wxGC
*wxGCPool
= NULL
;
157 static void wxInitGCPool()
159 // This really could wait until the first call to
160 // wxGetPoolGC, but we will make the first allocation
161 // now when other initialization is being performed.
163 // Set initial pool size.
164 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
166 // Allocate initial pool.
167 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
168 if (wxGCPool
== NULL
)
170 // If we cannot malloc, then fail with error
171 // when debug is enabled. If debug is not enabled,
172 // the problem will eventually get caught
174 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
178 // Zero initial pool.
179 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
182 static void wxCleanUpGCPool()
184 for (int i
= 0; i
< wxGCPoolSize
; i
++)
186 if (wxGCPool
[i
].m_gc
)
187 gdk_gc_unref( wxGCPool
[i
].m_gc
);
195 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
199 // Look for an available GC.
200 for (int i
= 0; i
< wxGCPoolSize
; i
++)
202 if (!wxGCPool
[i
].m_gc
)
204 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
205 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
206 wxGCPool
[i
].m_type
= type
;
207 wxGCPool
[i
].m_used
= false;
209 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
211 wxGCPool
[i
].m_used
= true;
212 return wxGCPool
[i
].m_gc
;
216 // We did not find an available GC.
217 // We need to grow the GC pool.
218 pptr
= (wxGC
*)realloc(wxGCPool
,
219 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
222 // Initialize newly allocated pool.
224 memset(&wxGCPool
[wxGCPoolSize
], 0,
225 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
227 // Initialize entry we will return.
228 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
229 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
230 wxGCPool
[wxGCPoolSize
].m_type
= type
;
231 wxGCPool
[wxGCPoolSize
].m_used
= true;
233 // Set new value of pool size.
234 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
236 // Return newly allocated entry.
237 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
240 // The realloc failed. Fall through to error.
241 wxFAIL_MSG( wxT("No GC available") );
246 static void wxFreePoolGC( GdkGC
*gc
)
248 for (int i
= 0; i
< wxGCPoolSize
; i
++)
250 if (wxGCPool
[i
].m_gc
== gc
)
252 wxGCPool
[i
].m_used
= false;
257 wxFAIL_MSG( wxT("Wrong GC") );
260 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
264 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxDC
)
266 wxWindowDCImpl::wxWindowDCImpl(wxDC
*owner
)
275 m_isScreenDC
= false;
279 wxWindowDCImpl::wxWindowDCImpl(wxDC
*owner
, wxWindow
*window
)
282 wxASSERT_MSG( window
, wxT("DC needs a window") );
291 m_isScreenDC
= false;
292 m_font
= window
->GetFont();
294 GtkWidget
*widget
= window
->m_wxwindow
;
296 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
297 // code should still be able to create wxClientDCs for them, so we will
298 // use the parent window here then.
301 window
= window
->GetParent();
302 widget
= window
->m_wxwindow
;
305 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
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) */
333 wxWindowDCImpl::~wxWindowDCImpl()
338 void wxWindowDCImpl::SetUpDC()
342 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
346 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
347 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
348 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
349 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
351 else if (m_isMemDC
&& (((wxMemoryDCImpl
*)this)->m_selected
.GetDepth() == 1))
353 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
354 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
355 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
356 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
360 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
361 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
362 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
363 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
366 /* background colour */
367 m_backgroundBrush
= *wxWHITE_BRUSH
;
368 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
369 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
372 m_textForegroundColour
.CalcPixel( m_cmap
);
373 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
375 m_textBackgroundColour
.CalcPixel( m_cmap
);
376 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
378 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
381 m_pen
.GetColour().CalcPixel( m_cmap
);
382 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
383 gdk_gc_set_background( m_penGC
, bg_col
);
385 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
388 m_brush
.GetColour().CalcPixel( m_cmap
);
389 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
390 gdk_gc_set_background( m_brushGC
, bg_col
);
392 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
395 gdk_gc_set_background( m_bgGC
, bg_col
);
396 gdk_gc_set_foreground( m_bgGC
, bg_col
);
398 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
401 gdk_gc_set_function( m_textGC
, GDK_COPY
);
402 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
403 gdk_gc_set_function( m_penGC
, GDK_COPY
);
406 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
407 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
408 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
409 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
413 hatch_bitmap
= hatches
;
414 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
415 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
416 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
417 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
418 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
419 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
423 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
425 wxCHECK_RET( m_owner
, wxT("GetSize() doesn't work without window") );
427 m_owner
->GetSize(width
, height
);
430 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
431 const wxColour
& col
, wxFloodFillStyle style
);
433 bool wxWindowDCImpl::DoFloodFill(wxCoord x
, wxCoord y
,
434 const wxColour
& col
, wxFloodFillStyle style
)
436 return wxDoFloodFill(GetOwner(), x
, y
, col
, style
);
439 bool wxWindowDCImpl::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
441 // Generic (and therefore rather inefficient) method.
442 // Could be improved.
444 wxBitmap
bitmap(1, 1);
445 memdc
.SelectObject(bitmap
);
446 memdc
.Blit(0, 0, 1, 1, GetOwner(), x1
, y1
);
447 memdc
.SelectObject(wxNullBitmap
);
449 wxImage image
= bitmap
.ConvertToImage();
450 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
454 void wxWindowDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
456 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
458 if (m_pen
.GetStyle() != wxTRANSPARENT
)
461 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
463 CalcBoundingBox(x1
, y1
);
464 CalcBoundingBox(x2
, y2
);
468 void wxWindowDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
470 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
472 if (m_pen
.GetStyle() != wxTRANSPARENT
)
477 wxCoord xx
= XLOG2DEV(x
);
478 wxCoord yy
= YLOG2DEV(y
);
481 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
482 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
487 void wxWindowDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
488 wxCoord xc
, wxCoord yc
)
490 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
492 wxCoord xx1
= XLOG2DEV(x1
);
493 wxCoord yy1
= YLOG2DEV(y1
);
494 wxCoord xx2
= XLOG2DEV(x2
);
495 wxCoord yy2
= YLOG2DEV(y2
);
496 wxCoord xxc
= XLOG2DEV(xc
);
497 wxCoord yyc
= YLOG2DEV(yc
);
498 double dx
= xx1
- xxc
;
499 double dy
= yy1
- yyc
;
500 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
501 wxCoord r
= (wxCoord
)radius
;
502 double radius1
, radius2
;
504 if (xx1
== xx2
&& yy1
== yy2
)
509 else if ( wxIsNullDouble(radius
) )
516 radius1
= (xx1
- xxc
== 0) ?
517 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
518 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
519 radius2
= (xx2
- xxc
== 0) ?
520 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
521 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
523 wxCoord alpha1
= wxCoord(radius1
* 64.0);
524 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
525 while (alpha2
<= 0) alpha2
+= 360*64;
526 while (alpha1
> 360*64) alpha1
-= 360*64;
530 if (m_brush
.GetStyle() != wxTRANSPARENT
)
532 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
534 gdk_gc_set_ts_origin( m_textGC
,
535 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
536 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
537 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
538 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
540 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
542 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
543 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
544 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
546 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
548 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
549 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
550 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
552 if (m_brush
.GetStyle() == wxSTIPPLE
)
554 gdk_gc_set_ts_origin( m_brushGC
,
555 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
556 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
557 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
558 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
562 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
566 if (m_pen
.GetStyle() != wxTRANSPARENT
)
568 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
570 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
571 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
575 CalcBoundingBox (x1
, y1
);
576 CalcBoundingBox (x2
, y2
);
579 void wxWindowDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
581 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
583 wxCoord xx
= XLOG2DEV(x
);
584 wxCoord yy
= YLOG2DEV(y
);
585 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
586 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
588 // CMB: handle -ve width and/or height
589 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
590 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
594 wxCoord start
= wxCoord(sa
* 64.0);
595 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
597 if (m_brush
.GetStyle() != wxTRANSPARENT
)
599 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
601 gdk_gc_set_ts_origin( m_textGC
,
602 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
603 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
604 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
605 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
607 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
609 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
610 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
611 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
613 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
615 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
616 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
617 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
619 if (m_brush
.GetStyle() == wxSTIPPLE
)
621 gdk_gc_set_ts_origin( m_brushGC
,
622 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
623 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
624 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
625 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
629 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
633 if (m_pen
.GetStyle() != wxTRANSPARENT
)
634 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
637 CalcBoundingBox (x
, y
);
638 CalcBoundingBox (x
+ width
, y
+ height
);
641 void wxWindowDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
643 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
645 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
646 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
648 CalcBoundingBox (x
, y
);
651 void wxWindowDCImpl::DoDrawLines( int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
653 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
655 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
659 GdkPoint
* const gpts
= new GdkPoint
[n
];
662 wxFAIL_MSG( wxT("Cannot allocate PolyLine") );
666 for (int i
= 0; i
< n
; i
++)
668 wxCoord x
= points
[i
].x
+ xoffset
,
669 y
= points
[i
].y
+ yoffset
;
671 CalcBoundingBox(x
+ xoffset
, y
+ yoffset
);
673 gpts
[i
].x
= XLOG2DEV(x
);
674 gpts
[i
].y
= YLOG2DEV(y
);
677 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
682 void wxWindowDCImpl::DoDrawPolygon( int n
, const wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, wxPolygonFillMode
WXUNUSED(fillStyle
) )
684 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
688 GdkPoint
* const gpts
= new GdkPoint
[n
];
690 for (int i
= 0 ; i
< n
; i
++)
692 wxCoord x
= points
[i
].x
+ xoffset
,
693 y
= points
[i
].y
+ yoffset
;
695 CalcBoundingBox(x
+ xoffset
, y
+ yoffset
);
697 gpts
[i
].x
= XLOG2DEV(x
);
698 gpts
[i
].y
= YLOG2DEV(y
);
701 if (m_brush
.GetStyle() == wxSOLID
)
703 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gpts
, n
);
705 else if (m_brush
.GetStyle() != wxTRANSPARENT
)
707 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
709 gdk_gc_set_ts_origin( m_textGC
,
710 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
711 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
712 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gpts
, n
);
713 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
715 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
717 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
718 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gpts
, n
);
719 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
721 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
723 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
724 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gpts
, n
);
725 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
727 if (m_brush
.GetStyle() == wxSTIPPLE
)
729 gdk_gc_set_ts_origin( m_brushGC
,
730 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
731 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
732 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gpts
, n
);
733 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
737 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gpts
, n
);
741 if (m_pen
.GetStyle() != wxTRANSPARENT
)
743 gdk_draw_polygon( m_window
, m_penGC
, FALSE
, gpts
, n
);
750 void wxWindowDCImpl::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
752 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
754 wxCoord xx
= XLOG2DEV(x
);
755 wxCoord yy
= YLOG2DEV(y
);
756 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
757 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
759 // CMB: draw nothing if transformed w or h is 0
760 if (ww
== 0 || hh
== 0) return;
762 // CMB: handle -ve width and/or height
763 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
764 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
768 if (m_brush
.GetStyle() != wxTRANSPARENT
)
770 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
772 gdk_gc_set_ts_origin( m_textGC
,
773 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
774 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
775 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
776 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
778 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
780 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
781 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
782 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
784 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
786 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
787 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
788 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
790 if (m_brush
.GetStyle() == wxSTIPPLE
)
792 gdk_gc_set_ts_origin( m_brushGC
,
793 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
794 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
795 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
796 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
800 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
804 if (m_pen
.GetStyle() != wxTRANSPARENT
)
805 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
808 CalcBoundingBox( x
, y
);
809 CalcBoundingBox( x
+ width
, y
+ height
);
812 void wxWindowDCImpl::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
814 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
816 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
818 wxCoord xx
= XLOG2DEV(x
);
819 wxCoord yy
= YLOG2DEV(y
);
820 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
821 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
822 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
824 // CMB: handle -ve width and/or height
825 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
826 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
828 // CMB: if radius is zero use DrawRectangle() instead to avoid
829 // X drawing errors with small radii
832 DoDrawRectangle( x
, y
, width
, height
);
836 // CMB: draw nothing if transformed w or h is 0
837 if (ww
== 0 || hh
== 0) return;
839 // CMB: adjust size if outline is drawn otherwise the result is
840 // 1 pixel too wide and high
841 if (m_pen
.GetStyle() != wxTRANSPARENT
)
849 // CMB: ensure dd is not larger than rectangle otherwise we
850 // get an hour glass shape
852 if (dd
> ww
) dd
= ww
;
853 if (dd
> hh
) dd
= hh
;
856 if (m_brush
.GetStyle() != wxTRANSPARENT
)
858 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
860 gdk_gc_set_ts_origin( m_textGC
,
861 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
862 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
863 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
864 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
865 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
866 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
867 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
868 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
869 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
871 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
873 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
874 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
875 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
876 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
877 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
878 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
879 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
880 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
882 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
884 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
885 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
886 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
887 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
888 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
889 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
890 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
891 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
893 if (m_brush
.GetStyle() == wxSTIPPLE
)
895 gdk_gc_set_ts_origin( m_brushGC
,
896 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
897 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
898 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
899 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
900 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
901 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
902 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
903 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
904 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
908 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
909 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
910 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
911 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
912 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
913 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
917 if (m_pen
.GetStyle() != wxTRANSPARENT
)
919 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
920 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
921 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
922 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
923 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
924 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
925 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
926 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
930 // this ignores the radius
931 CalcBoundingBox( x
, y
);
932 CalcBoundingBox( x
+ width
, y
+ height
);
935 void wxWindowDCImpl::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
937 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
939 wxCoord xx
= XLOG2DEV(x
);
940 wxCoord yy
= YLOG2DEV(y
);
941 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
942 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
944 // CMB: handle -ve width and/or height
945 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
946 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
950 if (m_brush
.GetStyle() != wxTRANSPARENT
)
952 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
954 gdk_gc_set_ts_origin( m_textGC
,
955 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
956 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
957 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
958 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
960 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
962 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
963 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
964 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
966 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
968 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
969 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
970 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
972 if (m_brush
.GetStyle() == wxSTIPPLE
)
974 gdk_gc_set_ts_origin( m_brushGC
,
975 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
976 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
977 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
978 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
982 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
986 if (m_pen
.GetStyle() != wxTRANSPARENT
)
987 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
990 CalcBoundingBox( x
, y
);
991 CalcBoundingBox( x
+ width
, y
+ height
);
994 void wxWindowDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
996 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
997 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, true );
1000 void wxWindowDCImpl::DoDrawBitmap( const wxBitmap
&bitmap
,
1001 wxCoord x
, wxCoord y
,
1004 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1006 wxCHECK_RET( bitmap
.IsOk(), wxT("invalid bitmap") );
1008 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1010 // scale/translate size and position
1011 int xx
= XLOG2DEV(x
);
1012 int yy
= YLOG2DEV(y
);
1014 int w
= bitmap
.GetWidth();
1015 int h
= bitmap
.GetHeight();
1017 CalcBoundingBox( x
, y
);
1018 CalcBoundingBox( x
+ w
, y
+ h
);
1020 if (!m_window
) return;
1022 int ww
= XLOG2DEVREL(w
);
1023 int hh
= YLOG2DEVREL(h
);
1025 // compare to current clipping region
1026 if (!m_currentClippingRegion
.IsNull())
1028 wxRegion
tmp( xx
,yy
,ww
,hh
);
1029 tmp
.Intersect( m_currentClippingRegion
);
1034 // scale bitmap if required
1035 wxBitmap use_bitmap
= bitmap
;
1036 if ((w
!= ww
) || (h
!= hh
))
1037 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1039 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1040 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1041 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1042 // and also creates the mask as a side-effect:
1043 use_bitmap
.GetPixmap();
1045 // apply mask if any
1046 GdkBitmap
*mask
= NULL
;
1047 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1049 GdkBitmap
*new_mask
= NULL
;
1051 if (useMask
&& mask
)
1053 if (!m_currentClippingRegion
.IsNull())
1056 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1057 GdkGC
*gc
= gdk_gc_new( new_mask
);
1059 gdk_gc_set_foreground( gc
, &col
);
1060 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1062 gdk_gc_set_background( gc
, &col
);
1064 gdk_gc_set_foreground( gc
, &col
);
1065 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1066 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1067 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1068 gdk_gc_set_stipple( gc
, mask
);
1069 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1076 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1078 gdk_gc_set_clip_mask( m_textGC
, mask
);
1079 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1084 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1086 gdk_gc_set_clip_mask( m_penGC
, mask
);
1087 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1091 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1092 // drawing a mono-bitmap (XBitmap) we use the current text GC
1095 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
1099 gdk_draw_pixmap(m_window
, m_penGC
,
1100 use_bitmap
.GetPixmap(),
1101 0, 0, xx
, yy
, -1, -1);
1104 // remove mask again if any
1105 if (useMask
&& mask
)
1109 gdk_gc_set_clip_mask( m_textGC
, NULL
);
1110 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1111 if (!m_currentClippingRegion
.IsNull())
1112 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1116 gdk_gc_set_clip_mask( m_penGC
, NULL
);
1117 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1118 if (!m_currentClippingRegion
.IsNull())
1119 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1124 gdk_bitmap_unref( new_mask
);
1127 bool wxWindowDCImpl::DoBlit( wxCoord xdest
, wxCoord ydest
,
1128 wxCoord width
, wxCoord height
,
1130 wxCoord xsrc
, wxCoord ysrc
,
1131 wxRasterOperationMode logical_func
,
1133 wxCoord xsrcMask
, wxCoord ysrcMask
)
1135 wxCHECK_MSG( IsOk(), false, wxT("invalid window dc") );
1137 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1139 if (!m_window
) return false;
1141 // transform the source DC coords to the device ones
1142 xsrc
= source
->LogicalToDeviceX(xsrc
);
1143 ysrc
= source
->LogicalToDeviceY(ysrc
);
1145 wxWindowDCImpl
*srcDC
= wxDynamicCast(source
->GetImpl(), wxWindowDCImpl
);
1146 wxCHECK_MSG( srcDC
, false, "source must be a window DC" );
1148 // FIXME: this cast is not always valid, see the code using m_isMemDC
1149 wxMemoryDCImpl
*memDC
= static_cast<wxMemoryDCImpl
*>(srcDC
);
1151 bool use_bitmap_method
= false;
1152 bool is_mono
= false;
1154 if (xsrcMask
== -1 && ysrcMask
== -1)
1160 if (srcDC
->m_isMemDC
)
1162 if (!memDC
->m_selected
.IsOk()) return false;
1164 is_mono
= (memDC
->m_selected
.GetDepth() == 1);
1166 // we use the "XCopyArea" way to copy a memory dc into
1167 // a different window if the memory dc BOTH
1168 // a) doesn't have any mask or its mask isn't used
1172 if (useMask
&& (memDC
->m_selected
.GetMask()))
1174 // we HAVE TO use the direct way for memory dcs
1175 // that have mask since the XCopyArea doesn't know
1177 use_bitmap_method
= true;
1181 // we HAVE TO use the direct way for memory dcs
1182 // that are bitmaps because XCopyArea doesn't cope
1183 // with different bit depths
1184 use_bitmap_method
= true;
1186 else if ((xsrc
== 0) && (ysrc
== 0) &&
1187 (width
== memDC
->m_selected
.GetWidth()) &&
1188 (height
== memDC
->m_selected
.GetHeight()))
1190 // we SHOULD use the direct way if all of the bitmap
1191 // in the memory dc is copied in which case XCopyArea
1192 // wouldn't be able able to boost performace by reducing
1193 // the area to be scaled
1194 use_bitmap_method
= true;
1198 use_bitmap_method
= false;
1202 CalcBoundingBox( xdest
, ydest
);
1203 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1205 // scale/translate size and position
1206 wxCoord xx
= XLOG2DEV(xdest
);
1207 wxCoord yy
= YLOG2DEV(ydest
);
1209 wxCoord ww
= XLOG2DEVREL(width
);
1210 wxCoord hh
= YLOG2DEVREL(height
);
1212 // compare to current clipping region
1213 if (!m_currentClippingRegion
.IsNull())
1215 wxRegion
tmp( xx
,yy
,ww
,hh
);
1216 tmp
.Intersect( m_currentClippingRegion
);
1221 wxRasterOperationMode old_logical_func
= m_logicalFunction
;
1222 SetLogicalFunction( logical_func
);
1224 if (use_bitmap_method
)
1226 // scale/translate bitmap size
1227 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1228 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1230 // Get clip coords for the bitmap. If we don't
1231 // use wxBitmap::Rescale(), which can clip the
1232 // bitmap, these are the same as the original
1239 // interpret userscale of src too
1241 memDC
->GetUserScale(&xsc
,&ysc
);
1242 bm_width
= (int) (bm_width
/ xsc
);
1243 bm_height
= (int) (bm_height
/ ysc
);
1245 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1246 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1248 // Scale bitmap if required
1249 wxBitmap use_bitmap
;
1250 if ((memDC
->m_selected
.GetWidth()!= bm_ww
) || ( memDC
->m_selected
.GetHeight()!= bm_hh
))
1252 // This indicates that the blitting code below will get
1253 // a clipped bitmap and therefore needs to move the origin
1255 wxRegion
tmp( xx
,yy
,ww
,hh
);
1256 tmp
.Intersect( m_currentClippingRegion
);
1257 tmp
.GetBox(cx
,cy
,cw
,ch
);
1259 // Scale and clipped bitmap
1260 use_bitmap
= memDC
->m_selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1264 // Don't scale bitmap
1265 use_bitmap
= memDC
->m_selected
;
1268 // apply mask if any
1269 GdkBitmap
*mask
= NULL
;
1270 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1272 GdkBitmap
*new_mask
= NULL
;
1274 if (useMask
&& mask
)
1276 if (!m_currentClippingRegion
.IsNull())
1279 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1280 GdkGC
*gc
= gdk_gc_new( new_mask
);
1282 gdk_gc_set_foreground( gc
, &col
);
1283 gdk_gc_set_ts_origin( gc
, -xsrcMask
, -ysrcMask
);
1284 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1286 gdk_gc_set_background( gc
, &col
);
1288 gdk_gc_set_foreground( gc
, &col
);
1289 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1290 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1291 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1292 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1293 gdk_gc_set_stipple( gc
, mask
);
1294 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1302 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1303 gdk_gc_set_clip_origin( m_textGC
, cx
, cy
);
1307 gdk_gc_set_clip_mask( m_textGC
, mask
);
1308 gdk_gc_set_clip_origin( m_textGC
, cx
-xsrcMask
, cy
-ysrcMask
);
1315 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1316 gdk_gc_set_clip_origin( m_penGC
, cx
, cy
);
1320 gdk_gc_set_clip_mask( m_penGC
, mask
);
1321 gdk_gc_set_clip_origin( m_penGC
, cx
-xsrcMask
, cy
-ysrcMask
);
1326 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1327 // drawing a mono-bitmap (XBitmap) we use the current text GC
1331 // was: gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
1332 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1336 // was: gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1337 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1340 // remove mask again if any
1341 if (useMask
&& mask
)
1345 gdk_gc_set_clip_mask( m_textGC
, NULL
);
1346 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1347 if (!m_currentClippingRegion
.IsNull())
1348 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1352 gdk_gc_set_clip_mask( m_penGC
, NULL
);
1353 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1354 if (!m_currentClippingRegion
.IsNull())
1355 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1360 gdk_bitmap_unref( new_mask
);
1362 else // use_bitmap_method
1364 if ((width
!= ww
) || (height
!= hh
))
1367 wxRegion
tmp( xx
,yy
,ww
,hh
);
1368 tmp
.Intersect( m_currentClippingRegion
);
1369 wxCoord cx
,cy
,cw
,ch
;
1370 tmp
.GetBox(cx
,cy
,cw
,ch
);
1373 wxBitmap bitmap
= memDC
->m_selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1375 // draw scaled bitmap
1376 // was: gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1377 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1381 // No scaling and not a memory dc with a mask either
1383 // copy including child window contents
1384 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1385 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1387 xsrc
, ysrc
, width
, height
);
1388 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1392 SetLogicalFunction( old_logical_func
);
1397 void wxWindowDCImpl::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1399 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1401 if (!m_window
) return;
1403 if (text
.empty()) return;
1405 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1407 wxCHECK_RET( font
, wxT("invalid font") );
1412 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1413 wxCoord height
= font
->ascent
+ font
->descent
;
1415 if ( m_backgroundMode
== wxSOLID
)
1417 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1418 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1419 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1421 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1423 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1424 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1425 properties (see wxXt implementation) */
1426 if (m_font
.GetUnderlined())
1428 wxCoord ul_y
= y
+ font
->ascent
;
1429 if (font
->descent
> 0) ul_y
++;
1430 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1433 width
= wxCoord(width
/ m_scaleX
);
1434 height
= wxCoord(height
/ m_scaleY
);
1435 CalcBoundingBox (x
+ width
, y
+ height
);
1436 CalcBoundingBox (x
, y
);
1440 // TODO: There is an example of rotating text with GTK2 that would probably be
1441 // a better approach here:
1442 // http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1444 void wxWindowDCImpl::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1446 if ( wxIsNullDouble(angle
) )
1448 DoDrawText(text
, x
, y
);
1452 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1454 if (!m_window
) return;
1459 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1461 wxCHECK_RET( font
, wxT("invalid font") );
1463 // the size of the text
1464 w
= gdk_string_width( font
, text
.mbc_str() );
1465 h
= font
->ascent
+ font
->descent
;
1467 // draw the string normally
1470 dc
.SelectObject(src
);
1471 dc
.SetFont(GetFont());
1472 dc
.SetBackground(*wxBLACK_BRUSH
);
1473 dc
.SetBrush(*wxBLACK_BRUSH
);
1475 dc
.SetTextForeground( *wxWHITE
);
1476 dc
.DrawText(text
, 0, 0);
1477 dc
.SelectObject(wxNullBitmap
);
1479 // Calculate the size of the rotated bounding box.
1480 double rad
= DegToRad(angle
);
1481 double dx
= cos(rad
),
1484 // the rectngle vertices are counted clockwise with the first one being at
1485 // (0, 0) (or, rather, at (x, y))
1487 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1490 double x3
= x4
+ x2
,
1494 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1495 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1496 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1497 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1500 wxImage image
= src
.ConvertToImage();
1502 image
.ConvertColourToAlpha( m_textForegroundColour
.Red(),
1503 m_textForegroundColour
.Green(),
1504 m_textForegroundColour
.Blue() );
1505 image
= image
.Rotate( rad
, wxPoint(0,0) );
1507 int i_angle
= (int) angle
;
1508 i_angle
= i_angle
% 360;
1512 if ((i_angle
>= 90.0) && (i_angle
< 270.0))
1513 xoffset
= image
.GetWidth();
1515 if ((i_angle
>= 0.0) && (i_angle
< 180.0))
1516 yoffset
= image
.GetHeight();
1518 if ((i_angle
>= 0) && (i_angle
< 90))
1519 yoffset
-= (int)( cos(rad
)*h
);
1520 if ((i_angle
>= 90) && (i_angle
< 180))
1521 xoffset
-= (int)( sin(rad
)*h
);
1522 if ((i_angle
>= 180) && (i_angle
< 270))
1523 yoffset
-= (int)( cos(rad
)*h
);
1524 if ((i_angle
>= 270) && (i_angle
< 360))
1525 xoffset
-= (int)( sin(rad
)*h
);
1527 int i_x
= x
- xoffset
;
1528 int i_y
= y
- yoffset
;
1531 DoDrawBitmap( src
, i_x
, i_y
, true );
1534 // it would be better to draw with non underlined font and draw the line
1535 // manually here (it would be more straight...)
1537 if ( m_font
.GetUnderlined() )
1539 gdk_draw_line( m_window
, m_textGC
,
1540 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1541 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1545 // update the bounding box
1546 CalcBoundingBox(x
+ minX
, y
+ minY
);
1547 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1550 void wxWindowDCImpl::DoGetTextExtent(const wxString
&string
,
1551 wxCoord
*width
, wxCoord
*height
,
1552 wxCoord
*descent
, wxCoord
*externalLeading
,
1553 const wxFont
*theFont
) const
1561 if ( externalLeading
)
1562 *externalLeading
= 0;
1569 wxFont fontToUse
= m_font
;
1571 fontToUse
= *theFont
;
1573 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1578 *width
= wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1580 *height
= wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1582 *descent
= wxCoord(font
->descent
/ m_scaleY
);
1585 wxCoord
wxWindowDCImpl::GetCharWidth() const
1587 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1588 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1590 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1593 wxCoord
wxWindowDCImpl::GetCharHeight() const
1595 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1596 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1598 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1601 void wxWindowDCImpl::Clear()
1603 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1605 if (!m_window
) return;
1607 // VZ: the code below results in infinite recursion and crashes when
1608 // dc.Clear() is done from OnPaint() so I disable it for now.
1609 // I don't know what the correct fix is but Clear() surely should not
1610 // reenter OnPaint()!
1612 /* - we either are a memory dc or have a window as the
1613 owner. anything else shouldn't happen.
1614 - we don't use gdk_window_clear() as we don't set
1615 the window's background colour anymore. it is too
1616 much pain to keep the DC's and the window's back-
1617 ground colour in synch. */
1628 GetSize( &width
, &height
);
1629 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1634 GetSize( &width
, &height
);
1635 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1639 void wxWindowDCImpl::SetFont( const wxFont
&font
)
1644 void wxWindowDCImpl::SetPen( const wxPen
&pen
)
1646 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1648 if (m_pen
== pen
) return;
1652 if (!m_pen
.IsOk()) return;
1654 if (!m_window
) return;
1656 gint width
= m_pen
.GetWidth();
1659 // CMB: if width is non-zero scale it with the dc
1664 // X doesn't allow different width in x and y and so we take
1667 ( fabs((double) XLOG2DEVREL(width
)) +
1668 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1672 // width can't be 0 or an internal GTK error occurs inside
1673 // gdk_gc_set_dashes() below
1678 static const wxGTKDash dotted
[] = {1, 1};
1679 static const wxGTKDash short_dashed
[] = {2, 2};
1680 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1681 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1683 // We express dash pattern in pen width unit, so we are
1684 // independent of zoom factor and so on...
1686 const wxGTKDash
*req_dash
;
1688 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1689 switch (m_pen
.GetStyle())
1693 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1694 req_nb_dash
= m_pen
.GetDashCount();
1695 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1700 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1707 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1709 req_dash
= wxCoord_dashed
;
1714 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1716 req_dash
= short_dashed
;
1721 // lineStyle = GDK_LINE_DOUBLE_DASH;
1722 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1724 req_dash
= dotted_dashed
;
1729 case wxSTIPPLE_MASK_OPAQUE
:
1734 lineStyle
= GDK_LINE_SOLID
;
1741 if (req_dash
&& req_nb_dash
)
1743 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1746 for (int i
= 0; i
< req_nb_dash
; i
++)
1747 real_req_dash
[i
] = req_dash
[i
] * width
;
1748 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1749 delete[] real_req_dash
;
1753 // No Memory. We use non-scaled dash pattern...
1754 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1758 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1759 switch (m_pen
.GetCap())
1761 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1762 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1769 capStyle
= GDK_CAP_NOT_LAST
;
1773 capStyle
= GDK_CAP_ROUND
;
1779 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1780 switch (m_pen
.GetJoin())
1782 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1783 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1785 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1788 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1790 m_pen
.GetColour().CalcPixel( m_cmap
);
1791 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1794 void wxWindowDCImpl::SetBrush( const wxBrush
&brush
)
1796 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1798 if (m_brush
== brush
) return;
1802 if (!m_brush
.IsOk()) return;
1804 if (!m_window
) return;
1806 m_brush
.GetColour().CalcPixel( m_cmap
);
1807 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1809 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1811 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->IsOk()))
1813 if (m_brush
.GetStipple()->GetPixmap())
1815 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1816 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1820 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1821 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
1825 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1827 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1828 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1831 if (m_brush
.IsHatch())
1833 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1834 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1835 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
1839 void wxWindowDCImpl::SetBackground( const wxBrush
&brush
)
1841 /* CMB 21/7/98: Added SetBackground. Sets background brush
1842 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1844 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1846 if (m_backgroundBrush
== brush
) return;
1848 m_backgroundBrush
= brush
;
1850 if (!m_backgroundBrush
.IsOk()) return;
1852 if (!m_window
) return;
1854 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1855 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
1856 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
1857 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1858 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1860 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1862 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->IsOk()))
1864 if (m_backgroundBrush
.GetStipple()->GetPixmap())
1866 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
1867 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
1871 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1872 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
1876 if (m_backgroundBrush
.IsHatch())
1878 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1879 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
1880 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
1884 void wxWindowDCImpl::SetLogicalFunction( wxRasterOperationMode function
)
1886 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1888 if (m_logicalFunction
== function
)
1891 // VZ: shouldn't this be a CHECK?
1898 case wxXOR
: mode
= GDK_XOR
; break;
1899 case wxINVERT
: mode
= GDK_INVERT
; break;
1900 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1901 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1902 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1903 case wxSET
: mode
= GDK_SET
; break;
1904 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1905 case wxAND
: mode
= GDK_AND
; break;
1906 case wxOR
: mode
= GDK_OR
; break;
1907 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1908 case wxNAND
: mode
= GDK_NAND
; break;
1909 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1910 case wxCOPY
: mode
= GDK_COPY
; break;
1911 case wxNO_OP
: mode
= GDK_NOOP
; break;
1912 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1914 // unsupported by GTK
1915 case wxNOR
: mode
= GDK_COPY
; break;
1917 wxFAIL_MSG( wxT("unsupported logical function") );
1921 m_logicalFunction
= function
;
1923 gdk_gc_set_function( m_penGC
, mode
);
1924 gdk_gc_set_function( m_brushGC
, mode
);
1926 // to stay compatible with wxMSW, we don't apply ROPs to the text
1927 // operations (i.e. DrawText/DrawRotatedText).
1928 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1929 gdk_gc_set_function( m_textGC
, mode
);
1932 void wxWindowDCImpl::SetTextForeground( const wxColour
&col
)
1934 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1936 // don't set m_textForegroundColour to an invalid colour as we'd crash
1937 // later then (we use m_textForegroundColour.GetColor() without checking
1939 if ( !col
.IsOk() || (m_textForegroundColour
== col
) )
1942 m_textForegroundColour
= col
;
1946 m_textForegroundColour
.CalcPixel( m_cmap
);
1947 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1951 void wxWindowDCImpl::SetTextBackground( const wxColour
&col
)
1953 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1956 if ( !col
.IsOk() || (m_textBackgroundColour
== col
) )
1959 m_textBackgroundColour
= col
;
1963 m_textBackgroundColour
.CalcPixel( m_cmap
);
1964 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1968 void wxWindowDCImpl::SetBackgroundMode( int mode
)
1970 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1972 m_backgroundMode
= mode
;
1974 if (!m_window
) return;
1976 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
1977 // transparent/solid background mode
1979 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
1981 gdk_gc_set_fill( m_brushGC
,
1982 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
1986 void wxWindowDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1988 wxFAIL_MSG( wxT("wxWindowDCImpl::SetPalette not implemented") );
1991 void wxWindowDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1993 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
1995 if (!m_window
) return;
1998 rect
.x
= XLOG2DEV(x
);
1999 rect
.y
= YLOG2DEV(y
);
2000 rect
.width
= XLOG2DEVREL(width
);
2001 rect
.height
= YLOG2DEVREL(height
);
2003 if (!m_currentClippingRegion
.IsNull())
2004 m_currentClippingRegion
.Intersect( rect
);
2006 m_currentClippingRegion
.Union( rect
);
2008 #if USE_PAINT_REGION
2009 if (!m_paintClippingRegion
.IsNull())
2010 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2013 wxCoord xx
, yy
, ww
, hh
;
2014 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2015 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2017 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2018 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2019 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2020 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2023 void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion
®ion
)
2025 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2029 DestroyClippingRegion();
2033 if (!m_window
) return;
2035 if (!m_currentClippingRegion
.IsNull())
2036 m_currentClippingRegion
.Intersect( region
);
2038 m_currentClippingRegion
.Union( region
);
2040 #if USE_PAINT_REGION
2041 if (!m_paintClippingRegion
.IsNull())
2042 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2045 wxCoord xx
, yy
, ww
, hh
;
2046 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2047 wxGTKDCImpl::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2049 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2050 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2051 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2052 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2055 void wxWindowDCImpl::DestroyClippingRegion()
2057 wxCHECK_RET( IsOk(), wxT("invalid window dc") );
2059 wxGTKDCImpl::DestroyClippingRegion();
2061 m_currentClippingRegion
.Clear();
2063 #if USE_PAINT_REGION
2064 if (!m_paintClippingRegion
.IsEmpty())
2065 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2068 if (!m_window
) return;
2070 if (m_currentClippingRegion
.IsEmpty())
2072 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
2073 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
2074 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
2075 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
2079 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2080 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2081 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2082 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2086 void wxWindowDCImpl::Destroy()
2088 if (m_penGC
) wxFreePoolGC( m_penGC
);
2090 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2092 if (m_textGC
) wxFreePoolGC( m_textGC
);
2094 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2098 void wxWindowDCImpl::ComputeScaleAndOrigin()
2100 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
2102 wxGTKDCImpl::ComputeScaleAndOrigin();
2104 // if scale has changed call SetPen to recalulate the line width
2105 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
2107 // this is a bit artificial, but we need to force wxDC to think the pen
2115 // Resolution in pixels per logical inch
2116 wxSize
wxWindowDCImpl::GetPPI() const
2118 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2121 int wxWindowDCImpl::GetDepth() const
2123 wxFAIL_MSG(wxT("not implemented"));
2129 //-----------------------------------------------------------------------------
2131 //-----------------------------------------------------------------------------
2133 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxClientDCImpl
)
2135 // Limit the paint region to the window size. Sometimes
2136 // the paint region is too big, and this risks X11 errors
2137 static void wxLimitRegionToSize(wxRegion
& region
, const wxSize
& sz
)
2139 wxRect originalRect
= region
.GetBox();
2140 wxRect
rect(originalRect
);
2141 if (rect
.width
+ rect
.x
> sz
.x
)
2142 rect
.width
= sz
.x
- rect
.x
;
2143 if (rect
.height
+ rect
.y
> sz
.y
)
2144 rect
.height
= sz
.y
- rect
.y
;
2145 if (rect
!= originalRect
)
2147 region
= wxRegion(rect
);
2148 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2149 originalRect
.x
, originalRect
.y
, originalRect
.width
, originalRect
.height
,
2150 rect
.x
, rect
.y
, rect
.width
, rect
.height
);
2154 wxPaintDCImpl::wxPaintDCImpl(wxDC
*owner
, wxWindow
*win
)
2155 : wxClientDCImpl(owner
, win
)
2157 #if USE_PAINT_REGION
2158 if (!win
->m_clipPaintRegion
)
2161 wxSize sz
= win
->GetSize();
2162 m_paintClippingRegion
= win
->GetUpdateRegion();
2163 wxLimitRegionToSize(m_paintClippingRegion
, sz
);
2165 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2168 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2169 wxLimitRegionToSize(m_currentClippingRegion
, sz
);
2171 if (sz
.x
<= 0 || sz
.y
<= 0)
2174 gdk_gc_set_clip_region( m_penGC
, region
);
2175 gdk_gc_set_clip_region( m_brushGC
, region
);
2176 gdk_gc_set_clip_region( m_textGC
, region
);
2177 gdk_gc_set_clip_region( m_bgGC
, region
);
2179 #endif // USE_PAINT_REGION
2182 //-----------------------------------------------------------------------------
2184 //-----------------------------------------------------------------------------
2186 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
2188 wxClientDCImpl::wxClientDCImpl(wxDC
*owner
, wxWindow
*win
)
2189 : wxWindowDCImpl(owner
, win
)
2191 wxCHECK_RET( win
, wxT("NULL window in wxClientDCImpl::wxClientDCImpl") );
2193 #ifdef __WXUNIVERSAL__
2194 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2195 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2196 wxSize size
= win
->GetClientSize();
2197 SetClippingRegion(wxPoint(0, 0), size
);
2198 #endif // __WXUNIVERSAL__
2201 void wxClientDCImpl::DoGetSize(int *width
, int *height
) const
2203 wxCHECK_RET( m_owner
, wxT("GetSize() doesn't work without window") );
2205 m_owner
->GetClientSize( width
, height
);
2208 // ----------------------------------------------------------------------------
2210 // ----------------------------------------------------------------------------
2212 class wxDCModule
: public wxModule
2219 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2222 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2224 bool wxDCModule::OnInit()
2230 void wxDCModule::OnExit()