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