]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcclient.cpp
compilation fix for PCH-less build
[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#if !GTK_CHECK_VERSION(2,2,0)
1117 // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code.
1118 // Pixbufs-based bitmaps with alpha channel don't have a mask, so we
1119 // have to call GetPixmap() here -- it converts the pixbuf into pixmap
1120 // and also creates the mask as a side-effect:
1121 use_bitmap.GetPixmap();
1122#endif
ab9d0a8c 1123
d90c9596 1124 // apply mask if any
463c1fa1 1125 GdkBitmap *mask = (GdkBitmap *) NULL;
280831d5
PC
1126 if (useMask && use_bitmap.GetMask())
1127 mask = use_bitmap.GetMask()->GetBitmap();
1128
1129 GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
7d5af6fa 1130
d90c9596 1131 GdkBitmap *new_mask = (GdkBitmap*) NULL;
ab9d0a8c 1132
280831d5 1133 if (mask != NULL)
d90c9596
RR
1134 {
1135 if (!m_currentClippingRegion.IsNull())
82ea63e6 1136 {
d90c9596
RR
1137 GdkColor col;
1138 new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 );
1139 GdkGC *gc = gdk_gc_new( new_mask );
1140 col.pixel = 0;
1141 gdk_gc_set_foreground( gc, &col );
1142 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
1143 col.pixel = 0;
1144 gdk_gc_set_background( gc, &col );
1145 col.pixel = 1;
1146 gdk_gc_set_foreground( gc, &col );
1147 gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
1148 gdk_gc_set_clip_origin( gc, -xx, -yy );
1149 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
1150 gdk_gc_set_stipple( gc, mask );
1151 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
280831d5 1152 mask = new_mask;
3fe39b0c 1153 g_object_unref (gc);
d90c9596 1154 }
ab9d0a8c 1155
280831d5
PC
1156 gdk_gc_set_clip_mask(use_gc, mask);
1157 gdk_gc_set_clip_origin(use_gc, xx, yy);
d90c9596 1158 }
7d5af6fa 1159
d90c9596
RR
1160 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1161 // drawing a mono-bitmap (XBitmap) we use the current text GC
82ea63e6 1162 if (is_mono)
d90c9596 1163 {
4e115ed2
VZ
1164 GdkPixmap *bitmap2 = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, -1 );
1165 GdkGC *gc = gdk_gc_new( bitmap2 );
d90c9596
RR
1166 gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
1167 gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
b85229d1 1168 gdk_wx_draw_bitmap( bitmap2, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
ab9d0a8c 1169
280831d5 1170 gdk_draw_drawable(m_window, use_gc, bitmap2, 0, 0, xx, yy, -1, -1);
ab9d0a8c 1171
3fe39b0c
MR
1172 g_object_unref (bitmap2);
1173 g_object_unref (gc);
d90c9596 1174 }
82ea63e6 1175 else
d90c9596 1176 {
feac7937 1177#if GTK_CHECK_VERSION(2,2,0)
cc35003a 1178 if (!gtk_check_version(2,2,0) && use_bitmap.HasPixbuf())
feac7937 1179 {
280831d5 1180 gdk_draw_pixbuf(m_window, use_gc,
feac7937
VS
1181 use_bitmap.GetPixbuf(),
1182 0, 0, xx, yy, -1, -1,
1183 GDK_RGB_DITHER_NORMAL, xx, yy);
1184 }
1185 else
1186#endif
1187 {
280831d5 1188 gdk_draw_drawable(m_window, use_gc,
15f0ad70
MR
1189 use_bitmap.GetPixmap(),
1190 0, 0, xx, yy, -1, -1);
feac7937 1191 }
d90c9596 1192 }
72174350 1193
d90c9596 1194 // remove mask again if any
280831d5 1195 if (mask != NULL)
463c1fa1 1196 {
280831d5
PC
1197 gdk_gc_set_clip_mask(use_gc, NULL);
1198 gdk_gc_set_clip_origin(use_gc, 0, 0);
1199 if (!m_currentClippingRegion.IsNull())
1200 gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
1201 if (new_mask != NULL)
1202 g_object_unref(new_mask);
463c1fa1 1203 }
463c1fa1
RR
1204}
1205
2970ae54 1206bool wxGTKWindowImplDC::DoBlit( wxCoord xdest, wxCoord ydest,
1e6feb95
VZ
1207 wxCoord width, wxCoord height,
1208 wxDC *source,
1209 wxCoord xsrc, wxCoord ysrc,
1210 int logical_func,
0cbff120
JS
1211 bool useMask,
1212 wxCoord xsrcMask, wxCoord ysrcMask )
c801d85f 1213{
ab9d0a8c 1214 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
7d5af6fa 1215
ab9d0a8c 1216 wxCHECK_MSG( source, false, wxT("invalid source dc") );
7d5af6fa 1217
ab9d0a8c 1218 if (!m_window) return false;
7d5af6fa 1219
1e6feb95 1220 // transform the source DC coords to the device ones
772b3767
PC
1221 xsrc = source->LogicalToDeviceX(xsrc);
1222 ysrc = source->LogicalToDeviceY(ysrc);
1e6feb95 1223
e19a8aea 1224 wxBitmap selected;
f98bd6d6 1225 wxMemoryDC *memDC = wxDynamicCast(source, wxMemoryDC);
e19a8aea
VZ
1226 if ( memDC )
1227 {
1228 selected = memDC->GetSelectedBitmap();
1229 if ( !selected.IsOk() )
1230 return false;
1231 }
f4322df6 1232
ab9d0a8c
WS
1233 bool use_bitmap_method = false;
1234 bool is_mono = false;
7d5af6fa 1235
0cbff120
JS
1236 if (xsrcMask == -1 && ysrcMask == -1)
1237 {
d90c9596
RR
1238 xsrcMask = xsrc;
1239 ysrcMask = ysrc;
0cbff120
JS
1240 }
1241
f98bd6d6 1242 if (selected.Ok())
6e13c196 1243 {
f98bd6d6 1244 is_mono = (selected.GetDepth() == 1);
d90c9596
RR
1245
1246 // we use the "XCopyArea" way to copy a memory dc into
1247 // a different window if the memory dc BOTH
1248 // a) doesn't have any mask or its mask isn't used
1249 // b) it is clipped
1250 // c) is not 1-bit
7d5af6fa 1251
f98bd6d6 1252 if (useMask && (selected.GetMask()))
b0e0d661 1253 {
d90c9596
RR
1254 // we HAVE TO use the direct way for memory dcs
1255 // that have mask since the XCopyArea doesn't know
1256 // about masks
ab9d0a8c 1257 use_bitmap_method = true;
b0e0d661 1258 }
d90c9596 1259 else if (is_mono)
b0e0d661 1260 {
d90c9596
RR
1261 // we HAVE TO use the direct way for memory dcs
1262 // that are bitmaps because XCopyArea doesn't cope
1263 // with different bit depths
ab9d0a8c 1264 use_bitmap_method = true;
b0e0d661
VZ
1265 }
1266 else if ((xsrc == 0) && (ysrc == 0) &&
f98bd6d6
RD
1267 (width == selected.GetWidth()) &&
1268 (height == selected.GetHeight()))
b0e0d661 1269 {
d90c9596
RR
1270 // we SHOULD use the direct way if all of the bitmap
1271 // in the memory dc is copied in which case XCopyArea
1272 // wouldn't be able able to boost performace by reducing
1273 // the area to be scaled
ab9d0a8c 1274 use_bitmap_method = true;
b0e0d661 1275 }
6e13c196 1276 }
7d5af6fa 1277
265898fd
RR
1278 CalcBoundingBox( xdest, ydest );
1279 CalcBoundingBox( xdest + width, ydest + height );
7d5af6fa 1280
d90c9596 1281 // scale/translate size and position
3d2d8da1
RR
1282 wxCoord xx = XLOG2DEV(xdest);
1283 wxCoord yy = YLOG2DEV(ydest);
1284
1285 wxCoord ww = XLOG2DEVREL(width);
1286 wxCoord hh = YLOG2DEVREL(height);
1287
d90c9596 1288 // compare to current clipping region
e1208c31 1289 if (!m_currentClippingRegion.IsNull())
3d2d8da1
RR
1290 {
1291 wxRegion tmp( xx,yy,ww,hh );
1292 tmp.Intersect( m_currentClippingRegion );
1293 if (tmp.IsEmpty())
ab9d0a8c 1294 return true;
3d2d8da1
RR
1295 }
1296
4bc67cc5
RR
1297 int old_logical_func = m_logicalFunction;
1298 SetLogicalFunction( logical_func );
5f170f33 1299
6e13c196 1300 if (use_bitmap_method)
6f65e337 1301 {
d90c9596 1302 // scale/translate bitmap size
f98bd6d6
RD
1303 wxCoord bm_width = selected.GetWidth();
1304 wxCoord bm_height = selected.GetHeight();
7d5af6fa 1305
551b5391
RR
1306 // Get clip coords for the bitmap. If we don't
1307 // use wxBitmap::Rescale(), which can clip the
1308 // bitmap, these are the same as the original
1309 // coordinates
1310 wxCoord cx = xx;
1311 wxCoord cy = yy;
1312 wxCoord cw = ww;
1313 wxCoord ch = hh;
ab9d0a8c 1314
d90c9596
RR
1315 // interpret userscale of src too
1316 double xsc,ysc;
1317 memDC->GetUserScale(&xsc,&ysc);
1318 bm_width = (int) (bm_width / xsc);
1319 bm_height = (int) (bm_height / ysc);
1320
72cdf4c9
VZ
1321 wxCoord bm_ww = XLOG2DEVREL( bm_width );
1322 wxCoord bm_hh = YLOG2DEVREL( bm_height );
7d5af6fa 1323
551b5391 1324 // Scale bitmap if required
f98bd6d6
RD
1325 wxBitmap use_bitmap = selected;
1326 if ((selected.GetWidth()!= bm_ww) || ( selected.GetHeight()!= bm_hh))
6e13c196 1327 {
551b5391
RR
1328 // This indicates that the blitting code below will get
1329 // a clipped bitmap and therefore needs to move the origin
1330 // accordingly
1331 wxRegion tmp( xx,yy,ww,hh );
93da796d
RR
1332 if (!m_currentClippingRegion.IsNull())
1333 tmp.Intersect( m_currentClippingRegion );
551b5391 1334 tmp.GetBox(cx,cy,cw,ch);
ab9d0a8c 1335
551b5391 1336 // Scale and clipped bitmap
f98bd6d6 1337 use_bitmap = selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh);
6e13c196 1338 }
7d5af6fa 1339
d90c9596 1340 // apply mask if any
6e13c196 1341 GdkBitmap *mask = (GdkBitmap *) NULL;
280831d5
PC
1342 if (useMask && use_bitmap.GetMask())
1343 mask = use_bitmap.GetMask()->GetBitmap();
1344
1345 GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
7d5af6fa 1346
d90c9596 1347 GdkBitmap *new_mask = (GdkBitmap*) NULL;
ab9d0a8c 1348
280831d5 1349 if (mask != NULL)
6e13c196 1350 {
e1208c31 1351 if (!m_currentClippingRegion.IsNull())
3d2d8da1
RR
1352 {
1353 GdkColor col;
c2fa61e8 1354 new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 );
3d2d8da1
RR
1355 GdkGC *gc = gdk_gc_new( new_mask );
1356 col.pixel = 0;
1357 gdk_gc_set_foreground( gc, &col );
b7a49654 1358 gdk_gc_set_ts_origin( gc, -xsrcMask, -ysrcMask);
3d2d8da1
RR
1359 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
1360 col.pixel = 0;
1361 gdk_gc_set_background( gc, &col );
1362 col.pixel = 1;
1363 gdk_gc_set_foreground( gc, &col );
1364 gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
d90c9596
RR
1365 // was: gdk_gc_set_clip_origin( gc, -xx, -yy );
1366 gdk_gc_set_clip_origin( gc, -cx, -cy );
3d2d8da1
RR
1367 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
1368 gdk_gc_set_stipple( gc, mask );
1369 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
280831d5 1370 mask = new_mask;
3fe39b0c 1371 g_object_unref (gc);
3d2d8da1 1372 }
d90c9596 1373
280831d5
PC
1374 gdk_gc_set_clip_mask(use_gc, mask);
1375 if (new_mask != NULL)
1376 gdk_gc_set_clip_origin(use_gc, cx, cy);
82ea63e6 1377 else
280831d5 1378 gdk_gc_set_clip_origin(use_gc, cx - xsrcMask, cy - ysrcMask);
6e13c196 1379 }
7d5af6fa 1380
d90c9596
RR
1381 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1382 // drawing a mono-bitmap (XBitmap) we use the current text GC
5f170f33 1383
82ea63e6 1384 if (is_mono)
d90c9596 1385 {
d90c9596
RR
1386 GdkPixmap *bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, -1 );
1387 GdkGC *gc = gdk_gc_new( bitmap );
1388 gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
1389 gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
b85229d1 1390 gdk_wx_draw_bitmap( bitmap, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
ab9d0a8c 1391
280831d5 1392 gdk_draw_drawable(m_window, use_gc, bitmap, xsrc, ysrc, cx, cy, cw, ch);
ab9d0a8c 1393
3fe39b0c
MR
1394 g_object_unref (bitmap);
1395 g_object_unref (gc);
d90c9596 1396 }
82ea63e6 1397 else
d90c9596 1398 {
15f0ad70 1399 // was: gdk_draw_drawable( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
280831d5 1400 gdk_draw_drawable(m_window, use_gc, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch);
d90c9596 1401 }
82ea63e6 1402
d90c9596 1403 // remove mask again if any
280831d5 1404 if (mask != NULL)
6e13c196 1405 {
280831d5
PC
1406 gdk_gc_set_clip_mask(use_gc, NULL);
1407 gdk_gc_set_clip_origin(use_gc, 0, 0);
1408 if (!m_currentClippingRegion.IsNull())
1409 gdk_gc_set_clip_region(use_gc, m_currentClippingRegion.GetRegion());
265898fd 1410 }
ab9d0a8c 1411
d90c9596 1412 if (new_mask)
3fe39b0c 1413 g_object_unref (new_mask);
6f65e337 1414 }
d90c9596 1415 else // use_bitmap_method
6e13c196 1416 {
f98bd6d6 1417 if (selected.Ok() && ((width != ww) || (height != hh)))
b0e0d661 1418 {
d90c9596
RR
1419 // get clip coords
1420 wxRegion tmp( xx,yy,ww,hh );
1421 tmp.Intersect( m_currentClippingRegion );
1422 wxCoord cx,cy,cw,ch;
1423 tmp.GetBox(cx,cy,cw,ch);
ab9d0a8c
WS
1424
1425 // rescale bitmap
f98bd6d6 1426 wxBitmap bitmap = selected.Rescale( cx-xx, cy-yy, cw, ch, ww, hh );
7d5af6fa 1427
d90c9596 1428 // draw scaled bitmap
15f0ad70
MR
1429 // was: gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1430 gdk_draw_drawable( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, cx, cy, -1, -1 );
b0e0d661
VZ
1431 }
1432 else
1433 {
ab9d0a8c 1434 // No scaling and not a memory dc with a mask either
993f97ee 1435
f98bd6d6
RD
1436 GdkWindow* window = source->GetGDKWindow();
1437 if ( !window )
1438 return false;
f4322df6 1439
d90c9596 1440 // copy including child window contents
a56fcaaf 1441 gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
15f0ad70 1442 gdk_draw_drawable( m_window, m_penGC,
f98bd6d6 1443 window,
15f0ad70
MR
1444 xsrc, ysrc, xx, yy,
1445 width, height );
a56fcaaf 1446 gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
b0e0d661 1447 }
6e13c196 1448 }
c801d85f 1449
4bc67cc5 1450 SetLogicalFunction( old_logical_func );
ab9d0a8c
WS
1451
1452 return true;
903f689b 1453}
c801d85f 1454
2970ae54 1455void wxGTKWindowImplDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
c801d85f 1456{
223d09f6 1457 wxCHECK_RET( Ok(), wxT("invalid window dc") );
18a2fa37 1458
6db90681 1459 if (!m_window) return;
ab9d0a8c 1460
2b5f62a0 1461 if (text.empty()) return;
7d5af6fa 1462
265898fd
RR
1463 x = XLOG2DEV(x);
1464 y = YLOG2DEV(y);
18a2fa37 1465
cfcc3932 1466 wxCHECK_RET( m_context, wxT("no Pango context") );
61850501 1467 wxCHECK_RET( m_layout, wxT("no Pango layout") );
cfcc3932 1468 wxCHECK_RET( m_fontdesc, wxT("no Pango font description") );
e4da1035 1469
24bbbfb1
RR
1470 gdk_pango_context_set_colormap( m_context, m_cmap );
1471
1dbeee57
VS
1472 bool underlined = m_font.Ok() && m_font.GetUnderlined();
1473
a3669332
VZ
1474 const wxCharBuffer data = wxGTK_CONV( text );
1475 if ( !data )
7706daf3 1476 return;
67a083dd
RR
1477 size_t datalen = strlen(data);
1478
5f4d1820
VZ
1479 // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
1480 // has been fixed and thus the hack implemented below should never be used
1481 static bool pangoOk = !wx_pango_version_check(1, 16, 0);
1482
1483 bool needshack = underlined && !pangoOk;
67a083dd
RR
1484 char *hackstring = NULL;
1485
1486 if (needshack)
1487 {
1488 // a PangoLayout which has leading/trailing spaces with underlined font
1489 // is not correctly drawn by this pango version: Pango won't underline the spaces.
1490 // This can be a problem; e.g. wxHTML rendering of underlined text relies on
1491 // this behaviour. To workaround this problem, we use a special hack here
1492 // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
1493 // empty space characters and give them a dummy colour attribute.
1494 // This will force Pango to underline the leading/trailing spaces, too.
1495
1496 // need to realloc the string to prepend & append our special characters
1497 hackstring = (char*)malloc((datalen+7)*sizeof(char));
1498
1499 // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1500 strcpy(hackstring, "\342\200\214");
1501
1502 // copy the user string
1503 memcpy(&hackstring[3], data, datalen);
1504
1505 // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
1506 strcpy(&hackstring[datalen+3], "\342\200\214");
1507
1508 // the special characters that we added require 6 additional bytes:
1509 datalen += 6;
1510
1511 pango_layout_set_text(m_layout, hackstring, datalen);
1512 }
1513 else
1514 {
1515 pango_layout_set_text(m_layout, data, datalen);
1516 }
ab9d0a8c 1517
1dbeee57
VS
1518 if (underlined)
1519 {
1520 PangoAttrList *attrs = pango_attr_list_new();
1521 PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1522 a->start_index = 0;
1523 a->end_index = datalen;
1524 pango_attr_list_insert(attrs, a);
67a083dd
RR
1525
1526 if (needshack)
1527 {
1528 // dummy colour for the leading space
1529 a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1530 a->start_index = 0;
1531 a->end_index = 1;
1532 pango_attr_list_insert(attrs, a);
1533
1534 // dummy colour for the trailing space
1535 a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
1536 a->start_index = datalen - 1;
1537 a->end_index = datalen;
1538 pango_attr_list_insert(attrs, a);
1539 }
1540
1dbeee57
VS
1541 pango_layout_set_attributes(m_layout, attrs);
1542 pango_attr_list_unref(attrs);
1543 }
e4da1035 1544
76b20467 1545 int w,h;
fa499247
RR
1546
1547 if (fabs(m_scaleY - 1.0) > 0.00001)
e4da1035
RR
1548 {
1549 // If there is a user or actually any scale applied to
1550 // the device context, scale the font.
ab9d0a8c 1551
e4da1035
RR
1552 // scale font description
1553 gint oldSize = pango_font_description_get_size( m_fontdesc );
1554 double size = oldSize;
1555 size = size * m_scaleY;
1556 pango_font_description_set_size( m_fontdesc, (gint)size );
ab9d0a8c 1557
e4da1035
RR
1558 // actually apply scaled font
1559 pango_layout_set_font_description( m_layout, m_fontdesc );
ab9d0a8c 1560
76b20467
VS
1561 pango_layout_get_pixel_size( m_layout, &w, &h );
1562 if ( m_backgroundMode == wxSOLID )
1563 {
1564 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1565 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1566 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1567 }
ab9d0a8c 1568
e4da1035 1569 // Draw layout.
847dfdb4
RR
1570 if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
1571 gdk_draw_layout( m_window, m_textGC, x-w, y, m_layout );
1572 else
1573 gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
ab9d0a8c 1574
e4da1035
RR
1575 // reset unscaled size
1576 pango_font_description_set_size( m_fontdesc, oldSize );
ab9d0a8c 1577
61850501 1578 // actually apply unscaled font
e4da1035
RR
1579 pango_layout_set_font_description( m_layout, m_fontdesc );
1580 }
1581 else
1582 {
76b20467
VS
1583 pango_layout_get_pixel_size( m_layout, &w, &h );
1584 if ( m_backgroundMode == wxSOLID )
1585 {
1586 gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
1587 gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
1588 gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
1589 }
f4322df6 1590
76b20467 1591 // Draw layout.
847dfdb4
RR
1592 if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
1593 gdk_draw_layout( m_window, m_textGC, x-w, y, m_layout );
1594 else
1595 gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
8943b403 1596 }
1dbeee57
VS
1597
1598 if (underlined)
1599 {
1600 // undo underline attributes setting:
1601 pango_layout_set_attributes(m_layout, NULL);
1602 }
ab9d0a8c 1603
2b5f62a0
VZ
1604 wxCoord width = w;
1605 wxCoord height = h;
ab9d0a8c 1606
8943b403
OK
1607 width = wxCoord(width / m_scaleX);
1608 height = wxCoord(height / m_scaleY);
1609 CalcBoundingBox (x + width, y + height);
265898fd 1610 CalcBoundingBox (x, y);
67a083dd
RR
1611
1612 if (hackstring)
1613 free(hackstring);
903f689b 1614}
c801d85f 1615
bf47e398
RD
1616
1617// TODO: There is an example of rotating text with GTK2 that would probably be
1618// a better approach here:
1619// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
1620
2970ae54 1621void wxGTKWindowImplDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
95724b1a 1622{
1c2d839f
PC
1623 if (!m_window || text.empty())
1624 return;
1625
1626 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1627
c77a6796 1628 if ( wxIsNullDouble(angle) )
95724b1a
VZ
1629 {
1630 DrawText(text, x, y);
1631 return;
1632 }
1633
bf47e398
RD
1634 wxCoord w;
1635 wxCoord h;
1636
68567a96 1637 // TODO: implement later without GdkFont for GTK 2.0
bf47e398 1638 GetTextExtent(text, &w, &h, NULL,NULL, &m_font);
ab9d0a8c 1639
9a8c7620
VZ
1640 // draw the string normally
1641 wxBitmap src(w, h);
95724b1a
VZ
1642 wxMemoryDC dc;
1643 dc.SelectObject(src);
1644 dc.SetFont(GetFont());
f1c72f0c 1645 dc.SetBackground(*wxBLACK_BRUSH);
95724b1a
VZ
1646 dc.SetBrush(*wxBLACK_BRUSH);
1647 dc.Clear();
f1c72f0c 1648 dc.SetTextForeground( *wxWHITE );
95724b1a 1649 dc.DrawText(text, 0, 0);
9a8c7620 1650 dc.SelectObject(wxNullBitmap);
95724b1a
VZ
1651
1652 // Calculate the size of the rotated bounding box.
9a8c7620
VZ
1653 double rad = DegToRad(angle);
1654 double dx = cos(rad),
1655 dy = sin(rad);
1656
1657 // the rectngle vertices are counted clockwise with the first one being at
1658 // (0, 0) (or, rather, at (x, y))
1659 double x2 = w*dx,
1660 y2 = -w*dy; // y axis points to the bottom, hence minus
1661 double x4 = h*dy,
1662 y4 = h*dx;
1663 double x3 = x4 + x2,
1664 y3 = y4 + y2;
ab9d0a8c 1665
72174350 1666 // calc max and min
9a8c7620
VZ
1667 wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5),
1668 maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5),
1669 minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
1670 minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
1671
72174350 1672
f1c72f0c 1673 wxImage image = src.ConvertToImage();
9a8c7620 1674
f1c72f0c
RR
1675 image.ConvertColourToAlpha( m_textForegroundColour.Red(),
1676 m_textForegroundColour.Green(),
1677 m_textForegroundColour.Blue() );
1678 image = image.Rotate( rad, wxPoint(0,0) );
ab9d0a8c 1679
1d65e535
RR
1680 int i_angle = (int) angle;
1681 i_angle = i_angle % 360;
c2cb80c8
KH
1682 if (i_angle < 0)
1683 i_angle += 360;
1d65e535
RR
1684 int xoffset = 0;
1685 if ((i_angle >= 90.0) && (i_angle < 270.0))
1686 xoffset = image.GetWidth();
1687 int yoffset = 0;
1688 if ((i_angle >= 0.0) && (i_angle < 180.0))
1689 yoffset = image.GetHeight();
ab9d0a8c 1690
1d65e535
RR
1691 if ((i_angle >= 0) && (i_angle < 90))
1692 yoffset -= (int)( cos(rad)*h );
1693 if ((i_angle >= 90) && (i_angle < 180))
ab9d0a8c 1694 xoffset -= (int)( sin(rad)*h );
1d65e535
RR
1695 if ((i_angle >= 180) && (i_angle < 270))
1696 yoffset -= (int)( cos(rad)*h );
1697 if ((i_angle >= 270) && (i_angle < 360))
1698 xoffset -= (int)( sin(rad)*h );
ab9d0a8c 1699
1d65e535
RR
1700 int i_x = x - xoffset;
1701 int i_y = y - yoffset;
ab9d0a8c 1702
f1c72f0c 1703 src = image;
1d65e535 1704 DoDrawBitmap( src, i_x, i_y, true );
9a8c7620 1705
95724b1a 1706
9a8c7620
VZ
1707 // it would be better to draw with non underlined font and draw the line
1708 // manually here (it would be more straight...)
1709#if 0
1710 if ( m_font.GetUnderlined() )
1711 {
1712 gdk_draw_line( m_window, m_textGC,
1713 XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent),
1714 XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent));
1715 }
1716#endif // 0
1717
9a8c7620
VZ
1718 // update the bounding box
1719 CalcBoundingBox(x + minX, y + minY);
1720 CalcBoundingBox(x + maxX, y + maxY);
95724b1a
VZ
1721}
1722
2970ae54 1723void wxGTKWindowImplDC::DoGetTextExtent(const wxString &string,
72cdf4c9
VZ
1724 wxCoord *width, wxCoord *height,
1725 wxCoord *descent, wxCoord *externalLeading,
c94f845b 1726 const wxFont *theFont) const
c801d85f 1727{
b1f0abe4
VZ
1728 if ( width )
1729 *width = 0;
1730 if ( height )
1731 *height = 0;
1732 if ( descent )
1733 *descent = 0;
1734 if ( externalLeading )
1735 *externalLeading = 0;
1736
ab9d0a8c 1737 if (string.empty())
48d011c8 1738 return;
ab9d0a8c 1739
bf5752a4
VZ
1740 // ensure that theFont is always non-NULL
1741 if ( !theFont || !theFont->Ok() )
1742 theFont = wx_const_cast(wxFont *, &m_font);
1743
1744 // and use it if it's valid
1745 if ( theFont->Ok() )
1746 {
1747 pango_layout_set_font_description
1748 (
1749 m_layout,
1750 theFont->GetNativeFontInfo()->description
1751 );
1752 }
ab9d0a8c 1753
2b5f62a0 1754 // Set layout's text
bf5752a4 1755 const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *theFont);
a1e101d0
VZ
1756 if ( !dataUTF8 )
1757 {
1758 // hardly ideal, but what else can we do if conversion failed?
1759 return;
1760 }
1761
1762 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
ab9d0a8c 1763
48d011c8
RR
1764 if (descent)
1765 {
ace35c62
RR
1766 int h;
1767 pango_layout_get_pixel_size( m_layout, width, &h );
f69e2009
VS
1768 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1769 int baseline = pango_layout_iter_get_baseline(iter);
1770 pango_layout_iter_free(iter);
1771 *descent = h - PANGO_PIXELS(baseline);
ace35c62
RR
1772
1773 if (height)
1774 *height = (wxCoord) h;
1775 }
1776 else
1777 {
1778 pango_layout_get_pixel_size( m_layout, width, height );
48d011c8 1779 }
ab9d0a8c 1780
cfcc3932 1781 // Reset old font description
6fbe4b24 1782 if (theFont->IsOk())
cfcc3932 1783 pango_layout_set_font_description( m_layout, m_fontdesc );
903f689b 1784}
c801d85f 1785
1f91072f 1786
2970ae54 1787bool wxGTKWindowImplDC::DoGetPartialTextExtents(const wxString& text,
1f91072f
VZ
1788 wxArrayInt& widths) const
1789{
1790 const size_t len = text.length();
1791 widths.Empty();
1792 widths.Add(0, len);
1793
1794 if (text.empty())
1795 return true;
1796
1797 // Set layout's text
1798 const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, m_font);
1799 if ( !dataUTF8 )
1800 {
1801 // hardly ideal, but what else can we do if conversion failed?
1802 wxLogLastError(wxT("DoGetPartialTextExtents"));
1803 return false;
1804 }
1805
1806 pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
f4322df6 1807
1f91072f
VZ
1808 // Calculate the position of each character based on the widths of
1809 // the previous characters
1810
1811 // Code borrowed from Scintilla's PlatGTK
1812 PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
1813 PangoRectangle pos;
1814 pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
1815 size_t i = 0;
1816 while (pango_layout_iter_next_cluster(iter))
1817 {
1818 pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
1819 int position = PANGO_PIXELS(pos.x);
1f91072f
VZ
1820 widths[i++] = position;
1821 }
1822 while (i < len)
1823 widths[i++] = PANGO_PIXELS(pos.x + pos.width);
1824 pango_layout_iter_free(iter);
1825
1826 return true;
1827}
1828
1829
2970ae54 1830wxCoord wxGTKWindowImplDC::GetCharWidth() const
c801d85f 1831{
cfcc3932 1832 pango_layout_set_text( m_layout, "H", 1 );
ace35c62
RR
1833 int w;
1834 pango_layout_get_pixel_size( m_layout, &w, NULL );
2b5f62a0 1835 return w;
903f689b 1836}
c801d85f 1837
2970ae54 1838wxCoord wxGTKWindowImplDC::GetCharHeight() const
c801d85f 1839{
a8c5e1a9 1840 PangoFontMetrics *metrics = pango_context_get_metrics (m_context, m_fontdesc, pango_context_get_language(m_context));
2e61f681
VZ
1841 wxCHECK_MSG( metrics, -1, _T("failed to get pango font metrics") );
1842
1843 wxCoord h = PANGO_PIXELS (pango_font_metrics_get_descent (metrics) +
1844 pango_font_metrics_get_ascent (metrics));
1845 pango_font_metrics_unref (metrics);
1846 return h;
903f689b 1847}
c801d85f 1848
2970ae54 1849void wxGTKWindowImplDC::Clear()
c801d85f 1850{
223d09f6 1851 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1852
6db90681 1853 if (!m_window) return;
7d5af6fa 1854
f60e7fdd
VZ
1855 // VZ: the code below results in infinite recursion and crashes when
1856 // dc.Clear() is done from OnPaint() so I disable it for now.
1857 // I don't know what the correct fix is but Clear() surely should not
1858 // reenter OnPaint()!
1859#if 0
f234c60c
RR
1860 /* - we either are a memory dc or have a window as the
1861 owner. anything else shouldn't happen.
1862 - we don't use gdk_window_clear() as we don't set
1863 the window's background colour anymore. it is too
1864 much pain to keep the DC's and the window's back-
1865 ground colour in synch. */
7d5af6fa 1866
f234c60c 1867 if (m_owner)
265898fd 1868 {
f90566f5 1869 m_owner->Clear();
b0e0d661 1870 return;
265898fd 1871 }
f234c60c
RR
1872
1873 if (m_isMemDC)
265898fd
RR
1874 {
1875 int width,height;
1876 GetSize( &width, &height );
1877 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
b0e0d661 1878 return;
265898fd 1879 }
f60e7fdd
VZ
1880#else // 1
1881 int width,height;
1882 GetSize( &width, &height );
1883 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
1884#endif // 0/1
903f689b 1885}
c801d85f 1886
2970ae54 1887void wxGTKWindowImplDC::SetFont( const wxFont &font )
c801d85f 1888{
265898fd 1889 m_font = font;
ab9d0a8c 1890
77416abd 1891 if (m_font.Ok())
2b5f62a0 1892 {
cfcc3932
RR
1893 if (m_fontdesc)
1894 pango_font_description_free( m_fontdesc );
ab9d0a8c 1895
cfcc3932 1896 m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
ab9d0a8c
WS
1897
1898
77416abd
JS
1899 if (m_owner)
1900 {
cfcc3932 1901 PangoContext *oldContext = m_context;
ab9d0a8c 1902
f26623c8 1903 m_context = m_owner->GtkGetPangoDefaultContext();
ab9d0a8c 1904
cfcc3932
RR
1905 // If we switch back/forth between different contexts
1906 // we also have to create a new layout. I think so,
ab9d0a8c 1907 // at least, and it doesn't hurt to do it.
cfcc3932
RR
1908 if (oldContext != m_context)
1909 {
1910 if (m_layout)
3fe39b0c 1911 g_object_unref (m_layout);
ab9d0a8c 1912
cfcc3932
RR
1913 m_layout = pango_layout_new( m_context );
1914 }
77416abd 1915 }
ab9d0a8c 1916
cfcc3932 1917 pango_layout_set_font_description( m_layout, m_fontdesc );
2b5f62a0 1918 }
903f689b 1919}
c801d85f 1920
2970ae54 1921void wxGTKWindowImplDC::SetPen( const wxPen &pen )
c801d85f 1922{
223d09f6 1923 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 1924
265898fd 1925 if (m_pen == pen) return;
7d5af6fa 1926
265898fd 1927 m_pen = pen;
7d5af6fa 1928
265898fd 1929 if (!m_pen.Ok()) return;
7d5af6fa 1930
6db90681 1931 if (!m_window) return;
7d5af6fa 1932
265898fd 1933 gint width = m_pen.GetWidth();
265898fd
RR
1934 if (width <= 0)
1935 {
112c5086 1936 // CMB: if width is non-zero scale it with the dc
265898fd
RR
1937 width = 1;
1938 }
1939 else
1940 {
1941 // X doesn't allow different width in x and y and so we take
1942 // the average
503f414e
VZ
1943 double w = 0.5 +
1944 ( fabs((double) XLOG2DEVREL(width)) +
1945 fabs((double) YLOG2DEVREL(width)) ) / 2.0;
265898fd 1946 width = (int)w;
375fc5a9
VZ
1947 if ( !width )
1948 {
1949 // width can't be 0 or an internal GTK error occurs inside
1950 // gdk_gc_set_dashes() below
1951 width = 1;
1952 }
265898fd 1953 }
7d5af6fa 1954
2eca425d
RL
1955 static const wxGTKDash dotted[] = {1, 1};
1956 static const wxGTKDash short_dashed[] = {2, 2};
1957 static const wxGTKDash wxCoord_dashed[] = {2, 4};
1958 static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3};
7d5af6fa 1959
112c5086
RR
1960 // We express dash pattern in pen width unit, so we are
1961 // independent of zoom factor and so on...
1962 int req_nb_dash;
2eca425d 1963 const wxGTKDash *req_dash;
7d5af6fa 1964
265898fd
RR
1965 GdkLineStyle lineStyle = GDK_LINE_SOLID;
1966 switch (m_pen.GetStyle())
1967 {
112c5086 1968 case wxUSER_DASH:
7d5af6fa
VZ
1969 {
1970 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086 1971 req_nb_dash = m_pen.GetDashCount();
2eca425d 1972 req_dash = (wxGTKDash*)m_pen.GetDash();
112c5086 1973 break;
7d5af6fa
VZ
1974 }
1975 case wxDOT:
1976 {
1977 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
1978 req_nb_dash = 2;
1979 req_dash = dotted;
7d5af6fa
VZ
1980 break;
1981 }
1982 case wxLONG_DASH:
1983 {
1984 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086 1985 req_nb_dash = 2;
72cdf4c9 1986 req_dash = wxCoord_dashed;
7d5af6fa
VZ
1987 break;
1988 }
1989 case wxSHORT_DASH:
1990 {
1991 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
1992 req_nb_dash = 2;
1993 req_dash = short_dashed;
7d5af6fa
VZ
1994 break;
1995 }
1996 case wxDOT_DASH:
1997 {
1998// lineStyle = GDK_LINE_DOUBLE_DASH;
1999 lineStyle = GDK_LINE_ON_OFF_DASH;
112c5086
RR
2000 req_nb_dash = 4;
2001 req_dash = dotted_dashed;
7d5af6fa
VZ
2002 break;
2003 }
2004
2005 case wxTRANSPARENT:
72174350 2006 case wxSTIPPLE_MASK_OPAQUE:
7d5af6fa
VZ
2007 case wxSTIPPLE:
2008 case wxSOLID:
2009 default:
2010 {
2011 lineStyle = GDK_LINE_SOLID;
2eca425d 2012 req_dash = (wxGTKDash*)NULL;
112c5086 2013 req_nb_dash = 0;
7d5af6fa
VZ
2014 break;
2015 }
265898fd 2016 }
7d5af6fa 2017
112c5086
RR
2018 if (req_dash && req_nb_dash)
2019 {
2eca425d 2020 wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash];
112c5086
RR
2021 if (real_req_dash)
2022 {
2023 for (int i = 0; i < req_nb_dash; i++)
2024 real_req_dash[i] = req_dash[i] * width;
2eca425d 2025 gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash );
112c5086
RR
2026 delete[] real_req_dash;
2027 }
2028 else
2029 {
2030 // No Memory. We use non-scaled dash pattern...
2eca425d 2031 gdk_gc_set_dashes( m_penGC, 0, (wxGTKDash*)req_dash, req_nb_dash );
112c5086
RR
2032 }
2033 }
7d5af6fa 2034
265898fd
RR
2035 GdkCapStyle capStyle = GDK_CAP_ROUND;
2036 switch (m_pen.GetCap())
2037 {
265898fd
RR
2038 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
2039 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
d4aa3a4b
RR
2040 case wxCAP_ROUND:
2041 default:
72174350 2042 {
d4aa3a4b
RR
2043 if (width <= 1)
2044 {
2045 width = 0;
2046 capStyle = GDK_CAP_NOT_LAST;
2047 }
2048 else
2049 {
2050 capStyle = GDK_CAP_ROUND;
2051 }
72174350 2052 break;
d4aa3a4b 2053 }
265898fd 2054 }
7d5af6fa 2055
265898fd
RR
2056 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
2057 switch (m_pen.GetJoin())
2058 {
2059 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
265898fd 2060 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
d4aa3a4b
RR
2061 case wxJOIN_ROUND:
2062 default: { joinStyle = GDK_JOIN_ROUND; break; }
265898fd 2063 }
7d5af6fa 2064
265898fd 2065 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
7d5af6fa 2066
265898fd
RR
2067 m_pen.GetColour().CalcPixel( m_cmap );
2068 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
903f689b 2069}
c801d85f 2070
2970ae54 2071void wxGTKWindowImplDC::SetBrush( const wxBrush &brush )
c801d85f 2072{
223d09f6 2073 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2074
265898fd 2075 if (m_brush == brush) return;
7d5af6fa 2076
265898fd 2077 m_brush = brush;
7d5af6fa 2078
265898fd 2079 if (!m_brush.Ok()) return;
7d5af6fa 2080
6db90681 2081 if (!m_window) return;
7d5af6fa 2082
265898fd
RR
2083 m_brush.GetColour().CalcPixel( m_cmap );
2084 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
7d5af6fa 2085
956dbab1 2086 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
7d5af6fa 2087
4fcd73bd 2088 if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
265898fd 2089 {
b85229d1 2090 if (m_brush.GetStipple()->GetDepth() != 1)
7d5af6fa 2091 {
956dbab1 2092 gdk_gc_set_fill( m_brushGC, GDK_TILED );
cd25b18c 2093 gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
7d5af6fa 2094 }
b0e0d661 2095 else
7d5af6fa 2096 {
956dbab1 2097 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
b85229d1 2098 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
7d5af6fa 2099 }
265898fd 2100 }
7d5af6fa 2101
de2d2cdc
VZ
2102 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
2103 {
e1208c31
RR
2104 gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED);
2105 gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() );
de2d2cdc
VZ
2106 }
2107
ab9d0a8c 2108 if (m_brush.IsHatch())
265898fd 2109 {
956dbab1 2110 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
265898fd
RR
2111 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
2112 gdk_gc_set_stipple( m_brushGC, hatches[num] );
2113 }
903f689b 2114}
c801d85f 2115
2970ae54 2116void wxGTKWindowImplDC::SetBackground( const wxBrush &brush )
46dc76ba 2117{
bbbbe360
RR
2118 /* CMB 21/7/98: Added SetBackground. Sets background brush
2119 * for Clear() and bg colour for shapes filled with cross-hatch brush */
7d5af6fa 2120
223d09f6 2121 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2122
265898fd 2123 if (m_backgroundBrush == brush) return;
7d5af6fa 2124
265898fd 2125 m_backgroundBrush = brush;
7d5af6fa 2126
265898fd 2127 if (!m_backgroundBrush.Ok()) return;
7d5af6fa 2128
6db90681 2129 if (!m_window) return;
7d5af6fa 2130
265898fd
RR
2131 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
2132 gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
a802c3a1 2133 gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
031b2a7b 2134 gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
265898fd 2135 gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
3417c2cd
RR
2136
2137 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
7d5af6fa 2138
cd25b18c 2139 if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
265898fd 2140 {
b85229d1 2141 if (m_backgroundBrush.GetStipple()->GetDepth() != 1)
7d5af6fa 2142 {
3417c2cd 2143 gdk_gc_set_fill( m_bgGC, GDK_TILED );
fd128b0c 2144 gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
7d5af6fa 2145 }
cd25b18c 2146 else
7d5af6fa 2147 {
3417c2cd 2148 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
b85229d1 2149 gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
7d5af6fa 2150 }
265898fd 2151 }
7d5af6fa 2152
ab9d0a8c 2153 if (m_backgroundBrush.IsHatch())
265898fd 2154 {
3417c2cd 2155 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
265898fd
RR
2156 int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
2157 gdk_gc_set_stipple( m_bgGC, hatches[num] );
bbbbe360 2158 }
903f689b 2159}
46dc76ba 2160
2970ae54 2161void wxGTKWindowImplDC::SetLogicalFunction( int function )
c801d85f 2162{
223d09f6 2163 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2164
72174350
VZ
2165 if (m_logicalFunction == function)
2166 return;
2167
2168 // VZ: shouldn't this be a CHECK?
2169 if (!m_window)
2170 return;
01eaf507 2171
2b5f62a0 2172 GdkFunction mode;
265898fd
RR
2173 switch (function)
2174 {
3c679789
RR
2175 case wxXOR: mode = GDK_XOR; break;
2176 case wxINVERT: mode = GDK_INVERT; break;
3c679789
RR
2177 case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
2178 case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
2179 case wxCLEAR: mode = GDK_CLEAR; break;
2180 case wxSET: mode = GDK_SET; break;
2181 case wxOR_INVERT: mode = GDK_OR_INVERT; break;
2182 case wxAND: mode = GDK_AND; break;
2183 case wxOR: mode = GDK_OR; break;
2184 case wxEQUIV: mode = GDK_EQUIV; break;
2185 case wxNAND: mode = GDK_NAND; break;
2186 case wxAND_INVERT: mode = GDK_AND_INVERT; break;
7d5af6fa
VZ
2187 case wxCOPY: mode = GDK_COPY; break;
2188 case wxNO_OP: mode = GDK_NOOP; break;
2189 case wxSRC_INVERT: mode = GDK_COPY_INVERT; break;
72174350 2190
2d52841d
RR
2191 // unsupported by GTK
2192 case wxNOR: mode = GDK_COPY; break;
01eaf507 2193 default:
223d09f6 2194 wxFAIL_MSG( wxT("unsupported logical function") );
2b5f62a0 2195 mode = GDK_COPY;
265898fd 2196 }
7d5af6fa 2197
265898fd 2198 m_logicalFunction = function;
7d5af6fa 2199
265898fd
RR
2200 gdk_gc_set_function( m_penGC, mode );
2201 gdk_gc_set_function( m_brushGC, mode );
72174350
VZ
2202
2203 // to stay compatible with wxMSW, we don't apply ROPs to the text
3d2d8da1
RR
2204 // operations (i.e. DrawText/DrawRotatedText).
2205 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2206 gdk_gc_set_function( m_textGC, mode );
903f689b 2207}
c801d85f 2208
2970ae54 2209void wxGTKWindowImplDC::SetTextForeground( const wxColour &col )
c801d85f 2210{
223d09f6 2211 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2212
71ec83d2
VZ
2213 // don't set m_textForegroundColour to an invalid colour as we'd crash
2214 // later then (we use m_textForegroundColour.GetColor() without checking
2215 // in a few places)
2216 if ( !col.Ok() || (m_textForegroundColour == col) )
2217 return;
7d5af6fa 2218
265898fd 2219 m_textForegroundColour = col;
7d5af6fa 2220
71ec83d2
VZ
2221 if ( m_window )
2222 {
2223 m_textForegroundColour.CalcPixel( m_cmap );
2224 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
2225 }
903f689b 2226}
c801d85f 2227
2970ae54 2228void wxGTKWindowImplDC::SetTextBackground( const wxColour &col )
c801d85f 2229{
223d09f6 2230 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2231
71ec83d2
VZ
2232 // same as above
2233 if ( !col.Ok() || (m_textBackgroundColour == col) )
2234 return;
7d5af6fa 2235
265898fd 2236 m_textBackgroundColour = col;
7d5af6fa 2237
71ec83d2
VZ
2238 if ( m_window )
2239 {
2240 m_textBackgroundColour.CalcPixel( m_cmap );
2241 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
2242 }
903f689b 2243}
c801d85f 2244
2970ae54 2245void wxGTKWindowImplDC::SetBackgroundMode( int mode )
c801d85f 2246{
223d09f6 2247 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2248
265898fd 2249 m_backgroundMode = mode;
46dc76ba 2250
6db90681 2251 if (!m_window) return;
7d5af6fa 2252
265898fd
RR
2253 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2254 // transparent/solid background mode
7d5af6fa 2255
265898fd
RR
2256 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
2257 {
2258 gdk_gc_set_fill( m_brushGC,
2259 (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
2260 }
903f689b 2261}
c801d85f 2262
2970ae54 2263void wxGTKWindowImplDC::SetPalette( const wxPalette& WXUNUSED(palette) )
c801d85f 2264{
2970ae54 2265 wxFAIL_MSG( wxT("wxGTKWindowImplDC::SetPalette not implemented") );
903f689b 2266}
c801d85f 2267
2970ae54 2268void wxGTKWindowImplDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
c801d85f 2269{
223d09f6 2270 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2271
6db90681 2272 if (!m_window) return;
7d5af6fa 2273
3d2d8da1 2274 wxRect rect;
265898fd
RR
2275 rect.x = XLOG2DEV(x);
2276 rect.y = YLOG2DEV(y);
2277 rect.width = XLOG2DEVREL(width);
2278 rect.height = YLOG2DEVREL(height);
5f170f33 2279
49e74855
RR
2280 if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
2281 {
2282 rect.x -= rect.width;
2283 }
2284
e1208c31 2285 if (!m_currentClippingRegion.IsNull())
993f97ee
RR
2286 m_currentClippingRegion.Intersect( rect );
2287 else
2288 m_currentClippingRegion.Union( rect );
5f170f33
VZ
2289
2290#if USE_PAINT_REGION
e1208c31 2291 if (!m_paintClippingRegion.IsNull())
3d2d8da1 2292 m_currentClippingRegion.Intersect( m_paintClippingRegion );
809934d2 2293#endif
3d2d8da1 2294
ee8dbe63
RL
2295 wxCoord xx, yy, ww, hh;
2296 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2297 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2298
3d2d8da1
RR
2299 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2300 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2301 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2302 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
903f689b 2303}
c801d85f 2304
2970ae54 2305void wxGTKWindowImplDC::DoSetClippingRegionAsRegion( const wxRegion &region )
463c1fa1 2306{
223d09f6 2307 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2308
463c1fa1
RR
2309 if (region.Empty())
2310 {
2311 DestroyClippingRegion();
2312 return;
2313 }
7d5af6fa 2314
6db90681 2315 if (!m_window) return;
5f170f33 2316
e1208c31 2317 if (!m_currentClippingRegion.IsNull())
993f97ee
RR
2318 m_currentClippingRegion.Intersect( region );
2319 else
2320 m_currentClippingRegion.Union( region );
5f170f33
VZ
2321
2322#if USE_PAINT_REGION
e1208c31 2323 if (!m_paintClippingRegion.IsNull())
3d2d8da1 2324 m_currentClippingRegion.Intersect( m_paintClippingRegion );
809934d2 2325#endif
3d2d8da1 2326
ee8dbe63
RL
2327 wxCoord xx, yy, ww, hh;
2328 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2329 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2330
3d2d8da1
RR
2331 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2332 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2333 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2334 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
463c1fa1
RR
2335}
2336
2970ae54 2337void wxGTKWindowImplDC::DestroyClippingRegion()
c801d85f 2338{
223d09f6 2339 wxCHECK_RET( Ok(), wxT("invalid window dc") );
7d5af6fa 2340
265898fd 2341 wxDC::DestroyClippingRegion();
7d5af6fa 2342
3d2d8da1 2343 m_currentClippingRegion.Clear();
5f170f33
VZ
2344
2345#if USE_PAINT_REGION
3d2d8da1
RR
2346 if (!m_paintClippingRegion.IsEmpty())
2347 m_currentClippingRegion.Union( m_paintClippingRegion );
993f97ee 2348#endif
3d2d8da1 2349
6db90681 2350 if (!m_window) return;
7d5af6fa 2351
3d2d8da1
RR
2352 if (m_currentClippingRegion.IsEmpty())
2353 {
2354 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
2355 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
2356 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
2357 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
2358 }
2359 else
2360 {
2361 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2362 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2363 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2364 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
2365 }
903f689b 2366}
c801d85f 2367
2970ae54 2368void wxGTKWindowImplDC::Destroy()
dbf858b5 2369{
3d2d8da1 2370 if (m_penGC) wxFreePoolGC( m_penGC );
265898fd 2371 m_penGC = (GdkGC*) NULL;
3d2d8da1 2372 if (m_brushGC) wxFreePoolGC( m_brushGC );
265898fd 2373 m_brushGC = (GdkGC*) NULL;
3d2d8da1 2374 if (m_textGC) wxFreePoolGC( m_textGC );
265898fd 2375 m_textGC = (GdkGC*) NULL;
3d2d8da1 2376 if (m_bgGC) wxFreePoolGC( m_bgGC );
265898fd 2377 m_bgGC = (GdkGC*) NULL;
dbf858b5
RR
2378}
2379
2970ae54 2380void wxGTKWindowImplDC::SetDeviceOrigin( wxCoord x, wxCoord y )
847dfdb4
RR
2381{
2382 m_deviceOriginX = x;
2383 m_deviceOriginY = y;
f4322df6 2384
847dfdb4
RR
2385 ComputeScaleAndOrigin();
2386}
2387
2970ae54 2388void wxGTKWindowImplDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
847dfdb4
RR
2389{
2390 m_signX = (xLeftRight ? 1 : -1);
2391 m_signY = (yBottomUp ? -1 : 1);
f4322df6 2392
847dfdb4 2393 if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
f4322df6
VZ
2394 m_signX = -m_signX;
2395
847dfdb4
RR
2396 ComputeScaleAndOrigin();
2397}
2398
2970ae54 2399void wxGTKWindowImplDC::ComputeScaleAndOrigin()
238d735d 2400{
c77a6796 2401 const wxRealPoint origScale(m_scaleX, m_scaleY);
238d735d
RR
2402
2403 wxDC::ComputeScaleAndOrigin();
2404
c77a6796
VZ
2405 // if scale has changed call SetPen to recalulate the line width
2406 if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.Ok() )
238d735d 2407 {
c77a6796
VZ
2408 // this is a bit artificial, but we need to force wxDC to think the pen
2409 // has changed
0a164d4c
WS
2410 wxPen pen = m_pen;
2411 m_pen = wxNullPen;
2412 SetPen( pen );
2413 }
238d735d
RR
2414}
2415
b0e0d661 2416// Resolution in pixels per logical inch
2970ae54 2417wxSize wxGTKWindowImplDC::GetPPI() const
b0e0d661 2418{
7a5e6267 2419 return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5));
b0e0d661
VZ
2420}
2421
2970ae54 2422int wxGTKWindowImplDC::GetDepth() const
c801d85f 2423{
ace35c62 2424 return gdk_drawable_get_depth(m_window);
903f689b 2425}
c801d85f 2426
ec758a20
RR
2427
2428//-----------------------------------------------------------------------------
2429// wxPaintDC
2430//-----------------------------------------------------------------------------
2431
2970ae54
RR
2432#if wxUSE_NEW_DC
2433IMPLEMENT_DYNAMIC_CLASS(wxGTKPaintImplDC, wxGTKClientImplDC)
2434#else
f469b27c 2435IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
2970ae54 2436#endif
ec758a20 2437
2cfddfe7
JS
2438// Limit the paint region to the window size. Sometimes
2439// the paint region is too big, and this risks X11 errors
2440static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz)
2441{
2442 wxRect originalRect = region.GetBox();
2443 wxRect rect(originalRect);
2444 if (rect.width + rect.x > sz.x)
2445 rect.width = sz.x - rect.x;
2446 if (rect.height + rect.y > sz.y)
2447 rect.height = sz.y - rect.y;
2448 if (rect != originalRect)
2449 {
2450 region = wxRegion(rect);
2451 wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
2452 originalRect.x, originalRect.y, originalRect.width, originalRect.height,
2453 rect.x, rect.y, rect.width, rect.height);
2454 }
2455}
2456
2970ae54
RR
2457wxGTKPaintImplDC::wxGTKPaintImplDC( wxWindow *win )
2458 : wxGTKClientImplDC( win )
ec758a20 2459{
b6fa52db
RR
2460#if USE_PAINT_REGION
2461 if (!win->m_clipPaintRegion)
2462 return;
f469b27c 2463
2cfddfe7 2464 wxSize sz = win->GetSize();
bcb614b3 2465 m_paintClippingRegion = win->m_nativeUpdateRegion;
2cfddfe7 2466 wxLimitRegionToSize(m_paintClippingRegion, sz);
ab9d0a8c 2467
5f170f33
VZ
2468 GdkRegion *region = m_paintClippingRegion.GetRegion();
2469 if ( region )
2470 {
823faac3 2471 m_currentClippingRegion.Union( m_paintClippingRegion );
2cfddfe7
JS
2472 wxLimitRegionToSize(m_currentClippingRegion, sz);
2473
2474 if (sz.x <= 0 || sz.y <= 0)
2475 return ;
5f170f33 2476
823faac3
JS
2477 gdk_gc_set_clip_region( m_penGC, region );
2478 gdk_gc_set_clip_region( m_brushGC, region );
2479 gdk_gc_set_clip_region( m_textGC, region );
2480 gdk_gc_set_clip_region( m_bgGC, region );
5f170f33 2481 }
1e6feb95 2482#endif // USE_PAINT_REGION
ec758a20
RR
2483}
2484
2485//-----------------------------------------------------------------------------
2486// wxClientDC
2487//-----------------------------------------------------------------------------
2488
2970ae54
RR
2489#if wxUSE_NEW_DC
2490IMPLEMENT_DYNAMIC_CLASS(wxGTKClientImplDC, wxGTKWindowImplDC)
2491#else
f469b27c 2492IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
2970ae54 2493#endif
ec758a20 2494
2970ae54
RR
2495wxGTKClientImplDC::wxGTKClientImplDC( wxWindow *win )
2496 : wxGTKWindowImplDC( win )
ec758a20 2497{
2970ae54 2498 wxCHECK_RET( win, _T("NULL window in wxGTKClientImplDC::wxClientDC") );
4f55a07f 2499
1e6feb95
VZ
2500#ifdef __WXUNIVERSAL__
2501 wxPoint ptOrigin = win->GetClientAreaOrigin();
2502 SetDeviceOrigin(ptOrigin.x, ptOrigin.y);
2503 wxSize size = win->GetClientSize();
2504 SetClippingRegion(wxPoint(0, 0), size);
2505#endif // __WXUNIVERSAL__
ec758a20
RR
2506}
2507
2970ae54 2508void wxGTKClientImplDC::DoGetSize(int *width, int *height) const
4f55a07f
VZ
2509{
2510 wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") );
2511
2512 m_owner->GetClientSize( width, height );
2513}
2514
3d2d8da1
RR
2515// ----------------------------------------------------------------------------
2516// wxDCModule
2517// ----------------------------------------------------------------------------
2518
2519class wxDCModule : public wxModule
2520{
2521public:
2522 bool OnInit();
2523 void OnExit();
2524
2525private:
2526 DECLARE_DYNAMIC_CLASS(wxDCModule)
2527};
2528
2529IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
2530
2531bool wxDCModule::OnInit()
2532{
2533 wxInitGCPool();
ab9d0a8c 2534 return true;
3d2d8da1
RR
2535}
2536
2537void wxDCModule::OnExit()
2538{
2539 wxCleanUpGCPool();
2540}