]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcclient.cpp
Improve wxImage::LoadImage so that image format in not anymore required
[wxWidgets.git] / src / os2 / dcclient.cpp
CommitLineData
0e320a79
DW
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 "wx/region.h"
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
32IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
33IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
34IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
35#endif
36
37/*
38 * wxWindowDC
39 */
40
41wxWindowDC::wxWindowDC(void)
42{
43};
44
45wxWindowDC::wxWindowDC( wxWindow *window )
46{
47};
48
49wxWindowDC::~wxWindowDC(void)
50{
51};
52
1408104d 53void wxWindowDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1),
0e320a79
DW
54 const wxColour& WXUNUSED(col), int WXUNUSED(style) )
55{
56};
57
58bool wxWindowDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
59{
60 return FALSE;
61};
62
63void wxWindowDC::DrawLine( long x1, long y1, long x2, long y2 )
64{
65 if (!Ok()) return;
1408104d 66
0e320a79
DW
67};
68
69void wxWindowDC::CrossHair( long x, long y )
70{
71 if (!Ok()) return;
1408104d 72
0e320a79
DW
73};
74
75void wxWindowDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc )
76{
77 if (!Ok()) return;
1408104d
DW
78
79 long xx1 = XLOG2DEV(x1);
0e320a79 80 long yy1 = YLOG2DEV(y1);
1408104d 81 long xx2 = XLOG2DEV(x2);
0e320a79 82 long yy2 = YLOG2DEV(y2);
1408104d 83 long xxc = XLOG2DEV((long)xc);
0e320a79 84 long yyc = YLOG2DEV((long)yc);
1408104d 85 double dx = xx1 - xxc;
0e320a79
DW
86 double dy = yy1 - yyc;
87 double radius = sqrt(dx*dx+dy*dy);
88 long r = (long)radius;
89 double radius1, radius2;
90
1408104d 91 if (xx1 == xx2 && yy1 == yy2)
0e320a79
DW
92 {
93 radius1 = 0.0;
94 radius2 = 360.0;
1408104d
DW
95 }
96 else
97 if (radius == 0.0)
0e320a79
DW
98 {
99 radius1 = radius2 = 0.0;
1408104d
DW
100 }
101 else
0e320a79
DW
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) {};
1408104d 116
0e320a79 117 if (m_pen.GetStyle() != wxTRANSPARENT) {};
1408104d 118
0e320a79
DW
119};
120
121void wxWindowDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
122{
123 if (!Ok()) return;
1408104d
DW
124
125 long xx = XLOG2DEV(x);
0e320a79 126 long yy = YLOG2DEV(y);
1408104d 127 long ww = m_signX * XLOG2DEVREL(width);
0e320a79 128 long hh = m_signY * YLOG2DEVREL(height);
1408104d 129
0e320a79
DW
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; }
1408104d 133
0e320a79
DW
134 long start = long(sa * 64.0);
135 long end = long(ea * 64.0);
136 if (m_brush.GetStyle() != wxTRANSPARENT) {};
1408104d 137
0e320a79
DW
138 if (m_pen.GetStyle() != wxTRANSPARENT) {};
139};
140
141void wxWindowDC::DrawPoint( long x, long y )
142{
143 if (!Ok()) return;
1408104d 144
0e320a79
DW
145 if (m_pen.GetStyle() != wxTRANSPARENT) {};
146};
147
148void wxWindowDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
149{
150 if (!Ok()) return;
1408104d 151
0e320a79 152 if (m_pen.GetStyle() == wxTRANSPARENT) return;
1408104d 153
0e320a79
DW
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
163void wxWindowDC::DrawLines( wxList *points, long xoffset, long yoffset )
164{
165 if (!Ok()) return;
1408104d 166
0e320a79 167 if (m_pen.GetStyle() == wxTRANSPARENT) return;
1408104d 168
0e320a79
DW
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
1408104d 182void wxWindowDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[],
0e320a79
DW
183 long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
184{
185 if (!Ok()) return;
186};
187
1408104d 188void wxWindowDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset),
0e320a79
DW
189 long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
190{
191 if (!Ok()) return;
192};
193
194void wxWindowDC::DrawRectangle( long x, long y, long width, long height )
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);
1408104d 202
0e320a79
DW
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) {};
1408104d 211
0e320a79
DW
212 if (m_pen.GetStyle() != wxTRANSPARENT) {};
213};
214
215void wxWindowDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
216{
217 if (!Ok()) return;
1408104d 218
0e320a79 219 if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
1408104d
DW
220
221 long xx = XLOG2DEV(x);
0e320a79 222 long yy = YLOG2DEV(y);
1408104d 223 long ww = m_signX * XLOG2DEVREL(width);
0e320a79
DW
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 };
1408104d 260
0e320a79
DW
261 if (m_pen.GetStyle() != wxTRANSPARENT)
262 {
263 };
264};
265
266void wxWindowDC::DrawEllipse( long x, long y, long width, long height )
267{
268 if (!Ok()) return;
1408104d
DW
269
270 long xx = XLOG2DEV(x);
0e320a79 271 long yy = YLOG2DEV(y);
1408104d 272 long ww = m_signX * XLOG2DEVREL(width);
0e320a79
DW
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; }
1408104d 278
0e320a79 279 if (m_brush.GetStyle() != wxTRANSPARENT) {};
1408104d 280
0e320a79
DW
281 if (m_pen.GetStyle() != wxTRANSPARENT) {};
282};
283
284bool wxWindowDC::CanDrawBitmap(void) const
285{
286 return TRUE;
287};
288
289void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
290{
291 if (!Ok()) return;
1408104d 292
0e320a79 293 if (!icon.Ok()) return;
1408104d 294
0e320a79
DW
295 int xx = XLOG2DEV(x);
296 int yy = YLOG2DEV(y);
1408104d 297
0e320a79
DW
298};
299
300bool wxWindowDC::Blit( long xdest, long ydest, long width, long height,
301 wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) )
302{
303 if (!Ok()) return FALSE;
1408104d 304
0e320a79
DW
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
329void wxWindowDC::DrawText( const wxString &text, long x, long y, bool
330WXUNUSED(use16) )
331{
332 if (!Ok()) return;
333
334};
335
336
337
338bool wxWindowDC::CanGetTextExtent(void) const
339{
340 return TRUE;
341};
342
343void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height,
344 long *WXUNUSED(descent), long *WXUNUSED(externalLeading),
1408104d 345 wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) ) const
0e320a79
DW
346{
347 if (!Ok()) return;
1408104d 348
0e320a79
DW
349};
350
1408104d 351long wxWindowDC::GetCharWidth(void) const
0e320a79
DW
352{
353 if (!Ok()) return 0;
354 return 0;
355};
356
1408104d 357long wxWindowDC::GetCharHeight(void) const
0e320a79
DW
358{
359 if (!Ok()) return 0;
360 return 0;
361};
362
363void wxWindowDC::Clear(void)
364{
365 if (!Ok()) return;
1408104d 366
0e320a79
DW
367};
368
369void wxWindowDC::SetFont( const wxFont &font )
370{
371 if (!Ok()) return;
1408104d 372
0e320a79
DW
373 m_font = font;
374};
375
376void wxWindowDC::SetPen( const wxPen &pen )
377{
378 if (!Ok()) return;
379
380 if (m_pen == pen) return;
1408104d 381
0e320a79 382 m_pen = pen;
1408104d 383
0e320a79
DW
384 if (!m_pen.Ok()) return;
385};
386
387void wxWindowDC::SetBrush( const wxBrush &brush )
388{
389 if (!Ok()) return;
1408104d 390
0e320a79 391 if (m_brush == brush) return;
1408104d 392
0e320a79 393 m_brush = brush;
1408104d 394
0e320a79 395 if (!m_brush.Ok()) return;
1408104d 396
0e320a79
DW
397};
398
399void wxWindowDC::SetBackground( const wxBrush &brush )
400{
401 if (!Ok()) return;
1408104d 402
0e320a79 403 if (m_backgroundBrush == brush) return;
1408104d 404
0e320a79 405 m_backgroundBrush = brush;
1408104d 406
0e320a79 407 if (!m_backgroundBrush.Ok()) return;
1408104d 408
0e320a79
DW
409};
410
411void wxWindowDC::SetLogicalFunction( int function )
412{
413 if (m_logicalFunction == function) return;
414};
415
416void wxWindowDC::SetTextForeground( const wxColour &col )
417{
418 if (!Ok()) return;
1408104d 419
0e320a79 420 if (m_textForegroundColour == col) return;
1408104d 421
0e320a79
DW
422 m_textForegroundColour = col;
423 if (!m_textForegroundColour.Ok()) return;
424};
425
426void wxWindowDC::SetTextBackground( const wxColour &col )
427{
428 if (!Ok()) return;
1408104d 429
0e320a79 430 if (m_textBackgroundColour == col) return;
1408104d 431
0e320a79
DW
432 m_textBackgroundColour = col;
433 if (!m_textBackgroundColour.Ok()) return;
434};
435
436void wxWindowDC::SetBackgroundMode( int mode )
437{
438 m_backgroundMode = mode;
439
440 if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
441 {
442 }
443};
444
445void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
446{
447};
448
449void wxWindowDC::SetClippingRegion( long x, long y, long width, long height )
450{
451 wxDC::SetClippingRegion( x, y, width, height );
452
453 // TODO
1408104d 454
0e320a79
DW
455};
456
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
466void wxWindowDC::DestroyClippingRegion(void)
467{
468 wxDC::DestroyClippingRegion();
1408104d 469
0e320a79
DW
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
587void wxWindowDC::DrawSpline( wxList *points )
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};