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 /* Another macro: this one is for portable creation of bitmaps. We assume that
153 under Unix bitmaps live in XPMs and under Windows they're in ressources.
156 #if defined(__WXMSW__) || defined(__WXPM__)
157 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
158 #else // !(Windows || OS2)
159 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
162 // ===========================================================================
164 // ===========================================================================
166 // ---------------------------------------------------------------------------
168 // ---------------------------------------------------------------------------
169 class WXDLLEXPORT wxSize
172 // members are public for compatibility (don't use them directly,
173 // especially that there names were chosen very unfortunately - they should
174 // have been called width and height)
178 wxSize() { x
= y
= 0; }
179 wxSize(int xx
, int yy
) { Set(xx
, yy
); }
181 // no copy ctor or assignment operator - the defaults are ok
182 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
184 // FIXME are these really useful? If they're, we should have += &c as well
185 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
186 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
189 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
190 void SetWidth(int w
) { x
= w
; }
191 void SetHeight(int h
) { y
= h
; }
193 int GetWidth() const { return x
; }
194 int GetHeight() const { return y
; }
197 int GetX() const { return x
; }
198 int GetY() const { return y
; }
201 // ---------------------------------------------------------------------------
202 // Point classes: with real or integer coordinates
203 // ---------------------------------------------------------------------------
205 class WXDLLEXPORT wxRealPoint
211 wxRealPoint() { x
= y
= 0.0; };
212 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
214 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
215 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
217 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
220 class WXDLLEXPORT wxPoint
225 wxPoint() { x
= y
= 0; };
226 wxPoint(int xx
, int yy
) { x
= xx
; y
= yy
; };
228 // no copy ctor or assignment operator - the defaults are ok
231 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
232 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
234 // arithmetic operations (component wise)
235 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
236 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
238 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
239 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
242 #if WXWIN_COMPATIBILITY
243 #define wxIntPoint wxPoint
244 #define wxRectangle wxRect
245 #endif // WXWIN_COMPATIBILITY
247 // ---------------------------------------------------------------------------
249 // ---------------------------------------------------------------------------
251 class WXDLLEXPORT wxRect
254 wxRect() { x
= y
= width
= height
= 0; }
255 wxRect(int xx
, int yy
, int ww
, int hh
)
256 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
257 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
258 wxRect(const wxPoint
& pos
, const wxSize
& size
);
260 // default copy ctor and assignment operators ok
262 int GetX() const { return x
; }
263 void SetX(int xx
) { x
= xx
; }
265 int GetY() const { return y
; }
266 void SetY(int yy
) { y
= yy
; }
268 int GetWidth() const { return width
; }
269 void SetWidth(int w
) { width
= w
; }
271 int GetHeight() const { return height
; }
272 void SetHeight(int h
) { height
= h
; }
274 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
275 wxSize
GetSize() const { return wxSize(width
, height
); }
277 // MFC-like functions
279 int GetLeft() const { return x
; }
280 int GetTop() const { return y
; }
281 int GetBottom() const { return y
+ height
- 1; }
282 int GetRight() const { return x
+ width
- 1; }
284 void SetLeft(int left
) { x
= left
; }
285 void SetRight(int right
) { width
= right
- x
+ 1; }
286 void SetTop(int top
) { y
= top
; }
287 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
289 bool operator==(const wxRect
& rect
) const;
290 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
292 bool Inside(int cx
, int cy
) const;
293 wxRect
operator + (const wxRect
& rect
) const;
294 const wxRect
& operator += (const wxRect
& rect
);
297 int x
, y
, width
, height
;
300 // ---------------------------------------------------------------------------
301 // Management of pens, brushes and fonts
302 // ---------------------------------------------------------------------------
304 class WXDLLEXPORT wxPenList
: public wxList
306 DECLARE_DYNAMIC_CLASS(wxPenList
)
312 void AddPen(wxPen
*pen
);
313 void RemovePen(wxPen
*pen
);
314 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
317 class WXDLLEXPORT wxBrushList
: public wxList
319 DECLARE_DYNAMIC_CLASS(wxBrushList
)
325 void AddBrush(wxBrush
*brush
);
326 void RemoveBrush(wxBrush
*brush
);
327 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
330 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
332 class WXDLLEXPORT wxFontList
: public wxList
334 DECLARE_DYNAMIC_CLASS(wxFontList
)
340 void AddFont(wxFont
*font
);
341 void RemoveFont(wxFont
*font
);
342 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
343 bool underline
= FALSE
,
344 const wxString
& face
= wxEmptyString
);
347 class WXDLLEXPORT wxColourDatabase
: public wxList
349 DECLARE_CLASS(wxColourDatabase
)
352 wxColourDatabase(int type
);
353 ~wxColourDatabase() ;
355 // Not const because it may add a name to the database
356 wxColour
*FindColour(const wxString
& colour
) ;
357 wxString
FindName(const wxColour
& colour
) const;
361 class WXDLLEXPORT wxBitmapList
: public wxList
363 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
369 void AddBitmap(wxBitmap
*bitmap
);
370 void RemoveBitmap(wxBitmap
*bitmap
);
373 class WXDLLEXPORT wxResourceCache
: public wxList
376 wxResourceCache() { }
377 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
381 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
384 // ---------------------------------------------------------------------------
386 // ---------------------------------------------------------------------------
388 // Lists of GDI objects
389 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
390 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
391 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
392 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
395 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
396 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
397 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
398 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
400 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
401 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
402 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
403 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
404 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
405 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
406 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
407 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
408 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
409 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
411 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
412 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
413 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
414 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
415 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
416 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
417 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
418 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
419 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
420 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
422 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
423 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
424 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
425 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
426 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
427 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
428 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
431 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
432 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
433 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
434 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
435 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
436 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
437 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
438 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
440 // Stock cursors types
441 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
442 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
443 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
445 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
447 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
449 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
450 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
452 // The list of objects which should be deleted
453 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
455 // ---------------------------------------------------------------------------
457 // ---------------------------------------------------------------------------
459 // resource management
460 extern void WXDLLEXPORT
wxInitializeStockObjects();
461 extern void WXDLLEXPORT
wxInitializeStockLists();
462 extern void WXDLLEXPORT
wxDeleteStockObjects();
463 extern void WXDLLEXPORT
wxDeleteStockLists();
465 // is the display colour (or monochrome)?
466 extern bool WXDLLEXPORT
wxColourDisplay();
468 // Returns depth of screen
469 extern int WXDLLEXPORT
wxDisplayDepth();
470 #define wxGetDisplayDepth wxDisplayDepth
472 // get the diaplay size
473 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
474 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
477 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);