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