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_CORE wxBitmap
;
31 class WXDLLIMPEXP_CORE wxBrush
;
32 class WXDLLIMPEXP_CORE wxColour
;
33 class WXDLLIMPEXP_CORE wxCursor
;
34 class WXDLLIMPEXP_CORE wxFont
;
35 class WXDLLIMPEXP_CORE wxIcon
;
36 class WXDLLIMPEXP_CORE wxPalette
;
37 class WXDLLIMPEXP_CORE wxPen
;
38 class WXDLLIMPEXP_CORE wxRegion
;
39 class WXDLLIMPEXP_BASE wxString
;
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
48 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
50 wxBITMAP_TYPE_BMP_RESOURCE
,
51 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
53 wxBITMAP_TYPE_ICO_RESOURCE
,
55 wxBITMAP_TYPE_CUR_RESOURCE
,
57 wxBITMAP_TYPE_XBM_DATA
,
59 wxBITMAP_TYPE_XPM_DATA
,
61 wxBITMAP_TYPE_TIF_RESOURCE
,
63 wxBITMAP_TYPE_GIF_RESOURCE
,
65 wxBITMAP_TYPE_PNG_RESOURCE
,
67 wxBITMAP_TYPE_JPEG_RESOURCE
,
69 wxBITMAP_TYPE_PNM_RESOURCE
,
71 wxBITMAP_TYPE_PCX_RESOURCE
,
73 wxBITMAP_TYPE_PICT_RESOURCE
,
75 wxBITMAP_TYPE_ICON_RESOURCE
,
78 wxBITMAP_TYPE_MACCURSOR
,
79 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
80 wxBITMAP_TYPE_ANY
= 50
86 wxCURSOR_NONE
, // should be 0
96 wxCURSOR_MIDDLE_BUTTON
,
101 wxCURSOR_POINT_RIGHT
,
102 wxCURSOR_QUESTION_ARROW
,
103 wxCURSOR_RIGHT_BUTTON
,
114 wxCURSOR_DEFAULT
, // standard X11 cursor
117 wxCURSOR_COPY_ARROW
, // MacOS Theme Plus arrow
120 // Not yet implemented for Windows
121 wxCURSOR_CROSS_REVERSE
,
122 wxCURSOR_DOUBLE_ARROW
,
123 wxCURSOR_BASED_ARROW_UP
,
124 wxCURSOR_BASED_ARROW_DOWN
,
133 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
136 // ---------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------
140 /* Useful macro for creating icons portably, for example:
142 wxIcon *icon = new wxICON(mondrian);
146 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
147 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
151 // Load from a resource
152 #define wxICON(X) wxIcon(wxT(#X))
153 #elif defined(__WXPM__)
154 // Load from a resource
155 #define wxICON(X) wxIcon(wxT(#X))
156 #elif defined(__WXMGL__)
157 // Initialize from an included XPM
158 #define wxICON(X) wxIcon( (const char**) X##_xpm )
159 #elif defined(__WXGTK__)
160 // Initialize from an included XPM
161 #define wxICON(X) wxIcon( (const char**) X##_xpm )
162 #elif defined(__WXMAC__)
163 // Initialize from an included XPM
164 #define wxICON(X) wxIcon( (const char**) X##_xpm )
165 #elif defined(__WXMOTIF__)
166 // Initialize from an included XPM
167 #define wxICON(X) wxIcon( X##_xpm )
168 #elif defined(__WXX11__)
169 // Initialize from an included XPM
170 #define wxICON(X) wxIcon( X##_xpm )
172 // This will usually mean something on any platform
173 #define wxICON(X) wxIcon(wxT(#X))
176 /* Another macro: this one is for portable creation of bitmaps. We assume that
177 under Unix bitmaps live in XPMs and under Windows they're in ressources.
180 #if defined(__WXMSW__) || defined(__WXPM__)
181 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
182 #elif defined(__WXGTK__) || \
183 defined(__WXMOTIF__) || \
184 defined(__WXX11__) || \
185 defined(__WXMAC__) || \
186 defined(__WXMGL__) || \
188 // Initialize from an included XPM
189 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
190 #else // other platforms
191 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
194 // ===========================================================================
196 // ===========================================================================
198 // ---------------------------------------------------------------------------
200 // ---------------------------------------------------------------------------
202 class WXDLLEXPORT wxSize
205 // members are public for compatibility, don't use them directly.
209 wxSize() : x(0), y(0) { }
210 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
212 // no copy ctor or assignment operator - the defaults are ok
214 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
215 bool operator!=(const wxSize
& sz
) const { return x
!= sz
.x
|| y
!= sz
.y
; }
217 wxSize
operator+(const wxSize
& sz
) const { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
218 wxSize
operator-(const wxSize
& sz
) const { return wxSize(x
- sz
.x
, y
- sz
.y
); }
219 wxSize
operator/(int i
) const { return wxSize(x
/ i
, y
/ i
); }
220 wxSize
operator*(int i
) const { return wxSize(x
* i
, y
* i
); }
222 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
223 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
224 wxSize
& operator/=(const int i
) { x
/= i
; y
/= i
; return *this; }
225 wxSize
& operator*=(const int i
) { x
*= i
; y
*= i
; return *this; }
227 void IncTo(const wxSize
& sz
)
228 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
229 void DecTo(const wxSize
& sz
)
230 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
233 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
234 void SetWidth(int w
) { x
= w
; }
235 void SetHeight(int h
) { y
= h
; }
237 int GetWidth() const { return x
; }
238 int GetHeight() const { return y
; }
240 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
242 // combine this size with the other one replacing the default (i.e. equal
243 // to wxDefaultCoord) components of this object with those of the other
244 void SetDefaults(const wxSize
& size
)
246 if ( x
== wxDefaultCoord
)
248 if ( y
== wxDefaultCoord
)
253 int GetX() const { return x
; }
254 int GetY() const { return y
; }
257 // ---------------------------------------------------------------------------
258 // Point classes: with real or integer coordinates
259 // ---------------------------------------------------------------------------
261 class WXDLLEXPORT wxRealPoint
267 wxRealPoint() : x(0.0), y(0.0) { }
268 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
270 wxRealPoint
operator+(const wxRealPoint
& pt
) const { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
271 wxRealPoint
operator-(const wxRealPoint
& pt
) const { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
273 bool operator==(const wxRealPoint
& pt
) const
275 return wxIsSameDouble(x
, pt
.x
) && wxIsSameDouble(y
, pt
.y
);
277 bool operator!=(const wxRealPoint
& pt
) const { return !(*this == pt
); }
281 class WXDLLEXPORT wxPoint
286 wxPoint() : x(0), y(0) { }
287 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
289 // no copy ctor or assignment operator - the defaults are ok
292 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
293 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
295 // arithmetic operations (component wise)
296 wxPoint
operator+(const wxPoint
& p
) const { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
297 wxPoint
operator-(const wxPoint
& p
) const { return wxPoint(x
- p
.x
, y
- p
.y
); }
299 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
300 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
302 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
303 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
305 wxPoint
operator+(const wxSize
& s
) const { return wxPoint(x
+ s
.GetWidth(), y
+ s
.GetHeight()); }
306 wxPoint
operator-(const wxSize
& s
) const { return wxPoint(x
- s
.GetWidth(), y
- s
.GetHeight()); }
309 // ---------------------------------------------------------------------------
311 // ---------------------------------------------------------------------------
313 class WXDLLEXPORT wxRect
317 : x(0), y(0), width(0), height(0)
319 wxRect(int xx
, int yy
, int ww
, int hh
)
320 : x(xx
), y(yy
), width(ww
), height(hh
)
322 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
323 wxRect(const wxPoint
& pt
, const wxSize
& size
)
324 : x(pt
.x
), y(pt
.y
), width(size
.x
), height(size
.y
)
326 wxRect(const wxSize
& size
)
327 : x(0), y(0), width(size
.x
), height(size
.y
)
330 // default copy ctor and assignment operators ok
332 int GetX() const { return x
; }
333 void SetX(int xx
) { x
= xx
; }
335 int GetY() const { return y
; }
336 void SetY(int yy
) { y
= yy
; }
338 int GetWidth() const { return width
; }
339 void SetWidth(int w
) { width
= w
; }
341 int GetHeight() const { return height
; }
342 void SetHeight(int h
) { height
= h
; }
344 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
345 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
347 wxSize
GetSize() const { return wxSize(width
, height
); }
348 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
350 bool IsEmpty() const { return (width
<= 0) || (height
<= 0); }
352 wxPoint
GetTopLeft() const { return GetPosition(); }
353 wxPoint
GetLeftTop() const { return GetTopLeft(); }
354 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
355 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
357 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
358 wxPoint
GetRightBottom() const { return GetBottomRight(); }
359 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
360 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
362 int GetLeft() const { return x
; }
363 int GetTop() const { return y
; }
364 int GetBottom() const { return y
+ height
- 1; }
365 int GetRight() const { return x
+ width
- 1; }
367 void SetLeft(int left
) { x
= left
; }
368 void SetRight(int right
) { width
= right
- x
+ 1; }
369 void SetTop(int top
) { y
= top
; }
370 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
372 // operations with rect
373 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
374 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
375 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
382 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
383 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
384 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
391 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
392 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
394 wxRect
& Intersect(const wxRect
& rect
);
395 wxRect
Intersect(const wxRect
& rect
) const
402 wxRect
& Union(const wxRect
& rect
);
403 wxRect
Union(const wxRect
& rect
) const
410 // compare rectangles
411 bool operator==(const wxRect
& rect
) const;
412 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
414 // return true if the point is (not strcitly) inside the rect
415 bool Inside(int x
, int y
) const;
416 bool Inside(const wxPoint
& pt
) const { return Inside(pt
.x
, pt
.y
); }
418 // return true if the rectangles have a non empty intersection
419 bool Intersects(const wxRect
& rect
) const;
422 // these are like Union() but don't ignore empty rectangles
423 wxRect
operator+(const wxRect
& rect
) const;
424 wxRect
& operator+=(const wxRect
& rect
)
426 *this = *this + rect
;
431 // centre this rectangle in the given (usually, but not necessarily,
433 wxRect
CentreIn(const wxRect
& r
, int dir
= wxBOTH
) const
435 return wxRect(dir
& wxHORIZONTAL
? r
.x
+ (r
.width
- width
)/2 : x
,
436 dir
& wxVERTICAL
? r
.y
+ (r
.height
- height
)/2 : y
,
440 wxRect
CenterIn(const wxRect
& r
, int dir
= wxBOTH
) const
442 return CentreIn(r
, dir
);
446 int x
, y
, width
, height
;
449 // ---------------------------------------------------------------------------
450 // Management of pens, brushes and fonts
451 // ---------------------------------------------------------------------------
453 typedef wxInt8 wxDash
;
455 class WXDLLEXPORT wxPenList
: public wxList
461 void AddPen(wxPen
*pen
);
462 void RemovePen(wxPen
*pen
);
463 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
466 class WXDLLEXPORT wxBrushList
: public wxList
472 void AddBrush(wxBrush
*brush
);
473 void RemoveBrush(wxBrush
*brush
);
474 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
= wxSOLID
);
477 class WXDLLEXPORT wxFontList
: public wxList
483 void AddFont(wxFont
*font
);
484 void RemoveFont(wxFont
*font
);
485 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
486 bool underline
= false,
487 const wxString
& face
= wxEmptyString
,
488 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
491 WX_DECLARE_STRING_HASH_MAP( wxColour
*, wxStringToColourHashMap
);
493 class WXDLLEXPORT wxColourDatabase
499 // find colour by name or name for the given colour
500 wxColour
Find(const wxString
& name
) const;
501 wxString
FindName(const wxColour
& colour
) const;
503 // add a new colour to the database
504 void AddColour(const wxString
& name
, const wxColour
& colour
);
506 // deprecated, use Find() instead
507 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
511 // PM keeps its own type of colour table
517 // load the database with the built in colour values when called for the
518 // first time, do nothing after this
521 wxStringToColourHashMap
*m_map
;
524 class WXDLLEXPORT wxBitmapList
: public wxList
530 void AddBitmap(wxBitmap
*bitmap
);
531 void RemoveBitmap(wxBitmap
*bitmap
);
534 class WXDLLEXPORT wxResourceCache
: public wxList
537 wxResourceCache() { }
539 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
544 // ---------------------------------------------------------------------------
546 // ---------------------------------------------------------------------------
548 // Lists of GDI objects
549 extern WXDLLEXPORT_DATA(wxPenList
*) wxThePenList
;
550 extern WXDLLEXPORT_DATA(wxBrushList
*) wxTheBrushList
;
551 extern WXDLLEXPORT_DATA(wxFontList
*) wxTheFontList
;
552 extern WXDLLEXPORT_DATA(wxBitmapList
*) wxTheBitmapList
;
555 extern WXDLLEXPORT_DATA(wxFont
*) wxNORMAL_FONT
;
556 extern WXDLLEXPORT_DATA(wxFont
*) wxSMALL_FONT
;
557 extern WXDLLEXPORT_DATA(wxFont
*) wxITALIC_FONT
;
558 extern WXDLLEXPORT_DATA(wxFont
*) wxSWISS_FONT
;
560 extern WXDLLEXPORT_DATA(wxPen
*) wxRED_PEN
;
561 extern WXDLLEXPORT_DATA(wxPen
*) wxCYAN_PEN
;
562 extern WXDLLEXPORT_DATA(wxPen
*) wxGREEN_PEN
;
563 extern WXDLLEXPORT_DATA(wxPen
*) wxBLACK_PEN
;
564 extern WXDLLEXPORT_DATA(wxPen
*) wxWHITE_PEN
;
565 extern WXDLLEXPORT_DATA(wxPen
*) wxTRANSPARENT_PEN
;
566 extern WXDLLEXPORT_DATA(wxPen
*) wxBLACK_DASHED_PEN
;
567 extern WXDLLEXPORT_DATA(wxPen
*) wxGREY_PEN
;
568 extern WXDLLEXPORT_DATA(wxPen
*) wxMEDIUM_GREY_PEN
;
569 extern WXDLLEXPORT_DATA(wxPen
*) wxLIGHT_GREY_PEN
;
571 extern WXDLLEXPORT_DATA(wxBrush
*) wxBLUE_BRUSH
;
572 extern WXDLLEXPORT_DATA(wxBrush
*) wxGREEN_BRUSH
;
573 extern WXDLLEXPORT_DATA(wxBrush
*) wxWHITE_BRUSH
;
574 extern WXDLLEXPORT_DATA(wxBrush
*) wxBLACK_BRUSH
;
575 extern WXDLLEXPORT_DATA(wxBrush
*) wxGREY_BRUSH
;
576 extern WXDLLEXPORT_DATA(wxBrush
*) wxMEDIUM_GREY_BRUSH
;
577 extern WXDLLEXPORT_DATA(wxBrush
*) wxLIGHT_GREY_BRUSH
;
578 extern WXDLLEXPORT_DATA(wxBrush
*) wxTRANSPARENT_BRUSH
;
579 extern WXDLLEXPORT_DATA(wxBrush
*) wxCYAN_BRUSH
;
580 extern WXDLLEXPORT_DATA(wxBrush
*) wxRED_BRUSH
;
582 extern WXDLLEXPORT_DATA(wxColour
*) wxBLACK
;
583 extern WXDLLEXPORT_DATA(wxColour
*) wxWHITE
;
584 extern WXDLLEXPORT_DATA(wxColour
*) wxRED
;
585 extern WXDLLEXPORT_DATA(wxColour
*) wxBLUE
;
586 extern WXDLLEXPORT_DATA(wxColour
*) wxGREEN
;
587 extern WXDLLEXPORT_DATA(wxColour
*) wxCYAN
;
588 extern WXDLLEXPORT_DATA(wxColour
*) wxLIGHT_GREY
;
591 extern WXDLLEXPORT_DATA(wxBitmap
) wxNullBitmap
;
592 extern WXDLLEXPORT_DATA(wxIcon
) wxNullIcon
;
593 extern WXDLLEXPORT_DATA(wxCursor
) wxNullCursor
;
594 extern WXDLLEXPORT_DATA(wxPen
) wxNullPen
;
595 extern WXDLLEXPORT_DATA(wxBrush
) wxNullBrush
;
596 extern WXDLLEXPORT_DATA(wxPalette
) wxNullPalette
;
597 extern WXDLLEXPORT_DATA(wxFont
) wxNullFont
;
598 extern WXDLLEXPORT_DATA(wxColour
) wxNullColour
;
600 // Stock cursors types
601 extern WXDLLEXPORT_DATA(wxCursor
*) wxSTANDARD_CURSOR
;
602 extern WXDLLEXPORT_DATA(wxCursor
*) wxHOURGLASS_CURSOR
;
603 extern WXDLLEXPORT_DATA(wxCursor
*) wxCROSS_CURSOR
;
605 extern WXDLLEXPORT_DATA(wxColourDatabase
*) wxTheColourDatabase
;
607 extern WXDLLEXPORT_DATA(const wxChar
) wxPanelNameStr
[];
609 extern WXDLLEXPORT_DATA(const wxSize
) wxDefaultSize
;
610 extern WXDLLEXPORT_DATA(const wxPoint
) wxDefaultPosition
;
612 // The list of objects which should be deleted
613 extern WXDLLEXPORT_DATA(wxList
) wxPendingDelete
;
615 // ---------------------------------------------------------------------------
617 // ---------------------------------------------------------------------------
619 // resource management
620 extern void WXDLLEXPORT
wxInitializeStockObjects();
621 extern void WXDLLEXPORT
wxInitializeStockLists();
622 extern void WXDLLEXPORT
wxDeleteStockObjects();
623 extern void WXDLLEXPORT
wxDeleteStockLists();
625 // is the display colour (or monochrome)?
626 extern bool WXDLLEXPORT
wxColourDisplay();
628 // Returns depth of screen
629 extern int WXDLLEXPORT
wxDisplayDepth();
630 #define wxGetDisplayDepth wxDisplayDepth
632 // get the display size
633 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
634 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
635 extern void WXDLLEXPORT
wxDisplaySizeMM(int *width
, int *height
);
636 extern wxSize WXDLLEXPORT
wxGetDisplaySizeMM();
638 // Get position and size of the display workarea
639 extern void WXDLLEXPORT
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
640 extern wxRect WXDLLEXPORT
wxGetClientDisplayRect();
643 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);