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_BMP
= 1,
54 wxBITMAP_TYPE_BMP_RESOURCE
,
55 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
57 wxBITMAP_TYPE_ICO_RESOURCE
,
59 wxBITMAP_TYPE_CUR_RESOURCE
,
61 wxBITMAP_TYPE_XBM_DATA
,
63 wxBITMAP_TYPE_XPM_DATA
,
65 wxBITMAP_TYPE_TIF_RESOURCE
,
67 wxBITMAP_TYPE_GIF_RESOURCE
,
69 wxBITMAP_TYPE_PNG_RESOURCE
,
71 wxBITMAP_TYPE_JPEG_RESOURCE
,
73 wxBITMAP_TYPE_PNM_RESOURCE
,
75 wxBITMAP_TYPE_PCX_RESOURCE
,
77 wxBITMAP_TYPE_PICT_RESOURCE
,
79 wxBITMAP_TYPE_ICON_RESOURCE
,
80 wxBITMAP_TYPE_MACCURSOR
,
81 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
82 wxBITMAP_TYPE_ANY
= 50
88 wxCURSOR_NONE
, // should be 0
97 wxCURSOR_MIDDLE_BUTTON
,
102 wxCURSOR_POINT_RIGHT
,
103 wxCURSOR_QUESTION_ARROW
,
104 wxCURSOR_RIGHT_BUTTON
,
115 wxCURSOR_DEFAULT
, // standard X11 cursor
118 // Not yet implemented for Windows
119 wxCURSOR_CROSS_REVERSE
,
120 wxCURSOR_DOUBLE_ARROW
,
121 wxCURSOR_BASED_ARROW_UP
,
122 wxCURSOR_BASED_ARROW_DOWN
,
128 // ---------------------------------------------------------------------------
130 // ---------------------------------------------------------------------------
132 /* Useful macro for creating icons portably, for example:
134 wxIcon *icon = new wxICON(mondrian);
138 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
139 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
143 // Load from a resource
144 #define wxICON(X) wxIcon("" #X "")
145 #elif defined(__WXPM__)
146 // Load from a resource
147 #define wxICON(X) wxIcon("" #X "")
148 #elif defined(__WXGTK__)
149 // Initialize from an included XPM
150 #define wxICON(X) wxIcon( (const char**) X##_xpm )
151 #elif defined(__WXMOTIF__)
152 // Initialize from an included XPM
153 #define wxICON(X) wxIcon( X##_xpm )
155 // This will usually mean something on any platform
156 #define wxICON(X) wxIcon("" #X "")
159 /* Another macro: this one is for portable creation of bitmaps. We assume that
160 under Unix bitmaps live in XPMs and under Windows they're in ressources.
163 #if defined(__WXMSW__) || defined(__WXPM__)
164 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
165 #else // !(Windows || OS2)
166 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
169 // ===========================================================================
171 // ===========================================================================
173 // ---------------------------------------------------------------------------
175 // ---------------------------------------------------------------------------
176 class WXDLLEXPORT wxSize
179 // members are public for compatibility (don't use them directly,
180 // especially that there names were chosen very unfortunately - they should
181 // have been called width and height)
185 wxSize() { x
= y
= 0; }
186 wxSize(int xx
, int yy
) { Set(xx
, yy
); }
188 // no copy ctor or assignment operator - the defaults are ok
189 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
191 // FIXME are these really useful? If they're, we should have += &c as well
192 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
193 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
196 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
197 void SetWidth(int w
) { x
= w
; }
198 void SetHeight(int h
) { y
= h
; }
200 int GetWidth() const { return x
; }
201 int GetHeight() const { return y
; }
204 int GetX() const { return x
; }
205 int GetY() const { return y
; }
208 // ---------------------------------------------------------------------------
209 // Point classes: with real or integer coordinates
210 // ---------------------------------------------------------------------------
212 class WXDLLEXPORT wxRealPoint
218 wxRealPoint() { x
= y
= 0.0; };
219 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
221 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
222 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
224 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
227 class WXDLLEXPORT wxPoint
232 wxPoint() { x
= y
= 0; };
233 wxPoint(int xx
, int yy
) { x
= xx
; y
= yy
; };
235 // no copy ctor or assignment operator - the defaults are ok
238 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
239 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
241 // arithmetic operations (component wise)
242 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
243 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
245 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
246 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
249 #if WXWIN_COMPATIBILITY
250 #define wxIntPoint wxPoint
251 #define wxRectangle wxRect
252 #endif // WXWIN_COMPATIBILITY
254 // ---------------------------------------------------------------------------
256 // ---------------------------------------------------------------------------
258 class WXDLLEXPORT wxRect
261 wxRect() { x
= y
= width
= height
= 0; }
262 wxRect(int xx
, int yy
, int ww
, int hh
)
263 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
264 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
265 wxRect(const wxPoint
& pos
, const wxSize
& size
);
267 // default copy ctor and assignment operators ok
269 int GetX() const { return x
; }
270 void SetX(int xx
) { x
= xx
; }
272 int GetY() const { return y
; }
273 void SetY(int yy
) { y
= yy
; }
275 int GetWidth() const { return width
; }
276 void SetWidth(int w
) { width
= w
; }
278 int GetHeight() const { return height
; }
279 void SetHeight(int h
) { height
= h
; }
281 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
282 wxSize
GetSize() const { return wxSize(width
, height
); }
284 // MFC-like functions
286 int GetLeft() const { return x
; }
287 int GetTop() const { return y
; }
288 int GetBottom() const { return y
+ height
- 1; }
289 int GetRight() const { return x
+ width
- 1; }
291 void SetLeft(int left
) { x
= left
; }
292 void SetRight(int right
) { width
= right
- x
+ 1; }
293 void SetTop(int top
) { y
= top
; }
294 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
296 bool operator==(const wxRect
& rect
) const;
297 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
299 bool Inside(int cx
, int cy
) const;
300 wxRect
operator + (const wxRect
& rect
) const;
301 const wxRect
& operator += (const wxRect
& rect
);
304 int x
, y
, width
, height
;
307 // ---------------------------------------------------------------------------
308 // Management of pens, brushes and fonts
309 // ---------------------------------------------------------------------------
311 class WXDLLEXPORT wxPenList
: public wxList
313 DECLARE_DYNAMIC_CLASS(wxPenList
)
319 void AddPen(wxPen
*pen
);
320 void RemovePen(wxPen
*pen
);
321 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
324 class WXDLLEXPORT wxBrushList
: public wxList
326 DECLARE_DYNAMIC_CLASS(wxBrushList
)
332 void AddBrush(wxBrush
*brush
);
333 void RemoveBrush(wxBrush
*brush
);
334 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
337 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
339 class WXDLLEXPORT wxFontList
: public wxList
341 DECLARE_DYNAMIC_CLASS(wxFontList
)
347 void AddFont(wxFont
*font
);
348 void RemoveFont(wxFont
*font
);
349 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
350 bool underline
= FALSE
,
351 const wxString
& face
= wxEmptyString
,
352 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
355 class WXDLLEXPORT wxColourDatabase
: public wxList
357 DECLARE_CLASS(wxColourDatabase
)
360 wxColourDatabase(int type
);
361 ~wxColourDatabase() ;
363 // Not const because it may add a name to the database
364 wxColour
*FindColour(const wxString
& colour
) ;
365 wxString
FindName(const wxColour
& colour
) const;
369 class WXDLLEXPORT wxBitmapList
: public wxList
371 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
377 void AddBitmap(wxBitmap
*bitmap
);
378 void RemoveBitmap(wxBitmap
*bitmap
);
381 class WXDLLEXPORT wxResourceCache
: public wxList
384 wxResourceCache() { }
385 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
389 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
392 // ---------------------------------------------------------------------------
394 // ---------------------------------------------------------------------------
396 // Lists of GDI objects
397 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
398 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
399 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
400 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
403 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
404 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
405 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
406 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
408 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
409 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
410 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
411 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
412 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
413 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
414 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
415 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
416 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
417 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
419 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
420 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
421 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
422 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
423 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
424 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
425 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
426 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
427 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
428 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
430 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
431 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
432 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
433 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
434 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
435 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
436 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
439 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
440 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
441 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
442 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
443 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
444 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
445 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
446 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
448 // Stock cursors types
449 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
450 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
451 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
453 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
455 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
457 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
458 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
460 // The list of objects which should be deleted
461 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
463 // ---------------------------------------------------------------------------
465 // ---------------------------------------------------------------------------
467 // resource management
468 extern void WXDLLEXPORT
wxInitializeStockObjects();
469 extern void WXDLLEXPORT
wxInitializeStockLists();
470 extern void WXDLLEXPORT
wxDeleteStockObjects();
471 extern void WXDLLEXPORT
wxDeleteStockLists();
473 // is the display colour (or monochrome)?
474 extern bool WXDLLEXPORT
wxColourDisplay();
476 // Returns depth of screen
477 extern int WXDLLEXPORT
wxDisplayDepth();
478 #define wxGetDisplayDepth wxDisplayDepth
480 // get the diaplay size
481 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
482 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
485 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);