]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gdicmn.h
use wxTextEntry in wxTextValidator (modified patch 1821743)
[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,
f03fc89f
VZ
83 wxBITMAP_TYPE_ANY = 50
84};
85
c801d85f 86// Standard cursors
f03fc89f
VZ
87enum wxStockCursor
88{
89 wxCURSOR_NONE, // should be 0
90 wxCURSOR_ARROW,
15dadf31 91 wxCURSOR_RIGHT_ARROW,
f03fc89f
VZ
92 wxCURSOR_BULLSEYE,
93 wxCURSOR_CHAR,
94 wxCURSOR_CROSS,
95 wxCURSOR_HAND,
96 wxCURSOR_IBEAM,
97 wxCURSOR_LEFT_BUTTON,
98 wxCURSOR_MAGNIFIER,
99 wxCURSOR_MIDDLE_BUTTON,
100 wxCURSOR_NO_ENTRY,
101 wxCURSOR_PAINT_BRUSH,
102 wxCURSOR_PENCIL,
103 wxCURSOR_POINT_LEFT,
104 wxCURSOR_POINT_RIGHT,
105 wxCURSOR_QUESTION_ARROW,
106 wxCURSOR_RIGHT_BUTTON,
107 wxCURSOR_SIZENESW,
108 wxCURSOR_SIZENS,
109 wxCURSOR_SIZENWSE,
110 wxCURSOR_SIZEWE,
111 wxCURSOR_SIZING,
112 wxCURSOR_SPRAYCAN,
113 wxCURSOR_WAIT,
114 wxCURSOR_WATCH,
115 wxCURSOR_BLANK,
ae53c98c
KB
116#ifdef __WXGTK__
117 wxCURSOR_DEFAULT, // standard X11 cursor
118#endif
5f7a6626 119#ifdef __WXMAC__
5d3e7b52 120 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
5f7a6626 121#endif
c801d85f 122#ifdef __X__
f03fc89f
VZ
123 // Not yet implemented for Windows
124 wxCURSOR_CROSS_REVERSE,
125 wxCURSOR_DOUBLE_ARROW,
126 wxCURSOR_BASED_ARROW_UP,
ea804aad 127 wxCURSOR_BASED_ARROW_DOWN,
f03fc89f
VZ
128#endif // X11
129
83f96286
RD
130 wxCURSOR_ARROWWAIT,
131
f03fc89f
VZ
132 wxCURSOR_MAX
133};
134
943d28e4
VZ
135#ifndef __WXGTK__
136 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
137#endif
138
f03fc89f
VZ
139// ---------------------------------------------------------------------------
140// macros
141// ---------------------------------------------------------------------------
142
143/* Useful macro for creating icons portably, for example:
144
145 wxIcon *icon = new wxICON(mondrian);
146
147 expands into:
148
149 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
150 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
151 */
152
153#ifdef __WXMSW__
154 // Load from a resource
2b5f62a0 155 #define wxICON(X) wxIcon(wxT(#X))
1777b9bb
DW
156#elif defined(__WXPM__)
157 // Load from a resource
2b5f62a0 158 #define wxICON(X) wxIcon(wxT(#X))
1e6feb95 159#elif defined(__WXMGL__)
1d965e2f
VS
160 // Initialize from an included XPM
161 #define wxICON(X) wxIcon( (const char**) X##_xpm )
d8bfd727
VS
162#elif defined(__WXDFB__)
163 // Initialize from an included XPM
164 #define wxICON(X) wxIcon( (const char**) X##_xpm )
f03fc89f
VZ
165#elif defined(__WXGTK__)
166 // Initialize from an included XPM
167 #define wxICON(X) wxIcon( (const char**) X##_xpm )
0532484d
GD
168#elif defined(__WXMAC__)
169 // Initialize from an included XPM
170 #define wxICON(X) wxIcon( (const char**) X##_xpm )
f03fc89f
VZ
171#elif defined(__WXMOTIF__)
172 // Initialize from an included XPM
173 #define wxICON(X) wxIcon( X##_xpm )
83df96d6
JS
174#elif defined(__WXX11__)
175 // Initialize from an included XPM
176 #define wxICON(X) wxIcon( X##_xpm )
f03fc89f
VZ
177#else
178 // This will usually mean something on any platform
2b5f62a0 179 #define wxICON(X) wxIcon(wxT(#X))
f03fc89f
VZ
180#endif // platform
181
0c5d3e1c
VZ
182/* Another macro: this one is for portable creation of bitmaps. We assume that
183 under Unix bitmaps live in XPMs and under Windows they're in ressources.
184 */
185
1d965e2f 186#if defined(__WXMSW__) || defined(__WXPM__)
2b5f62a0 187 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
d22004c4
WS
188#elif defined(__WXGTK__) || \
189 defined(__WXMOTIF__) || \
190 defined(__WXX11__) || \
191 defined(__WXMAC__) || \
192 defined(__WXMGL__) || \
d8bfd727 193 defined(__WXDFB__) || \
d22004c4 194 defined(__WXCOCOA__)
bab537dc
VS
195 // Initialize from an included XPM
196 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
b8aa1680 197#else // other platforms
0c5d3e1c
VZ
198 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
199#endif // platform
200
f03fc89f
VZ
201// ===========================================================================
202// classes
203// ===========================================================================
c801d85f 204
f03fc89f
VZ
205// ---------------------------------------------------------------------------
206// wxSize
207// ---------------------------------------------------------------------------
1e6feb95 208
6a6c0a8b 209class WXDLLEXPORT wxSize
c801d85f
KB
210{
211public:
e6c96a7c 212 // members are public for compatibility, don't use them directly.
72cdf4c9 213 int x, y;
f03fc89f
VZ
214
215 // constructors
7ee31b00
GD
216 wxSize() : x(0), y(0) { }
217 wxSize(int xx, int yy) : x(xx), y(yy) { }
f03fc89f
VZ
218
219 // no copy ctor or assignment operator - the defaults are ok
1e6feb95 220
fc84bd05
WS
221 wxSize& operator+=(const wxSize& sz) { x += sz.x; y += sz.y; return *this; }
222 wxSize& operator-=(const wxSize& sz) { x -= sz.x; y -= sz.y; return *this; }
bc5e942b
VZ
223 wxSize& operator/=(int i) { x /= i; y /= i; return *this; }
224 wxSize& operator*=(int i) { x *= i; y *= i; return *this; }
706f1421 225
5b087ae2
VZ
226 void IncTo(const wxSize& sz)
227 { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; }
228 void DecTo(const wxSize& sz)
229 { if ( sz.x < x ) x = sz.x; if ( sz.y < y ) y = sz.y; }
f03fc89f 230
23359747
VZ
231 void IncBy(int dx, int dy) { x += dx; y += dy; }
232 void IncBy(const wxSize& sz) { IncBy(sz.x, sz.y); }
233 void IncBy(int d) { IncBy(d, d); }
234
235 void DecBy(int dx, int dy) { IncBy(-dx, -dy); }
236 void DecBy(const wxSize& sz) { DecBy(sz.x, sz.y); }
237 void DecBy(int d) { DecBy(d, d); }
238
239
c5bad604
RR
240 wxSize& Scale(float xscale, float yscale)
241 { x = (int)(x*xscale); y = (int)(y*yscale); return *this; }
8efb2907 242
eddf46fe
JS
243 // accessors
244 void Set(int xx, int yy) { x = xx; y = yy; }
72cdf4c9
VZ
245 void SetWidth(int w) { x = w; }
246 void SetHeight(int h) { y = h; }
cc775580 247
72cdf4c9
VZ
248 int GetWidth() const { return x; }
249 int GetHeight() const { return y; }
f03fc89f 250
5d3e7b52 251 bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; }
706f1421
VZ
252
253 // combine this size with the other one replacing the default (i.e. equal
5d3e7b52 254 // to wxDefaultCoord) components of this object with those of the other
706f1421
VZ
255 void SetDefaults(const wxSize& size)
256 {
5d3e7b52 257 if ( x == wxDefaultCoord )
706f1421 258 x = size.x;
5d3e7b52 259 if ( y == wxDefaultCoord )
706f1421
VZ
260 y = size.y;
261 }
262
cc775580 263 // compatibility
72cdf4c9
VZ
264 int GetX() const { return x; }
265 int GetY() const { return y; }
c801d85f
KB
266};
267
bc5e942b
VZ
268
269inline bool operator==(const wxSize& s1, const wxSize& s2)
270{
271 return s1.x == s2.x && s1.y == s2.y;
272}
273
274inline bool operator!=(const wxSize& s1, const wxSize& s2)
275{
276 return s1.x != s2.x || s1.y != s2.y;
277}
278
279
280inline wxSize operator+(const wxSize& s1, const wxSize& s2)
281{
282 return wxSize(s1.x + s2.x, s1.y + s2.y);
283}
284
285
286inline wxSize operator-(const wxSize& s1, const wxSize& s2)
287{
288 return wxSize(s1.x - s2.x, s1.y - s2.y);
289}
290
291
292inline wxSize operator/(const wxSize& s, int i)
293{
294 return wxSize(s.x / i, s.y / i);
295}
296
297
298inline wxSize operator*(const wxSize& s, int i)
299{
300 return wxSize(s.x * i, s.y * i);
301}
302
303
304inline wxSize operator*(int i, const wxSize& s)
305{
306 return wxSize(s.x * i, s.y * i);
307}
308
309
310
311
f03fc89f
VZ
312// ---------------------------------------------------------------------------
313// Point classes: with real or integer coordinates
314// ---------------------------------------------------------------------------
764a3a49 315
6a6c0a8b 316class WXDLLEXPORT wxRealPoint
c801d85f 317{
f03fc89f
VZ
318public:
319 double x;
320 double y;
321
7ee31b00
GD
322 wxRealPoint() : x(0.0), y(0.0) { }
323 wxRealPoint(double xx, double yy) : x(xx), y(yy) { }
bc5e942b 324};
f03fc89f 325
f03fc89f 326
bc5e942b
VZ
327inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2)
328{
329 return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y);
330}
331
332
333inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2)
334{
335 return !(p1 == p2);
336}
337
338
339inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2)
340{
341 return wxRealPoint(p1.x + p2.x, p1.y + p2.y);
342}
343
344
345inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2)
346{
347 return wxRealPoint(p1.x - p2.x, p1.y - p2.y);
348}
c801d85f 349
bc14c8b2 350
bc5e942b
VZ
351// ----------------------------------------------------------------------------
352// wxPoint: 2D point with integer coordinates
353// ----------------------------------------------------------------------------
354
6a6c0a8b 355class WXDLLEXPORT wxPoint
c801d85f 356{
f03fc89f 357public:
72cdf4c9 358 int x, y;
6a6c0a8b 359
7ee31b00
GD
360 wxPoint() : x(0), y(0) { }
361 wxPoint(int xx, int yy) : x(xx), y(yy) { }
f03fc89f
VZ
362
363 // no copy ctor or assignment operator - the defaults are ok
6a6c0a8b 364
bc5e942b 365 //assignment operators
764a3a49
VZ
366 wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
367 wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
d02bc4c8
JS
368
369 wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; }
370 wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; }
bc5e942b 371};
d02bc4c8 372
24b800a9 373
bc5e942b
VZ
374// comparison
375inline bool operator==(const wxPoint& p1, const wxPoint& p2)
376{
377 return p1.x == p2.x && p1.y == p2.y;
378}
379
380inline bool operator!=(const wxPoint& p1, const wxPoint& p2)
381{
382 return !(p1 == p2);
383}
384
385
386// arithmetic operations (component wise)
387inline wxPoint operator+(const wxPoint& p1, const wxPoint& p2)
388{
389 return wxPoint(p1.x + p2.x, p1.y + p2.y);
390}
391
392inline wxPoint operator-(const wxPoint& p1, const wxPoint& p2)
393{
394 return wxPoint(p1.x - p2.x, p1.y - p2.y);
395}
396
397inline wxPoint operator+(const wxPoint& p, const wxSize& s)
398{
399 return wxPoint(p.x + s.x, p.y + s.y);
400}
401
402inline wxPoint operator-(const wxPoint& p, const wxSize& s)
403{
404 return wxPoint(p.x - s.x, p.y - s.y);
405}
406
407inline wxPoint operator+(const wxSize& s, const wxPoint& p)
408{
409 return wxPoint(p.x + s.x, p.y + s.y);
410}
411
412inline wxPoint operator-(const wxSize& s, const wxPoint& p)
413{
414 return wxPoint(s.x - p.x, s.y - p.y);
415}
416
417inline wxPoint operator-(const wxPoint& p)
418{
419 return wxPoint(-p.x, -p.y);
420}
421
b0d7707b 422WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE);
c801d85f 423
f03fc89f
VZ
424// ---------------------------------------------------------------------------
425// wxRect
426// ---------------------------------------------------------------------------
c801d85f 427
6a6c0a8b
JS
428class WXDLLEXPORT wxRect
429{
c801d85f 430public:
7ee31b00
GD
431 wxRect()
432 : x(0), y(0), width(0), height(0)
433 { }
72cdf4c9 434 wxRect(int xx, int yy, int ww, int hh)
7ee31b00
GD
435 : x(xx), y(yy), width(ww), height(hh)
436 { }
f03fc89f 437 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
df83b840
VZ
438 wxRect(const wxPoint& pt, const wxSize& size)
439 : x(pt.x), y(pt.y), width(size.x), height(size.y)
440 { }
441 wxRect(const wxSize& size)
442 : x(0), y(0), width(size.x), height(size.y)
443 { }
a23fd0e1
VZ
444
445 // default copy ctor and assignment operators ok
c801d85f 446
72cdf4c9
VZ
447 int GetX() const { return x; }
448 void SetX(int xx) { x = xx; }
c801d85f 449
72cdf4c9
VZ
450 int GetY() const { return y; }
451 void SetY(int yy) { y = yy; }
c801d85f 452
72cdf4c9
VZ
453 int GetWidth() const { return width; }
454 void SetWidth(int w) { width = w; }
c801d85f 455
72cdf4c9
VZ
456 int GetHeight() const { return height; }
457 void SetHeight(int h) { height = h; }
f03fc89f 458
dcb44466 459 wxPoint GetPosition() const { return wxPoint(x, y); }
4aa0010b
RL
460 void SetPosition( const wxPoint &p ) { x = p.x; y = p.y; }
461
dcb44466 462 wxSize GetSize() const { return wxSize(width, height); }
4aa0010b 463 void SetSize( const wxSize &s ) { width = s.GetWidth(); height = s.GetHeight(); }
f03fc89f 464
b737ad10
RR
465 bool IsEmpty() const { return (width <= 0) || (height <= 0); }
466
f790ec82
VZ
467 int GetLeft() const { return x; }
468 int GetTop() const { return y; }
469 int GetBottom() const { return y + height - 1; }
470 int GetRight() const { return x + width - 1; }
471
472 void SetLeft(int left) { x = left; }
473 void SetRight(int right) { width = right - x + 1; }
474 void SetTop(int top) { y = top; }
475 void SetBottom(int bottom) { height = bottom - y + 1; }
476
355a5e2b
JS
477 wxPoint GetTopLeft() const { return GetPosition(); }
478 wxPoint GetLeftTop() const { return GetTopLeft(); }
479 void SetTopLeft(const wxPoint &p) { SetPosition(p); }
480 void SetLeftTop(const wxPoint &p) { SetTopLeft(p); }
481
482 wxPoint GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
483 wxPoint GetRightBottom() const { return GetBottomRight(); }
484 void SetBottomRight(const wxPoint &p) { SetRight(p.x); SetBottom(p.y); }
485 void SetRightBottom(const wxPoint &p) { SetBottomRight(p); }
486
f790ec82
VZ
487 wxPoint GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
488 wxPoint GetRightTop() const { return GetTopRight(); }
489 void SetTopRight(const wxPoint &p) { SetRight(p.x); SetTop(p.y); }
490 void SetRightTop(const wxPoint &p) { SetTopLeft(p); }
f03fc89f 491
f790ec82
VZ
492 wxPoint GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
493 wxPoint GetLeftBottom() const { return GetBottomLeft(); }
494 void SetBottomLeft(const wxPoint &p) { SetLeft(p.x); SetBottom(p.y); }
495 void SetLeftBottom(const wxPoint &p) { SetBottomLeft(p); }
dcb44466 496
1e6feb95
VZ
497 // operations with rect
498 wxRect& Inflate(wxCoord dx, wxCoord dy);
c2c4d939 499 wxRect& Inflate(const wxSize& d) { return Inflate(d.x, d.y); }
1e6feb95
VZ
500 wxRect& Inflate(wxCoord d) { return Inflate(d, d); }
501 wxRect Inflate(wxCoord dx, wxCoord dy) const
502 {
503 wxRect r = *this;
504 r.Inflate(dx, dy);
505 return r;
506 }
507
508 wxRect& Deflate(wxCoord dx, wxCoord dy) { return Inflate(-dx, -dy); }
c2c4d939 509 wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); }
1e6feb95
VZ
510 wxRect& Deflate(wxCoord d) { return Inflate(-d); }
511 wxRect Deflate(wxCoord dx, wxCoord dy) const
512 {
513 wxRect r = *this;
514 r.Deflate(dx, dy);
515 return r;
516 }
517
518 void Offset(wxCoord dx, wxCoord dy) { x += dx; y += dy; }
519 void Offset(const wxPoint& pt) { Offset(pt.x, pt.y); }
520
521 wxRect& Intersect(const wxRect& rect);
522 wxRect Intersect(const wxRect& rect) const
45816ddd 523 {
1e6feb95
VZ
524 wxRect r = *this;
525 r.Intersect(rect);
526 return r;
45816ddd
VZ
527 }
528
df83b840
VZ
529 wxRect& Union(const wxRect& rect);
530 wxRect Union(const wxRect& rect) const
531 {
532 wxRect r = *this;
533 r.Union(rect);
534 return r;
535 }
45816ddd 536
5d3e7b52 537 // return true if the point is (not strcitly) inside the rect
22a35096
VS
538 bool Contains(int x, int y) const;
539 bool Contains(const wxPoint& pt) const { return Contains(pt.x, pt.y); }
869b59fc 540 // return true if the rectangle is (not strcitly) inside the rect
22a35096
VS
541 bool Contains(const wxRect& rect) const;
542
543#if WXWIN_COMPATIBILITY_2_6
544 // use Contains() instead
545 wxDEPRECATED( bool Inside(int x, int y) const );
546 wxDEPRECATED( bool Inside(const wxPoint& pt) const );
547 wxDEPRECATED( bool Inside(const wxRect& rect) const );
548#endif // WXWIN_COMPATIBILITY_2_6
1e6feb95 549
5d3e7b52 550 // return true if the rectangles have a non empty intersection
1e6feb95 551 bool Intersects(const wxRect& rect) const;
72cdf4c9 552
bc5e942b
VZ
553 // like Union() but don't ignore empty rectangles
554 wxRect& operator+=(const wxRect& rect);
df83b840 555
bc5e942b
VZ
556 // intersections of two rectrangles not testing for empty rectangles
557 wxRect& operator*=(const wxRect& rect);
df83b840 558
1bfb73b8
VZ
559 // centre this rectangle in the given (usually, but not necessarily,
560 // larger) one
561 wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const
562 {
563 return wxRect(dir & wxHORIZONTAL ? r.x + (r.width - width)/2 : x,
564 dir & wxVERTICAL ? r.y + (r.height - height)/2 : y,
565 width, height);
566 }
567
568 wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const
569 {
570 return CentreIn(r, dir);
571 }
572
f03fc89f 573public:
72cdf4c9 574 int x, y, width, height;
f03fc89f 575};
c801d85f 576
bc5e942b
VZ
577
578// compare rectangles
579inline bool operator==(const wxRect& r1, const wxRect& r2)
580{
581 return (r1.x == r2.x) && (r1.y == r2.y) &&
582 (r1.width == r2.width) && (r1.height == r2.height);
583}
584
585inline bool operator!=(const wxRect& r1, const wxRect& r2)
586{
587 return !(r1 == r2);
588}
589
590// like Union() but don't treat empty rectangles specially
591WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2);
592
593// intersections of two rectangles
594WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2);
595
596
597
598
22a35096 599#if WXWIN_COMPATIBILITY_2_6
3e69f6e5 600inline bool wxRect::Inside(int cx, int cy) const { return Contains(cx, cy); }
22a35096
VS
601inline bool wxRect::Inside(const wxPoint& pt) const { return Contains(pt); }
602inline bool wxRect::Inside(const wxRect& rect) const { return Contains(rect); }
603#endif // WXWIN_COMPATIBILITY_2_6
604
605
f03fc89f 606// ---------------------------------------------------------------------------
c801d85f 607// Management of pens, brushes and fonts
f03fc89f
VZ
608// ---------------------------------------------------------------------------
609
236a9de3
RL
610typedef wxInt8 wxDash;
611
1de8d512 612class WXDLLIMPEXP_CORE wxGDIObjListBase {
f03fc89f 613public:
1de8d512
VZ
614 wxGDIObjListBase();
615 ~wxGDIObjListBase();
f03fc89f 616
1de8d512
VZ
617protected:
618 wxList list;
c801d85f
KB
619};
620
1de8d512 621class WXDLLIMPEXP_CORE wxPenList: public wxGDIObjListBase
c801d85f 622{
f03fc89f 623public:
1de8d512
VZ
624 wxPen *FindOrCreatePen(const wxColour& colour, int width, int style);
625#if WXWIN_COMPATIBILITY_2_6
626 wxDEPRECATED( void AddPen(wxPen*) );
627 wxDEPRECATED( void RemovePen(wxPen*) );
628#endif
629};
f03fc89f 630
1de8d512
VZ
631class WXDLLIMPEXP_CORE wxBrushList: public wxGDIObjListBase
632{
633public:
cf000528 634 wxBrush *FindOrCreateBrush(const wxColour& colour, int style = wxSOLID);
1de8d512
VZ
635#if WXWIN_COMPATIBILITY_2_6
636 wxDEPRECATED( void AddBrush(wxBrush*) );
637 wxDEPRECATED( void RemoveBrush(wxBrush*) );
638#endif
c801d85f
KB
639};
640
1de8d512 641class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase
c801d85f 642{
f03fc89f 643public:
f03fc89f 644 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
5d3e7b52 645 bool underline = false,
37bebc11
RD
646 const wxString& face = wxEmptyString,
647 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
1de8d512
VZ
648#if WXWIN_COMPATIBILITY_2_6
649 wxDEPRECATED( void AddFont(wxFont*) );
650 wxDEPRECATED( void RemoveFont(wxFont*) );
651#endif
c801d85f
KB
652};
653
f79f1604
PC
654WX_DECLARE_STRING_HASH_MAP(wxColour*, wxStringToColourHashMap);
655
222ed1d6 656class WXDLLEXPORT wxColourDatabase
c801d85f 657{
f03fc89f 658public:
222ed1d6 659 wxColourDatabase();
c50f92d0 660 ~wxColourDatabase();
f03fc89f 661
c50f92d0
VZ
662 // find colour by name or name for the given colour
663 wxColour Find(const wxString& name) const;
f03fc89f 664 wxString FindName(const wxColour& colour) const;
c50f92d0
VZ
665
666 // add a new colour to the database
667 void AddColour(const wxString& name, const wxColour& colour);
668
ca3e85cf 669#if WXWIN_COMPATIBILITY_2_6
492e2a5b
VZ
670 // deprecated, use Find() instead
671 wxDEPRECATED( wxColour *FindColour(const wxString& name) );
ca3e85cf 672#endif // WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
673
674
19bf0c69
DW
675#ifdef __WXPM__
676 // PM keeps its own type of colour table
677 long* m_palTable;
678 size_t m_nSize;
679#endif
c50f92d0 680
222ed1d6 681private:
c50f92d0
VZ
682 // load the database with the built in colour values when called for the
683 // first time, do nothing after this
684 void Initialize();
222ed1d6 685
c50f92d0 686 wxStringToColourHashMap *m_map;
c801d85f
KB
687};
688
f03fc89f
VZ
689class WXDLLEXPORT wxResourceCache: public wxList
690{
691public:
692 wxResourceCache() { }
222ed1d6 693#if !wxUSE_STL
f03fc89f 694 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
222ed1d6 695#endif
d3c7fc99 696 virtual ~wxResourceCache();
f03fc89f
VZ
697};
698
699// ---------------------------------------------------------------------------
700// global variables
701// ---------------------------------------------------------------------------
702
c801d85f 703// Lists of GDI objects
16cba29d
WS
704extern WXDLLEXPORT_DATA(wxPenList*) wxThePenList;
705extern WXDLLEXPORT_DATA(wxBrushList*) wxTheBrushList;
706extern WXDLLEXPORT_DATA(wxFontList*) wxTheFontList;
c801d85f 707
f516d986
VZ
708/* Stock objects
709
710 wxStockGDI creates the stock GDI objects on demand. Pointers to the
711 created objects are stored in the ms_stockObject array, which is indexed
712 by the Item enum values. Platorm-specific fonts can be created by
713 implementing a derived class with an override for the GetFont function.
714 wxStockGDI operates as a singleton, accessed through the ms_instance
715 pointer. By default this pointer is set to an instance of wxStockGDI.
716 A derived class must arrange to set this pointer to an instance of itself.
717*/
718class WXDLLIMPEXP_CORE wxStockGDI
719{
720public:
721 enum Item {
722 BRUSH_BLACK,
723 BRUSH_BLUE,
724 BRUSH_CYAN,
725 BRUSH_GREEN,
726 BRUSH_GREY,
727 BRUSH_LIGHTGREY,
728 BRUSH_MEDIUMGREY,
729 BRUSH_RED,
730 BRUSH_TRANSPARENT,
731 BRUSH_WHITE,
732 COLOUR_BLACK,
733 COLOUR_BLUE,
734 COLOUR_CYAN,
735 COLOUR_GREEN,
736 COLOUR_LIGHTGREY,
737 COLOUR_RED,
738 COLOUR_WHITE,
739 CURSOR_CROSS,
740 CURSOR_HOURGLASS,
741 CURSOR_STANDARD,
742 FONT_ITALIC,
743 FONT_NORMAL,
744 FONT_SMALL,
745 FONT_SWISS,
746 PEN_BLACK,
747 PEN_BLACKDASHED,
748 PEN_CYAN,
749 PEN_GREEN,
750 PEN_GREY,
751 PEN_LIGHTGREY,
752 PEN_MEDIUMGREY,
753 PEN_RED,
754 PEN_TRANSPARENT,
755 PEN_WHITE,
756 ITEMCOUNT
757 };
758
759 wxStockGDI();
760 virtual ~wxStockGDI();
761 static void DeleteAll();
762
763 static wxStockGDI& instance() { return *ms_instance; }
764
765 static const wxBrush* GetBrush(Item item);
766 static const wxColour* GetColour(Item item);
767 static const wxCursor* GetCursor(Item item);
768 // Can be overridden by platform-specific derived classes
769 virtual const wxFont* GetFont(Item item);
770 static const wxPen* GetPen(Item item);
771
772protected:
773 static wxStockGDI* ms_instance;
774
775 static wxObject* ms_stockObject[ITEMCOUNT];
776
777 DECLARE_NO_COPY_CLASS(wxStockGDI)
778};
779
780#define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
781#define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
782#define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
783#define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
784
785#define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
786#define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
787#define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
788#define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
789#define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
790#define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
791#define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
792#define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
793#define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
794#define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
795
796#define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
797#define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
798#define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
799#define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
800#define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
801#define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
802#define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
803#define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
804#define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
805#define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
806
807#define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
808#define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
809#define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
810#define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
811#define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
812#define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
813#define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
814
815#define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
816#define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
817#define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
c801d85f
KB
818
819// 'Null' objects
16cba29d
WS
820extern WXDLLEXPORT_DATA(wxBitmap) wxNullBitmap;
821extern WXDLLEXPORT_DATA(wxIcon) wxNullIcon;
822extern WXDLLEXPORT_DATA(wxCursor) wxNullCursor;
823extern WXDLLEXPORT_DATA(wxPen) wxNullPen;
824extern WXDLLEXPORT_DATA(wxBrush) wxNullBrush;
52734360 825extern WXDLLEXPORT_DATA(wxPalette) wxNullPalette;
16cba29d
WS
826extern WXDLLEXPORT_DATA(wxFont) wxNullFont;
827extern WXDLLEXPORT_DATA(wxColour) wxNullColour;
52734360 828extern WXDLLEXPORT_DATA(wxIconBundle) wxNullIconBundle;
c801d85f 829
16cba29d 830extern WXDLLEXPORT_DATA(wxColourDatabase*) wxTheColourDatabase;
f03fc89f 831
63ec432b 832extern WXDLLEXPORT_DATA(const wxChar) wxPanelNameStr[];
c801d85f 833
16cba29d
WS
834extern WXDLLEXPORT_DATA(const wxSize) wxDefaultSize;
835extern WXDLLEXPORT_DATA(const wxPoint) wxDefaultPosition;
f03fc89f 836
f03fc89f
VZ
837// ---------------------------------------------------------------------------
838// global functions
839// ---------------------------------------------------------------------------
840
841// resource management
a3622daa 842extern void WXDLLEXPORT wxInitializeStockLists();
a3622daa 843extern void WXDLLEXPORT wxDeleteStockLists();
c801d85f 844
f03fc89f 845// is the display colour (or monochrome)?
6a6c0a8b 846extern bool WXDLLEXPORT wxColourDisplay();
c801d85f
KB
847
848// Returns depth of screen
6a6c0a8b
JS
849extern int WXDLLEXPORT wxDisplayDepth();
850#define wxGetDisplayDepth wxDisplayDepth
c801d85f 851
904a68b6 852// get the display size
c801d85f 853extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
6a6c0a8b 854extern wxSize WXDLLEXPORT wxGetDisplaySize();
904a68b6
RL
855extern void WXDLLEXPORT wxDisplaySizeMM(int *width, int *height);
856extern wxSize WXDLLEXPORT wxGetDisplaySizeMM();
c801d85f 857
ec5d7799
RD
858// Get position and size of the display workarea
859extern void WXDLLEXPORT wxClientDisplayRect(int *x, int *y, int *width, int *height);
860extern wxRect WXDLLEXPORT wxGetClientDisplayRect();
861
f03fc89f 862// set global cursor
c801d85f
KB
863extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
864
c801d85f 865#endif
34138703 866 // _WX_GDICMNH__