]>
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, Markus Holzem, 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/gtk/win_gtk.h"
25 #include <math.h> // for floating-point functions
29 #include <gdk/gdkprivate.h>
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 #define USE_PAINT_REGION 1
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
50 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
51 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
54 static GdkPixmap
*hatches
[num_hatches
];
55 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
57 extern GtkWidget
*wxGetRootWindow();
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 const double RAD2DEG
= 180.0 / M_PI
;
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
70 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
72 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
74 //-----------------------------------------------------------------------------
75 // temporary implementation of the missing GDK function
76 //-----------------------------------------------------------------------------
78 #include "gdk/gdkprivate.h"
80 void gdk_wx_draw_bitmap(GdkDrawable
*drawable
,
90 gint src_width
, src_height
;
92 GdkWindowPrivate
*drawable_private
;
93 GdkWindowPrivate
*src_private
;
94 GdkGCPrivate
*gc_private
;
97 g_return_if_fail (drawable
!= NULL
);
98 g_return_if_fail (src
!= NULL
);
99 g_return_if_fail (gc
!= NULL
);
102 if (GDK_WINDOW_DESTROYED(drawable
) || GDK_WINDOW_DESTROYED(src
))
105 gdk_drawable_get_size(src
, &src_width
, &src_height
);
107 drawable_private
= (GdkWindowPrivate
*) drawable
;
108 src_private
= (GdkWindowPrivate
*) src
;
109 if (drawable_private
->destroyed
|| src_private
->destroyed
)
112 src_width
= src_private
->width
;
113 src_height
= src_private
->height
;
115 gc_private
= (GdkGCPrivate
*) gc
;
118 if (width
== -1) width
= src_width
;
119 if (height
== -1) height
= src_height
;
122 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable
),
124 GDK_WINDOW_XID(drawable
),
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 static wxGC wxGCPool
[GC_POOL_SIZE
];
174 static void wxInitGCPool()
176 memset( wxGCPool
, 0, GC_POOL_SIZE
*sizeof(wxGC
) );
179 static void wxCleanUpGCPool()
181 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
183 if (wxGCPool
[i
].m_gc
)
184 gdk_gc_unref( wxGCPool
[i
].m_gc
);
188 static GdkGC
* wxGetPoolGC( GdkWindow
*window
, wxPoolGCType type
)
190 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
192 if (!wxGCPool
[i
].m_gc
)
194 wxGCPool
[i
].m_gc
= gdk_gc_new( window
);
195 gdk_gc_set_exposures( wxGCPool
[i
].m_gc
, FALSE
);
196 wxGCPool
[i
].m_type
= type
;
197 wxGCPool
[i
].m_used
= FALSE
;
199 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
201 wxGCPool
[i
].m_used
= TRUE
;
202 return wxGCPool
[i
].m_gc
;
206 wxFAIL_MSG( wxT("No GC available") );
208 return (GdkGC
*) NULL
;
211 static void wxFreePoolGC( GdkGC
*gc
)
213 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
215 if (wxGCPool
[i
].m_gc
== gc
)
217 wxGCPool
[i
].m_used
= FALSE
;
222 wxFAIL_MSG( wxT("Wrong GC") );
225 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
229 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
231 wxWindowDC::wxWindowDC()
233 m_penGC
= (GdkGC
*) NULL
;
234 m_brushGC
= (GdkGC
*) NULL
;
235 m_textGC
= (GdkGC
*) NULL
;
236 m_bgGC
= (GdkGC
*) NULL
;
237 m_cmap
= (GdkColormap
*) NULL
;
239 m_isScreenDC
= FALSE
;
240 m_owner
= (wxWindow
*)NULL
;
242 m_context
= (PangoContext
*)NULL
;
243 m_fontdesc
= (PangoFontDescription
*)NULL
;
247 wxWindowDC::wxWindowDC( wxWindow
*window
)
249 wxASSERT_MSG( window
, wxT("DC needs a window") );
251 m_penGC
= (GdkGC
*) NULL
;
252 m_brushGC
= (GdkGC
*) NULL
;
253 m_textGC
= (GdkGC
*) NULL
;
254 m_bgGC
= (GdkGC
*) NULL
;
255 m_cmap
= (GdkColormap
*) NULL
;
256 m_owner
= (wxWindow
*)NULL
;
258 m_isScreenDC
= FALSE
;
259 m_font
= window
->GetFont();
261 GtkWidget
*widget
= window
->m_wxwindow
;
263 // some controls don't have m_wxwindow - like wxStaticBox, but the user
264 // code should still be able to create wxClientDCs for them, so we will
265 // use the parent window here then
268 window
= window
->GetParent();
269 widget
= window
->m_wxwindow
;
272 wxASSERT_MSG( widget
, wxT("DC needs a widget") );
275 m_context
= gtk_widget_get_pango_context( widget
);
276 m_fontdesc
= widget
->style
->font_desc
;
279 GtkPizza
*pizza
= GTK_PIZZA( widget
);
280 m_window
= pizza
->bin_window
;
285 /* don't report problems */
291 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
295 /* this must be done after SetUpDC, bacause SetUpDC calls the
296 repective SetBrush, SetPen, SetBackground etc functions
297 to set up the DC. SetBackground call m_owner->SetBackground
298 and this might not be desired as the standard dc background
299 is white whereas a window might assume gray to be the
300 standard (as e.g. wxStatusBar) */
305 wxWindowDC::~wxWindowDC()
310 void wxWindowDC::SetUpDC()
314 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
318 m_penGC
= wxGetPoolGC( m_window
, wxPEN_SCREEN
);
319 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_SCREEN
);
320 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_SCREEN
);
321 m_bgGC
= wxGetPoolGC( m_window
, wxBG_SCREEN
);
324 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
326 m_penGC
= wxGetPoolGC( m_window
, wxPEN_MONO
);
327 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_MONO
);
328 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_MONO
);
329 m_bgGC
= wxGetPoolGC( m_window
, wxBG_MONO
);
333 m_penGC
= wxGetPoolGC( m_window
, wxPEN_COLOUR
);
334 m_brushGC
= wxGetPoolGC( m_window
, wxBRUSH_COLOUR
);
335 m_textGC
= wxGetPoolGC( m_window
, wxTEXT_COLOUR
);
336 m_bgGC
= wxGetPoolGC( m_window
, wxBG_COLOUR
);
339 /* background colour */
340 m_backgroundBrush
= *wxWHITE_BRUSH
;
341 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
342 GdkColor
*bg_col
= m_backgroundBrush
.GetColour().GetColor();
345 m_textForegroundColour
.CalcPixel( m_cmap
);
346 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
348 m_textBackgroundColour
.CalcPixel( m_cmap
);
349 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
351 gdk_gc_set_fill( m_textGC
, GDK_SOLID
);
354 m_pen
.GetColour().CalcPixel( m_cmap
);
355 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
356 gdk_gc_set_background( m_penGC
, bg_col
);
358 gdk_gc_set_line_attributes( m_penGC
, 0, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
, GDK_JOIN_ROUND
);
361 m_brush
.GetColour().CalcPixel( m_cmap
);
362 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
363 gdk_gc_set_background( m_brushGC
, bg_col
);
365 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
368 gdk_gc_set_background( m_bgGC
, bg_col
);
369 gdk_gc_set_foreground( m_bgGC
, bg_col
);
371 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
374 gdk_gc_set_function( m_textGC
, GDK_COPY
);
375 gdk_gc_set_function( m_brushGC
, GDK_COPY
);
376 gdk_gc_set_function( m_penGC
, GDK_COPY
);
379 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
380 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
381 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
382 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
386 hatch_bitmap
= hatches
;
387 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
388 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
389 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
390 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
391 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
392 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
396 void wxWindowDC::DoGetSize( int* width
, int* height
) const
398 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
400 m_owner
->GetSize(width
, height
);
403 void wxWindowDC::DoFloodFill( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
404 const wxColour
&WXUNUSED(col
), int WXUNUSED(style
) )
406 wxFAIL_MSG( wxT("wxWindowDC::DoFloodFill not implemented") );
409 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
411 // Generic (and therefore rather inefficient) method.
412 // Could be improved.
414 wxBitmap
bitmap(1, 1);
415 memdc
.SelectObject(bitmap
);
416 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
417 memdc
.SelectObject(wxNullBitmap
);
419 wxImage image
= bitmap
.ConvertToImage();
420 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
424 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
426 wxCHECK_RET( Ok(), wxT("invalid window dc") );
428 if (m_pen
.GetStyle() != wxTRANSPARENT
)
431 gdk_draw_line( m_window
, m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
433 CalcBoundingBox(x1
, y1
);
434 CalcBoundingBox(x2
, y2
);
438 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
440 wxCHECK_RET( Ok(), wxT("invalid window dc") );
442 if (m_pen
.GetStyle() != wxTRANSPARENT
)
447 wxCoord xx
= XLOG2DEV(x
);
448 wxCoord yy
= YLOG2DEV(y
);
451 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
452 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
457 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
458 wxCoord xc
, wxCoord yc
)
460 wxCHECK_RET( Ok(), wxT("invalid window dc") );
462 wxCoord xx1
= XLOG2DEV(x1
);
463 wxCoord yy1
= YLOG2DEV(y1
);
464 wxCoord xx2
= XLOG2DEV(x2
);
465 wxCoord yy2
= YLOG2DEV(y2
);
466 wxCoord xxc
= XLOG2DEV(xc
);
467 wxCoord yyc
= YLOG2DEV(yc
);
468 double dx
= xx1
- xxc
;
469 double dy
= yy1
- yyc
;
470 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
471 wxCoord r
= (wxCoord
)radius
;
472 double radius1
, radius2
;
474 if (xx1
== xx2
&& yy1
== yy2
)
482 radius1
= radius2
= 0.0;
486 radius1
= (xx1
- xxc
== 0) ?
487 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
488 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
489 radius2
= (xx2
- xxc
== 0) ?
490 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
491 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
493 wxCoord alpha1
= wxCoord(radius1
* 64.0);
494 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
495 while (alpha2
<= 0) alpha2
+= 360*64;
496 while (alpha1
> 360*64) alpha1
-= 360*64;
500 if (m_brush
.GetStyle() != wxTRANSPARENT
)
502 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
504 gdk_gc_set_ts_origin( m_textGC
,
505 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
506 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
507 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
508 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
510 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
512 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
513 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
514 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
516 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
518 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
519 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
520 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
522 if (m_brush
.GetStyle() == wxSTIPPLE
)
524 gdk_gc_set_ts_origin( m_brushGC
,
525 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
526 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
527 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
528 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
532 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
536 if (m_pen
.GetStyle() != wxTRANSPARENT
)
538 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
540 gdk_draw_line( m_window
, m_penGC
, xx1
, yy1
, xxc
, yyc
);
541 gdk_draw_line( m_window
, m_penGC
, xxc
, yyc
, xx2
, yy2
);
545 CalcBoundingBox (x1
, y1
);
546 CalcBoundingBox (x2
, y2
);
549 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
551 wxCHECK_RET( Ok(), wxT("invalid window dc") );
553 wxCoord xx
= XLOG2DEV(x
);
554 wxCoord yy
= YLOG2DEV(y
);
555 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
556 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
558 // CMB: handle -ve width and/or height
559 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
560 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
564 wxCoord start
= wxCoord(sa
* 64.0);
565 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
567 if (m_brush
.GetStyle() != wxTRANSPARENT
)
569 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
571 gdk_gc_set_ts_origin( m_textGC
,
572 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
573 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
574 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
575 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
577 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
579 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
580 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
581 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
583 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
585 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
586 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
587 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
589 if (m_brush
.GetStyle() == wxSTIPPLE
)
591 gdk_gc_set_ts_origin( m_brushGC
,
592 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
593 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
594 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
595 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
599 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
603 if (m_pen
.GetStyle() != wxTRANSPARENT
)
604 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
607 CalcBoundingBox (x
, y
);
608 CalcBoundingBox (x
+ width
, y
+ height
);
611 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
613 wxCHECK_RET( Ok(), wxT("invalid window dc") );
615 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
616 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
618 CalcBoundingBox (x
, y
);
621 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
623 wxCHECK_RET( Ok(), wxT("invalid window dc") );
625 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
628 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
630 for (int i
= 0; i
< n
-1; i
++)
632 wxCoord x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
633 wxCoord x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
634 wxCoord y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
635 wxCoord y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
638 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
640 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
644 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
) )
646 wxCHECK_RET( Ok(), wxT("invalid window dc") );
650 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
652 for (i
= 0 ; i
< n
; i
++)
654 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
655 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
657 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
662 if (m_brush
.GetStyle() != wxTRANSPARENT
)
664 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
666 gdk_gc_set_ts_origin( m_textGC
,
667 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
668 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
669 gdk_draw_polygon( m_window
, m_textGC
, TRUE
, gdkpoints
, n
);
670 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
672 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
674 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
675 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
676 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
678 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
680 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
681 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
682 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
684 if (m_brush
.GetStyle() == wxSTIPPLE
)
686 gdk_gc_set_ts_origin( m_brushGC
,
687 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
688 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
689 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
690 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
694 gdk_draw_polygon( m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
698 if (m_pen
.GetStyle() != wxTRANSPARENT
)
700 for (i
= 0 ; i
< n
; i
++)
702 gdk_draw_line( m_window
, m_penGC
,
705 gdkpoints
[(i
+1)%n
].x
,
706 gdkpoints
[(i
+1)%n
].y
);
714 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
716 wxCHECK_RET( Ok(), wxT("invalid window dc") );
718 wxCoord xx
= XLOG2DEV(x
);
719 wxCoord yy
= YLOG2DEV(y
);
720 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
721 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
723 // CMB: draw nothing if transformed w or h is 0
724 if (ww
== 0 || hh
== 0) return;
726 // CMB: handle -ve width and/or height
727 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
728 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
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_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
);
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_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
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_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
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_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
760 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
764 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
768 if (m_pen
.GetStyle() != wxTRANSPARENT
)
769 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
772 CalcBoundingBox( x
, y
);
773 CalcBoundingBox( x
+ width
, y
+ height
);
776 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
778 wxCHECK_RET( Ok(), wxT("invalid window dc") );
780 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
782 wxCoord xx
= XLOG2DEV(x
);
783 wxCoord yy
= YLOG2DEV(y
);
784 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
785 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
786 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
788 // CMB: handle -ve width and/or height
789 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
790 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
792 // CMB: if radius is zero use DrawRectangle() instead to avoid
793 // X drawing errors with small radii
796 DrawRectangle( x
, y
, width
, height
);
800 // CMB: draw nothing if transformed w or h is 0
801 if (ww
== 0 || hh
== 0) return;
803 // CMB: adjust size if outline is drawn otherwise the result is
804 // 1 pixel too wide and high
805 if (m_pen
.GetStyle() != wxTRANSPARENT
)
813 // CMB: ensure dd is not larger than rectangle otherwise we
814 // get an hour glass shape
816 if (dd
> ww
) dd
= ww
;
817 if (dd
> hh
) dd
= hh
;
820 if (m_brush
.GetStyle() != wxTRANSPARENT
)
822 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
824 gdk_gc_set_ts_origin( m_textGC
,
825 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
826 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
827 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
828 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
829 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
830 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
831 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
832 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
833 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
835 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
837 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
838 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
839 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
840 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
841 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
842 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
843 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
844 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
846 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
848 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
849 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
850 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
851 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
852 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
853 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
854 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
855 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
857 if (m_brush
.GetStyle() == wxSTIPPLE
)
859 gdk_gc_set_ts_origin( m_brushGC
,
860 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
861 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
862 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
863 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
864 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
865 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
866 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
867 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
868 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
872 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
873 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
874 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
875 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
876 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
877 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
881 if (m_pen
.GetStyle() != wxTRANSPARENT
)
883 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
884 gdk_draw_line( m_window
, m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
885 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
886 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
887 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
888 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
889 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
890 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
894 // this ignores the radius
895 CalcBoundingBox( x
, y
);
896 CalcBoundingBox( x
+ width
, y
+ height
);
899 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
901 wxCHECK_RET( Ok(), wxT("invalid window dc") );
903 wxCoord xx
= XLOG2DEV(x
);
904 wxCoord yy
= YLOG2DEV(y
);
905 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
906 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
908 // CMB: handle -ve width and/or height
909 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
910 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
914 if (m_brush
.GetStyle() != wxTRANSPARENT
)
916 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
918 gdk_gc_set_ts_origin( m_textGC
,
919 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
920 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
921 gdk_draw_arc( m_window
, m_textGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
922 gdk_gc_set_ts_origin( m_textGC
, 0, 0 );
924 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
926 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
927 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
928 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
930 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
932 gdk_gc_set_ts_origin( m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
933 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
934 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
936 if (m_brush
.GetStyle() == wxSTIPPLE
)
938 gdk_gc_set_ts_origin( m_brushGC
,
939 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
940 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
941 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
942 gdk_gc_set_ts_origin( m_brushGC
, 0, 0 );
946 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
950 if (m_pen
.GetStyle() != wxTRANSPARENT
)
951 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
954 CalcBoundingBox( x
, y
);
955 CalcBoundingBox( x
+ width
, y
+ height
);
958 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
960 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
961 DoDrawBitmap( (const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
964 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
965 wxCoord x
, wxCoord y
,
968 wxCHECK_RET( Ok(), wxT("invalid window dc") );
970 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
972 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
974 /* scale/translate size and position */
975 int xx
= XLOG2DEV(x
);
976 int yy
= YLOG2DEV(y
);
978 int w
= bitmap
.GetWidth();
979 int h
= bitmap
.GetHeight();
981 CalcBoundingBox( x
, y
);
982 CalcBoundingBox( x
+ w
, y
+ h
);
984 if (!m_window
) return;
986 int ww
= XLOG2DEVREL(w
);
987 int hh
= YLOG2DEVREL(h
);
989 /* compare to current clipping region */
990 if (!m_currentClippingRegion
.IsNull())
992 wxRegion
tmp( xx
,yy
,ww
,hh
);
993 tmp
.Intersect( m_currentClippingRegion
);
998 /* scale bitmap if required */
1000 if ((w
!= ww
) || (h
!= hh
))
1002 wxImage image
= bitmap
.ConvertToImage();
1003 image
.Rescale( ww
, hh
);
1005 use_bitmap
= wxBitmap(image
.ConvertToMono(255,255,255), 1);
1007 use_bitmap
= wxBitmap(image
);
1011 use_bitmap
= bitmap
;
1018 /* apply mask if any */
1019 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1020 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1022 if (useMask
&& mask
)
1024 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1025 if (!m_currentClippingRegion
.IsNull())
1028 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1029 GdkGC
*gc
= gdk_gc_new( new_mask
);
1031 gdk_gc_set_foreground( gc
, &col
);
1032 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1034 gdk_gc_set_background( gc
, &col
);
1036 gdk_gc_set_foreground( gc
, &col
);
1037 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1038 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1039 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1040 gdk_gc_set_stipple( gc
, mask
);
1041 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1048 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1050 gdk_gc_set_clip_mask( m_textGC
, mask
);
1051 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1056 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1058 gdk_gc_set_clip_mask( m_penGC
, mask
);
1059 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1062 gdk_bitmap_unref( new_mask
);
1065 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1066 drawing a mono-bitmap (XBitmap) we use the current text GC */
1068 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), 0, 0, xx
, yy
, -1, -1 );
1070 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1072 /* remove mask again if any */
1073 if (useMask
&& mask
)
1077 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1078 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1079 if (!m_currentClippingRegion
.IsNull())
1080 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1084 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1085 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1086 if (!m_currentClippingRegion
.IsNull())
1087 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1092 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1093 wxCoord width
, wxCoord height
,
1095 wxCoord xsrc
, wxCoord ysrc
,
1098 wxCoord xsrcMask
, wxCoord ysrcMask
)
1100 /* this is the nth try to get this utterly useless function to
1101 work. it now completely ignores the scaling or translation
1102 of the source dc, but scales correctly on the target dc and
1103 knows about possible mask information in a memory dc. */
1105 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid window dc") );
1107 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1109 if (!m_window
) return FALSE
;
1112 // transform the source DC coords to the device ones
1113 xsrc
= source
->XLOG2DEV(xsrc
);
1114 ysrc
= source
->YLOG2DEV(ysrc
);
1117 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1118 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1120 bool use_bitmap_method
= FALSE
;
1121 bool is_mono
= FALSE
;
1123 /* TODO: use the mask origin when drawing transparently */
1124 if (xsrcMask
== -1 && ysrcMask
== -1)
1126 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1129 if (srcDC
->m_isMemDC
)
1131 if (!memDC
->m_selected
.Ok()) return FALSE
;
1133 /* we use the "XCopyArea" way to copy a memory dc into
1134 y different window if the memory dc BOTH
1135 a) doesn't have any mask or its mask isn't used
1139 if (useMask
&& (memDC
->m_selected
.GetMask()))
1141 /* we HAVE TO use the direct way for memory dcs
1142 that have mask since the XCopyArea doesn't know
1144 use_bitmap_method
= TRUE
;
1146 else if (memDC
->m_selected
.GetDepth() == 1)
1148 /* we HAVE TO use the direct way for memory dcs
1149 that are bitmaps because XCopyArea doesn't cope
1150 with different bit depths */
1152 use_bitmap_method
= TRUE
;
1154 else if ((xsrc
== 0) && (ysrc
== 0) &&
1155 (width
== memDC
->m_selected
.GetWidth()) &&
1156 (height
== memDC
->m_selected
.GetHeight()))
1158 /* we SHOULD use the direct way if all of the bitmap
1159 in the memory dc is copied in which case XCopyArea
1160 wouldn't be able able to boost performace by reducing
1161 the area to be scaled */
1162 use_bitmap_method
= TRUE
;
1166 use_bitmap_method
= FALSE
;
1170 CalcBoundingBox( xdest
, ydest
);
1171 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1173 /* scale/translate size and position */
1174 wxCoord xx
= XLOG2DEV(xdest
);
1175 wxCoord yy
= YLOG2DEV(ydest
);
1177 wxCoord ww
= XLOG2DEVREL(width
);
1178 wxCoord hh
= YLOG2DEVREL(height
);
1180 /* compare to current clipping region */
1181 if (!m_currentClippingRegion
.IsNull())
1183 wxRegion
tmp( xx
,yy
,ww
,hh
);
1184 tmp
.Intersect( m_currentClippingRegion
);
1189 int old_logical_func
= m_logicalFunction
;
1190 SetLogicalFunction( logical_func
);
1192 if (use_bitmap_method
)
1194 /* scale/translate bitmap size */
1195 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1196 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1198 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1199 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1201 /* scale bitmap if required */
1202 wxBitmap use_bitmap
;
1204 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1206 wxImage image
= memDC
->m_selected
.ConvertToImage();
1207 image
= image
.Scale( bm_ww
, bm_hh
);
1210 use_bitmap
= wxBitmap(image
.ConvertToMono(255,255,255), 1);
1212 use_bitmap
= wxBitmap(image
);
1216 use_bitmap
= memDC
->m_selected
;
1219 /* apply mask if any */
1220 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1221 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1223 if (useMask
&& mask
)
1225 GdkBitmap
*new_mask
= (GdkBitmap
*) NULL
;
1226 if (!m_currentClippingRegion
.IsNull())
1229 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1230 GdkGC
*gc
= gdk_gc_new( new_mask
);
1232 gdk_gc_set_foreground( gc
, &col
);
1233 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1235 gdk_gc_set_background( gc
, &col
);
1237 gdk_gc_set_foreground( gc
, &col
);
1238 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1239 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1240 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1241 gdk_gc_set_stipple( gc
, mask
);
1242 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1249 gdk_gc_set_clip_mask( m_textGC
, new_mask
);
1251 gdk_gc_set_clip_mask( m_textGC
, mask
);
1252 gdk_gc_set_clip_origin( m_textGC
, xx
, yy
);
1257 gdk_gc_set_clip_mask( m_penGC
, new_mask
);
1259 gdk_gc_set_clip_mask( m_penGC
, mask
);
1260 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
1263 gdk_bitmap_unref( new_mask
);
1266 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1267 drawing a mono-bitmap (XBitmap) we use the current text GC */
1270 gdk_wx_draw_bitmap( m_window
, m_textGC
, use_bitmap
.GetBitmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1272 gdk_draw_pixmap( m_window
, m_penGC
, use_bitmap
.GetPixmap(), xsrc
, ysrc
, xx
, yy
, ww
, hh
);
1274 /* remove mask again if any */
1275 if (useMask
&& mask
)
1279 gdk_gc_set_clip_mask( m_textGC
, (GdkBitmap
*) NULL
);
1280 gdk_gc_set_clip_origin( m_textGC
, 0, 0 );
1281 if (!m_currentClippingRegion
.IsNull())
1282 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1286 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
1287 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
1288 if (!m_currentClippingRegion
.IsNull())
1289 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1293 else /* use_bitmap_method */
1295 if ((width
!= ww
) || (height
!= hh
))
1297 /* draw source window into a bitmap as we cannot scale
1298 a window in contrast to a bitmap. this would actually
1299 work with memory dcs as well, but we'd lose the mask
1300 information and waste one step in this process since
1301 a memory already has a bitmap. all this is slightly
1302 inefficient as we could take an XImage directly from
1303 an X window, but we'd then also have to care that
1304 the window is not outside the screen (in which case
1305 we'd get a BadMatch or what not).
1306 Is a double XGetImage and combined XGetPixel and
1307 XPutPixel really faster? I'm not sure. look at wxXt
1308 for a different implementation of the same problem. */
1310 wxBitmap
bitmap( width
, height
);
1312 /* copy including child window contents */
1313 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1314 gdk_window_copy_area( bitmap
.GetPixmap(), m_penGC
, 0, 0,
1316 xsrc
, ysrc
, width
, height
);
1317 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1320 wxImage image
= bitmap
.ConvertToImage();
1321 image
= image
.Scale( ww
, hh
);
1323 /* convert to bitmap */
1324 bitmap
= wxBitmap(image
);
1326 /* draw scaled bitmap */
1327 gdk_draw_pixmap( m_window
, m_penGC
, bitmap
.GetPixmap(), 0, 0, xx
, yy
, -1, -1 );
1332 /* No scaling and not a memory dc with a mask either */
1334 /* copy including child window contents */
1335 gdk_gc_set_subwindow( m_penGC
, GDK_INCLUDE_INFERIORS
);
1336 gdk_window_copy_area( m_window
, m_penGC
, xx
, yy
,
1338 xsrc
, ysrc
, width
, height
);
1339 gdk_gc_set_subwindow( m_penGC
, GDK_CLIP_BY_CHILDREN
);
1343 SetLogicalFunction( old_logical_func
);
1347 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1349 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1351 if (!m_window
) return;
1353 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1355 wxCHECK_RET( font
, wxT("invalid font") );
1357 #if defined(__WXGTK20__)
1358 wxCHECK_RET( m_context
, wxT("no Pango context") );
1364 #if defined(__WXGTK20__) && wxUSE_WCHAR_T
1365 // TODO: the layout engine should be abstracted at a higher level!
1366 PangoLayout
*layout
= pango_layout_new(m_context
);
1367 pango_layout_set_font_description(layout
, m_fontdesc
);
1369 const wxWX2MBbuf data
= text
.mb_str(wxConvUTF8
);
1370 pango_layout_set_text(layout
, data
, strlen(data
));
1372 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1373 PangoRectangle rect
;
1374 pango_layout_line_get_extents(line
, NULL
, &rect
);
1375 wxCoord width
= rect
.width
;
1376 wxCoord height
= rect
.height
;
1377 gdk_draw_layout( m_window
, m_textGC
, x
, y
, layout
);
1379 wxCoord width
= gdk_string_width( font
, text
.mbc_str() );
1380 wxCoord height
= font
->ascent
+ font
->descent
;
1382 if ( m_backgroundMode
== wxSOLID
)
1384 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
1385 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
1386 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1388 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
.mbc_str() );
1389 #endif // GTK+ 2.0/1.x
1391 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1392 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1393 properties (see wxXt implementation) */
1394 if (m_font
.GetUnderlined())
1396 wxCoord ul_y
= y
+ font
->ascent
;
1397 if (font
->descent
> 0) ul_y
++;
1398 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1401 #if defined(__WXGTK20__) && wxUSE_WCHAR_T
1402 g_object_unref( G_OBJECT( layout
) );
1405 width
= wxCoord(width
/ m_scaleX
);
1406 height
= wxCoord(height
/ m_scaleY
);
1407 CalcBoundingBox (x
+ width
, y
+ height
);
1408 CalcBoundingBox (x
, y
);
1411 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1415 DrawText(text
, x
, y
);
1419 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1421 if (!m_window
) return;
1423 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1425 wxCHECK_RET( font
, wxT("invalid font") );
1427 // the size of the text
1428 wxCoord w
= gdk_string_width( font
, text
.mbc_str() );
1429 wxCoord h
= font
->ascent
+ font
->descent
;
1431 // draw the string normally
1434 dc
.SelectObject(src
);
1435 dc
.SetFont(GetFont());
1436 dc
.SetBackground(*wxWHITE_BRUSH
);
1437 dc
.SetBrush(*wxBLACK_BRUSH
);
1439 dc
.DrawText(text
, 0, 0);
1440 dc
.SelectObject(wxNullBitmap
);
1442 // Calculate the size of the rotated bounding box.
1443 double rad
= DegToRad(angle
);
1444 double dx
= cos(rad
),
1447 // the rectngle vertices are counted clockwise with the first one being at
1448 // (0, 0) (or, rather, at (x, y))
1450 y2
= -w
*dy
; // y axis points to the bottom, hence minus
1453 double x3
= x4
+ x2
,
1457 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5),
1458 maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5),
1459 minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5),
1460 minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1462 // prepare to blit-with-rotate the bitmap to the DC
1463 wxImage image
= src
.ConvertToImage();
1465 GdkColor
*colText
= m_textForegroundColour
.GetColor(),
1466 *colBack
= m_textBackgroundColour
.GetColor();
1468 bool textColSet
= TRUE
;
1470 unsigned char *data
= image
.GetData();
1472 // paint pixel by pixel
1473 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1475 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1477 // transform source coords to dest coords
1478 double r
= sqrt((double)srcX
*srcX
+ srcY
*srcY
);
1479 double angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1480 wxCoord dstX
= (wxCoord
)(r
*cos(angleOrig
) + 0.5),
1481 dstY
= (wxCoord
)(r
*sin(angleOrig
) + 0.5);
1484 bool textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1485 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1487 // change colour if needed
1488 if ( textPixel
!= textColSet
)
1490 gdk_gc_set_foreground( m_textGC
, textPixel
? colText
1493 textColSet
= textPixel
;
1496 // don't use DrawPoint() because it uses the current pen
1497 // colour, and we don't need it here
1498 gdk_draw_point( m_window
, m_textGC
,
1499 XLOG2DEV(x
+ dstX
), YLOG2DEV(y
+ dstY
) );
1504 // it would be better to draw with non underlined font and draw the line
1505 // manually here (it would be more straight...)
1507 if ( m_font
.GetUnderlined() )
1509 gdk_draw_line( m_window
, m_textGC
,
1510 XLOG2DEV(x
+ x4
), YLOG2DEV(y
+ y4
+ font
->descent
),
1511 XLOG2DEV(x
+ x3
), YLOG2DEV(y
+ y3
+ font
->descent
));
1515 // restore the font colour
1516 gdk_gc_set_foreground( m_textGC
, colText
);
1518 // update the bounding box
1519 CalcBoundingBox(x
+ minX
, y
+ minY
);
1520 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1523 void wxWindowDC::DoGetTextExtent(const wxString
&string
,
1524 wxCoord
*width
, wxCoord
*height
,
1525 wxCoord
*descent
, wxCoord
*externalLeading
,
1526 wxFont
*theFont
) const
1528 wxFont fontToUse
= m_font
;
1529 if (theFont
) fontToUse
= *theFont
;
1531 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
1532 if (width
) (*width
) = wxCoord(gdk_string_width( font
, string
.mbc_str() ) / m_scaleX
);
1533 if (height
) (*height
) = wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1534 if (descent
) (*descent
) = wxCoord(font
->descent
/ m_scaleY
);
1535 if (externalLeading
) (*externalLeading
) = 0; // ??
1538 wxCoord
wxWindowDC::GetCharWidth() const
1540 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1541 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1543 return wxCoord(gdk_string_width( font
, "H" ) / m_scaleX
);
1546 wxCoord
wxWindowDC::GetCharHeight() const
1548 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
1549 wxCHECK_MSG( font
, -1, wxT("invalid font") );
1551 return wxCoord((font
->ascent
+ font
->descent
) / m_scaleY
);
1554 void wxWindowDC::Clear()
1556 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1558 if (!m_window
) return;
1560 /* - we either are a memory dc or have a window as the
1561 owner. anything else shouldn't happen.
1562 - we don't use gdk_window_clear() as we don't set
1563 the window's background colour anymore. it is too
1564 much pain to keep the DC's and the window's back-
1565 ground colour in synch. */
1570 m_owner
->GetSize( &width
, &height
);
1571 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1578 GetSize( &width
, &height
);
1579 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
1584 void wxWindowDC::SetFont( const wxFont
&font
)
1586 wxCHECK_RET( font
.Ok(), _T("invalid font in wxWindowDC::SetFont") );
1594 void wxWindowDC::SetPen( const wxPen
&pen
)
1596 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1598 if (m_pen
== pen
) return;
1602 if (!m_pen
.Ok()) return;
1604 if (!m_window
) return;
1606 gint width
= m_pen
.GetWidth();
1609 // CMB: if width is non-zero scale it with the dc
1614 // X doesn't allow different width in x and y and so we take
1617 ( fabs((double) XLOG2DEVREL(width
)) +
1618 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1622 static const wxGTKDash dotted
[] = {1, 1};
1623 static const wxGTKDash short_dashed
[] = {2, 2};
1624 static const wxGTKDash wxCoord_dashed
[] = {2, 4};
1625 static const wxGTKDash dotted_dashed
[] = {3, 3, 1, 3};
1627 // We express dash pattern in pen width unit, so we are
1628 // independent of zoom factor and so on...
1630 const wxGTKDash
*req_dash
;
1632 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
1633 switch (m_pen
.GetStyle())
1637 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1638 req_nb_dash
= m_pen
.GetDashCount();
1639 req_dash
= (wxGTKDash
*)m_pen
.GetDash();
1644 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1651 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1653 req_dash
= wxCoord_dashed
;
1658 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1660 req_dash
= short_dashed
;
1665 // lineStyle = GDK_LINE_DOUBLE_DASH;
1666 lineStyle
= GDK_LINE_ON_OFF_DASH
;
1668 req_dash
= dotted_dashed
;
1673 case wxSTIPPLE_MASK_OPAQUE
:
1678 lineStyle
= GDK_LINE_SOLID
;
1679 req_dash
= (wxGTKDash
*)NULL
;
1685 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
1686 if (req_dash
&& req_nb_dash
)
1688 wxGTKDash
*real_req_dash
= new wxGTKDash
[req_nb_dash
];
1691 for (int i
= 0; i
< req_nb_dash
; i
++)
1692 real_req_dash
[i
] = req_dash
[i
] * width
;
1693 gdk_gc_set_dashes( m_penGC
, 0, real_req_dash
, req_nb_dash
);
1694 delete[] real_req_dash
;
1698 // No Memory. We use non-scaled dash pattern...
1699 gdk_gc_set_dashes( m_penGC
, 0, (wxGTKDash
*)req_dash
, req_nb_dash
);
1704 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
1705 switch (m_pen
.GetCap())
1707 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
1708 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
1715 capStyle
= GDK_CAP_NOT_LAST
;
1719 capStyle
= GDK_CAP_ROUND
;
1725 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
1726 switch (m_pen
.GetJoin())
1728 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
1729 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
1731 default: { joinStyle
= GDK_JOIN_ROUND
; break; }
1734 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1736 m_pen
.GetColour().CalcPixel( m_cmap
);
1737 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
1740 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1742 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1744 if (m_brush
== brush
) return;
1748 if (!m_brush
.Ok()) return;
1750 if (!m_window
) return;
1752 m_brush
.GetColour().CalcPixel( m_cmap
);
1753 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
1755 gdk_gc_set_fill( m_brushGC
, GDK_SOLID
);
1757 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1759 if (m_brush
.GetStipple()->GetPixmap())
1761 gdk_gc_set_fill( m_brushGC
, GDK_TILED
);
1762 gdk_gc_set_tile( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
1766 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1767 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetBitmap() );
1771 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1773 gdk_gc_set_fill( m_textGC
, GDK_OPAQUE_STIPPLED
);
1774 gdk_gc_set_stipple( m_textGC
, m_brush
.GetStipple()->GetMask()->GetBitmap() );
1777 if (IS_HATCH(m_brush
.GetStyle()))
1779 gdk_gc_set_fill( m_brushGC
, GDK_STIPPLED
);
1780 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1781 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
1785 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1787 /* CMB 21/7/98: Added SetBackground. Sets background brush
1788 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1790 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1792 if (m_backgroundBrush
== brush
) return;
1794 m_backgroundBrush
= brush
;
1796 if (!m_backgroundBrush
.Ok()) return;
1798 if (!m_window
) return;
1800 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1801 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
1802 gdk_gc_set_background( m_penGC
, m_backgroundBrush
.GetColour().GetColor() );
1803 gdk_gc_set_background( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1804 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
1806 gdk_gc_set_fill( m_bgGC
, GDK_SOLID
);
1808 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
1810 if (m_backgroundBrush
.GetStipple()->GetPixmap())
1812 gdk_gc_set_fill( m_bgGC
, GDK_TILED
);
1813 gdk_gc_set_tile( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
1817 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1818 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetBitmap() );
1822 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
1824 gdk_gc_set_fill( m_bgGC
, GDK_STIPPLED
);
1825 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
1826 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
1830 void wxWindowDC::SetLogicalFunction( int function
)
1832 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1834 if (m_logicalFunction
== function
)
1837 // VZ: shouldn't this be a CHECK?
1841 GdkFunction mode
= GDK_COPY
;
1844 case wxXOR
: mode
= GDK_XOR
; break;
1845 case wxINVERT
: mode
= GDK_INVERT
; break;
1846 #if (GTK_MINOR_VERSION > 0)
1847 case wxOR_REVERSE
: mode
= GDK_OR_REVERSE
; break;
1848 case wxAND_REVERSE
: mode
= GDK_AND_REVERSE
; break;
1849 case wxCLEAR
: mode
= GDK_CLEAR
; break;
1850 case wxSET
: mode
= GDK_SET
; break;
1851 case wxOR_INVERT
: mode
= GDK_OR_INVERT
; break;
1852 case wxAND
: mode
= GDK_AND
; break;
1853 case wxOR
: mode
= GDK_OR
; break;
1854 case wxEQUIV
: mode
= GDK_EQUIV
; break;
1855 case wxNAND
: mode
= GDK_NAND
; break;
1856 case wxAND_INVERT
: mode
= GDK_AND_INVERT
; break;
1857 case wxCOPY
: mode
= GDK_COPY
; break;
1858 case wxNO_OP
: mode
= GDK_NOOP
; break;
1859 case wxSRC_INVERT
: mode
= GDK_COPY_INVERT
; break;
1861 // unsupported by GTK
1862 case wxNOR
: mode
= GDK_COPY
; break;
1866 wxFAIL_MSG( wxT("unsupported logical function") );
1871 m_logicalFunction
= function
;
1873 gdk_gc_set_function( m_penGC
, mode
);
1874 gdk_gc_set_function( m_brushGC
, mode
);
1876 // to stay compatible with wxMSW, we don't apply ROPs to the text
1877 // operations (i.e. DrawText/DrawRotatedText).
1878 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1879 gdk_gc_set_function( m_textGC
, mode
);
1882 void wxWindowDC::SetTextForeground( const wxColour
&col
)
1884 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1886 // don't set m_textForegroundColour to an invalid colour as we'd crash
1887 // later then (we use m_textForegroundColour.GetColor() without checking
1889 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
1892 m_textForegroundColour
= col
;
1896 m_textForegroundColour
.CalcPixel( m_cmap
);
1897 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
1901 void wxWindowDC::SetTextBackground( const wxColour
&col
)
1903 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1906 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
1909 m_textBackgroundColour
= col
;
1913 m_textBackgroundColour
.CalcPixel( m_cmap
);
1914 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
1918 void wxWindowDC::SetBackgroundMode( int mode
)
1920 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1922 m_backgroundMode
= mode
;
1924 if (!m_window
) return;
1926 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
1927 // transparent/solid background mode
1929 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
1931 gdk_gc_set_fill( m_brushGC
,
1932 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
1936 void wxWindowDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
1938 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
1941 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1943 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1945 if (!m_window
) return;
1948 rect
.x
= XLOG2DEV(x
);
1949 rect
.y
= YLOG2DEV(y
);
1950 rect
.width
= XLOG2DEVREL(width
);
1951 rect
.height
= YLOG2DEVREL(height
);
1953 if (!m_currentClippingRegion
.IsNull())
1954 m_currentClippingRegion
.Intersect( rect
);
1956 m_currentClippingRegion
.Union( rect
);
1958 #if USE_PAINT_REGION
1959 if (!m_paintClippingRegion
.IsNull())
1960 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1963 wxCoord xx
, yy
, ww
, hh
;
1964 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1965 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1967 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
1968 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
1969 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
1970 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
1973 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1975 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1979 DestroyClippingRegion();
1983 if (!m_window
) return;
1985 if (!m_currentClippingRegion
.IsNull())
1986 m_currentClippingRegion
.Intersect( region
);
1988 m_currentClippingRegion
.Union( region
);
1990 #if USE_PAINT_REGION
1991 if (!m_paintClippingRegion
.IsNull())
1992 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1995 wxCoord xx
, yy
, ww
, hh
;
1996 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1997 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1999 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2000 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2001 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2002 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2005 void wxWindowDC::DestroyClippingRegion()
2007 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2009 wxDC::DestroyClippingRegion();
2011 m_currentClippingRegion
.Clear();
2013 #if USE_PAINT_REGION
2014 if (!m_paintClippingRegion
.IsEmpty())
2015 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2018 if (!m_window
) return;
2020 if (m_currentClippingRegion
.IsEmpty())
2022 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
2023 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
2024 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
2025 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
2029 gdk_gc_set_clip_region( m_penGC
, m_currentClippingRegion
.GetRegion() );
2030 gdk_gc_set_clip_region( m_brushGC
, m_currentClippingRegion
.GetRegion() );
2031 gdk_gc_set_clip_region( m_textGC
, m_currentClippingRegion
.GetRegion() );
2032 gdk_gc_set_clip_region( m_bgGC
, m_currentClippingRegion
.GetRegion() );
2036 void wxWindowDC::Destroy()
2038 if (m_penGC
) wxFreePoolGC( m_penGC
);
2039 m_penGC
= (GdkGC
*) NULL
;
2040 if (m_brushGC
) wxFreePoolGC( m_brushGC
);
2041 m_brushGC
= (GdkGC
*) NULL
;
2042 if (m_textGC
) wxFreePoolGC( m_textGC
);
2043 m_textGC
= (GdkGC
*) NULL
;
2044 if (m_bgGC
) wxFreePoolGC( m_bgGC
);
2045 m_bgGC
= (GdkGC
*) NULL
;
2048 void wxWindowDC::ComputeScaleAndOrigin()
2050 /* CMB: copy scale to see if it changes */
2051 double origScaleX
= m_scaleX
;
2052 double origScaleY
= m_scaleY
;
2054 wxDC::ComputeScaleAndOrigin();
2056 /* CMB: if scale has changed call SetPen to recalulate the line width */
2057 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
2060 /* this is a bit artificial, but we need to force wxDC to think
2061 the pen has changed */
2068 // Resolution in pixels per logical inch
2069 wxSize
wxWindowDC::GetPPI() const
2071 return wxSize( (int) (m_mm_to_pix_x
* 25.4 + 0.5), (int) (m_mm_to_pix_y
* 25.4 + 0.5));
2074 int wxWindowDC::GetDepth() const
2076 wxFAIL_MSG(wxT("not implemented"));
2082 //-----------------------------------------------------------------------------
2084 //-----------------------------------------------------------------------------
2086 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2088 wxPaintDC::wxPaintDC( wxWindow
*win
)
2091 #if USE_PAINT_REGION
2092 if (!win
->m_clipPaintRegion
)
2095 m_paintClippingRegion
= win
->GetUpdateRegion();
2096 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2099 m_paintClippingRegion
= win
->GetUpdateRegion();
2100 GdkRegion
*region
= m_paintClippingRegion
.GetRegion();
2103 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2105 gdk_gc_set_clip_region( m_penGC
, region
);
2106 gdk_gc_set_clip_region( m_brushGC
, region
);
2107 gdk_gc_set_clip_region( m_textGC
, region
);
2108 gdk_gc_set_clip_region( m_bgGC
, region
);
2111 #endif // USE_PAINT_REGION
2114 //-----------------------------------------------------------------------------
2116 //-----------------------------------------------------------------------------
2118 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2120 wxClientDC::wxClientDC( wxWindow
*win
)
2123 wxCHECK_RET( win
, _T("NULL window in wxClientDC::wxClientDC") );
2125 #ifdef __WXUNIVERSAL__
2126 wxPoint ptOrigin
= win
->GetClientAreaOrigin();
2127 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2128 wxSize size
= win
->GetClientSize();
2129 SetClippingRegion(wxPoint(0, 0), size
);
2130 #endif // __WXUNIVERSAL__
2133 void wxClientDC::DoGetSize(int *width
, int *height
) const
2135 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2137 m_owner
->GetClientSize( width
, height
);
2140 // ----------------------------------------------------------------------------
2142 // ----------------------------------------------------------------------------
2144 class wxDCModule
: public wxModule
2151 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2154 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2156 bool wxDCModule::OnInit()
2162 void wxDCModule::OnExit()