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