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)
179 wxSize() { x
= y
= 0; }
180 wxSize(long xx
, long yy
) { Set(xx
, yy
); }
182 // no copy ctor or assignment operator - the defaults are ok
183 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
185 // FIXME are these really useful? If they're, we should have += &c as well
186 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
187 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
190 void Set(long xx
, long yy
) { x
= xx
; y
= yy
; }
191 void SetWidth(long w
) { x
= w
; }
192 void SetHeight(long h
) { y
= h
; }
194 long GetWidth() const { return x
; }
195 long GetHeight() const { return y
; }
198 long GetX() const { return x
; }
199 long GetY() const { return y
; }
202 // ---------------------------------------------------------------------------
203 // Point classes: with real or integer coordinates
204 // ---------------------------------------------------------------------------
206 class WXDLLEXPORT wxRealPoint
212 wxRealPoint() { x
= y
= 0.0; };
213 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
215 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
216 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
218 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
221 class WXDLLEXPORT wxPoint
224 #if defined(__WXMSW__) && !defined(__WIN32__)
232 wxPoint() { x
= y
= 0; };
233 wxPoint(long xx
, long 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(long xx
, long yy
, long ww
, long 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 long GetX() const { return x
; }
270 void SetX(long xx
) { x
= xx
; }
272 long GetY() const { return y
; }
273 void SetY(long yy
) { y
= yy
; }
275 long GetWidth() const { return width
; }
276 void SetWidth(long w
) { width
= w
; }
278 long GetHeight() const { return height
; }
279 void SetHeight(long h
) { height
= h
; }
281 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
282 wxSize
GetSize() const { return wxSize(width
, height
); }
284 // MFC-like functions
286 long GetLeft() const { return x
; }
287 long GetTop() const { return y
; }
288 long GetBottom() const { return y
+ height
- 1; }
289 long GetRight() const { return x
+ width
- 1; }
291 void SetLeft(long left
) { x
= left
; }
292 void SetRight(long right
) { width
= right
- x
+ 1; }
293 void SetTop(long top
) { y
= top
; }
294 void SetBottom(long 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 long 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
);
354 class WXDLLEXPORT wxColourDatabase
: public wxList
356 DECLARE_CLASS(wxColourDatabase
)
359 wxColourDatabase(int type
);
360 ~wxColourDatabase() ;
362 // Not const because it may add a name to the database
363 wxColour
*FindColour(const wxString
& colour
) ;
364 wxString
FindName(const wxColour
& colour
) const;
368 class WXDLLEXPORT wxBitmapList
: public wxList
370 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
376 void AddBitmap(wxBitmap
*bitmap
);
377 void RemoveBitmap(wxBitmap
*bitmap
);
380 class WXDLLEXPORT wxResourceCache
: public wxList
383 wxResourceCache() { }
384 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
388 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
391 // ---------------------------------------------------------------------------
393 // ---------------------------------------------------------------------------
395 // Lists of GDI objects
396 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
397 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
398 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
399 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
402 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
403 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
404 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
405 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
407 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
408 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
409 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
410 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
411 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
412 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
413 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
414 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
415 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
416 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
418 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
419 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
420 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
421 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
422 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
423 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
424 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
425 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
426 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
427 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
429 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
430 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
431 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
432 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
433 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
434 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
435 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
438 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
439 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
440 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
441 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
442 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
443 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
444 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
445 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
447 // Stock cursors types
448 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
449 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
450 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
452 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
454 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
456 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
457 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
459 // The list of objects which should be deleted
460 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
462 // ---------------------------------------------------------------------------
464 // ---------------------------------------------------------------------------
466 // resource management
467 extern void WXDLLEXPORT
wxInitializeStockObjects();
468 extern void WXDLLEXPORT
wxInitializeStockLists();
469 extern void WXDLLEXPORT
wxDeleteStockObjects();
470 extern void WXDLLEXPORT
wxDeleteStockLists();
472 // is the display colour (or monochrome)?
473 extern bool WXDLLEXPORT
wxColourDisplay();
475 // Returns depth of screen
476 extern int WXDLLEXPORT
wxDisplayDepth();
477 #define wxGetDisplayDepth wxDisplayDepth
479 // get the diaplay size
480 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
481 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
484 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);