1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes, types and declarations
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
20 #pragma interface "gdicmn.h"
23 #include "wx/object.h"
26 #include "wx/string.h"
28 #include "wx/colour.h"
31 // ---------------------------------------------------------------------------
32 // forward declarations
33 // ---------------------------------------------------------------------------
35 class WXDLLEXPORT wxBitmap
;
36 class WXDLLEXPORT wxBrush
;
37 class WXDLLEXPORT wxColour
;
38 class WXDLLEXPORT wxCursor
;
39 class WXDLLEXPORT wxFont
;
40 class WXDLLEXPORT wxIcon
;
41 class WXDLLEXPORT wxPalette
;
42 class WXDLLEXPORT wxPen
;
43 class WXDLLEXPORT wxRegion
;
44 class WXDLLEXPORT wxString
;
46 // ---------------------------------------------------------------------------
48 // ---------------------------------------------------------------------------
53 wxBITMAP_TYPE_INVALID
, // should be == 0 for compatibility!
55 wxBITMAP_TYPE_BMP_RESOURCE
,
56 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
58 wxBITMAP_TYPE_ICO_RESOURCE
,
60 wxBITMAP_TYPE_CUR_RESOURCE
,
62 wxBITMAP_TYPE_XBM_DATA
,
64 wxBITMAP_TYPE_XPM_DATA
,
66 wxBITMAP_TYPE_TIF_RESOURCE
,
68 wxBITMAP_TYPE_GIF_RESOURCE
,
70 wxBITMAP_TYPE_PNG_RESOURCE
,
72 wxBITMAP_TYPE_JPEG_RESOURCE
,
74 wxBITMAP_TYPE_PNM_RESOURCE
,
76 wxBITMAP_TYPE_PCX_RESOURCE
,
78 wxBITMAP_TYPE_PICT_RESOURCE
,
80 wxBITMAP_TYPE_ICON_RESOURCE
,
81 wxBITMAP_TYPE_MACCURSOR
,
82 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
83 wxBITMAP_TYPE_ANY
= 50
89 wxCURSOR_NONE
, // should be 0
98 wxCURSOR_MIDDLE_BUTTON
,
100 wxCURSOR_PAINT_BRUSH
,
103 wxCURSOR_POINT_RIGHT
,
104 wxCURSOR_QUESTION_ARROW
,
105 wxCURSOR_RIGHT_BUTTON
,
116 wxCURSOR_DEFAULT
, // standard X11 cursor
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("" #X "")
152 #elif defined(__WXPM__)
153 // Load from a resource
154 #define wxICON(X) wxIcon("" #X "")
155 #elif defined(__WXGTK__)
156 // Initialize from an included XPM
157 #define wxICON(X) wxIcon( (const char**) X##_xpm )
158 #elif defined(__WXMOTIF__)
159 // Initialize from an included XPM
160 #define wxICON(X) wxIcon( X##_xpm )
162 // This will usually mean something on any platform
163 #define wxICON(X) wxIcon("" #X "")
166 /* Another macro: this one is for portable creation of bitmaps. We assume that
167 under Unix bitmaps live in XPMs and under Windows they're in ressources.
170 #if defined(__WXMSW__) || defined(__WXPM__)
171 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
172 #elif defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
173 // Initialize from an included XPM
174 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
175 #else // other platforms
176 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
179 // ===========================================================================
181 // ===========================================================================
183 // ---------------------------------------------------------------------------
185 // ---------------------------------------------------------------------------
186 class WXDLLEXPORT wxSize
189 // members are public for compatibility (don't use them directly,
190 // especially that there names were chosen very unfortunately - they should
191 // have been called width and height)
195 wxSize() { x
= y
= 0; }
196 wxSize(int xx
, int yy
) { Set(xx
, yy
); }
198 // no copy ctor or assignment operator - the defaults are ok
199 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
201 // FIXME are these really useful? If they're, we should have += &c as well
202 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
203 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
206 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
207 void SetWidth(int w
) { x
= w
; }
208 void SetHeight(int h
) { y
= h
; }
210 int GetWidth() const { return x
; }
211 int GetHeight() const { return y
; }
214 int GetX() const { return x
; }
215 int GetY() const { return y
; }
218 // ---------------------------------------------------------------------------
219 // Point classes: with real or integer coordinates
220 // ---------------------------------------------------------------------------
222 class WXDLLEXPORT wxRealPoint
228 wxRealPoint() { x
= y
= 0.0; };
229 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
231 wxRealPoint
operator+(const wxRealPoint
& pt
) const { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
232 wxRealPoint
operator-(const wxRealPoint
& pt
) const { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
234 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
237 class WXDLLEXPORT wxPoint
242 wxPoint() { x
= y
= 0; };
243 wxPoint(int xx
, int yy
) { x
= xx
; y
= yy
; };
245 // no copy ctor or assignment operator - the defaults are ok
248 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
249 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
251 // arithmetic operations (component wise)
252 wxPoint
operator+(const wxPoint
& p
) const { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
253 wxPoint
operator-(const wxPoint
& p
) const { return wxPoint(x
- p
.x
, y
- p
.y
); }
255 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
256 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
259 #if WXWIN_COMPATIBILITY
260 #define wxIntPoint wxPoint
261 #define wxRectangle wxRect
262 #endif // WXWIN_COMPATIBILITY
264 // ---------------------------------------------------------------------------
266 // ---------------------------------------------------------------------------
268 class WXDLLEXPORT wxRect
271 wxRect() { x
= y
= width
= height
= 0; }
272 wxRect(int xx
, int yy
, int ww
, int hh
)
273 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
274 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
275 wxRect(const wxPoint
& pos
, const wxSize
& size
);
277 // default copy ctor and assignment operators ok
279 int GetX() const { return x
; }
280 void SetX(int xx
) { x
= xx
; }
282 int GetY() const { return y
; }
283 void SetY(int yy
) { y
= yy
; }
285 int GetWidth() const { return width
; }
286 void SetWidth(int w
) { width
= w
; }
288 int GetHeight() const { return height
; }
289 void SetHeight(int h
) { height
= h
; }
291 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
292 wxSize
GetSize() const { return wxSize(width
, height
); }
294 int GetLeft() const { return x
; }
295 int GetTop() const { return y
; }
296 int GetBottom() const { return y
+ height
- 1; }
297 int GetRight() const { return x
+ width
- 1; }
299 void SetLeft(int left
) { x
= left
; }
300 void SetRight(int right
) { width
= right
- x
+ 1; }
301 void SetTop(int top
) { y
= top
; }
302 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
304 void Inflate(wxCoord dx
, wxCoord dy
)
312 void Inflate(wxCoord d
) { Inflate(d
, d
); }
314 bool operator==(const wxRect
& rect
) const;
315 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
317 bool Inside(int cx
, int cy
) const;
318 bool Inside(const wxPoint
& pt
) const { return Inside(pt
.x
, pt
.y
); }
319 wxRect
operator+(const wxRect
& rect
) const;
320 wxRect
& operator+=(const wxRect
& rect
);
323 int x
, y
, width
, height
;
326 // ---------------------------------------------------------------------------
327 // Management of pens, brushes and fonts
328 // ---------------------------------------------------------------------------
330 typedef wxInt8 wxDash
;
332 class WXDLLEXPORT wxPenList
: public wxList
334 DECLARE_DYNAMIC_CLASS(wxPenList
)
340 void AddPen(wxPen
*pen
);
341 void RemovePen(wxPen
*pen
);
342 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
345 class WXDLLEXPORT wxBrushList
: public wxList
347 DECLARE_DYNAMIC_CLASS(wxBrushList
)
353 void AddBrush(wxBrush
*brush
);
354 void RemoveBrush(wxBrush
*brush
);
355 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
358 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
360 class WXDLLEXPORT wxFontList
: public wxList
362 DECLARE_DYNAMIC_CLASS(wxFontList
)
368 void AddFont(wxFont
*font
);
369 void RemoveFont(wxFont
*font
);
370 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
371 bool underline
= FALSE
,
372 const wxString
& face
= wxEmptyString
,
373 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
376 class WXDLLEXPORT wxColourDatabase
: public wxList
378 DECLARE_CLASS(wxColourDatabase
)
381 wxColourDatabase(int type
);
382 ~wxColourDatabase() ;
384 // Not const because it may add a name to the database
385 wxColour
*FindColour(const wxString
& colour
) ;
386 wxString
FindName(const wxColour
& colour
) const;
389 // PM keeps its own type of colour table
395 class WXDLLEXPORT wxBitmapList
: public wxList
397 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
403 void AddBitmap(wxBitmap
*bitmap
);
404 void RemoveBitmap(wxBitmap
*bitmap
);
407 class WXDLLEXPORT wxResourceCache
: public wxList
410 wxResourceCache() { }
411 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
415 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
418 // ---------------------------------------------------------------------------
420 // ---------------------------------------------------------------------------
422 // Lists of GDI objects
423 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
424 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
425 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
426 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
429 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
430 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
431 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
432 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
434 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
435 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
436 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
437 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
438 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
439 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
440 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
441 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
442 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
443 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
445 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
446 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
447 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
448 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
449 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
450 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
451 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
452 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
453 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
454 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
456 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
457 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
458 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
459 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
460 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
461 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
462 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
465 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
466 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
467 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
468 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
469 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
470 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
471 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
472 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
474 // Stock cursors types
475 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
476 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
477 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
479 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
481 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
483 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
484 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
486 // The list of objects which should be deleted
487 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
489 // ---------------------------------------------------------------------------
491 // ---------------------------------------------------------------------------
493 // resource management
494 extern void WXDLLEXPORT
wxInitializeStockObjects();
495 extern void WXDLLEXPORT
wxInitializeStockLists();
496 extern void WXDLLEXPORT
wxDeleteStockObjects();
497 extern void WXDLLEXPORT
wxDeleteStockLists();
499 // is the display colour (or monochrome)?
500 extern bool WXDLLEXPORT
wxColourDisplay();
502 // Returns depth of screen
503 extern int WXDLLEXPORT
wxDisplayDepth();
504 #define wxGetDisplayDepth wxDisplayDepth
506 // get the display size
507 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
508 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
509 extern void WXDLLEXPORT
wxDisplaySizeMM(int *width
, int *height
);
510 extern wxSize WXDLLEXPORT
wxGetDisplaySizeMM();
512 // Get position and size of the display workarea
513 extern void WXDLLEXPORT
wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
);
514 extern wxRect WXDLLEXPORT
wxGetClientDisplayRect();
517 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);