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