1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes, types and declarations
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
21 #include "wx/string.h"
22 #include "wx/fontenc.h"
23 #include "wx/hashmap.h"
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
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
;
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
50 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
52 wxBITMAP_TYPE_BMP_RESOURCE
,
53 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
55 wxBITMAP_TYPE_ICO_RESOURCE
,
57 wxBITMAP_TYPE_CUR_RESOURCE
,
59 wxBITMAP_TYPE_XBM_DATA
,
61 wxBITMAP_TYPE_XPM_DATA
,
63 wxBITMAP_TYPE_TIF
= wxBITMAP_TYPE_TIFF
,
64 wxBITMAP_TYPE_TIFF_RESOURCE
,
65 wxBITMAP_TYPE_TIF_RESOURCE
= wxBITMAP_TYPE_TIFF_RESOURCE
,
67 wxBITMAP_TYPE_GIF_RESOURCE
,
69 wxBITMAP_TYPE_PNG_RESOURCE
,
71 wxBITMAP_TYPE_JPEG_RESOURCE
,
73 wxBITMAP_TYPE_PNM_RESOURCE
,
75 wxBITMAP_TYPE_PCX_RESOURCE
,
77 wxBITMAP_TYPE_PICT_RESOURCE
,
79 wxBITMAP_TYPE_ICON_RESOURCE
,
83 wxBITMAP_TYPE_MACCURSOR
,
84 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
87 wxBITMAP_TYPE_ANY
= 50
90 // Polygon filling mode
91 enum wxPolygonFillMode
100 wxCURSOR_NONE
, // should be 0
102 wxCURSOR_RIGHT_ARROW
,
108 wxCURSOR_LEFT_BUTTON
,
110 wxCURSOR_MIDDLE_BUTTON
,
112 wxCURSOR_PAINT_BRUSH
,
115 wxCURSOR_POINT_RIGHT
,
116 wxCURSOR_QUESTION_ARROW
,
117 wxCURSOR_RIGHT_BUTTON
,
128 wxCURSOR_DEFAULT
, // standard X11 cursor
131 wxCURSOR_COPY_ARROW
, // MacOS Theme Plus arrow
134 // Not yet implemented for Windows
135 wxCURSOR_CROSS_REVERSE
,
136 wxCURSOR_DOUBLE_ARROW
,
137 wxCURSOR_BASED_ARROW_UP
,
138 wxCURSOR_BASED_ARROW_DOWN
,
143 wxCURSOR_CLOSED_HAND
,
150 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
154 // TODO CS supply openhand and closedhand cursors
155 #define wxCURSOR_OPEN_HAND wxCURSOR_HAND
156 #define wxCURSOR_CLOSED_HAND wxCURSOR_HAND
159 // ---------------------------------------------------------------------------
161 // ---------------------------------------------------------------------------
163 #if defined(__WINDOWS__) || defined(__WXPM__)
164 #define wxHAS_IMAGES_IN_RESOURCES
167 /* Useful macro for creating icons portably, for example:
169 wxIcon *icon = new wxICON(sample);
173 wxIcon *icon = new wxIcon("sample"); // On Windows
174 wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
178 // Load from a resource
179 #define wxICON(X) wxIcon(wxT(#X))
180 #elif defined(__WXPM__)
181 // Load from a resource
182 #define wxICON(X) wxIcon(wxT(#X))
183 #elif defined(__WXDFB__)
184 // Initialize from an included XPM
185 #define wxICON(X) wxIcon( X##_xpm )
186 #elif defined(__WXGTK__)
187 // Initialize from an included XPM
188 #define wxICON(X) wxIcon( X##_xpm )
189 #elif defined(__WXMAC__)
190 // Initialize from an included XPM
191 #define wxICON(X) wxIcon( X##_xpm )
192 #elif defined(__WXMOTIF__)
193 // Initialize from an included XPM
194 #define wxICON(X) wxIcon( X##_xpm )
195 #elif defined(__WXX11__)
196 // Initialize from an included XPM
197 #define wxICON(X) wxIcon( X##_xpm )
199 // This will usually mean something on any platform
200 #define wxICON(X) wxIcon(wxT(#X))
203 /* Another macro: this one is for portable creation of bitmaps. We assume that
204 under Unix bitmaps live in XPMs and under Windows they're in ressources.
207 #if defined(__WINDOWS__) || defined(__WXPM__)
208 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE)
209 #elif defined(__WXGTK__) || \
210 defined(__WXMOTIF__) || \
211 defined(__WXX11__) || \
212 defined(__WXMAC__) || \
213 defined(__WXDFB__) || \
215 // Initialize from an included XPM
216 #define wxBITMAP(name) wxBitmap(name##_xpm)
217 #else // other platforms
218 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
221 // Macro for creating wxBitmap from in-memory PNG data.
223 // It reads PNG data from name_png static byte arrays that can be created using
224 // e.g. misc/scripts/png2c.py.
226 // This macro exists mostly as a helper for wxBITMAP_PNG() below but also
227 // because it's slightly more convenient to use than NewFromPNGData() directly.
228 #define wxBITMAP_PNG_FROM_DATA(name) \
229 wxBitmap::NewFromPNGData(name##_png, WXSIZEOF(name##_png))
231 // Similar to wxBITMAP but used for the bitmaps in PNG format.
233 // Under Windows they should be embedded into the resource file using RT_RCDATA
234 // resource type and under OS X the PNG file with the specified name must be
235 // available in the resource subdirectory of the bundle. Elsewhere, this is
236 // exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above.
237 #if defined(__WINDOWS__) || defined(__WXOSX__)
238 #define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE)
240 #define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name)
243 // ===========================================================================
245 // ===========================================================================
247 // ---------------------------------------------------------------------------
249 // ---------------------------------------------------------------------------
251 class WXDLLIMPEXP_CORE wxSize
254 // members are public for compatibility, don't use them directly.
258 wxSize() : x(0), y(0) { }
259 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
261 // no copy ctor or assignment operator - the defaults are ok
263 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
264 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
265 wxSize
& operator/=(int i
) { x
/= i
; y
/= i
; return *this; }
266 wxSize
& operator*=(int i
) { x
*= i
; y
*= i
; return *this; }
267 wxSize
& operator/=(unsigned int i
) { x
/= i
; y
/= i
; return *this; }
268 wxSize
& operator*=(unsigned int i
) { x
*= i
; y
*= i
; return *this; }
269 wxSize
& operator/=(long i
) { x
/= i
; y
/= i
; return *this; }
270 wxSize
& operator*=(long i
) { x
*= i
; y
*= i
; return *this; }
271 wxSize
& operator/=(unsigned long i
) { x
/= i
; y
/= i
; return *this; }
272 wxSize
& operator*=(unsigned long i
) { x
*= i
; y
*= i
; return *this; }
273 wxSize
& operator/=(double i
) { x
= int(x
/i
); y
= int(y
/i
); return *this; }
274 wxSize
& operator*=(double i
) { x
= int(x
*i
); y
= int(y
*i
); return *this; }
276 void IncTo(const wxSize
& sz
)
277 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
278 void DecTo(const wxSize
& sz
)
279 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
280 void DecToIfSpecified(const wxSize
& sz
)
282 if ( sz
.x
!= wxDefaultCoord
&& sz
.x
< x
)
284 if ( sz
.y
!= wxDefaultCoord
&& sz
.y
< y
)
288 void IncBy(int dx
, int dy
) { x
+= dx
; y
+= dy
; }
289 void IncBy(const wxPoint
& pt
);
290 void IncBy(const wxSize
& sz
) { IncBy(sz
.x
, sz
.y
); }
291 void IncBy(int d
) { IncBy(d
, d
); }
293 void DecBy(int dx
, int dy
) { IncBy(-dx
, -dy
); }
294 void DecBy(const wxPoint
& pt
);
295 void DecBy(const wxSize
& sz
) { DecBy(sz
.x
, sz
.y
); }
296 void DecBy(int d
) { DecBy(d
, d
); }
299 wxSize
& Scale(float xscale
, float yscale
)
300 { x
= (int)(x
*xscale
); y
= (int)(y
*yscale
); return *this; }
303 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
304 void SetWidth(int w
) { x
= w
; }
305 void SetHeight(int h
) { y
= h
; }
307 int GetWidth() const { return x
; }
308 int GetHeight() const { return y
; }
310 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
312 // combine this size with the other one replacing the default (i.e. equal
313 // to wxDefaultCoord) components of this object with those of the other
314 void SetDefaults(const wxSize
& size
)
316 if ( x
== wxDefaultCoord
)
318 if ( y
== wxDefaultCoord
)
323 int GetX() const { return x
; }
324 int GetY() const { return y
; }
327 inline bool operator==(const wxSize
& s1
, const wxSize
& s2
)
329 return s1
.x
== s2
.x
&& s1
.y
== s2
.y
;
332 inline bool operator!=(const wxSize
& s1
, const wxSize
& s2
)
334 return s1
.x
!= s2
.x
|| s1
.y
!= s2
.y
;
337 inline wxSize
operator+(const wxSize
& s1
, const wxSize
& s2
)
339 return wxSize(s1
.x
+ s2
.x
, s1
.y
+ s2
.y
);
342 inline wxSize
operator-(const wxSize
& s1
, const wxSize
& s2
)
344 return wxSize(s1
.x
- s2
.x
, s1
.y
- s2
.y
);
347 inline wxSize
operator/(const wxSize
& s
, int i
)
349 return wxSize(s
.x
/ i
, s
.y
/ i
);
352 inline wxSize
operator*(const wxSize
& s
, int i
)
354 return wxSize(s
.x
* i
, s
.y
* i
);
357 inline wxSize
operator*(int i
, const wxSize
& s
)
359 return wxSize(s
.x
* i
, s
.y
* i
);
362 inline wxSize
operator/(const wxSize
& s
, unsigned int i
)
364 return wxSize(s
.x
/ i
, s
.y
/ i
);
367 inline wxSize
operator*(const wxSize
& s
, unsigned int i
)
369 return wxSize(s
.x
* i
, s
.y
* i
);
372 inline wxSize
operator*(unsigned int i
, const wxSize
& s
)
374 return wxSize(s
.x
* i
, s
.y
* i
);
377 inline wxSize
operator/(const wxSize
& s
, long i
)
379 return wxSize(s
.x
/ i
, s
.y
/ i
);
382 inline wxSize
operator*(const wxSize
& s
, long i
)
384 return wxSize(s
.x
* i
, s
.y
* i
);
387 inline wxSize
operator*(long i
, const wxSize
& s
)
389 return wxSize(s
.x
* i
, s
.y
* i
);
392 inline wxSize
operator/(const wxSize
& s
, unsigned long i
)
394 return wxSize(s
.x
/ i
, s
.y
/ i
);
397 inline wxSize
operator*(const wxSize
& s
, unsigned long i
)
399 return wxSize(s
.x
* i
, s
.y
* i
);
402 inline wxSize
operator*(unsigned long i
, const wxSize
& s
)
404 return wxSize(s
.x
* i
, s
.y
* i
);
407 inline wxSize
operator*(const wxSize
& s
, double i
)
409 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
412 inline wxSize
operator*(double i
, const wxSize
& s
)
414 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
419 // ---------------------------------------------------------------------------
420 // Point classes: with real or integer coordinates
421 // ---------------------------------------------------------------------------
423 class WXDLLIMPEXP_CORE wxRealPoint
429 wxRealPoint() : x(0.0), y(0.0) { }
430 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
431 wxRealPoint(const wxPoint
& pt
);
433 // no copy ctor or assignment operator - the defaults are ok
435 //assignment operators
436 wxRealPoint
& operator+=(const wxRealPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
437 wxRealPoint
& operator-=(const wxRealPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
439 wxRealPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
440 wxRealPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
444 inline bool operator==(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
446 return wxIsSameDouble(p1
.x
, p2
.x
) && wxIsSameDouble(p1
.y
, p2
.y
);
449 inline bool operator!=(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
454 inline wxRealPoint
operator+(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
456 return wxRealPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
460 inline wxRealPoint
operator-(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
462 return wxRealPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
466 inline wxRealPoint
operator/(const wxRealPoint
& s
, int i
)
468 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
471 inline wxRealPoint
operator*(const wxRealPoint
& s
, int i
)
473 return wxRealPoint(s
.x
* i
, s
.y
* i
);
476 inline wxRealPoint
operator*(int i
, const wxRealPoint
& s
)
478 return wxRealPoint(s
.x
* i
, s
.y
* i
);
481 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned int i
)
483 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
486 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned int i
)
488 return wxRealPoint(s
.x
* i
, s
.y
* i
);
491 inline wxRealPoint
operator*(unsigned int i
, const wxRealPoint
& s
)
493 return wxRealPoint(s
.x
* i
, s
.y
* i
);
496 inline wxRealPoint
operator/(const wxRealPoint
& s
, long i
)
498 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
501 inline wxRealPoint
operator*(const wxRealPoint
& s
, long i
)
503 return wxRealPoint(s
.x
* i
, s
.y
* i
);
506 inline wxRealPoint
operator*(long i
, const wxRealPoint
& s
)
508 return wxRealPoint(s
.x
* i
, s
.y
* i
);
511 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned long i
)
513 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
516 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned long i
)
518 return wxRealPoint(s
.x
* i
, s
.y
* i
);
521 inline wxRealPoint
operator*(unsigned long i
, const wxRealPoint
& s
)
523 return wxRealPoint(s
.x
* i
, s
.y
* i
);
526 inline wxRealPoint
operator*(const wxRealPoint
& s
, double i
)
528 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
531 inline wxRealPoint
operator*(double i
, const wxRealPoint
& s
)
533 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
537 // ----------------------------------------------------------------------------
538 // wxPoint: 2D point with integer coordinates
539 // ----------------------------------------------------------------------------
541 class WXDLLIMPEXP_CORE wxPoint
546 wxPoint() : x(0), y(0) { }
547 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
548 wxPoint(const wxRealPoint
& pt
) : x(int(pt
.x
)), y(int(pt
.y
)) { }
550 // no copy ctor or assignment operator - the defaults are ok
552 //assignment operators
553 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
554 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
556 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
557 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
559 // check if both components are set/initialized
560 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
562 // fill in the unset components with the values from the other point
563 void SetDefaults(const wxPoint
& pt
)
565 if ( x
== wxDefaultCoord
)
567 if ( y
== wxDefaultCoord
)
574 inline bool operator==(const wxPoint
& p1
, const wxPoint
& p2
)
576 return p1
.x
== p2
.x
&& p1
.y
== p2
.y
;
579 inline bool operator!=(const wxPoint
& p1
, const wxPoint
& p2
)
585 // arithmetic operations (component wise)
586 inline wxPoint
operator+(const wxPoint
& p1
, const wxPoint
& p2
)
588 return wxPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
591 inline wxPoint
operator-(const wxPoint
& p1
, const wxPoint
& p2
)
593 return wxPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
596 inline wxPoint
operator+(const wxPoint
& p
, const wxSize
& s
)
598 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
601 inline wxPoint
operator-(const wxPoint
& p
, const wxSize
& s
)
603 return wxPoint(p
.x
- s
.x
, p
.y
- s
.y
);
606 inline wxPoint
operator+(const wxSize
& s
, const wxPoint
& p
)
608 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
611 inline wxPoint
operator-(const wxSize
& s
, const wxPoint
& p
)
613 return wxPoint(s
.x
- p
.x
, s
.y
- p
.y
);
616 inline wxPoint
operator-(const wxPoint
& p
)
618 return wxPoint(-p
.x
, -p
.y
);
621 inline wxPoint
operator/(const wxPoint
& s
, int i
)
623 return wxPoint(s
.x
/ i
, s
.y
/ i
);
626 inline wxPoint
operator*(const wxPoint
& s
, int i
)
628 return wxPoint(s
.x
* i
, s
.y
* i
);
631 inline wxPoint
operator*(int i
, const wxPoint
& s
)
633 return wxPoint(s
.x
* i
, s
.y
* i
);
636 inline wxPoint
operator/(const wxPoint
& s
, unsigned int i
)
638 return wxPoint(s
.x
/ i
, s
.y
/ i
);
641 inline wxPoint
operator*(const wxPoint
& s
, unsigned int i
)
643 return wxPoint(s
.x
* i
, s
.y
* i
);
646 inline wxPoint
operator*(unsigned int i
, const wxPoint
& s
)
648 return wxPoint(s
.x
* i
, s
.y
* i
);
651 inline wxPoint
operator/(const wxPoint
& s
, long i
)
653 return wxPoint(s
.x
/ i
, s
.y
/ i
);
656 inline wxPoint
operator*(const wxPoint
& s
, long i
)
658 return wxPoint(s
.x
* i
, s
.y
* i
);
661 inline wxPoint
operator*(long i
, const wxPoint
& s
)
663 return wxPoint(s
.x
* i
, s
.y
* i
);
666 inline wxPoint
operator/(const wxPoint
& s
, unsigned long i
)
668 return wxPoint(s
.x
/ i
, s
.y
/ i
);
671 inline wxPoint
operator*(const wxPoint
& s
, unsigned long i
)
673 return wxPoint(s
.x
* i
, s
.y
* i
);
676 inline wxPoint
operator*(unsigned long i
, const wxPoint
& s
)
678 return wxPoint(s
.x
* i
, s
.y
* i
);
681 inline wxPoint
operator*(const wxPoint
& s
, double i
)
683 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
686 inline wxPoint
operator*(double i
, const wxPoint
& s
)
688 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
691 WX_DECLARE_LIST_WITH_DECL(wxPoint
, wxPointList
, class WXDLLIMPEXP_CORE
);
693 // ---------------------------------------------------------------------------
695 // ---------------------------------------------------------------------------
697 class WXDLLIMPEXP_CORE wxRect
701 : x(0), y(0), width(0), height(0)
703 wxRect(int xx
, int yy
, int ww
, int hh
)
704 : x(xx
), y(yy
), width(ww
), height(hh
)
706 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
707 wxRect(const wxPoint
& pt
, const wxSize
& size
)
708 : x(pt
.x
), y(pt
.y
), width(size
.x
), height(size
.y
)
710 wxRect(const wxSize
& size
)
711 : x(0), y(0), width(size
.x
), height(size
.y
)
714 // default copy ctor and assignment operators ok
716 int GetX() const { return x
; }
717 void SetX(int xx
) { x
= xx
; }
719 int GetY() const { return y
; }
720 void SetY(int yy
) { y
= yy
; }
722 int GetWidth() const { return width
; }
723 void SetWidth(int w
) { width
= w
; }
725 int GetHeight() const { return height
; }
726 void SetHeight(int h
) { height
= h
; }
728 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
729 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
731 wxSize
GetSize() const { return wxSize(width
, height
); }
732 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
734 bool IsEmpty() const { return (width
<= 0) || (height
<= 0); }
736 int GetLeft() const { return x
; }
737 int GetTop() const { return y
; }
738 int GetBottom() const { return y
+ height
- 1; }
739 int GetRight() const { return x
+ width
- 1; }
741 void SetLeft(int left
) { x
= left
; }
742 void SetRight(int right
) { width
= right
- x
+ 1; }
743 void SetTop(int top
) { y
= top
; }
744 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
746 wxPoint
GetTopLeft() const { return GetPosition(); }
747 wxPoint
GetLeftTop() const { return GetTopLeft(); }
748 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
749 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
751 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
752 wxPoint
GetRightBottom() const { return GetBottomRight(); }
753 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
754 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
756 wxPoint
GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
757 wxPoint
GetRightTop() const { return GetTopRight(); }
758 void SetTopRight(const wxPoint
&p
) { SetRight(p
.x
); SetTop(p
.y
); }
759 void SetRightTop(const wxPoint
&p
) { SetTopRight(p
); }
761 wxPoint
GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
762 wxPoint
GetLeftBottom() const { return GetBottomLeft(); }
763 void SetBottomLeft(const wxPoint
&p
) { SetLeft(p
.x
); SetBottom(p
.y
); }
764 void SetLeftBottom(const wxPoint
&p
) { SetBottomLeft(p
); }
766 // operations with rect
767 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
768 wxRect
& Inflate(const wxSize
& d
) { return Inflate(d
.x
, d
.y
); }
769 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
770 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
777 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
778 wxRect
& Deflate(const wxSize
& d
) { return Inflate(-d
.x
, -d
.y
); }
779 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
780 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
787 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
788 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
790 wxRect
& Intersect(const wxRect
& rect
);
791 wxRect
Intersect(const wxRect
& rect
) const
798 wxRect
& Union(const wxRect
& rect
);
799 wxRect
Union(const wxRect
& rect
) const
806 // return true if the point is (not strcitly) inside the rect
807 bool Contains(int x
, int y
) const;
808 bool Contains(const wxPoint
& pt
) const { return Contains(pt
.x
, pt
.y
); }
809 // return true if the rectangle 'rect' is (not strictly) inside this rect
810 bool Contains(const wxRect
& rect
) const;
812 #if WXWIN_COMPATIBILITY_2_6
813 // use Contains() instead
814 wxDEPRECATED( bool Inside(int x
, int y
) const );
815 wxDEPRECATED( bool Inside(const wxPoint
& pt
) const );
816 wxDEPRECATED( bool Inside(const wxRect
& rect
) const );
817 #endif // WXWIN_COMPATIBILITY_2_6
819 // return true if the rectangles have a non empty intersection
820 bool Intersects(const wxRect
& rect
) const;
822 // like Union() but don't ignore empty rectangles
823 wxRect
& operator+=(const wxRect
& rect
);
825 // intersections of two rectrangles not testing for empty rectangles
826 wxRect
& operator*=(const wxRect
& rect
);
828 // centre this rectangle in the given (usually, but not necessarily,
830 wxRect
CentreIn(const wxRect
& r
, int dir
= wxBOTH
) const
832 return wxRect(dir
& wxHORIZONTAL
? r
.x
+ (r
.width
- width
)/2 : x
,
833 dir
& wxVERTICAL
? r
.y
+ (r
.height
- height
)/2 : y
,
837 wxRect
CenterIn(const wxRect
& r
, int dir
= wxBOTH
) const
839 return CentreIn(r
, dir
);
843 int x
, y
, width
, height
;
847 // compare rectangles
848 inline bool operator==(const wxRect
& r1
, const wxRect
& r2
)
850 return (r1
.x
== r2
.x
) && (r1
.y
== r2
.y
) &&
851 (r1
.width
== r2
.width
) && (r1
.height
== r2
.height
);
854 inline bool operator!=(const wxRect
& r1
, const wxRect
& r2
)
859 // like Union() but don't treat empty rectangles specially
860 WXDLLIMPEXP_CORE wxRect
operator+(const wxRect
& r1
, const wxRect
& r2
);
862 // intersections of two rectangles
863 WXDLLIMPEXP_CORE wxRect
operator*(const wxRect
& r1
, const wxRect
& r2
);
868 #if WXWIN_COMPATIBILITY_2_6
869 inline bool wxRect::Inside(int cx
, int cy
) const { return Contains(cx
, cy
); }
870 inline bool wxRect::Inside(const wxPoint
& pt
) const { return Contains(pt
); }
871 inline bool wxRect::Inside(const wxRect
& rect
) const { return Contains(rect
); }
872 #endif // WXWIN_COMPATIBILITY_2_6
875 // define functions which couldn't be defined above because of declarations
877 inline void wxSize::IncBy(const wxPoint
& pt
) { IncBy(pt
.x
, pt
.y
); }
878 inline void wxSize::DecBy(const wxPoint
& pt
) { DecBy(pt
.x
, pt
.y
); }
880 // ---------------------------------------------------------------------------
881 // Management of pens, brushes and fonts
882 // ---------------------------------------------------------------------------
884 typedef wxInt8 wxDash
;
886 class WXDLLIMPEXP_CORE wxGDIObjListBase
{
895 WX_DECLARE_STRING_HASH_MAP(wxColour
*, wxStringToColourHashMap
);
897 class WXDLLIMPEXP_CORE wxColourDatabase
903 // find colour by name or name for the given colour
904 wxColour
Find(const wxString
& name
) const;
905 wxString
FindName(const wxColour
& colour
) const;
907 // add a new colour to the database
908 void AddColour(const wxString
& name
, const wxColour
& colour
);
910 #if WXWIN_COMPATIBILITY_2_6
911 // deprecated, use Find() instead
912 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
913 #endif // WXWIN_COMPATIBILITY_2_6
917 // PM keeps its own type of colour table
923 // load the database with the built in colour values when called for the
924 // first time, do nothing after this
927 wxStringToColourHashMap
*m_map
;
930 class WXDLLIMPEXP_CORE wxResourceCache
: public wxList
933 wxResourceCache() { }
934 #if !wxUSE_STD_CONTAINERS
935 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
937 virtual ~wxResourceCache();
940 // ---------------------------------------------------------------------------
942 // ---------------------------------------------------------------------------
947 wxStockGDI creates the stock GDI objects on demand. Pointers to the
948 created objects are stored in the ms_stockObject array, which is indexed
949 by the Item enum values. Platorm-specific fonts can be created by
950 implementing a derived class with an override for the GetFont function.
951 wxStockGDI operates as a singleton, accessed through the ms_instance
952 pointer. By default this pointer is set to an instance of wxStockGDI.
953 A derived class must arrange to set this pointer to an instance of itself.
955 class WXDLLIMPEXP_CORE wxStockGDI
1001 virtual ~wxStockGDI();
1002 static void DeleteAll();
1004 static wxStockGDI
& instance() { return *ms_instance
; }
1006 static const wxBrush
* GetBrush(Item item
);
1007 static const wxColour
* GetColour(Item item
);
1008 static const wxCursor
* GetCursor(Item item
);
1009 // Can be overridden by platform-specific derived classes
1010 virtual const wxFont
* GetFont(Item item
);
1011 static const wxPen
* GetPen(Item item
);
1014 static wxStockGDI
* ms_instance
;
1016 static wxObject
* ms_stockObject
[ITEMCOUNT
];
1018 wxDECLARE_NO_COPY_CLASS(wxStockGDI
);
1021 #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
1022 #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
1023 #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
1024 #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
1026 #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
1027 #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
1028 #define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE)
1029 #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
1030 #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
1031 #define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW)
1032 #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
1033 #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
1034 #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
1035 #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
1036 #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
1037 #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
1039 #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
1040 #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
1041 #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
1042 #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
1043 #define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW)
1044 #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
1045 #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
1046 #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
1047 #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
1048 #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
1049 #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
1051 #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
1052 #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
1053 #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
1054 #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
1055 #define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW)
1056 #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
1057 #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
1058 #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
1060 #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
1061 #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
1062 #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
1065 extern WXDLLIMPEXP_DATA_CORE(wxBitmap
) wxNullBitmap
;
1066 extern WXDLLIMPEXP_DATA_CORE(wxIcon
) wxNullIcon
;
1067 extern WXDLLIMPEXP_DATA_CORE(wxCursor
) wxNullCursor
;
1068 extern WXDLLIMPEXP_DATA_CORE(wxPen
) wxNullPen
;
1069 extern WXDLLIMPEXP_DATA_CORE(wxBrush
) wxNullBrush
;
1070 extern WXDLLIMPEXP_DATA_CORE(wxPalette
) wxNullPalette
;
1071 extern WXDLLIMPEXP_DATA_CORE(wxFont
) wxNullFont
;
1072 extern WXDLLIMPEXP_DATA_CORE(wxColour
) wxNullColour
;
1073 extern WXDLLIMPEXP_DATA_CORE(wxIconBundle
) wxNullIconBundle
;
1075 extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase
*) wxTheColourDatabase
;
1077 extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr
[];
1079 extern WXDLLIMPEXP_DATA_CORE(const wxSize
) wxDefaultSize
;
1080 extern WXDLLIMPEXP_DATA_CORE(const wxPoint
) wxDefaultPosition
;
1082 // ---------------------------------------------------------------------------
1084 // ---------------------------------------------------------------------------
1086 // resource management
1087 extern void WXDLLIMPEXP_CORE
wxInitializeStockLists();
1088 extern void WXDLLIMPEXP_CORE
wxDeleteStockLists();
1090 // is the display colour (or monochrome)?
1091 extern bool WXDLLIMPEXP_CORE
wxColourDisplay();
1093 // Returns depth of screen
1094 extern int WXDLLIMPEXP_CORE
wxDisplayDepth();
1095 #define wxGetDisplayDepth wxDisplayDepth
1097 // get the display size
1098 extern void WXDLLIMPEXP_CORE
wxDisplaySize(int *width
, int *height
);
1099 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySize();
1100 extern void WXDLLIMPEXP_CORE
wxDisplaySizeMM(int *width
, int *height
);
1101 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySizeMM();
1102 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplayPPI();
1104 // Get position and size of the display workarea
1105 extern void WXDLLIMPEXP_CORE
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
1106 extern wxRect WXDLLIMPEXP_CORE
wxGetClientDisplayRect();
1108 // set global cursor
1109 extern void WXDLLIMPEXP_CORE
wxSetCursor(const wxCursor
& cursor
);