]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dcclient.cpp
wxMimeTypesManagerImpl::GetFileTypeFromMimeType() implemented
[wxWidgets.git] / src / gtk1 / dcclient.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcclient.cpp
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "dcclient.h"
12#endif
13
14#include "wx/dcclient.h"
6f65e337 15#include "wx/dcmemory.h"
4bc67cc5 16#include "wx/image.h"
f5368809 17#include <math.h>
c801d85f 18
83624f79
RR
19#include "gdk/gdk.h"
20#include "gtk/gtk.h"
21
c801d85f
KB
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
34static GdkPixmap *hatches[num_hatches];
c67daf87 35static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL;
c801d85f
KB
36
37//-----------------------------------------------------------------------------
38// constants
39//-----------------------------------------------------------------------------
40
41#define RAD2DEG 57.2957795131
42
6f65e337
JS
43//-----------------------------------------------------------------------------
44// temporary implementation of the missing GDK function
45//-----------------------------------------------------------------------------
46#include "gdk/gdkprivate.h"
47void gdk_draw_bitmap (GdkDrawable *drawable,
48 GdkGC *gc,
49 GdkDrawable *src,
50 gint xsrc,
51 gint ysrc,
52 gint xdest,
53 gint ydest,
54 gint width,
55 gint height)
56{
265898fd
RR
57 GdkWindowPrivate *drawable_private;
58 GdkWindowPrivate *src_private;
59 GdkGCPrivate *gc_private;
60
61 g_return_if_fail (drawable != NULL);
62 g_return_if_fail (src != NULL);
63 g_return_if_fail (gc != NULL);
64
65 drawable_private = (GdkWindowPrivate*) drawable;
66 src_private = (GdkWindowPrivate*) src;
67 if (drawable_private->destroyed || src_private->destroyed)
68 return;
69
70 gc_private = (GdkGCPrivate*) gc;
71
72 if (width == -1) width = src_private->width;
73 if (height == -1) height = src_private->height;
74
75 XCopyPlane( drawable_private->xdisplay,
76 src_private->xwindow,
77 drawable_private->xwindow,
78 gc_private->xgc,
79 xsrc, ysrc,
80 width, height,
81 xdest, ydest,
82 1 );
6f65e337
JS
83}
84
c801d85f 85//-----------------------------------------------------------------------------
ec758a20 86// wxWindowDC
c801d85f
KB
87//-----------------------------------------------------------------------------
88
ec758a20 89IMPLEMENT_DYNAMIC_CLASS(wxWindowDC,wxDC)
c801d85f 90
4bc67cc5 91wxWindowDC::wxWindowDC()
c801d85f 92{
265898fd
RR
93 m_penGC = (GdkGC *) NULL;
94 m_brushGC = (GdkGC *) NULL;
95 m_textGC = (GdkGC *) NULL;
96 m_bgGC = (GdkGC *) NULL;
97 m_cmap = (GdkColormap *) NULL;
98 m_isMemDC = FALSE;
903f689b 99}
c801d85f 100
ec758a20 101wxWindowDC::wxWindowDC( wxWindow *window )
c801d85f 102{
265898fd
RR
103 m_penGC = (GdkGC *) NULL;
104 m_brushGC = (GdkGC *) NULL;
105 m_textGC = (GdkGC *) NULL;
106 m_bgGC = (GdkGC *) NULL;
107 m_cmap = (GdkColormap *) NULL;
108
109 if (!window) return;
110 GtkWidget *widget = window->m_wxwindow;
111 if (!widget) return;
112 m_window = widget->window;
113 if (!m_window) return;
114 if (window->m_wxwindow)
115 m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
116 else
117 m_cmap = gtk_widget_get_colormap( window->m_widget );
0180d5da 118
265898fd 119 m_isMemDC = FALSE;
0180d5da 120
265898fd 121 SetUpDC();
76ed8f8d 122
903f689b 123}
c801d85f 124
4bc67cc5 125wxWindowDC::~wxWindowDC()
c801d85f 126{
265898fd 127 Destroy();
903f689b 128}
c801d85f 129
463c1fa1
RR
130void wxWindowDC::FloodFill( long WXUNUSED(x), long WXUNUSED(y),
131 const wxColour &WXUNUSED(col), int WXUNUSED(style) )
c801d85f 132{
ec758a20 133 wxFAIL_MSG( "wxWindowDC::FloodFill not implemented" );
903f689b 134}
c801d85f 135
ec758a20 136bool wxWindowDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
c801d85f 137{
ec758a20 138 wxFAIL_MSG( "wxWindowDC::GetPixel not implemented" );
265898fd 139 return FALSE;
903f689b 140}
c801d85f 141
ec758a20 142void wxWindowDC::DrawLine( long x1, long y1, long x2, long y2 )
c801d85f 143{
4bc67cc5 144 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 145
265898fd
RR
146 if (m_pen.GetStyle() != wxTRANSPARENT)
147 {
148 gdk_draw_line( m_window, m_penGC,
149 XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
ed880dd4
RR
150
151 CalcBoundingBox(x1, y1);
152 CalcBoundingBox(x2, y2);
265898fd 153 }
903f689b 154}
c801d85f 155
ec758a20 156void wxWindowDC::CrossHair( long x, long y )
c801d85f 157{
4bc67cc5 158 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 159
265898fd
RR
160 if (m_pen.GetStyle() != wxTRANSPARENT)
161 {
162 int w = 0;
163 int h = 0;
164 GetSize( &w, &h );
165 long xx = XLOG2DEV(x);
166 long yy = YLOG2DEV(y);
167 gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy );
168 gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) );
169 }
903f689b 170}
c801d85f 171
ec758a20 172void wxWindowDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double yc )
c801d85f 173{
4bc67cc5 174 wxCHECK_RET( Ok(), "invalid window dc" );
265898fd
RR
175
176 long xx1 = XLOG2DEV(x1);
177 long yy1 = YLOG2DEV(y1);
178 long xx2 = XLOG2DEV(x2);
179 long yy2 = YLOG2DEV(y2);
180 long xxc = XLOG2DEV((long)xc);
181 long yyc = YLOG2DEV((long)yc);
182 double dx = xx1 - xxc;
183 double dy = yy1 - yyc;
184 double radius = sqrt(dx*dx+dy*dy);
185 long r = (long)radius;
186 double radius1, radius2;
187
188 if (xx1 == xx2 && yy1 == yy2)
189 {
190 radius1 = 0.0;
191 radius2 = 360.0;
192 }
193 else
194 if (radius == 0.0)
195 {
196 radius1 = radius2 = 0.0;
197 }
198 else
199 {
200 radius1 = (xx1 - xxc == 0) ?
c801d85f
KB
201 (yy1 - yyc < 0) ? 90.0 : -90.0 :
202 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
265898fd 203 radius2 = (xx2 - xxc == 0) ?
c801d85f
KB
204 (yy2 - yyc < 0) ? 90.0 : -90.0 :
205 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
265898fd
RR
206 }
207 long alpha1 = long(radius1 * 64.0);
208 long alpha2 = long((radius2 - radius1) * 64.0);
209 while (alpha2 <= 0) alpha2 += 360*64;
210 while (alpha1 > 360*64) alpha1 -= 360*64;
211
212 if (m_brush.GetStyle() != wxTRANSPARENT)
213 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
c801d85f 214
265898fd
RR
215 if (m_pen.GetStyle() != wxTRANSPARENT)
216 gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
217
218 CalcBoundingBox (x1, y1);
219 CalcBoundingBox (x2, y2);
903f689b 220}
c801d85f 221
ec758a20 222void wxWindowDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
c801d85f 223{
4bc67cc5 224 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 225
265898fd
RR
226 long xx = XLOG2DEV(x);
227 long yy = YLOG2DEV(y);
228 long ww = m_signX * XLOG2DEVREL(width);
229 long hh = m_signY * YLOG2DEVREL(height);
c801d85f 230
265898fd
RR
231 // CMB: handle -ve width and/or height
232 if (ww < 0) { ww = -ww; xx = xx - ww; }
233 if (hh < 0) { hh = -hh; yy = yy - hh; }
6f65e337 234
265898fd
RR
235 long start = long(sa * 64.0);
236 long end = long(ea * 64.0);
237 if (m_brush.GetStyle() != wxTRANSPARENT)
238 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
c801d85f 239
265898fd
RR
240 if (m_pen.GetStyle() != wxTRANSPARENT)
241 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
242
243 CalcBoundingBox (x, y);
244 CalcBoundingBox (x + width, y + height);
903f689b 245}
c801d85f 246
ec758a20 247void wxWindowDC::DrawPoint( long x, long y )
c801d85f 248{
4bc67cc5 249 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 250
265898fd
RR
251 if (m_pen.GetStyle() != wxTRANSPARENT)
252 gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
253
254 CalcBoundingBox (x, y);
903f689b 255}
c801d85f 256
ec758a20 257void wxWindowDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
c801d85f 258{
4bc67cc5 259 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 260
265898fd
RR
261 if (m_pen.GetStyle() == wxTRANSPARENT) return;
262 if (n <= 0) return;
c801d85f 263
265898fd
RR
264 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
265
266 for (int i = 0; i < n-1; i++)
267 {
268 long x1 = XLOG2DEV(points[i].x + xoffset);
269 long x2 = XLOG2DEV(points[i+1].x + xoffset);
270 long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
271 long y2 = YLOG2DEV(points[i+1].y + yoffset);
272 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
273
274 CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset );
275 }
903f689b 276}
c801d85f 277
ec758a20 278void wxWindowDC::DrawLines( wxList *points, long xoffset, long yoffset )
c801d85f 279{
4bc67cc5 280 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 281
265898fd 282 if (m_pen.GetStyle() == wxTRANSPARENT) return;
c801d85f 283
265898fd
RR
284 wxNode *node = points->First();
285 if (!node) return;
286
287 wxPoint *pt = (wxPoint*)node->Data();
288 CalcBoundingBox( pt->x + xoffset, pt->y + yoffset );
289
290 while (node->Next())
291 {
292 wxPoint *point = (wxPoint*)node->Data();
293 wxPoint *npoint = (wxPoint*)node->Next()->Data();
294 long x1 = XLOG2DEV(point->x + xoffset);
295 long x2 = XLOG2DEV(npoint->x + xoffset);
296 long y1 = YLOG2DEV(point->y + yoffset); // and a waste again...
297 long y2 = YLOG2DEV(npoint->y + yoffset);
298 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
299 node = node->Next();
300
301 CalcBoundingBox( npoint->x + xoffset, npoint->y + yoffset );
302 }
903f689b 303}
c801d85f 304
ec758a20 305void wxWindowDC::DrawPolygon( int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle) )
cf7a7e13 306{
4bc67cc5 307 wxCHECK_RET( Ok(), "invalid window dc" );
cf7a7e13 308
4bc67cc5 309 if (n <= 0) return;
265898fd
RR
310
311 GdkPoint *gdkpoints = new GdkPoint[n+1];
312 int i;
313 for (i = 0 ; i < n ; i++)
314 {
315 gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset);
316 gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset);
317
318 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset );
319 }
320
321 if (m_brush.GetStyle() != wxTRANSPARENT)
322 gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
323
324 // To do: Fillstyle
325
326 if (m_pen.GetStyle() != wxTRANSPARENT)
327 for (i = 0 ; i < n ; i++)
328 {
329 gdk_draw_line( m_window, m_penGC,
330 gdkpoints[i%n].x,
331 gdkpoints[i%n].y,
332 gdkpoints[(i+1)%n].x,
333 gdkpoints[(i+1)%n].y);
334 }
335
336 delete[] gdkpoints;
903f689b 337}
c801d85f 338
ec758a20 339void wxWindowDC::DrawPolygon( wxList *lines, long xoffset, long yoffset, int WXUNUSED(fillStyle))
cf7a7e13 340{
4bc67cc5 341 wxCHECK_RET( Ok(), "invalid window dc" );
265898fd
RR
342
343 int n = lines->Number();
4bc67cc5 344 if (n <= 0) return;
265898fd
RR
345
346 GdkPoint *gdkpoints = new GdkPoint[n];
347 wxNode *node = lines->First();
348 int cnt = 0;
349 while (node)
350 {
351 wxPoint *p = (wxPoint *) node->Data();
352 gdkpoints[cnt].x = XLOG2DEV(p->x + xoffset);
353 gdkpoints[cnt].y = YLOG2DEV(p->y + yoffset);
354 node = node->Next();
355 cnt++;
356
357 CalcBoundingBox( p->x + xoffset, p->y + yoffset );
358 }
359
360 if (m_brush.GetStyle() != wxTRANSPARENT)
361 gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
362
363 // To do: Fillstyle
364
365 if (m_pen.GetStyle() != wxTRANSPARENT)
366 {
367 int i;
368 for (i = 0 ; i < n ; i++)
369 {
370 gdk_draw_line( m_window, m_penGC,
371 gdkpoints[i%n].x,
372 gdkpoints[i%n].y,
373 gdkpoints[(i+1)%n].x,
374 gdkpoints[(i+1)%n].y );
375 }
376 }
377 delete[] gdkpoints;
903f689b 378}
c801d85f 379
ec758a20 380void wxWindowDC::DrawRectangle( long x, long y, long width, long height )
c801d85f 381{
4bc67cc5 382 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 383
265898fd
RR
384 long xx = XLOG2DEV(x);
385 long yy = YLOG2DEV(y);
386 long ww = m_signX * XLOG2DEVREL(width);
387 long hh = m_signY * YLOG2DEVREL(height);
c801d85f 388
265898fd
RR
389 // CMB: draw nothing if transformed w or h is 0
390 if (ww == 0 || hh == 0) return;
6f65e337 391
265898fd
RR
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; }
6f65e337 395
265898fd
RR
396 if (m_brush.GetStyle() != wxTRANSPARENT)
397 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
c801d85f 398
265898fd
RR
399 if (m_pen.GetStyle() != wxTRANSPARENT)
400 gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
401
402 CalcBoundingBox( x, y );
403 CalcBoundingBox( x + width, y + height );
903f689b 404}
c801d85f 405
ec758a20 406void wxWindowDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
c801d85f 407{
4bc67cc5 408 wxCHECK_RET( Ok(), "invalid window dc" );
265898fd
RR
409
410 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
411
412 long xx = XLOG2DEV(x);
413 long yy = YLOG2DEV(y);
414 long ww = m_signX * XLOG2DEVREL(width);
415 long hh = m_signY * YLOG2DEVREL(height);
416 long rr = XLOG2DEVREL((long)radius);
417
418 // CMB: handle -ve width and/or height
419 if (ww < 0) { ww = -ww; xx = xx - ww; }
420 if (hh < 0) { hh = -hh; yy = yy - hh; }
421
422 // CMB: if radius is zero use DrawRectangle() instead to avoid
423 // X drawing errors with small radii
424 if (rr == 0)
425 {
426 DrawRectangle( x, y, width, height );
427 return;
428 }
429
430 // CMB: draw nothing if transformed w or h is 0
431 if (ww == 0 || hh == 0) return;
432
433 // CMB: adjust size if outline is drawn otherwise the result is
434 // 1 pixel too wide and high
435 if (m_pen.GetStyle() != wxTRANSPARENT)
436 {
437 ww--;
438 hh--;
439 }
440
441 // CMB: ensure dd is not larger than rectangle otherwise we
442 // get an hour glass shape
443 long dd = 2 * rr;
444 if (dd > ww) dd = ww;
445 if (dd > hh) dd = hh;
446 rr = dd / 2;
447
448 if (m_brush.GetStyle() != wxTRANSPARENT)
449 {
450 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
451 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
452 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
453 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
454 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
455 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
456 }
457
458 if (m_pen.GetStyle() != wxTRANSPARENT)
459 {
460 gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
461 gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
462 gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
463 gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
464 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
465 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
466 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
467 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
468 }
469
470 // this ignores the radius
471 CalcBoundingBox( x, y );
472 CalcBoundingBox( x + width, y + height );
903f689b 473}
c801d85f 474
ec758a20 475void wxWindowDC::DrawEllipse( long x, long y, long width, long height )
c801d85f 476{
4bc67cc5 477 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 478
265898fd
RR
479 long xx = XLOG2DEV(x);
480 long yy = YLOG2DEV(y);
481 long ww = m_signX * XLOG2DEVREL(width);
482 long hh = m_signY * YLOG2DEVREL(height);
6f65e337 483
265898fd
RR
484 // CMB: handle -ve width and/or height
485 if (ww < 0) { ww = -ww; xx = xx - ww; }
486 if (hh < 0) { hh = -hh; yy = yy - hh; }
c801d85f 487
265898fd
RR
488 if (m_brush.GetStyle() != wxTRANSPARENT)
489 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
c801d85f 490
265898fd
RR
491 if (m_pen.GetStyle() != wxTRANSPARENT)
492 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
493
ed880dd4 494 CalcBoundingBox( x - width, y - height );
265898fd 495 CalcBoundingBox( x + width, y + height );
903f689b 496}
c801d85f 497
4bc67cc5 498bool wxWindowDC::CanDrawBitmap() const
c801d85f 499{
4bc67cc5 500 return TRUE;
903f689b 501}
c801d85f 502
463c1fa1 503void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y )
c801d85f 504{
4bc67cc5
RR
505 DrawBitmap( icon, x, y, TRUE );
506}
507
508void wxWindowDC::DrawBitmap( const wxBitmap &bitmap, long x, long y, bool useMask )
509{
510 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 511
4bc67cc5 512 if (!bitmap.Ok()) return;
c801d85f 513
265898fd
RR
514 int xx = XLOG2DEV(x);
515 int yy = YLOG2DEV(y);
c801d85f 516
4bc67cc5
RR
517 int w = bitmap.GetWidth();
518 int h = bitmap.GetHeight();
c801d85f 519
4bc67cc5
RR
520 int ww = XLOG2DEVREL(w);
521 int hh = YLOG2DEVREL(h);
522
523 wxBitmap use_bitmap;
524
525 if ((w != ww) || (h != hh))
265898fd 526 {
4bc67cc5
RR
527 wxImage image( bitmap );
528 image = image.Scale( ww, hh );
529
530 use_bitmap = image.ConvertToBitmap();
265898fd 531 }
4bc67cc5 532 else
265898fd 533 {
4bc67cc5 534 use_bitmap = bitmap;
265898fd
RR
535 }
536
463c1fa1 537 GdkBitmap *mask = (GdkBitmap *) NULL;
4bc67cc5 538 if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
463c1fa1
RR
539
540 if (useMask && mask)
541 {
542 gdk_gc_set_clip_mask( m_penGC, mask );
543 gdk_gc_set_clip_origin( m_penGC, xx, yy );
544 }
545
4bc67cc5 546 GdkPixmap *pm = use_bitmap.GetPixmap();
463c1fa1
RR
547 gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
548
549 if (useMask && mask)
550 {
551 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
552 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
553 }
554
555 CalcBoundingBox( x, y );
4bc67cc5 556 CalcBoundingBox( x + w, y + h );
463c1fa1
RR
557}
558
ec758a20 559bool wxWindowDC::Blit( long xdest, long ydest, long width, long height,
4bc67cc5 560 wxDC *source, long xsrc, long ysrc, int logical_func, bool useMask )
c801d85f 561{
4bc67cc5 562 wxCHECK_MSG( Ok(), FALSE, "invalid window dc" );
e23d0e95 563
265898fd
RR
564 CalcBoundingBox( xdest, ydest );
565 CalcBoundingBox( xdest + width, ydest + height );
566
4bc67cc5
RR
567 int old_logical_func = m_logicalFunction;
568 SetLogicalFunction( logical_func );
569
265898fd 570 wxClientDC *csrc = (wxClientDC*)source;
f96aa4d9 571
265898fd 572 if (csrc->m_isMemDC)
6f65e337 573 {
265898fd 574 wxMemoryDC* srcDC = (wxMemoryDC*)source;
e23d0e95
RR
575 GdkPixmap* pmap = srcDC->m_selected.GetPixmap();
576 if (pmap)
577 {
578 long xx = XLOG2DEV(xdest);
579 long yy = YLOG2DEV(ydest);
580
581 GdkBitmap *mask = (GdkBitmap *) NULL;
582 if (srcDC->m_selected.GetMask()) mask = srcDC->m_selected.GetMask()->GetBitmap();
583
584 if (useMask && mask)
585 {
4bc67cc5
RR
586 gdk_gc_set_clip_mask( m_penGC, mask );
587 gdk_gc_set_clip_origin( m_penGC, xx, yy );
e23d0e95 588 }
031b2a7b 589
4bc67cc5 590 gdk_draw_pixmap( m_window, m_penGC, pmap,
e23d0e95
RR
591 source->DeviceToLogicalX(xsrc),
592 source->DeviceToLogicalY(ysrc),
593 xx,
594 yy,
595 source->DeviceToLogicalXRel(width),
596 source->DeviceToLogicalYRel(height) );
597
598 if (useMask && mask)
599 {
4bc67cc5
RR
600 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
601 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
e23d0e95
RR
602 }
603
4bc67cc5 604 SetLogicalFunction( old_logical_func );
e23d0e95
RR
605 return TRUE;
606 }
607
608 GdkBitmap* bmap = srcDC->m_selected.GetBitmap();
265898fd
RR
609 if (bmap)
610 {
611 long xx = XLOG2DEV(xdest);
612 long yy = YLOG2DEV(ydest);
df875e59 613
265898fd
RR
614 GdkBitmap *mask = (GdkBitmap *) NULL;
615 if (srcDC->m_selected.GetMask()) mask = srcDC->m_selected.GetMask()->GetBitmap();
df875e59 616
265898fd
RR
617 if (useMask && mask)
618 {
4bc67cc5
RR
619 gdk_gc_set_clip_mask( m_penGC, mask );
620 gdk_gc_set_clip_origin( m_penGC, xx, yy );
265898fd
RR
621 }
622
ee5e8025 623 gdk_draw_bitmap( m_window, m_textGC, bmap,
265898fd
RR
624 source->DeviceToLogicalX(xsrc),
625 source->DeviceToLogicalY(ysrc),
626 xx,
627 yy,
628 source->DeviceToLogicalXRel(width),
629 source->DeviceToLogicalYRel(height) );
df875e59 630
265898fd
RR
631 if (useMask && mask)
632 {
4bc67cc5
RR
633 gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
634 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
265898fd 635 }
df875e59 636
4bc67cc5 637 SetLogicalFunction( old_logical_func );
265898fd
RR
638 return TRUE;
639 }
6f65e337 640 }
c801d85f 641
4bc67cc5 642 gdk_window_copy_area ( m_window, m_penGC,
265898fd
RR
643 XLOG2DEV(xdest), YLOG2DEV(ydest),
644 csrc->GetWindow(),
645 source->DeviceToLogicalX(xsrc),
646 source->DeviceToLogicalY(ysrc),
647 source->DeviceToLogicalXRel(width),
648 source->DeviceToLogicalYRel(height) );
c801d85f 649
4bc67cc5
RR
650 SetLogicalFunction( old_logical_func );
651 return TRUE;
903f689b 652}
c801d85f 653
ec758a20 654void wxWindowDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) )
c801d85f 655{
4bc67cc5 656 wxCHECK_RET( Ok(), "invalid window dc" );
18a2fa37 657
265898fd 658 GdkFont *font = m_font.GetInternalFont( m_scaleY );
6f65e337 659
265898fd
RR
660 x = XLOG2DEV(x);
661 y = YLOG2DEV(y);
18a2fa37 662
265898fd
RR
663 // CMB 21/5/98: draw text background if mode is wxSOLID
664 if (m_backgroundMode == wxSOLID)
665 {
666 long width = gdk_string_width( font, text );
667 long height = font->ascent + font->descent;
668 gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
669 gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
670 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
671 }
672 gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text );
18a2fa37 673
265898fd
RR
674 // CMB 17/7/98: simple underline: ignores scaling and underlying
675 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
676 // properties (see wxXt implementation)
677 if (m_font.GetUnderlined())
678 {
679 long width = gdk_string_width( font, text );
680 long ul_y = y + font->ascent;
681 if (font->descent > 0) ul_y++;
682 gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
683 }
684
685 long w, h;
686 GetTextExtent (text, &w, &h);
687 CalcBoundingBox (x + w, y + h);
688 CalcBoundingBox (x, y);
903f689b 689}
c801d85f 690
4bc67cc5 691bool wxWindowDC::CanGetTextExtent() const
c801d85f 692{
265898fd 693 return TRUE;
903f689b 694}
c801d85f 695
ec758a20 696void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height,
c33c4050
RR
697 long *descent, long *externalLeading,
698 wxFont *theFont, bool WXUNUSED(use16) )
c801d85f 699{
4bc67cc5 700 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 701
265898fd
RR
702 wxFont fontToUse = m_font;
703 if (theFont) fontToUse = *theFont;
c33c4050 704
265898fd
RR
705 GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
706 if (width) (*width) = long(gdk_string_width( font, string ) / m_scaleX);
707 if (height) (*height) = long((font->ascent + font->descent) / m_scaleY);
708 if (descent) (*descent) = long(font->descent / m_scaleY);
709 if (externalLeading) (*externalLeading) = 0; // ??
903f689b 710}
c801d85f 711
4bc67cc5 712long wxWindowDC::GetCharWidth()
c801d85f 713{
4bc67cc5 714 wxCHECK_MSG( Ok(), 0, "invalid window dc" );
c801d85f 715
265898fd
RR
716 GdkFont *font = m_font.GetInternalFont( m_scaleY );
717 return long(gdk_string_width( font, "H" ) / m_scaleX);
903f689b 718}
c801d85f 719
4bc67cc5 720long wxWindowDC::GetCharHeight()
c801d85f 721{
4bc67cc5 722 wxCHECK_MSG( Ok(), 0, "invalid window dc" );
c801d85f 723
265898fd
RR
724 GdkFont *font = m_font.GetInternalFont( m_scaleY );
725 return long((font->ascent + font->descent) / m_scaleY);
903f689b 726}
c801d85f 727
4bc67cc5 728void wxWindowDC::Clear()
c801d85f 729{
4bc67cc5 730 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 731
265898fd
RR
732 if (!m_isMemDC)
733 {
734 gdk_window_clear( m_window );
735 }
736 else
737 {
738 int width,height;
739 GetSize( &width, &height );
740 gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
741 }
903f689b 742}
c801d85f 743
ec758a20 744void wxWindowDC::SetFont( const wxFont &font )
c801d85f 745{
4bc67cc5 746 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 747
265898fd 748 m_font = font;
903f689b 749}
c801d85f 750
ec758a20 751void wxWindowDC::SetPen( const wxPen &pen )
c801d85f 752{
4bc67cc5
RR
753 wxCHECK_RET( Ok(), "invalid window dc" );
754
265898fd
RR
755 if (m_pen == pen) return;
756
757 m_pen = pen;
758
759 if (!m_pen.Ok()) return;
760
761 gint width = m_pen.GetWidth();
762 // CMB: if width is non-zero scale it with the dc
763 if (width <= 0)
764 {
765 width = 1;
766 }
767 else
768 {
769 // X doesn't allow different width in x and y and so we take
770 // the average
771 double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0;
772 width = (int)w;
773 }
774
775 GdkLineStyle lineStyle = GDK_LINE_SOLID;
776 switch (m_pen.GetStyle())
777 {
778 case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; }
779 case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
780 case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
781 case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
782 case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; }
783 }
784
785 GdkCapStyle capStyle = GDK_CAP_ROUND;
786 switch (m_pen.GetCap())
787 {
788 case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; }
789 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }
790 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }
791 }
792
793 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
794 switch (m_pen.GetJoin())
795 {
796 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; }
797 case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; }
798 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; }
799 }
800
801 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
802
803 m_pen.GetColour().CalcPixel( m_cmap );
804 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
903f689b 805}
c801d85f 806
ec758a20 807void wxWindowDC::SetBrush( const wxBrush &brush )
c801d85f 808{
4bc67cc5 809 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 810
265898fd 811 if (m_brush == brush) return;
c801d85f 812
265898fd 813 m_brush = brush;
c801d85f 814
265898fd 815 if (!m_brush.Ok()) return;
c801d85f 816
265898fd
RR
817 m_brush.GetColour().CalcPixel( m_cmap );
818 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
c801d85f 819
265898fd
RR
820 GdkFill fillStyle = GDK_SOLID;
821 switch (m_brush.GetStyle())
822 {
823 case wxSOLID:
824 case wxTRANSPARENT:
825 break;
826 default:
827 fillStyle = GDK_STIPPLED;
828 }
c801d85f 829
265898fd 830 gdk_gc_set_fill( m_brushGC, fillStyle );
c801d85f 831
265898fd
RR
832 if (m_brush.GetStyle() == wxSTIPPLE)
833 {
834 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
835 }
836
837 if (IS_HATCH(m_brush.GetStyle()))
838 {
839 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
840 gdk_gc_set_stipple( m_brushGC, hatches[num] );
841 }
903f689b 842}
c801d85f 843
ec758a20 844void wxWindowDC::SetBackground( const wxBrush &brush )
46dc76ba 845{
4bc67cc5
RR
846 // CMB 21/7/98: Added SetBackground. Sets background brush
847 // for Clear() and bg colour for shapes filled with cross-hatch brush
848
849 wxCHECK_RET( Ok(), "invalid window dc" );
46dc76ba 850
265898fd 851 if (m_backgroundBrush == brush) return;
46dc76ba 852
265898fd 853 m_backgroundBrush = brush;
46dc76ba 854
265898fd 855 if (!m_backgroundBrush.Ok()) return;
46dc76ba 856
265898fd
RR
857 m_backgroundBrush.GetColour().CalcPixel( m_cmap );
858 gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
a802c3a1 859 gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
031b2a7b 860 gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
265898fd 861 gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
46dc76ba 862
265898fd
RR
863 GdkFill fillStyle = GDK_SOLID;
864 switch (m_backgroundBrush.GetStyle())
865 {
866 case wxSOLID:
867 case wxTRANSPARENT:
868 break;
869 default:
870 fillStyle = GDK_STIPPLED;
871 }
46dc76ba 872
265898fd 873 gdk_gc_set_fill( m_bgGC, fillStyle );
46dc76ba 874
265898fd
RR
875 if (m_backgroundBrush.GetStyle() == wxSTIPPLE)
876 {
877 gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
878 }
46dc76ba 879
265898fd
RR
880 if (IS_HATCH(m_backgroundBrush.GetStyle()))
881 {
882 int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
883 gdk_gc_set_stipple( m_bgGC, hatches[num] );
884 }
903f689b 885}
46dc76ba 886
ec758a20 887void wxWindowDC::SetLogicalFunction( int function )
c801d85f 888{
4bc67cc5
RR
889 wxCHECK_RET( Ok(), "invalid window dc" );
890
265898fd 891 if (m_logicalFunction == function) return;
4bc67cc5 892
265898fd
RR
893 GdkFunction mode = GDK_COPY;
894 switch (function)
895 {
896 case wxXOR: mode = GDK_INVERT; break;
897 case wxINVERT: mode = GDK_INVERT; break;
898 default: break;
899 }
4bc67cc5 900
265898fd
RR
901 m_logicalFunction = function;
902 gdk_gc_set_function( m_penGC, mode );
903 gdk_gc_set_function( m_brushGC, mode );
3bc755fc 904 gdk_gc_set_function( m_textGC, mode );
903f689b 905}
c801d85f 906
ec758a20 907void wxWindowDC::SetTextForeground( const wxColour &col )
c801d85f 908{
4bc67cc5 909 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 910
265898fd 911 if (m_textForegroundColour == col) return;
c801d85f 912
265898fd
RR
913 m_textForegroundColour = col;
914 if (!m_textForegroundColour.Ok()) return;
c801d85f 915
265898fd
RR
916 m_textForegroundColour.CalcPixel( m_cmap );
917 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
903f689b 918}
c801d85f 919
ec758a20 920void wxWindowDC::SetTextBackground( const wxColour &col )
c801d85f 921{
4bc67cc5 922 wxCHECK_RET( Ok(), "invalid window dc" );
c801d85f 923
265898fd 924 if (m_textBackgroundColour == col) return;
c801d85f 925
265898fd
RR
926 m_textBackgroundColour = col;
927 if (!m_textBackgroundColour.Ok()) return;
c801d85f 928
265898fd
RR
929 m_textBackgroundColour.CalcPixel( m_cmap );
930 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
903f689b 931}
c801d85f 932
ec758a20 933void wxWindowDC::SetBackgroundMode( int mode )
c801d85f 934{
4bc67cc5
RR
935 wxCHECK_RET( Ok(), "invalid window dc" );
936
265898fd 937 m_backgroundMode = mode;
46dc76ba 938
265898fd
RR
939 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
940 // transparent/solid background mode
4bc67cc5 941
265898fd
RR
942 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
943 {
944 gdk_gc_set_fill( m_brushGC,
945 (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
946 }
903f689b 947}
c801d85f 948
ec758a20 949void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
c801d85f 950{
4bc67cc5 951 wxFAIL_MSG( "wxWindowDC::SetPalette not implemented" );
903f689b 952}
c801d85f 953
ec758a20 954void wxWindowDC::SetClippingRegion( long x, long y, long width, long height )
c801d85f 955{
4bc67cc5
RR
956 wxCHECK_RET( Ok(), "invalid window dc" );
957
265898fd 958 wxDC::SetClippingRegion( x, y, width, height );
c801d85f 959
265898fd
RR
960 GdkRectangle rect;
961 rect.x = XLOG2DEV(x);
962 rect.y = YLOG2DEV(y);
963 rect.width = XLOG2DEVREL(width);
964 rect.height = YLOG2DEVREL(height);
965 gdk_gc_set_clip_rectangle( m_penGC, &rect );
966 gdk_gc_set_clip_rectangle( m_brushGC, &rect );
967 gdk_gc_set_clip_rectangle( m_textGC, &rect );
968 gdk_gc_set_clip_rectangle( m_bgGC, &rect );
903f689b 969}
c801d85f 970
463c1fa1
RR
971void wxWindowDC::SetClippingRegion( const wxRegion &region )
972{
4bc67cc5
RR
973 wxCHECK_RET( Ok(), "invalid window dc" );
974
463c1fa1
RR
975 if (region.Empty())
976 {
977 DestroyClippingRegion();
978 return;
979 }
980
981 gdk_gc_set_clip_region( m_penGC, region.GetRegion() );
982 gdk_gc_set_clip_region( m_brushGC, region.GetRegion() );
983 gdk_gc_set_clip_region( m_textGC, region.GetRegion() );
984 gdk_gc_set_clip_region( m_bgGC, region.GetRegion() );
985}
986
4bc67cc5 987void wxWindowDC::DestroyClippingRegion()
c801d85f 988{
4bc67cc5
RR
989 wxCHECK_RET( Ok(), "invalid window dc" );
990
265898fd 991 wxDC::DestroyClippingRegion();
c801d85f 992
265898fd
RR
993 gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL );
994 gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL );
995 gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL );
996 gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL );
903f689b 997}
c801d85f 998
4bc67cc5 999void wxWindowDC::SetUpDC()
c801d85f 1000{
265898fd
RR
1001 Destroy();
1002 m_ok = TRUE;
1003 m_logicalFunction = wxCOPY;
1004 m_penGC = gdk_gc_new( m_window );
1005 m_brushGC = gdk_gc_new( m_window );
1006 m_textGC = gdk_gc_new( m_window );
1007 m_bgGC = gdk_gc_new( m_window );
a802c3a1
RR
1008
1009 wxColour tmp_col( m_textForegroundColour );
1010 m_textForegroundColour = wxNullColour;
1011 SetTextForeground( tmp_col );
1012 tmp_col = m_textBackgroundColour;
1013 m_textBackgroundColour = wxNullColour;
1014 SetTextBackground( tmp_col );
031b2a7b
RR
1015
1016 wxPen tmp_pen( m_pen );
1017 m_pen = wxNullPen;
1018 SetPen( tmp_pen );
1019
1020 wxFont tmp_font( m_font );
1021 m_font = wxNullFont;
1022 SetFont( tmp_font );
1023
1024 wxBrush tmp_brush( m_brush );
1025 m_brush = wxNullBrush;
1026 SetBrush( tmp_brush );
1027
1028 tmp_brush = m_backgroundBrush;
1029 m_backgroundBrush = wxNullBrush;
1030 SetBackground( tmp_brush );
265898fd 1031
265898fd
RR
1032 if (!hatch_bitmap)
1033 {
1034 hatch_bitmap = hatches;
1035 hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height );
1036 hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height );
1037 hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height );
1038 hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height );
1039 hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height );
1040 hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height );
1041 }
903f689b 1042}
c801d85f 1043
4bc67cc5 1044void wxWindowDC::Destroy()
dbf858b5 1045{
265898fd
RR
1046 if (m_penGC) gdk_gc_unref( m_penGC );
1047 m_penGC = (GdkGC*) NULL;
1048 if (m_brushGC) gdk_gc_unref( m_brushGC );
1049 m_brushGC = (GdkGC*) NULL;
1050 if (m_textGC) gdk_gc_unref( m_textGC );
1051 m_textGC = (GdkGC*) NULL;
1052 if (m_bgGC) gdk_gc_unref( m_bgGC );
1053 m_bgGC = (GdkGC*) NULL;
dbf858b5
RR
1054}
1055
4bc67cc5 1056GdkWindow *wxWindowDC::GetWindow()
c801d85f 1057{
265898fd 1058 return m_window;
903f689b 1059}
c801d85f
KB
1060
1061// ----------------------------------- spline code ----------------------------------------
1062
1063void wx_quadratic_spline(double a1, double b1, double a2, double b2,
1064 double a3, double b3, double a4, double b4);
4bc67cc5 1065void wx_clear_stack();
c801d85f
KB
1066int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
1067 double *y3, double *x4, double *y4);
1068void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
1069 double x4, double y4);
1070static bool wx_spline_add_point(double x, double y);
1071static void wx_spline_draw_point_array(wxDC *dc);
1072
1073wxList wx_spline_point_list;
1074
1075#define half(z1, z2) ((z1+z2)/2.0)
1076#define THRESHOLD 5
1077
1078/* iterative version */
1079
1080void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
1081 double b4)
1082{
1083 register double xmid, ymid;
1084 double x1, y1, x2, y2, x3, y3, x4, y4;
1085
1086 wx_clear_stack();
1087 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
1088
1089 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
1090 xmid = (double)half(x2, x3);
1091 ymid = (double)half(y2, y3);
1092 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
1093 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
1094 wx_spline_add_point( x1, y1 );
1095 wx_spline_add_point( xmid, ymid );
1096 } else {
1097 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
1098 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
1099 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
1100 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
1101 }
1102 }
1103}
1104
1105/* utilities used by spline drawing routines */
1106
1107typedef struct wx_spline_stack_struct {
1108 double x1, y1, x2, y2, x3, y3, x4, y4;
1109} Stack;
1110
1111#define SPLINE_STACK_DEPTH 20
1112static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
1113static Stack *wx_stack_top;
1114static int wx_stack_count;
1115
4bc67cc5 1116void wx_clear_stack()
c801d85f
KB
1117{
1118 wx_stack_top = wx_spline_stack;
1119 wx_stack_count = 0;
1120}
1121
1122void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
1123{
1124 wx_stack_top->x1 = x1;
1125 wx_stack_top->y1 = y1;
1126 wx_stack_top->x2 = x2;
1127 wx_stack_top->y2 = y2;
1128 wx_stack_top->x3 = x3;
1129 wx_stack_top->y3 = y3;
1130 wx_stack_top->x4 = x4;
1131 wx_stack_top->y4 = y4;
1132 wx_stack_top++;
1133 wx_stack_count++;
1134}
1135
1136int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
1137 double *x3, double *y3, double *x4, double *y4)
1138{
1139 if (wx_stack_count == 0)
1140 return (0);
1141 wx_stack_top--;
1142 wx_stack_count--;
1143 *x1 = wx_stack_top->x1;
1144 *y1 = wx_stack_top->y1;
1145 *x2 = wx_stack_top->x2;
1146 *y2 = wx_stack_top->y2;
1147 *x3 = wx_stack_top->x3;
1148 *y3 = wx_stack_top->y3;
1149 *x4 = wx_stack_top->x4;
1150 *y4 = wx_stack_top->y4;
1151 return (1);
1152}
1153
1154static bool wx_spline_add_point(double x, double y)
1155{
1156 wxPoint *point = new wxPoint ;
1157 point->x = (int) x;
1158 point->y = (int) y;
1159 wx_spline_point_list.Append((wxObject*)point);
1160 return TRUE;
1161}
1162
1163static void wx_spline_draw_point_array(wxDC *dc)
1164{
1165 dc->DrawLines(&wx_spline_point_list, 0, 0 );
1166 wxNode *node = wx_spline_point_list.First();
1167 while (node)
1168 {
1169 wxPoint *point = (wxPoint *)node->Data();
1170 delete point;
1171 delete node;
1172 node = wx_spline_point_list.First();
1173 }
1174}
1175
ec758a20 1176void wxWindowDC::DrawSpline( wxList *points )
c801d85f 1177{
4bc67cc5
RR
1178 wxCHECK_RET( Ok(), "invalid window dc" );
1179
c801d85f
KB
1180 wxPoint *p;
1181 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
1182 double x1, y1, x2, y2;
1183
1184 wxNode *node = points->First();
1185 p = (wxPoint *)node->Data();
1186
1187 x1 = p->x;
1188 y1 = p->y;
1189
1190 node = node->Next();
1191 p = (wxPoint *)node->Data();
1192
1193 x2 = p->x;
1194 y2 = p->y;
1195 cx1 = (double)((x1 + x2) / 2);
1196 cy1 = (double)((y1 + y2) / 2);
1197 cx2 = (double)((cx1 + x2) / 2);
1198 cy2 = (double)((cy1 + y2) / 2);
1199
1200 wx_spline_add_point(x1, y1);
1201
1202 while ((node = node->Next()) != NULL)
1203 {
1204 p = (wxPoint *)node->Data();
1205 x1 = x2;
1206 y1 = y2;
1207 x2 = p->x;
1208 y2 = p->y;
1209 cx4 = (double)(x1 + x2) / 2;
1210 cy4 = (double)(y1 + y2) / 2;
1211 cx3 = (double)(x1 + cx4) / 2;
1212 cy3 = (double)(y1 + cy4) / 2;
1213
1214 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
1215
1216 cx1 = cx4;
1217 cy1 = cy4;
1218 cx2 = (double)(cx1 + x2) / 2;
1219 cy2 = (double)(cy1 + y2) / 2;
1220 }
1221
1222 wx_spline_add_point( cx1, cy1 );
1223 wx_spline_add_point( x2, y2 );
1224
1225 wx_spline_draw_point_array( this );
903f689b 1226}
ec758a20
RR
1227
1228
1229//-----------------------------------------------------------------------------
1230// wxPaintDC
1231//-----------------------------------------------------------------------------
1232
1233IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxWindowDC)
1234
4bc67cc5 1235wxPaintDC::wxPaintDC()
ec758a20
RR
1236 : wxWindowDC()
1237{
1238}
1239
1240wxPaintDC::wxPaintDC( wxWindow *win )
1241 : wxWindowDC( win )
1242{
1243}
1244
1245//-----------------------------------------------------------------------------
1246// wxClientDC
1247//-----------------------------------------------------------------------------
1248
1249IMPLEMENT_DYNAMIC_CLASS(wxClientDC,wxWindowDC)
1250
4bc67cc5 1251wxClientDC::wxClientDC()
ec758a20
RR
1252 : wxWindowDC()
1253{
1254}
1255
1256wxClientDC::wxClientDC( wxWindow *win )
1257 : wxWindowDC( win )
1258{
1259}
1260