]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcclient.cpp
Added STRICT corrections.
[wxWidgets.git] / src / gtk / dcclient.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcclient.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6f65e337 6// RCS-ID: $Id$
c801d85f
KB
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "dcclient.h"
13#endif
14
15#include "wx/dcclient.h"
6f65e337 16#include "wx/dcmemory.h"
c801d85f
KB
17
18//-----------------------------------------------------------------------------
19// local data
20//-----------------------------------------------------------------------------
21
22#include "bdiag.xbm"
23#include "fdiag.xbm"
24#include "cdiag.xbm"
25#include "horiz.xbm"
26#include "verti.xbm"
27#include "cross.xbm"
28#define num_hatches 6
29
30static GdkPixmap *hatches[num_hatches];
31static GdkPixmap **hatch_bitmap = NULL;
32
33//-----------------------------------------------------------------------------
34// constants
35//-----------------------------------------------------------------------------
36
37#define RAD2DEG 57.2957795131
38
6f65e337
JS
39//-----------------------------------------------------------------------------
40// temporary implementation of the missing GDK function
41//-----------------------------------------------------------------------------
42#include "gdk/gdkprivate.h"
43void gdk_draw_bitmap (GdkDrawable *drawable,
44 GdkGC *gc,
45 GdkDrawable *src,
46 gint xsrc,
47 gint ysrc,
48 gint xdest,
49 gint ydest,
50 gint width,
51 gint height)
52{
53 GdkWindowPrivate *drawable_private;
54 GdkWindowPrivate *src_private;
55 GdkGCPrivate *gc_private;
56
57 g_return_if_fail (drawable != NULL);
58 g_return_if_fail (src != NULL);
59 g_return_if_fail (gc != NULL);
60
61 drawable_private = (GdkWindowPrivate*) drawable;
62 src_private = (GdkWindowPrivate*) src;
63 if (drawable_private->destroyed || src_private->destroyed)
64 return;
65 gc_private = (GdkGCPrivate*) gc;
66
67 if (width == -1)
68 width = src_private->width;
69 if (height == -1)
70 height = src_private->height;
71
72 XCopyPlane (drawable_private->xdisplay,
73 src_private->xwindow,
74 drawable_private->xwindow,
75 gc_private->xgc,
76 xsrc, ysrc,
77 width, height,
78 xdest, ydest,
79 1);
80}
81
c801d85f
KB
82//-----------------------------------------------------------------------------
83// wxPaintDC
84//-----------------------------------------------------------------------------
85
86IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxDC)
87
88wxPaintDC::wxPaintDC(void)
89{
90};
91
92wxPaintDC::wxPaintDC( wxWindow *window )
93{
94 if (!window) return;
95 GtkWidget *widget = window->m_wxwindow;
96 if (!widget) return;
97 m_window = widget->window;
98 if (!m_window) return;
99 if (window->m_wxwindow)
100 m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
101 else
102 m_cmap = gtk_widget_get_colormap( window->m_widget );
0180d5da
RR
103
104 m_isDrawable = TRUE;
105
c801d85f
KB
106 SetUpDC();
107
108 long x = 0;
109 long y = 0;
110 window->GetDrawingOffset( &x, &y );
111 SetInternalDeviceOrigin( -x, -y );
112};
113
114wxPaintDC::~wxPaintDC(void)
115{
116};
117
118void wxPaintDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1),
119 wxColour *WXUNUSED(col), int WXUNUSED(style) )
120{
121};
122
123bool wxPaintDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
124{
125 return FALSE;
126};
127
128void wxPaintDC::DrawLine( long x1, long y1, long x2, long y2 )
129{
130 if (!Ok()) return;
131
132 if (m_pen.GetStyle() != wxTRANSPARENT)
133 {
134 gdk_draw_line( m_window, m_penGC,
135 XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
136 };
137};
138
139void wxPaintDC::CrossHair( long x, long y )
140{
141 if (!Ok()) return;
142
143 if (m_pen.GetStyle() != wxTRANSPARENT)
144 {
145 int w = 0;
146 int h = 0;
147 GetSize( &w, &h );
148 long xx = XLOG2DEV(x);
149 long yy = YLOG2DEV(y);
150 gdk_draw_line( m_window, m_penGC,
151 0, yy, XLOG2DEVREL(w), yy );
152 gdk_draw_line( m_window, m_penGC,
153 xx, 0, xx, YLOG2DEVREL(h) );
154 };
155};
156
157void wxPaintDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double yc )
158{
159 if (!Ok()) return;
160
161 long xx1 = XLOG2DEV(x1);
162 long yy1 = YLOG2DEV(y1);
163 long xx2 = XLOG2DEV(x2);
164 long yy2 = YLOG2DEV(y2);
165 long xxc = XLOG2DEV((long)xc);
166 long yyc = YLOG2DEV((long)yc);
167 double dx = xx1 - xxc;
168 double dy = yy1 - yyc;
169 double radius = sqrt(dx*dx+dy*dy);
170 long r = (long)radius;
171 double radius1, radius2;
172
173 if (xx1 == xx2 && yy1 == yy2)
174 {
175 radius1 = 0.0;
176 radius2 = 360.0;
177 }
178 else
179 if (radius == 0.0)
180 {
181 radius1 = radius2 = 0.0;
182 }
183 else
184 {
185 radius1 = (xx1 - xxc == 0) ?
186 (yy1 - yyc < 0) ? 90.0 : -90.0 :
187 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
188 radius2 = (xx2 - xxc == 0) ?
189 (yy2 - yyc < 0) ? 90.0 : -90.0 :
190 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
191 };
192 long alpha1 = long(radius1 * 64.0);
193 long alpha2 = long((radius2 - radius1) * 64.0);
194 while (alpha2 <= 0) alpha2 += 360*64;
195 while (alpha1 > 360*64) alpha1 -= 360*64;
196
197 if (m_brush.GetStyle() != wxTRANSPARENT)
198 gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
199
200 if (m_pen.GetStyle() != wxTRANSPARENT)
201 gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
202
203};
204
205void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
206{
207 if (!Ok()) return;
208
c801d85f
KB
209 long xx = XLOG2DEV(x);
210 long yy = YLOG2DEV(y);
6f65e337
JS
211 long ww = m_signX * XLOG2DEVREL(width);
212 long hh = m_signY * YLOG2DEVREL(height);
c801d85f 213
6f65e337
JS
214 // CMB: handle -ve width and/or height
215 if (ww < 0) { ww = -ww; xx = xx - ww; }
216 if (hh < 0) { hh = -hh; yy = yy - hh; }
217
218 long start = long(sa * 64.0);
219 long end = long(ea * 64.0);
c801d85f 220 if (m_brush.GetStyle() != wxTRANSPARENT)
6f65e337 221 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end );
c801d85f
KB
222
223 if (m_pen.GetStyle() != wxTRANSPARENT)
6f65e337 224 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end );
c801d85f
KB
225};
226
227void wxPaintDC::DrawPoint( long x, long y )
228{
229 if (!Ok()) return;
230
231 if (m_pen.GetStyle() != wxTRANSPARENT)
232 gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
233};
234
235void wxPaintDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
236{
237 if (!Ok()) return;
238
239 if (m_pen.GetStyle() == wxTRANSPARENT) return;
240
241 for (int i = 0; i < n-1; i++)
242 {
243 long x1 = XLOG2DEV(points[i].x + xoffset);
244 long x2 = XLOG2DEV(points[i+1].x + xoffset);
245 long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
246 long y2 = YLOG2DEV(points[i+1].y + yoffset);
4c681997 247 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
c801d85f
KB
248 };
249};
250
251void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset )
252{
253 if (!Ok()) return;
254
255 if (m_pen.GetStyle() == wxTRANSPARENT) return;
256
257 wxNode *node = points->First();
258 while (node->Next())
259 {
260 wxPoint *point = (wxPoint*)node->Data();
261 wxPoint *npoint = (wxPoint*)node->Next()->Data();
262 long x1 = XLOG2DEV(point->x + xoffset);
263 long x2 = XLOG2DEV(npoint->x + xoffset);
264 long y1 = YLOG2DEV(point->y + yoffset); // and again...
265 long y2 = YLOG2DEV(npoint->y + yoffset);
4c681997 266 gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
c801d85f
KB
267 node = node->Next();
268 };
269};
270
271void wxPaintDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[],
272 long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
273{
274 if (!Ok()) return;
275};
276
277void wxPaintDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset),
278 long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
279{
280 if (!Ok()) return;
281};
282
283void wxPaintDC::DrawRectangle( long x, long y, long width, long height )
284{
285 if (!Ok()) return;
286
287 long xx = XLOG2DEV(x);
288 long yy = YLOG2DEV(y);
6f65e337
JS
289 long ww = m_signX * XLOG2DEVREL(width);
290 long hh = m_signY * YLOG2DEVREL(height);
c801d85f 291
6f65e337
JS
292 // CMB: draw nothing if transformed w or h is 0
293 if (ww == 0 || hh == 0) return;
294
295 // CMB: handle -ve width and/or height
296 if (ww < 0) { ww = -ww; xx = xx - ww; }
297 if (hh < 0) { hh = -hh; yy = yy - hh; }
298
c801d85f
KB
299 if (m_brush.GetStyle() != wxTRANSPARENT)
300 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
301
302 if (m_pen.GetStyle() != wxTRANSPARENT)
303 gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
304};
305
306void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
307{
308 if (!Ok()) return;
309
c801d85f
KB
310 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
311
312 long xx = XLOG2DEV(x);
313 long yy = YLOG2DEV(y);
6f65e337
JS
314 long ww = m_signX * XLOG2DEVREL(width);
315 long hh = m_signY * YLOG2DEVREL(height);
c801d85f 316 long rr = XLOG2DEVREL((long)radius);
6f65e337
JS
317
318 // CMB: handle -ve width and/or height
319 if (ww < 0) { ww = -ww; xx = xx - ww; }
320 if (hh < 0) { hh = -hh; yy = yy - hh; }
321
322 // CMB: if radius is zero use DrawRectangle() instead to avoid
323 // X drawing errors with small radii
324 if (rr == 0)
325 {
326 DrawRectangle( x, y, width, height );
327 return;
328 }
329
330 // CMB: draw nothing if transformed w or h is 0
331 if (ww == 0 || hh == 0) return;
332
333 // CMB: adjust size if outline is drawn otherwise the result is
334 // 1 pixel too wide and high
335 if (m_pen.GetStyle() != wxTRANSPARENT)
336 {
337 ww--;
338 hh--;
339 }
340
341 // CMB: ensure dd is not larger than rectangle otherwise we
342 // get an hour glass shape
c801d85f 343 long dd = 2 * rr;
6f65e337
JS
344 if (dd > ww) dd = ww;
345 if (dd > hh) dd = hh;
346 rr = dd / 2;
c801d85f
KB
347
348 if (m_brush.GetStyle() != wxTRANSPARENT)
349 {
6f65e337
JS
350 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh );
351 gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 );
c801d85f
KB
352 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
353 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
354 gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
355 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
356 };
357
358 if (m_pen.GetStyle() != wxTRANSPARENT)
359 {
360 gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
361 gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
362 gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
363 gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
364 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
365 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
366 gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
367 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
368 };
369};
370
371void wxPaintDC::DrawEllipse( long x, long y, long width, long height )
372{
373 if (!Ok()) return;
374
c801d85f
KB
375 long xx = XLOG2DEV(x);
376 long yy = YLOG2DEV(y);
6f65e337
JS
377 long ww = m_signX * XLOG2DEVREL(width);
378 long hh = m_signY * YLOG2DEVREL(height);
379
380 // CMB: handle -ve width and/or height
381 if (ww < 0) { ww = -ww; xx = xx - ww; }
382 if (hh < 0) { hh = -hh; yy = yy - hh; }
c801d85f
KB
383
384 if (m_brush.GetStyle() != wxTRANSPARENT)
385 gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
386
387 if (m_pen.GetStyle() != wxTRANSPARENT)
388 gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
389};
390
391bool wxPaintDC::CanDrawBitmap(void) const
392{
393 return TRUE;
394};
395
396void wxPaintDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
397{
398 if (!Ok()) return;
399
400 if (!icon.Ok()) return;
401
402 int xx = XLOG2DEV(x);
403 int yy = YLOG2DEV(y);
404
405 GdkBitmap *mask = NULL;
406 if (icon.GetMask()) mask = icon.GetMask()->GetBitmap();
407
408 if (useMask && mask)
409 {
410 gdk_gc_set_clip_mask( m_penGC, mask );
411 gdk_gc_set_clip_origin( m_penGC, xx, yy );
412 };
413
414 GdkPixmap *pm = icon.GetPixmap();
415 gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
416
417 if (useMask && mask)
418 {
419 gdk_gc_set_clip_mask( m_penGC, NULL );
420 gdk_gc_set_clip_origin( m_penGC, 0, 0 );
421 };
422};
423
424bool wxPaintDC::Blit( long xdest, long ydest, long width, long height,
425 wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) )
426{
427 if (!Ok()) return FALSE;
428
6f65e337
JS
429 // CMB 20/5/98: add blitting of bitmaps
430 if (source->IsKindOf(CLASSINFO(wxMemoryDC)))
431 {
432 wxMemoryDC* srcDC = (wxMemoryDC*)source;
433 GdkBitmap* bmap = srcDC->m_selected.GetBitmap();
434 if (bmap)
435 {
436 gdk_draw_bitmap (
437 m_window,
438 m_textGC,
439 bmap,
440 source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc),
441 XLOG2DEV(xdest), YLOG2DEV(ydest),
442 source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height)
443 );
444 return TRUE;
445 }
446 }
c801d85f 447
6f65e337 448 wxClientDC *csrc = (wxClientDC*)source;
c801d85f
KB
449 gdk_window_copy_area ( m_window, m_penGC,
450 XLOG2DEV(xdest), YLOG2DEV(ydest),
451 csrc->GetWindow(),
452 source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc),
453 source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height) );
454
455/*
456 gdk_window_copy_area ( m_window, m_penGC,
457 XLOG2DEV(xdest), YLOG2DEV(ydest),
458 csrc->GetWindow(),
459 xsrc, ysrc,
460 width, height );
461*/
462
463 return TRUE;
464};
465
466void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) )
467{
468 if (!Ok()) return;
469
470 GdkFont *font = m_font.GetInternalFont( m_scaleY );
6f65e337
JS
471
472 // CMB 21/5/98: draw text background if mode is wxSOLID
473 if (m_backgroundMode == wxSOLID)
474 {
475 long width = gdk_string_width( font, text );
476 long height = font->ascent + font->descent;
477 gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
478 gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
479 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
480 }
c801d85f
KB
481 gdk_draw_string( m_window, font, m_textGC,
482 XLOG2DEV(x),
483 YLOG2DEV(y) + font->ascent, text );
484};
485
486bool wxPaintDC::CanGetTextExtent(void) const
487{
488 return TRUE;
489};
490
491void wxPaintDC::GetTextExtent( const wxString &string, long *width, long *height,
492 long *WXUNUSED(descent), long *WXUNUSED(externalLeading),
493 wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) )
494{
495 if (!Ok()) return;
496
497 GdkFont *font = m_font.GetInternalFont( m_scaleY );
6f65e337
JS
498 if (width) (*width) = long(gdk_string_width( font, string ) / m_scaleX);
499 if (height) (*height) = long((font->ascent + font->descent) / m_scaleY);
c801d85f
KB
500};
501
502long wxPaintDC::GetCharWidth(void)
503{
504 if (!Ok()) return 0;
505
506 GdkFont *font = m_font.GetInternalFont( m_scaleY );
507 return gdk_string_width( font, "H" );
508};
509
510long wxPaintDC::GetCharHeight(void)
511{
512 if (!Ok()) return 0;
513
514 GdkFont *font = m_font.GetInternalFont( m_scaleY );
515 return font->ascent + font->descent;
516};
517
518void wxPaintDC::Clear(void)
519{
520 if (!Ok()) return;
521
522 DestroyClippingRegion();
0180d5da
RR
523
524 if (m_isDrawable)
525 {
526 gdk_window_clear( m_window );
527 }
528 else
529 {
530 int width = 0;
531 int height = 0;
532 GetSize( &width, &height );
533 gdk_draw_rectangle( m_window, m_brushGC, TRUE, 0, 0, width, height );
534 };
c801d85f
KB
535};
536
537void wxPaintDC::SetFont( const wxFont &font )
538{
539 if (!Ok()) return;
540
541 m_font = font;
542};
543
544void wxPaintDC::SetPen( const wxPen &pen )
545{
546 if (!Ok()) return;
547
548 if (m_pen == pen) return;
549
550 m_pen = pen;
551
552 if (!m_pen.Ok()) return;
553
554 gint width = m_pen.GetWidth();
6f65e337
JS
555 // CMB: if width is non-zero scale it with the dc
556 if (width <= 0)
557 {
558 width = 1;
559 }
560 else
561 {
562 // X doesn't allow different width in x and y and so we take
563 // the average
564 double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0;
565 width = (int)w;
566 }
c801d85f
KB
567
568 GdkLineStyle lineStyle = GDK_LINE_SOLID;
569 switch (m_pen.GetStyle())
570 {
571 case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; };
572 case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
573 case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
574 case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
575 case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; };
576 };
577
578 GdkCapStyle capStyle = GDK_CAP_ROUND;
579 switch (m_pen.GetCap())
580 {
6f65e337 581 case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; };
c801d85f
KB
582 case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; };
583 case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; };
584 };
585
586 GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
587 switch (m_pen.GetJoin())
588 {
589 case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; };
590 case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; };
591 case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; };
592 };
593
594 gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
595
596 m_pen.GetColour().CalcPixel( m_cmap );
597 gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
598};
599
600void wxPaintDC::SetBrush( const wxBrush &brush )
601{
602 if (!Ok()) return;
603
604 if (m_brush == brush) return;
605
606 m_brush = brush;
607
608 if (!m_brush.Ok()) return;
609
610 m_brush.GetColour().CalcPixel( m_cmap );
611 gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
612
613 GdkFill fillStyle = GDK_SOLID;
614 switch (m_brush.GetStyle())
615 {
616 case wxSOLID:
617 case wxTRANSPARENT:
618 break;
619 default:
620 fillStyle = GDK_STIPPLED;
621 };
622
623 gdk_gc_set_fill( m_brushGC, fillStyle );
624
625 if (m_brush.GetStyle() == wxSTIPPLE)
626 {
627 gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
628 };
629
630 if (IS_HATCH(m_brush.GetStyle()))
631 {
632 int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
633 gdk_gc_set_stipple( m_brushGC, hatches[num] );
634 };
635};
636
637void wxPaintDC::SetLogicalFunction( int function )
638{
639 if (m_logicalFunction == function) return;
640 GdkFunction mode = GDK_COPY;
641 switch (function)
642 {
643 case wxXOR: mode = GDK_INVERT; break;
644 case wxINVERT: mode = GDK_INVERT; break;
645 default: break;
646 };
647 m_logicalFunction = function;
648 gdk_gc_set_function( m_penGC, mode );
649 gdk_gc_set_function( m_brushGC, mode );
650};
651
652void wxPaintDC::SetTextForeground( const wxColour &col )
653{
654 if (!Ok()) return;
655
656 if (m_textForegroundColour == col) return;
657
658 m_textForegroundColour = col;
659 if (!m_textForegroundColour.Ok()) return;
660
661 m_textForegroundColour.CalcPixel( m_cmap );
662 gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
663};
664
665void wxPaintDC::SetTextBackground( const wxColour &col )
666{
667 if (!Ok()) return;
668
669 if (m_textBackgroundColour == col) return;
670
671 m_textBackgroundColour = col;
672 if (!m_textBackgroundColour.Ok()) return;
673
674 m_textBackgroundColour.CalcPixel( m_cmap );
675 gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
676};
677
6f65e337 678void wxPaintDC::SetBackgroundMode( int mode )
c801d85f 679{
6f65e337 680 m_backgroundMode = mode;
c801d85f
KB
681};
682
683void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) )
684{
685};
686
687void wxPaintDC::SetClippingRegion( long x, long y, long width, long height )
688{
689 wxDC::SetClippingRegion( x, y, width, height );
690
691 GdkRectangle rect;
692 rect.x = XLOG2DEV(x);
693 rect.y = YLOG2DEV(y);
694 rect.width = XLOG2DEV(x+width);
695 rect.height = YLOG2DEV(y+height);
696 gdk_gc_set_clip_rectangle( m_penGC, &rect );
697 gdk_gc_set_clip_rectangle( m_brushGC, &rect );
698 gdk_gc_set_clip_rectangle( m_textGC, &rect );
699 gdk_gc_set_clip_rectangle( m_bgGC, &rect );
700
701};
702
703void wxPaintDC::DestroyClippingRegion(void)
704{
705 wxDC::DestroyClippingRegion();
706
707 gdk_gc_set_clip_rectangle( m_penGC, NULL );
708 gdk_gc_set_clip_rectangle( m_brushGC, NULL );
709 gdk_gc_set_clip_rectangle( m_textGC, NULL );
710 gdk_gc_set_clip_rectangle( m_bgGC, NULL );
711};
712
713void wxPaintDC::SetUpDC(void)
714{
715 m_ok = TRUE;
716 m_logicalFunction = wxCOPY;
717 m_penGC = gdk_gc_new( m_window );
718 m_brushGC = gdk_gc_new( m_window );
719 m_textGC = gdk_gc_new( m_window );
720 m_bgGC = gdk_gc_new( m_window );
721 SetTextForeground( m_textForegroundColour );
722 SetTextBackground( m_textBackgroundColour );
723 SetPen( m_pen );
724 SetFont( m_font );
725 SetBrush( m_brush );
726
727 gdk_gc_set_background( m_penGC, wxWHITE->GetColor() );
728
729 if (!hatch_bitmap)
730 {
731 hatch_bitmap = hatches;
732 hatch_bitmap[0] = gdk_bitmap_create_from_data( NULL, bdiag_bits, bdiag_width, bdiag_height );
733 hatch_bitmap[1] = gdk_bitmap_create_from_data( NULL, cdiag_bits, cdiag_width, cdiag_height );
734 hatch_bitmap[2] = gdk_bitmap_create_from_data( NULL, fdiag_bits, fdiag_width, fdiag_height );
735 hatch_bitmap[3] = gdk_bitmap_create_from_data( NULL, cross_bits, cross_width, cross_height );
736 hatch_bitmap[4] = gdk_bitmap_create_from_data( NULL, horiz_bits, horiz_width, horiz_height );
737 hatch_bitmap[5] = gdk_bitmap_create_from_data( NULL, verti_bits, verti_width, verti_height );
738 };
739};
740
741GdkWindow *wxPaintDC::GetWindow(void)
742{
743 return m_window;
744};
745
746// ----------------------------------- spline code ----------------------------------------
747
748void wx_quadratic_spline(double a1, double b1, double a2, double b2,
749 double a3, double b3, double a4, double b4);
750void wx_clear_stack(void);
751int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
752 double *y3, double *x4, double *y4);
753void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
754 double x4, double y4);
755static bool wx_spline_add_point(double x, double y);
756static void wx_spline_draw_point_array(wxDC *dc);
757
758wxList wx_spline_point_list;
759
760#define half(z1, z2) ((z1+z2)/2.0)
761#define THRESHOLD 5
762
763/* iterative version */
764
765void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
766 double b4)
767{
768 register double xmid, ymid;
769 double x1, y1, x2, y2, x3, y3, x4, y4;
770
771 wx_clear_stack();
772 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
773
774 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
775 xmid = (double)half(x2, x3);
776 ymid = (double)half(y2, y3);
777 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
778 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
779 wx_spline_add_point( x1, y1 );
780 wx_spline_add_point( xmid, ymid );
781 } else {
782 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
783 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
784 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
785 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
786 }
787 }
788}
789
790/* utilities used by spline drawing routines */
791
792typedef struct wx_spline_stack_struct {
793 double x1, y1, x2, y2, x3, y3, x4, y4;
794} Stack;
795
796#define SPLINE_STACK_DEPTH 20
797static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
798static Stack *wx_stack_top;
799static int wx_stack_count;
800
801void wx_clear_stack(void)
802{
803 wx_stack_top = wx_spline_stack;
804 wx_stack_count = 0;
805}
806
807void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
808{
809 wx_stack_top->x1 = x1;
810 wx_stack_top->y1 = y1;
811 wx_stack_top->x2 = x2;
812 wx_stack_top->y2 = y2;
813 wx_stack_top->x3 = x3;
814 wx_stack_top->y3 = y3;
815 wx_stack_top->x4 = x4;
816 wx_stack_top->y4 = y4;
817 wx_stack_top++;
818 wx_stack_count++;
819}
820
821int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
822 double *x3, double *y3, double *x4, double *y4)
823{
824 if (wx_stack_count == 0)
825 return (0);
826 wx_stack_top--;
827 wx_stack_count--;
828 *x1 = wx_stack_top->x1;
829 *y1 = wx_stack_top->y1;
830 *x2 = wx_stack_top->x2;
831 *y2 = wx_stack_top->y2;
832 *x3 = wx_stack_top->x3;
833 *y3 = wx_stack_top->y3;
834 *x4 = wx_stack_top->x4;
835 *y4 = wx_stack_top->y4;
836 return (1);
837}
838
839static bool wx_spline_add_point(double x, double y)
840{
841 wxPoint *point = new wxPoint ;
842 point->x = (int) x;
843 point->y = (int) y;
844 wx_spline_point_list.Append((wxObject*)point);
845 return TRUE;
846}
847
848static void wx_spline_draw_point_array(wxDC *dc)
849{
850 dc->DrawLines(&wx_spline_point_list, 0, 0 );
851 wxNode *node = wx_spline_point_list.First();
852 while (node)
853 {
854 wxPoint *point = (wxPoint *)node->Data();
855 delete point;
856 delete node;
857 node = wx_spline_point_list.First();
858 }
859}
860
861void wxPaintDC::DrawOpenSpline( wxList *points )
862{
863 wxPoint *p;
864 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
865 double x1, y1, x2, y2;
866
867 wxNode *node = points->First();
868 p = (wxPoint *)node->Data();
869
870 x1 = p->x;
871 y1 = p->y;
872
873 node = node->Next();
874 p = (wxPoint *)node->Data();
875
876 x2 = p->x;
877 y2 = p->y;
878 cx1 = (double)((x1 + x2) / 2);
879 cy1 = (double)((y1 + y2) / 2);
880 cx2 = (double)((cx1 + x2) / 2);
881 cy2 = (double)((cy1 + y2) / 2);
882
883 wx_spline_add_point(x1, y1);
884
885 while ((node = node->Next()) != NULL)
886 {
887 p = (wxPoint *)node->Data();
888 x1 = x2;
889 y1 = y2;
890 x2 = p->x;
891 y2 = p->y;
892 cx4 = (double)(x1 + x2) / 2;
893 cy4 = (double)(y1 + y2) / 2;
894 cx3 = (double)(x1 + cx4) / 2;
895 cy3 = (double)(y1 + cy4) / 2;
896
897 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
898
899 cx1 = cx4;
900 cy1 = cy4;
901 cx2 = (double)(cx1 + x2) / 2;
902 cy2 = (double)(cy1 + y2) / 2;
903 }
904
905 wx_spline_add_point( cx1, cy1 );
906 wx_spline_add_point( x2, y2 );
907
908 wx_spline_draw_point_array( this );
909};