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_INVALID
, // should be == 0 for compatibility!
55 wxBITMAP_TYPE_BMP_RESOURCE
,
56 wxBITMAP_TYPE_RESOURCE
= wxBITMAP_TYPE_BMP_RESOURCE
,
58 wxBITMAP_TYPE_ICO_RESOURCE
,
60 wxBITMAP_TYPE_CUR_RESOURCE
,
62 wxBITMAP_TYPE_XBM_DATA
,
64 wxBITMAP_TYPE_XPM_DATA
,
66 wxBITMAP_TYPE_TIF_RESOURCE
,
68 wxBITMAP_TYPE_GIF_RESOURCE
,
70 wxBITMAP_TYPE_PNG_RESOURCE
,
72 wxBITMAP_TYPE_JPEG_RESOURCE
,
74 wxBITMAP_TYPE_PNM_RESOURCE
,
76 wxBITMAP_TYPE_PCX_RESOURCE
,
78 wxBITMAP_TYPE_PICT_RESOURCE
,
80 wxBITMAP_TYPE_ICON_RESOURCE
,
81 wxBITMAP_TYPE_MACCURSOR
,
82 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
83 wxBITMAP_TYPE_ANY
= 50
89 wxCURSOR_NONE
, // should be 0
98 wxCURSOR_MIDDLE_BUTTON
,
100 wxCURSOR_PAINT_BRUSH
,
103 wxCURSOR_POINT_RIGHT
,
104 wxCURSOR_QUESTION_ARROW
,
105 wxCURSOR_RIGHT_BUTTON
,
116 wxCURSOR_DEFAULT
, // standard X11 cursor
119 // Not yet implemented for Windows
120 wxCURSOR_CROSS_REVERSE
,
121 wxCURSOR_DOUBLE_ARROW
,
122 wxCURSOR_BASED_ARROW_UP
,
123 wxCURSOR_BASED_ARROW_DOWN
,
129 // ---------------------------------------------------------------------------
131 // ---------------------------------------------------------------------------
133 /* Useful macro for creating icons portably, for example:
135 wxIcon *icon = new wxICON(mondrian);
139 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
140 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
144 // Load from a resource
145 #define wxICON(X) wxIcon("" #X "")
146 #elif defined(__WXPM__)
147 // Load from a resource
148 #define wxICON(X) wxIcon("" #X "")
149 #elif defined(__WXGTK__)
150 // Initialize from an included XPM
151 #define wxICON(X) wxIcon( (const char**) X##_xpm )
152 #elif defined(__WXMOTIF__)
153 // Initialize from an included XPM
154 #define wxICON(X) wxIcon( X##_xpm )
156 // This will usually mean something on any platform
157 #define wxICON(X) wxIcon("" #X "")
160 /* Another macro: this one is for portable creation of bitmaps. We assume that
161 under Unix bitmaps live in XPMs and under Windows they're in ressources.
164 #if defined(__WXMSW__) || defined(__WXPM__)
165 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
166 #elif defined(__WXGTK__)
167 // Initialize from an included XPM
168 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
169 #else // !(Windows || OS2)
170 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
173 // ===========================================================================
175 // ===========================================================================
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
180 class WXDLLEXPORT wxSize
183 // members are public for compatibility (don't use them directly,
184 // especially that there names were chosen very unfortunately - they should
185 // have been called width and height)
189 wxSize() { x
= y
= 0; }
190 wxSize(int xx
, int yy
) { Set(xx
, yy
); }
192 // no copy ctor or assignment operator - the defaults are ok
193 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
195 // FIXME are these really useful? If they're, we should have += &c as well
196 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
197 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
200 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
201 void SetWidth(int w
) { x
= w
; }
202 void SetHeight(int h
) { y
= h
; }
204 int GetWidth() const { return x
; }
205 int GetHeight() const { return y
; }
208 int GetX() const { return x
; }
209 int GetY() const { return y
; }
212 // ---------------------------------------------------------------------------
213 // Point classes: with real or integer coordinates
214 // ---------------------------------------------------------------------------
216 class WXDLLEXPORT wxRealPoint
222 wxRealPoint() { x
= y
= 0.0; };
223 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
225 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
226 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
228 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
231 class WXDLLEXPORT wxPoint
236 wxPoint() { x
= y
= 0; };
237 wxPoint(int xx
, int yy
) { x
= xx
; y
= yy
; };
239 // no copy ctor or assignment operator - the defaults are ok
242 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
243 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
245 // arithmetic operations (component wise)
246 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
247 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
249 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
250 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
253 #if WXWIN_COMPATIBILITY
254 #define wxIntPoint wxPoint
255 #define wxRectangle wxRect
256 #endif // WXWIN_COMPATIBILITY
258 // ---------------------------------------------------------------------------
260 // ---------------------------------------------------------------------------
262 class WXDLLEXPORT wxRect
265 wxRect() { x
= y
= width
= height
= 0; }
266 wxRect(int xx
, int yy
, int ww
, int hh
)
267 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
268 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
269 wxRect(const wxPoint
& pos
, const wxSize
& size
);
271 // default copy ctor and assignment operators ok
273 int GetX() const { return x
; }
274 void SetX(int xx
) { x
= xx
; }
276 int GetY() const { return y
; }
277 void SetY(int yy
) { y
= yy
; }
279 int GetWidth() const { return width
; }
280 void SetWidth(int w
) { width
= w
; }
282 int GetHeight() const { return height
; }
283 void SetHeight(int h
) { height
= h
; }
285 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
286 wxSize
GetSize() const { return wxSize(width
, height
); }
288 // MFC-like functions
290 int GetLeft() const { return x
; }
291 int GetTop() const { return y
; }
292 int GetBottom() const { return y
+ height
- 1; }
293 int GetRight() const { return x
+ width
- 1; }
295 void SetLeft(int left
) { x
= left
; }
296 void SetRight(int right
) { width
= right
- x
+ 1; }
297 void SetTop(int top
) { y
= top
; }
298 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
300 bool operator==(const wxRect
& rect
) const;
301 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
303 bool Inside(int cx
, int cy
) const;
304 wxRect
operator + (const wxRect
& rect
) const;
305 const wxRect
& operator += (const wxRect
& rect
);
308 int x
, y
, width
, height
;
311 // ---------------------------------------------------------------------------
312 // Management of pens, brushes and fonts
313 // ---------------------------------------------------------------------------
315 class WXDLLEXPORT wxPenList
: public wxList
317 DECLARE_DYNAMIC_CLASS(wxPenList
)
323 void AddPen(wxPen
*pen
);
324 void RemovePen(wxPen
*pen
);
325 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
328 class WXDLLEXPORT wxBrushList
: public wxList
330 DECLARE_DYNAMIC_CLASS(wxBrushList
)
336 void AddBrush(wxBrush
*brush
);
337 void RemoveBrush(wxBrush
*brush
);
338 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
341 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
343 class WXDLLEXPORT wxFontList
: public wxList
345 DECLARE_DYNAMIC_CLASS(wxFontList
)
351 void AddFont(wxFont
*font
);
352 void RemoveFont(wxFont
*font
);
353 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
354 bool underline
= FALSE
,
355 const wxString
& face
= wxEmptyString
,
356 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
359 class WXDLLEXPORT wxColourDatabase
: public wxList
361 DECLARE_CLASS(wxColourDatabase
)
364 wxColourDatabase(int type
);
365 ~wxColourDatabase() ;
367 // Not const because it may add a name to the database
368 wxColour
*FindColour(const wxString
& colour
) ;
369 wxString
FindName(const wxColour
& colour
) const;
373 class WXDLLEXPORT wxBitmapList
: public wxList
375 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
381 void AddBitmap(wxBitmap
*bitmap
);
382 void RemoveBitmap(wxBitmap
*bitmap
);
385 class WXDLLEXPORT wxResourceCache
: public wxList
388 wxResourceCache() { }
389 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
393 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
396 // ---------------------------------------------------------------------------
398 // ---------------------------------------------------------------------------
400 // Lists of GDI objects
401 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
402 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
403 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
404 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
407 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
408 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
409 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
410 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
412 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
413 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
414 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
415 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
416 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
417 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
418 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
419 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
420 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
421 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
423 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
424 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
425 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
426 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
427 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
428 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
429 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
430 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
431 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
432 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
434 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
435 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
436 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
437 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
438 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
439 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
440 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
443 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
444 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
445 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
446 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
447 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
448 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
449 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
450 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
452 // Stock cursors types
453 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
454 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
455 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
457 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
459 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
461 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
462 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
464 // The list of objects which should be deleted
465 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
467 // ---------------------------------------------------------------------------
469 // ---------------------------------------------------------------------------
471 // resource management
472 extern void WXDLLEXPORT
wxInitializeStockObjects();
473 extern void WXDLLEXPORT
wxInitializeStockLists();
474 extern void WXDLLEXPORT
wxDeleteStockObjects();
475 extern void WXDLLEXPORT
wxDeleteStockLists();
477 // is the display colour (or monochrome)?
478 extern bool WXDLLEXPORT
wxColourDisplay();
480 // Returns depth of screen
481 extern int WXDLLEXPORT
wxDisplayDepth();
482 #define wxGetDisplayDepth wxDisplayDepth
484 // get the diaplay size
485 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
486 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
489 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);