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
,
76 wxBITMAP_TYPE_PICT_RESOURCE
,
78 wxBITMAP_TYPE_ICON_RESOURCE
,
79 wxBITMAP_TYPE_MACCURSOR
,
80 wxBITMAP_TYPE_MACCURSOR_RESOURCE
,
81 wxBITMAP_TYPE_ANY
= 50
87 wxCURSOR_NONE
, // should be 0
96 wxCURSOR_MIDDLE_BUTTON
,
101 wxCURSOR_POINT_RIGHT
,
102 wxCURSOR_QUESTION_ARROW
,
103 wxCURSOR_RIGHT_BUTTON
,
114 wxCURSOR_DEFAULT
, // standard X11 cursor
117 // Not yet implemented for Windows
118 wxCURSOR_CROSS_REVERSE
,
119 wxCURSOR_DOUBLE_ARROW
,
120 wxCURSOR_BASED_ARROW_UP
,
121 wxCURSOR_BASED_ARROW_DOWN
,
127 // ---------------------------------------------------------------------------
129 // ---------------------------------------------------------------------------
131 /* Useful macro for creating icons portably, for example:
133 wxIcon *icon = new wxICON(mondrian);
137 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
138 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
142 // Load from a resource
143 #define wxICON(X) wxIcon("" #X "")
144 #elif defined(__WXPM__)
145 // Load from a resource
146 #define wxICON(X) wxIcon("" #X "")
147 #elif defined(__WXGTK__)
148 // Initialize from an included XPM
149 #define wxICON(X) wxIcon( (const char**) X##_xpm )
150 #elif defined(__WXMOTIF__)
151 // Initialize from an included XPM
152 #define wxICON(X) wxIcon( X##_xpm )
154 // This will usually mean something on any platform
155 #define wxICON(X) wxIcon("" #X "")
158 /* Another macro: this one is for portable creation of bitmaps. We assume that
159 under Unix bitmaps live in XPMs and under Windows they're in ressources.
162 #if defined(__WXMSW__) || defined(__WXPM__)
163 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
164 #else // !(Windows || OS2)
165 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
168 // ===========================================================================
170 // ===========================================================================
172 // ---------------------------------------------------------------------------
174 // ---------------------------------------------------------------------------
175 class WXDLLEXPORT wxSize
178 // members are public for compatibility (don't use them directly,
179 // especially that there names were chosen very unfortunately - they should
180 // have been called width and height)
184 wxSize() { x
= y
= 0; }
185 wxSize(int xx
, int yy
) { Set(xx
, yy
); }
187 // no copy ctor or assignment operator - the defaults are ok
188 bool operator==(const wxSize
& sz
) const { return x
== sz
.x
&& y
== sz
.y
; }
190 // FIXME are these really useful? If they're, we should have += &c as well
191 wxSize
operator+(const wxSize
& sz
) { return wxSize(x
+ sz
.x
, y
+ sz
.y
); }
192 wxSize
operator-(const wxSize
& sz
) { return wxSize(x
- sz
.x
, y
- sz
.y
); }
195 void Set(int xx
, int yy
) { x
= xx
; y
= yy
; }
196 void SetWidth(int w
) { x
= w
; }
197 void SetHeight(int h
) { y
= h
; }
199 int GetWidth() const { return x
; }
200 int GetHeight() const { return y
; }
203 int GetX() const { return x
; }
204 int GetY() const { return y
; }
207 // ---------------------------------------------------------------------------
208 // Point classes: with real or integer coordinates
209 // ---------------------------------------------------------------------------
211 class WXDLLEXPORT wxRealPoint
217 wxRealPoint() { x
= y
= 0.0; };
218 wxRealPoint(double xx
, double yy
) { x
= xx
; y
= yy
; };
220 wxRealPoint
operator+(const wxRealPoint
& pt
) { return wxRealPoint(x
+ pt
.x
, y
+ pt
.y
); }
221 wxRealPoint
operator-(const wxRealPoint
& pt
) { return wxRealPoint(x
- pt
.x
, y
- pt
.y
); }
223 bool operator==(const wxRealPoint
& pt
) const { return x
== pt
.x
&& y
== pt
.y
; }
226 class WXDLLEXPORT wxPoint
231 wxPoint() { x
= y
= 0; };
232 wxPoint(int xx
, int yy
) { x
= xx
; y
= yy
; };
234 // no copy ctor or assignment operator - the defaults are ok
237 bool operator==(const wxPoint
& p
) const { return x
== p
.x
&& y
== p
.y
; }
238 bool operator!=(const wxPoint
& p
) const { return !(*this == p
); }
240 // arithmetic operations (component wise)
241 wxPoint
operator+(const wxPoint
& p
) { return wxPoint(x
+ p
.x
, y
+ p
.y
); }
242 wxPoint
operator-(const wxPoint
& p
) { return wxPoint(x
- p
.x
, y
- p
.y
); }
244 wxPoint
& operator+=(const wxPoint
& p
) { x
+= p
.x
; y
+= p
.y
; return *this; }
245 wxPoint
& operator-=(const wxPoint
& p
) { x
-= p
.x
; y
-= p
.y
; return *this; }
248 #if WXWIN_COMPATIBILITY
249 #define wxIntPoint wxPoint
250 #define wxRectangle wxRect
251 #endif // WXWIN_COMPATIBILITY
253 // ---------------------------------------------------------------------------
255 // ---------------------------------------------------------------------------
257 class WXDLLEXPORT wxRect
260 wxRect() { x
= y
= width
= height
= 0; }
261 wxRect(int xx
, int yy
, int ww
, int hh
)
262 { x
= xx
; y
= yy
; width
= ww
; height
= hh
; }
263 wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
264 wxRect(const wxPoint
& pos
, const wxSize
& size
);
266 // default copy ctor and assignment operators ok
268 int GetX() const { return x
; }
269 void SetX(int xx
) { x
= xx
; }
271 int GetY() const { return y
; }
272 void SetY(int yy
) { y
= yy
; }
274 int GetWidth() const { return width
; }
275 void SetWidth(int w
) { width
= w
; }
277 int GetHeight() const { return height
; }
278 void SetHeight(int h
) { height
= h
; }
280 wxPoint
GetPosition() const { return wxPoint(x
, y
); }
281 wxSize
GetSize() const { return wxSize(width
, height
); }
283 // MFC-like functions
285 int GetLeft() const { return x
; }
286 int GetTop() const { return y
; }
287 int GetBottom() const { return y
+ height
- 1; }
288 int GetRight() const { return x
+ width
- 1; }
290 void SetLeft(int left
) { x
= left
; }
291 void SetRight(int right
) { width
= right
- x
+ 1; }
292 void SetTop(int top
) { y
= top
; }
293 void SetBottom(int bottom
) { height
= bottom
- y
+ 1; }
295 bool operator==(const wxRect
& rect
) const;
296 bool operator!=(const wxRect
& rect
) const { return !(*this == rect
); }
298 bool Inside(int cx
, int cy
) const;
299 wxRect
operator + (const wxRect
& rect
) const;
300 const wxRect
& operator += (const wxRect
& rect
);
303 int x
, y
, width
, height
;
306 // ---------------------------------------------------------------------------
307 // Management of pens, brushes and fonts
308 // ---------------------------------------------------------------------------
310 class WXDLLEXPORT wxPenList
: public wxList
312 DECLARE_DYNAMIC_CLASS(wxPenList
)
318 void AddPen(wxPen
*pen
);
319 void RemovePen(wxPen
*pen
);
320 wxPen
*FindOrCreatePen(const wxColour
& colour
, int width
, int style
);
323 class WXDLLEXPORT wxBrushList
: public wxList
325 DECLARE_DYNAMIC_CLASS(wxBrushList
)
331 void AddBrush(wxBrush
*brush
);
332 void RemoveBrush(wxBrush
*brush
);
333 wxBrush
*FindOrCreateBrush(const wxColour
& colour
, int style
);
336 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
338 class WXDLLEXPORT wxFontList
: public wxList
340 DECLARE_DYNAMIC_CLASS(wxFontList
)
346 void AddFont(wxFont
*font
);
347 void RemoveFont(wxFont
*font
);
348 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
349 bool underline
= FALSE
,
350 const wxString
& face
= wxEmptyString
);
353 class WXDLLEXPORT wxColourDatabase
: public wxList
355 DECLARE_CLASS(wxColourDatabase
)
358 wxColourDatabase(int type
);
359 ~wxColourDatabase() ;
361 // Not const because it may add a name to the database
362 wxColour
*FindColour(const wxString
& colour
) ;
363 wxString
FindName(const wxColour
& colour
) const;
367 class WXDLLEXPORT wxBitmapList
: public wxList
369 DECLARE_DYNAMIC_CLASS(wxBitmapList
)
375 void AddBitmap(wxBitmap
*bitmap
);
376 void RemoveBitmap(wxBitmap
*bitmap
);
379 class WXDLLEXPORT wxResourceCache
: public wxList
382 wxResourceCache() { }
383 wxResourceCache(const unsigned int keyType
) : wxList(keyType
) { }
387 DECLARE_DYNAMIC_CLASS(wxResourceCache
)
390 // ---------------------------------------------------------------------------
392 // ---------------------------------------------------------------------------
394 // Lists of GDI objects
395 WXDLLEXPORT_DATA(extern wxPenList
*) wxThePenList
;
396 WXDLLEXPORT_DATA(extern wxBrushList
*) wxTheBrushList
;
397 WXDLLEXPORT_DATA(extern wxFontList
*) wxTheFontList
;
398 WXDLLEXPORT_DATA(extern wxBitmapList
*) wxTheBitmapList
;
401 WXDLLEXPORT_DATA(extern wxFont
*) wxNORMAL_FONT
;
402 WXDLLEXPORT_DATA(extern wxFont
*) wxSMALL_FONT
;
403 WXDLLEXPORT_DATA(extern wxFont
*) wxITALIC_FONT
;
404 WXDLLEXPORT_DATA(extern wxFont
*) wxSWISS_FONT
;
406 WXDLLEXPORT_DATA(extern wxPen
*) wxRED_PEN
;
407 WXDLLEXPORT_DATA(extern wxPen
*) wxCYAN_PEN
;
408 WXDLLEXPORT_DATA(extern wxPen
*) wxGREEN_PEN
;
409 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_PEN
;
410 WXDLLEXPORT_DATA(extern wxPen
*) wxWHITE_PEN
;
411 WXDLLEXPORT_DATA(extern wxPen
*) wxTRANSPARENT_PEN
;
412 WXDLLEXPORT_DATA(extern wxPen
*) wxBLACK_DASHED_PEN
;
413 WXDLLEXPORT_DATA(extern wxPen
*) wxGREY_PEN
;
414 WXDLLEXPORT_DATA(extern wxPen
*) wxMEDIUM_GREY_PEN
;
415 WXDLLEXPORT_DATA(extern wxPen
*) wxLIGHT_GREY_PEN
;
417 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLUE_BRUSH
;
418 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREEN_BRUSH
;
419 WXDLLEXPORT_DATA(extern wxBrush
*) wxWHITE_BRUSH
;
420 WXDLLEXPORT_DATA(extern wxBrush
*) wxBLACK_BRUSH
;
421 WXDLLEXPORT_DATA(extern wxBrush
*) wxGREY_BRUSH
;
422 WXDLLEXPORT_DATA(extern wxBrush
*) wxMEDIUM_GREY_BRUSH
;
423 WXDLLEXPORT_DATA(extern wxBrush
*) wxLIGHT_GREY_BRUSH
;
424 WXDLLEXPORT_DATA(extern wxBrush
*) wxTRANSPARENT_BRUSH
;
425 WXDLLEXPORT_DATA(extern wxBrush
*) wxCYAN_BRUSH
;
426 WXDLLEXPORT_DATA(extern wxBrush
*) wxRED_BRUSH
;
428 WXDLLEXPORT_DATA(extern wxColour
*) wxBLACK
;
429 WXDLLEXPORT_DATA(extern wxColour
*) wxWHITE
;
430 WXDLLEXPORT_DATA(extern wxColour
*) wxRED
;
431 WXDLLEXPORT_DATA(extern wxColour
*) wxBLUE
;
432 WXDLLEXPORT_DATA(extern wxColour
*) wxGREEN
;
433 WXDLLEXPORT_DATA(extern wxColour
*) wxCYAN
;
434 WXDLLEXPORT_DATA(extern wxColour
*) wxLIGHT_GREY
;
437 WXDLLEXPORT_DATA(extern wxBitmap
) wxNullBitmap
;
438 WXDLLEXPORT_DATA(extern wxIcon
) wxNullIcon
;
439 WXDLLEXPORT_DATA(extern wxCursor
) wxNullCursor
;
440 WXDLLEXPORT_DATA(extern wxPen
) wxNullPen
;
441 WXDLLEXPORT_DATA(extern wxBrush
) wxNullBrush
;
442 WXDLLEXPORT_DATA(extern wxPalette
) wxNullPalette
;
443 WXDLLEXPORT_DATA(extern wxFont
) wxNullFont
;
444 WXDLLEXPORT_DATA(extern wxColour
) wxNullColour
;
446 // Stock cursors types
447 WXDLLEXPORT_DATA(extern wxCursor
*) wxSTANDARD_CURSOR
;
448 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
449 WXDLLEXPORT_DATA(extern wxCursor
*) wxCROSS_CURSOR
;
451 WXDLLEXPORT_DATA(extern wxColourDatabase
*) wxTheColourDatabase
;
453 WXDLLEXPORT_DATA(extern const wxChar
*) wxPanelNameStr
;
455 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
456 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
458 // The list of objects which should be deleted
459 WXDLLEXPORT_DATA(extern wxList
) wxPendingDelete
;
461 // ---------------------------------------------------------------------------
463 // ---------------------------------------------------------------------------
465 // resource management
466 extern void WXDLLEXPORT
wxInitializeStockObjects();
467 extern void WXDLLEXPORT
wxInitializeStockLists();
468 extern void WXDLLEXPORT
wxDeleteStockObjects();
469 extern void WXDLLEXPORT
wxDeleteStockLists();
471 // is the display colour (or monochrome)?
472 extern bool WXDLLEXPORT
wxColourDisplay();
474 // Returns depth of screen
475 extern int WXDLLEXPORT
wxDisplayDepth();
476 #define wxGetDisplayDepth wxDisplayDepth
478 // get the diaplay size
479 extern void WXDLLEXPORT
wxDisplaySize(int *width
, int *height
);
480 extern wxSize WXDLLEXPORT
wxGetDisplaySize();
483 extern void WXDLLEXPORT
wxSetCursor(const wxCursor
& cursor
);