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 /* Useful macro for creating icons portably, for example:
165 wxIcon *icon = new wxICON(sample);
169 wxIcon *icon = new wxIcon("sample"); // On wxMSW
170 wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK
174 // Load from a resource
175 #define wxICON(X) wxIcon(wxT(#X))
176 #elif defined(__WXPM__)
177 // Load from a resource
178 #define wxICON(X) wxIcon(wxT(#X))
179 #elif defined(__WXMGL__)
180 // Initialize from an included XPM
181 #define wxICON(X) wxIcon( X##_xpm )
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(__WXMSW__) || 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(__WXMGL__) || \
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 // ===========================================================================
223 // ===========================================================================
225 // ---------------------------------------------------------------------------
227 // ---------------------------------------------------------------------------
229 class WXDLLIMPEXP_CORE wxSize
232 // members are public for compatibility, don't use them directly.
236 wxSize() : x(0), y(0) { }
237 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
239 // no copy ctor or assignment operator - the defaults are ok
241 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
242 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
243 wxSize
& operator/=(int i
) { x
/= i
; y
/= i
; return *this; }
244 wxSize
& operator*=(int i
) { x
*= i
; y
*= i
; return *this; }
245 wxSize
& operator/=(unsigned int i
) { x
/= i
; y
/= i
; return *this; }
246 wxSize
& operator*=(unsigned int i
) { x
*= i
; y
*= i
; return *this; }
247 wxSize
& operator/=(long i
) { x
/= i
; y
/= i
; return *this; }
248 wxSize
& operator*=(long i
) { x
*= i
; y
*= i
; return *this; }
249 wxSize
& operator/=(unsigned long i
) { x
/= i
; y
/= i
; return *this; }
250 wxSize
& operator*=(unsigned long i
) { x
*= i
; y
*= i
; return *this; }
251 wxSize
& operator/=(double i
) { x
= int(x
/i
); y
= int(y
/i
); return *this; }
252 wxSize
& operator*=(double i
) { x
= int(x
*i
); y
= int(y
*i
); return *this; }
254 void IncTo(const wxSize
& sz
)
255 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
256 void DecTo(const wxSize
& sz
)
257 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
259 void IncBy(int dx
, int dy
) { x
+= dx
; y
+= dy
; }
260 void IncBy(const wxPoint
& pt
);
261 void IncBy(const wxSize
& sz
) { IncBy(sz
.x
, sz
.y
); }
262 void IncBy(int d
) { IncBy(d
, d
); }
264 void DecBy(int dx
, int dy
) { IncBy(-dx
, -dy
); }
265 void DecBy(const wxPoint
& pt
);
266 void DecBy(const wxSize
& sz
) { DecBy(sz
.x
, sz
.y
); }
267 void DecBy(int d
) { DecBy(d
, d
); }
270 wxSize
& Scale(float xscale
, float yscale
)
271 { x
= (int)(x
*xscale
); y
= (int)(y
*yscale
); return *this; }
274 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
275 void SetWidth(int w
) { x
= w
; }
276 void SetHeight(int h
) { y
= h
; }
278 int GetWidth() const { return x
; }
279 int GetHeight() const { return y
; }
281 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
283 // combine this size with the other one replacing the default (i.e. equal
284 // to wxDefaultCoord) components of this object with those of the other
285 void SetDefaults(const wxSize
& size
)
287 if ( x
== wxDefaultCoord
)
289 if ( y
== wxDefaultCoord
)
294 int GetX() const { return x
; }
295 int GetY() const { return y
; }
298 inline bool operator==(const wxSize
& s1
, const wxSize
& s2
)
300 return s1
.x
== s2
.x
&& s1
.y
== s2
.y
;
303 inline bool operator!=(const wxSize
& s1
, const wxSize
& s2
)
305 return s1
.x
!= s2
.x
|| s1
.y
!= s2
.y
;
308 inline wxSize
operator+(const wxSize
& s1
, const wxSize
& s2
)
310 return wxSize(s1
.x
+ s2
.x
, s1
.y
+ s2
.y
);
313 inline wxSize
operator-(const wxSize
& s1
, const wxSize
& s2
)
315 return wxSize(s1
.x
- s2
.x
, s1
.y
- s2
.y
);
318 inline wxSize
operator/(const wxSize
& s
, int i
)
320 return wxSize(s
.x
/ i
, s
.y
/ i
);
323 inline wxSize
operator*(const wxSize
& s
, int i
)
325 return wxSize(s
.x
* i
, s
.y
* i
);
328 inline wxSize
operator*(int i
, const wxSize
& s
)
330 return wxSize(s
.x
* i
, s
.y
* i
);
333 inline wxSize
operator/(const wxSize
& s
, unsigned int i
)
335 return wxSize(s
.x
/ i
, s
.y
/ i
);
338 inline wxSize
operator*(const wxSize
& s
, unsigned int i
)
340 return wxSize(s
.x
* i
, s
.y
* i
);
343 inline wxSize
operator*(unsigned int i
, const wxSize
& s
)
345 return wxSize(s
.x
* i
, s
.y
* i
);
348 inline wxSize
operator/(const wxSize
& s
, long i
)
350 return wxSize(s
.x
/ i
, s
.y
/ i
);
353 inline wxSize
operator*(const wxSize
& s
, long i
)
355 return wxSize(s
.x
* i
, s
.y
* i
);
358 inline wxSize
operator*(long i
, const wxSize
& s
)
360 return wxSize(s
.x
* i
, s
.y
* i
);
363 inline wxSize
operator/(const wxSize
& s
, unsigned long i
)
365 return wxSize(s
.x
/ i
, s
.y
/ i
);
368 inline wxSize
operator*(const wxSize
& s
, unsigned long i
)
370 return wxSize(s
.x
* i
, s
.y
* i
);
373 inline wxSize
operator*(unsigned long i
, const wxSize
& s
)
375 return wxSize(s
.x
* i
, s
.y
* i
);
378 inline wxSize
operator*(const wxSize
& s
, double i
)
380 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
383 inline wxSize
operator*(double i
, const wxSize
& s
)
385 return wxSize(int(s
.x
* i
), int(s
.y
* i
));
390 // ---------------------------------------------------------------------------
391 // Point classes: with real or integer coordinates
392 // ---------------------------------------------------------------------------
394 class WXDLLIMPEXP_CORE wxRealPoint
400 wxRealPoint() : x(0.0), y(0.0) { }
401 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
402 wxRealPoint(const wxPoint
& pt
);
404 // no copy ctor or assignment operator - the defaults are ok
406 //assignment operators
407 wxRealPoint
& operator+=(const wxRealPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
408 wxRealPoint
& operator-=(const wxRealPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
410 wxRealPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
411 wxRealPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
415 inline bool operator==(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
417 return wxIsSameDouble(p1
.x
, p2
.x
) && wxIsSameDouble(p1
.y
, p2
.y
);
420 inline bool operator!=(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
425 inline wxRealPoint
operator+(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
427 return wxRealPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
431 inline wxRealPoint
operator-(const wxRealPoint
& p1
, const wxRealPoint
& p2
)
433 return wxRealPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
437 inline wxRealPoint
operator/(const wxRealPoint
& s
, int i
)
439 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
442 inline wxRealPoint
operator*(const wxRealPoint
& s
, int i
)
444 return wxRealPoint(s
.x
* i
, s
.y
* i
);
447 inline wxRealPoint
operator*(int i
, const wxRealPoint
& s
)
449 return wxRealPoint(s
.x
* i
, s
.y
* i
);
452 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned int i
)
454 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
457 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned int i
)
459 return wxRealPoint(s
.x
* i
, s
.y
* i
);
462 inline wxRealPoint
operator*(unsigned int i
, const wxRealPoint
& s
)
464 return wxRealPoint(s
.x
* i
, s
.y
* i
);
467 inline wxRealPoint
operator/(const wxRealPoint
& s
, long i
)
469 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
472 inline wxRealPoint
operator*(const wxRealPoint
& s
, long i
)
474 return wxRealPoint(s
.x
* i
, s
.y
* i
);
477 inline wxRealPoint
operator*(long i
, const wxRealPoint
& s
)
479 return wxRealPoint(s
.x
* i
, s
.y
* i
);
482 inline wxRealPoint
operator/(const wxRealPoint
& s
, unsigned long i
)
484 return wxRealPoint(s
.x
/ i
, s
.y
/ i
);
487 inline wxRealPoint
operator*(const wxRealPoint
& s
, unsigned long i
)
489 return wxRealPoint(s
.x
* i
, s
.y
* i
);
492 inline wxRealPoint
operator*(unsigned long i
, const wxRealPoint
& s
)
494 return wxRealPoint(s
.x
* i
, s
.y
* i
);
497 inline wxRealPoint
operator*(const wxRealPoint
& s
, double i
)
499 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
502 inline wxRealPoint
operator*(double i
, const wxRealPoint
& s
)
504 return wxRealPoint(int(s
.x
* i
), int(s
.y
* i
));
508 // ----------------------------------------------------------------------------
509 // wxPoint: 2D point with integer coordinates
510 // ----------------------------------------------------------------------------
512 class WXDLLIMPEXP_CORE wxPoint
517 wxPoint() : x(0), y(0) { }
518 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
519 wxPoint(const wxRealPoint
& pt
) : x(int(pt
.x
)), y(int(pt
.y
)) { }
521 // no copy ctor or assignment operator - the defaults are ok
523 //assignment operators
524 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
525 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
527 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
528 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
530 // check if both components are set/initialized
531 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
533 // fill in the unset components with the values from the other point
534 void SetDefaults(const wxPoint
& pt
)
536 if ( x
== wxDefaultCoord
)
538 if ( y
== wxDefaultCoord
)
545 inline bool operator==(const wxPoint
& p1
, const wxPoint
& p2
)
547 return p1
.x
== p2
.x
&& p1
.y
== p2
.y
;
550 inline bool operator!=(const wxPoint
& p1
, const wxPoint
& p2
)
556 // arithmetic operations (component wise)
557 inline wxPoint
operator+(const wxPoint
& p1
, const wxPoint
& p2
)
559 return wxPoint(p1
.x
+ p2
.x
, p1
.y
+ p2
.y
);
562 inline wxPoint
operator-(const wxPoint
& p1
, const wxPoint
& p2
)
564 return wxPoint(p1
.x
- p2
.x
, p1
.y
- p2
.y
);
567 inline wxPoint
operator+(const wxPoint
& p
, const wxSize
& s
)
569 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
572 inline wxPoint
operator-(const wxPoint
& p
, const wxSize
& s
)
574 return wxPoint(p
.x
- s
.x
, p
.y
- s
.y
);
577 inline wxPoint
operator+(const wxSize
& s
, const wxPoint
& p
)
579 return wxPoint(p
.x
+ s
.x
, p
.y
+ s
.y
);
582 inline wxPoint
operator-(const wxSize
& s
, const wxPoint
& p
)
584 return wxPoint(s
.x
- p
.x
, s
.y
- p
.y
);
587 inline wxPoint
operator-(const wxPoint
& p
)
589 return wxPoint(-p
.x
, -p
.y
);
592 inline wxPoint
operator/(const wxPoint
& s
, int i
)
594 return wxPoint(s
.x
/ i
, s
.y
/ i
);
597 inline wxPoint
operator*(const wxPoint
& s
, int i
)
599 return wxPoint(s
.x
* i
, s
.y
* i
);
602 inline wxPoint
operator*(int i
, const wxPoint
& s
)
604 return wxPoint(s
.x
* i
, s
.y
* i
);
607 inline wxPoint
operator/(const wxPoint
& s
, unsigned int i
)
609 return wxPoint(s
.x
/ i
, s
.y
/ i
);
612 inline wxPoint
operator*(const wxPoint
& s
, unsigned int i
)
614 return wxPoint(s
.x
* i
, s
.y
* i
);
617 inline wxPoint
operator*(unsigned int i
, const wxPoint
& s
)
619 return wxPoint(s
.x
* i
, s
.y
* i
);
622 inline wxPoint
operator/(const wxPoint
& s
, long i
)
624 return wxPoint(s
.x
/ i
, s
.y
/ i
);
627 inline wxPoint
operator*(const wxPoint
& s
, long i
)
629 return wxPoint(s
.x
* i
, s
.y
* i
);
632 inline wxPoint
operator*(long i
, const wxPoint
& s
)
634 return wxPoint(s
.x
* i
, s
.y
* i
);
637 inline wxPoint
operator/(const wxPoint
& s
, unsigned long i
)
639 return wxPoint(s
.x
/ i
, s
.y
/ i
);
642 inline wxPoint
operator*(const wxPoint
& s
, unsigned long i
)
644 return wxPoint(s
.x
* i
, s
.y
* i
);
647 inline wxPoint
operator*(unsigned long i
, const wxPoint
& s
)
649 return wxPoint(s
.x
* i
, s
.y
* i
);
652 inline wxPoint
operator*(const wxPoint
& s
, double i
)
654 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
657 inline wxPoint
operator*(double i
, const wxPoint
& s
)
659 return wxPoint(int(s
.x
* i
), int(s
.y
* i
));
662 WX_DECLARE_LIST_WITH_DECL(wxPoint
, wxPointList
, class WXDLLIMPEXP_CORE
);
664 // ---------------------------------------------------------------------------
666 // ---------------------------------------------------------------------------
668 class WXDLLIMPEXP_CORE wxRect
672 : x(0), y(0), width(0), height(0)
674 wxRect(int xx
, int yy
, int ww
, int hh
)
675 : x(xx
), y(yy
), width(ww
), height(hh
)
677 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
678 wxRect(const wxPoint
& pt
, const wxSize
& size
)
679 : x(pt
.x
), y(pt
.y
), width(size
.x
), height(size
.y
)
681 wxRect(const wxSize
& size
)
682 : x(0), y(0), width(size
.x
), height(size
.y
)
685 // default copy ctor and assignment operators ok
687 int GetX() const { return x
; }
688 void SetX(int xx
) { x
= xx
; }
690 int GetY() const { return y
; }
691 void SetY(int yy
) { y
= yy
; }
693 int GetWidth() const { return width
; }
694 void SetWidth(int w
) { width
= w
; }
696 int GetHeight() const { return height
; }
697 void SetHeight(int h
) { height
= h
; }
699 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
700 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
702 wxSize
GetSize() const { return wxSize(width
, height
); }
703 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
705 bool IsEmpty() const { return (width
<= 0) || (height
<= 0); }
707 int GetLeft() const { return x
; }
708 int GetTop() const { return y
; }
709 int GetBottom() const { return y
+ height
- 1; }
710 int GetRight() const { return x
+ width
- 1; }
712 void SetLeft(int left
) { x
= left
; }
713 void SetRight(int right
) { width
= right
- x
+ 1; }
714 void SetTop(int top
) { y
= top
; }
715 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
717 wxPoint
GetTopLeft() const { return GetPosition(); }
718 wxPoint
GetLeftTop() const { return GetTopLeft(); }
719 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
720 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
722 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
723 wxPoint
GetRightBottom() const { return GetBottomRight(); }
724 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
725 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
727 wxPoint
GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
728 wxPoint
GetRightTop() const { return GetTopRight(); }
729 void SetTopRight(const wxPoint
&p
) { SetRight(p
.x
); SetTop(p
.y
); }
730 void SetRightTop(const wxPoint
&p
) { SetTopRight(p
); }
732 wxPoint
GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
733 wxPoint
GetLeftBottom() const { return GetBottomLeft(); }
734 void SetBottomLeft(const wxPoint
&p
) { SetLeft(p
.x
); SetBottom(p
.y
); }
735 void SetLeftBottom(const wxPoint
&p
) { SetBottomLeft(p
); }
737 // operations with rect
738 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
739 wxRect
& Inflate(const wxSize
& d
) { return Inflate(d
.x
, d
.y
); }
740 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
741 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
748 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
749 wxRect
& Deflate(const wxSize
& d
) { return Inflate(-d
.x
, -d
.y
); }
750 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
751 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
758 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
759 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
761 wxRect
& Intersect(const wxRect
& rect
);
762 wxRect
Intersect(const wxRect
& rect
) const
769 wxRect
& Union(const wxRect
& rect
);
770 wxRect
Union(const wxRect
& rect
) const
777 // return true if the point is (not strcitly) inside the rect
778 bool Contains(int x
, int y
) const;
779 bool Contains(const wxPoint
& pt
) const { return Contains(pt
.x
, pt
.y
); }
780 // return true if the rectangle 'rect' is (not strictly) inside this rect
781 bool Contains(const wxRect
& rect
) const;
783 #if WXWIN_COMPATIBILITY_2_6
784 // use Contains() instead
785 wxDEPRECATED( bool Inside(int x
, int y
) const );
786 wxDEPRECATED( bool Inside(const wxPoint
& pt
) const );
787 wxDEPRECATED( bool Inside(const wxRect
& rect
) const );
788 #endif // WXWIN_COMPATIBILITY_2_6
790 // return true if the rectangles have a non empty intersection
791 bool Intersects(const wxRect
& rect
) const;
793 // like Union() but don't ignore empty rectangles
794 wxRect
& operator+=(const wxRect
& rect
);
796 // intersections of two rectrangles not testing for empty rectangles
797 wxRect
& operator*=(const wxRect
& rect
);
799 // centre this rectangle in the given (usually, but not necessarily,
801 wxRect
CentreIn(const wxRect
& r
, int dir
= wxBOTH
) const
803 return wxRect(dir
& wxHORIZONTAL
? r
.x
+ (r
.width
- width
)/2 : x
,
804 dir
& wxVERTICAL
? r
.y
+ (r
.height
- height
)/2 : y
,
808 wxRect
CenterIn(const wxRect
& r
, int dir
= wxBOTH
) const
810 return CentreIn(r
, dir
);
814 int x
, y
, width
, height
;
818 // compare rectangles
819 inline bool operator==(const wxRect
& r1
, const wxRect
& r2
)
821 return (r1
.x
== r2
.x
) && (r1
.y
== r2
.y
) &&
822 (r1
.width
== r2
.width
) && (r1
.height
== r2
.height
);
825 inline bool operator!=(const wxRect
& r1
, const wxRect
& r2
)
830 // like Union() but don't treat empty rectangles specially
831 WXDLLIMPEXP_CORE wxRect
operator+(const wxRect
& r1
, const wxRect
& r2
);
833 // intersections of two rectangles
834 WXDLLIMPEXP_CORE wxRect
operator*(const wxRect
& r1
, const wxRect
& r2
);
839 #if WXWIN_COMPATIBILITY_2_6
840 inline bool wxRect::Inside(int cx
, int cy
) const { return Contains(cx
, cy
); }
841 inline bool wxRect::Inside(const wxPoint
& pt
) const { return Contains(pt
); }
842 inline bool wxRect::Inside(const wxRect
& rect
) const { return Contains(rect
); }
843 #endif // WXWIN_COMPATIBILITY_2_6
846 // define functions which couldn't be defined above because of declarations
848 inline void wxSize::IncBy(const wxPoint
& pt
) { IncBy(pt
.x
, pt
.y
); }
849 inline void wxSize::DecBy(const wxPoint
& pt
) { DecBy(pt
.x
, pt
.y
); }
851 // ---------------------------------------------------------------------------
852 // Management of pens, brushes and fonts
853 // ---------------------------------------------------------------------------
855 typedef wxInt8 wxDash
;
857 class WXDLLIMPEXP_CORE wxGDIObjListBase
{
866 WX_DECLARE_STRING_HASH_MAP(wxColour
*, wxStringToColourHashMap
);
868 class WXDLLIMPEXP_CORE wxColourDatabase
874 // find colour by name or name for the given colour
875 wxColour
Find(const wxString
& name
) const;
876 wxString
FindName(const wxColour
& colour
) const;
878 // add a new colour to the database
879 void AddColour(const wxString
& name
, const wxColour
& colour
);
881 #if WXWIN_COMPATIBILITY_2_6
882 // deprecated, use Find() instead
883 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
884 #endif // WXWIN_COMPATIBILITY_2_6
888 // PM keeps its own type of colour table
894 // load the database with the built in colour values when called for the
895 // first time, do nothing after this
898 wxStringToColourHashMap
*m_map
;
901 class WXDLLIMPEXP_CORE wxResourceCache
: public wxList
904 wxResourceCache() { }
905 #if !wxUSE_STD_CONTAINERS
906 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
908 virtual ~wxResourceCache();
911 // ---------------------------------------------------------------------------
913 // ---------------------------------------------------------------------------
918 wxStockGDI creates the stock GDI objects on demand. Pointers to the
919 created objects are stored in the ms_stockObject array, which is indexed
920 by the Item enum values. Platorm-specific fonts can be created by
921 implementing a derived class with an override for the GetFont function.
922 wxStockGDI operates as a singleton, accessed through the ms_instance
923 pointer. By default this pointer is set to an instance of wxStockGDI.
924 A derived class must arrange to set this pointer to an instance of itself.
926 class WXDLLIMPEXP_CORE wxStockGDI
972 virtual ~wxStockGDI();
973 static void DeleteAll();
975 static wxStockGDI
& instance() { return *ms_instance
; }
977 static const wxBrush
* GetBrush(Item item
);
978 static const wxColour
* GetColour(Item item
);
979 static const wxCursor
* GetCursor(Item item
);
980 // Can be overridden by platform-specific derived classes
981 virtual const wxFont
* GetFont(Item item
);
982 static const wxPen
* GetPen(Item item
);
985 static wxStockGDI
* ms_instance
;
987 static wxObject
* ms_stockObject
[ITEMCOUNT
];
989 wxDECLARE_NO_COPY_CLASS(wxStockGDI
);
992 #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
993 #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
994 #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
995 #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
997 #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
998 #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
999 #define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE)
1000 #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
1001 #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
1002 #define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW)
1003 #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
1004 #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
1005 #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
1006 #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
1007 #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
1008 #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
1010 #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
1011 #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
1012 #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
1013 #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
1014 #define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW)
1015 #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
1016 #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
1017 #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
1018 #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
1019 #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
1020 #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
1022 #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
1023 #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
1024 #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
1025 #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
1026 #define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW)
1027 #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
1028 #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
1029 #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
1031 #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
1032 #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
1033 #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
1036 extern WXDLLIMPEXP_DATA_CORE(wxBitmap
) wxNullBitmap
;
1037 extern WXDLLIMPEXP_DATA_CORE(wxIcon
) wxNullIcon
;
1038 extern WXDLLIMPEXP_DATA_CORE(wxCursor
) wxNullCursor
;
1039 extern WXDLLIMPEXP_DATA_CORE(wxPen
) wxNullPen
;
1040 extern WXDLLIMPEXP_DATA_CORE(wxBrush
) wxNullBrush
;
1041 extern WXDLLIMPEXP_DATA_CORE(wxPalette
) wxNullPalette
;
1042 extern WXDLLIMPEXP_DATA_CORE(wxFont
) wxNullFont
;
1043 extern WXDLLIMPEXP_DATA_CORE(wxColour
) wxNullColour
;
1044 extern WXDLLIMPEXP_DATA_CORE(wxIconBundle
) wxNullIconBundle
;
1046 extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase
*) wxTheColourDatabase
;
1048 extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr
[];
1050 extern WXDLLIMPEXP_DATA_CORE(const wxSize
) wxDefaultSize
;
1051 extern WXDLLIMPEXP_DATA_CORE(const wxPoint
) wxDefaultPosition
;
1053 // ---------------------------------------------------------------------------
1055 // ---------------------------------------------------------------------------
1057 // resource management
1058 extern void WXDLLIMPEXP_CORE
wxInitializeStockLists();
1059 extern void WXDLLIMPEXP_CORE
wxDeleteStockLists();
1061 // is the display colour (or monochrome)?
1062 extern bool WXDLLIMPEXP_CORE
wxColourDisplay();
1064 // Returns depth of screen
1065 extern int WXDLLIMPEXP_CORE
wxDisplayDepth();
1066 #define wxGetDisplayDepth wxDisplayDepth
1068 // get the display size
1069 extern void WXDLLIMPEXP_CORE
wxDisplaySize(int *width
, int *height
);
1070 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySize();
1071 extern void WXDLLIMPEXP_CORE
wxDisplaySizeMM(int *width
, int *height
);
1072 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplaySizeMM();
1073 extern wxSize WXDLLIMPEXP_CORE
wxGetDisplayPPI();
1075 // Get position and size of the display workarea
1076 extern void WXDLLIMPEXP_CORE
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
1077 extern wxRect WXDLLIMPEXP_CORE
wxGetClientDisplayRect();
1079 // set global cursor
1080 extern void WXDLLIMPEXP_CORE
wxSetCursor(const wxCursor
& cursor
);