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