]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "dcclient.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
18 #define XCopyPlane XCOPYPLANE
21 #include "wx/dcclient.h"
22 #include "wx/dcmemory.h"
24 #include "wx/module.h"
26 #include "wx/fontutil.h"
28 #include "wx/gtk/win_gtk.h"
30 #include <math.h> // for floating-point functions
34 #include <gdk/gdkprivate.h>
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 #define USE_PAINT_REGION 1
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
55 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
56 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
59 static GdkPixmap
*hatches
[num_hatches
];
60 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
62 extern GtkWidget
*wxGetRootWindow();
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
68 const double RAD2DEG
= 180.0 / M_PI
;
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
75 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
77 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
79 //-----------------------------------------------------------------------------
80 // temporary implementation of the missing GDK function
81 //-----------------------------------------------------------------------------
83 #include "gdk/gdkprivate.h"
85 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
95 g_return_if_fail (drawable
!= NULL
);
96 g_return_if_fail (src
!= NULL
);
97 g_return_if_fail (gc
!= NULL
);
100 gint src_width
, src_height
;
101 gdk_drawable_get_size(src
, &src_width
, &src_height
);
102 if (width
== -1) width
= src_width
;
103 if (height
== -1) height
= src_height
;
105 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
107 GDK_WINDOW_XID(drawable
),
114 GdkWindowPrivate
*drawable_private
;
115 GdkWindowPrivate
*src_private
;
116 GdkGCPrivate
*gc_private
;
118 drawable_private
= (GdkWindowPrivate
*) drawable
;
119 src_private
= (GdkWindowPrivate
*) src
;
120 if (drawable_private
->destroyed
|| src_private
->destroyed
)
123 gint src_width
= src_private
->width
;
124 gint src_height
= src_private
->height
;
126 gc_private
= (GdkGCPrivate
*) gc
;
128 if (width
== -1) width
= src_width
;
129 if (height
== -1) height
= src_height
;
131 XCopyPlane( drawable_private
->xdisplay
,
132 src_private
->xwindow
,
133 drawable_private
->xwindow
,
142 //-----------------------------------------------------------------------------
143 // Implement Pool of Graphic contexts. Creating them takes too much time.
144 //-----------------------------------------------------------------------------
146 #define GC_POOL_SIZE 200
172 #define GC_POOL_ALLOC_SIZE 100
174 static int wxGCPoolSize
= 0;
176 static wxGC
*wxGCPool
= NULL
;
178 static void wxInitGCPool()
180 // This really could wait until the first call to
181 // wxGetPoolGC, but we will make the first allocation
182 // now when other initialization is being performed.
184 // Set initial pool size.
185 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
187 // Allocate initial pool.
188 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
189 if (wxGCPool
== NULL
)
191 // If we cannot malloc, then fail with error
192 // when debug is enabled. If debug is not enabled,
193 // the problem will eventually get caught
195 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
199 // Zero initial pool.
200 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
203 static void wxCleanUpGCPool()
205 for (int i
= 0; i
< wxGCPoolSize
; i
++)
207 if (wxGCPool
[i
].m_gc
)
208 gdk_gc_unref( wxGCPool
[i
].m_gc
);
216 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
220 // Look for an available GC.
221 for (int i
= 0; i
< wxGCPoolSize
; i
++)
223 if (!wxGCPool
[i
].m_gc
)
225 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
226 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
227 wxGCPool
[i
].m_type
= type
;
228 wxGCPool
[i
].m_used
= FALSE
;
230 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
232 wxGCPool
[i
].m_used
= TRUE
;
233 return wxGCPool
[i
].m_gc
;
237 // We did not find an available GC.
238 // We need to grow the GC pool.
239 pptr
= (wxGC
*)realloc(wxGCPool
,
240 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
243 // Initialize newly allocated pool.
245 memset(&wxGCPool
[wxGCPoolSize
], 0,
246 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
248 // Initialize entry we will return.
249 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
250 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
251 wxGCPool
[wxGCPoolSize
].m_type
= type
;
252 wxGCPool
[wxGCPoolSize
].m_used
= TRUE
;
254 // Set new value of pool size.
255 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
257 // Return newly allocated entry.
258 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
261 // The realloc failed. Fall through to error.
262 wxFAIL_MSG( wxT("No GC available") );
264 return (GdkGC
*) NULL
;
267 static void wxFreePoolGC( GdkGC
*gc
)
269 for (int i
= 0; i
< wxGCPoolSize
; i
++)
271 if (wxGCPool
[i
].m_gc
== gc
)
273 wxGCPool
[i
].m_used
= FALSE
;
278 wxFAIL_MSG( wxT("Wrong GC") );
281 //-----------------------------------------------------------------------------
283 //-----------------------------------------------------------------------------
285 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
287 wxWindowDC::wxWindowDC()
289 m_penGC
= (GdkGC
*) NULL
;
290 m_brushGC
= (GdkGC
*) NULL
;
291 m_textGC
= (GdkGC
*) NULL
;
292 m_bgGC
= (GdkGC
*) NULL
;
293 m_cmap
= (GdkColormap
*) NULL
;
295 m_isScreenDC
= FALSE
;
296 m_owner
= (wxWindow
*)NULL
;
298 m_context
= (PangoContext
*)NULL
;
299 m_layout
= (PangoLayout
*)NULL
;
300 m_fontdesc
= (PangoFontDescription
*)NULL
;
304 wxWindowDC::wxWindowDC( wxWindow
*window
)
306 wxASSERT_MSG( window
, wxT("DC needs a window") );
308 m_penGC
= (GdkGC
*) NULL
;
309 m_brushGC
= (GdkGC
*) NULL
;
310 m_textGC
= (GdkGC
*) NULL
;
311 m_bgGC
= (GdkGC
*) NULL
;
312 m_cmap
= (GdkColormap
*) NULL
;
313 m_owner
= (wxWindow
*)NULL
;
315 m_isScreenDC
= FALSE
;
316 m_font
= window
->GetFont();
318 GtkWidget
*widget
= window
->m_wxwindow
;
320 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
321 // code should still be able to create wxClientDCs for them, so we will
322 // use the parent window here then.
325 window
= window
->GetParent();
326 widget
= window
->m_wxwindow
;
329 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
332 m_context
= window
->GtkGetPangoDefaultContext();
333 m_layout
= pango_layout_new( m_context
);
334 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
337 GtkPizza
*pizza
= GTK_PIZZA( widget
);
338 m_window
= pizza
->bin_window
;
340 // Window not realized ?
343 // Don't report problems as per MSW.
349 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
353 /* this must be done after SetUpDC, bacause SetUpDC calls the
354 repective SetBrush, SetPen, SetBackground etc functions
355 to set up the DC. SetBackground call m_owner->SetBackground
356 and this might not be desired as the standard dc background
357 is white whereas a window might assume gray to be the
358 standard (as e.g. wxStatusBar) */
363 wxWindowDC::~wxWindowDC()
369 g_object_unref( G_OBJECT( m_layout
) );
371 pango_font_description_free( m_fontdesc
);
375 void wxWindowDC::SetUpDC()
379 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
383 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
384 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
385 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
386 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
389 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
391 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
392 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
393 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
394 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
398 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
399 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
400 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
401 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
404 /* background colour */
405 m_backgroundBrush
= *wxWHITE_BRUSH
;
406 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
407 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
410 m_textForegroundColour
.CalcPixel( m_cmap
);
411 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
413 m_textBackgroundColour
.CalcPixel( m_cmap
);
414 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
416 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
419 m_pen
.GetColour().CalcPixel( m_cmap
);
420 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
421 gdk_gc_set_background( m_penGC
, bg_col
);
423 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
426 m_brush
.GetColour().CalcPixel( m_cmap
);
427 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
428 gdk_gc_set_background( m_brushGC
, bg_col
);
430 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
433 gdk_gc_set_background( m_bgGC
, bg_col
);
434 gdk_gc_set_foreground( m_bgGC
, bg_col
);
436 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
439 gdk_gc_set_function( m_textGC
, GDK_COPY
);
440 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
441 gdk_gc_set_function( m_penGC
, GDK_COPY
);
444 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
445 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
446 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
447 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
451 hatch_bitmap
= hatches
;
452 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
453 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
454 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
455 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
456 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
457 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
461 void wxWindowDC::DoGetSize( int* width
, int* height
) const
463 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
465 m_owner
->GetSize(width
, height
);
468 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
469 const wxColour
& col
, int style
);
471 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
472 const wxColour
& col
, int style
)
474 return wxDoFloodFill(this, x
, y
, col
, style
);
477 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
479 // Generic (and therefore rather inefficient) method.
480 // Could be improved.
482 wxBitmap
bitmap(1, 1);
483 memdc
.SelectObject(bitmap
);
484 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
485 memdc
.SelectObject(wxNullBitmap
);
487 wxImage image
= bitmap
.ConvertToImage();
488 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
492 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
494 wxCHECK_RET( Ok(), wxT("invalid window dc") );
496 if (m_pen
.GetStyle() != wxTRANSPARENT
)
499 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
501 CalcBoundingBox(x1
, y1
);
502 CalcBoundingBox(x2
, y2
);
506 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
508 wxCHECK_RET( Ok(), wxT("invalid window dc") );
510 if (m_pen
.GetStyle() != wxTRANSPARENT
)
515 wxCoord xx
= XLOG2DEV(x
);
516 wxCoord yy
= YLOG2DEV(y
);
519 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
520 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
525 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
526 wxCoord xc
, wxCoord yc
)
528 wxCHECK_RET( Ok(), wxT("invalid window dc") );
530 wxCoord xx1
= XLOG2DEV(x1
);
531 wxCoord yy1
= YLOG2DEV(y1
);
532 wxCoord xx2
= XLOG2DEV(x2
);
533 wxCoord yy2
= YLOG2DEV(y2
);
534 wxCoord xxc
= XLOG2DEV(xc
);
535 wxCoord yyc
= YLOG2DEV(yc
);
536 double dx
= xx1
- xxc
;
537 double dy
= yy1
- yyc
;
538 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
539 wxCoord r
= (wxCoord
)radius
;
540 double radius1
, radius2
;
542 if (xx1
== xx2
&& yy1
== yy2
)
550 radius1
= radius2
= 0.0;
554 radius1
= (xx1
- xxc
== 0) ?
555 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
556 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
557 radius2
= (xx2
- xxc
== 0) ?
558 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
559 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
561 wxCoord alpha1
= wxCoord(radius1
* 64.0);
562 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
563 while (alpha2
<= 0) alpha2
+= 360*64;
564 while (alpha1
> 360*64) alpha1
-= 360*64;
568 if (m_brush
.GetStyle() != wxTRANSPARENT
)
570 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
572 gdk_gc_set_ts_origin( m_textGC
,
573 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
574 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
575 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
576 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
578 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
580 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
586 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
587 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
588 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
590 if (m_brush
.GetStyle() == wxSTIPPLE
)
592 gdk_gc_set_ts_origin( m_brushGC
,
593 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
594 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
595 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
596 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
600 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
604 if (m_pen
.GetStyle() != wxTRANSPARENT
)
606 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
608 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
609 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
613 CalcBoundingBox (x1
, y1
);
614 CalcBoundingBox (x2
, y2
);
617 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
619 wxCHECK_RET( Ok(), wxT("invalid window dc") );
621 wxCoord xx
= XLOG2DEV(x
);
622 wxCoord yy
= YLOG2DEV(y
);
623 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
624 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
626 // CMB: handle -ve width and/or height
627 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
628 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
632 wxCoord start
= wxCoord(sa
* 64.0);
633 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
635 if (m_brush
.GetStyle() != wxTRANSPARENT
)
637 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
639 gdk_gc_set_ts_origin( m_textGC
,
640 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
641 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
642 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
643 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
645 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
647 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 (IS_16_PIX_HATCH(m_brush
.GetStyle()))
653 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
654 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
655 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
657 if (m_brush
.GetStyle() == wxSTIPPLE
)
659 gdk_gc_set_ts_origin( m_brushGC
,
660 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
661 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
662 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
663 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
667 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
671 if (m_pen
.GetStyle() != wxTRANSPARENT
)
672 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
675 CalcBoundingBox (x
, y
);
676 CalcBoundingBox (x
+ width
, y
+ height
);
679 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
681 wxCHECK_RET( Ok(), wxT("invalid window dc") );
683 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
684 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
686 CalcBoundingBox (x
, y
);
689 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
691 wxCHECK_RET( Ok(), wxT("invalid window dc") );
693 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
696 GdkPoint
*gpts
= new GdkPoint
[n
];
699 wxFAIL_MSG( wxT("Cannot allocate PolyLine") );
703 for (int i
= 0; i
< n
; i
++)
705 wxCoord x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
706 wxCoord y1
= YLOG2DEV(points
[i
].y
+ yoffset
);
708 CalcBoundingBox( x1
+ xoffset
, y1
+ yoffset
);
715 gdk_draw_lines( m_window
, m_penGC
, gpts
, n
);
720 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
722 wxCHECK_RET( Ok(), wxT("invalid window dc") );
726 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
728 for (i
= 0 ; i
< n
; i
++)
730 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
731 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
733 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
738 if (m_brush
.GetStyle() != wxTRANSPARENT
)
740 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
742 gdk_gc_set_ts_origin( m_textGC
,
743 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
744 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
745 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
746 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
748 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
750 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
751 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
752 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
754 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
756 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
757 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
758 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
760 if (m_brush
.GetStyle() == wxSTIPPLE
)
762 gdk_gc_set_ts_origin( m_brushGC
,
763 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
764 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
765 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
766 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
770 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
774 if (m_pen
.GetStyle() != wxTRANSPARENT
)
776 for (i
= 0 ; i
< n
; i
++)
778 gdk_draw_line( m_window
, m_penGC
,
781 gdkpoints
[(i
+1)%n
].x
,
782 gdkpoints
[(i
+1)%n
].y
);
790 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
792 wxCHECK_RET( Ok(), wxT("invalid window dc") );
794 wxCoord xx
= XLOG2DEV(x
);
795 wxCoord yy
= YLOG2DEV(y
);
796 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
797 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
799 // CMB: draw nothing if transformed w or h is 0
800 if (ww
== 0 || hh
== 0) return;
802 // CMB: handle -ve width and/or height
803 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
804 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
808 if (m_brush
.GetStyle() != wxTRANSPARENT
)
810 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
812 gdk_gc_set_ts_origin( m_textGC
,
813 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
814 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
815 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
816 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
818 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
820 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
821 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
822 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
824 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
826 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
827 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
828 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
830 if (m_brush
.GetStyle() == wxSTIPPLE
)
832 gdk_gc_set_ts_origin( m_brushGC
,
833 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
834 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
835 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
836 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
840 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
844 if (m_pen
.GetStyle() != wxTRANSPARENT
)
845 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
848 CalcBoundingBox( x
, y
);
849 CalcBoundingBox( x
+ width
, y
+ height
);
852 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
854 wxCHECK_RET( Ok(), wxT("invalid window dc") );
856 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
858 wxCoord xx
= XLOG2DEV(x
);
859 wxCoord yy
= YLOG2DEV(y
);
860 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
861 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
862 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
864 // CMB: handle -ve width and/or height
865 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
866 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
868 // CMB: if radius is zero use DrawRectangle() instead to avoid
869 // X drawing errors with small radii
872 DrawRectangle( x
, y
, width
, height
);
876 // CMB: draw nothing if transformed w or h is 0
877 if (ww
== 0 || hh
== 0) return;
879 // CMB: adjust size if outline is drawn otherwise the result is
880 // 1 pixel too wide and high
881 if (m_pen
.GetStyle() != wxTRANSPARENT
)
889 // CMB: ensure dd is not larger than rectangle otherwise we
890 // get an hour glass shape
892 if (dd
> ww
) dd
= ww
;
893 if (dd
> hh
) dd
= hh
;
896 if (m_brush
.GetStyle() != wxTRANSPARENT
)
898 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
900 gdk_gc_set_ts_origin( m_textGC
,
901 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
902 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
903 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
904 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
905 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
906 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
907 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
908 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
909 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
911 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
913 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
914 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
915 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
916 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
917 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
918 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
919 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
920 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
922 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
924 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
925 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
926 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
927 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
928 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
929 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
930 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
931 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
933 if (m_brush
.GetStyle() == wxSTIPPLE
)
935 gdk_gc_set_ts_origin( m_brushGC
,
936 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
937 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
938 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
939 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
940 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
941 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
942 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
943 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
944 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
948 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
949 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
950 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
951 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
952 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
953 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
957 if (m_pen
.GetStyle() != wxTRANSPARENT
)
959 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
960 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
961 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
962 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
963 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
964 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
965 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
966 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
970 // this ignores the radius
971 CalcBoundingBox( x
, y
);
972 CalcBoundingBox( x
+ width
, y
+ height
);
975 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
977 wxCHECK_RET( Ok(), wxT("invalid window dc") );
979 wxCoord xx
= XLOG2DEV(x
);
980 wxCoord yy
= YLOG2DEV(y
);
981 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
982 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
984 // CMB: handle -ve width and/or height
985 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
986 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
990 if (m_brush
.GetStyle() != wxTRANSPARENT
)
992 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
994 gdk_gc_set_ts_origin( m_textGC
,
995 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
996 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
997 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
998 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
1000 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
1002 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
1003 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1004 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1006 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1008 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
1009 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1010 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1012 if (m_brush
.GetStyle() == wxSTIPPLE
)
1014 gdk_gc_set_ts_origin( m_brushGC
,
1015 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1016 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1017 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1018 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1022 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1026 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1027 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1030 CalcBoundingBox( x
, y
);
1031 CalcBoundingBox( x
+ width
, y
+ height
);
1034 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1036 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1037 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
1040 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1041 wxCoord x
, wxCoord y
,
1044 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1046 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1048 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1050 // scale/translate size and position
1051 int xx
= XLOG2DEV(x
);
1052 int yy
= YLOG2DEV(y
);
1054 int w
= bitmap
.GetWidth();
1055 int h
= bitmap
.GetHeight();
1057 CalcBoundingBox( x
, y
);
1058 CalcBoundingBox( x
+ w
, y
+ h
);
1060 if (!m_window
) return;
1062 int ww
= XLOG2DEVREL(w
);
1063 int hh
= YLOG2DEVREL(h
);
1065 // compare to current clipping region
1066 if (!m_currentClippingRegion
.IsNull())
1068 wxRegion
tmp( xx
,yy
,ww
,hh
);
1069 tmp
.Intersect( m_currentClippingRegion
);
1074 // scale bitmap if required
1075 wxBitmap use_bitmap
= bitmap
;
1076 if ((w
!= ww
) || (h
!= hh
))
1077 use_bitmap
= use_bitmap
.Rescale( 0, 0, ww
, hh
, ww
, hh
);
1079 // apply mask if any
1080 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1081 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1083 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1085 if (useMask
&& mask
)
1087 if (!m_currentClippingRegion
.IsNull())
1090 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1091 GdkGC
*gc
= gdk_gc_new( new_mask
);
1093 gdk_gc_set_foreground( gc
, &col
);
1094 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1096 gdk_gc_set_background( gc
, &col
);
1098 gdk_gc_set_foreground( gc
, &col
);
1099 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1100 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1101 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1102 gdk_gc_set_stipple( gc
, mask
);
1103 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1110 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1112 gdk_gc_set_clip_mask( m_textGC
, mask
);
1113 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1118 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1120 gdk_gc_set_clip_mask( m_penGC
, mask
);
1121 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1125 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1126 // drawing a mono-bitmap (XBitmap) we use the current text GC
1130 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, -1 );
1131 GdkGC
*gc
= gdk_gc_new( bitmap
);
1132 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1133 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1134 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetBitmap(), 0, 0, 0, 0, -1, -1 );
1136 gdk_draw_drawable( m_window
, m_textGC
, bitmap
, 0, 0, xx
, yy
, -1, -1 );
1138 gdk_bitmap_unref( bitmap
);
1141 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
1146 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1149 // remove mask again if any
1150 if (useMask
&& mask
)
1154 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1155 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1156 if (!m_currentClippingRegion
.IsNull())
1157 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1161 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1162 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1163 if (!m_currentClippingRegion
.IsNull())
1164 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1169 gdk_bitmap_unref( new_mask
);
1172 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1173 wxCoord width
, wxCoord height
,
1175 wxCoord xsrc
, wxCoord ysrc
,
1178 wxCoord xsrcMask
, wxCoord ysrcMask
)
1180 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid window dc") );
1182 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1184 if (!m_window
) return FALSE
;
1186 // transform the source DC coords to the device ones
1187 xsrc
= source
->XLOG2DEV(xsrc
);
1188 ysrc
= source
->YLOG2DEV(ysrc
);
1190 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1191 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1193 bool use_bitmap_method
= FALSE
;
1194 bool is_mono
= FALSE
;
1196 // TODO: use the mask origin when drawing transparently
1197 if (xsrcMask
== -1 && ysrcMask
== -1)
1203 if (srcDC
->m_isMemDC
)
1205 if (!memDC
->m_selected
.Ok()) return FALSE
;
1207 is_mono
= (memDC
->m_selected
.GetDepth() == 1);
1209 // we use the "XCopyArea" way to copy a memory dc into
1210 // a different window if the memory dc BOTH
1211 // a) doesn't have any mask or its mask isn't used
1215 if (useMask
&& (memDC
->m_selected
.GetMask()))
1217 // we HAVE TO use the direct way for memory dcs
1218 // that have mask since the XCopyArea doesn't know
1220 use_bitmap_method
= TRUE
;
1224 // we HAVE TO use the direct way for memory dcs
1225 // that are bitmaps because XCopyArea doesn't cope
1226 // with different bit depths
1227 use_bitmap_method
= TRUE
;
1229 else if ((xsrc
== 0) && (ysrc
== 0) &&
1230 (width
== memDC
->m_selected
.GetWidth()) &&
1231 (height
== memDC
->m_selected
.GetHeight()))
1233 // we SHOULD use the direct way if all of the bitmap
1234 // in the memory dc is copied in which case XCopyArea
1235 // wouldn't be able able to boost performace by reducing
1236 // the area to be scaled
1237 use_bitmap_method
= TRUE
;
1241 use_bitmap_method
= FALSE
;
1245 CalcBoundingBox( xdest
, ydest
);
1246 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1248 // scale/translate size and position
1249 wxCoord xx
= XLOG2DEV(xdest
);
1250 wxCoord yy
= YLOG2DEV(ydest
);
1252 wxCoord ww
= XLOG2DEVREL(width
);
1253 wxCoord hh
= YLOG2DEVREL(height
);
1255 // compare to current clipping region
1256 if (!m_currentClippingRegion
.IsNull())
1258 wxRegion
tmp( xx
,yy
,ww
,hh
);
1259 tmp
.Intersect( m_currentClippingRegion
);
1264 int old_logical_func
= m_logicalFunction
;
1265 SetLogicalFunction( logical_func
);
1267 if (use_bitmap_method
)
1269 // scale/translate bitmap size
1270 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1271 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1274 wxRegion
tmp( xx
,yy
,ww
,hh
);
1275 tmp
.Intersect( m_currentClippingRegion
);
1276 wxCoord cx
,cy
,cw
,ch
;
1277 tmp
.GetBox(cx
,cy
,cw
,ch
);
1279 // interpret userscale of src too
1281 memDC
->GetUserScale(&xsc
,&ysc
);
1282 bm_width
= (int) (bm_width
/ xsc
);
1283 bm_height
= (int) (bm_height
/ ysc
);
1285 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1286 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1288 // scale bitmap if required
1289 wxBitmap use_bitmap
;
1291 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1293 use_bitmap
= memDC
->m_selected
.Rescale(cx
-xx
,cy
-yy
,cw
,ch
,bm_ww
,bm_hh
);
1297 // FIXME: use cx,cy,cw,ch here, too?
1298 use_bitmap
= memDC
->m_selected
;
1301 // apply mask if any
1302 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1303 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1305 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1307 if (useMask
&& mask
)
1309 if (!m_currentClippingRegion
.IsNull())
1312 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1313 GdkGC
*gc
= gdk_gc_new( new_mask
);
1315 gdk_gc_set_foreground( gc
, &col
);
1316 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1318 gdk_gc_set_background( gc
, &col
);
1320 gdk_gc_set_foreground( gc
, &col
);
1321 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1322 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1323 gdk_gc_set_clip_origin( gc
, -cx
, -cy
);
1324 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1325 gdk_gc_set_stipple( gc
, mask
);
1326 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1333 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1335 gdk_gc_set_clip_mask( m_textGC
, mask
);
1336 // was: gdk_gc_set_clip_origin( m_textGC, xx, yy );
1337 gdk_gc_set_clip_origin( m_textGC
, cx
, cy
);
1342 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1344 gdk_gc_set_clip_mask( m_penGC
, mask
);
1345 // was: gdk_gc_set_clip_origin( m_penGC, xx, yy );
1346 gdk_gc_set_clip_origin( m_penGC
, cx
, cy
);
1350 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1351 // drawing a mono-bitmap (XBitmap) we use the current text GC
1356 GdkPixmap
*bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, -1 );
1357 GdkGC
*gc
= gdk_gc_new( bitmap
);
1358 gdk_gc_set_foreground( gc
, m_textForegroundColour
.GetColor() );
1359 gdk_gc_set_background( gc
, m_textBackgroundColour
.GetColor() );
1360 gdk_wx_draw_bitmap( bitmap
, gc
, use_bitmap
.GetBitmap(), 0, 0, 0, 0, -1, -1 );
1362 gdk_draw_drawable( m_window
, m_textGC
, bitmap
, xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1364 gdk_bitmap_unref( bitmap
);
1367 // was: gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
1368 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1373 // was: gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1374 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, cx
, cy
, cw
, ch
);
1377 // remove mask again if any
1378 if (useMask
&& mask
)
1382 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1383 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1384 if (!m_currentClippingRegion
.IsNull())
1385 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1389 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1390 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1391 if (!m_currentClippingRegion
.IsNull())
1392 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1397 gdk_bitmap_unref( new_mask
);
1399 else // use_bitmap_method
1401 if ((width
!= ww
) || (height
!= hh
))
1404 wxRegion
tmp( xx
,yy
,ww
,hh
);
1405 tmp
.Intersect( m_currentClippingRegion
);
1406 wxCoord cx
,cy
,cw
,ch
;
1407 tmp
.GetBox(cx
,cy
,cw
,ch
);
1410 wxBitmap bitmap
= memDC
->m_selected
.Rescale( cx
-xx
, cy
-yy
, cw
, ch
, ww
, hh
);
1412 // draw scaled bitmap
1413 // was: gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1414 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, cx
, cy
, -1, -1 );
1418 // No scaling and not a memory dc with a mask either
1420 // copy including child window contents
1421 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1422 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1424 xsrc
, ysrc
, width
, height
);
1425 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1429 SetLogicalFunction( old_logical_func
);
1434 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1436 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1438 if (!m_window
) return;
1440 if (text
.empty()) return;
1443 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1445 wxCHECK_RET( font
, wxT("invalid font") );
1452 wxCHECK_RET( m_context
, wxT("no Pango context") );
1453 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1454 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1457 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1459 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1460 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1462 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1466 if (abs(m_scaleY
- 1.0) < 0.00001)
1468 // If there is a user or actually any scale applied to
1469 // the device context, scale the font.
1471 // scale font description
1472 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1473 double size
= oldSize
;
1474 size
= size
* m_scaleY
;
1475 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1477 // actually apply scaled font
1478 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1480 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1481 if ( m_backgroundMode
== wxSOLID
)
1483 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1484 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1485 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1489 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1491 // reset unscaled size
1492 pango_font_description_set_size( m_fontdesc
, oldSize
);
1494 // actually apply unscaled font
1495 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1499 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1500 if ( m_backgroundMode
== wxSOLID
)
1502 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1503 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1504 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1507 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1514 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1515 wxCoord height
= font
->ascent
+ font
->descent
;
1517 if ( m_backgroundMode
== wxSOLID
)
1519 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1520 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1521 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1523 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1525 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1526 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1527 properties (see wxXt implementation) */
1528 if (m_font
.GetUnderlined())
1530 wxCoord ul_y
= y
+ font
->ascent
;
1531 if (font
->descent
> 0) ul_y
++;
1532 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1534 #endif // GTK+ 2.0/1.x
1536 width
= wxCoord(width
/ m_scaleX
);
1537 height
= wxCoord(height
/ m_scaleY
);
1538 CalcBoundingBox (x
+ width
, y
+ height
);
1539 CalcBoundingBox (x
, y
);
1542 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1546 DrawText(text
, x
, y
);
1550 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1552 if (!m_window
) return;
1555 // implement later without GdkFont for GTK 2.0
1558 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1560 wxCHECK_RET( font
, wxT("invalid font") );
1562 // the size of the text
1563 wxCoord w
= gdk_string_width( font
, text
.mbc_str() );
1564 wxCoord h
= font
->ascent
+ font
->descent
;
1566 // draw the string normally
1569 dc
.SelectObject(src
);
1570 dc
.SetFont(GetFont());
1571 dc
.SetBackground(*wxWHITE_BRUSH
);
1572 dc
.SetBrush(*wxBLACK_BRUSH
);
1574 dc
.DrawText(text
, 0, 0);
1575 dc
.SelectObject(wxNullBitmap
);
1577 // Calculate the size of the rotated bounding box.
1578 double rad
= DegToRad(angle
);
1579 double dx
= cos(rad
),
1582 // the rectngle vertices are counted clockwise with the first one being at
1583 // (0, 0) (or, rather, at (x, y))
1585 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1588 double x3
= x4
+ x2
,
1592 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1593 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1594 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1595 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1597 // prepare to blit-with-rotate the bitmap to the DC
1598 wxImage image
= src
.ConvertToImage();
1600 GdkColor
*colText
= m_textForegroundColour
.GetColor(),
1601 *colBack
= m_textBackgroundColour
.GetColor();
1603 bool textColSet
= TRUE
;
1605 unsigned char *data
= image
.GetData();
1607 // paint pixel by pixel
1608 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1610 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1612 // transform source coords to dest coords
1613 double r
= sqrt((double)srcX
*srcX
+ srcY
*srcY
);
1614 double angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1615 wxCoord dstX
= (wxCoord
)(r
*cos(angleOrig
) + 0.5),
1616 dstY
= (wxCoord
)(r
*sin(angleOrig
) + 0.5);
1619 bool textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1620 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1622 // change colour if needed
1623 if ( textPixel
!= textColSet
)
1625 gdk_gc_set_foreground( m_textGC
, textPixel
? colText
1628 textColSet
= textPixel
;
1631 // don't use DrawPoint() because it uses the current pen
1632 // colour, and we don't need it here
1633 gdk_draw_point( m_window
, m_textGC
,
1634 XLOG2DEV(x
) + dstX
, YLOG2DEV(y
) + dstY
);
1639 // it would be better to draw with non underlined font and draw the line
1640 // manually here (it would be more straight...)
1642 if ( m_font
.GetUnderlined() )
1644 gdk_draw_line( m_window
, m_textGC
,
1645 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1646 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1650 // restore the font colour
1651 gdk_gc_set_foreground( m_textGC
, colText
);
1653 // update the bounding box
1654 CalcBoundingBox(x
+ minX
, y
+ minY
);
1655 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1659 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1660 wxCoord
*width
, wxCoord
*height
,
1661 wxCoord
*descent
, wxCoord
*externalLeading
,
1662 wxFont
*theFont
) const
1664 if (string
.IsEmpty())
1666 if (width
) (*width
) = 0;
1667 if (height
) (*height
) = 0;
1672 // Set new font description
1674 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1676 // Set layout's text
1678 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1679 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1681 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1682 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1683 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1687 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1689 if (width
) (*width
) = (wxCoord
) w
;
1690 if (height
) (*height
) = (wxCoord
) h
;
1693 // Do something about metrics here. TODO.
1696 if (externalLeading
) (*externalLeading
) = 0; // ??
1698 // Reset old font description
1700 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1702 wxFont fontToUse
= m_font
;
1703 if (theFont
) fontToUse
= *theFont
;
1705 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1706 if (width
) (*width
) = wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1707 if (height
) (*height
) = wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1708 if (descent
) (*descent
) = wxCoord(font
->descent
/ m_scaleY
);
1709 if (externalLeading
) (*externalLeading
) = 0; // ??
1713 wxCoord
wxWindowDC::GetCharWidth() const
1716 pango_layout_set_text( m_layout
, "H", 1 );
1718 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1721 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1722 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1724 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1728 wxCoord
wxWindowDC::GetCharHeight() const
1731 pango_layout_set_text( m_layout
, "H", 1 );
1733 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1736 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1737 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1739 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1743 void wxWindowDC::Clear()
1745 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1747 if (!m_window
) return;
1749 // VZ: the code below results in infinite recursion and crashes when
1750 // dc.Clear() is done from OnPaint() so I disable it for now.
1751 // I don't know what the correct fix is but Clear() surely should not
1752 // reenter OnPaint()!
1754 /* - we either are a memory dc or have a window as the
1755 owner. anything else shouldn't happen.
1756 - we don't use gdk_window_clear() as we don't set
1757 the window's background colour anymore. it is too
1758 much pain to keep the DC's and the window's back-
1759 ground colour in synch. */
1770 GetSize( &width
, &height
);
1771 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1776 GetSize( &width
, &height
);
1777 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1781 void wxWindowDC::SetFont( const wxFont
&font
)
1789 pango_font_description_free( m_fontdesc
);
1791 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1796 PangoContext
*oldContext
= m_context
;
1798 // We might want to use the X11 context for faster
1799 // rendering on screen
1800 if (m_font
.GetNoAntiAliasing())
1801 m_context
= m_owner
->GtkGetPangoX11Context();
1803 m_context
= m_owner
->GtkGetPangoDefaultContext();
1805 // If we switch back/forth between different contexts
1806 // we also have to create a new layout. I think so,
1807 // at least, and it doesn't hurt to do it.
1808 if (oldContext
!= m_context
)
1811 g_object_unref( G_OBJECT( m_layout
) );
1813 m_layout
= pango_layout_new( m_context
);
1817 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1822 void wxWindowDC::SetPen( const wxPen
&pen
)
1824 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1826 if (m_pen
== pen
) return;
1830 if (!m_pen
.Ok()) return;
1832 if (!m_window
) return;
1834 gint width
= m_pen
.GetWidth();
1837 // CMB: if width is non-zero scale it with the dc
1842 // X doesn't allow different width in x and y and so we take
1845 ( fabs((double) XLOG2DEVREL(width
)) +
1846 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1850 // width can't be 0 or an internal GTK error occurs inside
1851 // gdk_gc_set_dashes() below
1856 static const wxGTKDash dotted
[] = {1, 1};
1857 static const wxGTKDash short_dashed
[] = {2, 2};
1858 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1859 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1861 // We express dash pattern in pen width unit, so we are
1862 // independent of zoom factor and so on...
1864 const wxGTKDash
*req_dash
;
1866 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1867 switch (m_pen
.GetStyle())
1871 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1872 req_nb_dash
= m_pen
.GetDashCount();
1873 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1878 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1885 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1887 req_dash
= wxCoord_dashed
;
1892 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1894 req_dash
= short_dashed
;
1899 // lineStyle = GDK_LINE_DOUBLE_DASH;
1900 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1902 req_dash
= dotted_dashed
;
1907 case wxSTIPPLE_MASK_OPAQUE
:
1912 lineStyle
= GDK_LINE_SOLID
;
1913 req_dash
= (wxGTKDash
*)NULL
;
1919 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
1920 if (req_dash
&& req_nb_dash
)
1922 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1925 for (int i
= 0; i
< req_nb_dash
; i
++)
1926 real_req_dash
[i
] = req_dash
[i
] * width
;
1927 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1928 delete[] real_req_dash
;
1932 // No Memory. We use non-scaled dash pattern...
1933 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1936 #endif // GTK+ > 1.0
1938 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1939 switch (m_pen
.GetCap())
1941 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1942 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1949 capStyle
= GDK_CAP_NOT_LAST
;
1953 capStyle
= GDK_CAP_ROUND
;
1959 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1960 switch (m_pen
.GetJoin())
1962 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1963 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1965 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1968 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1970 m_pen
.GetColour().CalcPixel( m_cmap
);
1971 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1974 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1976 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1978 if (m_brush
== brush
) return;
1982 if (!m_brush
.Ok()) return;
1984 if (!m_window
) return;
1986 m_brush
.GetColour().CalcPixel( m_cmap
);
1987 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1989 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1991 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1993 if (m_brush
.GetStipple()->GetPixmap())
1995 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1996 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
2000 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2001 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
2005 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
2007 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
2008 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
2011 if (IS_HATCH(m_brush
.GetStyle()))
2013 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
2014 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
2015 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
2019 void wxWindowDC::SetBackground( const wxBrush
&brush
)
2021 /* CMB 21/7/98: Added SetBackground. Sets background brush
2022 * for Clear() and bg colour for shapes filled with cross-hatch brush */
2024 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2026 if (m_backgroundBrush
== brush
) return;
2028 m_backgroundBrush
= brush
;
2030 if (!m_backgroundBrush
.Ok()) return;
2032 if (!m_window
) return;
2034 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2035 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2036 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2037 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2038 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2040 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2042 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
2044 if (m_backgroundBrush
.GetStipple()->GetPixmap())
2046 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2047 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2051 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2052 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
2056 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
2058 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2059 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2060 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2064 void wxWindowDC::SetLogicalFunction( int function
)
2066 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2068 if (m_logicalFunction
== function
)
2071 // VZ: shouldn't this be a CHECK?
2078 case wxXOR
: mode
= GDK_XOR
; break;
2079 case wxINVERT
: mode
= GDK_INVERT
; break;
2080 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
2081 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2082 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2083 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2084 case wxSET
: mode
= GDK_SET
; break;
2085 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2086 case wxAND
: mode
= GDK_AND
; break;
2087 case wxOR
: mode
= GDK_OR
; break;
2088 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2089 case wxNAND
: mode
= GDK_NAND
; break;
2090 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2091 case wxCOPY
: mode
= GDK_COPY
; break;
2092 case wxNO_OP
: mode
= GDK_NOOP
; break;
2093 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2095 // unsupported by GTK
2096 case wxNOR
: mode
= GDK_COPY
; break;
2097 #endif // GTK+ > 1.0
2099 wxFAIL_MSG( wxT("unsupported logical function") );
2103 m_logicalFunction
= function
;
2105 gdk_gc_set_function( m_penGC
, mode
);
2106 gdk_gc_set_function( m_brushGC
, mode
);
2108 // to stay compatible with wxMSW, we don't apply ROPs to the text
2109 // operations (i.e. DrawText/DrawRotatedText).
2110 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2111 gdk_gc_set_function( m_textGC
, mode
);
2114 void wxWindowDC::SetTextForeground( const wxColour
&col
)
2116 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2118 // don't set m_textForegroundColour to an invalid colour as we'd crash
2119 // later then (we use m_textForegroundColour.GetColor() without checking
2121 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2124 m_textForegroundColour
= col
;
2128 m_textForegroundColour
.CalcPixel( m_cmap
);
2129 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2133 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2135 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2138 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2141 m_textBackgroundColour
= col
;
2145 m_textBackgroundColour
.CalcPixel( m_cmap
);
2146 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2150 void wxWindowDC::SetBackgroundMode( int mode
)
2152 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2154 m_backgroundMode
= mode
;
2156 if (!m_window
) return;
2158 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2159 // transparent/solid background mode
2161 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2163 gdk_gc_set_fill( m_brushGC
,
2164 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2168 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2170 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
2173 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2175 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2177 if (!m_window
) return;
2180 rect
.x
= XLOG2DEV(x
);
2181 rect
.y
= YLOG2DEV(y
);
2182 rect
.width
= XLOG2DEVREL(width
);
2183 rect
.height
= YLOG2DEVREL(height
);
2185 if (!m_currentClippingRegion
.IsNull())
2186 m_currentClippingRegion
.Intersect( rect
);
2188 m_currentClippingRegion
.Union( rect
);
2190 #if USE_PAINT_REGION
2191 if (!m_paintClippingRegion
.IsNull())
2192 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2195 wxCoord xx
, yy
, ww
, hh
;
2196 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2197 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2199 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2200 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2201 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2202 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2205 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2207 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2211 DestroyClippingRegion();
2215 if (!m_window
) return;
2217 if (!m_currentClippingRegion
.IsNull())
2218 m_currentClippingRegion
.Intersect( region
);
2220 m_currentClippingRegion
.Union( region
);
2222 #if USE_PAINT_REGION
2223 if (!m_paintClippingRegion
.IsNull())
2224 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2227 wxCoord xx
, yy
, ww
, hh
;
2228 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2229 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2231 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2232 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2233 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2234 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2237 void wxWindowDC::DestroyClippingRegion()
2239 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2241 wxDC::DestroyClippingRegion();
2243 m_currentClippingRegion
.Clear();
2245 #if USE_PAINT_REGION
2246 if (!m_paintClippingRegion
.IsEmpty())
2247 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2250 if (!m_window
) return;
2252 if (m_currentClippingRegion
.IsEmpty())
2254 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2255 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2256 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2257 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2261 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2262 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2263 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2264 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2268 void wxWindowDC::Destroy()
2270 if (m_penGC
) wxFreePoolGC( m_penGC
);
2271 m_penGC
= (GdkGC
*) NULL
;
2272 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2273 m_brushGC
= (GdkGC
*) NULL
;
2274 if (m_textGC
) wxFreePoolGC( m_textGC
);
2275 m_textGC
= (GdkGC
*) NULL
;
2276 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2277 m_bgGC
= (GdkGC
*) NULL
;
2280 void wxWindowDC::ComputeScaleAndOrigin()
2282 /* CMB: copy scale to see if it changes */
2283 double origScaleX
= m_scaleX
;
2284 double origScaleY
= m_scaleY
;
2286 wxDC::ComputeScaleAndOrigin();
2288 /* CMB: if scale has changed call SetPen to recalulate the line width */
2289 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
2292 /* this is a bit artificial, but we need to force wxDC to think
2293 the pen has changed */
2300 // Resolution in pixels per logical inch
2301 wxSize
wxWindowDC::GetPPI() const
2303 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2306 int wxWindowDC::GetDepth() const
2308 wxFAIL_MSG(wxT("not implemented"));
2314 //-----------------------------------------------------------------------------
2316 //-----------------------------------------------------------------------------
2318 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2320 wxPaintDC::wxPaintDC( wxWindow
*win
)
2323 #if USE_PAINT_REGION
2324 if (!win
->m_clipPaintRegion
)
2327 m_paintClippingRegion
= win
->GetUpdateRegion();
2328 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2331 m_paintClippingRegion
= win
->GetUpdateRegion();
2332 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2335 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2337 gdk_gc_set_clip_region( m_penGC
, region
);
2338 gdk_gc_set_clip_region( m_brushGC
, region
);
2339 gdk_gc_set_clip_region( m_textGC
, region
);
2340 gdk_gc_set_clip_region( m_bgGC
, region
);
2343 #endif // USE_PAINT_REGION
2346 //-----------------------------------------------------------------------------
2348 //-----------------------------------------------------------------------------
2350 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2352 wxClientDC::wxClientDC( wxWindow
*win
)
2355 wxCHECK_RET( win
, _T("NULL window in wxClientDC::wxClientDC") );
2357 #ifdef __WXUNIVERSAL__
2358 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2359 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2360 wxSize size
= win
->GetClientSize();
2361 SetClippingRegion(wxPoint(0, 0), size
);
2362 #endif // __WXUNIVERSAL__
2365 void wxClientDC::DoGetSize(int *width
, int *height
) const
2367 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2369 m_owner
->GetClientSize( width
, height
);
2372 // ----------------------------------------------------------------------------
2374 // ----------------------------------------------------------------------------
2376 class wxDCModule
: public wxModule
2383 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2386 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2388 bool wxDCModule::OnInit()
2394 void wxDCModule::OnExit()