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