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