]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcclient.cpp
compile fix for Mac
[wxWidgets.git] / src / gtk / dcclient.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/gtk/dcclient.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
6c9a19aa 6// Copyright: (c) 1998 Robert Roebling, Chris Breeze
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
d02af7bb
JJ
13#ifdef __VMS
14#define XCopyPlane XCOPYPLANE
15#endif
16
c801d85f 17#include "wx/dcclient.h"
e4db172a
WS
18
19#ifndef WX_PRECOMP
772b3767 20 #include "wx/window.h"
e4db172a 21 #include "wx/log.h"
f38924e8 22 #include "wx/dcmemory.h"
18680f86 23 #include "wx/math.h" // for floating-point functions
155ecd4c 24 #include "wx/image.h"
02761f6c 25 #include "wx/module.h"
e4db172a
WS
26#endif
27
db16cab4 28#include "wx/fontutil.h"
e5131165 29
ed673c6a 30#include "wx/gtk/win_gtk.h"
a3669332 31#include "wx/gtk/private.h"
c801d85f 32
993f97ee 33#include <gdk/gdkx.h>
83624f79 34
809934d2
RR
35//-----------------------------------------------------------------------------
36// local defines
37//-----------------------------------------------------------------------------
38
e1208c31 39#define USE_PAINT_REGION 1
809934d2 40
c801d85f
KB
41//-----------------------------------------------------------------------------
42// local data
43//-----------------------------------------------------------------------------
44
45#include "bdiag.xbm"
46#include "fdiag.xbm"
47#include "cdiag.xbm"
48#include "horiz.xbm"
49#include "verti.xbm"
50#include "cross.xbm"
51#define num_hatches 6
52
3ca6a5f0
BP
53#define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
54#define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
55
56
c801d85f 57static GdkPixmap *hatches[num_hatches];
c67daf87 58static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL;
c801d85f 59
c2fa61e8 60extern GtkWidget *wxGetRootWindow();
3d2d8da1 61
c801d85f
KB
62//-----------------------------------------------------------------------------
63// constants
64//-----------------------------------------------------------------------------
65
95724b1a 66const double RAD2DEG = 180.0 / M_PI;
c801d85f 67
9a8c7620
VZ
68// ----------------------------------------------------------------------------
69// private functions
70// ----------------------------------------------------------------------------
71
72static inline double dmax(double a, double b) { return a > b ? a : b; }
73static inline double dmin(double a, double b) { return a < b ? a : b; }
74
75static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
76
6f65e337
JS
77//-----------------------------------------------------------------------------
78// temporary implementation of the missing GDK function
79//-----------------------------------------------------------------------------
b0e0d661 80
6f65e337 81#include "gdk/gdkprivate.h"
b0e0d661 82
9be3f755 83static
1e6feb95
VZ
84void gdk_wx_draw_bitmap(GdkDrawable *drawable,
85 GdkGC *gc,
86 GdkDrawable *src,
87 gint xsrc,
88 gint ysrc,
89 gint xdest,
90 gint ydest,
91 gint width,
92 gint height)
6f65e337 93{
17a1ebd1
VZ
94 wxCHECK_RET( drawable, _T("NULL drawable in gdk_wx_draw_bitmap") );
95 wxCHECK_RET( src, _T("NULL src in gdk_wx_draw_bitmap") );
96 wxCHECK_RET( gc, _T("NULL gc in gdk_wx_draw_bitmap") );
ab9d0a8c 97
d90c9596 98 gint src_width, src_height;
8943b403 99 gdk_drawable_get_size(src, &src_width, &src_height);
8943b403
OK
100 if (width == -1) width = src_width;
101 if (height == -1) height = src_height;
265898fd 102
8943b403
OK
103 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable),
104 GDK_WINDOW_XID(src),
105 GDK_WINDOW_XID(drawable),
106 GDK_GC_XGC(gc),
107 xsrc, ysrc,
108 width, height,
d90c9596 109 0, 0,
8943b403 110 1 );
6f65e337
JS
111}
112
3d2d8da1
RR
113//-----------------------------------------------------------------------------
114// Implement Pool of Graphic contexts. Creating them takes too much time.
115//-----------------------------------------------------------------------------
116
0e09f76e
RR
117enum wxPoolGCType
118{
119 wxGC_ERROR = 0,
120 wxTEXT_MONO,
121 wxBG_MONO,
122 wxPEN_MONO,
123 wxBRUSH_MONO,
124 wxTEXT_COLOUR,
125 wxBG_COLOUR,
126 wxPEN_COLOUR,
f6bcfd97
BP
127 wxBRUSH_COLOUR,
128 wxTEXT_SCREEN,
129 wxBG_SCREEN,
130 wxPEN_SCREEN,
131 wxBRUSH_SCREEN
0e09f76e
RR
132};
133
3d2d8da1
RR
134struct wxGC
135{
0e09f76e
RR
136 GdkGC *m_gc;
137 wxPoolGCType m_type;
138 bool m_used;
3d2d8da1
RR
139};
140
696f36b7
JS
141#define GC_POOL_ALLOC_SIZE 100
142
143static int wxGCPoolSize = 0;
144
145static wxGC *wxGCPool = NULL;
3d2d8da1
RR
146
147static void wxInitGCPool()
148{
696f36b7
JS
149 // This really could wait until the first call to
150 // wxGetPoolGC, but we will make the first allocation
151 // now when other initialization is being performed.
ab9d0a8c 152
696f36b7
JS
153 // Set initial pool size.
154 wxGCPoolSize = GC_POOL_ALLOC_SIZE;
ab9d0a8c 155
696f36b7
JS
156 // Allocate initial pool.
157 wxGCPool = (wxGC *)malloc(wxGCPoolSize * sizeof(wxGC));
158 if (wxGCPool == NULL)
159 {
160 // If we cannot malloc, then fail with error
161 // when debug is enabled. If debug is not enabled,
162 // the problem will eventually get caught
551b5391 163 // in wxGetPoolGC.
696f36b7
JS
164 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
165 return;
166 }
ab9d0a8c 167
696f36b7
JS
168 // Zero initial pool.
169 memset(wxGCPool, 0, wxGCPoolSize * sizeof(wxGC));
3d2d8da1
RR
170}
171
172static void wxCleanUpGCPool()
173{
f6116855 174 for (int i = 0; i < wxGCPoolSize; i++)
3d2d8da1
RR
175 {
176 if (wxGCPool[i].m_gc)
3fe39b0c 177 g_object_unref (wxGCPool[i].m_gc);
3d2d8da1 178 }
696f36b7
JS
179
180 free(wxGCPool);
181 wxGCPool = NULL;
182 wxGCPoolSize = 0;
3d2d8da1
RR
183}
184
0e09f76e 185static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type )
3d2d8da1 186{
696f36b7 187 wxGC *pptr;
ab9d0a8c 188
696f36b7
JS
189 // Look for an available GC.
190 for (int i = 0; i < wxGCPoolSize; i++)
3d2d8da1
RR
191 {
192 if (!wxGCPool[i].m_gc)
193 {
194 wxGCPool[i].m_gc = gdk_gc_new( window );
195 gdk_gc_set_exposures( wxGCPool[i].m_gc, FALSE );
0e09f76e 196 wxGCPool[i].m_type = type;
ab9d0a8c 197 wxGCPool[i].m_used = false;
3d2d8da1 198 }
0e09f76e 199 if ((!wxGCPool[i].m_used) && (wxGCPool[i].m_type == type))
3d2d8da1 200 {
ab9d0a8c 201 wxGCPool[i].m_used = true;
3d2d8da1
RR
202 return wxGCPool[i].m_gc;
203 }
204 }
5f170f33 205
696f36b7
JS
206 // We did not find an available GC.
207 // We need to grow the GC pool.
208 pptr = (wxGC *)realloc(wxGCPool,
551b5391 209 (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC));
696f36b7
JS
210 if (pptr != NULL)
211 {
212 // Initialize newly allocated pool.
213 wxGCPool = pptr;
551b5391
RR
214 memset(&wxGCPool[wxGCPoolSize], 0,
215 GC_POOL_ALLOC_SIZE*sizeof(wxGC));
ab9d0a8c
WS
216
217 // Initialize entry we will return.
696f36b7
JS
218 wxGCPool[wxGCPoolSize].m_gc = gdk_gc_new( window );
219 gdk_gc_set_exposures( wxGCPool[wxGCPoolSize].m_gc, FALSE );
220 wxGCPool[wxGCPoolSize].m_type = type;
ab9d0a8c
WS
221 wxGCPool[wxGCPoolSize].m_used = true;
222
696f36b7
JS
223 // Set new value of pool size.
224 wxGCPoolSize += GC_POOL_ALLOC_SIZE;
ab9d0a8c 225
696f36b7
JS
226 // Return newly allocated entry.
227 return wxGCPool[wxGCPoolSize-GC_POOL_ALLOC_SIZE].m_gc;
228 }
ab9d0a8c 229
696f36b7 230 // The realloc failed. Fall through to error.
3d2d8da1 231 wxFAIL_MSG( wxT("No GC available") );
5f170f33 232
3d2d8da1
RR
233 return (GdkGC*) NULL;
234}
235
236static void wxFreePoolGC( GdkGC *gc )
237{
696f36b7 238 for (int i = 0; i < wxGCPoolSize; i++)
3d2d8da1
RR
239 {
240 if (wxGCPool[i].m_gc == gc)
241 {
ab9d0a8c 242 wxGCPool[i].m_used = false;
3d2d8da1
RR
243 return;
244 }
245 }
5f170f33 246
3d2d8da1
RR
247 wxFAIL_MSG( wxT("Wrong GC") );
248}
249
c801d85f 250//-----------------------------------------------------------------------------
ec758a20 251// wxWindowDC
c801d85f
KB
252//-----------------------------------------------------------------------------
253
b0e0d661 254IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
c801d85f 255
4bc67cc5 256wxWindowDC::wxWindowDC()
c801d85f 257{
265898fd
RR
258 m_penGC = (GdkGC *) NULL;
259 m_brushGC = (GdkGC *) NULL;
260 m_textGC = (GdkGC *) NULL;
261 m_bgGC = (GdkGC *) NULL;
262 m_cmap = (GdkColormap *) NULL;
ab9d0a8c
WS
263 m_isMemDC = false;
264 m_isScreenDC = false;
bbbbe360 265 m_owner = (wxWindow *)NULL;
8943b403 266 m_context = (PangoContext *)NULL;
cfcc3932 267 m_layout = (PangoLayout *)NULL;
8943b403 268 m_fontdesc = (PangoFontDescription *)NULL;
903f689b 269}
c801d85f 270
ec758a20 271wxWindowDC::wxWindowDC( wxWindow *window )
c801d85f 272{
3cd0b8c5
RR
273 wxASSERT_MSG( window, wxT("DC needs a window") );
274
265898fd
RR
275 m_penGC = (GdkGC *) NULL;
276 m_brushGC = (GdkGC *) NULL;
277 m_textGC = (GdkGC *) NULL;
278 m_bgGC = (GdkGC *) NULL;
279 m_cmap = (GdkColormap *) NULL;
bbbbe360 280 m_owner = (wxWindow *)NULL;
ab9d0a8c
WS
281 m_isMemDC = false;
282 m_isScreenDC = false;
3b245d60 283 m_font = window->GetFont();
7d5af6fa 284
a2053b27 285 GtkWidget *widget = window->m_wxwindow;
7d5af6fa 286
cfcc3932 287 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
b7f1f77f 288 // code should still be able to create wxClientDCs for them, so we will
cfcc3932 289 // use the parent window here then.
b7f1f77f
VZ
290 if ( !widget )
291 {
292 window = window->GetParent();
293 widget = window->m_wxwindow;
294 }
295
223d09f6 296 wxASSERT_MSG( widget, wxT("DC needs a widget") );
7d5af6fa 297
2b5f62a0 298 m_context = window->GtkGetPangoDefaultContext();
cfcc3932
RR
299 m_layout = pango_layout_new( m_context );
300 m_fontdesc = pango_font_description_copy( widget->style->font_desc );
8943b403 301
da048e3d
RR
302 GtkPizza *pizza = GTK_PIZZA( widget );
303 m_window = pizza->bin_window;
7d5af6fa 304
cfcc3932 305 // Window not realized ?
1e133b7d
RR
306 if (!m_window)
307 {
cfcc3932 308 // Don't report problems as per MSW.
ab9d0a8c 309 m_ok = true;
7d5af6fa
VZ
310
311 return;
1e133b7d 312 }
7d5af6fa 313
b7f1f77f 314 m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
7d5af6fa 315
265898fd 316 SetUpDC();
bbbbe360
RR
317
318 /* this must be done after SetUpDC, bacause SetUpDC calls the
319 repective SetBrush, SetPen, SetBackground etc functions
320 to set up the DC. SetBackground call m_owner->SetBackground
321 and this might not be desired as the standard dc background
322 is white whereas a window might assume gray to be the
323 standard (as e.g. wxStatusBar) */
7d5af6fa 324
bbbbe360 325 m_owner = window;
847dfdb4
RR
326
327 if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
328 {
329 m_signX = -1;
330 gint width;
331 gdk_window_get_geometry( GTK_PIZZA(m_owner->m_wxwindow)->bin_window,
332 NULL, NULL, &width, NULL, NULL );
333 m_deviceOriginX = width;;
334 }
903f689b 335}
c801d85f 336
4bc67cc5 337wxWindowDC::~wxWindowDC()
c801d85f 338{
265898fd 339 Destroy();
ab9d0a8c 340
cfcc3932 341 if (m_layout)
3fe39b0c 342 g_object_unref (m_layout);
cfcc3932
RR
343 if (m_fontdesc)
344 pango_font_description_free( m_fontdesc );
903f689b 345}
c801d85f 346
809934d2
RR
347void wxWindowDC::SetUpDC()
348{
ab9d0a8c 349 m_ok = true;
5f170f33 350
809934d2 351 wxASSERT_MSG( !m_penGC, wxT("GCs already created") );
5f170f33 352
f6bcfd97
BP
353 if (m_isScreenDC)
354 {
355 m_penGC = wxGetPoolGC( m_window, wxPEN_SCREEN );
356 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_SCREEN );
357 m_textGC = wxGetPoolGC( m_window, wxTEXT_SCREEN );
358 m_bgGC = wxGetPoolGC( m_window, wxBG_SCREEN );
359 }
360 else
809934d2
RR
361 if (m_isMemDC && (((wxMemoryDC*)this)->m_selected.GetDepth() == 1))
362 {
363 m_penGC = wxGetPoolGC( m_window, wxPEN_MONO );
364 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_MONO );
365 m_textGC = wxGetPoolGC( m_window, wxTEXT_MONO );
366 m_bgGC = wxGetPoolGC( m_window, wxBG_MONO );
367 }
368 else
369 {
370 m_penGC = wxGetPoolGC( m_window, wxPEN_COLOUR );
371 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_COLOUR );
372 m_textGC = wxGetPoolGC( m_window, wxTEXT_COLOUR );
373 m_bgGC = wxGetPoolGC( m_window, wxBG_COLOUR );
374 }
375
376 /* background colour */
377 m_backgroundBrush = *wxWHITE_BRUSH;
378 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
2796f657 379#ifdef __WXGTK24__
c6685317 380 const GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor();
2796f657
PC
381#else
382 GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor();
383#endif
809934d2
RR
384
385 /* m_textGC */
386 m_textForegroundColour.CalcPixel( m_cmap );
387 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
388
389 m_textBackgroundColour.CalcPixel( m_cmap );
390 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
391
392 gdk_gc_set_fill( m_textGC, GDK_SOLID );
393
394 /* m_penGC */
395 m_pen.GetColour().CalcPixel( m_cmap );
396 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
397 gdk_gc_set_background( m_penGC, bg_col );
5f170f33 398
809934d2 399 gdk_gc_set_line_attributes( m_penGC, 0, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND );
5f170f33 400
809934d2
RR
401 /* m_brushGC */
402 m_brush.GetColour().CalcPixel( m_cmap );
403 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
404 gdk_gc_set_background( m_brushGC, bg_col );
5f170f33 405
809934d2 406 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
5f170f33 407
809934d2
RR
408 /* m_bgGC */
409 gdk_gc_set_background( m_bgGC, bg_col );
410 gdk_gc_set_foreground( m_bgGC, bg_col );
411
412 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
5f170f33 413
809934d2
RR
414 /* ROPs */
415 gdk_gc_set_function( m_textGC, GDK_COPY );
416 gdk_gc_set_function( m_brushGC, GDK_COPY );
417 gdk_gc_set_function( m_penGC, GDK_COPY );
5f170f33 418
809934d2
RR
419 /* clipping */
420 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
421 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
422 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
423 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
424
425 if (!hatch_bitmap)
426 {
427 hatch_bitmap = hatches;
428 hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height );
429 hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height );
430 hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height );
431 hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height );
432 hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height );
433 hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height );
434 }
435}
436
376aa62a
VZ
437void wxWindowDC::DoGetSize( int* width, int* height ) const
438{
439 wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") );
440
441 m_owner->GetSize(width, height);
442}
443
ab9d0a8c 444extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
06cf7c08 445 const wxColour & col, int style);
b1699cd3 446
387ebd3e 447bool wxWindowDC::DoFloodFill(wxCoord x, wxCoord y,
06cf7c08
VS
448 const wxColour& col, int style)
449{
387ebd3e 450 return wxDoFloodFill(this, x, y, col, style);
903f689b 451}
c801d85f 452
dc1efb1d 453bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
c801d85f 454{
dc1efb1d
JS
455 // Generic (and therefore rather inefficient) method.
456 // Could be improved.
457 wxMemoryDC memdc;
458 wxBitmap bitmap(1, 1);
459 memdc.SelectObject(bitmap);
460 memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
461 memdc.SelectObject(wxNullBitmap);
c2fa61e8 462
368d59f0 463 wxImage image = bitmap.ConvertToImage();
dc1efb1d 464 col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
ab9d0a8c 465 return true;
903f689b 466}
c801d85f 467
72cdf4c9 468void wxWindowDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
c801d85f 469{
223d09f6 470 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 471
265898fd
RR
472 if (m_pen.GetStyle() != wxTRANSPARENT)
473 {
6db90681
RR
474 if (m_window)
475 gdk_draw_line( m_window, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
7d5af6fa 476
ed880dd4
RR
477 CalcBoundingBox(x1, y1);
478 CalcBoundingBox(x2, y2);
265898fd 479 }
903f689b 480}
c801d85f 481
72cdf4c9 482void wxWindowDC::DoCrossHair( wxCoord x, wxCoord y )
c801d85f 483{
223d09f6 484 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 485
265898fd
RR
486 if (m_pen.GetStyle() != wxTRANSPARENT)
487 {
488 int w = 0;
489 int h = 0;
490 GetSize( &w, &h );
72cdf4c9
VZ
491 wxCoord xx = XLOG2DEV(x);
492 wxCoord yy = YLOG2DEV(y);
6db90681 493 if (m_window)
7d5af6fa 494 {
6db90681
RR
495 gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
496 gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
7d5af6fa 497 }
265898fd 498 }
903f689b 499}
c801d85f 500
72cdf4c9
VZ
501void wxWindowDC::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
502 wxCoord xc, wxCoord yc )
c801d85f 503{
223d09f6 504 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 505
72cdf4c9
VZ
506 wxCoord xx1 = XLOG2DEV(x1);
507 wxCoord yy1 = YLOG2DEV(y1);
508 wxCoord xx2 = XLOG2DEV(x2);
509 wxCoord yy2 = YLOG2DEV(y2);
510 wxCoord xxc = XLOG2DEV(xc);
511 wxCoord yyc = YLOG2DEV(yc);
7d5af6fa 512 double dx = xx1 - xxc;
265898fd 513 double dy = yy1 - yyc;
de87c353 514 double radius = sqrt((double)(dx*dx+dy*dy));
72cdf4c9 515 wxCoord r = (wxCoord)radius;
265898fd
RR
516 double radius1, radius2;
517
7d5af6fa 518 if (xx1 == xx2 && yy1 == yy2)
265898fd
RR
519 {
520 radius1 = 0.0;
521 radius2 = 360.0;
7d5af6fa 522 }
c77a6796 523 else if ( wxIsNullDouble(radius) )
265898fd 524 {
c77a6796
VZ
525 radius1 =
526 radius2 = 0.0;
7d5af6fa
VZ
527 }
528 else
265898fd
RR
529 {
530 radius1 = (xx1 - xxc == 0) ?
b0e0d661
VZ
531 (yy1 - yyc < 0) ? 90.0 : -90.0 :
532 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
265898fd 533 radius2 = (xx2 - xxc == 0) ?
b0e0d661
VZ
534 (yy2 - yyc < 0) ? 90.0 : -90.0 :
535 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
265898fd 536 }
72cdf4c9
VZ
537 wxCoord alpha1 = wxCoord(radius1 * 64.0);
538 wxCoord alpha2 = wxCoord((radius2 - radius1) * 64.0);
265898fd
RR
539 while (alpha2 <= 0) alpha2 += 360*64;
540 while (alpha1 > 360*64) alpha1 -= 360*64;
541
6db90681
RR
542 if (m_window)
543 {
544 if (m_brush.GetStyle() != wxTRANSPARENT)
e9f88d04
VZ
545 {
546 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
547 {
548 gdk_gc_set_ts_origin( m_textGC,
549 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
550 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
551 gdk_draw_arc( m_window, m_textGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
552 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
553 } else
3ca6a5f0
BP
554 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
555 {
556 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
557 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
558 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
559 } else
560 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
561 {
562 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
563 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
564 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
565 } else
e9f88d04
VZ
566 if (m_brush.GetStyle() == wxSTIPPLE)
567 {
568 gdk_gc_set_ts_origin( m_brushGC,
569 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
570 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
571 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
572 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
573 }
574 else
575 {
576 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
577 }
578 }
7d5af6fa 579
6db90681 580 if (m_pen.GetStyle() != wxTRANSPARENT)
3d0c4d2e 581 {
6db90681 582 gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
f469b27c 583
3d0c4d2e
RR
584 gdk_draw_line( m_window, m_penGC, xx1, yy1, xxc, yyc );
585 gdk_draw_line( m_window, m_penGC, xxc, yyc, xx2, yy2 );
586 }
6db90681 587 }
7d5af6fa 588
265898fd
RR
589 CalcBoundingBox (x1, y1);
590 CalcBoundingBox (x2, y2);
903f689b 591}
c801d85f 592
72cdf4c9 593void wxWindowDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double sa, double ea )
c801d85f 594{
223d09f6 595 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 596
72cdf4c9
VZ
597 wxCoord xx = XLOG2DEV(x);
598 wxCoord yy = YLOG2DEV(y);
599 wxCoord ww = m_signX * XLOG2DEVREL(width);
600 wxCoord hh = m_signY * YLOG2DEVREL(height);
7d5af6fa 601
265898fd
RR
602 // CMB: handle -ve width and/or height
603 if (ww < 0) { ww = -ww; xx = xx - ww; }
604 if (hh < 0) { hh = -hh; yy = yy - hh; }
7d5af6fa 605
6db90681
RR
606 if (m_window)
607 {
72cdf4c9 608 wxCoord start = wxCoord(sa * 64.0);
3d0c4d2e 609 wxCoord end = wxCoord((ea-sa) * 64.0);
7d5af6fa 610
6db90681 611 if (m_brush.GetStyle() != wxTRANSPARENT)
e9f88d04
VZ
612 {
613 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
614 {
615 gdk_gc_set_ts_origin( m_textGC,
616 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
617 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
618 gdk_draw_arc( m_window, m_textGC, TRUE, xx, yy, ww, hh, start, end );
619 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
620 } else
3ca6a5f0
BP
621 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
622 {
623 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
624 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
625 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
626 } else
627 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
628 {
629 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
630 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
631 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
632 } else
e9f88d04
VZ
633 if (m_brush.GetStyle() == wxSTIPPLE)
634 {
635 gdk_gc_set_ts_origin( m_brushGC,
636 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
637 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
638 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
639 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
640 }
641 else
642 {
643 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
644 }
645 }
7d5af6fa 646
6db90681
RR
647 if (m_pen.GetStyle() != wxTRANSPARENT)
648 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
649 }
7d5af6fa 650
265898fd
RR
651 CalcBoundingBox (x, y);
652 CalcBoundingBox (x + width, y + height);
903f689b 653}
c801d85f 654
72cdf4c9 655void wxWindowDC::DoDrawPoint( wxCoord x, wxCoord y )
c801d85f 656{
223d09f6 657 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 658
6db90681 659 if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
265898fd 660 gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
7d5af6fa 661
265898fd 662 CalcBoundingBox (x, y);
903f689b 663}
c801d85f 664
72cdf4c9 665void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset )
c801d85f 666{
223d09f6 667 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 668
265898fd
RR
669 if (m_pen.GetStyle() == wxTRANSPARENT) return;
670 if (n <= 0) return;
7d5af6fa 671
e90411c2 672 //Check, if scaling is necessary
280831d5
PC
673 const bool doScale =
674 xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
e90411c2 675
280831d5
PC
676 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
677 GdkPoint* gpts = reinterpret_cast<GdkPoint*>(points);
e90411c2 678
280831d5 679 if (doScale)
e90411c2 680 gpts = new GdkPoint[n];
7d5af6fa 681
ab9d0a8c 682 for (int i = 0; i < n; i++)
265898fd 683 {
280831d5
PC
684 if (doScale)
685 {
686 gpts[i].x = XLOG2DEV(points[i].x + xoffset);
687 gpts[i].y = YLOG2DEV(points[i].y + yoffset);
e90411c2 688 }
280831d5 689 CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset);
e90411c2 690 }
6eb37239
VZ
691
692 if (m_window)
693 gdk_draw_lines( m_window, m_penGC, gpts, n);
694
e90411c2 695 if (doScale)
280831d5 696 delete[] gpts;
903f689b 697}
c801d85f 698
72cdf4c9 699void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int WXUNUSED(fillStyle) )
cf7a7e13 700{
223d09f6 701 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 702
4bc67cc5 703 if (n <= 0) return;
7d5af6fa 704
e90411c2 705 //Check, if scaling is necessary
280831d5
PC
706 const bool doScale =
707 xoffset != 0 || yoffset != 0 || XLOG2DEV(10) != 10 || YLOG2DEV(10) != 10;
e90411c2 708
280831d5
PC
709 // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other
710 GdkPoint* gdkpoints = reinterpret_cast<GdkPoint*>(points);
e90411c2 711
280831d5
PC
712 if (doScale)
713 gdkpoints = new GdkPoint[n];
e90411c2 714
265898fd
RR
715 int i;
716 for (i = 0 ; i < n ; i++)
717 {
280831d5
PC
718 if (doScale)
719 {
720 gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset);
721 gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset);
e90411c2 722 }
280831d5 723 CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset);
e90411c2 724 }
7d5af6fa 725
de2d2cdc 726 if (m_window)
72174350 727 {
e1208c31 728 if (m_brush.GetStyle() != wxTRANSPARENT)
72174350 729 {
e1208c31
RR
730 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
731 {
5f170f33
VZ
732 gdk_gc_set_ts_origin( m_textGC,
733 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
e1208c31
RR
734 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
735 gdk_draw_polygon( m_window, m_textGC, TRUE, gdkpoints, n );
736 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
737 } else
3ca6a5f0
BP
738 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
739 {
740 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
741 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
742 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
743 } else
744 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
745 {
746 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
747 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
748 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
749 } else
e1208c31
RR
750 if (m_brush.GetStyle() == wxSTIPPLE)
751 {
5f170f33
VZ
752 gdk_gc_set_ts_origin( m_brushGC,
753 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
e1208c31
RR
754 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
755 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
756 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
757 }
758 else
759 {
760 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
761 }
72174350 762 }
7d5af6fa 763
e1208c31 764 if (m_pen.GetStyle() != wxTRANSPARENT)
b0e0d661 765 {
bb56b0a8 766/*
e1208c31
RR
767 for (i = 0 ; i < n ; i++)
768 {
769 gdk_draw_line( m_window, m_penGC,
770 gdkpoints[i%n].x,
771 gdkpoints[i%n].y,
772 gdkpoints[(i+1)%n].x,
773 gdkpoints[(i+1)%n].y);
774 }
bb56b0a8
JS
775*/
776 gdk_draw_polygon( m_window, m_penGC, FALSE, gdkpoints, n );
ab9d0a8c 777
265898fd 778 }
6db90681 779 }
7d5af6fa 780
e90411c2 781 if (doScale)
280831d5 782 delete[] gdkpoints;
903f689b 783}
c801d85f 784
72cdf4c9 785void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
c801d85f 786{
223d09f6 787 wxCHECK_RET( Ok(), wxT("invalid window dc") );
c801d85f 788
72cdf4c9
VZ
789 wxCoord xx = XLOG2DEV(x);
790 wxCoord yy = YLOG2DEV(y);
791 wxCoord ww = m_signX * XLOG2DEVREL(width);
792 wxCoord hh = m_signY * YLOG2DEVREL(height);
7d5af6fa 793
265898fd
RR
794 // CMB: draw nothing if transformed w or h is 0
795 if (ww == 0 || hh == 0) return;
6f65e337 796
265898fd
RR
797 // CMB: handle -ve width and/or height
798 if (ww < 0) { ww = -ww; xx = xx - ww; }
799 if (hh < 0) { hh = -hh; yy = yy - hh; }
6f65e337 800
6db90681
RR
801 if (m_window)
802 {
e1208c31 803 if (m_brush.GetStyle() != wxTRANSPARENT)
72174350 804 {
e1208c31
RR
805 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
806 {
5f170f33
VZ
807 gdk_gc_set_ts_origin( m_textGC,
808 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
e1208c31
RR
809 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
810 gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh );
811 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
3ca6a5f0
BP
812 } else
813 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
814 {
815 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
816 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
817 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
818 } else
819 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
820 {
821 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
822 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
823 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
824 } else
825 if (m_brush.GetStyle() == wxSTIPPLE)
e1208c31 826 {
5f170f33
VZ
827 gdk_gc_set_ts_origin( m_brushGC,
828 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
e1208c31 829 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
72174350 830 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
e1208c31
RR
831 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
832 }
833 else
834 {
835 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
836 }
72174350 837 }
e1208c31
RR
838
839 if (m_pen.GetStyle() != wxTRANSPARENT)
840 gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
6db90681 841 }
7d5af6fa 842
265898fd
RR
843 CalcBoundingBox( x, y );
844 CalcBoundingBox( x + width, y + height );
903f689b 845}
c801d85f 846
72cdf4c9 847void wxWindowDC::DoDrawRoundedRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius )
c801d85f 848{
223d09f6 849 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 850
265898fd 851 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
7d5af6fa 852
72cdf4c9
VZ
853 wxCoord xx = XLOG2DEV(x);
854 wxCoord yy = YLOG2DEV(y);
855 wxCoord ww = m_signX * XLOG2DEVREL(width);
856 wxCoord hh = m_signY * YLOG2DEVREL(height);
857 wxCoord rr = XLOG2DEVREL((wxCoord)radius);
265898fd
RR
858
859 // CMB: handle -ve width and/or height
860 if (ww < 0) { ww = -ww; xx = xx - ww; }
861 if (hh < 0) { hh = -hh; yy = yy - hh; }
862
863 // CMB: if radius is zero use DrawRectangle() instead to avoid
864 // X drawing errors with small radii
865 if (rr == 0)
866 {
867 DrawRectangle( x, y, width, height );
868 return;
869 }
870
871 // CMB: draw nothing if transformed w or h is 0
872 if (ww == 0 || hh == 0) return;
873
874 // CMB: adjust size if outline is drawn otherwise the result is
875 // 1 pixel too wide and high
876 if (m_pen.GetStyle() != wxTRANSPARENT)
877 {
878 ww--;
879 hh--;
880 }
881
6db90681 882 if (m_window)
265898fd 883 {
6db90681
RR
884 // CMB: ensure dd is not larger than rectangle otherwise we
885 // get an hour glass shape
72cdf4c9 886 wxCoord dd = 2 * rr;
6db90681
RR
887 if (dd > ww) dd = ww;
888 if (dd > hh) dd = hh;
889 rr = dd / 2;
890
891 if (m_brush.GetStyle() != wxTRANSPARENT)
892 {
a56fcaaf
RR
893 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
894 {
5f170f33
VZ
895 gdk_gc_set_ts_origin( m_textGC,
896 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
a56fcaaf
RR
897 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
898 gdk_draw_rectangle( m_window, m_textGC, TRUE, xx+rr, yy, ww-dd+1, hh );
899 gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
900 gdk_draw_arc( m_window, m_textGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
901 gdk_draw_arc( m_window, m_textGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
902 gdk_draw_arc( m_window, m_textGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
903 gdk_draw_arc( m_window, m_textGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
904 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
3ca6a5f0
BP
905 } else
906 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
907 {
908 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
909 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
910 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
911 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
912 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
913 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
914 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
915 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
916 } else
917 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
918 {
919 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
920 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
921 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
922 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
923 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
924 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
925 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
926 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
927 } else
928 if (m_brush.GetStyle() == wxSTIPPLE)
a56fcaaf 929 {
5f170f33
VZ
930 gdk_gc_set_ts_origin( m_brushGC,
931 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
a56fcaaf
RR
932 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
933 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
934 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
935 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
936 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
937 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
938 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
939 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
940 }
941 else
942 {
943 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
944 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
945 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
946 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
947 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
948 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
949 }
6db90681 950 }
7d5af6fa 951
6db90681 952 if (m_pen.GetStyle() != wxTRANSPARENT)
7d5af6fa 953 {
3ca6a5f0
BP
954 gdk_draw_line( m_window, m_penGC, xx+rr+1, yy, xx+ww-rr, yy );
955 gdk_draw_line( m_window, m_penGC, xx+rr+1, yy+hh, xx+ww-rr, yy+hh );
956 gdk_draw_line( m_window, m_penGC, xx, yy+rr+1, xx, yy+hh-rr );
957 gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr+1, xx+ww, yy+hh-rr );
6db90681
RR
958 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
959 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
960 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
961 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
7d5af6fa 962 }
265898fd 963 }
7d5af6fa 964
265898fd
RR
965 // this ignores the radius
966 CalcBoundingBox( x, y );
967 CalcBoundingBox( x + width, y + height );
903f689b 968}
c801d85f 969
72cdf4c9 970void wxWindowDC::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
c801d85f 971{
223d09f6 972 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 973
72cdf4c9
VZ
974 wxCoord xx = XLOG2DEV(x);
975 wxCoord yy = YLOG2DEV(y);
976 wxCoord ww = m_signX * XLOG2DEVREL(width);
977 wxCoord hh = m_signY * YLOG2DEVREL(height);
6f65e337 978
265898fd
RR
979 // CMB: handle -ve width and/or height
980 if (ww < 0) { ww = -ww; xx = xx - ww; }
981 if (hh < 0) { hh = -hh; yy = yy - hh; }
7d5af6fa 982
6db90681
RR
983 if (m_window)
984 {
985 if (m_brush.GetStyle() != wxTRANSPARENT)
a56fcaaf
RR
986 {
987 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
988 {
5f170f33
VZ
989 gdk_gc_set_ts_origin( m_textGC,
990 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
a56fcaaf
RR
991 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
992 gdk_draw_arc( m_window, m_textGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
993 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
3ca6a5f0
BP
994 } else
995 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
996 {
997 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
998 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
999 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
1000 } else
1001 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
1002 {
1003 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
1004 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
1005 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
1006 } else
1007 if (m_brush.GetStyle() == wxSTIPPLE)
a56fcaaf 1008 {
5f170f33
VZ
1009 gdk_gc_set_ts_origin( m_brushGC,
1010 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
a56fcaaf
RR
1011 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
1012 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
1013 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
1014 }
1015 else
1016 {
1017 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
1018 }
1019 }
7d5af6fa 1020
6db90681
RR
1021 if (m_pen.GetStyle() != wxTRANSPARENT)
1022 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
1023 }
7d5af6fa 1024
44856297 1025 CalcBoundingBox( x, y );
265898fd 1026 CalcBoundingBox( x + width, y + height );
903f689b 1027}
c801d85f 1028
72cdf4c9 1029void wxWindowDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
c801d85f 1030{
b0e0d661 1031 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
ab9d0a8c 1032 DoDrawBitmap( (const wxBitmap&)icon, x, y, true );
903f689b 1033}
c801d85f 1034
b0e0d661 1035void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
72cdf4c9 1036 wxCoord x, wxCoord y,
b0e0d661 1037 bool useMask )
4bc67cc5 1038{
223d09f6 1039 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1040
223d09f6 1041 wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") );
7d5af6fa 1042
b85229d1 1043 bool is_mono = bitmap.GetDepth() == 1;
82ea63e6 1044
d90c9596 1045 // scale/translate size and position
265898fd
RR
1046 int xx = XLOG2DEV(x);
1047 int yy = YLOG2DEV(y);
7d5af6fa 1048
4bc67cc5
RR
1049 int w = bitmap.GetWidth();
1050 int h = bitmap.GetHeight();
847dfdb4
RR
1051
1052 if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
1053 xx -= w;
1054
6453876e
RR
1055 CalcBoundingBox( x, y );
1056 CalcBoundingBox( x + w, y + h );
7d5af6fa 1057
6453876e 1058 if (!m_window) return;
7d5af6fa 1059
4bc67cc5
RR
1060 int ww = XLOG2DEVREL(w);
1061 int hh = YLOG2DEVREL(h);
7d5af6fa 1062
d90c9596 1063 // compare to current clipping region
e1208c31 1064 if (!m_currentClippingRegion.IsNull())
3d2d8da1
RR
1065 {
1066 wxRegion tmp( xx,yy,ww,hh );
1067 tmp.Intersect( m_currentClippingRegion );
1068 if (tmp.IsEmpty())
1069 return;
1070 }
5f170f33 1071
ab9d0a8c 1072 // scale bitmap if required
d90c9596 1073 wxBitmap use_bitmap = bitmap;
4bc67cc5 1074 if ((w != ww) || (h != hh))
d90c9596 1075 use_bitmap = use_bitmap.Rescale( 0, 0, ww, hh, ww, hh );
ab9d0a8c 1076
1abedc32
VS
1077#if !GTK_CHECK_VERSION(2,2,0)
1078 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1079 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1080 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1081 // and also creates the mask as a side-effect:
1082 use_bitmap.GetPixmap();
1083#endif
ab9d0a8c 1084
d90c9596 1085 // apply mask if any
463c1fa1 1086 GdkBitmap *mask = (GdkBitmap *) NULL;
280831d5
PC
1087 if (useMask && use_bitmap.GetMask())
1088 mask = use_bitmap.GetMask()->GetBitmap();
1089
1090 GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
7d5af6fa 1091
d90c9596 1092 GdkBitmap *new_mask = (GdkBitmap*) NULL;
ab9d0a8c 1093
280831d5 1094 if (mask != NULL)
d90c9596
RR
1095 {
1096 if (!m_currentClippingRegion.IsNull())
82ea63e6 1097 {
d90c9596
RR
1098 GdkColor col;
1099 new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 );
1100 GdkGC *gc = gdk_gc_new( new_mask );
1101 col.pixel = 0;
1102 gdk_gc_set_foreground( gc, &col );
1103 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
1104 col.pixel = 0;
1105 gdk_gc_set_background( gc, &col );
1106 col.pixel = 1;
1107 gdk_gc_set_foreground( gc, &col );
1108 gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
1109 gdk_gc_set_clip_origin( gc, -xx, -yy );
1110 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
1111 gdk_gc_set_stipple( gc, mask );
1112 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
280831d5 1113 mask = new_mask;
3fe39b0c 1114 g_object_unref (gc);
d90c9596 1115 }
ab9d0a8c 1116
280831d5
PC
1117 gdk_gc_set_clip_mask(use_gc, mask);
1118 gdk_gc_set_clip_origin(use_gc, xx, yy);
d90c9596 1119 }
7d5af6fa 1120
d90c9596
RR
1121 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1122 // drawing a mono-bitmap (XBitmap) we use the current text GC
82ea63e6 1123 if (is_mono)
d90c9596 1124 {
4e115ed2
VZ
1125 GdkPixmap *bitmap2 = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, -1 );
1126 GdkGC *gc = gdk_gc_new( bitmap2 );
d90c9596
RR
1127 gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
1128 gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
b85229d1 1129 gdk_wx_draw_bitmap( bitmap2, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
ab9d0a8c 1130
280831d5 1131 gdk_draw_drawable(m_window, use_gc, bitmap2, 0, 0, xx, yy, -1, -1);
ab9d0a8c 1132
3fe39b0c
MR
1133 g_object_unref (bitmap2);
1134 g_object_unref (gc);
d90c9596 1135 }
82ea63e6 1136 else
d90c9596 1137 {
feac7937 1138#if GTK_CHECK_VERSION(2,2,0)
cc35003a 1139 if (!gtk_check_version(2,2,0) && use_bitmap.HasPixbuf())
feac7937 1140 {
280831d5 1141 gdk_draw_pixbuf(m_window, use_gc,
feac7937
VS
1142 use_bitmap.GetPixbuf(),
1143 0, 0, xx, yy, -1, -1,
1144 GDK_RGB_DITHER_NORMAL, xx, yy);
1145 }
1146 else
1147#endif
1148 {
280831d5 1149 gdk_draw_drawable(m_window, use_gc,
15f0ad70
MR
1150 use_bitmap.GetPixmap(),
1151 0, 0, xx, yy, -1, -1);
feac7937 1152 }
d90c9596 1153 }
72174350 1154
d90c9596 1155 // remove mask again if any
280831d5 1156 if (mask != NULL)
463c1fa1 1157 {
280831d5
PC
1158 gdk_gc_set_clip_mask(use_gc, NULL);
1159 gdk_gc_set_clip_origin(use_gc, 0, 0);
1160 if (!m_currentClippingRegion.IsNull())
1161 gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
1162 if (new_mask != NULL)
1163 g_object_unref(new_mask);
463c1fa1 1164 }
463c1fa1
RR
1165}
1166
1e6feb95
VZ
1167bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
1168 wxCoord width, wxCoord height,
1169 wxDC *source,
1170 wxCoord xsrc, wxCoord ysrc,
1171 int logical_func,
0cbff120
JS
1172 bool useMask,
1173 wxCoord xsrcMask, wxCoord ysrcMask )
c801d85f 1174{
ab9d0a8c 1175 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
7d5af6fa 1176
ab9d0a8c 1177 wxCHECK_MSG( source, false, wxT("invalid source dc") );
7d5af6fa 1178
ab9d0a8c 1179 if (!m_window) return false;
7d5af6fa 1180
1e6feb95 1181 // transform the source DC coords to the device ones
772b3767
PC
1182 xsrc = source->LogicalToDeviceX(xsrc);
1183 ysrc = source->LogicalToDeviceY(ysrc);
1e6feb95 1184
6e13c196
RR
1185 wxClientDC *srcDC = (wxClientDC*)source;
1186 wxMemoryDC *memDC = (wxMemoryDC*)source;
7d5af6fa 1187
ab9d0a8c
WS
1188 bool use_bitmap_method = false;
1189 bool is_mono = false;
7d5af6fa 1190
0cbff120
JS
1191 if (xsrcMask == -1 && ysrcMask == -1)
1192 {
d90c9596
RR
1193 xsrcMask = xsrc;
1194 ysrcMask = ysrc;
0cbff120
JS
1195 }
1196
6e13c196
RR
1197 if (srcDC->m_isMemDC)
1198 {
ab9d0a8c 1199 if (!memDC->m_selected.Ok()) return false;
7d5af6fa 1200
d90c9596
RR
1201 is_mono = (memDC->m_selected.GetDepth() == 1);
1202
1203 // we use the "XCopyArea" way to copy a memory dc into
1204 // a different window if the memory dc BOTH
1205 // a) doesn't have any mask or its mask isn't used
1206 // b) it is clipped
1207 // c) is not 1-bit
7d5af6fa 1208
f234c60c 1209 if (useMask && (memDC->m_selected.GetMask()))
b0e0d661 1210 {
d90c9596
RR
1211 // we HAVE TO use the direct way for memory dcs
1212 // that have mask since the XCopyArea doesn't know
1213 // about masks
ab9d0a8c 1214 use_bitmap_method = true;
b0e0d661 1215 }
d90c9596 1216 else if (is_mono)
b0e0d661 1217 {
d90c9596
RR
1218 // we HAVE TO use the direct way for memory dcs
1219 // that are bitmaps because XCopyArea doesn't cope
1220 // with different bit depths
ab9d0a8c 1221 use_bitmap_method = true;
b0e0d661
VZ
1222 }
1223 else if ((xsrc == 0) && (ysrc == 0) &&
1224 (width == memDC->m_selected.GetWidth()) &&
1225 (height == memDC->m_selected.GetHeight()))
1226 {
d90c9596
RR
1227 // we SHOULD use the direct way if all of the bitmap
1228 // in the memory dc is copied in which case XCopyArea
1229 // wouldn't be able able to boost performace by reducing
1230 // the area to be scaled
ab9d0a8c 1231 use_bitmap_method = true;
b0e0d661 1232 }
6e13c196 1233 }
7d5af6fa 1234
265898fd
RR
1235 CalcBoundingBox( xdest, ydest );
1236 CalcBoundingBox( xdest + width, ydest + height );
7d5af6fa 1237
d90c9596 1238 // scale/translate size and position
3d2d8da1
RR
1239 wxCoord xx = XLOG2DEV(xdest);
1240 wxCoord yy = YLOG2DEV(ydest);
1241
1242 wxCoord ww = XLOG2DEVREL(width);
1243 wxCoord hh = YLOG2DEVREL(height);
1244
d90c9596 1245 // compare to current clipping region
e1208c31 1246 if (!m_currentClippingRegion.IsNull())
3d2d8da1
RR
1247 {
1248 wxRegion tmp( xx,yy,ww,hh );
1249 tmp.Intersect( m_currentClippingRegion );
1250 if (tmp.IsEmpty())
ab9d0a8c 1251 return true;
3d2d8da1
RR
1252 }
1253
4bc67cc5
RR
1254 int old_logical_func = m_logicalFunction;
1255 SetLogicalFunction( logical_func );
5f170f33 1256
6e13c196 1257 if (use_bitmap_method)
6f65e337 1258 {
d90c9596 1259 // scale/translate bitmap size
72cdf4c9
VZ
1260 wxCoord bm_width = memDC->m_selected.GetWidth();
1261 wxCoord bm_height = memDC->m_selected.GetHeight();
7d5af6fa 1262
551b5391
RR
1263 // Get clip coords for the bitmap. If we don't
1264 // use wxBitmap::Rescale(), which can clip the
1265 // bitmap, these are the same as the original
1266 // coordinates
1267 wxCoord cx = xx;
1268 wxCoord cy = yy;
1269 wxCoord cw = ww;
1270 wxCoord ch = hh;
ab9d0a8c 1271
d90c9596
RR
1272 // interpret userscale of src too
1273 double xsc,ysc;
1274 memDC->GetUserScale(&xsc,&ysc);
1275 bm_width = (int) (bm_width / xsc);
1276 bm_height = (int) (bm_height / ysc);
1277
72cdf4c9
VZ
1278 wxCoord bm_ww = XLOG2DEVREL( bm_width );
1279 wxCoord bm_hh = YLOG2DEVREL( bm_height );
7d5af6fa 1280
551b5391 1281 // Scale bitmap if required
280831d5 1282 wxBitmap use_bitmap = memDC->m_selected;
f53df133 1283 if ((memDC->m_selected.GetWidth()!= bm_ww) || ( memDC->m_selected.GetHeight()!= bm_hh))
6e13c196 1284 {
551b5391
RR
1285 // This indicates that the blitting code below will get
1286 // a clipped bitmap and therefore needs to move the origin
1287 // accordingly
1288 wxRegion tmp( xx,yy,ww,hh );
1289 tmp.Intersect( m_currentClippingRegion );
1290 tmp.GetBox(cx,cy,cw,ch);
ab9d0a8c 1291
551b5391
RR
1292 // Scale and clipped bitmap
1293 use_bitmap = memDC->m_selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh);
6e13c196 1294 }
7d5af6fa 1295
d90c9596 1296 // apply mask if any
6e13c196 1297 GdkBitmap *mask = (GdkBitmap *) NULL;
280831d5
PC
1298 if (useMask && use_bitmap.GetMask())
1299 mask = use_bitmap.GetMask()->GetBitmap();
1300
1301 GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
7d5af6fa 1302
d90c9596 1303 GdkBitmap *new_mask = (GdkBitmap*) NULL;
ab9d0a8c 1304
280831d5 1305 if (mask != NULL)
6e13c196 1306 {
e1208c31 1307 if (!m_currentClippingRegion.IsNull())
3d2d8da1
RR
1308 {
1309 GdkColor col;
c2fa61e8 1310 new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 );
3d2d8da1
RR
1311 GdkGC *gc = gdk_gc_new( new_mask );
1312 col.pixel = 0;
1313 gdk_gc_set_foreground( gc, &col );
b7a49654 1314 gdk_gc_set_ts_origin( gc, -xsrcMask, -ysrcMask);
3d2d8da1
RR
1315 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
1316 col.pixel = 0;
1317 gdk_gc_set_background( gc, &col );
1318 col.pixel = 1;
1319 gdk_gc_set_foreground( gc, &col );
1320 gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
d90c9596
RR
1321 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1322 gdk_gc_set_clip_origin( gc, -cx, -cy );
3d2d8da1
RR
1323 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
1324 gdk_gc_set_stipple( gc, mask );
1325 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
280831d5 1326 mask = new_mask;
3fe39b0c 1327 g_object_unref (gc);
3d2d8da1 1328 }
d90c9596 1329
280831d5
PC
1330 gdk_gc_set_clip_mask(use_gc, mask);
1331 if (new_mask != NULL)
1332 gdk_gc_set_clip_origin(use_gc, cx, cy);
82ea63e6 1333 else
280831d5 1334 gdk_gc_set_clip_origin(use_gc, cx - xsrcMask, cy - ysrcMask);
6e13c196 1335 }
7d5af6fa 1336
d90c9596
RR
1337 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1338 // drawing a mono-bitmap (XBitmap) we use the current text GC
5f170f33 1339
82ea63e6 1340 if (is_mono)
d90c9596 1341 {
d90c9596
RR
1342 GdkPixmap *bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, -1 );
1343 GdkGC *gc = gdk_gc_new( bitmap );
1344 gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
1345 gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
b85229d1 1346 gdk_wx_draw_bitmap( bitmap, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
ab9d0a8c 1347
280831d5 1348 gdk_draw_drawable(m_window, use_gc, bitmap, xsrc, ysrc, cx, cy, cw, ch);
ab9d0a8c 1349
3fe39b0c
MR
1350 g_object_unref (bitmap);
1351 g_object_unref (gc);
d90c9596 1352 }
82ea63e6 1353 else
d90c9596 1354 {
15f0ad70 1355 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
280831d5 1356 gdk_draw_drawable(m_window, use_gc, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch);
d90c9596 1357 }
82ea63e6 1358
d90c9596 1359 // remove mask again if any
280831d5 1360 if (mask != NULL)
6e13c196 1361 {
280831d5
PC
1362 gdk_gc_set_clip_mask(use_gc, NULL);
1363 gdk_gc_set_clip_origin(use_gc, 0, 0);
1364 if (!m_currentClippingRegion.IsNull())
1365 gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
265898fd 1366 }
ab9d0a8c 1367
d90c9596 1368 if (new_mask)
3fe39b0c 1369 g_object_unref (new_mask);
6f65e337 1370 }
d90c9596 1371 else // use_bitmap_method
6e13c196 1372 {
bf9848e7 1373 if ((width != ww) || (height != hh))
b0e0d661 1374 {
d90c9596
RR
1375 // get clip coords
1376 wxRegion tmp( xx,yy,ww,hh );
1377 tmp.Intersect( m_currentClippingRegion );
1378 wxCoord cx,cy,cw,ch;
1379 tmp.GetBox(cx,cy,cw,ch);
ab9d0a8c
WS
1380
1381 // rescale bitmap
d90c9596 1382 wxBitmap bitmap = memDC->m_selected.Rescale( cx-xx, cy-yy, cw, ch, ww, hh );
7d5af6fa 1383
d90c9596 1384 // draw scaled bitmap
15f0ad70
MR
1385 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1386 gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, cx, cy, -1, -1 );
b0e0d661
VZ
1387 }
1388 else
1389 {
ab9d0a8c 1390 // No scaling and not a memory dc with a mask either
993f97ee 1391
d90c9596 1392 // copy including child window contents
a56fcaaf 1393 gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
15f0ad70
MR
1394 gdk_draw_drawable( m_window, m_penGC,
1395 srcDC->GetWindow(),
1396 xsrc, ysrc, xx, yy,
1397 width, height );
a56fcaaf 1398 gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
b0e0d661 1399 }
6e13c196 1400 }
c801d85f 1401
4bc67cc5 1402 SetLogicalFunction( old_logical_func );
ab9d0a8c
WS
1403
1404 return true;
903f689b 1405}
c801d85f 1406
72cdf4c9 1407void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
c801d85f 1408{
223d09f6 1409 wxCHECK_RET( Ok(), wxT("invalid window dc") );
18a2fa37 1410
6db90681 1411 if (!m_window) return;
ab9d0a8c 1412
2b5f62a0 1413 if (text.empty()) return;
7d5af6fa 1414
265898fd
RR
1415 x = XLOG2DEV(x);
1416 y = YLOG2DEV(y);
18a2fa37 1417
cfcc3932 1418 wxCHECK_RET( m_context, wxT("no Pango context") );
61850501 1419 wxCHECK_RET( m_layout, wxT("no Pango layout") );
cfcc3932 1420 wxCHECK_RET( m_fontdesc, wxT("no Pango font description") );
e4da1035 1421
1dbeee57
VS
1422 bool underlined = m_font.Ok() && m_font.GetUnderlined();
1423
a3669332
VZ
1424 const wxCharBuffer data = wxGTK_CONV( text );
1425 if ( !data )
7706daf3 1426 return;
a3669332
VZ
1427 const size_t datalen = strlen(data);
1428 pango_layout_set_text( m_layout, data, datalen);
ab9d0a8c 1429
1dbeee57
VS
1430 if (underlined)
1431 {
1432 PangoAttrList *attrs = pango_attr_list_new();
1433 PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1434 a->start_index = 0;
1435 a->end_index = datalen;
1436 pango_attr_list_insert(attrs, a);
1437 pango_layout_set_attributes(m_layout, attrs);
1438 pango_attr_list_unref(attrs);
1439 }
e4da1035 1440
76b20467 1441 int w,h;
fa499247
RR
1442
1443 if (fabs(m_scaleY - 1.0) > 0.00001)
e4da1035
RR
1444 {
1445 // If there is a user or actually any scale applied to
1446 // the device context, scale the font.
ab9d0a8c 1447
e4da1035
RR
1448 // scale font description
1449 gint oldSize = pango_font_description_get_size( m_fontdesc );
1450 double size = oldSize;
1451 size = size * m_scaleY;
1452 pango_font_description_set_size( m_fontdesc, (gint)size );
ab9d0a8c 1453
e4da1035
RR
1454 // actually apply scaled font
1455 pango_layout_set_font_description( m_layout, m_fontdesc );
ab9d0a8c 1456
76b20467
VS
1457 pango_layout_get_pixel_size( m_layout, &w, &h );
1458 if ( m_backgroundMode == wxSOLID )
1459 {
1460 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1461 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1462 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1463 }
ab9d0a8c 1464
e4da1035 1465 // Draw layout.
847dfdb4
RR
1466 if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
1467 gdk_draw_layout( m_window, m_textGC, x-w, y, m_layout );
1468 else
1469 gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
ab9d0a8c 1470
e4da1035
RR
1471 // reset unscaled size
1472 pango_font_description_set_size( m_fontdesc, oldSize );
ab9d0a8c 1473
61850501 1474 // actually apply unscaled font
e4da1035
RR
1475 pango_layout_set_font_description( m_layout, m_fontdesc );
1476 }
1477 else
1478 {
76b20467
VS
1479 pango_layout_get_pixel_size( m_layout, &w, &h );
1480 if ( m_backgroundMode == wxSOLID )
1481 {
1482 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1483 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1484 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1485 }
847dfdb4 1486
76b20467 1487 // Draw layout.
847dfdb4
RR
1488 if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
1489 gdk_draw_layout( m_window, m_textGC, x-w, y, m_layout );
1490 else
1491 gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
8943b403 1492 }
1dbeee57
VS
1493
1494 if (underlined)
1495 {
1496 // undo underline attributes setting:
1497 pango_layout_set_attributes(m_layout, NULL);
1498 }
ab9d0a8c 1499
2b5f62a0
VZ
1500 wxCoord width = w;
1501 wxCoord height = h;
ab9d0a8c 1502
8943b403
OK
1503 width = wxCoord(width / m_scaleX);
1504 height = wxCoord(height / m_scaleY);
1505 CalcBoundingBox (x + width, y + height);
265898fd 1506 CalcBoundingBox (x, y);
903f689b 1507}
c801d85f 1508
bf47e398
RD
1509
1510// TODO: There is an example of rotating text with GTK2 that would probably be
1511// a better approach here:
1512// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1513
95724b1a
VZ
1514void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
1515{
1c2d839f
PC
1516 if (!m_window || text.empty())
1517 return;
1518
1519 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1520
c77a6796 1521 if ( wxIsNullDouble(angle) )
95724b1a
VZ
1522 {
1523 DrawText(text, x, y);
1524 return;
1525 }
1526
bf47e398
RD
1527 wxCoord w;
1528 wxCoord h;
1529
68567a96 1530 // TODO: implement later without GdkFont for GTK 2.0
bf47e398 1531 GetTextExtent(text, &w, &h, NULL,NULL, &m_font);
ab9d0a8c 1532
9a8c7620
VZ
1533 // draw the string normally
1534 wxBitmap src(w, h);
95724b1a
VZ
1535 wxMemoryDC dc;
1536 dc.SelectObject(src);
1537 dc.SetFont(GetFont());
f1c72f0c 1538 dc.SetBackground(*wxBLACK_BRUSH);
95724b1a
VZ
1539 dc.SetBrush(*wxBLACK_BRUSH);
1540 dc.Clear();
f1c72f0c 1541 dc.SetTextForeground( *wxWHITE );
95724b1a 1542 dc.DrawText(text, 0, 0);
9a8c7620 1543 dc.SelectObject(wxNullBitmap);
95724b1a
VZ
1544
1545 // Calculate the size of the rotated bounding box.
9a8c7620
VZ
1546 double rad = DegToRad(angle);
1547 double dx = cos(rad),
1548 dy = sin(rad);
1549
1550 // the rectngle vertices are counted clockwise with the first one being at
1551 // (0, 0) (or, rather, at (x, y))
1552 double x2 = w*dx,
1553 y2 = -w*dy; // y axis points to the bottom, hence minus
1554 double x4 = h*dy,
1555 y4 = h*dx;
1556 double x3 = x4 + x2,
1557 y3 = y4 + y2;
ab9d0a8c 1558
72174350 1559 // calc max and min
9a8c7620
VZ
1560 wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5),
1561 maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5),
1562 minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
1563 minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
1564
72174350 1565
f1c72f0c 1566 wxImage image = src.ConvertToImage();
9a8c7620 1567
f1c72f0c
RR
1568 image.ConvertColourToAlpha( m_textForegroundColour.Red(),
1569 m_textForegroundColour.Green(),
1570 m_textForegroundColour.Blue() );
1571 image = image.Rotate( rad, wxPoint(0,0) );
ab9d0a8c 1572
1d65e535
RR
1573 int i_angle = (int) angle;
1574 i_angle = i_angle % 360;
c2cb80c8
KH
1575 if (i_angle < 0)
1576 i_angle += 360;
1d65e535
RR
1577 int xoffset = 0;
1578 if ((i_angle >= 90.0) && (i_angle < 270.0))
1579 xoffset = image.GetWidth();
1580 int yoffset = 0;
1581 if ((i_angle >= 0.0) && (i_angle < 180.0))
1582 yoffset = image.GetHeight();
ab9d0a8c 1583
1d65e535
RR
1584 if ((i_angle >= 0) && (i_angle < 90))
1585 yoffset -= (int)( cos(rad)*h );
1586 if ((i_angle >= 90) && (i_angle < 180))
ab9d0a8c 1587 xoffset -= (int)( sin(rad)*h );
1d65e535
RR
1588 if ((i_angle >= 180) && (i_angle < 270))
1589 yoffset -= (int)( cos(rad)*h );
1590 if ((i_angle >= 270) && (i_angle < 360))
1591 xoffset -= (int)( sin(rad)*h );
ab9d0a8c 1592
1d65e535
RR
1593 int i_x = x - xoffset;
1594 int i_y = y - yoffset;
ab9d0a8c 1595
f1c72f0c 1596 src = image;
1d65e535 1597 DoDrawBitmap( src, i_x, i_y, true );
9a8c7620 1598
95724b1a 1599
9a8c7620
VZ
1600 // it would be better to draw with non underlined font and draw the line
1601 // manually here (it would be more straight...)
1602#if 0
1603 if ( m_font.GetUnderlined() )
1604 {
1605 gdk_draw_line( m_window, m_textGC,
1606 XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent),
1607 XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent));
1608 }
1609#endif // 0
1610
9a8c7620
VZ
1611 // update the bounding box
1612 CalcBoundingBox(x + minX, y + minY);
1613 CalcBoundingBox(x + maxX, y + maxY);
95724b1a
VZ
1614}
1615
72cdf4c9
VZ
1616void wxWindowDC::DoGetTextExtent(const wxString &string,
1617 wxCoord *width, wxCoord *height,
1618 wxCoord *descent, wxCoord *externalLeading,
1619 wxFont *theFont) const
c801d85f 1620{
b1f0abe4
VZ
1621 if ( width )
1622 *width = 0;
1623 if ( height )
1624 *height = 0;
1625 if ( descent )
1626 *descent = 0;
1627 if ( externalLeading )
1628 *externalLeading = 0;
1629
ab9d0a8c 1630 if (string.empty())
48d011c8 1631 return;
ab9d0a8c 1632
bf5752a4
VZ
1633 // ensure that theFont is always non-NULL
1634 if ( !theFont || !theFont->Ok() )
1635 theFont = wx_const_cast(wxFont *, &m_font);
1636
1637 // and use it if it's valid
1638 if ( theFont->Ok() )
1639 {
1640 pango_layout_set_font_description
1641 (
1642 m_layout,
1643 theFont->GetNativeFontInfo()->description
1644 );
1645 }
ab9d0a8c 1646
2b5f62a0 1647 // Set layout's text
bf5752a4 1648 const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *theFont);
a1e101d0
VZ
1649 if ( !dataUTF8 )
1650 {
1651 // hardly ideal, but what else can we do if conversion failed?
1652 return;
1653 }
1654
1655 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
ab9d0a8c 1656
48d011c8
RR
1657 if (descent)
1658 {
ace35c62
RR
1659 int h;
1660 pango_layout_get_pixel_size( m_layout, width, &h );
f69e2009
VS
1661 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1662 int baseline = pango_layout_iter_get_baseline(iter);
1663 pango_layout_iter_free(iter);
1664 *descent = h - PANGO_PIXELS(baseline);
ace35c62
RR
1665
1666 if (height)
1667 *height = (wxCoord) h;
1668 }
1669 else
1670 {
1671 pango_layout_get_pixel_size( m_layout, width, height );
48d011c8 1672 }
ab9d0a8c 1673
cfcc3932
RR
1674 // Reset old font description
1675 if (theFont)
1676 pango_layout_set_font_description( m_layout, m_fontdesc );
903f689b 1677}
c801d85f 1678
72cdf4c9 1679wxCoord wxWindowDC::GetCharWidth() const
c801d85f 1680{
cfcc3932 1681 pango_layout_set_text( m_layout, "H", 1 );
ace35c62
RR
1682 int w;
1683 pango_layout_get_pixel_size( m_layout, &w, NULL );
2b5f62a0 1684 return w;
903f689b 1685}
c801d85f 1686
72cdf4c9 1687wxCoord wxWindowDC::GetCharHeight() const
c801d85f 1688{
a8c5e1a9 1689 PangoFontMetrics *metrics = pango_context_get_metrics (m_context, m_fontdesc, pango_context_get_language(m_context));
370b406c 1690 return PANGO_PIXELS (pango_font_metrics_get_descent (metrics) + pango_font_metrics_get_ascent (metrics));
903f689b 1691}
c801d85f 1692
4bc67cc5 1693void wxWindowDC::Clear()
c801d85f 1694{
223d09f6 1695 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1696
6db90681 1697 if (!m_window) return;
7d5af6fa 1698
f60e7fdd
VZ
1699 // VZ: the code below results in infinite recursion and crashes when
1700 // dc.Clear() is done from OnPaint() so I disable it for now.
1701 // I don't know what the correct fix is but Clear() surely should not
1702 // reenter OnPaint()!
1703#if 0
f234c60c
RR
1704 /* - we either are a memory dc or have a window as the
1705 owner. anything else shouldn't happen.
1706 - we don't use gdk_window_clear() as we don't set
1707 the window's background colour anymore. it is too
1708 much pain to keep the DC's and the window's back-
1709 ground colour in synch. */
7d5af6fa 1710
f234c60c 1711 if (m_owner)
265898fd 1712 {
f90566f5 1713 m_owner->Clear();
b0e0d661 1714 return;
265898fd 1715 }
f234c60c
RR
1716
1717 if (m_isMemDC)
265898fd
RR
1718 {
1719 int width,height;
1720 GetSize( &width, &height );
1721 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
b0e0d661 1722 return;
265898fd 1723 }
f60e7fdd
VZ
1724#else // 1
1725 int width,height;
1726 GetSize( &width, &height );
1727 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
1728#endif // 0/1
903f689b 1729}
c801d85f 1730
ec758a20 1731void wxWindowDC::SetFont( const wxFont &font )
c801d85f 1732{
265898fd 1733 m_font = font;
ab9d0a8c 1734
77416abd 1735 if (m_font.Ok())
2b5f62a0 1736 {
cfcc3932
RR
1737 if (m_fontdesc)
1738 pango_font_description_free( m_fontdesc );
ab9d0a8c 1739
cfcc3932 1740 m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
ab9d0a8c
WS
1741
1742
77416abd
JS
1743 if (m_owner)
1744 {
cfcc3932 1745 PangoContext *oldContext = m_context;
ab9d0a8c 1746
f26623c8 1747 m_context = m_owner->GtkGetPangoDefaultContext();
ab9d0a8c 1748
cfcc3932
RR
1749 // If we switch back/forth between different contexts
1750 // we also have to create a new layout. I think so,
ab9d0a8c 1751 // at least, and it doesn't hurt to do it.
cfcc3932
RR
1752 if (oldContext != m_context)
1753 {
1754 if (m_layout)
3fe39b0c 1755 g_object_unref (m_layout);
ab9d0a8c 1756
cfcc3932
RR
1757 m_layout = pango_layout_new( m_context );
1758 }
77416abd 1759 }
ab9d0a8c 1760
cfcc3932 1761 pango_layout_set_font_description( m_layout, m_fontdesc );
2b5f62a0 1762 }
903f689b 1763}
c801d85f 1764
ec758a20 1765void wxWindowDC::SetPen( const wxPen &pen )
c801d85f 1766{
223d09f6 1767 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1768
265898fd 1769 if (m_pen == pen) return;
7d5af6fa 1770
265898fd 1771 m_pen = pen;
7d5af6fa 1772
265898fd 1773 if (!m_pen.Ok()) return;
7d5af6fa 1774
6db90681 1775 if (!m_window) return;
7d5af6fa 1776
265898fd 1777 gint width = m_pen.GetWidth();
265898fd
RR
1778 if (width <= 0)
1779 {
112c5086 1780 // CMB: if width is non-zero scale it with the dc
265898fd
RR
1781 width = 1;
1782 }
1783 else
1784 {
1785 // X doesn't allow different width in x and y and so we take
1786 // the average
503f414e
VZ
1787 double w = 0.5 +
1788 ( fabs((double) XLOG2DEVREL(width)) +
1789 fabs((double) YLOG2DEVREL(width)) ) / 2.0;
265898fd 1790 width = (int)w;
375fc5a9
VZ
1791 if ( !width )
1792 {
1793 // width can't be 0 or an internal GTK error occurs inside
1794 // gdk_gc_set_dashes() below
1795 width = 1;
1796 }
265898fd 1797 }
7d5af6fa 1798
2eca425d
RL
1799 static const wxGTKDash dotted[] = {1, 1};
1800 static const wxGTKDash short_dashed[] = {2, 2};
1801 static const wxGTKDash wxCoord_dashed[] = {2, 4};
1802 static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3};
7d5af6fa 1803
112c5086
RR
1804 // We express dash pattern in pen width unit, so we are
1805 // independent of zoom factor and so on...
1806 int req_nb_dash;
2eca425d 1807 const wxGTKDash *req_dash;
7d5af6fa 1808
265898fd
RR
1809 GdkLineStyle lineStyle = GDK_LINE_SOLID;
1810 switch (m_pen.GetStyle())
1811 {
112c5086 1812 case wxUSER_DASH:
7d5af6fa
VZ
1813 {
1814 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086 1815 req_nb_dash = m_pen.GetDashCount();
2eca425d 1816 req_dash = (wxGTKDash*)m_pen.GetDash();
112c5086 1817 break;
7d5af6fa
VZ
1818 }
1819 case wxDOT:
1820 {
1821 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
1822 req_nb_dash = 2;
1823 req_dash = dotted;
7d5af6fa
VZ
1824 break;
1825 }
1826 case wxLONG_DASH:
1827 {
1828 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086 1829 req_nb_dash = 2;
72cdf4c9 1830 req_dash = wxCoord_dashed;
7d5af6fa
VZ
1831 break;
1832 }
1833 case wxSHORT_DASH:
1834 {
1835 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
1836 req_nb_dash = 2;
1837 req_dash = short_dashed;
7d5af6fa
VZ
1838 break;
1839 }
1840 case wxDOT_DASH:
1841 {
1842// lineStyle = GDK_LINE_DOUBLE_DASH;
1843 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
1844 req_nb_dash = 4;
1845 req_dash = dotted_dashed;
7d5af6fa
VZ
1846 break;
1847 }
1848
1849 case wxTRANSPARENT:
72174350 1850 case wxSTIPPLE_MASK_OPAQUE:
7d5af6fa
VZ
1851 case wxSTIPPLE:
1852 case wxSOLID:
1853 default:
1854 {
1855 lineStyle = GDK_LINE_SOLID;
2eca425d 1856 req_dash = (wxGTKDash*)NULL;
112c5086 1857 req_nb_dash = 0;
7d5af6fa
VZ
1858 break;
1859 }
265898fd 1860 }
7d5af6fa 1861
112c5086
RR
1862 if (req_dash && req_nb_dash)
1863 {
2eca425d 1864 wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash];
112c5086
RR
1865 if (real_req_dash)
1866 {
1867 for (int i = 0; i < req_nb_dash; i++)
1868 real_req_dash[i] = req_dash[i] * width;
2eca425d 1869 gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash );
112c5086
RR
1870 delete[] real_req_dash;
1871 }
1872 else
1873 {
1874 // No Memory. We use non-scaled dash pattern...
2eca425d 1875 gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash );
112c5086
RR
1876 }
1877 }
7d5af6fa 1878
265898fd
RR
1879 GdkCapStyle capStyle = GDK_CAP_ROUND;
1880 switch (m_pen.GetCap())
1881 {
265898fd
RR
1882 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
1883 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
d4aa3a4b
RR
1884 case wxCAP_ROUND:
1885 default:
72174350 1886 {
d4aa3a4b
RR
1887 if (width <= 1)
1888 {
1889 width = 0;
1890 capStyle = GDK_CAP_NOT_LAST;
1891 }
1892 else
1893 {
1894 capStyle = GDK_CAP_ROUND;
1895 }
72174350 1896 break;
d4aa3a4b 1897 }
265898fd 1898 }
7d5af6fa 1899
265898fd
RR
1900 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
1901 switch (m_pen.GetJoin())
1902 {
1903 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
265898fd 1904 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
d4aa3a4b
RR
1905 case wxJOIN_ROUND:
1906 default: { joinStyle = GDK_JOIN_ROUND; break; }
265898fd 1907 }
7d5af6fa 1908
265898fd 1909 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
7d5af6fa 1910
265898fd
RR
1911 m_pen.GetColour().CalcPixel( m_cmap );
1912 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
903f689b 1913}
c801d85f 1914
ec758a20 1915void wxWindowDC::SetBrush( const wxBrush &brush )
c801d85f 1916{
223d09f6 1917 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1918
265898fd 1919 if (m_brush == brush) return;
7d5af6fa 1920
265898fd 1921 m_brush = brush;
7d5af6fa 1922
265898fd 1923 if (!m_brush.Ok()) return;
7d5af6fa 1924
6db90681 1925 if (!m_window) return;
7d5af6fa 1926
265898fd
RR
1927 m_brush.GetColour().CalcPixel( m_cmap );
1928 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
7d5af6fa 1929
956dbab1 1930 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
7d5af6fa 1931
4fcd73bd 1932 if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
265898fd 1933 {
b85229d1 1934 if (m_brush.GetStipple()->GetDepth() != 1)
7d5af6fa 1935 {
956dbab1 1936 gdk_gc_set_fill( m_brushGC, GDK_TILED );
cd25b18c 1937 gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
7d5af6fa 1938 }
b0e0d661 1939 else
7d5af6fa 1940 {
956dbab1 1941 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
b85229d1 1942 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
7d5af6fa 1943 }
265898fd 1944 }
7d5af6fa 1945
de2d2cdc
VZ
1946 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
1947 {
e1208c31
RR
1948 gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED);
1949 gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() );
de2d2cdc
VZ
1950 }
1951
ab9d0a8c 1952 if (m_brush.IsHatch())
265898fd 1953 {
956dbab1 1954 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
265898fd
RR
1955 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
1956 gdk_gc_set_stipple( m_brushGC, hatches[num] );
1957 }
903f689b 1958}
c801d85f 1959
ec758a20 1960void wxWindowDC::SetBackground( const wxBrush &brush )
46dc76ba 1961{
bbbbe360
RR
1962 /* CMB 21/7/98: Added SetBackground. Sets background brush
1963 * for Clear() and bg colour for shapes filled with cross-hatch brush */
7d5af6fa 1964
223d09f6 1965 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1966
265898fd 1967 if (m_backgroundBrush == brush) return;
7d5af6fa 1968
265898fd 1969 m_backgroundBrush = brush;
7d5af6fa 1970
265898fd 1971 if (!m_backgroundBrush.Ok()) return;
7d5af6fa 1972
6db90681 1973 if (!m_window) return;
7d5af6fa 1974
265898fd
RR
1975 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
1976 gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
a802c3a1 1977 gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
031b2a7b 1978 gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
265898fd 1979 gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
3417c2cd
RR
1980
1981 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
7d5af6fa 1982
cd25b18c 1983 if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
265898fd 1984 {
b85229d1 1985 if (m_backgroundBrush.GetStipple()->GetDepth() != 1)
7d5af6fa 1986 {
3417c2cd 1987 gdk_gc_set_fill( m_bgGC, GDK_TILED );
fd128b0c 1988 gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
7d5af6fa 1989 }
cd25b18c 1990 else
7d5af6fa 1991 {
3417c2cd 1992 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
b85229d1 1993 gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
7d5af6fa 1994 }
265898fd 1995 }
7d5af6fa 1996
ab9d0a8c 1997 if (m_backgroundBrush.IsHatch())
265898fd 1998 {
3417c2cd 1999 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
265898fd
RR
2000 int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
2001 gdk_gc_set_stipple( m_bgGC, hatches[num] );
bbbbe360 2002 }
903f689b 2003}
46dc76ba 2004
ec758a20 2005void wxWindowDC::SetLogicalFunction( int function )
c801d85f 2006{
223d09f6 2007 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2008
72174350
VZ
2009 if (m_logicalFunction == function)
2010 return;
2011
2012 // VZ: shouldn't this be a CHECK?
2013 if (!m_window)
2014 return;
01eaf507 2015
2b5f62a0 2016 GdkFunction mode;
265898fd
RR
2017 switch (function)
2018 {
3c679789
RR
2019 case wxXOR: mode = GDK_XOR; break;
2020 case wxINVERT: mode = GDK_INVERT; break;
3c679789
RR
2021 case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
2022 case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
2023 case wxCLEAR: mode = GDK_CLEAR; break;
2024 case wxSET: mode = GDK_SET; break;
2025 case wxOR_INVERT: mode = GDK_OR_INVERT; break;
2026 case wxAND: mode = GDK_AND; break;
2027 case wxOR: mode = GDK_OR; break;
2028 case wxEQUIV: mode = GDK_EQUIV; break;
2029 case wxNAND: mode = GDK_NAND; break;
2030 case wxAND_INVERT: mode = GDK_AND_INVERT; break;
7d5af6fa
VZ
2031 case wxCOPY: mode = GDK_COPY; break;
2032 case wxNO_OP: mode = GDK_NOOP; break;
2033 case wxSRC_INVERT: mode = GDK_COPY_INVERT; break;
72174350 2034
2d52841d
RR
2035 // unsupported by GTK
2036 case wxNOR: mode = GDK_COPY; break;
01eaf507 2037 default:
223d09f6 2038 wxFAIL_MSG( wxT("unsupported logical function") );
2b5f62a0 2039 mode = GDK_COPY;
265898fd 2040 }
7d5af6fa 2041
265898fd 2042 m_logicalFunction = function;
7d5af6fa 2043
265898fd
RR
2044 gdk_gc_set_function( m_penGC, mode );
2045 gdk_gc_set_function( m_brushGC, mode );
72174350
VZ
2046
2047 // to stay compatible with wxMSW, we don't apply ROPs to the text
3d2d8da1
RR
2048 // operations (i.e. DrawText/DrawRotatedText).
2049 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2050 gdk_gc_set_function( m_textGC, mode );
903f689b 2051}
c801d85f 2052
ec758a20 2053void wxWindowDC::SetTextForeground( const wxColour &col )
c801d85f 2054{
223d09f6 2055 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2056
71ec83d2
VZ
2057 // don't set m_textForegroundColour to an invalid colour as we'd crash
2058 // later then (we use m_textForegroundColour.GetColor() without checking
2059 // in a few places)
2060 if ( !col.Ok() || (m_textForegroundColour == col) )
2061 return;
7d5af6fa 2062
265898fd 2063 m_textForegroundColour = col;
7d5af6fa 2064
71ec83d2
VZ
2065 if ( m_window )
2066 {
2067 m_textForegroundColour.CalcPixel( m_cmap );
2068 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
2069 }
903f689b 2070}
c801d85f 2071
ec758a20 2072void wxWindowDC::SetTextBackground( const wxColour &col )
c801d85f 2073{
223d09f6 2074 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2075
71ec83d2
VZ
2076 // same as above
2077 if ( !col.Ok() || (m_textBackgroundColour == col) )
2078 return;
7d5af6fa 2079
265898fd 2080 m_textBackgroundColour = col;
7d5af6fa 2081
71ec83d2
VZ
2082 if ( m_window )
2083 {
2084 m_textBackgroundColour.CalcPixel( m_cmap );
2085 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
2086 }
903f689b 2087}
c801d85f 2088
ec758a20 2089void wxWindowDC::SetBackgroundMode( int mode )
c801d85f 2090{
223d09f6 2091 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2092
265898fd 2093 m_backgroundMode = mode;
46dc76ba 2094
6db90681 2095 if (!m_window) return;
7d5af6fa 2096
265898fd
RR
2097 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2098 // transparent/solid background mode
7d5af6fa 2099
265898fd
RR
2100 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
2101 {
2102 gdk_gc_set_fill( m_brushGC,
2103 (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
2104 }
903f689b 2105}
c801d85f 2106
ec758a20 2107void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
c801d85f 2108{
223d09f6 2109 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
903f689b 2110}
c801d85f 2111
72cdf4c9 2112void wxWindowDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
c801d85f 2113{
223d09f6 2114 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2115
6db90681 2116 if (!m_window) return;
7d5af6fa 2117
3d2d8da1 2118 wxRect rect;
265898fd
RR
2119 rect.x = XLOG2DEV(x);
2120 rect.y = YLOG2DEV(y);
2121 rect.width = XLOG2DEVREL(width);
2122 rect.height = YLOG2DEVREL(height);
5f170f33 2123
e1208c31 2124 if (!m_currentClippingRegion.IsNull())
993f97ee
RR
2125 m_currentClippingRegion.Intersect( rect );
2126 else
2127 m_currentClippingRegion.Union( rect );
5f170f33
VZ
2128
2129#if USE_PAINT_REGION
e1208c31 2130 if (!m_paintClippingRegion.IsNull())
3d2d8da1 2131 m_currentClippingRegion.Intersect( m_paintClippingRegion );
809934d2 2132#endif
3d2d8da1 2133
ee8dbe63
RL
2134 wxCoord xx, yy, ww, hh;
2135 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2136 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2137
3d2d8da1
RR
2138 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2139 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2140 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2141 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
903f689b 2142}
c801d85f 2143
b0e0d661 2144void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion &region )
463c1fa1 2145{
223d09f6 2146 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2147
463c1fa1
RR
2148 if (region.Empty())
2149 {
2150 DestroyClippingRegion();
2151 return;
2152 }
7d5af6fa 2153
6db90681 2154 if (!m_window) return;
5f170f33 2155
e1208c31 2156 if (!m_currentClippingRegion.IsNull())
993f97ee
RR
2157 m_currentClippingRegion.Intersect( region );
2158 else
2159 m_currentClippingRegion.Union( region );
5f170f33
VZ
2160
2161#if USE_PAINT_REGION
e1208c31 2162 if (!m_paintClippingRegion.IsNull())
3d2d8da1 2163 m_currentClippingRegion.Intersect( m_paintClippingRegion );
809934d2 2164#endif
3d2d8da1 2165
ee8dbe63
RL
2166 wxCoord xx, yy, ww, hh;
2167 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2168 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2169
3d2d8da1
RR
2170 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2171 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2172 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2173 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
463c1fa1
RR
2174}
2175
4bc67cc5 2176void wxWindowDC::DestroyClippingRegion()
c801d85f 2177{
223d09f6 2178 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2179
265898fd 2180 wxDC::DestroyClippingRegion();
7d5af6fa 2181
3d2d8da1 2182 m_currentClippingRegion.Clear();
5f170f33
VZ
2183
2184#if USE_PAINT_REGION
3d2d8da1
RR
2185 if (!m_paintClippingRegion.IsEmpty())
2186 m_currentClippingRegion.Union( m_paintClippingRegion );
993f97ee 2187#endif
3d2d8da1 2188
6db90681 2189 if (!m_window) return;
7d5af6fa 2190
3d2d8da1
RR
2191 if (m_currentClippingRegion.IsEmpty())
2192 {
2193 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
2194 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
2195 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
2196 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
2197 }
2198 else
2199 {
2200 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2201 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2202 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2203 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
2204 }
903f689b 2205}
c801d85f 2206
4bc67cc5 2207void wxWindowDC::Destroy()
dbf858b5 2208{
3d2d8da1 2209 if (m_penGC) wxFreePoolGC( m_penGC );
265898fd 2210 m_penGC = (GdkGC*) NULL;
3d2d8da1 2211 if (m_brushGC) wxFreePoolGC( m_brushGC );
265898fd 2212 m_brushGC = (GdkGC*) NULL;
3d2d8da1 2213 if (m_textGC) wxFreePoolGC( m_textGC );
265898fd 2214 m_textGC = (GdkGC*) NULL;
3d2d8da1 2215 if (m_bgGC) wxFreePoolGC( m_bgGC );
265898fd 2216 m_bgGC = (GdkGC*) NULL;
dbf858b5
RR
2217}
2218
847dfdb4
RR
2219void wxWindowDC::SetDeviceOrigin( wxCoord x, wxCoord y )
2220{
2221 m_deviceOriginX = x;
2222 m_deviceOriginY = y;
2223
2224 ComputeScaleAndOrigin();
2225}
2226
2227void wxWindowDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
2228{
2229 m_signX = (xLeftRight ? 1 : -1);
2230 m_signY = (yBottomUp ? -1 : 1);
2231
2232 if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
2233 m_signX = -m_signX;
2234
2235 ComputeScaleAndOrigin();
2236}
2237
238d735d
RR
2238void wxWindowDC::ComputeScaleAndOrigin()
2239{
c77a6796 2240 const wxRealPoint origScale(m_scaleX, m_scaleY);
238d735d
RR
2241
2242 wxDC::ComputeScaleAndOrigin();
2243
c77a6796
VZ
2244 // if scale has changed call SetPen to recalulate the line width
2245 if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.Ok() )
238d735d 2246 {
c77a6796
VZ
2247 // this is a bit artificial, but we need to force wxDC to think the pen
2248 // has changed
0a164d4c
WS
2249 wxPen pen = m_pen;
2250 m_pen = wxNullPen;
2251 SetPen( pen );
2252 }
238d735d
RR
2253}
2254
b0e0d661
VZ
2255// Resolution in pixels per logical inch
2256wxSize wxWindowDC::GetPPI() const
2257{
7a5e6267 2258 return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5));
b0e0d661
VZ
2259}
2260
2261int wxWindowDC::GetDepth() const
c801d85f 2262{
ace35c62 2263 return gdk_drawable_get_depth(m_window);
903f689b 2264}
c801d85f 2265
ec758a20
RR
2266
2267//-----------------------------------------------------------------------------
2268// wxPaintDC
2269//-----------------------------------------------------------------------------
2270
f469b27c 2271IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
ec758a20 2272
2cfddfe7
JS
2273// Limit the paint region to the window size. Sometimes
2274// the paint region is too big, and this risks X11 errors
2275static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz)
2276{
2277 wxRect originalRect = region.GetBox();
2278 wxRect rect(originalRect);
2279 if (rect.width + rect.x > sz.x)
2280 rect.width = sz.x - rect.x;
2281 if (rect.height + rect.y > sz.y)
2282 rect.height = sz.y - rect.y;
2283 if (rect != originalRect)
2284 {
2285 region = wxRegion(rect);
2286 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2287 originalRect.x, originalRect.y, originalRect.width, originalRect.height,
2288 rect.x, rect.y, rect.width, rect.height);
2289 }
2290}
2291
ec758a20 2292wxPaintDC::wxPaintDC( wxWindow *win )
f469b27c 2293 : wxClientDC( win )
ec758a20 2294{
b6fa52db
RR
2295#if USE_PAINT_REGION
2296 if (!win->m_clipPaintRegion)
2297 return;
f469b27c 2298
2cfddfe7 2299 wxSize sz = win->GetSize();
e1208c31 2300 m_paintClippingRegion = win->GetUpdateRegion();
2cfddfe7 2301 wxLimitRegionToSize(m_paintClippingRegion, sz);
ab9d0a8c 2302
5f170f33
VZ
2303 GdkRegion *region = m_paintClippingRegion.GetRegion();
2304 if ( region )
2305 {
823faac3 2306 m_currentClippingRegion.Union( m_paintClippingRegion );
2cfddfe7
JS
2307 wxLimitRegionToSize(m_currentClippingRegion, sz);
2308
2309 if (sz.x <= 0 || sz.y <= 0)
2310 return ;
5f170f33 2311
823faac3
JS
2312 gdk_gc_set_clip_region( m_penGC, region );
2313 gdk_gc_set_clip_region( m_brushGC, region );
2314 gdk_gc_set_clip_region( m_textGC, region );
2315 gdk_gc_set_clip_region( m_bgGC, region );
5f170f33 2316 }
1e6feb95 2317#endif // USE_PAINT_REGION
ec758a20
RR
2318}
2319
2320//-----------------------------------------------------------------------------
2321// wxClientDC
2322//-----------------------------------------------------------------------------
2323
f469b27c 2324IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
ec758a20 2325
f469b27c
VZ
2326wxClientDC::wxClientDC( wxWindow *win )
2327 : wxWindowDC( win )
ec758a20 2328{
4f55a07f
VZ
2329 wxCHECK_RET( win, _T("NULL window in wxClientDC::wxClientDC") );
2330
1e6feb95
VZ
2331#ifdef __WXUNIVERSAL__
2332 wxPoint ptOrigin = win->GetClientAreaOrigin();
2333 SetDeviceOrigin(ptOrigin.x, ptOrigin.y);
2334 wxSize size = win->GetClientSize();
2335 SetClippingRegion(wxPoint(0, 0), size);
2336#endif // __WXUNIVERSAL__
ec758a20
RR
2337}
2338
4f55a07f
VZ
2339void wxClientDC::DoGetSize(int *width, int *height) const
2340{
2341 wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") );
2342
2343 m_owner->GetClientSize( width, height );
2344}
2345
3d2d8da1
RR
2346// ----------------------------------------------------------------------------
2347// wxDCModule
2348// ----------------------------------------------------------------------------
2349
2350class wxDCModule : public wxModule
2351{
2352public:
2353 bool OnInit();
2354 void OnExit();
2355
2356private:
2357 DECLARE_DYNAMIC_CLASS(wxDCModule)
2358};
2359
2360IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
2361
2362bool wxDCModule::OnInit()
2363{
2364 wxInitGCPool();
ab9d0a8c 2365 return true;
3d2d8da1
RR
2366}
2367
2368void wxDCModule::OnExit()
2369{
2370 wxCleanUpGCPool();
2371}