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"
30 // ---------------------------------------------------------------------------
31 // forward declarations
32 // ---------------------------------------------------------------------------
34 class WXDLLEXPORT wxBitmap
;
35 class WXDLLEXPORT wxBrush
;
36 class WXDLLEXPORT wxColour
;
37 class WXDLLEXPORT wxCursor
;
38 class WXDLLEXPORT wxFont
;
39 class WXDLLEXPORT wxIcon
;
40 class WXDLLEXPORT wxPalette
;
41 class WXDLLEXPORT wxPen
;
42 class WXDLLEXPORT wxRegion
;
43 class WXDLLEXPORT wxString
;
45 // ---------------------------------------------------------------------------
47 // ---------------------------------------------------------------------------
52 wxBITMAP_TYPE_BMP
= 1,
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
,
71 wxBITMAP_TYPE_ANY
= 50
77 wxCURSOR_NONE
, // should be 0
86 wxCURSOR_MIDDLE_BUTTON
,
92 wxCURSOR_QUESTION_ARROW
,
93 wxCURSOR_RIGHT_BUTTON
,
104 wxCURSOR_DEFAULT
, // standard X11 cursor
107 // Not yet implemented for Windows
108 wxCURSOR_CROSS_REVERSE
,
109 wxCURSOR_DOUBLE_ARROW
,
110 wxCURSOR_BASED_ARROW_UP
,
111 wxCURSOR_BASED_ARROW_DOWN
,
117 // ---------------------------------------------------------------------------
119 // ---------------------------------------------------------------------------
121 /* Useful macro for creating icons portably, for example:
123 wxIcon *icon = new wxICON(mondrian);
127 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
128 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
132 // Load from a resource
133 #define wxICON(X) wxIcon("" #X "")
134 #elif defined(__WXPM__)
135 // Load from a resource
136 #define wxICON(X) wxIcon("" #X "")
137 #elif defined(__WXGTK__)
138 // Initialize from an included XPM
139 #define wxICON(X) wxIcon( (const char**) X##_xpm )
140 #elif defined(__WXMOTIF__)
141 // Initialize from an included XPM
142 #define wxICON(X) wxIcon( X##_xpm )
144 // This will usually mean something on any platform
145 #define wxICON(X) wxIcon("" #X "")
148 // ===========================================================================
150 // ===========================================================================
152 // ---------------------------------------------------------------------------
154 // ---------------------------------------------------------------------------
155 class WXDLLEXPORT wxSize
158 // members are public for compatibility (don't use them directly,
159 // especially that there names were chosen very unfortunately - they should
160 // have been called width and height)
165 wxSize() { x
= y
= 0; }
166 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
168 // no copy ctor or assignment operator - the defaults are ok
169 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
171 // FIXME are these really useful? If they're, we should have += &c as well
172 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
173 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
176 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
177 void SetWidth(long w
) { x
= w
; }
178 void SetHeight(long h
) { y
= h
; }
180 long GetWidth() const { return x
; }
181 long GetHeight() const { return y
; }
184 long GetX() const { return x
; }
185 long GetY() const { return y
; }
188 // ---------------------------------------------------------------------------
189 // Point classes: with real or integer coordinates
190 // ---------------------------------------------------------------------------
192 class WXDLLEXPORT wxRealPoint
198 wxRealPoint() { x
= y
= 0.0; };
199 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
201 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
202 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
204 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
207 class WXDLLEXPORT wxPoint
210 #if defined(__WXMSW__) && !defined(__WIN32__)
218 wxPoint() { x
= y
= 0; };
219 wxPoint(long xx
, long yy
) { x
= xx
; y
= yy
; };
221 // no copy ctor or assignment operator - the defaults are ok
224 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
225 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
227 // arithmetic operations (component wise)
228 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
229 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
231 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
232 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
235 #if WXWIN_COMPATIBILITY
236 #define wxIntPoint wxPoint
237 #define wxRectangle wxRect
238 #endif // WXWIN_COMPATIBILITY
240 // ---------------------------------------------------------------------------
242 // ---------------------------------------------------------------------------
244 class WXDLLEXPORT wxRect
247 wxRect() { x
= y
= width
= height
= 0; }
248 wxRect(long xx
, long yy
, long ww
, long hh
)
249 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
250 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
251 wxRect(const wxPoint
& pos
, const wxSize
& size
);
253 // default copy ctor and assignment operators ok
255 long GetX() const { return x
; }
256 void SetX(long xx
) { x
= xx
; }
258 long GetY() const { return y
; }
259 void SetY(long yy
) { y
= yy
; }
261 long GetWidth() const { return width
; }
262 void SetWidth(long w
) { width
= w
; }
264 long GetHeight() const { return height
; }
265 void SetHeight(long h
) { height
= h
; }
267 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
268 wxSize
GetSize() const { return wxSize(width
, height
); }
270 // MFC-like functions
272 long GetLeft() const { return x
; }
273 long GetTop() const { return y
; }
274 long GetBottom() const { return y
+ height
- 1; }
275 long GetRight() const { return x
+ width
- 1; }
277 void SetLeft(long left
) { x
= left
; }
278 void SetRight(long right
) { width
= right
- x
+ 1; }
279 void SetTop(long top
) { y
= top
; }
280 void SetBottom(long bottom
) { height
= bottom
- y
+ 1; }
282 bool operator==(const wxRect
& rect
) const;
283 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
285 bool Inside(int cx
, int cy
) const;
286 wxRect
operator + (const wxRect
& rect
) const;
287 const wxRect
& operator += (const wxRect
& rect
);
290 long x
, y
, width
, height
;
293 // ---------------------------------------------------------------------------
294 // Management of pens, brushes and fonts
295 // ---------------------------------------------------------------------------
297 class WXDLLEXPORT wxPenList
: public wxList
299 DECLARE_DYNAMIC_CLASS(wxPenList
)
305 void AddPen(wxPen
*pen
);
306 void RemovePen(wxPen
*pen
);
307 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
310 class WXDLLEXPORT wxBrushList
: public wxList
312 DECLARE_DYNAMIC_CLASS(wxBrushList
)
318 void AddBrush(wxBrush
*brush
);
319 void RemoveBrush(wxBrush
*brush
);
320 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
323 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
325 class WXDLLEXPORT wxFontList
: public wxList
327 DECLARE_DYNAMIC_CLASS(wxFontList
)
333 void AddFont(wxFont
*font
);
334 void RemoveFont(wxFont
*font
);
335 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
336 bool underline
= FALSE
,
337 const wxString
& face
= wxEmptyString
);
340 class WXDLLEXPORT wxColourDatabase
: public wxList
342 DECLARE_CLASS(wxColourDatabase
)
345 wxColourDatabase(int type
);
346 ~wxColourDatabase() ;
348 // Not const because it may add a name to the database
349 wxColour
*FindColour(const wxString
& colour
) ;
350 wxString
FindName(const wxColour
& colour
) const;
354 class WXDLLEXPORT wxBitmapList
: public wxList
356 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
362 void AddBitmap(wxBitmap
*bitmap
);
363 void RemoveBitmap(wxBitmap
*bitmap
);
366 class WXDLLEXPORT wxResourceCache
: public wxList
369 wxResourceCache() { }
370 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
374 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
377 // ---------------------------------------------------------------------------
379 // ---------------------------------------------------------------------------
381 // Lists of GDI objects
382 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
383 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
384 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
385 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
388 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
389 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
390 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
391 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
393 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
394 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
395 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
396 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
397 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
398 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
399 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
400 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
401 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
402 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
404 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
405 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
406 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
407 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
408 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
409 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
410 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
411 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
412 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
413 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
415 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
416 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
417 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
418 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
419 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
420 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
421 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
424 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
425 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
426 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
427 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
428 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
429 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
430 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
431 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
433 // Stock cursors types
434 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
435 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
436 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
438 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
440 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
442 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
443 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
445 // The list of objects which should be deleted
446 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
448 // ---------------------------------------------------------------------------
450 // ---------------------------------------------------------------------------
452 // resource management
453 extern void WXDLLEXPORT
wxInitializeStockObjects();
454 extern void WXDLLEXPORT
wxInitializeStockLists();
455 extern void WXDLLEXPORT
wxDeleteStockObjects();
456 extern void WXDLLEXPORT
wxDeleteStockLists();
458 // is the display colour (or monochrome)?
459 extern bool WXDLLEXPORT
wxColourDisplay();
461 // Returns depth of screen
462 extern int WXDLLEXPORT
wxDisplayDepth();
463 #define wxGetDisplayDepth wxDisplayDepth
465 // get the diaplay size
466 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
467 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
470 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);