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
,
71 wxBITMAP_TYPE_ANY
= 50
77 wxCURSOR_NONE
, // should be 0
86 wxCURSOR_MIDDLE_BUTTON
,
92 wxCURSOR_QUESTION_ARROW
,
93 wxCURSOR_RIGHT_BUTTON
,
104 wxCURSOR_DEFAULT
, // standard X11 cursor
107 // Not yet implemented for Windows
108 wxCURSOR_CROSS_REVERSE
,
109 wxCURSOR_DOUBLE_ARROW
,
110 wxCURSOR_BASED_ARROW_UP
,
111 wxCURSOR_BASED_ARROW_DOWN
,
117 // ---------------------------------------------------------------------------
119 // ---------------------------------------------------------------------------
121 /* Useful macro for creating icons portably, for example:
123 wxIcon *icon = new wxICON(mondrian);
127 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
128 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
132 // Load from a resource
133 #define wxICON(X) wxIcon("" #X "")
134 #elif defined(__WXGTK__)
135 // Initialize from an included XPM
136 #define wxICON(X) wxIcon( (const char**) X##_xpm )
137 #elif defined(__WXMOTIF__)
138 // Initialize from an included XPM
139 #define wxICON(X) wxIcon( X##_xpm )
141 // This will usually mean something on any platform
142 #define wxICON(X) wxIcon("" #X "")
145 // ===========================================================================
147 // ===========================================================================
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
152 class WXDLLEXPORT wxSize
155 // members are public for compatibility (don't use them directly,
156 // especially that there names were chosen very unfortunately - they should
157 // have been called width and height)
162 wxSize() { x
= y
= 0; }
163 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
165 // no copy ctor or assignment operator - the defaults are ok
166 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
168 // FIXME are these really useful? If they're, we should have += &c as well
169 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
170 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
173 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
174 void SetWidth(long w
) { x
= w
; }
175 void SetHeight(long h
) { y
= h
; }
177 long GetWidth() const { return x
; }
178 long GetHeight() const { return y
; }
181 long GetX() const { return x
; }
182 long GetY() const { return y
; }
185 // ---------------------------------------------------------------------------
186 // Point classes: with real or integer coordinates
187 // ---------------------------------------------------------------------------
189 class WXDLLEXPORT wxRealPoint
195 wxRealPoint() { x
= y
= 0.0; };
196 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
198 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
199 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
201 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
204 class WXDLLEXPORT wxPoint
207 #if defined(__WXMSW__) && !defined(__WIN32__)
215 wxPoint() { x
= y
= 0; };
216 wxPoint(long xx
, long yy
) { x
= xx
; y
= yy
; };
218 // no copy ctor or assignment operator - the defaults are ok
221 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
222 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
224 // arithmetic operations (component wise)
225 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
226 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
228 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
229 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
232 #if WXWIN_COMPATIBILITY
233 #define wxIntPoint wxPoint
234 #define wxRectangle wxRect
235 #endif // WXWIN_COMPATIBILITY
237 // ---------------------------------------------------------------------------
239 // ---------------------------------------------------------------------------
241 class WXDLLEXPORT wxRect
244 wxRect() { x
= y
= width
= height
= 0; }
245 wxRect(long xx
, long yy
, long ww
, long hh
)
246 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
247 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
248 wxRect(const wxPoint
& pos
, const wxSize
& size
);
250 // default copy ctor and assignment operators ok
252 long GetX() const { return x
; }
253 void SetX(long xx
) { x
= xx
; }
255 long GetY() const { return y
; }
256 void SetY(long yy
) { y
= yy
; }
258 long GetWidth() const { return width
; }
259 void SetWidth(long w
) { width
= w
; }
261 long GetHeight() const { return height
; }
262 void SetHeight(long h
) { height
= h
; }
264 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
265 wxSize
GetSize() const { return wxSize(width
, height
); }
267 // MFC-like functions
269 long GetLeft() const { return x
; }
270 long GetTop() const { return y
; }
271 long GetBottom() const { return y
+ height
- 1; }
272 long GetRight() const { return x
+ width
- 1; }
274 void SetLeft(long left
) { x
= left
; }
275 void SetRight(long right
) { width
= right
- x
+ 1; }
276 void SetTop(long top
) { y
= top
; }
277 void SetBottom(long bottom
) { height
= bottom
- y
+ 1; }
279 bool operator==(const wxRect
& rect
) const;
280 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
282 bool Inside(int cx
, int cy
) const;
283 wxRect
operator + (const wxRect
& rect
) const;
284 const wxRect
& operator += (const wxRect
& rect
);
287 long x
, y
, width
, height
;
290 // ---------------------------------------------------------------------------
291 // Management of pens, brushes and fonts
292 // ---------------------------------------------------------------------------
294 class WXDLLEXPORT wxPenList
: public wxList
296 DECLARE_DYNAMIC_CLASS(wxPenList
)
302 void AddPen(wxPen
*pen
);
303 void RemovePen(wxPen
*pen
);
304 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
307 class WXDLLEXPORT wxBrushList
: public wxList
309 DECLARE_DYNAMIC_CLASS(wxBrushList
)
315 void AddBrush(wxBrush
*brush
);
316 void RemoveBrush(wxBrush
*brush
);
317 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
320 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
322 class WXDLLEXPORT wxFontList
: public wxList
324 DECLARE_DYNAMIC_CLASS(wxFontList
)
330 void AddFont(wxFont
*font
);
331 void RemoveFont(wxFont
*font
);
332 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
333 bool underline
= FALSE
,
334 const wxString
& face
= wxEmptyString
);
337 class WXDLLEXPORT wxColourDatabase
: public wxList
339 DECLARE_CLASS(wxColourDatabase
)
342 wxColourDatabase(int type
);
343 ~wxColourDatabase() ;
345 // Not const because it may add a name to the database
346 wxColour
*FindColour(const wxString
& colour
) ;
347 wxString
FindName(const wxColour
& colour
) const;
351 class WXDLLEXPORT wxBitmapList
: public wxList
353 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
359 void AddBitmap(wxBitmap
*bitmap
);
360 void RemoveBitmap(wxBitmap
*bitmap
);
363 class WXDLLEXPORT wxResourceCache
: public wxList
366 wxResourceCache() { }
367 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
371 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
374 // ---------------------------------------------------------------------------
376 // ---------------------------------------------------------------------------
378 // Lists of GDI objects
379 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
380 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
381 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
382 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
385 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
386 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
387 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
388 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
390 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
391 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
392 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
393 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
394 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
395 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
396 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
397 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
398 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
399 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
401 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
402 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
403 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
404 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
405 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
406 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
407 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
408 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
409 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
410 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
412 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
413 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
414 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
415 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
416 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
417 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
418 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
421 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
422 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
423 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
424 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
425 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
426 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
427 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
428 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
430 // Stock cursors types
431 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
432 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
433 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
435 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
437 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
439 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
440 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
442 // The list of objects which should be deleted
443 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
445 // ---------------------------------------------------------------------------
447 // ---------------------------------------------------------------------------
449 // resource management
450 extern void WXDLLEXPORT
wxInitializeStockObjects();
451 extern void WXDLLEXPORT
wxInitializeStockLists();
452 extern void WXDLLEXPORT
wxDeleteStockObjects();
453 extern void WXDLLEXPORT
wxDeleteStockLists();
455 // is the display colour (or monochrome)?
456 extern bool WXDLLEXPORT
wxColourDisplay();
458 // Returns depth of screen
459 extern int WXDLLEXPORT
wxDisplayDepth();
460 #define wxGetDisplayDepth wxDisplayDepth
462 // get the diaplay size
463 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
464 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
467 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);