1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes, types and declarations
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "gdicmn.h"
25 #include "wx/string.h"
26 #include "wx/fontenc.h"
27 #include "wx/hashmap.h"
29 // ---------------------------------------------------------------------------
30 // forward declarations
31 // ---------------------------------------------------------------------------
33 class WXDLLEXPORT wxBitmap
;
34 class WXDLLEXPORT wxBrush
;
35 class WXDLLEXPORT wxColour
;
36 class WXDLLEXPORT wxCursor
;
37 class WXDLLEXPORT wxFont
;
38 class WXDLLEXPORT wxIcon
;
39 class WXDLLEXPORT wxPalette
;
40 class WXDLLEXPORT wxPen
;
41 class WXDLLEXPORT wxRegion
;
42 class WXDLLEXPORT wxString
;
44 // ---------------------------------------------------------------------------
46 // ---------------------------------------------------------------------------
51 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
53 wxBITMAP_TYPE_BMP_RESOURCE
,
54 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
56 wxBITMAP_TYPE_ICO_RESOURCE
,
58 wxBITMAP_TYPE_CUR_RESOURCE
,
60 wxBITMAP_TYPE_XBM_DATA
,
62 wxBITMAP_TYPE_XPM_DATA
,
64 wxBITMAP_TYPE_TIF_RESOURCE
,
66 wxBITMAP_TYPE_GIF_RESOURCE
,
68 wxBITMAP_TYPE_PNG_RESOURCE
,
70 wxBITMAP_TYPE_JPEG_RESOURCE
,
72 wxBITMAP_TYPE_PNM_RESOURCE
,
74 wxBITMAP_TYPE_PCX_RESOURCE
,
76 wxBITMAP_TYPE_PICT_RESOURCE
,
78 wxBITMAP_TYPE_ICON_RESOURCE
,
81 wxBITMAP_TYPE_MACCURSOR
,
82 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
83 wxBITMAP_TYPE_ANY
= 50
89 wxCURSOR_NONE
, // should be 0
99 wxCURSOR_MIDDLE_BUTTON
,
101 wxCURSOR_PAINT_BRUSH
,
104 wxCURSOR_POINT_RIGHT
,
105 wxCURSOR_QUESTION_ARROW
,
106 wxCURSOR_RIGHT_BUTTON
,
117 wxCURSOR_DEFAULT
, // standard X11 cursor
120 wxCURSOR_COPY_ARROW
, // MacOS Theme Plus arrow
123 // Not yet implemented for Windows
124 wxCURSOR_CROSS_REVERSE
,
125 wxCURSOR_DOUBLE_ARROW
,
126 wxCURSOR_BASED_ARROW_UP
,
127 wxCURSOR_BASED_ARROW_DOWN
,
136 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
139 // ---------------------------------------------------------------------------
141 // ---------------------------------------------------------------------------
143 /* Useful macro for creating icons portably, for example:
145 wxIcon *icon = new wxICON(mondrian);
149 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
150 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
154 // Load from a resource
155 #define wxICON(X) wxIcon(wxT(#X))
156 #elif defined(__WXPM__)
157 // Load from a resource
158 #define wxICON(X) wxIcon(wxT(#X))
159 #elif defined(__WXMGL__)
160 // Initialize from an included XPM
161 #define wxICON(X) wxIcon( (const char**) X##_xpm )
162 #elif defined(__WXGTK__)
163 // Initialize from an included XPM
164 #define wxICON(X) wxIcon( (const char**) X##_xpm )
165 #elif defined(__WXMAC__)
166 // Initialize from an included XPM
167 #define wxICON(X) wxIcon( (const char**) X##_xpm )
168 #elif defined(__WXMOTIF__)
169 // Initialize from an included XPM
170 #define wxICON(X) wxIcon( X##_xpm )
171 #elif defined(__WXX11__)
172 // Initialize from an included XPM
173 #define wxICON(X) wxIcon( X##_xpm )
175 // This will usually mean something on any platform
176 #define wxICON(X) wxIcon(wxT(#X))
179 /* Another macro: this one is for portable creation of bitmaps. We assume that
180 under Unix bitmaps live in XPMs and under Windows they're in ressources.
183 #if defined(__WXMSW__) || defined(__WXPM__)
184 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
185 #elif defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXCOCOA__)
186 // Initialize from an included XPM
187 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
188 #else // other platforms
189 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
192 // ===========================================================================
194 // ===========================================================================
196 // ---------------------------------------------------------------------------
198 // ---------------------------------------------------------------------------
200 class WXDLLEXPORT wxSize
203 // members are public for compatibility, don't use them directly.
207 wxSize() : x(0), y(0) { }
208 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
210 // no copy ctor or assignment operator - the defaults are ok
212 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
213 bool operator!=(const wxSize
& sz
) const { return x
!= sz
.x
|| y
!= sz
.y
; }
215 // FIXME are these really useful? If they're, we should have += &c as well
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
); }
219 void IncTo(const wxSize
& sz
)
220 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
221 void DecTo(const wxSize
& sz
)
222 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
225 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
226 void SetWidth(int w
) { x
= w
; }
227 void SetHeight(int h
) { y
= h
; }
229 int GetWidth() const { return x
; }
230 int GetHeight() const { return y
; }
232 bool IsFullySpecified() const { return x
!= -1 && y
!= -1; }
234 // combine this size with the other one replacing the default (i.e. equal
235 // to -1) components of this object with those of the other
236 void SetDefaults(const wxSize
& size
)
245 int GetX() const { return x
; }
246 int GetY() const { return y
; }
249 // ---------------------------------------------------------------------------
250 // Point classes: with real or integer coordinates
251 // ---------------------------------------------------------------------------
253 class WXDLLEXPORT wxRealPoint
259 wxRealPoint() : x(0.0), y(0.0) { }
260 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
262 wxRealPoint
operator+(const wxRealPoint
& pt
) const { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
263 wxRealPoint
operator-(const wxRealPoint
& pt
) const { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
265 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
266 bool operator!=(const wxRealPoint
& pt
) const { return x
!= pt
.x
|| y
!= pt
.y
; }
269 class WXDLLEXPORT wxPoint
274 wxPoint() : x(0), y(0) { }
275 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
277 // no copy ctor or assignment operator - the defaults are ok
280 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
281 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
283 // arithmetic operations (component wise)
284 wxPoint
operator+(const wxPoint
& p
) const { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
285 wxPoint
operator-(const wxPoint
& p
) const { return wxPoint(x
- p
.x
, y
- p
.y
); }
287 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
288 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
290 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
291 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
293 wxPoint
operator+(const wxSize
& s
) const { return wxPoint(x
+ s
.GetWidth(), y
+ s
.GetHeight()); }
294 wxPoint
operator-(const wxSize
& s
) const { return wxPoint(x
- s
.GetWidth(), y
- s
.GetHeight()); }
297 // ---------------------------------------------------------------------------
299 // ---------------------------------------------------------------------------
301 class WXDLLEXPORT wxRect
305 : x(0), y(0), width(0), height(0)
307 wxRect(int xx
, int yy
, int ww
, int hh
)
308 : x(xx
), y(yy
), width(ww
), height(hh
)
310 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
311 wxRect(const wxPoint
& pos
, const wxSize
& size
);
313 // default copy ctor and assignment operators ok
315 int GetX() const { return x
; }
316 void SetX(int xx
) { x
= xx
; }
318 int GetY() const { return y
; }
319 void SetY(int yy
) { y
= yy
; }
321 int GetWidth() const { return width
; }
322 void SetWidth(int w
) { width
= w
; }
324 int GetHeight() const { return height
; }
325 void SetHeight(int h
) { height
= h
; }
327 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
328 void SetPosition( const wxPoint
&p
) { x
= p
.x
; y
= p
.y
; }
330 wxSize
GetSize() const { return wxSize(width
, height
); }
331 void SetSize( const wxSize
&s
) { width
= s
.GetWidth(); height
= s
.GetHeight(); }
333 wxPoint
GetTopLeft() const { return GetPosition(); }
334 wxPoint
GetLeftTop() const { return GetTopLeft(); }
335 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
336 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
338 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
339 wxPoint
GetRightBottom() const { return GetBottomRight(); }
340 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
341 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
343 int GetLeft() const { return x
; }
344 int GetTop() const { return y
; }
345 int GetBottom() const { return y
+ height
- 1; }
346 int GetRight() const { return x
+ width
- 1; }
348 void SetLeft(int left
) { x
= left
; }
349 void SetRight(int right
) { width
= right
- x
+ 1; }
350 void SetTop(int top
) { y
= top
; }
351 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
353 // operations with rect
354 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
355 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
356 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
363 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
364 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
365 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
372 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
373 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
375 wxRect
& Intersect(const wxRect
& rect
);
376 wxRect
Intersect(const wxRect
& rect
) const
383 wxRect
operator+(const wxRect
& rect
) const;
384 wxRect
& operator+=(const wxRect
& rect
);
386 // compare rectangles
387 bool operator==(const wxRect
& rect
) const;
388 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
390 // return TRUE if the point is (not strcitly) inside the rect
391 bool Inside(int x
, int y
) const;
392 bool Inside(const wxPoint
& pt
) const { return Inside(pt
.x
, pt
.y
); }
394 // return TRUE if the rectangles have a non empty intersection
395 bool Intersects(const wxRect
& rect
) const;
398 int x
, y
, width
, height
;
401 // ---------------------------------------------------------------------------
402 // Management of pens, brushes and fonts
403 // ---------------------------------------------------------------------------
405 typedef wxInt8 wxDash
;
407 class WXDLLEXPORT wxPenList
: public wxList
413 void AddPen(wxPen
*pen
);
414 void RemovePen(wxPen
*pen
);
415 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
418 class WXDLLEXPORT wxBrushList
: public wxList
424 void AddBrush(wxBrush
*brush
);
425 void RemoveBrush(wxBrush
*brush
);
426 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
429 class WXDLLEXPORT wxFontList
: public wxList
435 void AddFont(wxFont
*font
);
436 void RemoveFont(wxFont
*font
);
437 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
438 bool underline
= FALSE
,
439 const wxString
& face
= wxEmptyString
,
440 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
443 WX_DECLARE_STRING_HASH_MAP( wxColour
*, wxStringToColourHashMap
);
445 class WXDLLEXPORT wxColourDatabase
451 // find colour by name or name for the given colour
452 wxColour
Find(const wxString
& name
) const;
453 wxString
FindName(const wxColour
& colour
) const;
455 // add a new colour to the database
456 void AddColour(const wxString
& name
, const wxColour
& colour
);
458 // deprecated, use Find() instead
459 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
463 // PM keeps its own type of colour table
469 // load the database with the built in colour values when called for the
470 // first time, do nothing after this
473 wxStringToColourHashMap
*m_map
;
476 class WXDLLEXPORT wxBitmapList
: public wxList
482 void AddBitmap(wxBitmap
*bitmap
);
483 void RemoveBitmap(wxBitmap
*bitmap
);
486 class WXDLLEXPORT wxResourceCache
: public wxList
489 wxResourceCache() { }
491 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
496 // ---------------------------------------------------------------------------
498 // ---------------------------------------------------------------------------
500 // Lists of GDI objects
501 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
502 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
503 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
504 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
507 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
508 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
509 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
510 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
512 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
513 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
514 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
515 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
516 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
517 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
518 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
519 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
520 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
521 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
523 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
524 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
525 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
526 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
527 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
528 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
529 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
530 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
531 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
532 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
534 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
535 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
536 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
537 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
538 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
539 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
540 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
543 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
544 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
545 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
546 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
547 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
548 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
549 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
550 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
552 // Stock cursors types
553 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
554 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
555 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
557 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
559 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
561 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
562 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
564 // The list of objects which should be deleted
565 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
567 // ---------------------------------------------------------------------------
569 // ---------------------------------------------------------------------------
571 // resource management
572 extern void WXDLLEXPORT
wxInitializeStockObjects();
573 extern void WXDLLEXPORT
wxInitializeStockLists();
574 extern void WXDLLEXPORT
wxDeleteStockObjects();
575 extern void WXDLLEXPORT
wxDeleteStockLists();
577 // is the display colour (or monochrome)?
578 extern bool WXDLLEXPORT
wxColourDisplay();
580 // Returns depth of screen
581 extern int WXDLLEXPORT
wxDisplayDepth();
582 #define wxGetDisplayDepth wxDisplayDepth
584 // get the display size
585 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
586 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
587 extern void WXDLLEXPORT
wxDisplaySizeMM(int *width
, int *height
);
588 extern wxSize WXDLLEXPORT
wxGetDisplaySizeMM();
590 // Get position and size of the display workarea
591 extern void WXDLLEXPORT
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
592 extern wxRect WXDLLEXPORT
wxGetClientDisplayRect();
595 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);