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 // Not yet implemented for Windows
105 wxCURSOR_CROSS_REVERSE
,
106 wxCURSOR_DOUBLE_ARROW
,
107 wxCURSOR_BASED_ARROW_UP
,
108 wxCURSOR_BASED_ARROW_DOWN
,
114 // ---------------------------------------------------------------------------
116 // ---------------------------------------------------------------------------
118 /* Useful macro for creating icons portably, for example:
120 wxIcon *icon = new wxICON(mondrian);
124 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
125 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
129 // Load from a resource
130 #define wxICON(X) wxIcon("" #X "")
131 #elif defined(__WXGTK__)
132 // Initialize from an included XPM
133 #define wxICON(X) wxIcon( (const char**) X##_xpm )
134 #elif defined(__WXMOTIF__)
135 // Initialize from an included XPM
136 #define wxICON(X) wxIcon( X##_xpm )
138 // This will usually mean something on any platform
139 #define wxICON(X) wxIcon("" #X "")
142 // ===========================================================================
144 // ===========================================================================
146 // ---------------------------------------------------------------------------
148 // ---------------------------------------------------------------------------
149 class WXDLLEXPORT wxSize
152 // members are public for compatibility (don't use them directly,
153 // especially that there names were chosen very unfortunately - they should
154 // have been called width and height)
159 wxSize() { x
= y
= 0; }
160 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
162 // no copy ctor or assignment operator - the defaults are ok
163 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
165 // FIXME are these really useful? If they're, we should have += &c as well
166 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
167 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
170 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
171 void SetWidth(long w
) { x
= w
; }
172 void SetHeight(long h
) { y
= h
; }
174 long GetWidth() const { return x
; }
175 long GetHeight() const { return y
; }
178 long GetX() const { return x
; }
179 long GetY() const { return y
; }
182 // ---------------------------------------------------------------------------
183 // Point classes: with real or integer coordinates
184 // ---------------------------------------------------------------------------
186 class WXDLLEXPORT wxRealPoint
192 wxRealPoint() { x
= y
= 0.0; };
193 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
195 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
196 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
198 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
201 class WXDLLEXPORT wxPoint
204 #if defined(__WXMSW__) && !defined(__WIN32__)
212 wxPoint() { x
= y
= 0; };
213 wxPoint(long xx
, long yy
) { x
= xx
; y
= yy
; };
215 // no copy ctor or assignment operator - the defaults are ok
218 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
219 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
221 // arithmetic operations (component wise)
222 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
223 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
225 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
226 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
229 #if WXWIN_COMPATIBILITY
230 #define wxIntPoint wxPoint
231 #define wxRectangle wxRect
232 #endif // WXWIN_COMPATIBILITY
234 // ---------------------------------------------------------------------------
236 // ---------------------------------------------------------------------------
238 class WXDLLEXPORT wxRect
241 wxRect() { x
= y
= width
= height
= 0; }
242 wxRect(long xx
, long yy
, long ww
, long hh
)
243 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
244 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
245 wxRect(const wxPoint
& pos
, const wxSize
& size
);
247 // default copy ctor and assignment operators ok
249 long GetX() const { return x
; }
250 void SetX(long xx
) { x
= xx
; }
252 long GetY() const { return y
; }
253 void SetY(long yy
) { y
= yy
; }
255 long GetWidth() const { return width
; }
256 void SetWidth(long w
) { width
= w
; }
258 long GetHeight() const { return height
; }
259 void SetHeight(long h
) { height
= h
; }
261 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
262 wxSize
GetSize() const { return wxSize(width
, height
); }
264 long GetLeft() const { return x
; }
265 long GetTop() const { return y
; }
266 long GetBottom() const { return y
+ height
; }
267 long GetRight() const { return x
+ width
; }
270 bool operator==(const wxRect
& rect
) const;
271 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
273 bool Inside(int cx
, int cy
) const;
274 wxRect
operator + (const wxRect
& rect
) const;
275 const wxRect
& operator += (const wxRect
& rect
);
278 long x
, y
, width
, height
;
281 // ---------------------------------------------------------------------------
282 // Management of pens, brushes and fonts
283 // ---------------------------------------------------------------------------
285 class WXDLLEXPORT wxPenList
: public wxList
287 DECLARE_DYNAMIC_CLASS(wxPenList
)
293 void AddPen(wxPen
*pen
);
294 void RemovePen(wxPen
*pen
);
295 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
298 class WXDLLEXPORT wxBrushList
: public wxList
300 DECLARE_DYNAMIC_CLASS(wxBrushList
)
306 void AddBrush(wxBrush
*brush
);
307 void RemoveBrush(wxBrush
*brush
);
308 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
311 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
313 class WXDLLEXPORT wxFontList
: public wxList
315 DECLARE_DYNAMIC_CLASS(wxFontList
)
321 void AddFont(wxFont
*font
);
322 void RemoveFont(wxFont
*font
);
323 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
324 bool underline
= FALSE
,
325 const wxString
& face
= wxEmptyString
);
328 class WXDLLEXPORT wxColourDatabase
: public wxList
330 DECLARE_CLASS(wxColourDatabase
)
333 wxColourDatabase(int type
);
334 ~wxColourDatabase() ;
336 // Not const because it may add a name to the database
337 wxColour
*FindColour(const wxString
& colour
) ;
338 wxString
FindName(const wxColour
& colour
) const;
342 class WXDLLEXPORT wxBitmapList
: public wxList
344 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
350 void AddBitmap(wxBitmap
*bitmap
);
351 void RemoveBitmap(wxBitmap
*bitmap
);
354 class WXDLLEXPORT wxResourceCache
: public wxList
357 wxResourceCache() { }
358 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
362 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
365 // ---------------------------------------------------------------------------
367 // ---------------------------------------------------------------------------
369 // Lists of GDI objects
370 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
371 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
372 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
373 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
376 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
377 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
378 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
379 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
381 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
382 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
383 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
384 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
385 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
386 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
387 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
388 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
389 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
390 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
392 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
393 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
394 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
395 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
396 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
397 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
398 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
399 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
400 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
401 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
403 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
404 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
405 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
406 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
407 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
408 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
409 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
412 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
413 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
414 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
415 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
416 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
417 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
418 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
419 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
421 // Stock cursors types
422 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
423 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
424 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
426 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
428 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
430 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
431 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
433 // The list of objects which should be deleted
434 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
436 // ---------------------------------------------------------------------------
438 // ---------------------------------------------------------------------------
440 // resource management
441 extern void WXDLLEXPORT
wxInitializeStockObjects();
442 extern void WXDLLEXPORT
wxInitializeStockLists();
443 extern void WXDLLEXPORT
wxDeleteStockObjects();
444 extern void WXDLLEXPORT
wxDeleteStockLists();
446 // is the display colour (or monochrome)?
447 extern bool WXDLLEXPORT
wxColourDisplay();
449 // Returns depth of screen
450 extern int WXDLLEXPORT
wxDisplayDepth();
451 #define wxGetDisplayDepth wxDisplayDepth
453 // get the diaplay size
454 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
455 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
458 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);