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