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