]> git.saurik.com Git - wxWidgets.git/blame - src/stubs/dcclient.cpp
corrected conditional compilation for Universal Interfaces (3.4 or later)
[wxWidgets.git] / src / stubs / dcclient.cpp
CommitLineData
93cf77c0
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcclient.cpp
3// Purpose: wxClientDC class
4// Author: AUTHOR
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dcclient.h"
14#endif
15
16#include "wx/dcclient.h"
17#include "wx/dcmemory.h"
c0ed460c 18#include "wx/region.h"
93cf77c0
JS
19#include <math.h>
20
21//-----------------------------------------------------------------------------
22// constants
23//-----------------------------------------------------------------------------
24
25#define RAD2DEG 57.2957795131
26
27//-----------------------------------------------------------------------------
28// wxPaintDC
29//-----------------------------------------------------------------------------
30
e6460682
JS
31IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
32IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
33IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
93cf77c0 34
e6460682
JS
35/*
36 * wxWindowDC
37 */
93cf77c0 38
e6460682 39wxWindowDC::wxWindowDC(void)
93cf77c0
JS
40{
41};
42
e6460682 43wxWindowDC::wxWindowDC( wxWindow *window )
93cf77c0
JS
44{
45};
46
e6460682 47wxWindowDC::~wxWindowDC(void)
93cf77c0
JS
48{
49};
50
e6460682 51void wxWindowDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1),
a367b9b3 52 const wxColour& WXUNUSED(col), int WXUNUSED(style) )
93cf77c0
JS
53{
54};
55
e6460682 56bool wxWindowDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
93cf77c0
JS
57{
58 return FALSE;
59};
60
e6460682 61void wxWindowDC::DrawLine( long x1, long y1, long x2, long y2 )
93cf77c0
JS
62{
63 if (!Ok()) return;
64
65};
66
e6460682 67void wxWindowDC::CrossHair( long x, long y )
93cf77c0
JS
68{
69 if (!Ok()) return;
70
71};
72
e6460682 73void wxWindowDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc )
93cf77c0
JS
74{
75 if (!Ok()) return;
76
77 long xx1 = XLOG2DEV(x1);
78 long yy1 = YLOG2DEV(y1);
79 long xx2 = XLOG2DEV(x2);
80 long yy2 = YLOG2DEV(y2);
81 long xxc = XLOG2DEV((long)xc);
82 long yyc = YLOG2DEV((long)yc);
83 double dx = xx1 - xxc;
84 double dy = yy1 - yyc;
85 double radius = sqrt(dx*dx+dy*dy);
86 long r = (long)radius;
87 double radius1, radius2;
88
89 if (xx1 == xx2 && yy1 == yy2)
90 {
91 radius1 = 0.0;
92 radius2 = 360.0;
93 }
94 else
95 if (radius == 0.0)
96 {
97 radius1 = radius2 = 0.0;
98 }
99 else
100 {
101 radius1 = (xx1 - xxc == 0) ?
102 (yy1 - yyc < 0) ? 90.0 : -90.0 :
103 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
104 radius2 = (xx2 - xxc == 0) ?
105 (yy2 - yyc < 0) ? 90.0 : -90.0 :
106 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
107 };
108 long alpha1 = long(radius1 * 64.0);
109 long alpha2 = long((radius2 - radius1) * 64.0);
110 while (alpha2 <= 0) alpha2 += 360*64;
111 while (alpha1 > 360*64) alpha1 -= 360*64;
112
113 if (m_brush.GetStyle() != wxTRANSPARENT) {};
114
115 if (m_pen.GetStyle() != wxTRANSPARENT) {};
116
117};
118
e6460682 119void wxWindowDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
93cf77c0
JS
120{
121 if (!Ok()) return;
122
123 long xx = XLOG2DEV(x);
124 long yy = YLOG2DEV(y);
125 long ww = m_signX * XLOG2DEVREL(width);
126 long hh = m_signY * YLOG2DEVREL(height);
127
128 // CMB: handle -ve width and/or height
129 if (ww < 0) { ww = -ww; xx = xx - ww; }
130 if (hh < 0) { hh = -hh; yy = yy - hh; }
131
132 long start = long(sa * 64.0);
133 long end = long(ea * 64.0);
134 if (m_brush.GetStyle() != wxTRANSPARENT) {};
135
136 if (m_pen.GetStyle() != wxTRANSPARENT) {};
137};
138
e6460682 139void wxWindowDC::DrawPoint( long x, long y )
93cf77c0
JS
140{
141 if (!Ok()) return;
142
143 if (m_pen.GetStyle() != wxTRANSPARENT) {};
144};
145
e6460682 146void wxWindowDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
93cf77c0
JS
147{
148 if (!Ok()) return;
149
150 if (m_pen.GetStyle() == wxTRANSPARENT) return;
151
152 for (int i = 0; i < n-1; i++)
153 {
154 long x1 = XLOG2DEV(points[i].x + xoffset);
155 long x2 = XLOG2DEV(points[i+1].x + xoffset);
156 long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
157 long y2 = YLOG2DEV(points[i+1].y + yoffset);
158 };
159};
160
e6460682 161void wxWindowDC::DrawLines( wxList *points, long xoffset, long yoffset )
93cf77c0
JS
162{
163 if (!Ok()) return;
164
165 if (m_pen.GetStyle() == wxTRANSPARENT) return;
166
167 wxNode *node = points->First();
168 while (node->Next())
169 {
170 wxPoint *point = (wxPoint*)node->Data();
171 wxPoint *npoint = (wxPoint*)node->Next()->Data();
172 long x1 = XLOG2DEV(point->x + xoffset);
173 long x2 = XLOG2DEV(npoint->x + xoffset);
174 long y1 = YLOG2DEV(point->y + yoffset); // and again...
175 long y2 = YLOG2DEV(npoint->y + yoffset);
176 node = node->Next();
177 };
178};
179
e6460682 180void wxWindowDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[],
93cf77c0
JS
181 long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
182{
183 if (!Ok()) return;
184};
185
e6460682 186void wxWindowDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset),
93cf77c0
JS
187 long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
188{
189 if (!Ok()) return;
190};
191
e6460682 192void wxWindowDC::DrawRectangle( long x, long y, long width, long height )
93cf77c0
JS
193{
194 if (!Ok()) return;
195
196 long xx = XLOG2DEV(x);
197 long yy = YLOG2DEV(y);
198 long ww = m_signX * XLOG2DEVREL(width);
199 long hh = m_signY * YLOG2DEVREL(height);
200
201 // CMB: draw nothing if transformed w or h is 0
202 if (ww == 0 || hh == 0) return;
203
204 // CMB: handle -ve width and/or height
205 if (ww < 0) { ww = -ww; xx = xx - ww; }
206 if (hh < 0) { hh = -hh; yy = yy - hh; }
207
208 if (m_brush.GetStyle() != wxTRANSPARENT) {};
209
210 if (m_pen.GetStyle() != wxTRANSPARENT) {};
211};
212
e6460682 213void wxWindowDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
93cf77c0
JS
214{
215 if (!Ok()) return;
216
217 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
218
219 long xx = XLOG2DEV(x);
220 long yy = YLOG2DEV(y);
221 long ww = m_signX * XLOG2DEVREL(width);
222 long hh = m_signY * YLOG2DEVREL(height);
223 long rr = XLOG2DEVREL((long)radius);
224
225 // CMB: handle -ve width and/or height
226 if (ww < 0) { ww = -ww; xx = xx - ww; }
227 if (hh < 0) { hh = -hh; yy = yy - hh; }
228
229 // CMB: if radius is zero use DrawRectangle() instead to avoid
230 // X drawing errors with small radii
231 if (rr == 0)
232 {
233 DrawRectangle( x, y, width, height );
234 return;
235 }
236
237 // CMB: draw nothing if transformed w or h is 0
238 if (ww == 0 || hh == 0) return;
239
240 // CMB: adjust size if outline is drawn otherwise the result is
241 // 1 pixel too wide and high
242 if (m_pen.GetStyle() != wxTRANSPARENT)
243 {
244 ww--;
245 hh--;
246 }
247
248 // CMB: ensure dd is not larger than rectangle otherwise we
249 // get an hour glass shape
250 long dd = 2 * rr;
251 if (dd > ww) dd = ww;
252 if (dd > hh) dd = hh;
253 rr = dd / 2;
254
255 if (m_brush.GetStyle() != wxTRANSPARENT)
256 {
257 };
258
259 if (m_pen.GetStyle() != wxTRANSPARENT)
260 {
261 };
262};
263
e6460682 264void wxWindowDC::DrawEllipse( long x, long y, long width, long height )
93cf77c0
JS
265{
266 if (!Ok()) return;
267
268 long xx = XLOG2DEV(x);
269 long yy = YLOG2DEV(y);
270 long ww = m_signX * XLOG2DEVREL(width);
271 long hh = m_signY * YLOG2DEVREL(height);
272
273 // CMB: handle -ve width and/or height
274 if (ww < 0) { ww = -ww; xx = xx - ww; }
275 if (hh < 0) { hh = -hh; yy = yy - hh; }
276
277 if (m_brush.GetStyle() != wxTRANSPARENT) {};
278
279 if (m_pen.GetStyle() != wxTRANSPARENT) {};
280};
281
e6460682 282bool wxWindowDC::CanDrawBitmap(void) const
93cf77c0
JS
283{
284 return TRUE;
285};
286
e6460682 287void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
93cf77c0
JS
288{
289 if (!Ok()) return;
290
291 if (!icon.Ok()) return;
292
293 int xx = XLOG2DEV(x);
294 int yy = YLOG2DEV(y);
295
296};
297
e6460682 298bool wxWindowDC::Blit( long xdest, long ydest, long width, long height,
93cf77c0
JS
299 wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) )
300{
301 if (!Ok()) return FALSE;
302
303 // CMB 20/5/98: add blitting of bitmaps
304 if (source->IsKindOf(CLASSINFO(wxMemoryDC)))
305 {
306 wxMemoryDC* srcDC = (wxMemoryDC*)source;
307 /*
308 GdkBitmap* bmap = srcDC->m_selected.GetBitmap();
309 if (bmap)
310 {
311 gdk_draw_bitmap (
312 m_window,
313 m_textGC,
314 bmap,
315 source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc),
316 XLOG2DEV(xdest), YLOG2DEV(ydest),
317 source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height)
318 );
319 return TRUE;
320 }
321 */
322 }
323
324 return TRUE;
325};
326
e6460682 327void wxWindowDC::DrawText( const wxString &text, long x, long y, bool
93cf77c0
JS
328WXUNUSED(use16) )
329{
330 if (!Ok()) return;
331
332};
333
334
335
e6460682 336bool wxWindowDC::CanGetTextExtent(void) const
93cf77c0
JS
337{
338 return TRUE;
339};
340
e6460682 341void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height,
93cf77c0
JS
342 long *WXUNUSED(descent), long *WXUNUSED(externalLeading),
343 wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) )
344{
345 if (!Ok()) return;
346
347};
348
e6460682 349long wxWindowDC::GetCharWidth(void)
93cf77c0
JS
350{
351 if (!Ok()) return 0;
34138703 352 return 0;
93cf77c0
JS
353};
354
e6460682 355long wxWindowDC::GetCharHeight(void)
93cf77c0
JS
356{
357 if (!Ok()) return 0;
34138703 358 return 0;
93cf77c0
JS
359};
360
e6460682 361void wxWindowDC::Clear(void)
93cf77c0
JS
362{
363 if (!Ok()) return;
364
365};
366
e6460682 367void wxWindowDC::SetFont( const wxFont &font )
93cf77c0
JS
368{
369 if (!Ok()) return;
370
371 m_font = font;
372};
373
e6460682 374void wxWindowDC::SetPen( const wxPen &pen )
93cf77c0
JS
375{
376 if (!Ok()) return;
377
378 if (m_pen == pen) return;
379
380 m_pen = pen;
381
382 if (!m_pen.Ok()) return;
383};
384
e6460682 385void wxWindowDC::SetBrush( const wxBrush &brush )
93cf77c0
JS
386{
387 if (!Ok()) return;
388
389 if (m_brush == brush) return;
390
391 m_brush = brush;
392
393 if (!m_brush.Ok()) return;
394
395};
396
e6460682 397void wxWindowDC::SetBackground( const wxBrush &brush )
93cf77c0
JS
398{
399 if (!Ok()) return;
400
401 if (m_backgroundBrush == brush) return;
402
403 m_backgroundBrush = brush;
404
405 if (!m_backgroundBrush.Ok()) return;
406
407};
408
e6460682 409void wxWindowDC::SetLogicalFunction( int function )
93cf77c0
JS
410{
411 if (m_logicalFunction == function) return;
412};
413
e6460682 414void wxWindowDC::SetTextForeground( const wxColour &col )
93cf77c0
JS
415{
416 if (!Ok()) return;
417
418 if (m_textForegroundColour == col) return;
419
420 m_textForegroundColour = col;
421 if (!m_textForegroundColour.Ok()) return;
422};
423
e6460682 424void wxWindowDC::SetTextBackground( const wxColour &col )
93cf77c0
JS
425{
426 if (!Ok()) return;
427
428 if (m_textBackgroundColour == col) return;
429
430 m_textBackgroundColour = col;
431 if (!m_textBackgroundColour.Ok()) return;
432};
433
e6460682 434void wxWindowDC::SetBackgroundMode( int mode )
93cf77c0
JS
435{
436 m_backgroundMode = mode;
437
438 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
439 {
440 }
441};
442
e6460682 443void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
93cf77c0
JS
444{
445};
446
e6460682 447void wxWindowDC::SetClippingRegion( long x, long y, long width, long height )
93cf77c0
JS
448{
449 wxDC::SetClippingRegion( x, y, width, height );
a724d789
JS
450
451 // TODO
93cf77c0
JS
452
453};
454
a724d789
JS
455void wxWindowDC::SetClippingRegion( const wxRegion& region )
456{
457 wxRect box = region.GetBox();
458
459 wxDC::SetClippingRegion( box.x, box.y, box.width, box.height );
460
461 // TODO
462}
463
e6460682 464void wxWindowDC::DestroyClippingRegion(void)
93cf77c0
JS
465{
466 wxDC::DestroyClippingRegion();
467
468};
469
470// ----------------------------------- spline code ----------------------------------------
471
472void wx_quadratic_spline(double a1, double b1, double a2, double b2,
473 double a3, double b3, double a4, double b4);
474void wx_clear_stack(void);
475int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
476 double *y3, double *x4, double *y4);
477void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
478 double x4, double y4);
479static bool wx_spline_add_point(double x, double y);
480static void wx_spline_draw_point_array(wxDC *dc);
481
482wxList wx_spline_point_list;
483
484#define half(z1, z2) ((z1+z2)/2.0)
485#define THRESHOLD 5
486
487/* iterative version */
488
489void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
490 double b4)
491{
492 register double xmid, ymid;
493 double x1, y1, x2, y2, x3, y3, x4, y4;
494
495 wx_clear_stack();
496 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
497
498 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
499 xmid = (double)half(x2, x3);
500 ymid = (double)half(y2, y3);
501 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
502 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
503 wx_spline_add_point( x1, y1 );
504 wx_spline_add_point( xmid, ymid );
505 } else {
506 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
507 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
508 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
509 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
510 }
511 }
512}
513
514/* utilities used by spline drawing routines */
515
516typedef struct wx_spline_stack_struct {
517 double x1, y1, x2, y2, x3, y3, x4, y4;
518} Stack;
519
520#define SPLINE_STACK_DEPTH 20
521static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
522static Stack *wx_stack_top;
523static int wx_stack_count;
524
525void wx_clear_stack(void)
526{
527 wx_stack_top = wx_spline_stack;
528 wx_stack_count = 0;
529}
530
531void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
532{
533 wx_stack_top->x1 = x1;
534 wx_stack_top->y1 = y1;
535 wx_stack_top->x2 = x2;
536 wx_stack_top->y2 = y2;
537 wx_stack_top->x3 = x3;
538 wx_stack_top->y3 = y3;
539 wx_stack_top->x4 = x4;
540 wx_stack_top->y4 = y4;
541 wx_stack_top++;
542 wx_stack_count++;
543}
544
545int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
546 double *x3, double *y3, double *x4, double *y4)
547{
548 if (wx_stack_count == 0)
549 return (0);
550 wx_stack_top--;
551 wx_stack_count--;
552 *x1 = wx_stack_top->x1;
553 *y1 = wx_stack_top->y1;
554 *x2 = wx_stack_top->x2;
555 *y2 = wx_stack_top->y2;
556 *x3 = wx_stack_top->x3;
557 *y3 = wx_stack_top->y3;
558 *x4 = wx_stack_top->x4;
559 *y4 = wx_stack_top->y4;
560 return (1);
561}
562
563static bool wx_spline_add_point(double x, double y)
564{
565 wxPoint *point = new wxPoint ;
566 point->x = (int) x;
567 point->y = (int) y;
568 wx_spline_point_list.Append((wxObject*)point);
569 return TRUE;
570}
571
572static void wx_spline_draw_point_array(wxDC *dc)
573{
574 dc->DrawLines(&wx_spline_point_list, 0, 0 );
575 wxNode *node = wx_spline_point_list.First();
576 while (node)
577 {
578 wxPoint *point = (wxPoint *)node->Data();
579 delete point;
580 delete node;
581 node = wx_spline_point_list.First();
582 }
583}
584
e6460682 585void wxWindowDC::DrawSpline( wxList *points )
93cf77c0
JS
586{
587 wxPoint *p;
588 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
589 double x1, y1, x2, y2;
590
591 wxNode *node = points->First();
592 p = (wxPoint *)node->Data();
593
594 x1 = p->x;
595 y1 = p->y;
596
597 node = node->Next();
598 p = (wxPoint *)node->Data();
599
600 x2 = p->x;
601 y2 = p->y;
602 cx1 = (double)((x1 + x2) / 2);
603 cy1 = (double)((y1 + y2) / 2);
604 cx2 = (double)((cx1 + x2) / 2);
605 cy2 = (double)((cy1 + y2) / 2);
606
607 wx_spline_add_point(x1, y1);
608
609 while ((node = node->Next()) != NULL)
610 {
611 p = (wxPoint *)node->Data();
612 x1 = x2;
613 y1 = y2;
614 x2 = p->x;
615 y2 = p->y;
616 cx4 = (double)(x1 + x2) / 2;
617 cy4 = (double)(y1 + y2) / 2;
618 cx3 = (double)(x1 + cx4) / 2;
619 cy3 = (double)(y1 + cy4) / 2;
620
621 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
622
623 cx1 = cx4;
624 cy1 = cy4;
625 cx2 = (double)(cx1 + x2) / 2;
626 cy2 = (double)(cy1 + y2) / 2;
627 }
628
629 wx_spline_add_point( cx1, cy1 );
630 wx_spline_add_point( x2, y2 );
631
632 wx_spline_draw_point_array( this );
633};