]>
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 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dcclient.h"
15 #define XCopyPlane XCOPYPLANE
18 #include "wx/dcclient.h"
19 #include "wx/dcmemory.h"
21 #include "wx/module.h"
23 #include "wx/fontutil.h"
25 #include "wx/gtk/win_gtk.h"
27 #include <math.h> // for floating-point functions
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 gint src_width
, src_height
;
94 GdkWindowPrivate
*drawable_private
;
95 GdkWindowPrivate
*src_private
;
96 GdkGCPrivate
*gc_private
;
99 g_return_if_fail (drawable
!= NULL
);
100 g_return_if_fail (src
!= NULL
);
101 g_return_if_fail (gc
!= NULL
);
104 if (GDK_WINDOW_DESTROYED(drawable
) || GDK_WINDOW_DESTROYED(src
))
107 gdk_drawable_get_size(src
, &src_width
, &src_height
);
109 drawable_private
= (GdkWindowPrivate
*) drawable
;
110 src_private
= (GdkWindowPrivate
*) src
;
111 if (drawable_private
->destroyed
|| src_private
->destroyed
)
114 src_width
= src_private
->width
;
115 src_height
= src_private
->height
;
117 gc_private
= (GdkGCPrivate
*) gc
;
120 if (width
== -1) width
= src_width
;
121 if (height
== -1) height
= src_height
;
124 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
126 GDK_WINDOW_XID(drawable
),
133 XCopyPlane( drawable_private
->xdisplay
,
134 src_private
->xwindow
,
135 drawable_private
->xwindow
,
144 //-----------------------------------------------------------------------------
145 // Implement Pool of Graphic contexts. Creating them takes too much time.
146 //-----------------------------------------------------------------------------
148 #define GC_POOL_SIZE 200
174 #define GC_POOL_ALLOC_SIZE 100
176 static int wxGCPoolSize
= 0;
178 static wxGC
*wxGCPool
= NULL
;
180 static void wxInitGCPool()
182 // This really could wait until the first call to
183 // wxGetPoolGC, but we will make the first allocation
184 // now when other initialization is being performed.
186 // Set initial pool size.
187 wxGCPoolSize
= GC_POOL_ALLOC_SIZE
;
189 // Allocate initial pool.
190 wxGCPool
= (wxGC
*)malloc(wxGCPoolSize
* sizeof(wxGC
));
191 if (wxGCPool
== NULL
)
193 // If we cannot malloc, then fail with error
194 // when debug is enabled. If debug is not enabled,
195 // the problem will eventually get caught
197 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
201 // Zero initial pool.
202 memset(wxGCPool
, 0, wxGCPoolSize
* sizeof(wxGC
));
205 static void wxCleanUpGCPool()
207 for (int i
= 0; i
< wxGCPoolSize
; i
++)
209 if (wxGCPool
[i
].m_gc
)
210 gdk_gc_unref( wxGCPool
[i
].m_gc
);
218 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
222 // Look for an available GC.
223 for (int i
= 0; i
< wxGCPoolSize
; i
++)
225 if (!wxGCPool
[i
].m_gc
)
227 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
228 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
229 wxGCPool
[i
].m_type
= type
;
230 wxGCPool
[i
].m_used
= FALSE
;
232 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
234 wxGCPool
[i
].m_used
= TRUE
;
235 return wxGCPool
[i
].m_gc
;
239 // We did not find an available GC.
240 // We need to grow the GC pool.
241 pptr
= (wxGC
*)realloc(wxGCPool
,
242 (wxGCPoolSize
+ GC_POOL_ALLOC_SIZE
)*sizeof(wxGC
));
245 // Initialize newly allocated pool.
247 memset(&wxGCPool
[wxGCPoolSize
], 0,
248 GC_POOL_ALLOC_SIZE
*sizeof(wxGC
));
250 // Initialize entry we will return.
251 wxGCPool
[wxGCPoolSize
].m_gc
= gdk_gc_new( window
);
252 gdk_gc_set_exposures( wxGCPool
[wxGCPoolSize
].m_gc
, FALSE
);
253 wxGCPool
[wxGCPoolSize
].m_type
= type
;
254 wxGCPool
[wxGCPoolSize
].m_used
= TRUE
;
256 // Set new value of pool size.
257 wxGCPoolSize
+= GC_POOL_ALLOC_SIZE
;
259 // Return newly allocated entry.
260 return wxGCPool
[wxGCPoolSize
-GC_POOL_ALLOC_SIZE
].m_gc
;
263 // The realloc failed. Fall through to error.
264 wxFAIL_MSG( wxT("No GC available") );
266 return (GdkGC
*) NULL
;
269 static void wxFreePoolGC( GdkGC
*gc
)
271 for (int i
= 0; i
< wxGCPoolSize
; i
++)
273 if (wxGCPool
[i
].m_gc
== gc
)
275 wxGCPool
[i
].m_used
= FALSE
;
280 wxFAIL_MSG( wxT("Wrong GC") );
283 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
287 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
289 wxWindowDC::wxWindowDC()
291 m_penGC
= (GdkGC
*) NULL
;
292 m_brushGC
= (GdkGC
*) NULL
;
293 m_textGC
= (GdkGC
*) NULL
;
294 m_bgGC
= (GdkGC
*) NULL
;
295 m_cmap
= (GdkColormap
*) NULL
;
297 m_isScreenDC
= FALSE
;
298 m_owner
= (wxWindow
*)NULL
;
300 m_context
= (PangoContext
*)NULL
;
301 m_layout
= (PangoLayout
*)NULL
;
302 m_fontdesc
= (PangoFontDescription
*)NULL
;
306 wxWindowDC::wxWindowDC( wxWindow
*window
)
308 wxASSERT_MSG( window
, wxT("DC needs a window") );
310 m_penGC
= (GdkGC
*) NULL
;
311 m_brushGC
= (GdkGC
*) NULL
;
312 m_textGC
= (GdkGC
*) NULL
;
313 m_bgGC
= (GdkGC
*) NULL
;
314 m_cmap
= (GdkColormap
*) NULL
;
315 m_owner
= (wxWindow
*)NULL
;
317 m_isScreenDC
= FALSE
;
318 m_font
= window
->GetFont();
320 GtkWidget
*widget
= window
->m_wxwindow
;
322 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
323 // code should still be able to create wxClientDCs for them, so we will
324 // use the parent window here then.
327 window
= window
->GetParent();
328 widget
= window
->m_wxwindow
;
331 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
334 m_context
= window
->GtkGetPangoDefaultContext();
335 m_layout
= pango_layout_new( m_context
);
336 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
339 GtkPizza
*pizza
= GTK_PIZZA( widget
);
340 m_window
= pizza
->bin_window
;
342 // Window not realized ?
345 // Don't report problems as per MSW.
351 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
355 /* this must be done after SetUpDC, bacause SetUpDC calls the
356 repective SetBrush, SetPen, SetBackground etc functions
357 to set up the DC. SetBackground call m_owner->SetBackground
358 and this might not be desired as the standard dc background
359 is white whereas a window might assume gray to be the
360 standard (as e.g. wxStatusBar) */
365 wxWindowDC::~wxWindowDC()
371 g_object_unref( G_OBJECT( m_layout
) );
373 pango_font_description_free( m_fontdesc
);
377 void wxWindowDC::SetUpDC()
381 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
385 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
386 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
387 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
388 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
391 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
393 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
394 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
395 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
396 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
400 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
401 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
402 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
403 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
406 /* background colour */
407 m_backgroundBrush
= *wxWHITE_BRUSH
;
408 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
409 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
412 m_textForegroundColour
.CalcPixel( m_cmap
);
413 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
415 m_textBackgroundColour
.CalcPixel( m_cmap
);
416 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
418 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
421 m_pen
.GetColour().CalcPixel( m_cmap
);
422 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
423 gdk_gc_set_background( m_penGC
, bg_col
);
425 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
428 m_brush
.GetColour().CalcPixel( m_cmap
);
429 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
430 gdk_gc_set_background( m_brushGC
, bg_col
);
432 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
435 gdk_gc_set_background( m_bgGC
, bg_col
);
436 gdk_gc_set_foreground( m_bgGC
, bg_col
);
438 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
441 gdk_gc_set_function( m_textGC
, GDK_COPY
);
442 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
443 gdk_gc_set_function( m_penGC
, GDK_COPY
);
446 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
447 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
448 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
449 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
453 hatch_bitmap
= hatches
;
454 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
455 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
456 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
457 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
458 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
459 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
463 void wxWindowDC::DoGetSize( int* width
, int* height
) const
465 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
467 m_owner
->GetSize(width
, height
);
470 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
471 const wxColour
& col
, int style
);
473 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
474 const wxColour
& col
, int style
)
476 return wxDoFloodFill(this, x
, y
, col
, style
);
479 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
481 // Generic (and therefore rather inefficient) method.
482 // Could be improved.
484 wxBitmap
bitmap(1, 1);
485 memdc
.SelectObject(bitmap
);
486 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
487 memdc
.SelectObject(wxNullBitmap
);
489 wxImage image
= bitmap
.ConvertToImage();
490 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
494 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
496 wxCHECK_RET( Ok(), wxT("invalid window dc") );
498 if (m_pen
.GetStyle() != wxTRANSPARENT
)
501 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
503 CalcBoundingBox(x1
, y1
);
504 CalcBoundingBox(x2
, y2
);
508 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
510 wxCHECK_RET( Ok(), wxT("invalid window dc") );
512 if (m_pen
.GetStyle() != wxTRANSPARENT
)
517 wxCoord xx
= XLOG2DEV(x
);
518 wxCoord yy
= YLOG2DEV(y
);
521 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
522 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
527 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
528 wxCoord xc
, wxCoord yc
)
530 wxCHECK_RET( Ok(), wxT("invalid window dc") );
532 wxCoord xx1
= XLOG2DEV(x1
);
533 wxCoord yy1
= YLOG2DEV(y1
);
534 wxCoord xx2
= XLOG2DEV(x2
);
535 wxCoord yy2
= YLOG2DEV(y2
);
536 wxCoord xxc
= XLOG2DEV(xc
);
537 wxCoord yyc
= YLOG2DEV(yc
);
538 double dx
= xx1
- xxc
;
539 double dy
= yy1
- yyc
;
540 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
541 wxCoord r
= (wxCoord
)radius
;
542 double radius1
, radius2
;
544 if (xx1
== xx2
&& yy1
== yy2
)
552 radius1
= radius2
= 0.0;
556 radius1
= (xx1
- xxc
== 0) ?
557 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
558 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
559 radius2
= (xx2
- xxc
== 0) ?
560 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
561 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
563 wxCoord alpha1
= wxCoord(radius1
* 64.0);
564 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
565 while (alpha2
<= 0) alpha2
+= 360*64;
566 while (alpha1
> 360*64) alpha1
-= 360*64;
570 if (m_brush
.GetStyle() != wxTRANSPARENT
)
572 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
574 gdk_gc_set_ts_origin( m_textGC
,
575 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
576 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
577 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
578 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
580 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
582 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
583 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
584 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
586 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
588 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
589 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
590 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
592 if (m_brush
.GetStyle() == wxSTIPPLE
)
594 gdk_gc_set_ts_origin( m_brushGC
,
595 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
596 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
597 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
598 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
602 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
606 if (m_pen
.GetStyle() != wxTRANSPARENT
)
608 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
610 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
611 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
615 CalcBoundingBox (x1
, y1
);
616 CalcBoundingBox (x2
, y2
);
619 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
621 wxCHECK_RET( Ok(), wxT("invalid window dc") );
623 wxCoord xx
= XLOG2DEV(x
);
624 wxCoord yy
= YLOG2DEV(y
);
625 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
626 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
628 // CMB: handle -ve width and/or height
629 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
630 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
634 wxCoord start
= wxCoord(sa
* 64.0);
635 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
637 if (m_brush
.GetStyle() != wxTRANSPARENT
)
639 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
641 gdk_gc_set_ts_origin( m_textGC
,
642 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
643 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
644 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
645 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
647 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
649 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
650 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
651 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
653 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
655 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
656 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
657 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
659 if (m_brush
.GetStyle() == wxSTIPPLE
)
661 gdk_gc_set_ts_origin( m_brushGC
,
662 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
663 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
664 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
665 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
669 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
673 if (m_pen
.GetStyle() != wxTRANSPARENT
)
674 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
677 CalcBoundingBox (x
, y
);
678 CalcBoundingBox (x
+ width
, y
+ height
);
681 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
683 wxCHECK_RET( Ok(), wxT("invalid window dc") );
685 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
686 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
688 CalcBoundingBox (x
, y
);
691 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
693 wxCHECK_RET( Ok(), wxT("invalid window dc") );
695 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
698 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
700 for (int i
= 0; i
< n
-1; i
++)
702 wxCoord x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
703 wxCoord x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
704 wxCoord y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
705 wxCoord y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
708 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
710 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
714 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
716 wxCHECK_RET( Ok(), wxT("invalid window dc") );
720 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
722 for (i
= 0 ; i
< n
; i
++)
724 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
725 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
727 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
732 if (m_brush
.GetStyle() != wxTRANSPARENT
)
734 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
736 gdk_gc_set_ts_origin( m_textGC
,
737 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
738 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
739 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
740 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
742 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
744 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
745 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
746 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
748 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
750 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
751 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
752 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
754 if (m_brush
.GetStyle() == wxSTIPPLE
)
756 gdk_gc_set_ts_origin( m_brushGC
,
757 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
758 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
759 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
760 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
764 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
768 if (m_pen
.GetStyle() != wxTRANSPARENT
)
770 for (i
= 0 ; i
< n
; i
++)
772 gdk_draw_line( m_window
, m_penGC
,
775 gdkpoints
[(i
+1)%n
].x
,
776 gdkpoints
[(i
+1)%n
].y
);
784 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
786 wxCHECK_RET( Ok(), wxT("invalid window dc") );
788 wxCoord xx
= XLOG2DEV(x
);
789 wxCoord yy
= YLOG2DEV(y
);
790 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
791 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
793 // CMB: draw nothing if transformed w or h is 0
794 if (ww
== 0 || hh
== 0) return;
796 // CMB: handle -ve width and/or height
797 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
798 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
802 if (m_brush
.GetStyle() != wxTRANSPARENT
)
804 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
806 gdk_gc_set_ts_origin( m_textGC
,
807 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
808 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
809 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
810 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
812 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
814 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
815 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
816 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
818 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
820 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
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 (m_brush
.GetStyle() == wxSTIPPLE
)
826 gdk_gc_set_ts_origin( m_brushGC
,
827 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
828 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
829 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
830 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
834 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
838 if (m_pen
.GetStyle() != wxTRANSPARENT
)
839 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
842 CalcBoundingBox( x
, y
);
843 CalcBoundingBox( x
+ width
, y
+ height
);
846 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
848 wxCHECK_RET( Ok(), wxT("invalid window dc") );
850 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
852 wxCoord xx
= XLOG2DEV(x
);
853 wxCoord yy
= YLOG2DEV(y
);
854 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
855 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
856 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
858 // CMB: handle -ve width and/or height
859 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
860 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
862 // CMB: if radius is zero use DrawRectangle() instead to avoid
863 // X drawing errors with small radii
866 DrawRectangle( x
, y
, width
, height
);
870 // CMB: draw nothing if transformed w or h is 0
871 if (ww
== 0 || hh
== 0) return;
873 // CMB: adjust size if outline is drawn otherwise the result is
874 // 1 pixel too wide and high
875 if (m_pen
.GetStyle() != wxTRANSPARENT
)
883 // CMB: ensure dd is not larger than rectangle otherwise we
884 // get an hour glass shape
886 if (dd
> ww
) dd
= ww
;
887 if (dd
> hh
) dd
= hh
;
890 if (m_brush
.GetStyle() != wxTRANSPARENT
)
892 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
894 gdk_gc_set_ts_origin( m_textGC
,
895 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
896 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
897 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
898 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
899 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
900 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
901 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
902 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
903 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
905 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
907 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
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 );
914 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
916 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
918 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
919 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
920 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
921 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
922 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
923 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
924 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
925 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
927 if (m_brush
.GetStyle() == wxSTIPPLE
)
929 gdk_gc_set_ts_origin( m_brushGC
,
930 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
931 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
932 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
933 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
934 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
935 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
936 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
937 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
938 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
942 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
943 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
944 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
945 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
946 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
947 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
951 if (m_pen
.GetStyle() != wxTRANSPARENT
)
953 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
954 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
955 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
956 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
957 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
958 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
959 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
960 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
964 // this ignores the radius
965 CalcBoundingBox( x
, y
);
966 CalcBoundingBox( x
+ width
, y
+ height
);
969 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
971 wxCHECK_RET( Ok(), wxT("invalid window dc") );
973 wxCoord xx
= XLOG2DEV(x
);
974 wxCoord yy
= YLOG2DEV(y
);
975 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
976 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
978 // CMB: handle -ve width and/or height
979 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
980 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
984 if (m_brush
.GetStyle() != wxTRANSPARENT
)
986 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
988 gdk_gc_set_ts_origin( m_textGC
,
989 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
990 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
991 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
992 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
994 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
996 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
997 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
998 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1000 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
1002 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
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 (m_brush
.GetStyle() == wxSTIPPLE
)
1008 gdk_gc_set_ts_origin( m_brushGC
,
1009 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
1010 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
1011 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1012 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
1016 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1020 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1021 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
1024 CalcBoundingBox( x
, y
);
1025 CalcBoundingBox( x
+ width
, y
+ height
);
1028 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1030 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1031 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
1034 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1035 wxCoord x
, wxCoord y
,
1038 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1040 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1042 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1044 /* scale/translate size and position */
1045 int xx
= XLOG2DEV(x
);
1046 int yy
= YLOG2DEV(y
);
1048 int w
= bitmap
.GetWidth();
1049 int h
= bitmap
.GetHeight();
1051 CalcBoundingBox( x
, y
);
1052 CalcBoundingBox( x
+ w
, y
+ h
);
1054 if (!m_window
) return;
1056 int ww
= XLOG2DEVREL(w
);
1057 int hh
= YLOG2DEVREL(h
);
1059 /* compare to current clipping region */
1060 if (!m_currentClippingRegion
.IsNull())
1062 wxRegion
tmp( xx
,yy
,ww
,hh
);
1063 tmp
.Intersect( m_currentClippingRegion
);
1068 /* scale bitmap if required */
1069 wxBitmap use_bitmap
;
1070 if ((w
!= ww
) || (h
!= hh
))
1072 wxImage image
= bitmap
.ConvertToImage();
1073 image
.Rescale( ww
, hh
);
1075 use_bitmap
= wxBitmap(image
.ConvertToMono(255,255,255), 1);
1077 use_bitmap
= wxBitmap(image
);
1081 use_bitmap
= bitmap
;
1084 /* apply mask if any */
1085 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1086 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1088 if (useMask
&& mask
)
1090 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1091 #ifndef __WXGTK20__ // TODO fix crash
1092 if (!m_currentClippingRegion
.IsNull())
1095 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1096 GdkGC
*gc
= gdk_gc_new( new_mask
);
1098 gdk_gc_set_foreground( gc
, &col
);
1099 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1101 gdk_gc_set_background( gc
, &col
);
1103 gdk_gc_set_foreground( gc
, &col
);
1104 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1105 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1106 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1107 gdk_gc_set_stipple( gc
, mask
);
1108 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1115 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1117 gdk_gc_set_clip_mask( m_textGC
, mask
);
1118 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1123 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1125 gdk_gc_set_clip_mask( m_penGC
, mask
);
1126 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1130 gdk_bitmap_unref( new_mask
);
1133 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1134 drawing a mono-bitmap (XBitmap) we use the current text GC */
1136 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
1138 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1140 /* remove mask again if any */
1141 if (useMask
&& mask
)
1145 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1146 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1147 if (!m_currentClippingRegion
.IsNull())
1148 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1152 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1153 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1154 if (!m_currentClippingRegion
.IsNull())
1155 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1160 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1161 wxCoord width
, wxCoord height
,
1163 wxCoord xsrc
, wxCoord ysrc
,
1166 wxCoord xsrcMask
, wxCoord ysrcMask
)
1168 /* this is the nth try to get this utterly useless function to
1169 work. it now completely ignores the scaling or translation
1170 of the source dc, but scales correctly on the target dc and
1171 knows about possible mask information in a memory dc. */
1173 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid window dc") );
1175 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1177 if (!m_window
) return FALSE
;
1180 // transform the source DC coords to the device ones
1181 xsrc
= source
->XLOG2DEV(xsrc
);
1182 ysrc
= source
->YLOG2DEV(ysrc
);
1185 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1186 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1188 bool use_bitmap_method
= FALSE
;
1189 bool is_mono
= FALSE
;
1191 /* TODO: use the mask origin when drawing transparently */
1192 if (xsrcMask
== -1 && ysrcMask
== -1)
1194 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1197 if (srcDC
->m_isMemDC
)
1199 if (!memDC
->m_selected
.Ok()) return FALSE
;
1201 /* we use the "XCopyArea" way to copy a memory dc into
1202 y different window if the memory dc BOTH
1203 a) doesn't have any mask or its mask isn't used
1207 if (useMask
&& (memDC
->m_selected
.GetMask()))
1209 /* we HAVE TO use the direct way for memory dcs
1210 that have mask since the XCopyArea doesn't know
1212 use_bitmap_method
= TRUE
;
1214 else if (memDC
->m_selected
.GetDepth() == 1)
1216 /* we HAVE TO use the direct way for memory dcs
1217 that are bitmaps because XCopyArea doesn't cope
1218 with different bit depths */
1220 use_bitmap_method
= TRUE
;
1222 else if ((xsrc
== 0) && (ysrc
== 0) &&
1223 (width
== memDC
->m_selected
.GetWidth()) &&
1224 (height
== memDC
->m_selected
.GetHeight()))
1226 /* we SHOULD use the direct way if all of the bitmap
1227 in the memory dc is copied in which case XCopyArea
1228 wouldn't be able able to boost performace by reducing
1229 the area to be scaled */
1230 use_bitmap_method
= TRUE
;
1234 use_bitmap_method
= FALSE
;
1238 CalcBoundingBox( xdest
, ydest
);
1239 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1241 /* scale/translate size and position */
1242 wxCoord xx
= XLOG2DEV(xdest
);
1243 wxCoord yy
= YLOG2DEV(ydest
);
1245 wxCoord ww
= XLOG2DEVREL(width
);
1246 wxCoord hh
= YLOG2DEVREL(height
);
1248 /* compare to current clipping region */
1249 if (!m_currentClippingRegion
.IsNull())
1251 wxRegion
tmp( xx
,yy
,ww
,hh
);
1252 tmp
.Intersect( m_currentClippingRegion
);
1257 int old_logical_func
= m_logicalFunction
;
1258 SetLogicalFunction( logical_func
);
1260 if (use_bitmap_method
)
1262 /* scale/translate bitmap size */
1263 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1264 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1266 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1267 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1269 /* scale bitmap if required */
1270 wxBitmap use_bitmap
;
1272 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1274 wxImage image
= memDC
->m_selected
.ConvertToImage();
1275 image
= image
.Scale( bm_ww
, bm_hh
);
1278 use_bitmap
= wxBitmap(image
.ConvertToMono(255,255,255), 1);
1280 use_bitmap
= wxBitmap(image
);
1284 use_bitmap
= memDC
->m_selected
;
1287 /* apply mask if any */
1288 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1289 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1291 if (useMask
&& mask
)
1293 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1294 #ifndef __WXGTK20__ // TODO fix crash
1295 if (!m_currentClippingRegion
.IsNull())
1298 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1299 GdkGC
*gc
= gdk_gc_new( new_mask
);
1301 gdk_gc_set_foreground( gc
, &col
);
1302 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1304 gdk_gc_set_background( gc
, &col
);
1306 gdk_gc_set_foreground( gc
, &col
);
1307 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1308 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1309 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1310 gdk_gc_set_stipple( gc
, mask
);
1311 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1318 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1320 gdk_gc_set_clip_mask( m_textGC
, mask
);
1321 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1326 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1328 gdk_gc_set_clip_mask( m_penGC
, mask
);
1329 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1332 gdk_bitmap_unref( new_mask
);
1335 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1336 drawing a mono-bitmap (XBitmap) we use the current text GC */
1339 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1341 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1343 /* remove mask again if any */
1344 if (useMask
&& mask
)
1348 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1349 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1350 if (!m_currentClippingRegion
.IsNull())
1351 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1355 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1356 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1357 if (!m_currentClippingRegion
.IsNull())
1358 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1362 else /* use_bitmap_method */
1364 if ((width
!= ww
) || (height
!= hh
))
1366 /* draw source window into a bitmap as we cannot scale
1367 a window in contrast to a bitmap. this would actually
1368 work with memory dcs as well, but we'd lose the mask
1369 information and waste one step in this process since
1370 a memory already has a bitmap. all this is slightly
1371 inefficient as we could take an XImage directly from
1372 an X window, but we'd then also have to care that
1373 the window is not outside the screen (in which case
1374 we'd get a BadMatch or what not).
1375 Is a double XGetImage and combined XGetPixel and
1376 XPutPixel really faster? I'm not sure. look at wxXt
1377 for a different implementation of the same problem. */
1379 wxBitmap
bitmap( width
, height
);
1381 /* copy including child window contents */
1382 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1383 gdk_window_copy_area( bitmap
.GetPixmap(), m_penGC
, 0, 0,
1385 xsrc
, ysrc
, width
, height
);
1386 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1389 wxImage image
= bitmap
.ConvertToImage();
1390 image
= image
.Scale( ww
, hh
);
1392 /* convert to bitmap */
1393 bitmap
= wxBitmap(image
);
1395 /* draw scaled bitmap */
1396 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1401 /* No scaling and not a memory dc with a mask either */
1403 /* copy including child window contents */
1404 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1405 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1407 xsrc
, ysrc
, width
, height
);
1408 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1412 SetLogicalFunction( old_logical_func
);
1416 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1418 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1420 if (!m_window
) return;
1422 if (text
.empty()) return;
1425 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1427 wxCHECK_RET( font
, wxT("invalid font") );
1434 wxCHECK_RET( m_context
, wxT("no Pango context") );
1435 wxCHECK_RET( m_layout
, wxT("no Pango layout") );
1436 wxCHECK_RET( m_fontdesc
, wxT("no Pango font description") );
1439 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1441 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1442 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1444 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1446 if (m_scaleY
!= 1.0)
1448 // If there is a user or actually any scale applied to
1449 // the device context, scale the font.
1451 // scale font description
1452 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1453 double size
= oldSize
;
1454 size
= size
* m_scaleY
;
1455 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1457 // actually apply scaled font
1458 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1461 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1463 // reset unscaled size
1464 pango_font_description_set_size( m_fontdesc
, oldSize
);
1466 // actually apply unscaled font
1467 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1472 gdk_draw_layout( m_window
, m_textGC
, x
, y
, m_layout
);
1478 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1488 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1489 wxCoord height
= font
->ascent
+ font
->descent
;
1491 if ( m_backgroundMode
== wxSOLID
)
1493 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1494 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1495 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1497 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1499 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1500 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1501 properties (see wxXt implementation) */
1502 if (m_font
.GetUnderlined())
1504 wxCoord ul_y
= y
+ font
->ascent
;
1505 if (font
->descent
> 0) ul_y
++;
1506 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1508 #endif // GTK+ 2.0/1.x
1510 width
= wxCoord(width
/ m_scaleX
);
1511 height
= wxCoord(height
/ m_scaleY
);
1512 CalcBoundingBox (x
+ width
, y
+ height
);
1513 CalcBoundingBox (x
, y
);
1516 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1520 DrawText(text
, x
, y
);
1524 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1526 if (!m_window
) return;
1529 // implement later without GdkFont for GTK 2.0
1532 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1534 wxCHECK_RET( font
, wxT("invalid font") );
1536 // the size of the text
1537 wxCoord w
= gdk_string_width( font
, text
.mbc_str() );
1538 wxCoord h
= font
->ascent
+ font
->descent
;
1540 // draw the string normally
1543 dc
.SelectObject(src
);
1544 dc
.SetFont(GetFont());
1545 dc
.SetBackground(*wxWHITE_BRUSH
);
1546 dc
.SetBrush(*wxBLACK_BRUSH
);
1548 dc
.DrawText(text
, 0, 0);
1549 dc
.SelectObject(wxNullBitmap
);
1551 // Calculate the size of the rotated bounding box.
1552 double rad
= DegToRad(angle
);
1553 double dx
= cos(rad
),
1556 // the rectngle vertices are counted clockwise with the first one being at
1557 // (0, 0) (or, rather, at (x, y))
1559 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1562 double x3
= x4
+ x2
,
1566 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1567 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1568 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1569 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1571 // prepare to blit-with-rotate the bitmap to the DC
1572 wxImage image
= src
.ConvertToImage();
1574 GdkColor
*colText
= m_textForegroundColour
.GetColor(),
1575 *colBack
= m_textBackgroundColour
.GetColor();
1577 bool textColSet
= TRUE
;
1579 unsigned char *data
= image
.GetData();
1581 // paint pixel by pixel
1582 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1584 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1586 // transform source coords to dest coords
1587 double r
= sqrt((double)srcX
*srcX
+ srcY
*srcY
);
1588 double angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1589 wxCoord dstX
= (wxCoord
)(r
*cos(angleOrig
) + 0.5),
1590 dstY
= (wxCoord
)(r
*sin(angleOrig
) + 0.5);
1593 bool textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1594 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1596 // change colour if needed
1597 if ( textPixel
!= textColSet
)
1599 gdk_gc_set_foreground( m_textGC
, textPixel
? colText
1602 textColSet
= textPixel
;
1605 // don't use DrawPoint() because it uses the current pen
1606 // colour, and we don't need it here
1607 gdk_draw_point( m_window
, m_textGC
,
1608 XLOG2DEV(x
) + dstX
, YLOG2DEV(y
) + dstY
);
1613 // it would be better to draw with non underlined font and draw the line
1614 // manually here (it would be more straight...)
1616 if ( m_font
.GetUnderlined() )
1618 gdk_draw_line( m_window
, m_textGC
,
1619 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1620 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1624 // restore the font colour
1625 gdk_gc_set_foreground( m_textGC
, colText
);
1627 // update the bounding box
1628 CalcBoundingBox(x
+ minX
, y
+ minY
);
1629 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1633 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1634 wxCoord
*width
, wxCoord
*height
,
1635 wxCoord
*descent
, wxCoord
*externalLeading
,
1636 wxFont
*theFont
) const
1638 if (string
.IsEmpty())
1640 if (width
) (*width
) = 0;
1641 if (height
) (*height
) = 0;
1646 // Set new font description
1648 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1650 // Set layout's text
1652 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1653 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1655 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1656 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1657 pango_layout_set_text( m_layout
, (const char*) data
, strlen( (const char*) data
));
1661 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1663 if (width
) (*width
) = (wxCoord
) w
;
1664 if (height
) (*height
) = (wxCoord
) h
;
1667 // Do something about metrics here. TODO.
1670 if (externalLeading
) (*externalLeading
) = 0; // ??
1672 // Reset old font description
1674 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1676 wxFont fontToUse
= m_font
;
1677 if (theFont
) fontToUse
= *theFont
;
1679 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1680 if (width
) (*width
) = wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1681 if (height
) (*height
) = wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1682 if (descent
) (*descent
) = wxCoord(font
->descent
/ m_scaleY
);
1683 if (externalLeading
) (*externalLeading
) = 0; // ??
1687 wxCoord
wxWindowDC::GetCharWidth() const
1690 pango_layout_set_text( m_layout
, "H", 1 );
1692 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1695 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1696 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1698 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1702 wxCoord
wxWindowDC::GetCharHeight() const
1705 pango_layout_set_text( m_layout
, "H", 1 );
1707 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1710 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1711 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1713 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1717 void wxWindowDC::Clear()
1719 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1721 if (!m_window
) return;
1723 // VZ: the code below results in infinite recursion and crashes when
1724 // dc.Clear() is done from OnPaint() so I disable it for now.
1725 // I don't know what the correct fix is but Clear() surely should not
1726 // reenter OnPaint()!
1728 /* - we either are a memory dc or have a window as the
1729 owner. anything else shouldn't happen.
1730 - we don't use gdk_window_clear() as we don't set
1731 the window's background colour anymore. it is too
1732 much pain to keep the DC's and the window's back-
1733 ground colour in synch. */
1744 GetSize( &width
, &height
);
1745 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1750 GetSize( &width
, &height
);
1751 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1755 void wxWindowDC::SetFont( const wxFont
&font
)
1763 pango_font_description_free( m_fontdesc
);
1765 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1770 PangoContext
*oldContext
= m_context
;
1772 // We might want to use the X11 context for faster
1773 // rendering on screen
1774 if (m_font
.GetNoAntiAliasing())
1775 m_context
= m_owner
->GtkGetPangoX11Context();
1777 m_context
= m_owner
->GtkGetPangoDefaultContext();
1779 // If we switch back/forth between different contexts
1780 // we also have to create a new layout. I think so,
1781 // at least, and it doesn't hurt to do it.
1782 if (oldContext
!= m_context
)
1785 g_object_unref( G_OBJECT( m_layout
) );
1787 m_layout
= pango_layout_new( m_context
);
1791 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1796 void wxWindowDC::SetPen( const wxPen
&pen
)
1798 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1800 if (m_pen
== pen
) return;
1804 if (!m_pen
.Ok()) return;
1806 if (!m_window
) return;
1808 gint width
= m_pen
.GetWidth();
1811 // CMB: if width is non-zero scale it with the dc
1816 // X doesn't allow different width in x and y and so we take
1819 ( fabs((double) XLOG2DEVREL(width
)) +
1820 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1824 static const wxGTKDash dotted
[] = {1, 1};
1825 static const wxGTKDash short_dashed
[] = {2, 2};
1826 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1827 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1829 // We express dash pattern in pen width unit, so we are
1830 // independent of zoom factor and so on...
1832 const wxGTKDash
*req_dash
;
1834 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1835 switch (m_pen
.GetStyle())
1839 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1840 req_nb_dash
= m_pen
.GetDashCount();
1841 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1846 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1853 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1855 req_dash
= wxCoord_dashed
;
1860 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1862 req_dash
= short_dashed
;
1867 // lineStyle = GDK_LINE_DOUBLE_DASH;
1868 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1870 req_dash
= dotted_dashed
;
1875 case wxSTIPPLE_MASK_OPAQUE
:
1880 lineStyle
= GDK_LINE_SOLID
;
1881 req_dash
= (wxGTKDash
*)NULL
;
1887 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
1888 if (req_dash
&& req_nb_dash
)
1890 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1893 for (int i
= 0; i
< req_nb_dash
; i
++)
1894 real_req_dash
[i
] = req_dash
[i
] * width
;
1895 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1896 delete[] real_req_dash
;
1900 // No Memory. We use non-scaled dash pattern...
1901 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1904 #endif // GTK+ > 1.0
1906 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1907 switch (m_pen
.GetCap())
1909 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1910 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1917 capStyle
= GDK_CAP_NOT_LAST
;
1921 capStyle
= GDK_CAP_ROUND
;
1927 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1928 switch (m_pen
.GetJoin())
1930 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1931 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1933 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1936 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1938 m_pen
.GetColour().CalcPixel( m_cmap
);
1939 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1942 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1944 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1946 if (m_brush
== brush
) return;
1950 if (!m_brush
.Ok()) return;
1952 if (!m_window
) return;
1954 m_brush
.GetColour().CalcPixel( m_cmap
);
1955 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1957 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1959 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1961 if (m_brush
.GetStipple()->GetPixmap())
1963 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1964 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1968 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1969 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
1973 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1975 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1976 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1979 if (IS_HATCH(m_brush
.GetStyle()))
1981 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1982 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1983 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
1987 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1989 /* CMB 21/7/98: Added SetBackground. Sets background brush
1990 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1992 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1994 if (m_backgroundBrush
== brush
) return;
1996 m_backgroundBrush
= brush
;
1998 if (!m_backgroundBrush
.Ok()) return;
2000 if (!m_window
) return;
2002 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
2003 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
2004 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
2005 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2006 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
2008 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
2010 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
2012 if (m_backgroundBrush
.GetStipple()->GetPixmap())
2014 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
2015 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
2019 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2020 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
2024 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
2026 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
2027 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2028 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
2032 void wxWindowDC::SetLogicalFunction( int function
)
2034 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2036 if (m_logicalFunction
== function
)
2039 // VZ: shouldn't this be a CHECK?
2046 case wxXOR
: mode
= GDK_XOR
; break;
2047 case wxINVERT
: mode
= GDK_INVERT
; break;
2048 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
2049 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
2050 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
2051 case wxCLEAR
: mode
= GDK_CLEAR
; break;
2052 case wxSET
: mode
= GDK_SET
; break;
2053 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
2054 case wxAND
: mode
= GDK_AND
; break;
2055 case wxOR
: mode
= GDK_OR
; break;
2056 case wxEQUIV
: mode
= GDK_EQUIV
; break;
2057 case wxNAND
: mode
= GDK_NAND
; break;
2058 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
2059 case wxCOPY
: mode
= GDK_COPY
; break;
2060 case wxNO_OP
: mode
= GDK_NOOP
; break;
2061 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
2063 // unsupported by GTK
2064 case wxNOR
: mode
= GDK_COPY
; break;
2065 #endif // GTK+ > 1.0
2067 wxFAIL_MSG( wxT("unsupported logical function") );
2071 m_logicalFunction
= function
;
2073 gdk_gc_set_function( m_penGC
, mode
);
2074 gdk_gc_set_function( m_brushGC
, mode
);
2076 // to stay compatible with wxMSW, we don't apply ROPs to the text
2077 // operations (i.e. DrawText/DrawRotatedText).
2078 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2079 gdk_gc_set_function( m_textGC
, mode
);
2082 void wxWindowDC::SetTextForeground( const wxColour
&col
)
2084 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2086 // don't set m_textForegroundColour to an invalid colour as we'd crash
2087 // later then (we use m_textForegroundColour.GetColor() without checking
2089 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2092 m_textForegroundColour
= col
;
2096 m_textForegroundColour
.CalcPixel( m_cmap
);
2097 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
2101 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2103 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2106 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2109 m_textBackgroundColour
= col
;
2113 m_textBackgroundColour
.CalcPixel( m_cmap
);
2114 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
2118 void wxWindowDC::SetBackgroundMode( int mode
)
2120 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2122 m_backgroundMode
= mode
;
2124 if (!m_window
) return;
2126 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2127 // transparent/solid background mode
2129 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2131 gdk_gc_set_fill( m_brushGC
,
2132 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
2136 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
2138 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
2141 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2143 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2145 if (!m_window
) return;
2148 rect
.x
= XLOG2DEV(x
);
2149 rect
.y
= YLOG2DEV(y
);
2150 rect
.width
= XLOG2DEVREL(width
);
2151 rect
.height
= YLOG2DEVREL(height
);
2153 if (!m_currentClippingRegion
.IsNull())
2154 m_currentClippingRegion
.Intersect( rect
);
2156 m_currentClippingRegion
.Union( rect
);
2158 #if USE_PAINT_REGION
2159 if (!m_paintClippingRegion
.IsNull())
2160 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2163 wxCoord xx
, yy
, ww
, hh
;
2164 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2165 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2167 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2168 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2169 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2170 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2173 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
2175 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2179 DestroyClippingRegion();
2183 if (!m_window
) return;
2185 if (!m_currentClippingRegion
.IsNull())
2186 m_currentClippingRegion
.Intersect( region
);
2188 m_currentClippingRegion
.Union( region
);
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::DestroyClippingRegion()
2207 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2209 wxDC::DestroyClippingRegion();
2211 m_currentClippingRegion
.Clear();
2213 #if USE_PAINT_REGION
2214 if (!m_paintClippingRegion
.IsEmpty())
2215 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2218 if (!m_window
) return;
2220 if (m_currentClippingRegion
.IsEmpty())
2222 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2223 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2224 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2225 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2229 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2230 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2231 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2232 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2236 void wxWindowDC::Destroy()
2238 if (m_penGC
) wxFreePoolGC( m_penGC
);
2239 m_penGC
= (GdkGC
*) NULL
;
2240 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2241 m_brushGC
= (GdkGC
*) NULL
;
2242 if (m_textGC
) wxFreePoolGC( m_textGC
);
2243 m_textGC
= (GdkGC
*) NULL
;
2244 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2245 m_bgGC
= (GdkGC
*) NULL
;
2248 void wxWindowDC::ComputeScaleAndOrigin()
2250 /* CMB: copy scale to see if it changes */
2251 double origScaleX
= m_scaleX
;
2252 double origScaleY
= m_scaleY
;
2254 wxDC::ComputeScaleAndOrigin();
2256 /* CMB: if scale has changed call SetPen to recalulate the line width */
2257 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
2260 /* this is a bit artificial, but we need to force wxDC to think
2261 the pen has changed */
2268 // Resolution in pixels per logical inch
2269 wxSize
wxWindowDC::GetPPI() const
2271 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2274 int wxWindowDC::GetDepth() const
2276 wxFAIL_MSG(wxT("not implemented"));
2282 //-----------------------------------------------------------------------------
2284 //-----------------------------------------------------------------------------
2286 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2288 wxPaintDC::wxPaintDC( wxWindow
*win
)
2291 #if USE_PAINT_REGION
2292 if (!win
->m_clipPaintRegion
)
2295 m_paintClippingRegion
= win
->GetUpdateRegion();
2296 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2299 m_paintClippingRegion
= win
->GetUpdateRegion();
2300 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2303 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2305 gdk_gc_set_clip_region( m_penGC
, region
);
2306 gdk_gc_set_clip_region( m_brushGC
, region
);
2307 gdk_gc_set_clip_region( m_textGC
, region
);
2308 gdk_gc_set_clip_region( m_bgGC
, region
);
2311 #endif // USE_PAINT_REGION
2314 //-----------------------------------------------------------------------------
2316 //-----------------------------------------------------------------------------
2318 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2320 wxClientDC::wxClientDC( wxWindow
*win
)
2323 wxCHECK_RET( win
, _T("NULL window in wxClientDC::wxClientDC") );
2325 #ifdef __WXUNIVERSAL__
2326 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2327 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2328 wxSize size
= win
->GetClientSize();
2329 SetClippingRegion(wxPoint(0, 0), size
);
2330 #endif // __WXUNIVERSAL__
2333 void wxClientDC::DoGetSize(int *width
, int *height
) const
2335 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2337 m_owner
->GetClientSize( width
, height
);
2340 // ----------------------------------------------------------------------------
2342 // ----------------------------------------------------------------------------
2344 class wxDCModule
: public wxModule
2351 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2354 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2356 bool wxDCModule::OnInit()
2362 void wxDCModule::OnExit()