]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dcclient.cpp
fixed encoding handling in ANSI mode
[wxWidgets.git] / src / gtk1 / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/dcclient.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "dcclient.h"
12 #endif
13
14 #ifdef __VMS
15 #define XCopyPlane XCOPYPLANE
16 #endif
17
18 #include "wx/dcclient.h"
19 #include "wx/dcmemory.h"
20 #include "wx/image.h"
21 #include "wx/module.h"
22 #include "wx/log.h"
23 #include "wx/fontutil.h"
24
25 #include "wx/gtk/win_gtk.h"
26
27 #include <math.h> // for floating-point functions
28
29 #include <gdk/gdk.h>
30 #include <gdk/gdkx.h>
31 #include <gdk/gdkprivate.h>
32 #include <gtk/gtk.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 void gdk_wx_draw_bitmap(GdkDrawable *drawable,
83 GdkGC *gc,
84 GdkDrawable *src,
85 gint xsrc,
86 gint ysrc,
87 gint xdest,
88 gint ydest,
89 gint width,
90 gint height)
91 {
92 gint src_width, src_height;
93 #ifndef __WXGTK20__
94 GdkWindowPrivate *drawable_private;
95 GdkWindowPrivate *src_private;
96 GdkGCPrivate *gc_private;
97 #endif
98
99 g_return_if_fail (drawable != NULL);
100 g_return_if_fail (src != NULL);
101 g_return_if_fail (gc != NULL);
102
103 #ifdef __WXGTK20__
104 if (GDK_WINDOW_DESTROYED(drawable) || GDK_WINDOW_DESTROYED(src))
105 return;
106
107 gdk_drawable_get_size(src, &src_width, &src_height);
108 #else
109 drawable_private = (GdkWindowPrivate*) drawable;
110 src_private = (GdkWindowPrivate*) src;
111 if (drawable_private->destroyed || src_private->destroyed)
112 return;
113
114 src_width = src_private->width;
115 src_height = src_private->height;
116
117 gc_private = (GdkGCPrivate*) gc;
118 #endif
119
120 if (width == -1) width = src_width;
121 if (height == -1) height = src_height;
122
123 #ifdef __WXGTK20__
124 XCopyPlane( GDK_WINDOW_XDISPLAY(drawable),
125 GDK_WINDOW_XID(src),
126 GDK_WINDOW_XID(drawable),
127 GDK_GC_XGC(gc),
128 xsrc, ysrc,
129 width, height,
130 xdest, ydest,
131 1 );
132 #else
133 XCopyPlane( drawable_private->xdisplay,
134 src_private->xwindow,
135 drawable_private->xwindow,
136 gc_private->xgc,
137 xsrc, ysrc,
138 width, height,
139 xdest, ydest,
140 1 );
141 #endif
142 }
143
144 //-----------------------------------------------------------------------------
145 // Implement Pool of Graphic contexts. Creating them takes too much time.
146 //-----------------------------------------------------------------------------
147
148 #define GC_POOL_SIZE 200
149
150 enum wxPoolGCType
151 {
152 wxGC_ERROR = 0,
153 wxTEXT_MONO,
154 wxBG_MONO,
155 wxPEN_MONO,
156 wxBRUSH_MONO,
157 wxTEXT_COLOUR,
158 wxBG_COLOUR,
159 wxPEN_COLOUR,
160 wxBRUSH_COLOUR,
161 wxTEXT_SCREEN,
162 wxBG_SCREEN,
163 wxPEN_SCREEN,
164 wxBRUSH_SCREEN
165 };
166
167 struct wxGC
168 {
169 GdkGC *m_gc;
170 wxPoolGCType m_type;
171 bool m_used;
172 };
173
174 #define GC_POOL_ALLOC_SIZE 100
175
176 static int wxGCPoolSize = 0;
177
178 static wxGC *wxGCPool = NULL;
179
180 static void wxInitGCPool()
181 {
182 // This really could wait until the first call to
183 // wxGetPoolGC, but we will make the first allocation
184 // now when other initialization is being performed.
185
186 // Set initial pool size.
187 wxGCPoolSize = GC_POOL_ALLOC_SIZE;
188
189 // Allocate initial pool.
190 wxGCPool = (wxGC *)malloc(wxGCPoolSize * sizeof(wxGC));
191 if (wxGCPool == NULL)
192 {
193 // If we cannot malloc, then fail with error
194 // when debug is enabled. If debug is not enabled,
195 // the problem will eventually get caught
196 // in wxGetPoolGC.
197 wxFAIL_MSG( wxT("Cannot allocate GC pool") );
198 return;
199 }
200
201 // Zero initial pool.
202 memset(wxGCPool, 0, wxGCPoolSize * sizeof(wxGC));
203 }
204
205 static void wxCleanUpGCPool()
206 {
207 for (int i = 0; i < wxGCPoolSize; i++)
208 {
209 if (wxGCPool[i].m_gc)
210 gdk_gc_unref( wxGCPool[i].m_gc );
211 }
212
213 free(wxGCPool);
214 wxGCPool = NULL;
215 wxGCPoolSize = 0;
216 }
217
218 static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type )
219 {
220 wxGC *pptr;
221
222 // Look for an available GC.
223 for (int i = 0; i < wxGCPoolSize; i++)
224 {
225 if (!wxGCPool[i].m_gc)
226 {
227 wxGCPool[i].m_gc = gdk_gc_new( window );
228 gdk_gc_set_exposures( wxGCPool[i].m_gc, FALSE );
229 wxGCPool[i].m_type = type;
230 wxGCPool[i].m_used = FALSE;
231 }
232 if ((!wxGCPool[i].m_used) && (wxGCPool[i].m_type == type))
233 {
234 wxGCPool[i].m_used = TRUE;
235 return wxGCPool[i].m_gc;
236 }
237 }
238
239 // We did not find an available GC.
240 // We need to grow the GC pool.
241 pptr = (wxGC *)realloc(wxGCPool,
242 (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC));
243 if (pptr != NULL)
244 {
245 // Initialize newly allocated pool.
246 wxGCPool = pptr;
247 memset(&wxGCPool[wxGCPoolSize], 0,
248 GC_POOL_ALLOC_SIZE*sizeof(wxGC));
249
250 // Initialize entry we will return.
251 wxGCPool[wxGCPoolSize].m_gc = gdk_gc_new( window );
252 gdk_gc_set_exposures( wxGCPool[wxGCPoolSize].m_gc, FALSE );
253 wxGCPool[wxGCPoolSize].m_type = type;
254 wxGCPool[wxGCPoolSize].m_used = TRUE;
255
256 // Set new value of pool size.
257 wxGCPoolSize += GC_POOL_ALLOC_SIZE;
258
259 // Return newly allocated entry.
260 return wxGCPool[wxGCPoolSize-GC_POOL_ALLOC_SIZE].m_gc;
261 }
262
263 // The realloc failed. Fall through to error.
264 wxFAIL_MSG( wxT("No GC available") );
265
266 return (GdkGC*) NULL;
267 }
268
269 static void wxFreePoolGC( GdkGC *gc )
270 {
271 for (int i = 0; i < wxGCPoolSize; i++)
272 {
273 if (wxGCPool[i].m_gc == gc)
274 {
275 wxGCPool[i].m_used = FALSE;
276 return;
277 }
278 }
279
280 wxFAIL_MSG( wxT("Wrong GC") );
281 }
282
283 //-----------------------------------------------------------------------------
284 // wxWindowDC
285 //-----------------------------------------------------------------------------
286
287 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
288
289 wxWindowDC::wxWindowDC()
290 {
291 m_penGC = (GdkGC *) NULL;
292 m_brushGC = (GdkGC *) NULL;
293 m_textGC = (GdkGC *) NULL;
294 m_bgGC = (GdkGC *) NULL;
295 m_cmap = (GdkColormap *) NULL;
296 m_isMemDC = FALSE;
297 m_isScreenDC = FALSE;
298 m_owner = (wxWindow *)NULL;
299 #ifdef __WXGTK20__
300 m_context = (PangoContext *)NULL;
301 m_fontdesc = (PangoFontDescription *)NULL;
302 #endif
303 }
304
305 wxWindowDC::wxWindowDC( wxWindow *window )
306 {
307 wxASSERT_MSG( window, wxT("DC needs a window") );
308
309 m_penGC = (GdkGC *) NULL;
310 m_brushGC = (GdkGC *) NULL;
311 m_textGC = (GdkGC *) NULL;
312 m_bgGC = (GdkGC *) NULL;
313 m_cmap = (GdkColormap *) NULL;
314 m_owner = (wxWindow *)NULL;
315 m_isMemDC = FALSE;
316 m_isScreenDC = FALSE;
317 m_font = window->GetFont();
318
319 GtkWidget *widget = window->m_wxwindow;
320
321 // some controls don't have m_wxwindow - like wxStaticBox, but the user
322 // code should still be able to create wxClientDCs for them, so we will
323 // use the parent window here then
324 if ( !widget )
325 {
326 window = window->GetParent();
327 widget = window->m_wxwindow;
328 }
329
330 wxASSERT_MSG( widget, wxT("DC needs a widget") );
331
332 #ifdef __WXGTK20__
333 m_context = window->GtkGetPangoDefaultContext();
334 m_fontdesc = widget->style->font_desc;
335 #endif
336
337 GtkPizza *pizza = GTK_PIZZA( widget );
338 m_window = pizza->bin_window;
339
340 /* not realized ? */
341 if (!m_window)
342 {
343 /* don't report problems */
344 m_ok = TRUE;
345
346 return;
347 }
348
349 m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
350
351 SetUpDC();
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) */
359
360 m_owner = window;
361 }
362
363 wxWindowDC::~wxWindowDC()
364 {
365 Destroy();
366 }
367
368 void wxWindowDC::SetUpDC()
369 {
370 m_ok = TRUE;
371
372 wxASSERT_MSG( !m_penGC, wxT("GCs already created") );
373
374 if (m_isScreenDC)
375 {
376 m_penGC = wxGetPoolGC( m_window, wxPEN_SCREEN );
377 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_SCREEN );
378 m_textGC = wxGetPoolGC( m_window, wxTEXT_SCREEN );
379 m_bgGC = wxGetPoolGC( m_window, wxBG_SCREEN );
380 }
381 else
382 if (m_isMemDC && (((wxMemoryDC*)this)->m_selected.GetDepth() == 1))
383 {
384 m_penGC = wxGetPoolGC( m_window, wxPEN_MONO );
385 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_MONO );
386 m_textGC = wxGetPoolGC( m_window, wxTEXT_MONO );
387 m_bgGC = wxGetPoolGC( m_window, wxBG_MONO );
388 }
389 else
390 {
391 m_penGC = wxGetPoolGC( m_window, wxPEN_COLOUR );
392 m_brushGC = wxGetPoolGC( m_window, wxBRUSH_COLOUR );
393 m_textGC = wxGetPoolGC( m_window, wxTEXT_COLOUR );
394 m_bgGC = wxGetPoolGC( m_window, wxBG_COLOUR );
395 }
396
397 /* background colour */
398 m_backgroundBrush = *wxWHITE_BRUSH;
399 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
400 GdkColor *bg_col = m_backgroundBrush.GetColour().GetColor();
401
402 /* m_textGC */
403 m_textForegroundColour.CalcPixel( m_cmap );
404 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
405
406 m_textBackgroundColour.CalcPixel( m_cmap );
407 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
408
409 gdk_gc_set_fill( m_textGC, GDK_SOLID );
410
411 /* m_penGC */
412 m_pen.GetColour().CalcPixel( m_cmap );
413 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
414 gdk_gc_set_background( m_penGC, bg_col );
415
416 gdk_gc_set_line_attributes( m_penGC, 0, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND );
417
418 /* m_brushGC */
419 m_brush.GetColour().CalcPixel( m_cmap );
420 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
421 gdk_gc_set_background( m_brushGC, bg_col );
422
423 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
424
425 /* m_bgGC */
426 gdk_gc_set_background( m_bgGC, bg_col );
427 gdk_gc_set_foreground( m_bgGC, bg_col );
428
429 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
430
431 /* ROPs */
432 gdk_gc_set_function( m_textGC, GDK_COPY );
433 gdk_gc_set_function( m_brushGC, GDK_COPY );
434 gdk_gc_set_function( m_penGC, GDK_COPY );
435
436 /* clipping */
437 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
438 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
439 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
440 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
441
442 if (!hatch_bitmap)
443 {
444 hatch_bitmap = hatches;
445 hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height );
446 hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height );
447 hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height );
448 hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height );
449 hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height );
450 hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height );
451 }
452 }
453
454 void wxWindowDC::DoGetSize( int* width, int* height ) const
455 {
456 wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") );
457
458 m_owner->GetSize(width, height);
459 }
460
461 extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
462 const wxColour & col, int style);
463
464 bool wxWindowDC::DoFloodFill(wxCoord x, wxCoord y,
465 const wxColour& col, int style)
466 {
467 return wxDoFloodFill(this, x, y, col, style);
468 }
469
470 bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
471 {
472 // Generic (and therefore rather inefficient) method.
473 // Could be improved.
474 wxMemoryDC memdc;
475 wxBitmap bitmap(1, 1);
476 memdc.SelectObject(bitmap);
477 memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
478 memdc.SelectObject(wxNullBitmap);
479
480 wxImage image = bitmap.ConvertToImage();
481 col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
482 return TRUE;
483 }
484
485 void wxWindowDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
486 {
487 wxCHECK_RET( Ok(), wxT("invalid window dc") );
488
489 if (m_pen.GetStyle() != wxTRANSPARENT)
490 {
491 if (m_window)
492 gdk_draw_line( m_window, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
493
494 CalcBoundingBox(x1, y1);
495 CalcBoundingBox(x2, y2);
496 }
497 }
498
499 void wxWindowDC::DoCrossHair( wxCoord x, wxCoord y )
500 {
501 wxCHECK_RET( Ok(), wxT("invalid window dc") );
502
503 if (m_pen.GetStyle() != wxTRANSPARENT)
504 {
505 int w = 0;
506 int h = 0;
507 GetSize( &w, &h );
508 wxCoord xx = XLOG2DEV(x);
509 wxCoord yy = YLOG2DEV(y);
510 if (m_window)
511 {
512 gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
513 gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
514 }
515 }
516 }
517
518 void wxWindowDC::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
519 wxCoord xc, wxCoord yc )
520 {
521 wxCHECK_RET( Ok(), wxT("invalid window dc") );
522
523 wxCoord xx1 = XLOG2DEV(x1);
524 wxCoord yy1 = YLOG2DEV(y1);
525 wxCoord xx2 = XLOG2DEV(x2);
526 wxCoord yy2 = YLOG2DEV(y2);
527 wxCoord xxc = XLOG2DEV(xc);
528 wxCoord yyc = YLOG2DEV(yc);
529 double dx = xx1 - xxc;
530 double dy = yy1 - yyc;
531 double radius = sqrt((double)(dx*dx+dy*dy));
532 wxCoord r = (wxCoord)radius;
533 double radius1, radius2;
534
535 if (xx1 == xx2 && yy1 == yy2)
536 {
537 radius1 = 0.0;
538 radius2 = 360.0;
539 }
540 else
541 if (radius == 0.0)
542 {
543 radius1 = radius2 = 0.0;
544 }
545 else
546 {
547 radius1 = (xx1 - xxc == 0) ?
548 (yy1 - yyc < 0) ? 90.0 : -90.0 :
549 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
550 radius2 = (xx2 - xxc == 0) ?
551 (yy2 - yyc < 0) ? 90.0 : -90.0 :
552 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
553 }
554 wxCoord alpha1 = wxCoord(radius1 * 64.0);
555 wxCoord alpha2 = wxCoord((radius2 - radius1) * 64.0);
556 while (alpha2 <= 0) alpha2 += 360*64;
557 while (alpha1 > 360*64) alpha1 -= 360*64;
558
559 if (m_window)
560 {
561 if (m_brush.GetStyle() != wxTRANSPARENT)
562 {
563 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
564 {
565 gdk_gc_set_ts_origin( m_textGC,
566 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
567 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
568 gdk_draw_arc( m_window, m_textGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
569 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
570 } else
571 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
572 {
573 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
574 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
575 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
576 } else
577 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
578 {
579 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
580 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
581 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
582 } else
583 if (m_brush.GetStyle() == wxSTIPPLE)
584 {
585 gdk_gc_set_ts_origin( m_brushGC,
586 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
587 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
588 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
589 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
590 }
591 else
592 {
593 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
594 }
595 }
596
597 if (m_pen.GetStyle() != wxTRANSPARENT)
598 {
599 gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
600
601 gdk_draw_line( m_window, m_penGC, xx1, yy1, xxc, yyc );
602 gdk_draw_line( m_window, m_penGC, xxc, yyc, xx2, yy2 );
603 }
604 }
605
606 CalcBoundingBox (x1, y1);
607 CalcBoundingBox (x2, y2);
608 }
609
610 void wxWindowDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double sa, double ea )
611 {
612 wxCHECK_RET( Ok(), wxT("invalid window dc") );
613
614 wxCoord xx = XLOG2DEV(x);
615 wxCoord yy = YLOG2DEV(y);
616 wxCoord ww = m_signX * XLOG2DEVREL(width);
617 wxCoord hh = m_signY * YLOG2DEVREL(height);
618
619 // CMB: handle -ve width and/or height
620 if (ww < 0) { ww = -ww; xx = xx - ww; }
621 if (hh < 0) { hh = -hh; yy = yy - hh; }
622
623 if (m_window)
624 {
625 wxCoord start = wxCoord(sa * 64.0);
626 wxCoord end = wxCoord((ea-sa) * 64.0);
627
628 if (m_brush.GetStyle() != wxTRANSPARENT)
629 {
630 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
631 {
632 gdk_gc_set_ts_origin( m_textGC,
633 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
634 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
635 gdk_draw_arc( m_window, m_textGC, TRUE, xx, yy, ww, hh, start, end );
636 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
637 } else
638 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
639 {
640 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
641 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
642 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
643 } else
644 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
645 {
646 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
647 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
648 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
649 } else
650 if (m_brush.GetStyle() == wxSTIPPLE)
651 {
652 gdk_gc_set_ts_origin( m_brushGC,
653 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
654 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
655 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
656 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
657 }
658 else
659 {
660 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
661 }
662 }
663
664 if (m_pen.GetStyle() != wxTRANSPARENT)
665 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
666 }
667
668 CalcBoundingBox (x, y);
669 CalcBoundingBox (x + width, y + height);
670 }
671
672 void wxWindowDC::DoDrawPoint( wxCoord x, wxCoord y )
673 {
674 wxCHECK_RET( Ok(), wxT("invalid window dc") );
675
676 if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
677 gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
678
679 CalcBoundingBox (x, y);
680 }
681
682 void wxWindowDC::DoDrawLines( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset )
683 {
684 wxCHECK_RET( Ok(), wxT("invalid window dc") );
685
686 if (m_pen.GetStyle() == wxTRANSPARENT) return;
687 if (n <= 0) return;
688
689 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
690
691 for (int i = 0; i < n-1; i++)
692 {
693 wxCoord x1 = XLOG2DEV(points[i].x + xoffset);
694 wxCoord x2 = XLOG2DEV(points[i+1].x + xoffset);
695 wxCoord y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
696 wxCoord y2 = YLOG2DEV(points[i+1].y + yoffset);
697
698 if (m_window)
699 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
700
701 CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset );
702 }
703 }
704
705 void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int WXUNUSED(fillStyle) )
706 {
707 wxCHECK_RET( Ok(), wxT("invalid window dc") );
708
709 if (n <= 0) return;
710
711 GdkPoint *gdkpoints = new GdkPoint[n+1];
712 int i;
713 for (i = 0 ; i < n ; i++)
714 {
715 gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset);
716 gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset);
717
718 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset );
719 }
720
721 if (m_window)
722 {
723 if (m_brush.GetStyle() != wxTRANSPARENT)
724 {
725 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
726 {
727 gdk_gc_set_ts_origin( m_textGC,
728 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
729 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
730 gdk_draw_polygon( m_window, m_textGC, TRUE, gdkpoints, n );
731 gdk_gc_set_ts_origin( m_textGC, 0, 0 );
732 } else
733 if (IS_15_PIX_HATCH(m_brush.GetStyle()))
734 {
735 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 );
736 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
737 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
738 } else
739 if (IS_16_PIX_HATCH(m_brush.GetStyle()))
740 {
741 gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 );
742 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
743 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
744 } else
745 if (m_brush.GetStyle() == wxSTIPPLE)
746 {
747 gdk_gc_set_ts_origin( m_brushGC,
748 m_deviceOriginX % m_brush.GetStipple()->GetWidth(),
749 m_deviceOriginY % m_brush.GetStipple()->GetHeight() );
750 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
751 gdk_gc_set_ts_origin( m_brushGC, 0, 0 );
752 }
753 else
754 {
755 gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n );
756 }
757 }
758
759 if (m_pen.GetStyle() != wxTRANSPARENT)
760 {
761 for (i = 0 ; i < n ; i++)
762 {
763 gdk_draw_line( m_window, m_penGC,
764 gdkpoints[i%n].x,
765 gdkpoints[i%n].y,
766 gdkpoints[(i+1)%n].x,
767 gdkpoints[(i+1)%n].y);
768 }
769 }
770 }
771
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, (bool)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.GetBitmap() != NULL);
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;
1061 if ((w != ww) || (h != hh))
1062 {
1063 wxImage image = bitmap.ConvertToImage();
1064 image.Rescale( ww, hh );
1065 if (is_mono)
1066 use_bitmap = wxBitmap(image.ConvertToMono(255,255,255), 1);
1067 else
1068 use_bitmap = wxBitmap(image);
1069 }
1070 else
1071 {
1072 use_bitmap = bitmap;
1073 }
1074
1075 /* apply mask if any */
1076 GdkBitmap *mask = (GdkBitmap *) NULL;
1077 if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
1078
1079 if (useMask && mask)
1080 {
1081 GdkBitmap *new_mask = (GdkBitmap*) NULL;
1082 #ifndef __WXGTK20__ // TODO fix crash
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 gdk_gc_unref( gc );
1101 }
1102 #endif
1103 if (is_mono)
1104 {
1105 if (new_mask)
1106 gdk_gc_set_clip_mask( m_textGC, new_mask );
1107 else
1108 gdk_gc_set_clip_mask( m_textGC, mask );
1109 gdk_gc_set_clip_origin( m_textGC, xx, yy );
1110 }
1111 else
1112 {
1113 if (new_mask)
1114 gdk_gc_set_clip_mask( m_penGC, new_mask );
1115 else
1116 gdk_gc_set_clip_mask( m_penGC, mask );
1117 gdk_gc_set_clip_origin( m_penGC, xx, yy );
1118 }
1119
1120 if (new_mask)
1121 gdk_bitmap_unref( new_mask );
1122 }
1123
1124 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1125 drawing a mono-bitmap (XBitmap) we use the current text GC */
1126 if (is_mono)
1127 gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 );
1128 else
1129 gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1130
1131 /* remove mask again if any */
1132 if (useMask && mask)
1133 {
1134 if (is_mono)
1135 {
1136 gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
1137 gdk_gc_set_clip_origin( m_textGC, 0, 0 );
1138 if (!m_currentClippingRegion.IsNull())
1139 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
1140 }
1141 else
1142 {
1143 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
1144 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
1145 if (!m_currentClippingRegion.IsNull())
1146 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
1147 }
1148 }
1149 }
1150
1151 bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
1152 wxCoord width, wxCoord height,
1153 wxDC *source,
1154 wxCoord xsrc, wxCoord ysrc,
1155 int logical_func,
1156 bool useMask,
1157 wxCoord xsrcMask, wxCoord ysrcMask )
1158 {
1159 /* this is the nth try to get this utterly useless function to
1160 work. it now completely ignores the scaling or translation
1161 of the source dc, but scales correctly on the target dc and
1162 knows about possible mask information in a memory dc. */
1163
1164 wxCHECK_MSG( Ok(), FALSE, wxT("invalid window dc") );
1165
1166 wxCHECK_MSG( source, FALSE, wxT("invalid source dc") );
1167
1168 if (!m_window) return FALSE;
1169
1170 #if 1
1171 // transform the source DC coords to the device ones
1172 xsrc = source->XLOG2DEV(xsrc);
1173 ysrc = source->YLOG2DEV(ysrc);
1174 #endif
1175
1176 wxClientDC *srcDC = (wxClientDC*)source;
1177 wxMemoryDC *memDC = (wxMemoryDC*)source;
1178
1179 bool use_bitmap_method = FALSE;
1180 bool is_mono = FALSE;
1181
1182 /* TODO: use the mask origin when drawing transparently */
1183 if (xsrcMask == -1 && ysrcMask == -1)
1184 {
1185 xsrcMask = xsrc; ysrcMask = ysrc;
1186 }
1187
1188 if (srcDC->m_isMemDC)
1189 {
1190 if (!memDC->m_selected.Ok()) return FALSE;
1191
1192 /* we use the "XCopyArea" way to copy a memory dc into
1193 y different window if the memory dc BOTH
1194 a) doesn't have any mask or its mask isn't used
1195 b) it is clipped
1196 c) is not 1-bit */
1197
1198 if (useMask && (memDC->m_selected.GetMask()))
1199 {
1200 /* we HAVE TO use the direct way for memory dcs
1201 that have mask since the XCopyArea doesn't know
1202 about masks */
1203 use_bitmap_method = TRUE;
1204 }
1205 else if (memDC->m_selected.GetDepth() == 1)
1206 {
1207 /* we HAVE TO use the direct way for memory dcs
1208 that are bitmaps because XCopyArea doesn't cope
1209 with different bit depths */
1210 is_mono = TRUE;
1211 use_bitmap_method = TRUE;
1212 }
1213 else if ((xsrc == 0) && (ysrc == 0) &&
1214 (width == memDC->m_selected.GetWidth()) &&
1215 (height == memDC->m_selected.GetHeight()))
1216 {
1217 /* we SHOULD use the direct way if all of the bitmap
1218 in the memory dc is copied in which case XCopyArea
1219 wouldn't be able able to boost performace by reducing
1220 the area to be scaled */
1221 use_bitmap_method = TRUE;
1222 }
1223 else
1224 {
1225 use_bitmap_method = FALSE;
1226 }
1227 }
1228
1229 CalcBoundingBox( xdest, ydest );
1230 CalcBoundingBox( xdest + width, ydest + height );
1231
1232 /* scale/translate size and position */
1233 wxCoord xx = XLOG2DEV(xdest);
1234 wxCoord yy = YLOG2DEV(ydest);
1235
1236 wxCoord ww = XLOG2DEVREL(width);
1237 wxCoord hh = YLOG2DEVREL(height);
1238
1239 /* compare to current clipping region */
1240 if (!m_currentClippingRegion.IsNull())
1241 {
1242 wxRegion tmp( xx,yy,ww,hh );
1243 tmp.Intersect( m_currentClippingRegion );
1244 if (tmp.IsEmpty())
1245 return TRUE;
1246 }
1247
1248 int old_logical_func = m_logicalFunction;
1249 SetLogicalFunction( logical_func );
1250
1251 if (use_bitmap_method)
1252 {
1253 /* scale/translate bitmap size */
1254 wxCoord bm_width = memDC->m_selected.GetWidth();
1255 wxCoord bm_height = memDC->m_selected.GetHeight();
1256
1257 wxCoord bm_ww = XLOG2DEVREL( bm_width );
1258 wxCoord bm_hh = YLOG2DEVREL( bm_height );
1259
1260 /* scale bitmap if required */
1261 wxBitmap use_bitmap;
1262
1263 if ((bm_width != bm_ww) || (bm_height != bm_hh))
1264 {
1265 wxImage image = memDC->m_selected.ConvertToImage();
1266 image = image.Scale( bm_ww, bm_hh );
1267
1268 if (is_mono)
1269 use_bitmap = wxBitmap(image.ConvertToMono(255,255,255), 1);
1270 else
1271 use_bitmap = wxBitmap(image);
1272 }
1273 else
1274 {
1275 use_bitmap = memDC->m_selected;
1276 }
1277
1278 /* apply mask if any */
1279 GdkBitmap *mask = (GdkBitmap *) NULL;
1280 if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
1281
1282 if (useMask && mask)
1283 {
1284 GdkBitmap *new_mask = (GdkBitmap*) NULL;
1285 #ifndef __WXGTK20__ // TODO fix crash
1286 if (!m_currentClippingRegion.IsNull())
1287 {
1288 GdkColor col;
1289 new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 );
1290 GdkGC *gc = gdk_gc_new( new_mask );
1291 col.pixel = 0;
1292 gdk_gc_set_foreground( gc, &col );
1293 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
1294 col.pixel = 0;
1295 gdk_gc_set_background( gc, &col );
1296 col.pixel = 1;
1297 gdk_gc_set_foreground( gc, &col );
1298 gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() );
1299 gdk_gc_set_clip_origin( gc, -xx, -yy );
1300 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
1301 gdk_gc_set_stipple( gc, mask );
1302 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
1303 gdk_gc_unref( gc );
1304 }
1305 #endif
1306 if (is_mono)
1307 {
1308 if (new_mask)
1309 gdk_gc_set_clip_mask( m_textGC, new_mask );
1310 else
1311 gdk_gc_set_clip_mask( m_textGC, mask );
1312 gdk_gc_set_clip_origin( m_textGC, xx, yy );
1313 }
1314 else
1315 {
1316 if (new_mask)
1317 gdk_gc_set_clip_mask( m_penGC, new_mask );
1318 else
1319 gdk_gc_set_clip_mask( m_penGC, mask );
1320 gdk_gc_set_clip_origin( m_penGC, xx, yy );
1321 }
1322 if (new_mask)
1323 gdk_bitmap_unref( new_mask );
1324 }
1325
1326 /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1327 drawing a mono-bitmap (XBitmap) we use the current text GC */
1328
1329 if (is_mono)
1330 gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
1331 else
1332 gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
1333
1334 /* remove mask again if any */
1335 if (useMask && mask)
1336 {
1337 if (is_mono)
1338 {
1339 gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
1340 gdk_gc_set_clip_origin( m_textGC, 0, 0 );
1341 if (!m_currentClippingRegion.IsNull())
1342 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
1343 }
1344 else
1345 {
1346 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
1347 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
1348 if (!m_currentClippingRegion.IsNull())
1349 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
1350 }
1351 }
1352 }
1353 else /* use_bitmap_method */
1354 {
1355 if ((width != ww) || (height != hh))
1356 {
1357 /* draw source window into a bitmap as we cannot scale
1358 a window in contrast to a bitmap. this would actually
1359 work with memory dcs as well, but we'd lose the mask
1360 information and waste one step in this process since
1361 a memory already has a bitmap. all this is slightly
1362 inefficient as we could take an XImage directly from
1363 an X window, but we'd then also have to care that
1364 the window is not outside the screen (in which case
1365 we'd get a BadMatch or what not).
1366 Is a double XGetImage and combined XGetPixel and
1367 XPutPixel really faster? I'm not sure. look at wxXt
1368 for a different implementation of the same problem. */
1369
1370 wxBitmap bitmap( width, height );
1371
1372 /* copy including child window contents */
1373 gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
1374 gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0,
1375 srcDC->GetWindow(),
1376 xsrc, ysrc, width, height );
1377 gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
1378
1379 /* scale image */
1380 wxImage image = bitmap.ConvertToImage();
1381 image = image.Scale( ww, hh );
1382
1383 /* convert to bitmap */
1384 bitmap = wxBitmap(image);
1385
1386 /* draw scaled bitmap */
1387 gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
1388
1389 }
1390 else
1391 {
1392 /* No scaling and not a memory dc with a mask either */
1393
1394 /* copy including child window contents */
1395 gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
1396 gdk_window_copy_area( m_window, m_penGC, xx, yy,
1397 srcDC->GetWindow(),
1398 xsrc, ysrc, width, height );
1399 gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
1400 }
1401 }
1402
1403 SetLogicalFunction( old_logical_func );
1404 return TRUE;
1405 }
1406
1407 void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
1408 {
1409 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1410
1411 if (!m_window) return;
1412
1413 if (text.empty()) return;
1414
1415 #ifndef __WXGTK20__
1416 GdkFont *font = m_font.GetInternalFont( m_scaleY );
1417
1418 wxCHECK_RET( font, wxT("invalid font") );
1419 #endif
1420
1421 #ifdef __WXGTK20__
1422 wxCHECK_RET( m_context, wxT("no Pango context") );
1423 #endif
1424
1425 x = XLOG2DEV(x);
1426 y = YLOG2DEV(y);
1427
1428 #ifdef __WXGTK20__
1429 // TODO: the layout engine should be abstracted at a higher level!
1430 PangoLayout *layout = pango_layout_new(m_context);
1431 pango_layout_set_font_description(layout, m_fontdesc);
1432 {
1433 #if wxUSE_UNICODE
1434 const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
1435 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
1436 #else
1437 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
1438 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
1439 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
1440 #endif
1441 }
1442
1443 // Measure layout.
1444 int w,h;
1445 pango_layout_get_pixel_size(layout, &w, &h);
1446 wxCoord width = w;
1447 wxCoord height = h;
1448
1449 // Draw layout.
1450 gdk_draw_layout( m_window, m_textGC, x, y, layout );
1451
1452 g_object_unref( G_OBJECT( layout ) );
1453 #else // GTK+ 1.x
1454 wxCoord width = gdk_string_width( font, text.mbc_str() );
1455 wxCoord height = font->ascent + font->descent;
1456
1457 if ( m_backgroundMode == wxSOLID )
1458 {
1459 gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
1460 gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
1461 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
1462 }
1463 gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
1464
1465 /* CMB 17/7/98: simple underline: ignores scaling and underlying
1466 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
1467 properties (see wxXt implementation) */
1468 if (m_font.GetUnderlined())
1469 {
1470 wxCoord ul_y = y + font->ascent;
1471 if (font->descent > 0) ul_y++;
1472 gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
1473 }
1474 #endif // GTK+ 2.0/1.x
1475
1476
1477 width = wxCoord(width / m_scaleX);
1478 height = wxCoord(height / m_scaleY);
1479 CalcBoundingBox (x + width, y + height);
1480 CalcBoundingBox (x, y);
1481 }
1482
1483 void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
1484 {
1485 if (angle == 0.0)
1486 {
1487 DrawText(text, x, y);
1488 return;
1489 }
1490
1491 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1492
1493 if (!m_window) return;
1494
1495 GdkFont *font = m_font.GetInternalFont( m_scaleY );
1496
1497 wxCHECK_RET( font, wxT("invalid font") );
1498
1499 // the size of the text
1500 wxCoord w = gdk_string_width( font, text.mbc_str() );
1501 wxCoord h = font->ascent + font->descent;
1502
1503 // draw the string normally
1504 wxBitmap src(w, h);
1505 wxMemoryDC dc;
1506 dc.SelectObject(src);
1507 dc.SetFont(GetFont());
1508 dc.SetBackground(*wxWHITE_BRUSH);
1509 dc.SetBrush(*wxBLACK_BRUSH);
1510 dc.Clear();
1511 dc.DrawText(text, 0, 0);
1512 dc.SelectObject(wxNullBitmap);
1513
1514 // Calculate the size of the rotated bounding box.
1515 double rad = DegToRad(angle);
1516 double dx = cos(rad),
1517 dy = sin(rad);
1518
1519 // the rectngle vertices are counted clockwise with the first one being at
1520 // (0, 0) (or, rather, at (x, y))
1521 double x2 = w*dx,
1522 y2 = -w*dy; // y axis points to the bottom, hence minus
1523 double x4 = h*dy,
1524 y4 = h*dx;
1525 double x3 = x4 + x2,
1526 y3 = y4 + y2;
1527
1528 // calc max and min
1529 wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5),
1530 maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5),
1531 minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
1532 minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
1533
1534 // prepare to blit-with-rotate the bitmap to the DC
1535 wxImage image = src.ConvertToImage();
1536
1537 GdkColor *colText = m_textForegroundColour.GetColor(),
1538 *colBack = m_textBackgroundColour.GetColor();
1539
1540 bool textColSet = TRUE;
1541
1542 unsigned char *data = image.GetData();
1543
1544 // paint pixel by pixel
1545 for ( wxCoord srcX = 0; srcX < w; srcX++ )
1546 {
1547 for ( wxCoord srcY = 0; srcY < h; srcY++ )
1548 {
1549 // transform source coords to dest coords
1550 double r = sqrt((double)srcX*srcX + srcY*srcY);
1551 double angleOrig = atan2((double)srcY, (double)srcX) - rad;
1552 wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
1553 dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
1554
1555 // black pixel?
1556 bool textPixel = data[(srcY*w + srcX)*3] == 0;
1557 if ( textPixel || (m_backgroundMode == wxSOLID) )
1558 {
1559 // change colour if needed
1560 if ( textPixel != textColSet )
1561 {
1562 gdk_gc_set_foreground( m_textGC, textPixel ? colText
1563 : colBack );
1564
1565 textColSet = textPixel;
1566 }
1567
1568 // don't use DrawPoint() because it uses the current pen
1569 // colour, and we don't need it here
1570 gdk_draw_point( m_window, m_textGC,
1571 XLOG2DEV(x) + dstX, YLOG2DEV(y) + dstY );
1572 }
1573 }
1574 }
1575
1576 // it would be better to draw with non underlined font and draw the line
1577 // manually here (it would be more straight...)
1578 #if 0
1579 if ( m_font.GetUnderlined() )
1580 {
1581 gdk_draw_line( m_window, m_textGC,
1582 XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent),
1583 XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent));
1584 }
1585 #endif // 0
1586
1587 // restore the font colour
1588 gdk_gc_set_foreground( m_textGC, colText );
1589
1590 // update the bounding box
1591 CalcBoundingBox(x + minX, y + minY);
1592 CalcBoundingBox(x + maxX, y + maxY);
1593 }
1594
1595 void wxWindowDC::DoGetTextExtent(const wxString &string,
1596 wxCoord *width, wxCoord *height,
1597 wxCoord *descent, wxCoord *externalLeading,
1598 wxFont *theFont) const
1599 {
1600 if (string.IsEmpty())
1601 {
1602 if (width) (*width) = 0;
1603 if (height) (*height) = 0;
1604 return;
1605 }
1606
1607 #ifdef __WXGTK20__
1608 // Create layout and set font description
1609 PangoLayout *layout = pango_layout_new(m_context);
1610 if (theFont)
1611 pango_layout_set_font_description( layout, theFont->GetNativeFontInfo()->description );
1612 else
1613 pango_layout_set_font_description(layout, m_fontdesc);
1614
1615 // Set layout's text
1616 #if wxUSE_UNICODE
1617 const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
1618 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
1619 #else
1620 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
1621 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
1622 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
1623 #endif
1624
1625 // Measure text.
1626 int w,h;
1627 pango_layout_get_pixel_size(layout, &w, &h);
1628
1629 if (width) (*width) = (wxCoord) w;
1630 if (height) (*height) = (wxCoord) h;
1631 if (descent)
1632 {
1633 // Do something about metrics here. TODO.
1634 (*descent) = 0;
1635 }
1636 if (externalLeading) (*externalLeading) = 0; // ??
1637
1638 g_object_unref( G_OBJECT( layout ) );
1639 #else
1640 wxFont fontToUse = m_font;
1641 if (theFont) fontToUse = *theFont;
1642
1643 GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
1644 if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
1645 if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
1646 if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
1647 if (externalLeading) (*externalLeading) = 0; // ??
1648 #endif
1649 }
1650
1651 wxCoord wxWindowDC::GetCharWidth() const
1652 {
1653 #ifdef __WXGTK20__
1654 // There should be an easier way.
1655 PangoLayout *layout = pango_layout_new(m_context);
1656 pango_layout_set_font_description(layout, m_fontdesc);
1657 pango_layout_set_text(layout, "H", 1 );
1658 int w,h;
1659 pango_layout_get_pixel_size(layout, &w, &h);
1660 g_object_unref( G_OBJECT( layout ) );
1661 return w;
1662 #else
1663 GdkFont *font = m_font.GetInternalFont( m_scaleY );
1664 wxCHECK_MSG( font, -1, wxT("invalid font") );
1665
1666 return wxCoord(gdk_string_width( font, "H" ) / m_scaleX);
1667 #endif
1668 }
1669
1670 wxCoord wxWindowDC::GetCharHeight() const
1671 {
1672 #ifdef __WXGTK20__
1673 // There should be an easier way.
1674 PangoLayout *layout = pango_layout_new(m_context);
1675 pango_layout_set_font_description(layout, m_fontdesc);
1676 pango_layout_set_text(layout, "H", 1 );
1677 int w,h;
1678 pango_layout_get_pixel_size(layout, &w, &h);
1679 g_object_unref( G_OBJECT( layout ) );
1680 return h;
1681 #else
1682 GdkFont *font = m_font.GetInternalFont( m_scaleY );
1683 wxCHECK_MSG( font, -1, wxT("invalid font") );
1684
1685 return wxCoord((font->ascent + font->descent) / m_scaleY);
1686 #endif
1687 }
1688
1689 void wxWindowDC::Clear()
1690 {
1691 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1692
1693 if (!m_window) return;
1694
1695 // VZ: the code below results in infinite recursion and crashes when
1696 // dc.Clear() is done from OnPaint() so I disable it for now.
1697 // I don't know what the correct fix is but Clear() surely should not
1698 // reenter OnPaint()!
1699 #if 0
1700 /* - we either are a memory dc or have a window as the
1701 owner. anything else shouldn't happen.
1702 - we don't use gdk_window_clear() as we don't set
1703 the window's background colour anymore. it is too
1704 much pain to keep the DC's and the window's back-
1705 ground colour in synch. */
1706
1707 if (m_owner)
1708 {
1709 m_owner->Clear();
1710 return;
1711 }
1712
1713 if (m_isMemDC)
1714 {
1715 int width,height;
1716 GetSize( &width, &height );
1717 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
1718 return;
1719 }
1720 #else // 1
1721 int width,height;
1722 GetSize( &width, &height );
1723 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
1724 #endif // 0/1
1725 }
1726
1727 void wxWindowDC::SetFont( const wxFont &font )
1728 {
1729 // It is common practice to set the font to wxNullFont, so
1730 // don't consider it to be an error
1731 // wxCHECK_RET( font.Ok(), _T("invalid font in wxWindowDC::SetFont") );
1732
1733 m_font = font;
1734 #ifdef __WXGTK20__
1735 if (m_font.Ok())
1736 {
1737 m_fontdesc = m_font.GetNativeFontInfo()->description;
1738
1739 if (m_owner)
1740 {
1741 if (m_font.GetNoAntiAliasing())
1742 m_context = m_owner->GtkGetPangoX11Context();
1743 else
1744 m_context = m_owner->GtkGetPangoDefaultContext();
1745 }
1746 }
1747 #endif
1748 }
1749
1750 void wxWindowDC::SetPen( const wxPen &pen )
1751 {
1752 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1753
1754 if (m_pen == pen) return;
1755
1756 m_pen = pen;
1757
1758 if (!m_pen.Ok()) return;
1759
1760 if (!m_window) return;
1761
1762 gint width = m_pen.GetWidth();
1763 if (width <= 0)
1764 {
1765 // CMB: if width is non-zero scale it with the dc
1766 width = 1;
1767 }
1768 else
1769 {
1770 // X doesn't allow different width in x and y and so we take
1771 // the average
1772 double w = 0.5 +
1773 ( fabs((double) XLOG2DEVREL(width)) +
1774 fabs((double) YLOG2DEVREL(width)) ) / 2.0;
1775 width = (int)w;
1776 }
1777
1778 static const wxGTKDash dotted[] = {1, 1};
1779 static const wxGTKDash short_dashed[] = {2, 2};
1780 static const wxGTKDash wxCoord_dashed[] = {2, 4};
1781 static const wxGTKDash dotted_dashed[] = {3, 3, 1, 3};
1782
1783 // We express dash pattern in pen width unit, so we are
1784 // independent of zoom factor and so on...
1785 int req_nb_dash;
1786 const wxGTKDash *req_dash;
1787
1788 GdkLineStyle lineStyle = GDK_LINE_SOLID;
1789 switch (m_pen.GetStyle())
1790 {
1791 case wxUSER_DASH:
1792 {
1793 lineStyle = GDK_LINE_ON_OFF_DASH;
1794 req_nb_dash = m_pen.GetDashCount();
1795 req_dash = (wxGTKDash*)m_pen.GetDash();
1796 break;
1797 }
1798 case wxDOT:
1799 {
1800 lineStyle = GDK_LINE_ON_OFF_DASH;
1801 req_nb_dash = 2;
1802 req_dash = dotted;
1803 break;
1804 }
1805 case wxLONG_DASH:
1806 {
1807 lineStyle = GDK_LINE_ON_OFF_DASH;
1808 req_nb_dash = 2;
1809 req_dash = wxCoord_dashed;
1810 break;
1811 }
1812 case wxSHORT_DASH:
1813 {
1814 lineStyle = GDK_LINE_ON_OFF_DASH;
1815 req_nb_dash = 2;
1816 req_dash = short_dashed;
1817 break;
1818 }
1819 case wxDOT_DASH:
1820 {
1821 // lineStyle = GDK_LINE_DOUBLE_DASH;
1822 lineStyle = GDK_LINE_ON_OFF_DASH;
1823 req_nb_dash = 4;
1824 req_dash = dotted_dashed;
1825 break;
1826 }
1827
1828 case wxTRANSPARENT:
1829 case wxSTIPPLE_MASK_OPAQUE:
1830 case wxSTIPPLE:
1831 case wxSOLID:
1832 default:
1833 {
1834 lineStyle = GDK_LINE_SOLID;
1835 req_dash = (wxGTKDash*)NULL;
1836 req_nb_dash = 0;
1837 break;
1838 }
1839 }
1840
1841 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
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 #endif // GTK+ > 1.0
1859
1860 GdkCapStyle capStyle = GDK_CAP_ROUND;
1861 switch (m_pen.GetCap())
1862 {
1863 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
1864 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
1865 case wxCAP_ROUND:
1866 default:
1867 {
1868 if (width <= 1)
1869 {
1870 width = 0;
1871 capStyle = GDK_CAP_NOT_LAST;
1872 }
1873 else
1874 {
1875 capStyle = GDK_CAP_ROUND;
1876 }
1877 break;
1878 }
1879 }
1880
1881 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
1882 switch (m_pen.GetJoin())
1883 {
1884 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
1885 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
1886 case wxJOIN_ROUND:
1887 default: { joinStyle = GDK_JOIN_ROUND; break; }
1888 }
1889
1890 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
1891
1892 m_pen.GetColour().CalcPixel( m_cmap );
1893 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
1894 }
1895
1896 void wxWindowDC::SetBrush( const wxBrush &brush )
1897 {
1898 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1899
1900 if (m_brush == brush) return;
1901
1902 m_brush = brush;
1903
1904 if (!m_brush.Ok()) return;
1905
1906 if (!m_window) return;
1907
1908 m_brush.GetColour().CalcPixel( m_cmap );
1909 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
1910
1911 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
1912
1913 if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
1914 {
1915 if (m_brush.GetStipple()->GetPixmap())
1916 {
1917 gdk_gc_set_fill( m_brushGC, GDK_TILED );
1918 gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
1919 }
1920 else
1921 {
1922 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
1923 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() );
1924 }
1925 }
1926
1927 if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask()))
1928 {
1929 gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED);
1930 gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() );
1931 }
1932
1933 if (IS_HATCH(m_brush.GetStyle()))
1934 {
1935 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
1936 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
1937 gdk_gc_set_stipple( m_brushGC, hatches[num] );
1938 }
1939 }
1940
1941 void wxWindowDC::SetBackground( const wxBrush &brush )
1942 {
1943 /* CMB 21/7/98: Added SetBackground. Sets background brush
1944 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1945
1946 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1947
1948 if (m_backgroundBrush == brush) return;
1949
1950 m_backgroundBrush = brush;
1951
1952 if (!m_backgroundBrush.Ok()) return;
1953
1954 if (!m_window) return;
1955
1956 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
1957 gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
1958 gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
1959 gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
1960 gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
1961
1962 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
1963
1964 if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
1965 {
1966 if (m_backgroundBrush.GetStipple()->GetPixmap())
1967 {
1968 gdk_gc_set_fill( m_bgGC, GDK_TILED );
1969 gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
1970 }
1971 else
1972 {
1973 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
1974 gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() );
1975 }
1976 }
1977
1978 if (IS_HATCH(m_backgroundBrush.GetStyle()))
1979 {
1980 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
1981 int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
1982 gdk_gc_set_stipple( m_bgGC, hatches[num] );
1983 }
1984 }
1985
1986 void wxWindowDC::SetLogicalFunction( int function )
1987 {
1988 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1989
1990 if (m_logicalFunction == function)
1991 return;
1992
1993 // VZ: shouldn't this be a CHECK?
1994 if (!m_window)
1995 return;
1996
1997 GdkFunction mode;
1998 switch (function)
1999 {
2000 case wxXOR: mode = GDK_XOR; break;
2001 case wxINVERT: mode = GDK_INVERT; break;
2002 #if (GTK_MINOR_VERSION > 0) || (GTK_MAJOR_VERSION > 1)
2003 case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
2004 case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
2005 case wxCLEAR: mode = GDK_CLEAR; break;
2006 case wxSET: mode = GDK_SET; break;
2007 case wxOR_INVERT: mode = GDK_OR_INVERT; break;
2008 case wxAND: mode = GDK_AND; break;
2009 case wxOR: mode = GDK_OR; break;
2010 case wxEQUIV: mode = GDK_EQUIV; break;
2011 case wxNAND: mode = GDK_NAND; break;
2012 case wxAND_INVERT: mode = GDK_AND_INVERT; break;
2013 case wxCOPY: mode = GDK_COPY; break;
2014 case wxNO_OP: mode = GDK_NOOP; break;
2015 case wxSRC_INVERT: mode = GDK_COPY_INVERT; break;
2016
2017 // unsupported by GTK
2018 case wxNOR: mode = GDK_COPY; break;
2019 #endif // GTK+ > 1.0
2020 default:
2021 wxFAIL_MSG( wxT("unsupported logical function") );
2022 mode = GDK_COPY;
2023 }
2024
2025 m_logicalFunction = function;
2026
2027 gdk_gc_set_function( m_penGC, mode );
2028 gdk_gc_set_function( m_brushGC, mode );
2029
2030 // to stay compatible with wxMSW, we don't apply ROPs to the text
2031 // operations (i.e. DrawText/DrawRotatedText).
2032 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2033 gdk_gc_set_function( m_textGC, mode );
2034 }
2035
2036 void wxWindowDC::SetTextForeground( const wxColour &col )
2037 {
2038 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2039
2040 // don't set m_textForegroundColour to an invalid colour as we'd crash
2041 // later then (we use m_textForegroundColour.GetColor() without checking
2042 // in a few places)
2043 if ( !col.Ok() || (m_textForegroundColour == col) )
2044 return;
2045
2046 m_textForegroundColour = col;
2047
2048 if ( m_window )
2049 {
2050 m_textForegroundColour.CalcPixel( m_cmap );
2051 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
2052 }
2053 }
2054
2055 void wxWindowDC::SetTextBackground( const wxColour &col )
2056 {
2057 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2058
2059 // same as above
2060 if ( !col.Ok() || (m_textBackgroundColour == col) )
2061 return;
2062
2063 m_textBackgroundColour = col;
2064
2065 if ( m_window )
2066 {
2067 m_textBackgroundColour.CalcPixel( m_cmap );
2068 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
2069 }
2070 }
2071
2072 void wxWindowDC::SetBackgroundMode( int mode )
2073 {
2074 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2075
2076 m_backgroundMode = mode;
2077
2078 if (!m_window) return;
2079
2080 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2081 // transparent/solid background mode
2082
2083 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
2084 {
2085 gdk_gc_set_fill( m_brushGC,
2086 (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
2087 }
2088 }
2089
2090 void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
2091 {
2092 wxFAIL_MSG( wxT("wxWindowDC::SetPalette not implemented") );
2093 }
2094
2095 void wxWindowDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
2096 {
2097 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2098
2099 if (!m_window) return;
2100
2101 wxRect rect;
2102 rect.x = XLOG2DEV(x);
2103 rect.y = YLOG2DEV(y);
2104 rect.width = XLOG2DEVREL(width);
2105 rect.height = YLOG2DEVREL(height);
2106
2107 if (!m_currentClippingRegion.IsNull())
2108 m_currentClippingRegion.Intersect( rect );
2109 else
2110 m_currentClippingRegion.Union( rect );
2111
2112 #if USE_PAINT_REGION
2113 if (!m_paintClippingRegion.IsNull())
2114 m_currentClippingRegion.Intersect( m_paintClippingRegion );
2115 #endif
2116
2117 wxCoord xx, yy, ww, hh;
2118 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2119 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2120
2121 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2122 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2123 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2124 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
2125 }
2126
2127 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion &region )
2128 {
2129 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2130
2131 if (region.Empty())
2132 {
2133 DestroyClippingRegion();
2134 return;
2135 }
2136
2137 if (!m_window) return;
2138
2139 if (!m_currentClippingRegion.IsNull())
2140 m_currentClippingRegion.Intersect( region );
2141 else
2142 m_currentClippingRegion.Union( region );
2143
2144 #if USE_PAINT_REGION
2145 if (!m_paintClippingRegion.IsNull())
2146 m_currentClippingRegion.Intersect( m_paintClippingRegion );
2147 #endif
2148
2149 wxCoord xx, yy, ww, hh;
2150 m_currentClippingRegion.GetBox( xx, yy, ww, hh );
2151 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
2152
2153 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2154 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2155 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2156 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
2157 }
2158
2159 void wxWindowDC::DestroyClippingRegion()
2160 {
2161 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2162
2163 wxDC::DestroyClippingRegion();
2164
2165 m_currentClippingRegion.Clear();
2166
2167 #if USE_PAINT_REGION
2168 if (!m_paintClippingRegion.IsEmpty())
2169 m_currentClippingRegion.Union( m_paintClippingRegion );
2170 #endif
2171
2172 if (!m_window) return;
2173
2174 if (m_currentClippingRegion.IsEmpty())
2175 {
2176 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
2177 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
2178 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
2179 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
2180 }
2181 else
2182 {
2183 gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() );
2184 gdk_gc_set_clip_region( m_brushGC, m_currentClippingRegion.GetRegion() );
2185 gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() );
2186 gdk_gc_set_clip_region( m_bgGC, m_currentClippingRegion.GetRegion() );
2187 }
2188 }
2189
2190 void wxWindowDC::Destroy()
2191 {
2192 if (m_penGC) wxFreePoolGC( m_penGC );
2193 m_penGC = (GdkGC*) NULL;
2194 if (m_brushGC) wxFreePoolGC( m_brushGC );
2195 m_brushGC = (GdkGC*) NULL;
2196 if (m_textGC) wxFreePoolGC( m_textGC );
2197 m_textGC = (GdkGC*) NULL;
2198 if (m_bgGC) wxFreePoolGC( m_bgGC );
2199 m_bgGC = (GdkGC*) NULL;
2200 }
2201
2202 void wxWindowDC::ComputeScaleAndOrigin()
2203 {
2204 /* CMB: copy scale to see if it changes */
2205 double origScaleX = m_scaleX;
2206 double origScaleY = m_scaleY;
2207
2208 wxDC::ComputeScaleAndOrigin();
2209
2210 /* CMB: if scale has changed call SetPen to recalulate the line width */
2211 if ((m_scaleX != origScaleX || m_scaleY != origScaleY) &&
2212 (m_pen.Ok()))
2213 {
2214 /* this is a bit artificial, but we need to force wxDC to think
2215 the pen has changed */
2216 wxPen pen = m_pen;
2217 m_pen = wxNullPen;
2218 SetPen( pen );
2219 }
2220 }
2221
2222 // Resolution in pixels per logical inch
2223 wxSize wxWindowDC::GetPPI() const
2224 {
2225 return wxSize( (int) (m_mm_to_pix_x * 25.4 + 0.5), (int) (m_mm_to_pix_y * 25.4 + 0.5));
2226 }
2227
2228 int wxWindowDC::GetDepth() const
2229 {
2230 wxFAIL_MSG(wxT("not implemented"));
2231
2232 return -1;
2233 }
2234
2235
2236 //-----------------------------------------------------------------------------
2237 // wxPaintDC
2238 //-----------------------------------------------------------------------------
2239
2240 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
2241
2242 wxPaintDC::wxPaintDC( wxWindow *win )
2243 : wxClientDC( win )
2244 {
2245 #if USE_PAINT_REGION
2246 if (!win->m_clipPaintRegion)
2247 return;
2248
2249 m_paintClippingRegion = win->GetUpdateRegion();
2250 GdkRegion *region = m_paintClippingRegion.GetRegion();
2251 if ( region )
2252 {
2253 m_paintClippingRegion = win->GetUpdateRegion();
2254 GdkRegion *region = m_paintClippingRegion.GetRegion();
2255 if ( region )
2256 {
2257 m_currentClippingRegion.Union( m_paintClippingRegion );
2258
2259 gdk_gc_set_clip_region( m_penGC, region );
2260 gdk_gc_set_clip_region( m_brushGC, region );
2261 gdk_gc_set_clip_region( m_textGC, region );
2262 gdk_gc_set_clip_region( m_bgGC, region );
2263 }
2264 }
2265 #endif // USE_PAINT_REGION
2266 }
2267
2268 //-----------------------------------------------------------------------------
2269 // wxClientDC
2270 //-----------------------------------------------------------------------------
2271
2272 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
2273
2274 wxClientDC::wxClientDC( wxWindow *win )
2275 : wxWindowDC( win )
2276 {
2277 wxCHECK_RET( win, _T("NULL window in wxClientDC::wxClientDC") );
2278
2279 #ifdef __WXUNIVERSAL__
2280 wxPoint ptOrigin = win->GetClientAreaOrigin();
2281 SetDeviceOrigin(ptOrigin.x, ptOrigin.y);
2282 wxSize size = win->GetClientSize();
2283 SetClippingRegion(wxPoint(0, 0), size);
2284 #endif // __WXUNIVERSAL__
2285 }
2286
2287 void wxClientDC::DoGetSize(int *width, int *height) const
2288 {
2289 wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") );
2290
2291 m_owner->GetClientSize( width, height );
2292 }
2293
2294 // ----------------------------------------------------------------------------
2295 // wxDCModule
2296 // ----------------------------------------------------------------------------
2297
2298 class wxDCModule : public wxModule
2299 {
2300 public:
2301 bool OnInit();
2302 void OnExit();
2303
2304 private:
2305 DECLARE_DYNAMIC_CLASS(wxDCModule)
2306 };
2307
2308 IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
2309
2310 bool wxDCModule::OnInit()
2311 {
2312 wxInitGCPool();
2313 return TRUE;
2314 }
2315
2316 void wxDCModule::OnExit()
2317 {
2318 wxCleanUpGCPool();
2319 }