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