]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gdicmn.h
1. wxIcon/wxCursor change, wxGDIImage class added
[wxWidgets.git] / include / wx / gdicmn.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: gdicmn.h
3// Purpose: Common GDI classes, types and declarations
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c)
f03fc89f 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_GDICMNH__
13#define _WX_GDICMNH__
c801d85f 14
f03fc89f
VZ
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
18
c801d85f 19#ifdef __GNUG__
f03fc89f 20 #pragma interface "gdicmn.h"
c801d85f
KB
21#endif
22
23#include "wx/object.h"
24#include "wx/list.h"
25#include "wx/hash.h"
34138703 26#include "wx/string.h"
c801d85f 27#include "wx/setup.h"
34138703 28#include "wx/colour.h"
37bebc11 29#include "wx/font.h"
c801d85f 30
f03fc89f
VZ
31// ---------------------------------------------------------------------------
32// forward declarations
33// ---------------------------------------------------------------------------
34
35class WXDLLEXPORT wxBitmap;
36class WXDLLEXPORT wxBrush;
37class WXDLLEXPORT wxColour;
38class WXDLLEXPORT wxCursor;
39class WXDLLEXPORT wxFont;
40class WXDLLEXPORT wxIcon;
41class WXDLLEXPORT wxPalette;
42class WXDLLEXPORT wxPen;
43class WXDLLEXPORT wxRegion;
44class WXDLLEXPORT wxString;
45
46// ---------------------------------------------------------------------------
47// constants
48// ---------------------------------------------------------------------------
49
50// Bitmap flags
51enum
52{
6d167489
VZ
53 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
54 wxBITMAP_TYPE_BMP,
f03fc89f
VZ
55 wxBITMAP_TYPE_BMP_RESOURCE,
56 wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
57 wxBITMAP_TYPE_ICO,
58 wxBITMAP_TYPE_ICO_RESOURCE,
59 wxBITMAP_TYPE_CUR,
60 wxBITMAP_TYPE_CUR_RESOURCE,
61 wxBITMAP_TYPE_XBM,
62 wxBITMAP_TYPE_XBM_DATA,
63 wxBITMAP_TYPE_XPM,
64 wxBITMAP_TYPE_XPM_DATA,
65 wxBITMAP_TYPE_TIF,
66 wxBITMAP_TYPE_TIF_RESOURCE,
67 wxBITMAP_TYPE_GIF,
68 wxBITMAP_TYPE_GIF_RESOURCE,
69 wxBITMAP_TYPE_PNG,
70 wxBITMAP_TYPE_PNG_RESOURCE,
71 wxBITMAP_TYPE_JPEG,
72 wxBITMAP_TYPE_JPEG_RESOURCE,
bcc46c75
SB
73 wxBITMAP_TYPE_PNM,
74 wxBITMAP_TYPE_PNM_RESOURCE,
6523d119
GRG
75 wxBITMAP_TYPE_PCX,
76 wxBITMAP_TYPE_PCX_RESOURCE,
6d167489
VZ
77 wxBITMAP_TYPE_PICT,
78 wxBITMAP_TYPE_PICT_RESOURCE,
79 wxBITMAP_TYPE_ICON,
80 wxBITMAP_TYPE_ICON_RESOURCE,
81 wxBITMAP_TYPE_MACCURSOR,
82 wxBITMAP_TYPE_MACCURSOR_RESOURCE,
f03fc89f
VZ
83 wxBITMAP_TYPE_ANY = 50
84};
85
c801d85f 86// Standard cursors
f03fc89f
VZ
87enum wxStockCursor
88{
89 wxCURSOR_NONE, // should be 0
90 wxCURSOR_ARROW,
91 wxCURSOR_BULLSEYE,
92 wxCURSOR_CHAR,
93 wxCURSOR_CROSS,
94 wxCURSOR_HAND,
95 wxCURSOR_IBEAM,
96 wxCURSOR_LEFT_BUTTON,
97 wxCURSOR_MAGNIFIER,
98 wxCURSOR_MIDDLE_BUTTON,
99 wxCURSOR_NO_ENTRY,
100 wxCURSOR_PAINT_BRUSH,
101 wxCURSOR_PENCIL,
102 wxCURSOR_POINT_LEFT,
103 wxCURSOR_POINT_RIGHT,
104 wxCURSOR_QUESTION_ARROW,
105 wxCURSOR_RIGHT_BUTTON,
106 wxCURSOR_SIZENESW,
107 wxCURSOR_SIZENS,
108 wxCURSOR_SIZENWSE,
109 wxCURSOR_SIZEWE,
110 wxCURSOR_SIZING,
111 wxCURSOR_SPRAYCAN,
112 wxCURSOR_WAIT,
113 wxCURSOR_WATCH,
114 wxCURSOR_BLANK,
ae53c98c
KB
115#ifdef __WXGTK__
116 wxCURSOR_DEFAULT, // standard X11 cursor
117#endif
c801d85f 118#ifdef __X__
f03fc89f
VZ
119 // Not yet implemented for Windows
120 wxCURSOR_CROSS_REVERSE,
121 wxCURSOR_DOUBLE_ARROW,
122 wxCURSOR_BASED_ARROW_UP,
ea804aad 123 wxCURSOR_BASED_ARROW_DOWN,
f03fc89f
VZ
124#endif // X11
125
126 wxCURSOR_MAX
127};
128
129// ---------------------------------------------------------------------------
130// macros
131// ---------------------------------------------------------------------------
132
133/* Useful macro for creating icons portably, for example:
134
135 wxIcon *icon = new wxICON(mondrian);
136
137 expands into:
138
139 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
140 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
141 */
142
143#ifdef __WXMSW__
144 // Load from a resource
145 #define wxICON(X) wxIcon("" #X "")
1777b9bb
DW
146#elif defined(__WXPM__)
147 // Load from a resource
148 #define wxICON(X) wxIcon("" #X "")
f03fc89f
VZ
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 )
155#else
156 // This will usually mean something on any platform
157 #define wxICON(X) wxIcon("" #X "")
158#endif // platform
159
0c5d3e1c
VZ
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.
162 */
163
164#if defined(__WXMSW__) || defined(__WXPM__)
165 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
166#else // !(Windows || OS2)
167 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
168#endif // platform
169
f03fc89f
VZ
170// ===========================================================================
171// classes
172// ===========================================================================
c801d85f 173
f03fc89f
VZ
174// ---------------------------------------------------------------------------
175// wxSize
176// ---------------------------------------------------------------------------
6a6c0a8b 177class WXDLLEXPORT wxSize
c801d85f
KB
178{
179public:
cc775580
VZ
180 // members are public for compatibility (don't use them directly,
181 // especially that there names were chosen very unfortunately - they should
182 // have been called width and height)
72cdf4c9 183 int x, y;
f03fc89f
VZ
184
185 // constructors
186 wxSize() { x = y = 0; }
72cdf4c9 187 wxSize(int xx, int yy) { Set(xx, yy); }
f03fc89f
VZ
188
189 // no copy ctor or assignment operator - the defaults are ok
f03fc89f
VZ
190 bool operator==(const wxSize& sz) const { return x == sz.x && y == sz.y; }
191
192 // FIXME are these really useful? If they're, we should have += &c as well
193 wxSize operator+(const wxSize& sz) { return wxSize(x + sz.x, y + sz.y); }
194 wxSize operator-(const wxSize& sz) { return wxSize(x - sz.x, y - sz.y); }
195
cc775580 196 // accessors
72cdf4c9
VZ
197 void Set(int xx, int yy) { x = xx; y = yy; }
198 void SetWidth(int w) { x = w; }
199 void SetHeight(int h) { y = h; }
cc775580 200
72cdf4c9
VZ
201 int GetWidth() const { return x; }
202 int GetHeight() const { return y; }
f03fc89f 203
cc775580 204 // compatibility
72cdf4c9
VZ
205 int GetX() const { return x; }
206 int GetY() const { return y; }
c801d85f
KB
207};
208
f03fc89f
VZ
209// ---------------------------------------------------------------------------
210// Point classes: with real or integer coordinates
211// ---------------------------------------------------------------------------
764a3a49 212
6a6c0a8b 213class WXDLLEXPORT wxRealPoint
c801d85f 214{
f03fc89f
VZ
215public:
216 double x;
217 double y;
218
219 wxRealPoint() { x = y = 0.0; };
220 wxRealPoint(double xx, double yy) { x = xx; y = yy; };
221
222 wxRealPoint operator+(const wxRealPoint& pt) { return wxRealPoint(x + pt.x, y + pt.y); }
223 wxRealPoint operator-(const wxRealPoint& pt) { return wxRealPoint(x - pt.x, y - pt.y); }
224
225 bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; }
c801d85f
KB
226};
227
6a6c0a8b 228class WXDLLEXPORT wxPoint
c801d85f 229{
f03fc89f 230public:
72cdf4c9 231 int x, y;
6a6c0a8b 232
f03fc89f 233 wxPoint() { x = y = 0; };
72cdf4c9 234 wxPoint(int xx, int yy) { x = xx; y = yy; };
f03fc89f
VZ
235
236 // no copy ctor or assignment operator - the defaults are ok
6a6c0a8b 237
764a3a49
VZ
238 // comparison
239 bool operator==(const wxPoint& p) const { return x == p.x && y == p.y; }
240 bool operator!=(const wxPoint& p) const { return !(*this == p); }
241
242 // arithmetic operations (component wise)
243 wxPoint operator+(const wxPoint& p) { return wxPoint(x + p.x, y + p.y); }
244 wxPoint operator-(const wxPoint& p) { return wxPoint(x - p.x, y - p.y); }
f03fc89f 245
764a3a49
VZ
246 wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
247 wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
c801d85f
KB
248};
249
250#if WXWIN_COMPATIBILITY
f03fc89f
VZ
251 #define wxIntPoint wxPoint
252 #define wxRectangle wxRect
253#endif // WXWIN_COMPATIBILITY
254
255// ---------------------------------------------------------------------------
256// wxRect
257// ---------------------------------------------------------------------------
c801d85f 258
6a6c0a8b
JS
259class WXDLLEXPORT wxRect
260{
c801d85f 261public:
a23fd0e1 262 wxRect() { x = y = width = height = 0; }
72cdf4c9 263 wxRect(int xx, int yy, int ww, int hh)
a23fd0e1 264 { x = xx; y = yy; width = ww; height = hh; }
f03fc89f
VZ
265 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
266 wxRect(const wxPoint& pos, const wxSize& size);
a23fd0e1
VZ
267
268 // default copy ctor and assignment operators ok
c801d85f 269
72cdf4c9
VZ
270 int GetX() const { return x; }
271 void SetX(int xx) { x = xx; }
c801d85f 272
72cdf4c9
VZ
273 int GetY() const { return y; }
274 void SetY(int yy) { y = yy; }
c801d85f 275
72cdf4c9
VZ
276 int GetWidth() const { return width; }
277 void SetWidth(int w) { width = w; }
c801d85f 278
72cdf4c9
VZ
279 int GetHeight() const { return height; }
280 void SetHeight(int h) { height = h; }
f03fc89f 281
dcb44466
JS
282 wxPoint GetPosition() const { return wxPoint(x, y); }
283 wxSize GetSize() const { return wxSize(width, height); }
f03fc89f 284
f3c0f9e7
JS
285 // MFC-like functions
286
72cdf4c9
VZ
287 int GetLeft() const { return x; }
288 int GetTop() const { return y; }
289 int GetBottom() const { return y + height - 1; }
290 int GetRight() const { return x + width - 1; }
f03fc89f 291
72cdf4c9
VZ
292 void SetLeft(int left) { x = left; }
293 void SetRight(int right) { width = right - x + 1; }
294 void SetTop(int top) { y = top; }
295 void SetBottom(int bottom) { height = bottom - y + 1; }
dcb44466 296
764a3a49
VZ
297 bool operator==(const wxRect& rect) const;
298 bool operator!=(const wxRect& rect) const { return !(*this == rect); }
f03fc89f 299
7742598f 300 bool Inside(int cx, int cy) const;
dcb44466
JS
301 wxRect operator + (const wxRect& rect) const;
302 const wxRect& operator += (const wxRect& rect);
72cdf4c9 303
f03fc89f 304public:
72cdf4c9 305 int x, y, width, height;
f03fc89f 306};
c801d85f 307
f03fc89f 308// ---------------------------------------------------------------------------
c801d85f 309// Management of pens, brushes and fonts
f03fc89f
VZ
310// ---------------------------------------------------------------------------
311
312class WXDLLEXPORT wxPenList : public wxList
c801d85f 313{
f03fc89f
VZ
314 DECLARE_DYNAMIC_CLASS(wxPenList)
315
316public:
317 wxPenList() { }
318 ~wxPenList();
319
320 void AddPen(wxPen *pen);
321 void RemovePen(wxPen *pen);
322 wxPen *FindOrCreatePen(const wxColour& colour, int width, int style);
c801d85f
KB
323};
324
f03fc89f 325class WXDLLEXPORT wxBrushList : public wxList
c801d85f 326{
f03fc89f
VZ
327 DECLARE_DYNAMIC_CLASS(wxBrushList)
328
329public:
330 wxBrushList() { }
331 ~wxBrushList();
332
333 void AddBrush(wxBrush *brush);
334 void RemoveBrush(wxBrush *brush);
335 wxBrush *FindOrCreateBrush(const wxColour& colour, int style);
c801d85f
KB
336};
337
9d2f3c71 338WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
c801d85f 339
f03fc89f 340class WXDLLEXPORT wxFontList : public wxList
c801d85f 341{
f03fc89f
VZ
342 DECLARE_DYNAMIC_CLASS(wxFontList)
343
344public:
345 wxFontList() { }
346 ~wxFontList();
347
348 void AddFont(wxFont *font);
349 void RemoveFont(wxFont *font);
350 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
351 bool underline = FALSE,
37bebc11
RD
352 const wxString& face = wxEmptyString,
353 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
c801d85f
KB
354};
355
f03fc89f 356class WXDLLEXPORT wxColourDatabase : public wxList
c801d85f 357{
f03fc89f
VZ
358 DECLARE_CLASS(wxColourDatabase)
359
360public:
361 wxColourDatabase(int type);
362 ~wxColourDatabase() ;
363
364 // Not const because it may add a name to the database
365 wxColour *FindColour(const wxString& colour) ;
366 wxString FindName(const wxColour& colour) const;
367 void Initialize();
c801d85f
KB
368};
369
f03fc89f 370class WXDLLEXPORT wxBitmapList : public wxList
c801d85f 371{
f03fc89f 372 DECLARE_DYNAMIC_CLASS(wxBitmapList)
c801d85f 373
f03fc89f
VZ
374public:
375 wxBitmapList();
376 ~wxBitmapList();
377
378 void AddBitmap(wxBitmap *bitmap);
379 void RemoveBitmap(wxBitmap *bitmap);
c801d85f
KB
380};
381
f03fc89f
VZ
382class WXDLLEXPORT wxResourceCache: public wxList
383{
384public:
385 wxResourceCache() { }
386 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
387 ~wxResourceCache();
388
389private:
390 DECLARE_DYNAMIC_CLASS(wxResourceCache)
391};
392
393// ---------------------------------------------------------------------------
394// global variables
395// ---------------------------------------------------------------------------
396
c801d85f 397// Lists of GDI objects
f03fc89f
VZ
398WXDLLEXPORT_DATA(extern wxPenList*) wxThePenList;
399WXDLLEXPORT_DATA(extern wxBrushList*) wxTheBrushList;
400WXDLLEXPORT_DATA(extern wxFontList*) wxTheFontList;
401WXDLLEXPORT_DATA(extern wxBitmapList*) wxTheBitmapList;
c801d85f
KB
402
403// Stock objects
f03fc89f
VZ
404WXDLLEXPORT_DATA(extern wxFont*) wxNORMAL_FONT;
405WXDLLEXPORT_DATA(extern wxFont*) wxSMALL_FONT;
406WXDLLEXPORT_DATA(extern wxFont*) wxITALIC_FONT;
407WXDLLEXPORT_DATA(extern wxFont*) wxSWISS_FONT;
408
409WXDLLEXPORT_DATA(extern wxPen*) wxRED_PEN;
410WXDLLEXPORT_DATA(extern wxPen*) wxCYAN_PEN;
411WXDLLEXPORT_DATA(extern wxPen*) wxGREEN_PEN;
412WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_PEN;
413WXDLLEXPORT_DATA(extern wxPen*) wxWHITE_PEN;
414WXDLLEXPORT_DATA(extern wxPen*) wxTRANSPARENT_PEN;
415WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_DASHED_PEN;
416WXDLLEXPORT_DATA(extern wxPen*) wxGREY_PEN;
417WXDLLEXPORT_DATA(extern wxPen*) wxMEDIUM_GREY_PEN;
418WXDLLEXPORT_DATA(extern wxPen*) wxLIGHT_GREY_PEN;
419
420WXDLLEXPORT_DATA(extern wxBrush*) wxBLUE_BRUSH;
421WXDLLEXPORT_DATA(extern wxBrush*) wxGREEN_BRUSH;
422WXDLLEXPORT_DATA(extern wxBrush*) wxWHITE_BRUSH;
423WXDLLEXPORT_DATA(extern wxBrush*) wxBLACK_BRUSH;
424WXDLLEXPORT_DATA(extern wxBrush*) wxGREY_BRUSH;
425WXDLLEXPORT_DATA(extern wxBrush*) wxMEDIUM_GREY_BRUSH;
426WXDLLEXPORT_DATA(extern wxBrush*) wxLIGHT_GREY_BRUSH;
427WXDLLEXPORT_DATA(extern wxBrush*) wxTRANSPARENT_BRUSH;
428WXDLLEXPORT_DATA(extern wxBrush*) wxCYAN_BRUSH;
429WXDLLEXPORT_DATA(extern wxBrush*) wxRED_BRUSH;
430
431WXDLLEXPORT_DATA(extern wxColour*) wxBLACK;
432WXDLLEXPORT_DATA(extern wxColour*) wxWHITE;
433WXDLLEXPORT_DATA(extern wxColour*) wxRED;
434WXDLLEXPORT_DATA(extern wxColour*) wxBLUE;
435WXDLLEXPORT_DATA(extern wxColour*) wxGREEN;
436WXDLLEXPORT_DATA(extern wxColour*) wxCYAN;
437WXDLLEXPORT_DATA(extern wxColour*) wxLIGHT_GREY;
c801d85f
KB
438
439// 'Null' objects
f03fc89f
VZ
440WXDLLEXPORT_DATA(extern wxBitmap) wxNullBitmap;
441WXDLLEXPORT_DATA(extern wxIcon) wxNullIcon;
442WXDLLEXPORT_DATA(extern wxCursor) wxNullCursor;
443WXDLLEXPORT_DATA(extern wxPen) wxNullPen;
444WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
445WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
446WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
447WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
c801d85f
KB
448
449// Stock cursors types
f03fc89f
VZ
450WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;
451WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
452WXDLLEXPORT_DATA(extern wxCursor*) wxCROSS_CURSOR;
453
454WXDLLEXPORT_DATA(extern wxColourDatabase*) wxTheColourDatabase;
455
456WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
c801d85f 457
f03fc89f
VZ
458WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
459WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
460
461// The list of objects which should be deleted
462WXDLLEXPORT_DATA(extern wxList) wxPendingDelete;
463
464// ---------------------------------------------------------------------------
465// global functions
466// ---------------------------------------------------------------------------
467
468// resource management
6a6c0a8b 469extern void WXDLLEXPORT wxInitializeStockObjects();
a3622daa 470extern void WXDLLEXPORT wxInitializeStockLists();
6a6c0a8b 471extern void WXDLLEXPORT wxDeleteStockObjects();
a3622daa 472extern void WXDLLEXPORT wxDeleteStockLists();
c801d85f 473
f03fc89f 474// is the display colour (or monochrome)?
6a6c0a8b 475extern bool WXDLLEXPORT wxColourDisplay();
c801d85f
KB
476
477// Returns depth of screen
6a6c0a8b
JS
478extern int WXDLLEXPORT wxDisplayDepth();
479#define wxGetDisplayDepth wxDisplayDepth
c801d85f 480
f03fc89f 481// get the diaplay size
c801d85f 482extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
6a6c0a8b 483extern wxSize WXDLLEXPORT wxGetDisplaySize();
c801d85f 484
f03fc89f 485// set global cursor
c801d85f
KB
486extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
487
c801d85f 488#endif
34138703 489 // _WX_GDICMNH__