]>
Commit | Line | Data |
---|---|---|
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 |
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; | |
f03fc89f VZ |
42 | |
43 | // --------------------------------------------------------------------------- | |
44 | // constants | |
45 | // --------------------------------------------------------------------------- | |
46 | ||
47 | // Bitmap flags | |
2aeec9ec | 48 | enum 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 |
89 | enum wxPolygonFillMode | |
90 | { | |
91 | wxODDEVEN_RULE = 1, | |
92 | wxWINDING_RULE | |
93 | }; | |
94 | ||
c801d85f | 95 | // Standard cursors |
f03fc89f VZ |
96 | enum 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 | ||
163 | wxIcon *icon = new wxICON(mondrian); | |
164 | ||
165 | expands into: | |
166 | ||
167 | wxIcon *icon = new wxIcon("mondrian"); // On wxMSW | |
168 | wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK | |
169 | */ | |
170 | ||
171 | #ifdef __WXMSW__ | |
172 | // Load from a resource | |
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 | 227 | class WXDLLIMPEXP_CORE wxSize |
c801d85f KB |
228 | { |
229 | public: | |
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; } | |
706f1421 | 243 | |
5b087ae2 VZ |
244 | void IncTo(const wxSize& sz) |
245 | { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; } | |
246 | void DecTo(const wxSize& sz) | |
247 | { if ( sz.x < x ) x = sz.x; if ( sz.y < y ) y = sz.y; } | |
f03fc89f | 248 | |
23359747 VZ |
249 | void IncBy(int dx, int dy) { x += dx; y += dy; } |
250 | void IncBy(const wxSize& sz) { IncBy(sz.x, sz.y); } | |
251 | void IncBy(int d) { IncBy(d, d); } | |
252 | ||
253 | void DecBy(int dx, int dy) { IncBy(-dx, -dy); } | |
254 | void DecBy(const wxSize& sz) { DecBy(sz.x, sz.y); } | |
255 | void DecBy(int d) { DecBy(d, d); } | |
256 | ||
257 | ||
c5bad604 RR |
258 | wxSize& Scale(float xscale, float yscale) |
259 | { x = (int)(x*xscale); y = (int)(y*yscale); return *this; } | |
8efb2907 | 260 | |
eddf46fe JS |
261 | // accessors |
262 | void Set(int xx, int yy) { x = xx; y = yy; } | |
72cdf4c9 VZ |
263 | void SetWidth(int w) { x = w; } |
264 | void SetHeight(int h) { y = h; } | |
cc775580 | 265 | |
72cdf4c9 VZ |
266 | int GetWidth() const { return x; } |
267 | int GetHeight() const { return y; } | |
f03fc89f | 268 | |
5d3e7b52 | 269 | bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; } |
706f1421 VZ |
270 | |
271 | // combine this size with the other one replacing the default (i.e. equal | |
5d3e7b52 | 272 | // to wxDefaultCoord) components of this object with those of the other |
706f1421 VZ |
273 | void SetDefaults(const wxSize& size) |
274 | { | |
5d3e7b52 | 275 | if ( x == wxDefaultCoord ) |
706f1421 | 276 | x = size.x; |
5d3e7b52 | 277 | if ( y == wxDefaultCoord ) |
706f1421 VZ |
278 | y = size.y; |
279 | } | |
280 | ||
cc775580 | 281 | // compatibility |
72cdf4c9 VZ |
282 | int GetX() const { return x; } |
283 | int GetY() const { return y; } | |
c801d85f KB |
284 | }; |
285 | ||
bc5e942b VZ |
286 | |
287 | inline bool operator==(const wxSize& s1, const wxSize& s2) | |
288 | { | |
289 | return s1.x == s2.x && s1.y == s2.y; | |
290 | } | |
291 | ||
292 | inline bool operator!=(const wxSize& s1, const wxSize& s2) | |
293 | { | |
294 | return s1.x != s2.x || s1.y != s2.y; | |
295 | } | |
296 | ||
297 | ||
298 | inline wxSize operator+(const wxSize& s1, const wxSize& s2) | |
299 | { | |
300 | return wxSize(s1.x + s2.x, s1.y + s2.y); | |
301 | } | |
302 | ||
303 | ||
304 | inline wxSize operator-(const wxSize& s1, const wxSize& s2) | |
305 | { | |
306 | return wxSize(s1.x - s2.x, s1.y - s2.y); | |
307 | } | |
308 | ||
309 | ||
310 | inline wxSize operator/(const wxSize& s, int i) | |
311 | { | |
312 | return wxSize(s.x / i, s.y / i); | |
313 | } | |
314 | ||
315 | ||
316 | inline wxSize operator*(const wxSize& s, int i) | |
317 | { | |
318 | return wxSize(s.x * i, s.y * i); | |
319 | } | |
320 | ||
321 | ||
322 | inline wxSize operator*(int i, const wxSize& s) | |
323 | { | |
324 | return wxSize(s.x * i, s.y * i); | |
325 | } | |
326 | ||
327 | ||
328 | ||
329 | ||
f03fc89f VZ |
330 | // --------------------------------------------------------------------------- |
331 | // Point classes: with real or integer coordinates | |
332 | // --------------------------------------------------------------------------- | |
764a3a49 | 333 | |
53a2db12 | 334 | class WXDLLIMPEXP_CORE wxRealPoint |
c801d85f | 335 | { |
f03fc89f VZ |
336 | public: |
337 | double x; | |
338 | double y; | |
339 | ||
7ee31b00 GD |
340 | wxRealPoint() : x(0.0), y(0.0) { } |
341 | wxRealPoint(double xx, double yy) : x(xx), y(yy) { } | |
bc5e942b | 342 | }; |
f03fc89f | 343 | |
f03fc89f | 344 | |
bc5e942b VZ |
345 | inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2) |
346 | { | |
347 | return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y); | |
348 | } | |
349 | ||
350 | ||
351 | inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2) | |
352 | { | |
353 | return !(p1 == p2); | |
354 | } | |
355 | ||
356 | ||
357 | inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2) | |
358 | { | |
359 | return wxRealPoint(p1.x + p2.x, p1.y + p2.y); | |
360 | } | |
361 | ||
362 | ||
363 | inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2) | |
364 | { | |
365 | return wxRealPoint(p1.x - p2.x, p1.y - p2.y); | |
366 | } | |
c801d85f | 367 | |
bc14c8b2 | 368 | |
bc5e942b VZ |
369 | // ---------------------------------------------------------------------------- |
370 | // wxPoint: 2D point with integer coordinates | |
371 | // ---------------------------------------------------------------------------- | |
372 | ||
53a2db12 | 373 | class WXDLLIMPEXP_CORE wxPoint |
c801d85f | 374 | { |
f03fc89f | 375 | public: |
72cdf4c9 | 376 | int x, y; |
6a6c0a8b | 377 | |
7ee31b00 GD |
378 | wxPoint() : x(0), y(0) { } |
379 | wxPoint(int xx, int yy) : x(xx), y(yy) { } | |
f03fc89f VZ |
380 | |
381 | // no copy ctor or assignment operator - the defaults are ok | |
6a6c0a8b | 382 | |
bc5e942b | 383 | //assignment operators |
764a3a49 VZ |
384 | wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; } |
385 | wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; } | |
d02bc4c8 JS |
386 | |
387 | wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } | |
388 | wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } | |
bc5e942b | 389 | }; |
d02bc4c8 | 390 | |
24b800a9 | 391 | |
bc5e942b VZ |
392 | // comparison |
393 | inline bool operator==(const wxPoint& p1, const wxPoint& p2) | |
394 | { | |
395 | return p1.x == p2.x && p1.y == p2.y; | |
396 | } | |
397 | ||
398 | inline bool operator!=(const wxPoint& p1, const wxPoint& p2) | |
399 | { | |
400 | return !(p1 == p2); | |
401 | } | |
402 | ||
403 | ||
404 | // arithmetic operations (component wise) | |
405 | inline wxPoint operator+(const wxPoint& p1, const wxPoint& p2) | |
406 | { | |
407 | return wxPoint(p1.x + p2.x, p1.y + p2.y); | |
408 | } | |
409 | ||
410 | inline wxPoint operator-(const wxPoint& p1, const wxPoint& p2) | |
411 | { | |
412 | return wxPoint(p1.x - p2.x, p1.y - p2.y); | |
413 | } | |
414 | ||
415 | inline wxPoint operator+(const wxPoint& p, const wxSize& s) | |
416 | { | |
417 | return wxPoint(p.x + s.x, p.y + s.y); | |
418 | } | |
419 | ||
420 | inline wxPoint operator-(const wxPoint& p, const wxSize& s) | |
421 | { | |
422 | return wxPoint(p.x - s.x, p.y - s.y); | |
423 | } | |
424 | ||
425 | inline wxPoint operator+(const wxSize& s, const wxPoint& p) | |
426 | { | |
427 | return wxPoint(p.x + s.x, p.y + s.y); | |
428 | } | |
429 | ||
430 | inline wxPoint operator-(const wxSize& s, const wxPoint& p) | |
431 | { | |
432 | return wxPoint(s.x - p.x, s.y - p.y); | |
433 | } | |
434 | ||
435 | inline wxPoint operator-(const wxPoint& p) | |
436 | { | |
437 | return wxPoint(-p.x, -p.y); | |
438 | } | |
439 | ||
b0d7707b | 440 | WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE); |
c801d85f | 441 | |
f03fc89f VZ |
442 | // --------------------------------------------------------------------------- |
443 | // wxRect | |
444 | // --------------------------------------------------------------------------- | |
c801d85f | 445 | |
53a2db12 | 446 | class WXDLLIMPEXP_CORE wxRect |
6a6c0a8b | 447 | { |
c801d85f | 448 | public: |
7ee31b00 GD |
449 | wxRect() |
450 | : x(0), y(0), width(0), height(0) | |
451 | { } | |
72cdf4c9 | 452 | wxRect(int xx, int yy, int ww, int hh) |
7ee31b00 GD |
453 | : x(xx), y(yy), width(ww), height(hh) |
454 | { } | |
f03fc89f | 455 | wxRect(const wxPoint& topLeft, const wxPoint& bottomRight); |
df83b840 VZ |
456 | wxRect(const wxPoint& pt, const wxSize& size) |
457 | : x(pt.x), y(pt.y), width(size.x), height(size.y) | |
458 | { } | |
459 | wxRect(const wxSize& size) | |
460 | : x(0), y(0), width(size.x), height(size.y) | |
461 | { } | |
a23fd0e1 VZ |
462 | |
463 | // default copy ctor and assignment operators ok | |
c801d85f | 464 | |
72cdf4c9 VZ |
465 | int GetX() const { return x; } |
466 | void SetX(int xx) { x = xx; } | |
c801d85f | 467 | |
72cdf4c9 VZ |
468 | int GetY() const { return y; } |
469 | void SetY(int yy) { y = yy; } | |
c801d85f | 470 | |
72cdf4c9 VZ |
471 | int GetWidth() const { return width; } |
472 | void SetWidth(int w) { width = w; } | |
c801d85f | 473 | |
72cdf4c9 VZ |
474 | int GetHeight() const { return height; } |
475 | void SetHeight(int h) { height = h; } | |
f03fc89f | 476 | |
dcb44466 | 477 | wxPoint GetPosition() const { return wxPoint(x, y); } |
4aa0010b RL |
478 | void SetPosition( const wxPoint &p ) { x = p.x; y = p.y; } |
479 | ||
dcb44466 | 480 | wxSize GetSize() const { return wxSize(width, height); } |
4aa0010b | 481 | void SetSize( const wxSize &s ) { width = s.GetWidth(); height = s.GetHeight(); } |
f03fc89f | 482 | |
b737ad10 RR |
483 | bool IsEmpty() const { return (width <= 0) || (height <= 0); } |
484 | ||
f790ec82 VZ |
485 | int GetLeft() const { return x; } |
486 | int GetTop() const { return y; } | |
487 | int GetBottom() const { return y + height - 1; } | |
488 | int GetRight() const { return x + width - 1; } | |
489 | ||
490 | void SetLeft(int left) { x = left; } | |
491 | void SetRight(int right) { width = right - x + 1; } | |
492 | void SetTop(int top) { y = top; } | |
493 | void SetBottom(int bottom) { height = bottom - y + 1; } | |
494 | ||
355a5e2b JS |
495 | wxPoint GetTopLeft() const { return GetPosition(); } |
496 | wxPoint GetLeftTop() const { return GetTopLeft(); } | |
497 | void SetTopLeft(const wxPoint &p) { SetPosition(p); } | |
498 | void SetLeftTop(const wxPoint &p) { SetTopLeft(p); } | |
499 | ||
500 | wxPoint GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); } | |
501 | wxPoint GetRightBottom() const { return GetBottomRight(); } | |
502 | void SetBottomRight(const wxPoint &p) { SetRight(p.x); SetBottom(p.y); } | |
503 | void SetRightBottom(const wxPoint &p) { SetBottomRight(p); } | |
504 | ||
f790ec82 VZ |
505 | wxPoint GetTopRight() const { return wxPoint(GetRight(), GetTop()); } |
506 | wxPoint GetRightTop() const { return GetTopRight(); } | |
507 | void SetTopRight(const wxPoint &p) { SetRight(p.x); SetTop(p.y); } | |
508 | void SetRightTop(const wxPoint &p) { SetTopLeft(p); } | |
f03fc89f | 509 | |
f790ec82 VZ |
510 | wxPoint GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); } |
511 | wxPoint GetLeftBottom() const { return GetBottomLeft(); } | |
512 | void SetBottomLeft(const wxPoint &p) { SetLeft(p.x); SetBottom(p.y); } | |
513 | void SetLeftBottom(const wxPoint &p) { SetBottomLeft(p); } | |
dcb44466 | 514 | |
1e6feb95 VZ |
515 | // operations with rect |
516 | wxRect& Inflate(wxCoord dx, wxCoord dy); | |
c2c4d939 | 517 | wxRect& Inflate(const wxSize& d) { return Inflate(d.x, d.y); } |
1e6feb95 VZ |
518 | wxRect& Inflate(wxCoord d) { return Inflate(d, d); } |
519 | wxRect Inflate(wxCoord dx, wxCoord dy) const | |
520 | { | |
521 | wxRect r = *this; | |
522 | r.Inflate(dx, dy); | |
523 | return r; | |
524 | } | |
525 | ||
526 | wxRect& Deflate(wxCoord dx, wxCoord dy) { return Inflate(-dx, -dy); } | |
c2c4d939 | 527 | wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); } |
1e6feb95 VZ |
528 | wxRect& Deflate(wxCoord d) { return Inflate(-d); } |
529 | wxRect Deflate(wxCoord dx, wxCoord dy) const | |
530 | { | |
531 | wxRect r = *this; | |
532 | r.Deflate(dx, dy); | |
533 | return r; | |
534 | } | |
535 | ||
536 | void Offset(wxCoord dx, wxCoord dy) { x += dx; y += dy; } | |
537 | void Offset(const wxPoint& pt) { Offset(pt.x, pt.y); } | |
538 | ||
539 | wxRect& Intersect(const wxRect& rect); | |
540 | wxRect Intersect(const wxRect& rect) const | |
45816ddd | 541 | { |
1e6feb95 VZ |
542 | wxRect r = *this; |
543 | r.Intersect(rect); | |
544 | return r; | |
45816ddd VZ |
545 | } |
546 | ||
df83b840 VZ |
547 | wxRect& Union(const wxRect& rect); |
548 | wxRect Union(const wxRect& rect) const | |
549 | { | |
550 | wxRect r = *this; | |
551 | r.Union(rect); | |
552 | return r; | |
553 | } | |
45816ddd | 554 | |
5d3e7b52 | 555 | // return true if the point is (not strcitly) inside the rect |
22a35096 VS |
556 | bool Contains(int x, int y) const; |
557 | bool Contains(const wxPoint& pt) const { return Contains(pt.x, pt.y); } | |
fc01e9b3 | 558 | // return true if the rectangle 'rect' is (not strictly) inside this rect |
22a35096 VS |
559 | bool Contains(const wxRect& rect) const; |
560 | ||
561 | #if WXWIN_COMPATIBILITY_2_6 | |
562 | // use Contains() instead | |
563 | wxDEPRECATED( bool Inside(int x, int y) const ); | |
564 | wxDEPRECATED( bool Inside(const wxPoint& pt) const ); | |
565 | wxDEPRECATED( bool Inside(const wxRect& rect) const ); | |
566 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1e6feb95 | 567 | |
5d3e7b52 | 568 | // return true if the rectangles have a non empty intersection |
1e6feb95 | 569 | bool Intersects(const wxRect& rect) const; |
72cdf4c9 | 570 | |
bc5e942b VZ |
571 | // like Union() but don't ignore empty rectangles |
572 | wxRect& operator+=(const wxRect& rect); | |
df83b840 | 573 | |
bc5e942b VZ |
574 | // intersections of two rectrangles not testing for empty rectangles |
575 | wxRect& operator*=(const wxRect& rect); | |
df83b840 | 576 | |
1bfb73b8 VZ |
577 | // centre this rectangle in the given (usually, but not necessarily, |
578 | // larger) one | |
579 | wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const | |
580 | { | |
581 | return wxRect(dir & wxHORIZONTAL ? r.x + (r.width - width)/2 : x, | |
582 | dir & wxVERTICAL ? r.y + (r.height - height)/2 : y, | |
583 | width, height); | |
584 | } | |
585 | ||
586 | wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const | |
587 | { | |
588 | return CentreIn(r, dir); | |
589 | } | |
590 | ||
f03fc89f | 591 | public: |
72cdf4c9 | 592 | int x, y, width, height; |
f03fc89f | 593 | }; |
c801d85f | 594 | |
bc5e942b VZ |
595 | |
596 | // compare rectangles | |
597 | inline bool operator==(const wxRect& r1, const wxRect& r2) | |
598 | { | |
599 | return (r1.x == r2.x) && (r1.y == r2.y) && | |
600 | (r1.width == r2.width) && (r1.height == r2.height); | |
601 | } | |
602 | ||
603 | inline bool operator!=(const wxRect& r1, const wxRect& r2) | |
604 | { | |
605 | return !(r1 == r2); | |
606 | } | |
607 | ||
608 | // like Union() but don't treat empty rectangles specially | |
609 | WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2); | |
610 | ||
611 | // intersections of two rectangles | |
612 | WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2); | |
613 | ||
614 | ||
615 | ||
616 | ||
22a35096 | 617 | #if WXWIN_COMPATIBILITY_2_6 |
3e69f6e5 | 618 | inline bool wxRect::Inside(int cx, int cy) const { return Contains(cx, cy); } |
22a35096 VS |
619 | inline bool wxRect::Inside(const wxPoint& pt) const { return Contains(pt); } |
620 | inline bool wxRect::Inside(const wxRect& rect) const { return Contains(rect); } | |
621 | #endif // WXWIN_COMPATIBILITY_2_6 | |
622 | ||
623 | ||
f03fc89f | 624 | // --------------------------------------------------------------------------- |
c801d85f | 625 | // Management of pens, brushes and fonts |
f03fc89f VZ |
626 | // --------------------------------------------------------------------------- |
627 | ||
236a9de3 RL |
628 | typedef wxInt8 wxDash; |
629 | ||
1de8d512 | 630 | class WXDLLIMPEXP_CORE wxGDIObjListBase { |
f03fc89f | 631 | public: |
1de8d512 VZ |
632 | wxGDIObjListBase(); |
633 | ~wxGDIObjListBase(); | |
f03fc89f | 634 | |
1de8d512 VZ |
635 | protected: |
636 | wxList list; | |
c801d85f KB |
637 | }; |
638 | ||
f79f1604 PC |
639 | WX_DECLARE_STRING_HASH_MAP(wxColour*, wxStringToColourHashMap); |
640 | ||
53a2db12 | 641 | class WXDLLIMPEXP_CORE wxColourDatabase |
c801d85f | 642 | { |
f03fc89f | 643 | public: |
222ed1d6 | 644 | wxColourDatabase(); |
c50f92d0 | 645 | ~wxColourDatabase(); |
f03fc89f | 646 | |
c50f92d0 VZ |
647 | // find colour by name or name for the given colour |
648 | wxColour Find(const wxString& name) const; | |
f03fc89f | 649 | wxString FindName(const wxColour& colour) const; |
c50f92d0 VZ |
650 | |
651 | // add a new colour to the database | |
652 | void AddColour(const wxString& name, const wxColour& colour); | |
653 | ||
ca3e85cf | 654 | #if WXWIN_COMPATIBILITY_2_6 |
492e2a5b VZ |
655 | // deprecated, use Find() instead |
656 | wxDEPRECATED( wxColour *FindColour(const wxString& name) ); | |
ca3e85cf | 657 | #endif // WXWIN_COMPATIBILITY_2_6 |
c50f92d0 VZ |
658 | |
659 | ||
19bf0c69 DW |
660 | #ifdef __WXPM__ |
661 | // PM keeps its own type of colour table | |
662 | long* m_palTable; | |
663 | size_t m_nSize; | |
664 | #endif | |
c50f92d0 | 665 | |
222ed1d6 | 666 | private: |
c50f92d0 VZ |
667 | // load the database with the built in colour values when called for the |
668 | // first time, do nothing after this | |
669 | void Initialize(); | |
222ed1d6 | 670 | |
c50f92d0 | 671 | wxStringToColourHashMap *m_map; |
c801d85f KB |
672 | }; |
673 | ||
53a2db12 | 674 | class WXDLLIMPEXP_CORE wxResourceCache: public wxList |
f03fc89f VZ |
675 | { |
676 | public: | |
677 | wxResourceCache() { } | |
222ed1d6 | 678 | #if !wxUSE_STL |
f03fc89f | 679 | wxResourceCache(const unsigned int keyType) : wxList(keyType) { } |
222ed1d6 | 680 | #endif |
d3c7fc99 | 681 | virtual ~wxResourceCache(); |
f03fc89f VZ |
682 | }; |
683 | ||
684 | // --------------------------------------------------------------------------- | |
685 | // global variables | |
686 | // --------------------------------------------------------------------------- | |
687 | ||
c801d85f | 688 | |
f516d986 VZ |
689 | /* Stock objects |
690 | ||
691 | wxStockGDI creates the stock GDI objects on demand. Pointers to the | |
692 | created objects are stored in the ms_stockObject array, which is indexed | |
693 | by the Item enum values. Platorm-specific fonts can be created by | |
694 | implementing a derived class with an override for the GetFont function. | |
695 | wxStockGDI operates as a singleton, accessed through the ms_instance | |
696 | pointer. By default this pointer is set to an instance of wxStockGDI. | |
697 | A derived class must arrange to set this pointer to an instance of itself. | |
698 | */ | |
699 | class WXDLLIMPEXP_CORE wxStockGDI | |
700 | { | |
701 | public: | |
702 | enum Item { | |
703 | BRUSH_BLACK, | |
704 | BRUSH_BLUE, | |
705 | BRUSH_CYAN, | |
706 | BRUSH_GREEN, | |
707 | BRUSH_GREY, | |
708 | BRUSH_LIGHTGREY, | |
709 | BRUSH_MEDIUMGREY, | |
710 | BRUSH_RED, | |
711 | BRUSH_TRANSPARENT, | |
712 | BRUSH_WHITE, | |
713 | COLOUR_BLACK, | |
714 | COLOUR_BLUE, | |
715 | COLOUR_CYAN, | |
716 | COLOUR_GREEN, | |
717 | COLOUR_LIGHTGREY, | |
718 | COLOUR_RED, | |
719 | COLOUR_WHITE, | |
720 | CURSOR_CROSS, | |
721 | CURSOR_HOURGLASS, | |
722 | CURSOR_STANDARD, | |
723 | FONT_ITALIC, | |
724 | FONT_NORMAL, | |
725 | FONT_SMALL, | |
726 | FONT_SWISS, | |
727 | PEN_BLACK, | |
728 | PEN_BLACKDASHED, | |
729 | PEN_CYAN, | |
730 | PEN_GREEN, | |
731 | PEN_GREY, | |
732 | PEN_LIGHTGREY, | |
733 | PEN_MEDIUMGREY, | |
734 | PEN_RED, | |
735 | PEN_TRANSPARENT, | |
736 | PEN_WHITE, | |
737 | ITEMCOUNT | |
738 | }; | |
739 | ||
740 | wxStockGDI(); | |
741 | virtual ~wxStockGDI(); | |
742 | static void DeleteAll(); | |
743 | ||
744 | static wxStockGDI& instance() { return *ms_instance; } | |
745 | ||
746 | static const wxBrush* GetBrush(Item item); | |
747 | static const wxColour* GetColour(Item item); | |
748 | static const wxCursor* GetCursor(Item item); | |
749 | // Can be overridden by platform-specific derived classes | |
750 | virtual const wxFont* GetFont(Item item); | |
751 | static const wxPen* GetPen(Item item); | |
752 | ||
753 | protected: | |
754 | static wxStockGDI* ms_instance; | |
755 | ||
756 | static wxObject* ms_stockObject[ITEMCOUNT]; | |
757 | ||
758 | DECLARE_NO_COPY_CLASS(wxStockGDI) | |
759 | }; | |
760 | ||
761 | #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC) | |
762 | #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL) | |
763 | #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL) | |
764 | #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS) | |
765 | ||
766 | #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED) | |
767 | #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK) | |
768 | #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN) | |
769 | #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN) | |
770 | #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY) | |
771 | #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY) | |
772 | #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY) | |
773 | #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED) | |
774 | #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT) | |
775 | #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE) | |
776 | ||
777 | #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK) | |
778 | #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE) | |
779 | #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN) | |
780 | #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN) | |
781 | #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY) | |
782 | #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY) | |
783 | #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY) | |
784 | #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED) | |
785 | #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT) | |
786 | #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE) | |
787 | ||
788 | #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK) | |
789 | #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE) | |
790 | #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN) | |
791 | #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN) | |
792 | #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY) | |
793 | #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED) | |
794 | #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE) | |
795 | ||
796 | #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS) | |
797 | #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS) | |
798 | #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD) | |
c801d85f KB |
799 | |
800 | // 'Null' objects | |
53a2db12 FM |
801 | extern WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap; |
802 | extern WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon; | |
803 | extern WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor; | |
804 | extern WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen; | |
805 | extern WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush; | |
806 | extern WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette; | |
807 | extern WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont; | |
808 | extern WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour; | |
809 | extern WXDLLIMPEXP_DATA_CORE(wxIconBundle) wxNullIconBundle; | |
c801d85f | 810 | |
53a2db12 | 811 | extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase; |
f03fc89f | 812 | |
53a2db12 | 813 | extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr[]; |
c801d85f | 814 | |
53a2db12 FM |
815 | extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize; |
816 | extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition; | |
f03fc89f | 817 | |
f03fc89f VZ |
818 | // --------------------------------------------------------------------------- |
819 | // global functions | |
820 | // --------------------------------------------------------------------------- | |
821 | ||
822 | // resource management | |
53a2db12 FM |
823 | extern void WXDLLIMPEXP_CORE wxInitializeStockLists(); |
824 | extern void WXDLLIMPEXP_CORE wxDeleteStockLists(); | |
c801d85f | 825 | |
f03fc89f | 826 | // is the display colour (or monochrome)? |
53a2db12 | 827 | extern bool WXDLLIMPEXP_CORE wxColourDisplay(); |
c801d85f KB |
828 | |
829 | // Returns depth of screen | |
53a2db12 | 830 | extern int WXDLLIMPEXP_CORE wxDisplayDepth(); |
6a6c0a8b | 831 | #define wxGetDisplayDepth wxDisplayDepth |
c801d85f | 832 | |
904a68b6 | 833 | // get the display size |
53a2db12 FM |
834 | extern void WXDLLIMPEXP_CORE wxDisplaySize(int *width, int *height); |
835 | extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize(); | |
836 | extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height); | |
837 | extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM(); | |
40fcf546 | 838 | extern wxSize WXDLLIMPEXP_CORE wxGetDisplayPPI(); |
c801d85f | 839 | |
ec5d7799 | 840 | // Get position and size of the display workarea |
53a2db12 FM |
841 | extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height); |
842 | extern wxRect WXDLLIMPEXP_CORE wxGetClientDisplayRect(); | |
ec5d7799 | 843 | |
f03fc89f | 844 | // set global cursor |
53a2db12 | 845 | extern void WXDLLIMPEXP_CORE wxSetCursor(const wxCursor& cursor); |
c801d85f | 846 | |
c801d85f | 847 | #endif |
34138703 | 848 | // _WX_GDICMNH__ |