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
,
72 wxBITMAP_TYPE_PNM_RESOURCE
,
74 wxBITMAP_TYPE_PCX_RESOURCE
,
75 wxBITMAP_TYPE_ANY
= 50
81 wxCURSOR_NONE
, // should be 0
90 wxCURSOR_MIDDLE_BUTTON
,
96 wxCURSOR_QUESTION_ARROW
,
97 wxCURSOR_RIGHT_BUTTON
,
108 wxCURSOR_DEFAULT
, // standard X11 cursor
111 // Not yet implemented for Windows
112 wxCURSOR_CROSS_REVERSE
,
113 wxCURSOR_DOUBLE_ARROW
,
114 wxCURSOR_BASED_ARROW_UP
,
115 wxCURSOR_BASED_ARROW_DOWN
,
121 // ---------------------------------------------------------------------------
123 // ---------------------------------------------------------------------------
125 /* Useful macro for creating icons portably, for example:
127 wxIcon *icon = new wxICON(mondrian);
131 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
132 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
136 // Load from a resource
137 #define wxICON(X) wxIcon("" #X "")
138 #elif defined(__WXPM__)
139 // Load from a resource
140 #define wxICON(X) wxIcon("" #X "")
141 #elif defined(__WXGTK__)
142 // Initialize from an included XPM
143 #define wxICON(X) wxIcon( (const char**) X##_xpm )
144 #elif defined(__WXMOTIF__)
145 // Initialize from an included XPM
146 #define wxICON(X) wxIcon( X##_xpm )
148 // This will usually mean something on any platform
149 #define wxICON(X) wxIcon("" #X "")
152 // ===========================================================================
154 // ===========================================================================
156 // ---------------------------------------------------------------------------
158 // ---------------------------------------------------------------------------
159 class WXDLLEXPORT wxSize
162 // members are public for compatibility (don't use them directly,
163 // especially that there names were chosen very unfortunately - they should
164 // have been called width and height)
169 wxSize() { x
= y
= 0; }
170 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
172 // no copy ctor or assignment operator - the defaults are ok
173 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
175 // FIXME are these really useful? If they're, we should have += &c as well
176 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
177 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
180 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
181 void SetWidth(long w
) { x
= w
; }
182 void SetHeight(long h
) { y
= h
; }
184 long GetWidth() const { return x
; }
185 long GetHeight() const { return y
; }
188 long GetX() const { return x
; }
189 long GetY() const { return y
; }
192 // ---------------------------------------------------------------------------
193 // Point classes: with real or integer coordinates
194 // ---------------------------------------------------------------------------
196 class WXDLLEXPORT wxRealPoint
202 wxRealPoint() { x
= y
= 0.0; };
203 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
205 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
206 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
208 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
211 class WXDLLEXPORT wxPoint
214 #if defined(__WXMSW__) && !defined(__WIN32__)
222 wxPoint() { x
= y
= 0; };
223 wxPoint(long xx
, long yy
) { x
= xx
; y
= yy
; };
225 // no copy ctor or assignment operator - the defaults are ok
228 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
229 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
231 // arithmetic operations (component wise)
232 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
233 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
235 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
236 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
239 #if WXWIN_COMPATIBILITY
240 #define wxIntPoint wxPoint
241 #define wxRectangle wxRect
242 #endif // WXWIN_COMPATIBILITY
244 // ---------------------------------------------------------------------------
246 // ---------------------------------------------------------------------------
248 class WXDLLEXPORT wxRect
251 wxRect() { x
= y
= width
= height
= 0; }
252 wxRect(long xx
, long yy
, long ww
, long hh
)
253 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
254 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
255 wxRect(const wxPoint
& pos
, const wxSize
& size
);
257 // default copy ctor and assignment operators ok
259 long GetX() const { return x
; }
260 void SetX(long xx
) { x
= xx
; }
262 long GetY() const { return y
; }
263 void SetY(long yy
) { y
= yy
; }
265 long GetWidth() const { return width
; }
266 void SetWidth(long w
) { width
= w
; }
268 long GetHeight() const { return height
; }
269 void SetHeight(long h
) { height
= h
; }
271 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
272 wxSize
GetSize() const { return wxSize(width
, height
); }
274 // MFC-like functions
276 long GetLeft() const { return x
; }
277 long GetTop() const { return y
; }
278 long GetBottom() const { return y
+ height
- 1; }
279 long GetRight() const { return x
+ width
- 1; }
281 void SetLeft(long left
) { x
= left
; }
282 void SetRight(long right
) { width
= right
- x
+ 1; }
283 void SetTop(long top
) { y
= top
; }
284 void SetBottom(long bottom
) { height
= bottom
- y
+ 1; }
286 bool operator==(const wxRect
& rect
) const;
287 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
289 bool Inside(int cx
, int cy
) const;
290 wxRect
operator + (const wxRect
& rect
) const;
291 const wxRect
& operator += (const wxRect
& rect
);
294 long x
, y
, width
, height
;
297 // ---------------------------------------------------------------------------
298 // Management of pens, brushes and fonts
299 // ---------------------------------------------------------------------------
301 class WXDLLEXPORT wxPenList
: public wxList
303 DECLARE_DYNAMIC_CLASS(wxPenList
)
309 void AddPen(wxPen
*pen
);
310 void RemovePen(wxPen
*pen
);
311 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
314 class WXDLLEXPORT wxBrushList
: public wxList
316 DECLARE_DYNAMIC_CLASS(wxBrushList
)
322 void AddBrush(wxBrush
*brush
);
323 void RemoveBrush(wxBrush
*brush
);
324 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
327 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
329 class WXDLLEXPORT wxFontList
: public wxList
331 DECLARE_DYNAMIC_CLASS(wxFontList
)
337 void AddFont(wxFont
*font
);
338 void RemoveFont(wxFont
*font
);
339 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
340 bool underline
= FALSE
,
341 const wxString
& face
= wxEmptyString
);
344 class WXDLLEXPORT wxColourDatabase
: public wxList
346 DECLARE_CLASS(wxColourDatabase
)
349 wxColourDatabase(int type
);
350 ~wxColourDatabase() ;
352 // Not const because it may add a name to the database
353 wxColour
*FindColour(const wxString
& colour
) ;
354 wxString
FindName(const wxColour
& colour
) const;
358 class WXDLLEXPORT wxBitmapList
: public wxList
360 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
366 void AddBitmap(wxBitmap
*bitmap
);
367 void RemoveBitmap(wxBitmap
*bitmap
);
370 class WXDLLEXPORT wxResourceCache
: public wxList
373 wxResourceCache() { }
374 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
378 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
381 // ---------------------------------------------------------------------------
383 // ---------------------------------------------------------------------------
385 // Lists of GDI objects
386 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
387 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
388 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
389 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
392 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
393 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
394 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
395 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
397 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
398 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
399 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
400 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
401 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
402 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
403 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
404 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
405 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
406 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
408 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
409 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
410 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
411 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
412 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
413 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
414 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
415 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
416 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
417 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
419 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
420 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
421 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
422 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
423 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
424 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
425 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
428 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
429 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
430 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
431 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
432 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
433 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
434 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
435 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
437 // Stock cursors types
438 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
439 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
440 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
442 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
444 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
446 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
447 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
449 // The list of objects which should be deleted
450 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
452 // ---------------------------------------------------------------------------
454 // ---------------------------------------------------------------------------
456 // resource management
457 extern void WXDLLEXPORT
wxInitializeStockObjects();
458 extern void WXDLLEXPORT
wxInitializeStockLists();
459 extern void WXDLLEXPORT
wxDeleteStockObjects();
460 extern void WXDLLEXPORT
wxDeleteStockLists();
462 // is the display colour (or monochrome)?
463 extern bool WXDLLEXPORT
wxColourDisplay();
465 // Returns depth of screen
466 extern int WXDLLEXPORT
wxDisplayDepth();
467 #define wxGetDisplayDepth wxDisplayDepth
469 // get the diaplay size
470 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
471 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
474 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);