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