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"
25 // ---------------------------------------------------------------------------
26 // forward declarations
27 // ---------------------------------------------------------------------------
29 class WXDLLIMPEXP_CORE wxBitmap
;
30 class WXDLLIMPEXP_CORE wxBrush
;
31 class WXDLLIMPEXP_CORE wxColour
;
32 class WXDLLIMPEXP_CORE wxCursor
;
33 class WXDLLIMPEXP_CORE wxFont
;
34 class WXDLLIMPEXP_CORE wxIcon
;
35 class WXDLLIMPEXP_CORE wxPalette
;
36 class WXDLLIMPEXP_CORE wxPen
;
37 class WXDLLIMPEXP_CORE wxRegion
;
38 class WXDLLIMPEXP_BASE wxString
;
40 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
47 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
49 wxBITMAP_TYPE_BMP_RESOURCE
,
50 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
52 wxBITMAP_TYPE_ICO_RESOURCE
,
54 wxBITMAP_TYPE_CUR_RESOURCE
,
56 wxBITMAP_TYPE_XBM_DATA
,
58 wxBITMAP_TYPE_XPM_DATA
,
60 wxBITMAP_TYPE_TIF_RESOURCE
,
62 wxBITMAP_TYPE_GIF_RESOURCE
,
64 wxBITMAP_TYPE_PNG_RESOURCE
,
66 wxBITMAP_TYPE_JPEG_RESOURCE
,
68 wxBITMAP_TYPE_PNM_RESOURCE
,
70 wxBITMAP_TYPE_PCX_RESOURCE
,
72 wxBITMAP_TYPE_PICT_RESOURCE
,
74 wxBITMAP_TYPE_ICON_RESOURCE
,
77 wxBITMAP_TYPE_MACCURSOR
,
78 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
79 wxBITMAP_TYPE_ANY
= 50
85 wxCURSOR_NONE
, // should be 0
95 wxCURSOR_MIDDLE_BUTTON
,
100 wxCURSOR_POINT_RIGHT
,
101 wxCURSOR_QUESTION_ARROW
,
102 wxCURSOR_RIGHT_BUTTON
,
113 wxCURSOR_DEFAULT
, // standard X11 cursor
116 wxCURSOR_COPY_ARROW
, // MacOS Theme Plus arrow
119 // Not yet implemented for Windows
120 wxCURSOR_CROSS_REVERSE
,
121 wxCURSOR_DOUBLE_ARROW
,
122 wxCURSOR_BASED_ARROW_UP
,
123 wxCURSOR_BASED_ARROW_DOWN
,
132 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
135 // ---------------------------------------------------------------------------
137 // ---------------------------------------------------------------------------
139 /* Useful macro for creating icons portably, for example:
141 wxIcon *icon = new wxICON(mondrian);
145 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
146 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
150 // Load from a resource
151 #define wxICON(X) wxIcon(wxT(#X))
152 #elif defined(__WXPM__)
153 // Load from a resource
154 #define wxICON(X) wxIcon(wxT(#X))
155 #elif defined(__WXMGL__)
156 // Initialize from an included XPM
157 #define wxICON(X) wxIcon( (const char**) X##_xpm )
158 #elif defined(__WXGTK__)
159 // Initialize from an included XPM
160 #define wxICON(X) wxIcon( (const char**) X##_xpm )
161 #elif defined(__WXMAC__)
162 // Initialize from an included XPM
163 #define wxICON(X) wxIcon( (const char**) X##_xpm )
164 #elif defined(__WXMOTIF__)
165 // Initialize from an included XPM
166 #define wxICON(X) wxIcon( X##_xpm )
167 #elif defined(__WXX11__)
168 // Initialize from an included XPM
169 #define wxICON(X) wxIcon( X##_xpm )
171 // This will usually mean something on any platform
172 #define wxICON(X) wxIcon(wxT(#X))
175 /* Another macro: this one is for portable creation of bitmaps. We assume that
176 under Unix bitmaps live in XPMs and under Windows they're in ressources.
179 #if defined(__WXMSW__) || defined(__WXPM__)
180 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
181 #elif defined(__WXGTK__) || \
182 defined(__WXMOTIF__) || \
183 defined(__WXX11__) || \
184 defined(__WXMAC__) || \
185 defined(__WXMGL__) || \
187 // Initialize from an included XPM
188 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
189 #else // other platforms
190 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
193 // ===========================================================================
195 // ===========================================================================
197 // ---------------------------------------------------------------------------
199 // ---------------------------------------------------------------------------
201 class WXDLLEXPORT wxSize
204 // members are public for compatibility, don't use them directly.
208 wxSize() : x(0), y(0) { }
209 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
211 // no copy ctor or assignment operator - the defaults are ok
213 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
214 bool operator!=(const wxSize
& sz
) const { return x
!= sz
.x
|| y
!= sz
.y
; }
216 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
217 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
218 wxSize
operator/(const int i
) { return wxSize(x
/ i
, y
/ i
); }
219 wxSize
operator*(const int i
) { return wxSize(x
* i
, y
* i
); }
221 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
222 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
223 wxSize
& operator/=(const int i
) { x
/= i
; y
/= i
; return *this; }
224 wxSize
& operator*=(const int i
) { x
*= i
; y
*= i
; return *this; }
226 void IncTo(const wxSize
& sz
)
227 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
228 void DecTo(const wxSize
& sz
)
229 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
232 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
233 void SetWidth(int w
) { x
= w
; }
234 void SetHeight(int h
) { y
= h
; }
236 int GetWidth() const { return x
; }
237 int GetHeight() const { return y
; }
239 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
241 // combine this size with the other one replacing the default (i.e. equal
242 // to wxDefaultCoord) components of this object with those of the other
243 void SetDefaults(const wxSize
& size
)
245 if ( x
== wxDefaultCoord
)
247 if ( y
== wxDefaultCoord
)
252 int GetX() const { return x
; }
253 int GetY() const { return y
; }
256 // ---------------------------------------------------------------------------
257 // Point classes: with real or integer coordinates
258 // ---------------------------------------------------------------------------
260 class WXDLLEXPORT wxRealPoint
266 wxRealPoint() : x(0.0), y(0.0) { }
267 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
269 wxRealPoint
operator+(const wxRealPoint
& pt
) const { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
270 wxRealPoint
operator-(const wxRealPoint
& pt
) const { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
272 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
273 bool operator!=(const wxRealPoint
& pt
) const { return x
!= pt
.x
|| y
!= pt
.y
; }
276 class WXDLLEXPORT wxPoint
281 wxPoint() : x(0), y(0) { }
282 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
284 // no copy ctor or assignment operator - the defaults are ok
287 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
288 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
290 // arithmetic operations (component wise)
291 wxPoint
operator+(const wxPoint
& p
) const { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
292 wxPoint
operator-(const wxPoint
& p
) const { return wxPoint(x
- p
.x
, y
- p
.y
); }
294 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
295 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
297 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
298 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
300 wxPoint
operator+(const wxSize
& s
) const { return wxPoint(x
+ s
.GetWidth(), y
+ s
.GetHeight()); }
301 wxPoint
operator-(const wxSize
& s
) const { return wxPoint(x
- s
.GetWidth(), y
- s
.GetHeight()); }
304 // ---------------------------------------------------------------------------
306 // ---------------------------------------------------------------------------
308 class WXDLLEXPORT wxRect
312 : x(0), y(0), width(0), height(0)
314 wxRect(int xx
, int yy
, int ww
, int hh
)
315 : x(xx
), y(yy
), width(ww
), height(hh
)
317 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
318 wxRect(const wxPoint
& pt
, const wxSize
& size
)
319 : x(pt
.x
), y(pt
.y
), width(size
.x
), height(size
.y
)
321 wxRect(const wxSize
& size
)
322 : x(0), y(0), width(size
.x
), height(size
.y
)
325 // default copy ctor and assignment operators ok
327 int GetX() const { return x
; }
328 void SetX(int xx
) { x
= xx
; }
330 int GetY() const { return y
; }
331 void SetY(int yy
) { y
= yy
; }
333 int GetWidth() const { return width
; }
334 void SetWidth(int w
) { width
= w
; }
336 int GetHeight() const { return height
; }
337 void SetHeight(int h
) { height
= h
; }
339 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
340 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
342 wxSize
GetSize() const { return wxSize(width
, height
); }
343 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
345 bool IsEmpty() const { return (width
<= 0) || (height
<= 0); }
347 wxPoint
GetTopLeft() const { return GetPosition(); }
348 wxPoint
GetLeftTop() const { return GetTopLeft(); }
349 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
350 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
352 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
353 wxPoint
GetRightBottom() const { return GetBottomRight(); }
354 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
355 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
357 int GetLeft() const { return x
; }
358 int GetTop() const { return y
; }
359 int GetBottom() const { return y
+ height
- 1; }
360 int GetRight() const { return x
+ width
- 1; }
362 void SetLeft(int left
) { x
= left
; }
363 void SetRight(int right
) { width
= right
- x
+ 1; }
364 void SetTop(int top
) { y
= top
; }
365 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
367 // operations with rect
368 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
369 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
370 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
377 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
378 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
379 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
386 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
387 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
389 wxRect
& Intersect(const wxRect
& rect
);
390 wxRect
Intersect(const wxRect
& rect
) const
397 wxRect
& Union(const wxRect
& rect
);
398 wxRect
Union(const wxRect
& rect
) const
405 // compare rectangles
406 bool operator==(const wxRect
& rect
) const;
407 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
409 // return true if the point is (not strcitly) inside the rect
410 bool Inside(int x
, int y
) const;
411 bool Inside(const wxPoint
& pt
) const { return Inside(pt
.x
, pt
.y
); }
413 // return true if the rectangles have a non empty intersection
414 bool Intersects(const wxRect
& rect
) const;
417 // these are like Union() but don't ignore empty rectangles
418 wxRect
operator+(const wxRect
& rect
) const;
419 wxRect
& operator+=(const wxRect
& rect
)
421 *this = *this + rect
;
427 int x
, y
, width
, height
;
430 // ---------------------------------------------------------------------------
431 // Management of pens, brushes and fonts
432 // ---------------------------------------------------------------------------
434 typedef wxInt8 wxDash
;
436 class WXDLLEXPORT wxPenList
: public wxList
442 void AddPen(wxPen
*pen
);
443 void RemovePen(wxPen
*pen
);
444 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
447 class WXDLLEXPORT wxBrushList
: public wxList
453 void AddBrush(wxBrush
*brush
);
454 void RemoveBrush(wxBrush
*brush
);
455 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
= wxSOLID
);
458 class WXDLLEXPORT wxFontList
: public wxList
464 void AddFont(wxFont
*font
);
465 void RemoveFont(wxFont
*font
);
466 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
467 bool underline
= false,
468 const wxString
& face
= wxEmptyString
,
469 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
472 WX_DECLARE_STRING_HASH_MAP( wxColour
*, wxStringToColourHashMap
);
474 class WXDLLEXPORT wxColourDatabase
480 // find colour by name or name for the given colour
481 wxColour
Find(const wxString
& name
) const;
482 wxString
FindName(const wxColour
& colour
) const;
484 // add a new colour to the database
485 void AddColour(const wxString
& name
, const wxColour
& colour
);
487 // deprecated, use Find() instead
488 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
492 // PM keeps its own type of colour table
498 // load the database with the built in colour values when called for the
499 // first time, do nothing after this
502 wxStringToColourHashMap
*m_map
;
505 class WXDLLEXPORT wxBitmapList
: public wxList
511 void AddBitmap(wxBitmap
*bitmap
);
512 void RemoveBitmap(wxBitmap
*bitmap
);
515 class WXDLLEXPORT wxResourceCache
: public wxList
518 wxResourceCache() { }
520 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
525 // ---------------------------------------------------------------------------
527 // ---------------------------------------------------------------------------
529 // Lists of GDI objects
530 extern WXDLLEXPORT_DATA(wxPenList
*) wxThePenList
;
531 extern WXDLLEXPORT_DATA(wxBrushList
*) wxTheBrushList
;
532 extern WXDLLEXPORT_DATA(wxFontList
*) wxTheFontList
;
533 extern WXDLLEXPORT_DATA(wxBitmapList
*) wxTheBitmapList
;
536 extern WXDLLEXPORT_DATA(wxFont
*) wxNORMAL_FONT
;
537 extern WXDLLEXPORT_DATA(wxFont
*) wxSMALL_FONT
;
538 extern WXDLLEXPORT_DATA(wxFont
*) wxITALIC_FONT
;
539 extern WXDLLEXPORT_DATA(wxFont
*) wxSWISS_FONT
;
541 extern WXDLLEXPORT_DATA(wxPen
*) wxRED_PEN
;
542 extern WXDLLEXPORT_DATA(wxPen
*) wxCYAN_PEN
;
543 extern WXDLLEXPORT_DATA(wxPen
*) wxGREEN_PEN
;
544 extern WXDLLEXPORT_DATA(wxPen
*) wxBLACK_PEN
;
545 extern WXDLLEXPORT_DATA(wxPen
*) wxWHITE_PEN
;
546 extern WXDLLEXPORT_DATA(wxPen
*) wxTRANSPARENT_PEN
;
547 extern WXDLLEXPORT_DATA(wxPen
*) wxBLACK_DASHED_PEN
;
548 extern WXDLLEXPORT_DATA(wxPen
*) wxGREY_PEN
;
549 extern WXDLLEXPORT_DATA(wxPen
*) wxMEDIUM_GREY_PEN
;
550 extern WXDLLEXPORT_DATA(wxPen
*) wxLIGHT_GREY_PEN
;
552 extern WXDLLEXPORT_DATA(wxBrush
*) wxBLUE_BRUSH
;
553 extern WXDLLEXPORT_DATA(wxBrush
*) wxGREEN_BRUSH
;
554 extern WXDLLEXPORT_DATA(wxBrush
*) wxWHITE_BRUSH
;
555 extern WXDLLEXPORT_DATA(wxBrush
*) wxBLACK_BRUSH
;
556 extern WXDLLEXPORT_DATA(wxBrush
*) wxGREY_BRUSH
;
557 extern WXDLLEXPORT_DATA(wxBrush
*) wxMEDIUM_GREY_BRUSH
;
558 extern WXDLLEXPORT_DATA(wxBrush
*) wxLIGHT_GREY_BRUSH
;
559 extern WXDLLEXPORT_DATA(wxBrush
*) wxTRANSPARENT_BRUSH
;
560 extern WXDLLEXPORT_DATA(wxBrush
*) wxCYAN_BRUSH
;
561 extern WXDLLEXPORT_DATA(wxBrush
*) wxRED_BRUSH
;
563 extern WXDLLEXPORT_DATA(wxColour
*) wxBLACK
;
564 extern WXDLLEXPORT_DATA(wxColour
*) wxWHITE
;
565 extern WXDLLEXPORT_DATA(wxColour
*) wxRED
;
566 extern WXDLLEXPORT_DATA(wxColour
*) wxBLUE
;
567 extern WXDLLEXPORT_DATA(wxColour
*) wxGREEN
;
568 extern WXDLLEXPORT_DATA(wxColour
*) wxCYAN
;
569 extern WXDLLEXPORT_DATA(wxColour
*) wxLIGHT_GREY
;
572 extern WXDLLEXPORT_DATA(wxBitmap
) wxNullBitmap
;
573 extern WXDLLEXPORT_DATA(wxIcon
) wxNullIcon
;
574 extern WXDLLEXPORT_DATA(wxCursor
) wxNullCursor
;
575 extern WXDLLEXPORT_DATA(wxPen
) wxNullPen
;
576 extern WXDLLEXPORT_DATA(wxBrush
) wxNullBrush
;
577 extern WXDLLEXPORT_DATA(wxPalette
) wxNullPalette
;
578 extern WXDLLEXPORT_DATA(wxFont
) wxNullFont
;
579 extern WXDLLEXPORT_DATA(wxColour
) wxNullColour
;
581 // Stock cursors types
582 extern WXDLLEXPORT_DATA(wxCursor
*) wxSTANDARD_CURSOR
;
583 extern WXDLLEXPORT_DATA(wxCursor
*) wxHOURGLASS_CURSOR
;
584 extern WXDLLEXPORT_DATA(wxCursor
*) wxCROSS_CURSOR
;
586 extern WXDLLEXPORT_DATA(wxColourDatabase
*) wxTheColourDatabase
;
588 extern WXDLLEXPORT_DATA(const wxChar
*) wxPanelNameStr
;
590 extern WXDLLEXPORT_DATA(const wxSize
) wxDefaultSize
;
591 extern WXDLLEXPORT_DATA(const wxPoint
) wxDefaultPosition
;
593 // The list of objects which should be deleted
594 extern WXDLLEXPORT_DATA(wxList
) wxPendingDelete
;
596 // ---------------------------------------------------------------------------
598 // ---------------------------------------------------------------------------
600 // resource management
601 extern void WXDLLEXPORT
wxInitializeStockObjects();
602 extern void WXDLLEXPORT
wxInitializeStockLists();
603 extern void WXDLLEXPORT
wxDeleteStockObjects();
604 extern void WXDLLEXPORT
wxDeleteStockLists();
606 // is the display colour (or monochrome)?
607 extern bool WXDLLEXPORT
wxColourDisplay();
609 // Returns depth of screen
610 extern int WXDLLEXPORT
wxDisplayDepth();
611 #define wxGetDisplayDepth wxDisplayDepth
613 // get the display size
614 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
615 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
616 extern void WXDLLEXPORT
wxDisplaySizeMM(int *width
, int *height
);
617 extern wxSize WXDLLEXPORT
wxGetDisplaySizeMM();
619 // Get position and size of the display workarea
620 extern void WXDLLEXPORT
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
621 extern wxRect WXDLLEXPORT
wxGetClientDisplayRect();
624 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);