1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes, types and declarations
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 // ---------------------------------------------------------------------------
16 // ---------------------------------------------------------------------------
20 #include "wx/string.h"
21 #include "wx/fontenc.h"
22 #include "wx/hashmap.h"
25 // ---------------------------------------------------------------------------
26 // forward declarations
27 // ---------------------------------------------------------------------------
29 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
30 class WXDLLIMPEXP_FWD_CORE wxBrush
;
31 class WXDLLIMPEXP_FWD_CORE wxColour
;
32 class WXDLLIMPEXP_FWD_CORE wxCursor
;
33 class WXDLLIMPEXP_FWD_CORE wxFont
;
34 class WXDLLIMPEXP_FWD_CORE wxIcon
;
35 class WXDLLIMPEXP_FWD_CORE wxPalette
;
36 class WXDLLIMPEXP_FWD_CORE wxPen
;
37 class WXDLLIMPEXP_FWD_CORE wxRegion
;
38 class WXDLLIMPEXP_FWD_BASE wxString
;
39 class WXDLLIMPEXP_FWD_CORE wxIconBundle
;
40 class WXDLLIMPEXP_FWD_CORE wxPoint
;
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
49 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
51 wxBITMAP_TYPE_BMP_RESOURCE
,
52 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
54 wxBITMAP_TYPE_ICO_RESOURCE
,
56 wxBITMAP_TYPE_CUR_RESOURCE
,
58 wxBITMAP_TYPE_XBM_DATA
,
60 wxBITMAP_TYPE_XPM_DATA
,
62 wxBITMAP_TYPE_TIF
= wxBITMAP_TYPE_TIFF
,
63 wxBITMAP_TYPE_TIFF_RESOURCE
,
64 wxBITMAP_TYPE_TIF_RESOURCE
= wxBITMAP_TYPE_TIFF_RESOURCE
,
66 wxBITMAP_TYPE_GIF_RESOURCE
,
68 wxBITMAP_TYPE_PNG_RESOURCE
,
70 wxBITMAP_TYPE_JPEG_RESOURCE
,
72 wxBITMAP_TYPE_PNM_RESOURCE
,
74 wxBITMAP_TYPE_PCX_RESOURCE
,
76 wxBITMAP_TYPE_PICT_RESOURCE
,
78 wxBITMAP_TYPE_ICON_RESOURCE
,
82 wxBITMAP_TYPE_MACCURSOR
,
83 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
86 wxBITMAP_TYPE_ANY
= 50
89 // Polygon filling mode
90 enum wxPolygonFillMode
99 wxCURSOR_NONE
, // should be 0
101 wxCURSOR_RIGHT_ARROW
,
107 wxCURSOR_LEFT_BUTTON
,
109 wxCURSOR_MIDDLE_BUTTON
,
111 wxCURSOR_PAINT_BRUSH
,
114 wxCURSOR_POINT_RIGHT
,
115 wxCURSOR_QUESTION_ARROW
,
116 wxCURSOR_RIGHT_BUTTON
,
127 wxCURSOR_DEFAULT
, // standard X11 cursor
130 wxCURSOR_COPY_ARROW
, // MacOS Theme Plus arrow
133 // Not yet implemented for Windows
134 wxCURSOR_CROSS_REVERSE
,
135 wxCURSOR_DOUBLE_ARROW
,
136 wxCURSOR_BASED_ARROW_UP
,
137 wxCURSOR_BASED_ARROW_DOWN
,
142 wxCURSOR_CLOSED_HAND
,
149 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
153 // TODO CS supply openhand and closedhand cursors
154 #define wxCURSOR_OPEN_HAND wxCURSOR_HAND
155 #define wxCURSOR_CLOSED_HAND wxCURSOR_HAND
158 // ---------------------------------------------------------------------------
160 // ---------------------------------------------------------------------------
162 #if defined(__WINDOWS__) || defined(__WXPM__)
163 #define wxHAS_IMAGES_IN_RESOURCES
166 /* Useful macro for creating icons portably, for example:
168 wxIcon *icon = new wxICON(sample);
172 wxIcon *icon = new wxIcon("sample"); // On Windows
173 wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
177 // Load from a resource
178 #define wxICON(X) wxIcon(wxT(#X))
179 #elif defined(__WXPM__)
180 // Load from a resource
181 #define wxICON(X) wxIcon(wxT(#X))
182 #elif defined(__WXDFB__)
183 // Initialize from an included XPM
184 #define wxICON(X) wxIcon( X##_xpm )
185 #elif defined(__WXGTK__)
186 // Initialize from an included XPM
187 #define wxICON(X) wxIcon( X##_xpm )
188 #elif defined(__WXMAC__)
189 // Initialize from an included XPM
190 #define wxICON(X) wxIcon( X##_xpm )
191 #elif defined(__WXMOTIF__)
192 // Initialize from an included XPM
193 #define wxICON(X) wxIcon( X##_xpm )
194 #elif defined(__WXX11__)
195 // Initialize from an included XPM
196 #define wxICON(X) wxIcon( X##_xpm )
198 // This will usually mean something on any platform
199 #define wxICON(X) wxIcon(wxT(#X))
202 /* Another macro: this one is for portable creation of bitmaps. We assume that
203 under Unix bitmaps live in XPMs and under Windows they're in ressources.
206 #if defined(__WINDOWS__) || defined(__WXPM__)
207 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE)
208 #elif defined(__WXGTK__) || \
209 defined(__WXMOTIF__) || \
210 defined(__WXX11__) || \
211 defined(__WXMAC__) || \
212 defined(__WXDFB__) || \
214 // Initialize from an included XPM
215 #define wxBITMAP(name) wxBitmap(name##_xpm)
216 #else // other platforms
217 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
220 // Macro for creating wxBitmap from in-memory PNG data.
222 // It reads PNG data from name_png static byte arrays that can be created using
223 // e.g. misc/scripts/png2c.py.
225 // This macro exists mostly as a helper for wxBITMAP_PNG() below but also
226 // because it's slightly more convenient to use than NewFromPNGData() directly.
227 #define wxBITMAP_PNG_FROM_DATA(name) \
228 wxBitmap::NewFromPNGData(name##_png, WXSIZEOF(name##_png))
230 // Similar to wxBITMAP but used for the bitmaps in PNG format.
232 // Under Windows they should be embedded into the resource file using RT_RCDATA
233 // resource type and under OS X the PNG file with the specified name must be
234 // available in the resource subdirectory of the bundle. Elsewhere, this is
235 // exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above.
236 #if defined(__WINDOWS__) || defined(__WXOSX__)
237 #define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE)
239 #define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name)
242 // ===========================================================================
244 // ===========================================================================
246 // ---------------------------------------------------------------------------
248 // ---------------------------------------------------------------------------
250 class WXDLLIMPEXP_CORE wxSize
253 // members are public for compatibility, don't use them directly.
257 wxSize() : x(0), y(0) { }
258 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
260 // no copy ctor or assignment operator - the defaults are ok
262 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
263 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
264 wxSize
& operator/=(int i
) { x
/= i
; y
/= i
; return *this; }
265 wxSize
& operator*=(int i
) { x
*= i
; y
*= i
; return *this; }
266 wxSize
& operator/=(unsigned int i
) { x
/= i
; y
/= i
; return *this; }
267 wxSize
& operator*=(unsigned int i
) { x
*= i
; y
*= i
; return *this; }
268 wxSize
& operator/=(long i
) { x
/= i
; y
/= i
; return *this; }
269 wxSize
& operator*=(long i
) { x
*= i
; y
*= i
; return *this; }
270 wxSize
& operator/=(unsigned long i
) { x
/= i
; y
/= i
; return *this; }
271 wxSize
& operator*=(unsigned long i
) { x
*= i
; y
*= i
; return *this; }
272 wxSize
& operator/=(double i
) { x
= int(x
/i
); y
= int(y
/i
); return *this; }
273 wxSize
& operator*=(double i
) { x
= int(x
*i
); y
= int(y
*i
); return *this; }
275 void IncTo(const wxSize
& sz
)
276 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
277 void DecTo(const wxSize
& sz
)
278 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
279 void DecToIfSpecified(const wxSize
& sz
)
281 if ( sz
.x
!= wxDefaultCoord
&& sz
.x
< x
)
283 if ( sz
.y
!= wxDefaultCoord
&& sz
.y
< y
)
287 void IncBy(int dx
, int dy
) { x
+= dx
; y
+= dy
; }
288 void IncBy(const wxPoint
& pt
);
289 void IncBy(const wxSize
& sz
) { IncBy(sz
.x
, sz
.y
); }
290 void IncBy(int d
) { IncBy(d
, d
); }
292 void DecBy(int dx
, int dy
) { IncBy(-dx
, -dy
); }
293 void DecBy(const wxPoint
& pt
);
294 void DecBy(const wxSize
& sz
) { DecBy(sz
.x
, sz
.y
); }
295 void DecBy(int d
) { DecBy(d
, d
); }
298 wxSize
& Scale(float xscale
, float yscale
)
299 { x
= (int)(x
*xscale
); y
= (int)(y
*yscale
); return *this; }
302 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
303 void SetWidth(int w
) { x
= w
; }
304 void SetHeight(int h
) { y
= h
; }
306 int GetWidth() const { return x
; }
307 int GetHeight() const { return y
; }
309 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
311 // combine this size with the other one replacing the default (i.e. equal
312 // to wxDefaultCoord) components of this object with those of the other
313 void SetDefaults(const wxSize
& size
)
315 if ( x
== wxDefaultCoord
)
317 if ( y
== wxDefaultCoord
)
322 int GetX() const { return x
; }
323 int GetY() const { return y
; }
326 inline bool operator==(const wxSize
& s1
, const wxSize
& s2
)
328 return s1
.x
== s2
.x
&& s1
.y
== s2
.y
;
331 inline bool operator!=(const wxSize
& s1
, const wxSize
& s2
)
333 return s1
.x
!= s2
.x
|| s1
.y
!= s2
.y
;
336 inline wxSize
operator+(const wxSize
& s1
, const wxSize
& s2
)
338 return wxSize(s1
.x
+ s2
.x
, s1
.y
+ s2
.y
);
341 inline wxSize
operator-(const wxSize
& s1
, const wxSize
& s2
)
343 return wxSize(s1
.x
- s2
.x
, s1
.y
- s2
.y
);
346 inline wxSize
operator/(const wxSize
& s
, int i
)
348 return wxSize(s
.x
/ i
, s
.y
/ i
);
351 inline wxSize
operator*(const wxSize
& s
, int i
)
353 return wxSize(s
.x
* i
, s
.y
* i
);
356 inline wxSize
operator*(int i
, const wxSize
& s
)
358 return wxSize(s
.x
* i
, s
.y
* i
);
361 inline wxSize
operator/(const wxSize
& s
, unsigned int i
)
363 return wxSize(s
.x
/ i
, s
.y
/ i
);
366 inline wxSize
operator*(const wxSize
& s
, unsigned int i
)
368 return wxSize(s
.x
* i
, s
.y
* i
);
371 inline wxSize
operator*(unsigned int i
, const wxSize
& s
)
373 return wxSize(s
.x
* i
, s
.y
* i
);
376 inline wxSize
operator/(const wxSize
& s
, long i
)
378 return wxSize(s
.x
/ i
, s
.y
/ i
);
381 inline wxSize
operator*(const wxSize
& s
, long i
)
383 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
386 inline wxSize
operator*(long i
, const wxSize
& s
)
388 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
391 inline wxSize
operator/(const wxSize
& s
, unsigned long i
)
393 return wxSize(int(s
.x
/ i
), int(s
.y
/ i
));
396 inline wxSize
operator*(const wxSize
& s
, unsigned long i
)
398 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
401 inline wxSize
operator*(unsigned long i
, const wxSize
& s
)
403 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
406 inline wxSize
operator*(const wxSize
& s
, double i
)
408 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
411 inline wxSize
operator*(double i
, const wxSize
& s
)
413 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
418 // ---------------------------------------------------------------------------
419 // Point classes: with real or integer coordinates
420 // ---------------------------------------------------------------------------
422 class WXDLLIMPEXP_CORE wxRealPoint
428 wxRealPoint() : x(0.0), y(0.0) { }
429 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
430 wxRealPoint(const wxPoint
& pt
);
432 // no copy ctor or assignment operator - the defaults are ok
434 //assignment operators
435 wxRealPoint
& operator+=(const wxRealPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
436 wxRealPoint
& operator-=(const wxRealPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
438 wxRealPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
439 wxRealPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
443 inline bool operator==(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
445 return wxIsSameDouble(p1
.x
, p2
.x
) && wxIsSameDouble(p1
.y
, p2
.y
);
448 inline bool operator!=(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
453 inline wxRealPoint
operator+(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
455 return wxRealPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
459 inline wxRealPoint
operator-(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
461 return wxRealPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
465 inline wxRealPoint
operator/(const wxRealPoint
& s
, int i
)
467 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
470 inline wxRealPoint
operator*(const wxRealPoint
& s
, int i
)
472 return wxRealPoint(s
.x
* i
, s
.y
* i
);
475 inline wxRealPoint
operator*(int i
, const wxRealPoint
& s
)
477 return wxRealPoint(s
.x
* i
, s
.y
* i
);
480 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned int i
)
482 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
485 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned int i
)
487 return wxRealPoint(s
.x
* i
, s
.y
* i
);
490 inline wxRealPoint
operator*(unsigned int i
, const wxRealPoint
& s
)
492 return wxRealPoint(s
.x
* i
, s
.y
* i
);
495 inline wxRealPoint
operator/(const wxRealPoint
& s
, long i
)
497 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
500 inline wxRealPoint
operator*(const wxRealPoint
& s
, long i
)
502 return wxRealPoint(s
.x
* i
, s
.y
* i
);
505 inline wxRealPoint
operator*(long i
, const wxRealPoint
& s
)
507 return wxRealPoint(s
.x
* i
, s
.y
* i
);
510 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned long i
)
512 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
515 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned long i
)
517 return wxRealPoint(s
.x
* i
, s
.y
* i
);
520 inline wxRealPoint
operator*(unsigned long i
, const wxRealPoint
& s
)
522 return wxRealPoint(s
.x
* i
, s
.y
* i
);
525 inline wxRealPoint
operator*(const wxRealPoint
& s
, double i
)
527 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
530 inline wxRealPoint
operator*(double i
, const wxRealPoint
& s
)
532 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
536 // ----------------------------------------------------------------------------
537 // wxPoint: 2D point with integer coordinates
538 // ----------------------------------------------------------------------------
540 class WXDLLIMPEXP_CORE wxPoint
545 wxPoint() : x(0), y(0) { }
546 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
547 wxPoint(const wxRealPoint
& pt
) : x(int(pt
.x
)), y(int(pt
.y
)) { }
549 // no copy ctor or assignment operator - the defaults are ok
551 //assignment operators
552 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
553 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
555 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
556 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
558 // check if both components are set/initialized
559 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
561 // fill in the unset components with the values from the other point
562 void SetDefaults(const wxPoint
& pt
)
564 if ( x
== wxDefaultCoord
)
566 if ( y
== wxDefaultCoord
)
573 inline bool operator==(const wxPoint
& p1
, const wxPoint
& p2
)
575 return p1
.x
== p2
.x
&& p1
.y
== p2
.y
;
578 inline bool operator!=(const wxPoint
& p1
, const wxPoint
& p2
)
584 // arithmetic operations (component wise)
585 inline wxPoint
operator+(const wxPoint
& p1
, const wxPoint
& p2
)
587 return wxPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
590 inline wxPoint
operator-(const wxPoint
& p1
, const wxPoint
& p2
)
592 return wxPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
595 inline wxPoint
operator+(const wxPoint
& p
, const wxSize
& s
)
597 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
600 inline wxPoint
operator-(const wxPoint
& p
, const wxSize
& s
)
602 return wxPoint(p
.x
- s
.x
, p
.y
- s
.y
);
605 inline wxPoint
operator+(const wxSize
& s
, const wxPoint
& p
)
607 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
610 inline wxPoint
operator-(const wxSize
& s
, const wxPoint
& p
)
612 return wxPoint(s
.x
- p
.x
, s
.y
- p
.y
);
615 inline wxPoint
operator-(const wxPoint
& p
)
617 return wxPoint(-p
.x
, -p
.y
);
620 inline wxPoint
operator/(const wxPoint
& s
, int i
)
622 return wxPoint(s
.x
/ i
, s
.y
/ i
);
625 inline wxPoint
operator*(const wxPoint
& s
, int i
)
627 return wxPoint(s
.x
* i
, s
.y
* i
);
630 inline wxPoint
operator*(int i
, const wxPoint
& s
)
632 return wxPoint(s
.x
* i
, s
.y
* i
);
635 inline wxPoint
operator/(const wxPoint
& s
, unsigned int i
)
637 return wxPoint(s
.x
/ i
, s
.y
/ i
);
640 inline wxPoint
operator*(const wxPoint
& s
, unsigned int i
)
642 return wxPoint(s
.x
* i
, s
.y
* i
);
645 inline wxPoint
operator*(unsigned int i
, const wxPoint
& s
)
647 return wxPoint(s
.x
* i
, s
.y
* i
);
650 inline wxPoint
operator/(const wxPoint
& s
, long i
)
652 return wxPoint(s
.x
/ i
, s
.y
/ i
);
655 inline wxPoint
operator*(const wxPoint
& s
, long i
)
657 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
660 inline wxPoint
operator*(long i
, const wxPoint
& s
)
662 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
665 inline wxPoint
operator/(const wxPoint
& s
, unsigned long i
)
667 return wxPoint(s
.x
/ i
, s
.y
/ i
);
670 inline wxPoint
operator*(const wxPoint
& s
, unsigned long i
)
672 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
675 inline wxPoint
operator*(unsigned long i
, const wxPoint
& s
)
677 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
680 inline wxPoint
operator*(const wxPoint
& s
, double i
)
682 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
685 inline wxPoint
operator*(double i
, const wxPoint
& s
)
687 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
690 WX_DECLARE_LIST_WITH_DECL(wxPoint
, wxPointList
, class WXDLLIMPEXP_CORE
);
692 // ---------------------------------------------------------------------------
694 // ---------------------------------------------------------------------------
696 class WXDLLIMPEXP_CORE wxRect
700 : x(0), y(0), width(0), height(0)
702 wxRect(int xx
, int yy
, int ww
, int hh
)
703 : x(xx
), y(yy
), width(ww
), height(hh
)
705 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
706 wxRect(const wxPoint
& pt
, const wxSize
& size
)
707 : x(pt
.x
), y(pt
.y
), width(size
.x
), height(size
.y
)
709 wxRect(const wxSize
& size
)
710 : x(0), y(0), width(size
.x
), height(size
.y
)
713 // default copy ctor and assignment operators ok
715 int GetX() const { return x
; }
716 void SetX(int xx
) { x
= xx
; }
718 int GetY() const { return y
; }
719 void SetY(int yy
) { y
= yy
; }
721 int GetWidth() const { return width
; }
722 void SetWidth(int w
) { width
= w
; }
724 int GetHeight() const { return height
; }
725 void SetHeight(int h
) { height
= h
; }
727 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
728 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
730 wxSize
GetSize() const { return wxSize(width
, height
); }
731 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
733 bool IsEmpty() const { return (width
<= 0) || (height
<= 0); }
735 int GetLeft() const { return x
; }
736 int GetTop() const { return y
; }
737 int GetBottom() const { return y
+ height
- 1; }
738 int GetRight() const { return x
+ width
- 1; }
740 void SetLeft(int left
) { x
= left
; }
741 void SetRight(int right
) { width
= right
- x
+ 1; }
742 void SetTop(int top
) { y
= top
; }
743 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
745 wxPoint
GetTopLeft() const { return GetPosition(); }
746 wxPoint
GetLeftTop() const { return GetTopLeft(); }
747 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
748 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
750 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
751 wxPoint
GetRightBottom() const { return GetBottomRight(); }
752 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
753 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
755 wxPoint
GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
756 wxPoint
GetRightTop() const { return GetTopRight(); }
757 void SetTopRight(const wxPoint
&p
) { SetRight(p
.x
); SetTop(p
.y
); }
758 void SetRightTop(const wxPoint
&p
) { SetTopRight(p
); }
760 wxPoint
GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
761 wxPoint
GetLeftBottom() const { return GetBottomLeft(); }
762 void SetBottomLeft(const wxPoint
&p
) { SetLeft(p
.x
); SetBottom(p
.y
); }
763 void SetLeftBottom(const wxPoint
&p
) { SetBottomLeft(p
); }
765 // operations with rect
766 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
767 wxRect
& Inflate(const wxSize
& d
) { return Inflate(d
.x
, d
.y
); }
768 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
769 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
776 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
777 wxRect
& Deflate(const wxSize
& d
) { return Inflate(-d
.x
, -d
.y
); }
778 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
779 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
786 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
787 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
789 wxRect
& Intersect(const wxRect
& rect
);
790 wxRect
Intersect(const wxRect
& rect
) const
797 wxRect
& Union(const wxRect
& rect
);
798 wxRect
Union(const wxRect
& rect
) const
805 // return true if the point is (not strcitly) inside the rect
806 bool Contains(int x
, int y
) const;
807 bool Contains(const wxPoint
& pt
) const { return Contains(pt
.x
, pt
.y
); }
808 // return true if the rectangle 'rect' is (not strictly) inside this rect
809 bool Contains(const wxRect
& rect
) const;
811 #if WXWIN_COMPATIBILITY_2_6
812 // use Contains() instead
813 wxDEPRECATED( bool Inside(int x
, int y
) const );
814 wxDEPRECATED( bool Inside(const wxPoint
& pt
) const );
815 wxDEPRECATED( bool Inside(const wxRect
& rect
) const );
816 #endif // WXWIN_COMPATIBILITY_2_6
818 // return true if the rectangles have a non empty intersection
819 bool Intersects(const wxRect
& rect
) const;
821 // like Union() but don't ignore empty rectangles
822 wxRect
& operator+=(const wxRect
& rect
);
824 // intersections of two rectrangles not testing for empty rectangles
825 wxRect
& operator*=(const wxRect
& rect
);
827 // centre this rectangle in the given (usually, but not necessarily,
829 wxRect
CentreIn(const wxRect
& r
, int dir
= wxBOTH
) const
831 return wxRect(dir
& wxHORIZONTAL
? r
.x
+ (r
.width
- width
)/2 : x
,
832 dir
& wxVERTICAL
? r
.y
+ (r
.height
- height
)/2 : y
,
836 wxRect
CenterIn(const wxRect
& r
, int dir
= wxBOTH
) const
838 return CentreIn(r
, dir
);
842 int x
, y
, width
, height
;
846 // compare rectangles
847 inline bool operator==(const wxRect
& r1
, const wxRect
& r2
)
849 return (r1
.x
== r2
.x
) && (r1
.y
== r2
.y
) &&
850 (r1
.width
== r2
.width
) && (r1
.height
== r2
.height
);
853 inline bool operator!=(const wxRect
& r1
, const wxRect
& r2
)
858 // like Union() but don't treat empty rectangles specially
859 WXDLLIMPEXP_CORE wxRect
operator+(const wxRect
& r1
, const wxRect
& r2
);
861 // intersections of two rectangles
862 WXDLLIMPEXP_CORE wxRect
operator*(const wxRect
& r1
, const wxRect
& r2
);
867 #if WXWIN_COMPATIBILITY_2_6
868 inline bool wxRect::Inside(int cx
, int cy
) const { return Contains(cx
, cy
); }
869 inline bool wxRect::Inside(const wxPoint
& pt
) const { return Contains(pt
); }
870 inline bool wxRect::Inside(const wxRect
& rect
) const { return Contains(rect
); }
871 #endif // WXWIN_COMPATIBILITY_2_6
874 // define functions which couldn't be defined above because of declarations
876 inline void wxSize::IncBy(const wxPoint
& pt
) { IncBy(pt
.x
, pt
.y
); }
877 inline void wxSize::DecBy(const wxPoint
& pt
) { DecBy(pt
.x
, pt
.y
); }
879 // ---------------------------------------------------------------------------
880 // Management of pens, brushes and fonts
881 // ---------------------------------------------------------------------------
883 typedef wxInt8 wxDash
;
885 class WXDLLIMPEXP_CORE wxGDIObjListBase
{
894 WX_DECLARE_STRING_HASH_MAP(wxColour
*, wxStringToColourHashMap
);
896 class WXDLLIMPEXP_CORE wxColourDatabase
902 // find colour by name or name for the given colour
903 wxColour
Find(const wxString
& name
) const;
904 wxString
FindName(const wxColour
& colour
) const;
906 // add a new colour to the database
907 void AddColour(const wxString
& name
, const wxColour
& colour
);
909 #if WXWIN_COMPATIBILITY_2_6
910 // deprecated, use Find() instead
911 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
912 #endif // WXWIN_COMPATIBILITY_2_6
916 // PM keeps its own type of colour table
922 // load the database with the built in colour values when called for the
923 // first time, do nothing after this
926 wxStringToColourHashMap
*m_map
;
929 class WXDLLIMPEXP_CORE wxResourceCache
: public wxList
932 wxResourceCache() { }
933 #if !wxUSE_STD_CONTAINERS
934 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
936 virtual ~wxResourceCache();
939 // ---------------------------------------------------------------------------
941 // ---------------------------------------------------------------------------
946 wxStockGDI creates the stock GDI objects on demand. Pointers to the
947 created objects are stored in the ms_stockObject array, which is indexed
948 by the Item enum values. Platorm-specific fonts can be created by
949 implementing a derived class with an override for the GetFont function.
950 wxStockGDI operates as a singleton, accessed through the ms_instance
951 pointer. By default this pointer is set to an instance of wxStockGDI.
952 A derived class must arrange to set this pointer to an instance of itself.
954 class WXDLLIMPEXP_CORE wxStockGDI
1000 virtual ~wxStockGDI();
1001 static void DeleteAll();
1003 static wxStockGDI
& instance() { return *ms_instance
; }
1005 static const wxBrush
* GetBrush(Item item
);
1006 static const wxColour
* GetColour(Item item
);
1007 static const wxCursor
* GetCursor(Item item
);
1008 // Can be overridden by platform-specific derived classes
1009 virtual const wxFont
* GetFont(Item item
);
1010 static const wxPen
* GetPen(Item item
);
1013 static wxStockGDI
* ms_instance
;
1015 static wxObject
* ms_stockObject
[ITEMCOUNT
];
1017 wxDECLARE_NO_COPY_CLASS(wxStockGDI
);
1020 #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
1021 #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
1022 #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
1023 #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
1025 #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
1026 #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
1027 #define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE)
1028 #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
1029 #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
1030 #define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW)
1031 #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
1032 #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
1033 #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
1034 #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
1035 #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
1036 #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
1038 #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
1039 #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
1040 #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
1041 #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
1042 #define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW)
1043 #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
1044 #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
1045 #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
1046 #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
1047 #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
1048 #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
1050 #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
1051 #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
1052 #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
1053 #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
1054 #define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW)
1055 #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
1056 #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
1057 #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
1059 #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
1060 #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
1061 #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
1064 extern WXDLLIMPEXP_DATA_CORE(wxBitmap
) wxNullBitmap
;
1065 extern WXDLLIMPEXP_DATA_CORE(wxIcon
) wxNullIcon
;
1066 extern WXDLLIMPEXP_DATA_CORE(wxCursor
) wxNullCursor
;
1067 extern WXDLLIMPEXP_DATA_CORE(wxPen
) wxNullPen
;
1068 extern WXDLLIMPEXP_DATA_CORE(wxBrush
) wxNullBrush
;
1069 extern WXDLLIMPEXP_DATA_CORE(wxPalette
) wxNullPalette
;
1070 extern WXDLLIMPEXP_DATA_CORE(wxFont
) wxNullFont
;
1071 extern WXDLLIMPEXP_DATA_CORE(wxColour
) wxNullColour
;
1072 extern WXDLLIMPEXP_DATA_CORE(wxIconBundle
) wxNullIconBundle
;
1074 extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase
*) wxTheColourDatabase
;
1076 extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr
[];
1078 extern WXDLLIMPEXP_DATA_CORE(const wxSize
) wxDefaultSize
;
1079 extern WXDLLIMPEXP_DATA_CORE(const wxPoint
) wxDefaultPosition
;
1081 // ---------------------------------------------------------------------------
1083 // ---------------------------------------------------------------------------
1085 // resource management
1086 extern void WXDLLIMPEXP_CORE
wxInitializeStockLists();
1087 extern void WXDLLIMPEXP_CORE
wxDeleteStockLists();
1089 // is the display colour (or monochrome)?
1090 extern bool WXDLLIMPEXP_CORE
wxColourDisplay();
1092 // Returns depth of screen
1093 extern int WXDLLIMPEXP_CORE
wxDisplayDepth();
1094 #define wxGetDisplayDepth wxDisplayDepth
1096 // get the display size
1097 extern void WXDLLIMPEXP_CORE
wxDisplaySize(int *width
, int *height
);
1098 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySize();
1099 extern void WXDLLIMPEXP_CORE
wxDisplaySizeMM(int *width
, int *height
);
1100 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySizeMM();
1101 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplayPPI();
1103 // Get position and size of the display workarea
1104 extern void WXDLLIMPEXP_CORE
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
1105 extern wxRect WXDLLIMPEXP_CORE
wxGetClientDisplayRect();
1107 // set global cursor
1108 extern void WXDLLIMPEXP_CORE
wxSetCursor(const wxCursor
& cursor
);