]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dcclient.cpp
Added and corrected a few more html makefiles,
[wxWidgets.git] / src / gtk1 / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/dcclient.h"
15 #include "wx/dcmemory.h"
16 #include "wx/image.h"
17 #include <math.h>
18
19 #include "gdk/gdk.h"
20 #include "gtk/gtk.h"
21
22 //-----------------------------------------------------------------------------
23 // local data
24 //-----------------------------------------------------------------------------
25
26 #include "bdiag.xbm"
27 #include "fdiag.xbm"
28 #include "cdiag.xbm"
29 #include "horiz.xbm"
30 #include "verti.xbm"
31 #include "cross.xbm"
32 #define num_hatches 6
33
34 static GdkPixmap *hatches[num_hatches];
35 static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL;
36
37 //-----------------------------------------------------------------------------
38 // constants
39 //-----------------------------------------------------------------------------
40
41 #define RAD2DEG 57.2957795131
42
43 //-----------------------------------------------------------------------------
44 // temporary implementation of the missing GDK function
45 //-----------------------------------------------------------------------------
46
47 #include "gdk/gdkprivate.h"
48
49 void gdk_draw_bitmap (GdkDrawable *drawable,
50 GdkGC *gc,
51 GdkDrawable *src,
52 gint xsrc,
53 gint ysrc,
54 gint xdest,
55 gint ydest,
56 gint width,
57 gint height)
58 {
59 GdkWindowPrivate *drawable_private;
60 GdkWindowPrivate *src_private;
61 GdkGCPrivate *gc_private;
62
63 g_return_if_fail (drawable != NULL);
64 g_return_if_fail (src != NULL);
65 g_return_if_fail (gc != NULL);
66
67 drawable_private = (GdkWindowPrivate*) drawable;
68 src_private = (GdkWindowPrivate*) src;
69 if (drawable_private->destroyed || src_private->destroyed)
70 return;
71
72 gc_private = (GdkGCPrivate*) gc;
73
74 if (width == -1) width = src_private->width;
75 if (height == -1) height = src_private->height;
76
77 XCopyPlane( drawable_private->xdisplay,
78 src_private->xwindow,
79 drawable_private->xwindow,
80 gc_private->xgc,
81 xsrc, ysrc,
82 width, height,
83 xdest, ydest,
84 1 );
85 }
86
87 //-----------------------------------------------------------------------------
88 // wxWindowDC
89 //-----------------------------------------------------------------------------
90
91 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
92
93 wxWindowDC::wxWindowDC()
94 {
95 m_penGC = (GdkGC *) NULL;
96 m_brushGC = (GdkGC *) NULL;
97 m_textGC = (GdkGC *) NULL;
98 m_bgGC = (GdkGC *) NULL;
99 m_cmap = (GdkColormap *) NULL;
100 m_isMemDC = FALSE;
101 m_owner = (wxWindow *)NULL;
102 }
103
104 wxWindowDC::wxWindowDC( wxWindow *window )
105 {
106 m_penGC = (GdkGC *) NULL;
107 m_brushGC = (GdkGC *) NULL;
108 m_textGC = (GdkGC *) NULL;
109 m_bgGC = (GdkGC *) NULL;
110 m_cmap = (GdkColormap *) NULL;
111 m_owner = (wxWindow *)NULL;
112 m_isMemDC = FALSE;
113 m_font = window->GetFont();
114
115 wxASSERT_MSG( window, _T("DC needs a window") );
116
117 GtkWidget *widget = window->m_wxwindow;
118
119 wxASSERT_MSG( widget, _T("DC needs a widget") );
120
121 m_window = widget->window;
122
123 /* not realized ? */
124 if (!m_window)
125 {
126 /* don't report problems */
127 m_ok = TRUE;
128
129 return;
130 }
131
132 if (window->m_wxwindow)
133 m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
134 else
135 m_cmap = gtk_widget_get_colormap( window->m_widget );
136
137 SetUpDC();
138
139 /* this must be done after SetUpDC, bacause SetUpDC calls the
140 repective SetBrush, SetPen, SetBackground etc functions
141 to set up the DC. SetBackground call m_owner->SetBackground
142 and this might not be desired as the standard dc background
143 is white whereas a window might assume gray to be the
144 standard (as e.g. wxStatusBar) */
145
146 m_owner = window;
147 }
148
149 wxWindowDC::~wxWindowDC()
150 {
151 Destroy();
152 }
153
154 void wxWindowDC::DoFloodFill( long WXUNUSED(x), long WXUNUSED(y),
155 const wxColour &WXUNUSED(col), int WXUNUSED(style) )
156 {
157 wxFAIL_MSG( _T("wxWindowDC::DoFloodFill not implemented") );
158 }
159
160 bool wxWindowDC::DoGetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
161 {
162 wxFAIL_MSG( _T("wxWindowDC::DoGetPixel not implemented") );
163 return FALSE;
164 }
165
166 void wxWindowDC::DoDrawLine( long x1, long y1, long x2, long y2 )
167 {
168 wxCHECK_RET( Ok(), _T("invalid window dc") );
169
170 if (m_pen.GetStyle() != wxTRANSPARENT)
171 {
172 if (m_window)
173 gdk_draw_line( m_window, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
174
175 CalcBoundingBox(x1, y1);
176 CalcBoundingBox(x2, y2);
177 }
178 }
179
180 void wxWindowDC::DoCrossHair( long x, long y )
181 {
182 wxCHECK_RET( Ok(), _T("invalid window dc") );
183
184 if (m_pen.GetStyle() != wxTRANSPARENT)
185 {
186 int w = 0;
187 int h = 0;
188 GetSize( &w, &h );
189 long xx = XLOG2DEV(x);
190 long yy = YLOG2DEV(y);
191 if (m_window)
192 {
193 gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
194 gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
195 }
196 }
197 }
198
199 void wxWindowDC::DoDrawArc( long x1, long y1, long x2, long y2,
200 long xc, long yc )
201 {
202 wxCHECK_RET( Ok(), _T("invalid window dc") );
203
204 long xx1 = XLOG2DEV(x1);
205 long yy1 = YLOG2DEV(y1);
206 long xx2 = XLOG2DEV(x2);
207 long yy2 = YLOG2DEV(y2);
208 long xxc = XLOG2DEV(xc);
209 long yyc = YLOG2DEV(yc);
210 double dx = xx1 - xxc;
211 double dy = yy1 - yyc;
212 double radius = sqrt(dx*dx+dy*dy);
213 long r = (long)radius;
214 double radius1, radius2;
215
216 if (xx1 == xx2 && yy1 == yy2)
217 {
218 radius1 = 0.0;
219 radius2 = 360.0;
220 }
221 else
222 if (radius == 0.0)
223 {
224 radius1 = radius2 = 0.0;
225 }
226 else
227 {
228 radius1 = (xx1 - xxc == 0) ?
229 (yy1 - yyc < 0) ? 90.0 : -90.0 :
230 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
231 radius2 = (xx2 - xxc == 0) ?
232 (yy2 - yyc < 0) ? 90.0 : -90.0 :
233 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
234 }
235 long alpha1 = long(radius1 * 64.0);
236 long alpha2 = long((radius2 - radius1) * 64.0);
237 while (alpha2 <= 0) alpha2 += 360*64;
238 while (alpha1 > 360*64) alpha1 -= 360*64;
239
240 if (m_window)
241 {
242 if (m_brush.GetStyle() != wxTRANSPARENT)
243 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
244
245 if (m_pen.GetStyle() != wxTRANSPARENT)
246 gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
247 }
248
249 CalcBoundingBox (x1, y1);
250 CalcBoundingBox (x2, y2);
251 }
252
253 void wxWindowDC::DoDrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
254 {
255 wxCHECK_RET( Ok(), _T("invalid window dc") );
256
257 long xx = XLOG2DEV(x);
258 long yy = YLOG2DEV(y);
259 long ww = m_signX * XLOG2DEVREL(width);
260 long hh = m_signY * YLOG2DEVREL(height);
261
262 // CMB: handle -ve width and/or height
263 if (ww < 0) { ww = -ww; xx = xx - ww; }
264 if (hh < 0) { hh = -hh; yy = yy - hh; }
265
266 if (m_window)
267 {
268 long start = long(sa * 64.0);
269 long end = long(ea * 64.0);
270
271 if (m_brush.GetStyle() != wxTRANSPARENT)
272 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
273
274 if (m_pen.GetStyle() != wxTRANSPARENT)
275 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
276 }
277
278 CalcBoundingBox (x, y);
279 CalcBoundingBox (x + width, y + height);
280 }
281
282 void wxWindowDC::DoDrawPoint( long x, long y )
283 {
284 wxCHECK_RET( Ok(), _T("invalid window dc") );
285
286 if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
287 gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
288
289 CalcBoundingBox (x, y);
290 }
291
292 void wxWindowDC::DoDrawLines( int n, wxPoint points[], long xoffset, long yoffset )
293 {
294 wxCHECK_RET( Ok(), _T("invalid window dc") );
295
296 if (m_pen.GetStyle() == wxTRANSPARENT) return;
297 if (n <= 0) return;
298
299 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
300
301 for (int i = 0; i < n-1; i++)
302 {
303 long x1 = XLOG2DEV(points[i].x + xoffset);
304 long x2 = XLOG2DEV(points[i+1].x + xoffset);
305 long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
306 long y2 = YLOG2DEV(points[i+1].y + yoffset);
307
308 if (m_window)
309 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
310
311 CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset );
312 }
313 }
314
315 void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle) )
316 {
317 wxCHECK_RET( Ok(), _T("invalid window dc") );
318
319 if (n <= 0) return;
320
321 GdkPoint *gdkpoints = new GdkPoint[n+1];
322 int i;
323 for (i = 0 ; i < n ; i++)
324 {
325 gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset);
326 gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset);
327
328 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset );
329 }
330
331 if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window)
332 gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
333
334 // To do: Fillstyle
335
336 if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window)
337 {
338 for (i = 0 ; i < n ; i++)
339 {
340 gdk_draw_line( m_window, m_penGC,
341 gdkpoints[i%n].x,
342 gdkpoints[i%n].y,
343 gdkpoints[(i+1)%n].x,
344 gdkpoints[(i+1)%n].y);
345 }
346 }
347
348 delete[] gdkpoints;
349 }
350
351 void wxWindowDC::DoDrawRectangle( long x, long y, long width, long height )
352 {
353 wxCHECK_RET( Ok(), _T("invalid window dc") );
354
355 long xx = XLOG2DEV(x);
356 long yy = YLOG2DEV(y);
357 long ww = m_signX * XLOG2DEVREL(width);
358 long hh = m_signY * YLOG2DEVREL(height);
359
360 // CMB: draw nothing if transformed w or h is 0
361 if (ww == 0 || hh == 0) return;
362
363 // CMB: handle -ve width and/or height
364 if (ww < 0) { ww = -ww; xx = xx - ww; }
365 if (hh < 0) { hh = -hh; yy = yy - hh; }
366
367 if (m_window)
368 {
369 if (m_brush.GetStyle() != wxTRANSPARENT)
370 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
371
372 if (m_pen.GetStyle() != wxTRANSPARENT)
373 gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
374 }
375
376 CalcBoundingBox( x, y );
377 CalcBoundingBox( x + width, y + height );
378 }
379
380 void wxWindowDC::DoDrawRoundedRectangle( long x, long y, long width, long height, double radius )
381 {
382 wxCHECK_RET( Ok(), _T("invalid window dc") );
383
384 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
385
386 long xx = XLOG2DEV(x);
387 long yy = YLOG2DEV(y);
388 long ww = m_signX * XLOG2DEVREL(width);
389 long hh = m_signY * YLOG2DEVREL(height);
390 long rr = XLOG2DEVREL((long)radius);
391
392 // CMB: handle -ve width and/or height
393 if (ww < 0) { ww = -ww; xx = xx - ww; }
394 if (hh < 0) { hh = -hh; yy = yy - hh; }
395
396 // CMB: if radius is zero use DrawRectangle() instead to avoid
397 // X drawing errors with small radii
398 if (rr == 0)
399 {
400 DrawRectangle( x, y, width, height );
401 return;
402 }
403
404 // CMB: draw nothing if transformed w or h is 0
405 if (ww == 0 || hh == 0) return;
406
407 // CMB: adjust size if outline is drawn otherwise the result is
408 // 1 pixel too wide and high
409 if (m_pen.GetStyle() != wxTRANSPARENT)
410 {
411 ww--;
412 hh--;
413 }
414
415 if (m_window)
416 {
417 // CMB: ensure dd is not larger than rectangle otherwise we
418 // get an hour glass shape
419 long dd = 2 * rr;
420 if (dd > ww) dd = ww;
421 if (dd > hh) dd = hh;
422 rr = dd / 2;
423
424 if (m_brush.GetStyle() != wxTRANSPARENT)
425 {
426 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
427 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
428 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
429 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
430 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
431 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
432 }
433
434 if (m_pen.GetStyle() != wxTRANSPARENT)
435 {
436 gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
437 gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
438 gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
439 gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
440 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
441 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
442 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
443 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
444 }
445 }
446
447 // this ignores the radius
448 CalcBoundingBox( x, y );
449 CalcBoundingBox( x + width, y + height );
450 }
451
452 void wxWindowDC::DoDrawEllipse( long x, long y, long width, long height )
453 {
454 wxCHECK_RET( Ok(), _T("invalid window dc") );
455
456 long xx = XLOG2DEV(x);
457 long yy = YLOG2DEV(y);
458 long ww = m_signX * XLOG2DEVREL(width);
459 long hh = m_signY * YLOG2DEVREL(height);
460
461 // CMB: handle -ve width and/or height
462 if (ww < 0) { ww = -ww; xx = xx - ww; }
463 if (hh < 0) { hh = -hh; yy = yy - hh; }
464
465 if (m_window)
466 {
467 if (m_brush.GetStyle() != wxTRANSPARENT)
468 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
469
470 if (m_pen.GetStyle() != wxTRANSPARENT)
471 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
472 }
473
474 CalcBoundingBox( x - width, y - height );
475 CalcBoundingBox( x + width, y + height );
476 }
477
478 void wxWindowDC::DoDrawIcon( const wxIcon &icon, long x, long y )
479 {
480 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
481 DoDrawBitmap( (const wxBitmap&)icon, x, y, (bool)TRUE );
482 }
483
484 void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
485 long x, long y,
486 bool useMask )
487 {
488 wxCHECK_RET( Ok(), _T("invalid window dc") );
489
490 wxCHECK_RET( bitmap.Ok(), _T("invalid bitmap") );
491
492 /* scale/translate size and position */
493
494 int xx = XLOG2DEV(x);
495 int yy = YLOG2DEV(y);
496
497 int w = bitmap.GetWidth();
498 int h = bitmap.GetHeight();
499
500 CalcBoundingBox( x, y );
501 CalcBoundingBox( x + w, y + h );
502
503 if (!m_window) return;
504
505 int ww = XLOG2DEVREL(w);
506 int hh = YLOG2DEVREL(h);
507
508 /* scale bitmap if required */
509
510 wxBitmap use_bitmap;
511
512 if ((w != ww) || (h != hh))
513 {
514 wxImage image( bitmap );
515 image = image.Scale( ww, hh );
516
517 use_bitmap = image.ConvertToBitmap();
518 }
519 else
520 {
521 use_bitmap = bitmap;
522 }
523
524 /* apply mask if any */
525
526 GdkBitmap *mask = (GdkBitmap *) NULL;
527 if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
528
529 if (useMask && mask)
530 {
531 gdk_gc_set_clip_mask( m_penGC, mask );
532 gdk_gc_set_clip_origin( m_penGC, xx, yy );
533 }
534
535 /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
536
537 GdkPixmap *pm = use_bitmap.GetPixmap();
538 if (pm)
539 {
540 gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
541 }
542 else
543 {
544 GdkBitmap *bm = use_bitmap.GetBitmap();
545 if (bm)
546 {
547 gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 );
548 }
549 }
550
551 /* remove mask again if any */
552
553 if (useMask && mask)
554 {
555 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
556 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
557 }
558 }
559
560 bool wxWindowDC::DoBlit( long xdest, long ydest, long width, long height,
561 wxDC *source, long xsrc, long ysrc,
562 int logical_func, bool useMask )
563 {
564 /* this is the nth try to get this utterly useless function to
565 work. it now completely ignores the scaling or translation
566 of the source dc, but scales correctly on the target dc and
567 knows about possible mask information in a memory dc. */
568
569 wxCHECK_MSG( Ok(), FALSE, _T("invalid window dc") );
570
571 wxCHECK_MSG( source, FALSE, _T("invalid source dc") );
572
573 if (!m_window) return FALSE;
574
575 wxClientDC *srcDC = (wxClientDC*)source;
576 wxMemoryDC *memDC = (wxMemoryDC*)source;
577
578 bool use_bitmap_method = FALSE;
579
580 if (srcDC->m_isMemDC)
581 {
582 if (!memDC->m_selected.Ok()) return FALSE;
583
584 /* we use the "XCopyArea" way to copy a memory dc into
585 y different window if the memory dc BOTH
586 a) doesn't have any mask or its mask isn't used
587 b) it is clipped
588 c) is not 1-bit */
589
590 if (useMask && (memDC->m_selected.GetMask()))
591 {
592 /* we HAVE TO use the direct way for memory dcs
593 that have mask since the XCopyArea doesn't know
594 about masks */
595 use_bitmap_method = TRUE;
596 }
597 else if (memDC->m_selected.GetDepth() == 1)
598 {
599 /* we HAVE TO use the direct way for memory dcs
600 that are bitmaps because XCopyArea doesn't cope
601 with different bit depths */
602 use_bitmap_method = TRUE;
603 }
604 else if ((xsrc == 0) && (ysrc == 0) &&
605 (width == memDC->m_selected.GetWidth()) &&
606 (height == memDC->m_selected.GetHeight()))
607 {
608 /* we SHOULD use the direct way if all of the bitmap
609 in the memory dc is copied in which case XCopyArea
610 wouldn't be able able to boost performace by reducing
611 the area to be scaled */
612 use_bitmap_method = TRUE;
613 }
614 else
615 {
616 use_bitmap_method = FALSE;
617 }
618 }
619
620 CalcBoundingBox( xdest, ydest );
621 CalcBoundingBox( xdest + width, ydest + height );
622
623 int old_logical_func = m_logicalFunction;
624 SetLogicalFunction( logical_func );
625
626 if (use_bitmap_method)
627 {
628 /* scale/translate bitmap size */
629
630 long bm_width = memDC->m_selected.GetWidth();
631 long bm_height = memDC->m_selected.GetHeight();
632
633 long bm_ww = XLOG2DEVREL( bm_width );
634 long bm_hh = YLOG2DEVREL( bm_height );
635
636 /* scale bitmap if required */
637
638 wxBitmap use_bitmap;
639
640 if ((bm_width != bm_ww) || (bm_height != bm_hh))
641 {
642 wxImage image( memDC->m_selected );
643 image = image.Scale( bm_ww, bm_hh );
644
645 use_bitmap = image.ConvertToBitmap();
646 }
647 else
648 {
649 use_bitmap = memDC->m_selected;
650 }
651
652 /* scale/translate size and position */
653
654 long xx = XLOG2DEV(xdest);
655 long yy = YLOG2DEV(ydest);
656
657 long ww = XLOG2DEVREL(width);
658 long hh = YLOG2DEVREL(height);
659
660 /* apply mask if any */
661
662 GdkBitmap *mask = (GdkBitmap *) NULL;
663 if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
664
665 if (useMask && mask)
666 {
667 gdk_gc_set_clip_mask( m_penGC, mask );
668 gdk_gc_set_clip_origin( m_penGC, xx, yy );
669 }
670
671 /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
672
673 GdkPixmap *pm = use_bitmap.GetPixmap();
674 if (pm)
675 {
676 gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh );
677 }
678 else
679 {
680 GdkBitmap *bm = use_bitmap.GetBitmap();
681 if (bm)
682 {
683 /* we use the textGC here because blitting a bitmap is done
684 using the current text colour */
685 gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh );
686 }
687 }
688
689 /* remove mask again if any */
690
691 if (useMask && mask)
692 {
693 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
694 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
695 }
696 }
697 else /* use_bitmap_method */
698 {
699 /* scale/translate size and position */
700
701 long xx = XLOG2DEV(xdest);
702 long yy = YLOG2DEV(ydest);
703
704 long ww = XLOG2DEVREL(width);
705 long hh = YLOG2DEVREL(height);
706
707 if ((width != ww) || (height != hh))
708 {
709 /* draw source window into a bitmap as we cannot scale
710 a window in contrast to a bitmap. this would actually
711 work with memory dcs as well, but we'd lose the mask
712 information and waste one step in this process since
713 a memory already has a bitmap. all this is slightly
714 inefficient as we could take an XImage directly from
715 an X window, but we'd then also have to care that
716 the window is not outside the screen (in which case
717 we'd get a BadMatch or what not).
718 Is a double XGetImage and combined XGetPixel and
719 XPutPixel really faster? I'm not sure. look at wxXt
720 for a different implementation of the same problem. */
721
722 wxBitmap bitmap( width, height );
723 gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0,
724 srcDC->GetWindow(),
725 xsrc, ysrc, width, height );
726
727 /* scale image */
728
729 wxImage image( bitmap );
730 image = image.Scale( ww, hh );
731
732 /* convert to bitmap */
733
734 bitmap = image.ConvertToBitmap();
735
736 /* draw scaled bitmap */
737
738 gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
739
740 }
741 else
742 {
743 /* no scaling and not a memory dc with a mask either */
744
745 gdk_window_copy_area( m_window, m_penGC, xx, yy,
746 srcDC->GetWindow(),
747 xsrc, ysrc, width, height );
748 }
749 }
750
751 SetLogicalFunction( old_logical_func );
752 return TRUE;
753 }
754
755 void wxWindowDC::DoDrawText( const wxString &text, long x, long y )
756 {
757 wxCHECK_RET( Ok(), _T("invalid window dc") );
758
759 if (!m_window) return;
760
761 GdkFont *font = m_font.GetInternalFont( m_scaleY );
762
763 x = XLOG2DEV(x);
764 y = YLOG2DEV(y);
765
766 /* CMB 21/5/98: draw text background if mode is wxSOLID */
767 if (m_backgroundMode == wxSOLID)
768 {
769 long width = gdk_string_width( font, text.mbc_str() );
770 long height = font->ascent + font->descent;
771 gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
772 gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
773 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
774 }
775 gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
776
777 /* CMB 17/7/98: simple underline: ignores scaling and underlying
778 X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
779 properties (see wxXt implementation) */
780 if (m_font.GetUnderlined())
781 {
782 long width = gdk_string_width( font, text.mbc_str() );
783 long ul_y = y + font->ascent;
784 if (font->descent > 0) ul_y++;
785 gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
786 }
787
788 long w, h;
789 GetTextExtent (text, &w, &h);
790 CalcBoundingBox (x + w, y + h);
791 CalcBoundingBox (x, y);
792 }
793
794 void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height,
795 long *descent, long *externalLeading,
796 wxFont *theFont ) const
797 {
798 wxFont fontToUse = m_font;
799 if (theFont) fontToUse = *theFont;
800
801 GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
802 if (width) (*width) = long(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
803 if (height) (*height) = long((font->ascent + font->descent) / m_scaleY);
804 if (descent) (*descent) = long(font->descent / m_scaleY);
805 if (externalLeading) (*externalLeading) = 0; // ??
806 }
807
808 long wxWindowDC::GetCharWidth() const
809 {
810 GdkFont *font = m_font.GetInternalFont( m_scaleY );
811 return long(gdk_string_width( font, "H" ) / m_scaleX);
812 }
813
814 long wxWindowDC::GetCharHeight() const
815 {
816 GdkFont *font = m_font.GetInternalFont( m_scaleY );
817 return long((font->ascent + font->descent) / m_scaleY);
818 }
819
820 void wxWindowDC::Clear()
821 {
822 wxCHECK_RET( Ok(), _T("invalid window dc") );
823
824 if (!m_window) return;
825
826 /* - we either are a memory dc or have a window as the
827 owner. anything else shouldn't happen.
828 - we don't use gdk_window_clear() as we don't set
829 the window's background colour anymore. it is too
830 much pain to keep the DC's and the window's back-
831 ground colour in synch. */
832
833 if (m_owner)
834 {
835 int width,height;
836 m_owner->GetSize( &width, &height );
837 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
838 return;
839 }
840
841 if (m_isMemDC)
842 {
843 int width,height;
844 GetSize( &width, &height );
845 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
846 return;
847 }
848 }
849
850 void wxWindowDC::SetFont( const wxFont &font )
851 {
852 m_font = font;
853 }
854
855 void wxWindowDC::SetPen( const wxPen &pen )
856 {
857 wxCHECK_RET( Ok(), _T("invalid window dc") );
858
859 if (m_pen == pen) return;
860
861 m_pen = pen;
862
863 if (!m_pen.Ok()) return;
864
865 if (!m_window) return;
866
867 gint width = m_pen.GetWidth();
868 if (width <= 0)
869 {
870 // CMB: if width is non-zero scale it with the dc
871 width = 1;
872 }
873 else
874 {
875 // X doesn't allow different width in x and y and so we take
876 // the average
877 double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0;
878 width = (int)w;
879 }
880
881 const static char dotted[] = {1, 1};
882 const static char short_dashed[] = {2, 2};
883 const static char long_dashed[] = {2, 4};
884 const static char dotted_dashed[] = {3, 3, 1, 3};
885
886 // We express dash pattern in pen width unit, so we are
887 // independent of zoom factor and so on...
888 int req_nb_dash;
889 const char *req_dash;
890
891 GdkLineStyle lineStyle = GDK_LINE_SOLID;
892 switch (m_pen.GetStyle())
893 {
894 case wxUSER_DASH:
895 {
896 lineStyle = GDK_LINE_ON_OFF_DASH;
897 req_nb_dash = m_pen.GetDashCount();
898 req_dash = m_pen.GetDash();
899 break;
900 }
901 case wxDOT:
902 {
903 lineStyle = GDK_LINE_ON_OFF_DASH;
904 req_nb_dash = 2;
905 req_dash = dotted;
906 break;
907 }
908 case wxLONG_DASH:
909 {
910 lineStyle = GDK_LINE_ON_OFF_DASH;
911 req_nb_dash = 2;
912 req_dash = long_dashed;
913 break;
914 }
915 case wxSHORT_DASH:
916 {
917 lineStyle = GDK_LINE_ON_OFF_DASH;
918 req_nb_dash = 2;
919 req_dash = short_dashed;
920 break;
921 }
922 case wxDOT_DASH:
923 {
924 // lineStyle = GDK_LINE_DOUBLE_DASH;
925 lineStyle = GDK_LINE_ON_OFF_DASH;
926 req_nb_dash = 4;
927 req_dash = dotted_dashed;
928 break;
929 }
930
931 case wxTRANSPARENT:
932 case wxSTIPPLE:
933 case wxSOLID:
934 default:
935 {
936 lineStyle = GDK_LINE_SOLID;
937 req_dash = (wxDash*)NULL;
938 req_nb_dash = 0;
939 break;
940 }
941 }
942
943 #if (GTK_MINOR_VERSION > 0)
944 if (req_dash && req_nb_dash)
945 {
946 char *real_req_dash = new char[req_nb_dash];
947 if (real_req_dash)
948 {
949 for (int i = 0; i < req_nb_dash; i++)
950 real_req_dash[i] = req_dash[i] * width;
951 gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash );
952 delete[] real_req_dash;
953 }
954 else
955 {
956 // No Memory. We use non-scaled dash pattern...
957 gdk_gc_set_dashes( m_penGC, 0, (char*)req_dash, req_nb_dash );
958 }
959 }
960 #endif
961
962 GdkCapStyle capStyle = GDK_CAP_ROUND;
963 switch (m_pen.GetCap())
964 {
965 case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; }
966 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
967 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
968 }
969
970 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
971 switch (m_pen.GetJoin())
972 {
973 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
974 case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; }
975 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
976 }
977
978 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
979
980 m_pen.GetColour().CalcPixel( m_cmap );
981 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
982 }
983
984 void wxWindowDC::SetBrush( const wxBrush &brush )
985 {
986 wxCHECK_RET( Ok(), _T("invalid window dc") );
987
988 if (m_brush == brush) return;
989
990 m_brush = brush;
991
992 if (!m_brush.Ok()) return;
993
994 if (!m_window) return;
995
996 m_brush.GetColour().CalcPixel( m_cmap );
997 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
998
999 gdk_gc_set_fill( m_brushGC, GDK_SOLID );
1000
1001 if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
1002 {
1003 if (m_brush.GetStipple()->GetPixmap())
1004 {
1005 gdk_gc_set_fill( m_brushGC, GDK_TILED );
1006 gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
1007 }
1008 else
1009 {
1010 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
1011 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() );
1012 }
1013 }
1014
1015 if (IS_HATCH(m_brush.GetStyle()))
1016 {
1017 gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
1018 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
1019 gdk_gc_set_stipple( m_brushGC, hatches[num] );
1020 }
1021 }
1022
1023 void wxWindowDC::SetBackground( const wxBrush &brush )
1024 {
1025 /* CMB 21/7/98: Added SetBackground. Sets background brush
1026 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1027
1028 wxCHECK_RET( Ok(), _T("invalid window dc") );
1029
1030 if (m_backgroundBrush == brush) return;
1031
1032 m_backgroundBrush = brush;
1033
1034 if (!m_backgroundBrush.Ok()) return;
1035
1036 if (!m_window) return;
1037
1038 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
1039 gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
1040 gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
1041 gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
1042 gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
1043
1044 gdk_gc_set_fill( m_bgGC, GDK_SOLID );
1045
1046 if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
1047 {
1048 if (m_backgroundBrush.GetStipple()->GetPixmap())
1049 {
1050 gdk_gc_set_fill( m_bgGC, GDK_TILED );
1051 gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
1052 }
1053 else
1054 {
1055 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
1056 gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() );
1057 }
1058 }
1059
1060 if (IS_HATCH(m_backgroundBrush.GetStyle()))
1061 {
1062 gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
1063 int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
1064 gdk_gc_set_stipple( m_bgGC, hatches[num] );
1065 }
1066 }
1067
1068 void wxWindowDC::SetLogicalFunction( int function )
1069 {
1070 wxCHECK_RET( Ok(), _T("invalid window dc") );
1071
1072 if (m_logicalFunction == function) return;
1073
1074 GdkFunction mode = GDK_COPY;
1075 switch (function)
1076 {
1077 case wxXOR: mode = GDK_XOR; break;
1078 case wxINVERT: mode = GDK_INVERT; break;
1079 #if (GTK_MINOR_VERSION > 0)
1080 case wxOR_REVERSE: mode = GDK_OR_REVERSE; break;
1081 case wxAND_REVERSE: mode = GDK_AND_REVERSE; break;
1082 case wxCLEAR: mode = GDK_CLEAR; break;
1083 case wxSET: mode = GDK_SET; break;
1084 case wxOR_INVERT: mode = GDK_OR_INVERT; break;
1085 case wxSRC_AND:
1086 case wxAND: mode = GDK_AND; break;
1087 case wxSRC_OR:
1088 case wxOR: mode = GDK_OR; break;
1089 case wxEQUIV: mode = GDK_EQUIV; break;
1090 case wxNAND: mode = GDK_NAND; break;
1091 case wxAND_INVERT: mode = GDK_AND_INVERT; break;
1092 case wxCOPY: mode = GDK_COPY; break;
1093 case wxNO_OP: mode = GDK_NOOP; break;
1094 case wxSRC_INVERT: mode = GDK_COPY_INVERT; break;
1095 #endif
1096 default:
1097 {
1098 wxFAIL_MSG( _T("unsupported logical function") );
1099 break;
1100 }
1101 }
1102
1103 m_logicalFunction = function;
1104
1105 if (!m_window) return;
1106
1107 gdk_gc_set_function( m_penGC, mode );
1108 gdk_gc_set_function( m_brushGC, mode );
1109 gdk_gc_set_function( m_textGC, mode );
1110 }
1111
1112 void wxWindowDC::SetTextForeground( const wxColour &col )
1113 {
1114 wxCHECK_RET( Ok(), _T("invalid window dc") );
1115
1116 if (m_textForegroundColour == col) return;
1117
1118 m_textForegroundColour = col;
1119 if (!m_textForegroundColour.Ok()) return;
1120
1121 if (!m_window) return;
1122
1123 m_textForegroundColour.CalcPixel( m_cmap );
1124 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
1125 }
1126
1127 void wxWindowDC::SetTextBackground( const wxColour &col )
1128 {
1129 wxCHECK_RET( Ok(), _T("invalid window dc") );
1130
1131 if (m_textBackgroundColour == col) return;
1132
1133 m_textBackgroundColour = col;
1134 if (!m_textBackgroundColour.Ok()) return;
1135
1136 if (!m_window) return;
1137
1138 m_textBackgroundColour.CalcPixel( m_cmap );
1139 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
1140 }
1141
1142 void wxWindowDC::SetBackgroundMode( int mode )
1143 {
1144 wxCHECK_RET( Ok(), _T("invalid window dc") );
1145
1146 m_backgroundMode = mode;
1147
1148 if (!m_window) return;
1149
1150 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
1151 // transparent/solid background mode
1152
1153 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
1154 {
1155 gdk_gc_set_fill( m_brushGC,
1156 (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
1157 }
1158 }
1159
1160 void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
1161 {
1162 wxFAIL_MSG( _T("wxWindowDC::SetPalette not implemented") );
1163 }
1164
1165 void wxWindowDC::DoSetClippingRegion( long x, long y, long width, long height )
1166 {
1167 wxCHECK_RET( Ok(), _T("invalid window dc") );
1168
1169 wxDC::DoSetClippingRegion( x, y, width, height );
1170
1171 if (!m_window) return;
1172
1173 GdkRectangle rect;
1174 rect.x = XLOG2DEV(x);
1175 rect.y = YLOG2DEV(y);
1176 rect.width = XLOG2DEVREL(width);
1177 rect.height = YLOG2DEVREL(height);
1178 gdk_gc_set_clip_rectangle( m_penGC, &rect );
1179 gdk_gc_set_clip_rectangle( m_brushGC, &rect );
1180 gdk_gc_set_clip_rectangle( m_textGC, &rect );
1181 gdk_gc_set_clip_rectangle( m_bgGC, &rect );
1182 }
1183
1184 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion &region )
1185 {
1186 wxCHECK_RET( Ok(), _T("invalid window dc") );
1187
1188 if (region.Empty())
1189 {
1190 DestroyClippingRegion();
1191 return;
1192 }
1193
1194 if (!m_window) return;
1195
1196 gdk_gc_set_clip_region( m_penGC, region.GetRegion() );
1197 gdk_gc_set_clip_region( m_brushGC, region.GetRegion() );
1198 gdk_gc_set_clip_region( m_textGC, region.GetRegion() );
1199 gdk_gc_set_clip_region( m_bgGC, region.GetRegion() );
1200 }
1201
1202 void wxWindowDC::DestroyClippingRegion()
1203 {
1204 wxCHECK_RET( Ok(), _T("invalid window dc") );
1205
1206 wxDC::DestroyClippingRegion();
1207
1208 if (!m_window) return;
1209
1210 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
1211 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
1212 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
1213 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
1214 }
1215
1216 void wxWindowDC::SetUpDC()
1217 {
1218 Destroy();
1219 m_ok = TRUE;
1220 m_logicalFunction = wxCOPY;
1221 m_penGC = gdk_gc_new( m_window );
1222 m_brushGC = gdk_gc_new( m_window );
1223 m_textGC = gdk_gc_new( m_window );
1224 m_bgGC = gdk_gc_new( m_window );
1225
1226 wxColour tmp_col( m_textForegroundColour );
1227 m_textForegroundColour = wxNullColour;
1228 SetTextForeground( tmp_col );
1229 tmp_col = m_textBackgroundColour;
1230 m_textBackgroundColour = wxNullColour;
1231 SetTextBackground( tmp_col );
1232
1233 wxPen tmp_pen( m_pen );
1234 m_pen = wxNullPen;
1235 SetPen( tmp_pen );
1236
1237 wxFont tmp_font( m_font );
1238 m_font = wxNullFont;
1239 SetFont( tmp_font );
1240
1241 wxBrush tmp_brush( m_brush );
1242 m_brush = wxNullBrush;
1243 SetBrush( tmp_brush );
1244
1245 /*
1246 tmp_brush = m_backgroundBrush;
1247 m_backgroundBrush = wxNullBrush;
1248 SetBackground( tmp_brush );
1249 */
1250 tmp_brush = m_backgroundBrush;
1251 m_backgroundBrush = wxNullBrush;
1252 SetBackground( *wxWHITE_BRUSH );
1253 m_backgroundBrush = tmp_brush;
1254
1255 if (!hatch_bitmap)
1256 {
1257 hatch_bitmap = hatches;
1258 hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height );
1259 hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height );
1260 hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height );
1261 hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height );
1262 hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height );
1263 hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height );
1264 }
1265 }
1266
1267 void wxWindowDC::Destroy()
1268 {
1269 if (m_penGC) gdk_gc_unref( m_penGC );
1270 m_penGC = (GdkGC*) NULL;
1271 if (m_brushGC) gdk_gc_unref( m_brushGC );
1272 m_brushGC = (GdkGC*) NULL;
1273 if (m_textGC) gdk_gc_unref( m_textGC );
1274 m_textGC = (GdkGC*) NULL;
1275 if (m_bgGC) gdk_gc_unref( m_bgGC );
1276 m_bgGC = (GdkGC*) NULL;
1277 }
1278
1279 void wxWindowDC::ComputeScaleAndOrigin()
1280 {
1281 /* CMB: copy scale to see if it changes */
1282 double origScaleX = m_scaleX;
1283 double origScaleY = m_scaleY;
1284
1285 wxDC::ComputeScaleAndOrigin();
1286
1287 /* CMB: if scale has changed call SetPen to recalulate the line width */
1288 if ((m_scaleX != origScaleX || m_scaleY != origScaleY) &&
1289 (m_pen.Ok()))
1290 {
1291 /* this is a bit artificial, but we need to force wxDC to think
1292 the pen has changed */
1293 wxPen pen = m_pen;
1294 m_pen = wxNullPen;
1295 SetPen( pen );
1296 }
1297 }
1298
1299 // Resolution in pixels per logical inch
1300 wxSize wxWindowDC::GetPPI() const
1301 {
1302 return wxSize(100, 100);
1303 }
1304
1305 int wxWindowDC::GetDepth() const
1306 {
1307 wxFAIL_MSG(_T("not implemented"));
1308
1309 return -1;
1310 }
1311
1312 #if wxUSE_SPLINES
1313 // ----------------------------------- spline code ----------------------------------------
1314
1315 void wx_quadratic_spline(double a1, double b1, double a2, double b2,
1316 double a3, double b3, double a4, double b4);
1317 void wx_clear_stack();
1318 int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
1319 double *y3, double *x4, double *y4);
1320 void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
1321 double x4, double y4);
1322 static bool wx_spline_add_point(double x, double y);
1323 static void wx_spline_draw_point_array(wxDC *dc);
1324
1325 wxList wx_spline_point_list;
1326
1327 #define half(z1, z2) ((z1+z2)/2.0)
1328 #define THRESHOLD 5
1329
1330 /* iterative version */
1331
1332 void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
1333 double b4)
1334 {
1335 register double xmid, ymid;
1336 double x1, y1, x2, y2, x3, y3, x4, y4;
1337
1338 wx_clear_stack();
1339 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
1340
1341 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
1342 xmid = (double)half(x2, x3);
1343 ymid = (double)half(y2, y3);
1344 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
1345 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
1346 wx_spline_add_point( x1, y1 );
1347 wx_spline_add_point( xmid, ymid );
1348 } else {
1349 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
1350 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
1351 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
1352 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
1353 }
1354 }
1355 }
1356
1357 /* utilities used by spline drawing routines */
1358
1359 typedef struct wx_spline_stack_struct {
1360 double x1, y1, x2, y2, x3, y3, x4, y4;
1361 } Stack;
1362
1363 #define SPLINE_STACK_DEPTH 20
1364 static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
1365 static Stack *wx_stack_top;
1366 static int wx_stack_count;
1367
1368 void wx_clear_stack()
1369 {
1370 wx_stack_top = wx_spline_stack;
1371 wx_stack_count = 0;
1372 }
1373
1374 void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
1375 {
1376 wx_stack_top->x1 = x1;
1377 wx_stack_top->y1 = y1;
1378 wx_stack_top->x2 = x2;
1379 wx_stack_top->y2 = y2;
1380 wx_stack_top->x3 = x3;
1381 wx_stack_top->y3 = y3;
1382 wx_stack_top->x4 = x4;
1383 wx_stack_top->y4 = y4;
1384 wx_stack_top++;
1385 wx_stack_count++;
1386 }
1387
1388 int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
1389 double *x3, double *y3, double *x4, double *y4)
1390 {
1391 if (wx_stack_count == 0)
1392 return (0);
1393 wx_stack_top--;
1394 wx_stack_count--;
1395 *x1 = wx_stack_top->x1;
1396 *y1 = wx_stack_top->y1;
1397 *x2 = wx_stack_top->x2;
1398 *y2 = wx_stack_top->y2;
1399 *x3 = wx_stack_top->x3;
1400 *y3 = wx_stack_top->y3;
1401 *x4 = wx_stack_top->x4;
1402 *y4 = wx_stack_top->y4;
1403 return (1);
1404 }
1405
1406 static bool wx_spline_add_point(double x, double y)
1407 {
1408 wxPoint *point = new wxPoint ;
1409 point->x = (int) x;
1410 point->y = (int) y;
1411 wx_spline_point_list.Append((wxObject*)point);
1412 return TRUE;
1413 }
1414
1415 static void wx_spline_draw_point_array(wxDC *dc)
1416 {
1417 dc->DrawLines(&wx_spline_point_list, 0, 0 );
1418 wxNode *node = wx_spline_point_list.First();
1419 while (node)
1420 {
1421 wxPoint *point = (wxPoint *)node->Data();
1422 delete point;
1423 delete node;
1424 node = wx_spline_point_list.First();
1425 }
1426 }
1427
1428 void wxWindowDC::DoDrawSpline( wxList *points )
1429 {
1430 wxCHECK_RET( Ok(), _T("invalid window dc") );
1431
1432 wxPoint *p;
1433 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
1434 double x1, y1, x2, y2;
1435
1436 wxNode *node = points->First();
1437 p = (wxPoint *)node->Data();
1438
1439 x1 = p->x;
1440 y1 = p->y;
1441
1442 node = node->Next();
1443 p = (wxPoint *)node->Data();
1444
1445 x2 = p->x;
1446 y2 = p->y;
1447 cx1 = (double)((x1 + x2) / 2);
1448 cy1 = (double)((y1 + y2) / 2);
1449 cx2 = (double)((cx1 + x2) / 2);
1450 cy2 = (double)((cy1 + y2) / 2);
1451
1452 wx_spline_add_point(x1, y1);
1453
1454 while ((node = node->Next()) != NULL)
1455 {
1456 p = (wxPoint *)node->Data();
1457 x1 = x2;
1458 y1 = y2;
1459 x2 = p->x;
1460 y2 = p->y;
1461 cx4 = (double)(x1 + x2) / 2;
1462 cy4 = (double)(y1 + y2) / 2;
1463 cx3 = (double)(x1 + cx4) / 2;
1464 cy3 = (double)(y1 + cy4) / 2;
1465
1466 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
1467
1468 cx1 = cx4;
1469 cy1 = cy4;
1470 cx2 = (double)(cx1 + x2) / 2;
1471 cy2 = (double)(cy1 + y2) / 2;
1472 }
1473
1474 wx_spline_add_point( cx1, cy1 );
1475 wx_spline_add_point( x2, y2 );
1476
1477 wx_spline_draw_point_array( this );
1478 }
1479
1480 #endif // wxUSE_SPLINE
1481
1482 //-----------------------------------------------------------------------------
1483 // wxPaintDC
1484 //-----------------------------------------------------------------------------
1485
1486 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxWindowDC)
1487
1488 wxPaintDC::wxPaintDC()
1489 : wxWindowDC()
1490 {
1491 }
1492
1493 wxPaintDC::wxPaintDC( wxWindow *win )
1494 : wxWindowDC( win )
1495 {
1496 }
1497
1498 //-----------------------------------------------------------------------------
1499 // wxClientDC
1500 //-----------------------------------------------------------------------------
1501
1502 IMPLEMENT_DYNAMIC_CLASS(wxClientDC,wxWindowDC)
1503
1504 wxClientDC::wxClientDC()
1505 : wxWindowDC()
1506 {
1507 }
1508
1509 wxClientDC::wxClientDC( wxWindow *win )
1510 : wxWindowDC( win )
1511 {
1512 }
1513