implement * and / operators for wxPoint, not only wxSize.
[wxWidgets.git] / include / wx / gdicmn.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gdicmn.h
3 // Purpose: Common GDI classes, types and declarations
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GDICMNH__
13 #define _WX_GDICMNH__
14
15 // ---------------------------------------------------------------------------
16 // headers
17 // ---------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20 #include "wx/list.h"
21 #include "wx/string.h"
22 #include "wx/fontenc.h"
23 #include "wx/hashmap.h"
24 #include "wx/math.h"
25
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
29
30 class WXDLLIMPEXP_FWD_CORE wxBitmap;
31 class WXDLLIMPEXP_FWD_CORE wxBrush;
32 class WXDLLIMPEXP_FWD_CORE wxColour;
33 class WXDLLIMPEXP_FWD_CORE wxCursor;
34 class WXDLLIMPEXP_FWD_CORE wxFont;
35 class WXDLLIMPEXP_FWD_CORE wxIcon;
36 class WXDLLIMPEXP_FWD_CORE wxPalette;
37 class WXDLLIMPEXP_FWD_CORE wxPen;
38 class WXDLLIMPEXP_FWD_CORE wxRegion;
39 class WXDLLIMPEXP_FWD_BASE wxString;
40 class WXDLLIMPEXP_FWD_CORE wxIconBundle;
41 class WXDLLIMPEXP_FWD_CORE wxPoint;
42
43 // ---------------------------------------------------------------------------
44 // constants
45 // ---------------------------------------------------------------------------
46
47 // Bitmap flags
48 enum wxBitmapType
49 {
50 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
51 wxBITMAP_TYPE_BMP,
52 wxBITMAP_TYPE_BMP_RESOURCE,
53 wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
54 wxBITMAP_TYPE_ICO,
55 wxBITMAP_TYPE_ICO_RESOURCE,
56 wxBITMAP_TYPE_CUR,
57 wxBITMAP_TYPE_CUR_RESOURCE,
58 wxBITMAP_TYPE_XBM,
59 wxBITMAP_TYPE_XBM_DATA,
60 wxBITMAP_TYPE_XPM,
61 wxBITMAP_TYPE_XPM_DATA,
62 wxBITMAP_TYPE_TIF,
63 wxBITMAP_TYPE_TIF_RESOURCE,
64 wxBITMAP_TYPE_GIF,
65 wxBITMAP_TYPE_GIF_RESOURCE,
66 wxBITMAP_TYPE_PNG,
67 wxBITMAP_TYPE_PNG_RESOURCE,
68 wxBITMAP_TYPE_JPEG,
69 wxBITMAP_TYPE_JPEG_RESOURCE,
70 wxBITMAP_TYPE_PNM,
71 wxBITMAP_TYPE_PNM_RESOURCE,
72 wxBITMAP_TYPE_PCX,
73 wxBITMAP_TYPE_PCX_RESOURCE,
74 wxBITMAP_TYPE_PICT,
75 wxBITMAP_TYPE_PICT_RESOURCE,
76 wxBITMAP_TYPE_ICON,
77 wxBITMAP_TYPE_ICON_RESOURCE,
78 wxBITMAP_TYPE_ANI,
79 wxBITMAP_TYPE_IFF,
80 wxBITMAP_TYPE_TGA,
81 wxBITMAP_TYPE_MACCURSOR,
82 wxBITMAP_TYPE_MACCURSOR_RESOURCE,
83
84 wxBITMAP_TYPE_MAX,
85 wxBITMAP_TYPE_ANY = 50
86 };
87
88 // Polygon filling mode
89 enum wxPolygonFillMode
90 {
91 wxODDEVEN_RULE = 1,
92 wxWINDING_RULE
93 };
94
95 // Standard cursors
96 enum wxStockCursor
97 {
98 wxCURSOR_NONE, // should be 0
99 wxCURSOR_ARROW,
100 wxCURSOR_RIGHT_ARROW,
101 wxCURSOR_BULLSEYE,
102 wxCURSOR_CHAR,
103 wxCURSOR_CROSS,
104 wxCURSOR_HAND,
105 wxCURSOR_IBEAM,
106 wxCURSOR_LEFT_BUTTON,
107 wxCURSOR_MAGNIFIER,
108 wxCURSOR_MIDDLE_BUTTON,
109 wxCURSOR_NO_ENTRY,
110 wxCURSOR_PAINT_BRUSH,
111 wxCURSOR_PENCIL,
112 wxCURSOR_POINT_LEFT,
113 wxCURSOR_POINT_RIGHT,
114 wxCURSOR_QUESTION_ARROW,
115 wxCURSOR_RIGHT_BUTTON,
116 wxCURSOR_SIZENESW,
117 wxCURSOR_SIZENS,
118 wxCURSOR_SIZENWSE,
119 wxCURSOR_SIZEWE,
120 wxCURSOR_SIZING,
121 wxCURSOR_SPRAYCAN,
122 wxCURSOR_WAIT,
123 wxCURSOR_WATCH,
124 wxCURSOR_BLANK,
125 #ifdef __WXGTK__
126 wxCURSOR_DEFAULT, // standard X11 cursor
127 #endif
128 #ifdef __WXMAC__
129 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
130 #endif
131 #ifdef __X__
132 // Not yet implemented for Windows
133 wxCURSOR_CROSS_REVERSE,
134 wxCURSOR_DOUBLE_ARROW,
135 wxCURSOR_BASED_ARROW_UP,
136 wxCURSOR_BASED_ARROW_DOWN,
137 #endif // X11
138 wxCURSOR_ARROWWAIT,
139 #ifdef __WXMAC__
140 wxCURSOR_OPEN_HAND,
141 wxCURSOR_CLOSED_HAND,
142 #endif
143
144 wxCURSOR_MAX
145 };
146
147 #ifndef __WXGTK__
148 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
149 #endif
150
151 #ifndef __WXMAC__
152 // TODO CS supply openhand and closedhand cursors
153 #define wxCURSOR_OPEN_HAND wxCURSOR_HAND
154 #define wxCURSOR_CLOSED_HAND wxCURSOR_HAND
155 #endif
156
157 // ---------------------------------------------------------------------------
158 // macros
159 // ---------------------------------------------------------------------------
160
161 /* Useful macro for creating icons portably, for example:
162
163 wxIcon *icon = new wxICON(mondrian);
164
165 expands into:
166
167 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
168 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
169 */
170
171 #ifdef __WXMSW__
172 // Load from a resource
173 #define wxICON(X) wxIcon(wxT(#X))
174 #elif defined(__WXPM__)
175 // Load from a resource
176 #define wxICON(X) wxIcon(wxT(#X))
177 #elif defined(__WXMGL__)
178 // Initialize from an included XPM
179 #define wxICON(X) wxIcon( X##_xpm )
180 #elif defined(__WXDFB__)
181 // Initialize from an included XPM
182 #define wxICON(X) wxIcon( X##_xpm )
183 #elif defined(__WXGTK__)
184 // Initialize from an included XPM
185 #define wxICON(X) wxIcon( X##_xpm )
186 #elif defined(__WXMAC__)
187 // Initialize from an included XPM
188 #define wxICON(X) wxIcon( X##_xpm )
189 #elif defined(__WXMOTIF__)
190 // Initialize from an included XPM
191 #define wxICON(X) wxIcon( X##_xpm )
192 #elif defined(__WXX11__)
193 // Initialize from an included XPM
194 #define wxICON(X) wxIcon( X##_xpm )
195 #else
196 // This will usually mean something on any platform
197 #define wxICON(X) wxIcon(wxT(#X))
198 #endif // platform
199
200 /* Another macro: this one is for portable creation of bitmaps. We assume that
201 under Unix bitmaps live in XPMs and under Windows they're in ressources.
202 */
203
204 #if defined(__WXMSW__) || defined(__WXPM__)
205 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
206 #elif defined(__WXGTK__) || \
207 defined(__WXMOTIF__) || \
208 defined(__WXX11__) || \
209 defined(__WXMAC__) || \
210 defined(__WXMGL__) || \
211 defined(__WXDFB__) || \
212 defined(__WXCOCOA__)
213 // Initialize from an included XPM
214 #define wxBITMAP(name) wxBitmap(name##_xpm)
215 #else // other platforms
216 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
217 #endif // platform
218
219 // ===========================================================================
220 // classes
221 // ===========================================================================
222
223 // ---------------------------------------------------------------------------
224 // wxSize
225 // ---------------------------------------------------------------------------
226
227 class WXDLLIMPEXP_CORE wxSize
228 {
229 public:
230 // members are public for compatibility, don't use them directly.
231 int x, y;
232
233 // constructors
234 wxSize() : x(0), y(0) { }
235 wxSize(int xx, int yy) : x(xx), y(yy) { }
236
237 // no copy ctor or assignment operator - the defaults are ok
238
239 wxSize& operator+=(const wxSize& sz) { x += sz.x; y += sz.y; return *this; }
240 wxSize& operator-=(const wxSize& sz) { x -= sz.x; y -= sz.y; return *this; }
241 wxSize& operator/=(int i) { x /= i; y /= i; return *this; }
242 wxSize& operator*=(int i) { x *= i; y *= i; return *this; }
243 wxSize& operator/=(unsigned int i) { x /= i; y /= i; return *this; }
244 wxSize& operator*=(unsigned int i) { x *= i; y *= i; return *this; }
245 wxSize& operator/=(long i) { x /= i; y /= i; return *this; }
246 wxSize& operator*=(long i) { x *= i; y *= i; return *this; }
247 wxSize& operator/=(unsigned long i) { x /= i; y /= i; return *this; }
248 wxSize& operator*=(unsigned long i) { x *= i; y *= i; return *this; }
249 wxSize& operator/=(double i) { x = int(x/i); y = int(y/i); return *this; }
250 wxSize& operator*=(double i) { x = int(x*i); y = int(y*i); return *this; }
251
252 void IncTo(const wxSize& sz)
253 { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; }
254 void DecTo(const wxSize& sz)
255 { if ( sz.x < x ) x = sz.x; if ( sz.y < y ) y = sz.y; }
256
257 void IncBy(int dx, int dy) { x += dx; y += dy; }
258 void IncBy(const wxSize& sz) { IncBy(sz.x, sz.y); }
259 void IncBy(int d) { IncBy(d, d); }
260
261 void DecBy(int dx, int dy) { IncBy(-dx, -dy); }
262 void DecBy(const wxSize& sz) { DecBy(sz.x, sz.y); }
263 void DecBy(int d) { DecBy(d, d); }
264
265
266 wxSize& Scale(float xscale, float yscale)
267 { x = (int)(x*xscale); y = (int)(y*yscale); return *this; }
268
269 // accessors
270 void Set(int xx, int yy) { x = xx; y = yy; }
271 void SetWidth(int w) { x = w; }
272 void SetHeight(int h) { y = h; }
273
274 int GetWidth() const { return x; }
275 int GetHeight() const { return y; }
276
277 bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; }
278
279 // combine this size with the other one replacing the default (i.e. equal
280 // to wxDefaultCoord) components of this object with those of the other
281 void SetDefaults(const wxSize& size)
282 {
283 if ( x == wxDefaultCoord )
284 x = size.x;
285 if ( y == wxDefaultCoord )
286 y = size.y;
287 }
288
289 // compatibility
290 int GetX() const { return x; }
291 int GetY() const { return y; }
292 };
293
294 inline bool operator==(const wxSize& s1, const wxSize& s2)
295 {
296 return s1.x == s2.x && s1.y == s2.y;
297 }
298
299 inline bool operator!=(const wxSize& s1, const wxSize& s2)
300 {
301 return s1.x != s2.x || s1.y != s2.y;
302 }
303
304 inline wxSize operator+(const wxSize& s1, const wxSize& s2)
305 {
306 return wxSize(s1.x + s2.x, s1.y + s2.y);
307 }
308
309 inline wxSize operator-(const wxSize& s1, const wxSize& s2)
310 {
311 return wxSize(s1.x - s2.x, s1.y - s2.y);
312 }
313
314 inline wxSize operator/(const wxSize& s, int i)
315 {
316 return wxSize(s.x / i, s.y / i);
317 }
318
319 inline wxSize operator*(const wxSize& s, int i)
320 {
321 return wxSize(s.x * i, s.y * i);
322 }
323
324 inline wxSize operator*(int i, const wxSize& s)
325 {
326 return wxSize(s.x * i, s.y * i);
327 }
328
329 inline wxSize operator/(const wxSize& s, unsigned int i)
330 {
331 return wxSize(s.x / i, s.y / i);
332 }
333
334 inline wxSize operator*(const wxSize& s, unsigned int i)
335 {
336 return wxSize(s.x * i, s.y * i);
337 }
338
339 inline wxSize operator*(unsigned int i, const wxSize& s)
340 {
341 return wxSize(s.x * i, s.y * i);
342 }
343
344 inline wxSize operator/(const wxSize& s, long i)
345 {
346 return wxSize(s.x / i, s.y / i);
347 }
348
349 inline wxSize operator*(const wxSize& s, long i)
350 {
351 return wxSize(s.x * i, s.y * i);
352 }
353
354 inline wxSize operator*(long i, const wxSize& s)
355 {
356 return wxSize(s.x * i, s.y * i);
357 }
358
359 inline wxSize operator/(const wxSize& s, unsigned long i)
360 {
361 return wxSize(s.x / i, s.y / i);
362 }
363
364 inline wxSize operator*(const wxSize& s, unsigned long i)
365 {
366 return wxSize(s.x * i, s.y * i);
367 }
368
369 inline wxSize operator*(unsigned long i, const wxSize& s)
370 {
371 return wxSize(s.x * i, s.y * i);
372 }
373
374 inline wxSize operator*(const wxSize& s, double i)
375 {
376 return wxSize(int(s.x * i), int(s.y * i));
377 }
378
379 inline wxSize operator*(double i, const wxSize& s)
380 {
381 return wxSize(int(s.x * i), int(s.y * i));
382 }
383
384
385
386 // ---------------------------------------------------------------------------
387 // Point classes: with real or integer coordinates
388 // ---------------------------------------------------------------------------
389
390 class WXDLLIMPEXP_CORE wxRealPoint
391 {
392 public:
393 double x;
394 double y;
395
396 wxRealPoint() : x(0.0), y(0.0) { }
397 wxRealPoint(double xx, double yy) : x(xx), y(yy) { }
398 };
399
400
401 inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2)
402 {
403 return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y);
404 }
405
406
407 inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2)
408 {
409 return !(p1 == p2);
410 }
411
412
413 inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2)
414 {
415 return wxRealPoint(p1.x + p2.x, p1.y + p2.y);
416 }
417
418
419 inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2)
420 {
421 return wxRealPoint(p1.x - p2.x, p1.y - p2.y);
422 }
423
424
425 // ----------------------------------------------------------------------------
426 // wxPoint: 2D point with integer coordinates
427 // ----------------------------------------------------------------------------
428
429 class WXDLLIMPEXP_CORE wxPoint
430 {
431 public:
432 int x, y;
433
434 wxPoint() : x(0), y(0) { }
435 wxPoint(int xx, int yy) : x(xx), y(yy) { }
436
437 // no copy ctor or assignment operator - the defaults are ok
438
439 //assignment operators
440 wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
441 wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
442
443 wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; }
444 wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; }
445 };
446
447
448 // comparison
449 inline bool operator==(const wxPoint& p1, const wxPoint& p2)
450 {
451 return p1.x == p2.x && p1.y == p2.y;
452 }
453
454 inline bool operator!=(const wxPoint& p1, const wxPoint& p2)
455 {
456 return !(p1 == p2);
457 }
458
459
460 // arithmetic operations (component wise)
461 inline wxPoint operator+(const wxPoint& p1, const wxPoint& p2)
462 {
463 return wxPoint(p1.x + p2.x, p1.y + p2.y);
464 }
465
466 inline wxPoint operator-(const wxPoint& p1, const wxPoint& p2)
467 {
468 return wxPoint(p1.x - p2.x, p1.y - p2.y);
469 }
470
471 inline wxPoint operator+(const wxPoint& p, const wxSize& s)
472 {
473 return wxPoint(p.x + s.x, p.y + s.y);
474 }
475
476 inline wxPoint operator-(const wxPoint& p, const wxSize& s)
477 {
478 return wxPoint(p.x - s.x, p.y - s.y);
479 }
480
481 inline wxPoint operator+(const wxSize& s, const wxPoint& p)
482 {
483 return wxPoint(p.x + s.x, p.y + s.y);
484 }
485
486 inline wxPoint operator-(const wxSize& s, const wxPoint& p)
487 {
488 return wxPoint(s.x - p.x, s.y - p.y);
489 }
490
491 inline wxPoint operator-(const wxPoint& p)
492 {
493 return wxPoint(-p.x, -p.y);
494 }
495
496 inline wxPoint operator/(const wxPoint& s, int i)
497 {
498 return wxPoint(s.x / i, s.y / i);
499 }
500
501 inline wxPoint operator*(const wxPoint& s, int i)
502 {
503 return wxPoint(s.x * i, s.y * i);
504 }
505
506 inline wxPoint operator*(int i, const wxPoint& s)
507 {
508 return wxPoint(s.x * i, s.y * i);
509 }
510
511 inline wxPoint operator/(const wxPoint& s, unsigned int i)
512 {
513 return wxPoint(s.x / i, s.y / i);
514 }
515
516 inline wxPoint operator*(const wxPoint& s, unsigned int i)
517 {
518 return wxPoint(s.x * i, s.y * i);
519 }
520
521 inline wxPoint operator*(unsigned int i, const wxPoint& s)
522 {
523 return wxPoint(s.x * i, s.y * i);
524 }
525
526 inline wxPoint operator/(const wxPoint& s, long i)
527 {
528 return wxPoint(s.x / i, s.y / i);
529 }
530
531 inline wxPoint operator*(const wxPoint& s, long i)
532 {
533 return wxPoint(s.x * i, s.y * i);
534 }
535
536 inline wxPoint operator*(long i, const wxPoint& s)
537 {
538 return wxPoint(s.x * i, s.y * i);
539 }
540
541 inline wxPoint operator/(const wxPoint& s, unsigned long i)
542 {
543 return wxPoint(s.x / i, s.y / i);
544 }
545
546 inline wxPoint operator*(const wxPoint& s, unsigned long i)
547 {
548 return wxPoint(s.x * i, s.y * i);
549 }
550
551 inline wxPoint operator*(unsigned long i, const wxPoint& s)
552 {
553 return wxPoint(s.x * i, s.y * i);
554 }
555
556 inline wxPoint operator*(const wxPoint& s, double i)
557 {
558 return wxPoint(int(s.x * i), int(s.y * i));
559 }
560
561 inline wxPoint operator*(double i, const wxPoint& s)
562 {
563 return wxPoint(int(s.x * i), int(s.y * i));
564 }
565
566 WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE);
567
568 // ---------------------------------------------------------------------------
569 // wxRect
570 // ---------------------------------------------------------------------------
571
572 class WXDLLIMPEXP_CORE wxRect
573 {
574 public:
575 wxRect()
576 : x(0), y(0), width(0), height(0)
577 { }
578 wxRect(int xx, int yy, int ww, int hh)
579 : x(xx), y(yy), width(ww), height(hh)
580 { }
581 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
582 wxRect(const wxPoint& pt, const wxSize& size)
583 : x(pt.x), y(pt.y), width(size.x), height(size.y)
584 { }
585 wxRect(const wxSize& size)
586 : x(0), y(0), width(size.x), height(size.y)
587 { }
588
589 // default copy ctor and assignment operators ok
590
591 int GetX() const { return x; }
592 void SetX(int xx) { x = xx; }
593
594 int GetY() const { return y; }
595 void SetY(int yy) { y = yy; }
596
597 int GetWidth() const { return width; }
598 void SetWidth(int w) { width = w; }
599
600 int GetHeight() const { return height; }
601 void SetHeight(int h) { height = h; }
602
603 wxPoint GetPosition() const { return wxPoint(x, y); }
604 void SetPosition( const wxPoint &p ) { x = p.x; y = p.y; }
605
606 wxSize GetSize() const { return wxSize(width, height); }
607 void SetSize( const wxSize &s ) { width = s.GetWidth(); height = s.GetHeight(); }
608
609 bool IsEmpty() const { return (width <= 0) || (height <= 0); }
610
611 int GetLeft() const { return x; }
612 int GetTop() const { return y; }
613 int GetBottom() const { return y + height - 1; }
614 int GetRight() const { return x + width - 1; }
615
616 void SetLeft(int left) { x = left; }
617 void SetRight(int right) { width = right - x + 1; }
618 void SetTop(int top) { y = top; }
619 void SetBottom(int bottom) { height = bottom - y + 1; }
620
621 wxPoint GetTopLeft() const { return GetPosition(); }
622 wxPoint GetLeftTop() const { return GetTopLeft(); }
623 void SetTopLeft(const wxPoint &p) { SetPosition(p); }
624 void SetLeftTop(const wxPoint &p) { SetTopLeft(p); }
625
626 wxPoint GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
627 wxPoint GetRightBottom() const { return GetBottomRight(); }
628 void SetBottomRight(const wxPoint &p) { SetRight(p.x); SetBottom(p.y); }
629 void SetRightBottom(const wxPoint &p) { SetBottomRight(p); }
630
631 wxPoint GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
632 wxPoint GetRightTop() const { return GetTopRight(); }
633 void SetTopRight(const wxPoint &p) { SetRight(p.x); SetTop(p.y); }
634 void SetRightTop(const wxPoint &p) { SetTopLeft(p); }
635
636 wxPoint GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
637 wxPoint GetLeftBottom() const { return GetBottomLeft(); }
638 void SetBottomLeft(const wxPoint &p) { SetLeft(p.x); SetBottom(p.y); }
639 void SetLeftBottom(const wxPoint &p) { SetBottomLeft(p); }
640
641 // operations with rect
642 wxRect& Inflate(wxCoord dx, wxCoord dy);
643 wxRect& Inflate(const wxSize& d) { return Inflate(d.x, d.y); }
644 wxRect& Inflate(wxCoord d) { return Inflate(d, d); }
645 wxRect Inflate(wxCoord dx, wxCoord dy) const
646 {
647 wxRect r = *this;
648 r.Inflate(dx, dy);
649 return r;
650 }
651
652 wxRect& Deflate(wxCoord dx, wxCoord dy) { return Inflate(-dx, -dy); }
653 wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); }
654 wxRect& Deflate(wxCoord d) { return Inflate(-d); }
655 wxRect Deflate(wxCoord dx, wxCoord dy) const
656 {
657 wxRect r = *this;
658 r.Deflate(dx, dy);
659 return r;
660 }
661
662 void Offset(wxCoord dx, wxCoord dy) { x += dx; y += dy; }
663 void Offset(const wxPoint& pt) { Offset(pt.x, pt.y); }
664
665 wxRect& Intersect(const wxRect& rect);
666 wxRect Intersect(const wxRect& rect) const
667 {
668 wxRect r = *this;
669 r.Intersect(rect);
670 return r;
671 }
672
673 wxRect& Union(const wxRect& rect);
674 wxRect Union(const wxRect& rect) const
675 {
676 wxRect r = *this;
677 r.Union(rect);
678 return r;
679 }
680
681 // return true if the point is (not strcitly) inside the rect
682 bool Contains(int x, int y) const;
683 bool Contains(const wxPoint& pt) const { return Contains(pt.x, pt.y); }
684 // return true if the rectangle 'rect' is (not strictly) inside this rect
685 bool Contains(const wxRect& rect) const;
686
687 #if WXWIN_COMPATIBILITY_2_6
688 // use Contains() instead
689 wxDEPRECATED( bool Inside(int x, int y) const );
690 wxDEPRECATED( bool Inside(const wxPoint& pt) const );
691 wxDEPRECATED( bool Inside(const wxRect& rect) const );
692 #endif // WXWIN_COMPATIBILITY_2_6
693
694 // return true if the rectangles have a non empty intersection
695 bool Intersects(const wxRect& rect) const;
696
697 // like Union() but don't ignore empty rectangles
698 wxRect& operator+=(const wxRect& rect);
699
700 // intersections of two rectrangles not testing for empty rectangles
701 wxRect& operator*=(const wxRect& rect);
702
703 // centre this rectangle in the given (usually, but not necessarily,
704 // larger) one
705 wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const
706 {
707 return wxRect(dir & wxHORIZONTAL ? r.x + (r.width - width)/2 : x,
708 dir & wxVERTICAL ? r.y + (r.height - height)/2 : y,
709 width, height);
710 }
711
712 wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const
713 {
714 return CentreIn(r, dir);
715 }
716
717 public:
718 int x, y, width, height;
719 };
720
721
722 // compare rectangles
723 inline bool operator==(const wxRect& r1, const wxRect& r2)
724 {
725 return (r1.x == r2.x) && (r1.y == r2.y) &&
726 (r1.width == r2.width) && (r1.height == r2.height);
727 }
728
729 inline bool operator!=(const wxRect& r1, const wxRect& r2)
730 {
731 return !(r1 == r2);
732 }
733
734 // like Union() but don't treat empty rectangles specially
735 WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2);
736
737 // intersections of two rectangles
738 WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2);
739
740
741
742
743 #if WXWIN_COMPATIBILITY_2_6
744 inline bool wxRect::Inside(int cx, int cy) const { return Contains(cx, cy); }
745 inline bool wxRect::Inside(const wxPoint& pt) const { return Contains(pt); }
746 inline bool wxRect::Inside(const wxRect& rect) const { return Contains(rect); }
747 #endif // WXWIN_COMPATIBILITY_2_6
748
749
750 // ---------------------------------------------------------------------------
751 // Management of pens, brushes and fonts
752 // ---------------------------------------------------------------------------
753
754 typedef wxInt8 wxDash;
755
756 class WXDLLIMPEXP_CORE wxGDIObjListBase {
757 public:
758 wxGDIObjListBase();
759 ~wxGDIObjListBase();
760
761 protected:
762 wxList list;
763 };
764
765 WX_DECLARE_STRING_HASH_MAP(wxColour*, wxStringToColourHashMap);
766
767 class WXDLLIMPEXP_CORE wxColourDatabase
768 {
769 public:
770 wxColourDatabase();
771 ~wxColourDatabase();
772
773 // find colour by name or name for the given colour
774 wxColour Find(const wxString& name) const;
775 wxString FindName(const wxColour& colour) const;
776
777 // add a new colour to the database
778 void AddColour(const wxString& name, const wxColour& colour);
779
780 #if WXWIN_COMPATIBILITY_2_6
781 // deprecated, use Find() instead
782 wxDEPRECATED( wxColour *FindColour(const wxString& name) );
783 #endif // WXWIN_COMPATIBILITY_2_6
784
785
786 #ifdef __WXPM__
787 // PM keeps its own type of colour table
788 long* m_palTable;
789 size_t m_nSize;
790 #endif
791
792 private:
793 // load the database with the built in colour values when called for the
794 // first time, do nothing after this
795 void Initialize();
796
797 wxStringToColourHashMap *m_map;
798 };
799
800 class WXDLLIMPEXP_CORE wxResourceCache: public wxList
801 {
802 public:
803 wxResourceCache() { }
804 #if !wxUSE_STL
805 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
806 #endif
807 virtual ~wxResourceCache();
808 };
809
810 // ---------------------------------------------------------------------------
811 // global variables
812 // ---------------------------------------------------------------------------
813
814
815 /* Stock objects
816
817 wxStockGDI creates the stock GDI objects on demand. Pointers to the
818 created objects are stored in the ms_stockObject array, which is indexed
819 by the Item enum values. Platorm-specific fonts can be created by
820 implementing a derived class with an override for the GetFont function.
821 wxStockGDI operates as a singleton, accessed through the ms_instance
822 pointer. By default this pointer is set to an instance of wxStockGDI.
823 A derived class must arrange to set this pointer to an instance of itself.
824 */
825 class WXDLLIMPEXP_CORE wxStockGDI
826 {
827 public:
828 enum Item {
829 BRUSH_BLACK,
830 BRUSH_BLUE,
831 BRUSH_CYAN,
832 BRUSH_GREEN,
833 BRUSH_YELLOW,
834 BRUSH_GREY,
835 BRUSH_LIGHTGREY,
836 BRUSH_MEDIUMGREY,
837 BRUSH_RED,
838 BRUSH_TRANSPARENT,
839 BRUSH_WHITE,
840 COLOUR_BLACK,
841 COLOUR_BLUE,
842 COLOUR_CYAN,
843 COLOUR_GREEN,
844 COLOUR_YELLOW,
845 COLOUR_LIGHTGREY,
846 COLOUR_RED,
847 COLOUR_WHITE,
848 CURSOR_CROSS,
849 CURSOR_HOURGLASS,
850 CURSOR_STANDARD,
851 FONT_ITALIC,
852 FONT_NORMAL,
853 FONT_SMALL,
854 FONT_SWISS,
855 PEN_BLACK,
856 PEN_BLACKDASHED,
857 PEN_BLUE,
858 PEN_CYAN,
859 PEN_GREEN,
860 PEN_YELLOW,
861 PEN_GREY,
862 PEN_LIGHTGREY,
863 PEN_MEDIUMGREY,
864 PEN_RED,
865 PEN_TRANSPARENT,
866 PEN_WHITE,
867 ITEMCOUNT
868 };
869
870 wxStockGDI();
871 virtual ~wxStockGDI();
872 static void DeleteAll();
873
874 static wxStockGDI& instance() { return *ms_instance; }
875
876 static const wxBrush* GetBrush(Item item);
877 static const wxColour* GetColour(Item item);
878 static const wxCursor* GetCursor(Item item);
879 // Can be overridden by platform-specific derived classes
880 virtual const wxFont* GetFont(Item item);
881 static const wxPen* GetPen(Item item);
882
883 protected:
884 static wxStockGDI* ms_instance;
885
886 static wxObject* ms_stockObject[ITEMCOUNT];
887
888 wxDECLARE_NO_COPY_CLASS(wxStockGDI);
889 };
890
891 #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
892 #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
893 #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
894 #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
895
896 #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
897 #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
898 #define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE)
899 #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
900 #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
901 #define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW)
902 #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
903 #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
904 #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
905 #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
906 #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
907 #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
908
909 #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
910 #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
911 #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
912 #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
913 #define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW)
914 #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
915 #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
916 #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
917 #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
918 #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
919 #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
920
921 #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
922 #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
923 #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
924 #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
925 #define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW)
926 #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
927 #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
928 #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
929
930 #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
931 #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
932 #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
933
934 // 'Null' objects
935 extern WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap;
936 extern WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon;
937 extern WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor;
938 extern WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen;
939 extern WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush;
940 extern WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette;
941 extern WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont;
942 extern WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour;
943 extern WXDLLIMPEXP_DATA_CORE(wxIconBundle) wxNullIconBundle;
944
945 extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase;
946
947 extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr[];
948
949 extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize;
950 extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition;
951
952 // ---------------------------------------------------------------------------
953 // global functions
954 // ---------------------------------------------------------------------------
955
956 // resource management
957 extern void WXDLLIMPEXP_CORE wxInitializeStockLists();
958 extern void WXDLLIMPEXP_CORE wxDeleteStockLists();
959
960 // is the display colour (or monochrome)?
961 extern bool WXDLLIMPEXP_CORE wxColourDisplay();
962
963 // Returns depth of screen
964 extern int WXDLLIMPEXP_CORE wxDisplayDepth();
965 #define wxGetDisplayDepth wxDisplayDepth
966
967 // get the display size
968 extern void WXDLLIMPEXP_CORE wxDisplaySize(int *width, int *height);
969 extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize();
970 extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height);
971 extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM();
972 extern wxSize WXDLLIMPEXP_CORE wxGetDisplayPPI();
973
974 // Get position and size of the display workarea
975 extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height);
976 extern wxRect WXDLLIMPEXP_CORE wxGetClientDisplayRect();
977
978 // set global cursor
979 extern void WXDLLIMPEXP_CORE wxSetCursor(const wxCursor& cursor);
980
981 #endif
982 // _WX_GDICMNH__