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 WXDLLIMPEXP_CORE wxBitmap
;
34 class WXDLLIMPEXP_CORE wxBrush
;
35 class WXDLLIMPEXP_CORE wxColour
;
36 class WXDLLIMPEXP_CORE wxCursor
;
37 class WXDLLIMPEXP_CORE wxFont
;
38 class WXDLLIMPEXP_CORE wxIcon
;
39 class WXDLLIMPEXP_CORE wxPalette
;
40 class WXDLLIMPEXP_CORE wxPen
;
41 class WXDLLIMPEXP_CORE wxRegion
;
42 class WXDLLIMPEXP_BASE 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__) || \
186 defined(__WXMOTIF__) || \
187 defined(__WXX11__) || \
188 defined(__WXMAC__) || \
189 defined(__WXMGL__) || \
191 // Initialize from an included XPM
192 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
193 #else // other platforms
194 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
197 // ===========================================================================
199 // ===========================================================================
201 // ---------------------------------------------------------------------------
203 // ---------------------------------------------------------------------------
205 class WXDLLEXPORT wxSize
208 // members are public for compatibility, don't use them directly.
212 wxSize() : x(0), y(0) { }
213 wxSize(int xx
, int yy
) : x(xx
), y(yy
) { }
215 // no copy ctor or assignment operator - the defaults are ok
217 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
218 bool operator!=(const wxSize
& sz
) const { return x
!= sz
.x
|| y
!= sz
.y
; }
220 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
221 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
222 wxSize
operator/(const int i
) { return wxSize(x
/ i
, y
/ i
); }
223 wxSize
operator*(const int i
) { return wxSize(x
* i
, y
* i
); }
225 wxSize
& operator+=(const wxSize
& sz
) { x
+= sz
.x
; y
+= sz
.y
; return *this; }
226 wxSize
& operator-=(const wxSize
& sz
) { x
-= sz
.x
; y
-= sz
.y
; return *this; }
227 wxSize
& operator/=(const int i
) { x
/= i
; y
/= i
; return *this; }
228 wxSize
& operator*=(const int i
) { x
*= i
; y
*= i
; return *this; }
230 void IncTo(const wxSize
& sz
)
231 { if ( sz
.x
> x
) x
= sz
.x
; if ( sz
.y
> y
) y
= sz
.y
; }
232 void DecTo(const wxSize
& sz
)
233 { if ( sz
.x
< x
) x
= sz
.x
; if ( sz
.y
< y
) y
= sz
.y
; }
236 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
237 void SetWidth(int w
) { x
= w
; }
238 void SetHeight(int h
) { y
= h
; }
240 int GetWidth() const { return x
; }
241 int GetHeight() const { return y
; }
243 bool IsFullySpecified() const { return x
!= wxDefaultCoord
&& y
!= wxDefaultCoord
; }
245 // combine this size with the other one replacing the default (i.e. equal
246 // to wxDefaultCoord) components of this object with those of the other
247 void SetDefaults(const wxSize
& size
)
249 if ( x
== wxDefaultCoord
)
251 if ( y
== wxDefaultCoord
)
256 int GetX() const { return x
; }
257 int GetY() const { return y
; }
260 // ---------------------------------------------------------------------------
261 // Point classes: with real or integer coordinates
262 // ---------------------------------------------------------------------------
264 class WXDLLEXPORT wxRealPoint
270 wxRealPoint() : x(0.0), y(0.0) { }
271 wxRealPoint(double xx
, double yy
) : x(xx
), y(yy
) { }
273 wxRealPoint
operator+(const wxRealPoint
& pt
) const { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
274 wxRealPoint
operator-(const wxRealPoint
& pt
) const { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
276 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
277 bool operator!=(const wxRealPoint
& pt
) const { return x
!= pt
.x
|| y
!= pt
.y
; }
280 class WXDLLEXPORT wxPoint
285 wxPoint() : x(0), y(0) { }
286 wxPoint(int xx
, int yy
) : x(xx
), y(yy
) { }
288 // no copy ctor or assignment operator - the defaults are ok
291 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
292 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
294 // arithmetic operations (component wise)
295 wxPoint
operator+(const wxPoint
& p
) const { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
296 wxPoint
operator-(const wxPoint
& p
) const { return wxPoint(x
- p
.x
, y
- p
.y
); }
298 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
299 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
301 wxPoint
& operator+=(const wxSize
& s
) { x
+= s
.GetWidth(); y
+= s
.GetHeight(); return *this; }
302 wxPoint
& operator-=(const wxSize
& s
) { x
-= s
.GetWidth(); y
-= s
.GetHeight(); return *this; }
304 wxPoint
operator+(const wxSize
& s
) const { return wxPoint(x
+ s
.GetWidth(), y
+ s
.GetHeight()); }
305 wxPoint
operator-(const wxSize
& s
) const { return wxPoint(x
- s
.GetWidth(), y
- s
.GetHeight()); }
308 // ---------------------------------------------------------------------------
310 // ---------------------------------------------------------------------------
312 class WXDLLEXPORT wxRect
316 : x(0), y(0), width(0), height(0)
318 wxRect(int xx
, int yy
, int ww
, int hh
)
319 : x(xx
), y(yy
), width(ww
), height(hh
)
321 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
322 wxRect(const wxPoint
& pos
, const wxSize
& size
);
323 wxRect(const wxSize
& size
);
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 wxPoint
GetTopLeft() const { return GetPosition(); }
346 wxPoint
GetLeftTop() const { return GetTopLeft(); }
347 void SetTopLeft(const wxPoint
&p
) { SetPosition(p
); }
348 void SetLeftTop(const wxPoint
&p
) { SetTopLeft(p
); }
350 wxPoint
GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
351 wxPoint
GetRightBottom() const { return GetBottomRight(); }
352 void SetBottomRight(const wxPoint
&p
) { SetRight(p
.x
); SetBottom(p
.y
); }
353 void SetRightBottom(const wxPoint
&p
) { SetBottomRight(p
); }
355 int GetLeft() const { return x
; }
356 int GetTop() const { return y
; }
357 int GetBottom() const { return y
+ height
- 1; }
358 int GetRight() const { return x
+ width
- 1; }
360 void SetLeft(int left
) { x
= left
; }
361 void SetRight(int right
) { width
= right
- x
+ 1; }
362 void SetTop(int top
) { y
= top
; }
363 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
365 // operations with rect
366 wxRect
& Inflate(wxCoord dx
, wxCoord dy
);
367 wxRect
& Inflate(wxCoord d
) { return Inflate(d
, d
); }
368 wxRect
Inflate(wxCoord dx
, wxCoord dy
) const
375 wxRect
& Deflate(wxCoord dx
, wxCoord dy
) { return Inflate(-dx
, -dy
); }
376 wxRect
& Deflate(wxCoord d
) { return Inflate(-d
); }
377 wxRect
Deflate(wxCoord dx
, wxCoord dy
) const
384 void Offset(wxCoord dx
, wxCoord dy
) { x
+= dx
; y
+= dy
; }
385 void Offset(const wxPoint
& pt
) { Offset(pt
.x
, pt
.y
); }
387 wxRect
& Intersect(const wxRect
& rect
);
388 wxRect
Intersect(const wxRect
& rect
) const
395 wxRect
operator+(const wxRect
& rect
) const;
396 wxRect
& operator+=(const wxRect
& rect
);
398 // compare rectangles
399 bool operator==(const wxRect
& rect
) const;
400 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
402 // return true if the point is (not strcitly) inside the rect
403 bool Inside(int x
, int y
) const;
404 bool Inside(const wxPoint
& pt
) const { return Inside(pt
.x
, pt
.y
); }
406 // return true if the rectangles have a non empty intersection
407 bool Intersects(const wxRect
& rect
) const;
410 int x
, y
, width
, height
;
413 // ---------------------------------------------------------------------------
414 // Management of pens, brushes and fonts
415 // ---------------------------------------------------------------------------
417 typedef wxInt8 wxDash
;
419 class WXDLLEXPORT wxPenList
: public wxList
425 void AddPen(wxPen
*pen
);
426 void RemovePen(wxPen
*pen
);
427 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
430 class WXDLLEXPORT wxBrushList
: public wxList
436 void AddBrush(wxBrush
*brush
);
437 void RemoveBrush(wxBrush
*brush
);
438 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
441 class WXDLLEXPORT wxFontList
: public wxList
447 void AddFont(wxFont
*font
);
448 void RemoveFont(wxFont
*font
);
449 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
450 bool underline
= false,
451 const wxString
& face
= wxEmptyString
,
452 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
455 WX_DECLARE_STRING_HASH_MAP( wxColour
*, wxStringToColourHashMap
);
457 class WXDLLEXPORT wxColourDatabase
463 // find colour by name or name for the given colour
464 wxColour
Find(const wxString
& name
) const;
465 wxString
FindName(const wxColour
& colour
) const;
467 // add a new colour to the database
468 void AddColour(const wxString
& name
, const wxColour
& colour
);
470 // deprecated, use Find() instead
471 wxDEPRECATED( wxColour
*FindColour(const wxString
& name
) );
475 // PM keeps its own type of colour table
481 // load the database with the built in colour values when called for the
482 // first time, do nothing after this
485 wxStringToColourHashMap
*m_map
;
488 class WXDLLEXPORT wxBitmapList
: public wxList
494 void AddBitmap(wxBitmap
*bitmap
);
495 void RemoveBitmap(wxBitmap
*bitmap
);
498 class WXDLLEXPORT wxResourceCache
: public wxList
501 wxResourceCache() { }
503 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
508 // ---------------------------------------------------------------------------
510 // ---------------------------------------------------------------------------
512 // Lists of GDI objects
513 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
514 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
515 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
516 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
519 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
520 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
521 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
522 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
524 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
525 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
526 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
527 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
528 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
529 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
530 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
531 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
532 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
533 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
535 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
536 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
537 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
538 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
539 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
540 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
541 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
542 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
543 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
544 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
546 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
547 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
548 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
549 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
550 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
551 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
552 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
555 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
556 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
557 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
558 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
559 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
560 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
561 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
562 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
564 // Stock cursors types
565 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
566 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
567 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
569 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
571 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
573 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
574 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
576 // The list of objects which should be deleted
577 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
579 // ---------------------------------------------------------------------------
581 // ---------------------------------------------------------------------------
583 // resource management
584 extern void WXDLLEXPORT
wxInitializeStockObjects();
585 extern void WXDLLEXPORT
wxInitializeStockLists();
586 extern void WXDLLEXPORT
wxDeleteStockObjects();
587 extern void WXDLLEXPORT
wxDeleteStockLists();
589 // is the display colour (or monochrome)?
590 extern bool WXDLLEXPORT
wxColourDisplay();
592 // Returns depth of screen
593 extern int WXDLLEXPORT
wxDisplayDepth();
594 #define wxGetDisplayDepth wxDisplayDepth
596 // get the display size
597 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
598 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
599 extern void WXDLLEXPORT
wxDisplaySizeMM(int *width
, int *height
);
600 extern wxSize WXDLLEXPORT
wxGetDisplaySizeMM();
602 // Get position and size of the display workarea
603 extern void WXDLLEXPORT
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
604 extern wxRect WXDLLEXPORT
wxGetClientDisplayRect();
607 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);