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
,
73 wxBITMAP_TYPE_ANY
= 50
79 wxCURSOR_NONE
, // should be 0
88 wxCURSOR_MIDDLE_BUTTON
,
94 wxCURSOR_QUESTION_ARROW
,
95 wxCURSOR_RIGHT_BUTTON
,
106 wxCURSOR_DEFAULT
, // standard X11 cursor
109 // Not yet implemented for Windows
110 wxCURSOR_CROSS_REVERSE
,
111 wxCURSOR_DOUBLE_ARROW
,
112 wxCURSOR_BASED_ARROW_UP
,
113 wxCURSOR_BASED_ARROW_DOWN
,
119 // ---------------------------------------------------------------------------
121 // ---------------------------------------------------------------------------
123 /* Useful macro for creating icons portably, for example:
125 wxIcon *icon = new wxICON(mondrian);
129 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
130 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
134 // Load from a resource
135 #define wxICON(X) wxIcon("" #X "")
136 #elif defined(__WXPM__)
137 // Load from a resource
138 #define wxICON(X) wxIcon("" #X "")
139 #elif defined(__WXGTK__)
140 // Initialize from an included XPM
141 #define wxICON(X) wxIcon( (const char**) X##_xpm )
142 #elif defined(__WXMOTIF__)
143 // Initialize from an included XPM
144 #define wxICON(X) wxIcon( X##_xpm )
146 // This will usually mean something on any platform
147 #define wxICON(X) wxIcon("" #X "")
150 // ===========================================================================
152 // ===========================================================================
154 // ---------------------------------------------------------------------------
156 // ---------------------------------------------------------------------------
157 class WXDLLEXPORT wxSize
160 // members are public for compatibility (don't use them directly,
161 // especially that there names were chosen very unfortunately - they should
162 // have been called width and height)
167 wxSize() { x
= y
= 0; }
168 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
170 // no copy ctor or assignment operator - the defaults are ok
171 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
173 // FIXME are these really useful? If they're, we should have += &c as well
174 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
175 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
178 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
179 void SetWidth(long w
) { x
= w
; }
180 void SetHeight(long h
) { y
= h
; }
182 long GetWidth() const { return x
; }
183 long GetHeight() const { return y
; }
186 long GetX() const { return x
; }
187 long GetY() const { return y
; }
190 // ---------------------------------------------------------------------------
191 // Point classes: with real or integer coordinates
192 // ---------------------------------------------------------------------------
194 class WXDLLEXPORT wxRealPoint
200 wxRealPoint() { x
= y
= 0.0; };
201 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
203 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
204 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
206 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
209 class WXDLLEXPORT wxPoint
212 #if defined(__WXMSW__) && !defined(__WIN32__)
220 wxPoint() { x
= y
= 0; };
221 wxPoint(long xx
, long yy
) { x
= xx
; y
= yy
; };
223 // no copy ctor or assignment operator - the defaults are ok
226 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
227 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
229 // arithmetic operations (component wise)
230 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
231 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
233 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
234 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
237 #if WXWIN_COMPATIBILITY
238 #define wxIntPoint wxPoint
239 #define wxRectangle wxRect
240 #endif // WXWIN_COMPATIBILITY
242 // ---------------------------------------------------------------------------
244 // ---------------------------------------------------------------------------
246 class WXDLLEXPORT wxRect
249 wxRect() { x
= y
= width
= height
= 0; }
250 wxRect(long xx
, long yy
, long ww
, long hh
)
251 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
252 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
253 wxRect(const wxPoint
& pos
, const wxSize
& size
);
255 // default copy ctor and assignment operators ok
257 long GetX() const { return x
; }
258 void SetX(long xx
) { x
= xx
; }
260 long GetY() const { return y
; }
261 void SetY(long yy
) { y
= yy
; }
263 long GetWidth() const { return width
; }
264 void SetWidth(long w
) { width
= w
; }
266 long GetHeight() const { return height
; }
267 void SetHeight(long h
) { height
= h
; }
269 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
270 wxSize
GetSize() const { return wxSize(width
, height
); }
272 // MFC-like functions
274 long GetLeft() const { return x
; }
275 long GetTop() const { return y
; }
276 long GetBottom() const { return y
+ height
- 1; }
277 long GetRight() const { return x
+ width
- 1; }
279 void SetLeft(long left
) { x
= left
; }
280 void SetRight(long right
) { width
= right
- x
+ 1; }
281 void SetTop(long top
) { y
= top
; }
282 void SetBottom(long bottom
) { height
= bottom
- y
+ 1; }
284 bool operator==(const wxRect
& rect
) const;
285 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
287 bool Inside(int cx
, int cy
) const;
288 wxRect
operator + (const wxRect
& rect
) const;
289 const wxRect
& operator += (const wxRect
& rect
);
292 long x
, y
, width
, height
;
295 // ---------------------------------------------------------------------------
296 // Management of pens, brushes and fonts
297 // ---------------------------------------------------------------------------
299 class WXDLLEXPORT wxPenList
: public wxList
301 DECLARE_DYNAMIC_CLASS(wxPenList
)
307 void AddPen(wxPen
*pen
);
308 void RemovePen(wxPen
*pen
);
309 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
312 class WXDLLEXPORT wxBrushList
: public wxList
314 DECLARE_DYNAMIC_CLASS(wxBrushList
)
320 void AddBrush(wxBrush
*brush
);
321 void RemoveBrush(wxBrush
*brush
);
322 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
325 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
327 class WXDLLEXPORT wxFontList
: public wxList
329 DECLARE_DYNAMIC_CLASS(wxFontList
)
335 void AddFont(wxFont
*font
);
336 void RemoveFont(wxFont
*font
);
337 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
338 bool underline
= FALSE
,
339 const wxString
& face
= wxEmptyString
);
342 class WXDLLEXPORT wxColourDatabase
: public wxList
344 DECLARE_CLASS(wxColourDatabase
)
347 wxColourDatabase(int type
);
348 ~wxColourDatabase() ;
350 // Not const because it may add a name to the database
351 wxColour
*FindColour(const wxString
& colour
) ;
352 wxString
FindName(const wxColour
& colour
) const;
356 class WXDLLEXPORT wxBitmapList
: public wxList
358 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
364 void AddBitmap(wxBitmap
*bitmap
);
365 void RemoveBitmap(wxBitmap
*bitmap
);
368 class WXDLLEXPORT wxResourceCache
: public wxList
371 wxResourceCache() { }
372 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
376 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
379 // ---------------------------------------------------------------------------
381 // ---------------------------------------------------------------------------
383 // Lists of GDI objects
384 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
385 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
386 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
387 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
390 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
391 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
392 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
393 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
395 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
396 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
397 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
398 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
399 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
400 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
401 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
402 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
403 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
404 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
406 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
407 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
408 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
409 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
410 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
411 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
412 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
413 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
414 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
415 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
417 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
418 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
419 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
420 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
421 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
422 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
423 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
426 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
427 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
428 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
429 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
430 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
431 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
432 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
433 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
435 // Stock cursors types
436 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
437 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
438 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
440 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
442 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
444 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
445 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
447 // The list of objects which should be deleted
448 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
450 // ---------------------------------------------------------------------------
452 // ---------------------------------------------------------------------------
454 // resource management
455 extern void WXDLLEXPORT
wxInitializeStockObjects();
456 extern void WXDLLEXPORT
wxInitializeStockLists();
457 extern void WXDLLEXPORT
wxDeleteStockObjects();
458 extern void WXDLLEXPORT
wxDeleteStockLists();
460 // is the display colour (or monochrome)?
461 extern bool WXDLLEXPORT
wxColourDisplay();
463 // Returns depth of screen
464 extern int WXDLLEXPORT
wxDisplayDepth();
465 #define wxGetDisplayDepth wxDisplayDepth
467 // get the diaplay size
468 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
469 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
472 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);