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