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