Added wxCURSOR_ARROWWAIT which is the default arrow+hourglass cursor
[wxWidgets.git] / include / wx / gdicmn.h
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)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GDICMNH__
13 #define _WX_GDICMNH__
14
15 // ---------------------------------------------------------------------------
16 // headers
17 // ---------------------------------------------------------------------------
18
19 #ifdef __GNUG__
20 #pragma interface "gdicmn.h"
21 #endif
22
23 #include "wx/object.h"
24 #include "wx/list.h"
25 #include "wx/hash.h"
26 #include "wx/string.h"
27 #include "wx/setup.h"
28 #include "wx/colour.h"
29 #include "wx/font.h"
30
31 // ---------------------------------------------------------------------------
32 // forward declarations
33 // ---------------------------------------------------------------------------
34
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;
45
46 // ---------------------------------------------------------------------------
47 // constants
48 // ---------------------------------------------------------------------------
49
50 // Bitmap flags
51 enum wxBitmapType
52 {
53 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
54 wxBITMAP_TYPE_BMP,
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,
73 wxBITMAP_TYPE_PNM,
74 wxBITMAP_TYPE_PNM_RESOURCE,
75 wxBITMAP_TYPE_PCX,
76 wxBITMAP_TYPE_PCX_RESOURCE,
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,
83 wxBITMAP_TYPE_ANY = 50
84 };
85
86 // Standard cursors
87 enum 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,
115 #ifdef __WXGTK__
116 wxCURSOR_DEFAULT, // standard X11 cursor
117 #endif
118 #ifdef __X__
119 // Not yet implemented for Windows
120 wxCURSOR_CROSS_REVERSE,
121 wxCURSOR_DOUBLE_ARROW,
122 wxCURSOR_BASED_ARROW_UP,
123 wxCURSOR_BASED_ARROW_DOWN,
124 #endif // X11
125
126 wxCURSOR_ARROWWAIT,
127
128 wxCURSOR_MAX
129 };
130
131 #ifndef __WXGTK__
132 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
133 #endif
134
135 // ---------------------------------------------------------------------------
136 // macros
137 // ---------------------------------------------------------------------------
138
139 /* Useful macro for creating icons portably, for example:
140
141 wxIcon *icon = new wxICON(mondrian);
142
143 expands into:
144
145 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
146 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
147 */
148
149 #ifdef __WXMSW__
150 // Load from a resource
151 #define wxICON(X) wxIcon("" #X "")
152 #elif defined(__WXPM__)
153 // Load from a resource
154 #define wxICON(X) wxIcon("" #X "")
155 #elif defined(__WXGTK__)
156 // Initialize from an included XPM
157 #define wxICON(X) wxIcon( (const char**) X##_xpm )
158 #elif defined(__WXMOTIF__)
159 // Initialize from an included XPM
160 #define wxICON(X) wxIcon( X##_xpm )
161 #else
162 // This will usually mean something on any platform
163 #define wxICON(X) wxIcon("" #X "")
164 #endif // platform
165
166 /* Another macro: this one is for portable creation of bitmaps. We assume that
167 under Unix bitmaps live in XPMs and under Windows they're in ressources.
168 */
169
170 #if defined(__WXMSW__) || defined(__WXPM__)
171 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
172 #elif defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
173 // Initialize from an included XPM
174 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
175 #else // other platforms
176 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
177 #endif // platform
178
179 // ===========================================================================
180 // classes
181 // ===========================================================================
182
183 // ---------------------------------------------------------------------------
184 // wxSize
185 // ---------------------------------------------------------------------------
186 class WXDLLEXPORT wxSize
187 {
188 public:
189 // members are public for compatibility (don't use them directly,
190 // especially that there names were chosen very unfortunately - they should
191 // have been called width and height)
192 int x, y;
193
194 // constructors
195 wxSize() { x = y = 0; }
196 wxSize(int xx, int yy) { Set(xx, yy); }
197
198 // no copy ctor or assignment operator - the defaults are ok
199 bool operator==(const wxSize& sz) const { return x == sz.x && y == sz.y; }
200
201 // FIXME are these really useful? If they're, we should have += &c as well
202 wxSize operator+(const wxSize& sz) { return wxSize(x + sz.x, y + sz.y); }
203 wxSize operator-(const wxSize& sz) { return wxSize(x - sz.x, y - sz.y); }
204
205 // accessors
206 void Set(int xx, int yy) { x = xx; y = yy; }
207 void SetWidth(int w) { x = w; }
208 void SetHeight(int h) { y = h; }
209
210 int GetWidth() const { return x; }
211 int GetHeight() const { return y; }
212
213 // compatibility
214 int GetX() const { return x; }
215 int GetY() const { return y; }
216 };
217
218 // ---------------------------------------------------------------------------
219 // Point classes: with real or integer coordinates
220 // ---------------------------------------------------------------------------
221
222 class WXDLLEXPORT wxRealPoint
223 {
224 public:
225 double x;
226 double y;
227
228 wxRealPoint() { x = y = 0.0; };
229 wxRealPoint(double xx, double yy) { x = xx; y = yy; };
230
231 wxRealPoint operator+(const wxRealPoint& pt) const { return wxRealPoint(x + pt.x, y + pt.y); }
232 wxRealPoint operator-(const wxRealPoint& pt) const { return wxRealPoint(x - pt.x, y - pt.y); }
233
234 bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; }
235 };
236
237 class WXDLLEXPORT wxPoint
238 {
239 public:
240 int x, y;
241
242 wxPoint() { x = y = 0; };
243 wxPoint(int xx, int yy) { x = xx; y = yy; };
244
245 // no copy ctor or assignment operator - the defaults are ok
246
247 // comparison
248 bool operator==(const wxPoint& p) const { return x == p.x && y == p.y; }
249 bool operator!=(const wxPoint& p) const { return !(*this == p); }
250
251 // arithmetic operations (component wise)
252 wxPoint operator+(const wxPoint& p) const { return wxPoint(x + p.x, y + p.y); }
253 wxPoint operator-(const wxPoint& p) const { return wxPoint(x - p.x, y - p.y); }
254
255 wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
256 wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
257 };
258
259 #if WXWIN_COMPATIBILITY
260 #define wxIntPoint wxPoint
261 #define wxRectangle wxRect
262 #endif // WXWIN_COMPATIBILITY
263
264 // ---------------------------------------------------------------------------
265 // wxRect
266 // ---------------------------------------------------------------------------
267
268 class WXDLLEXPORT wxRect
269 {
270 public:
271 wxRect() { x = y = width = height = 0; }
272 wxRect(int xx, int yy, int ww, int hh)
273 { x = xx; y = yy; width = ww; height = hh; }
274 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
275 wxRect(const wxPoint& pos, const wxSize& size);
276
277 // default copy ctor and assignment operators ok
278
279 int GetX() const { return x; }
280 void SetX(int xx) { x = xx; }
281
282 int GetY() const { return y; }
283 void SetY(int yy) { y = yy; }
284
285 int GetWidth() const { return width; }
286 void SetWidth(int w) { width = w; }
287
288 int GetHeight() const { return height; }
289 void SetHeight(int h) { height = h; }
290
291 wxPoint GetPosition() const { return wxPoint(x, y); }
292 wxSize GetSize() const { return wxSize(width, height); }
293
294 int GetLeft() const { return x; }
295 int GetTop() const { return y; }
296 int GetBottom() const { return y + height - 1; }
297 int GetRight() const { return x + width - 1; }
298
299 void SetLeft(int left) { x = left; }
300 void SetRight(int right) { width = right - x + 1; }
301 void SetTop(int top) { y = top; }
302 void SetBottom(int bottom) { height = bottom - y + 1; }
303
304 void Inflate(wxCoord dx, wxCoord dy)
305 {
306 x -= dx;
307 y -= dy;
308 width += 2*dx;
309 height += 2*dy;
310 }
311
312 void Inflate(wxCoord d) { Inflate(d, d); }
313
314 bool operator==(const wxRect& rect) const;
315 bool operator!=(const wxRect& rect) const { return !(*this == rect); }
316
317 bool Inside(int cx, int cy) const;
318 bool Inside(const wxPoint& pt) const { return Inside(pt.x, pt.y); }
319 wxRect operator+(const wxRect& rect) const;
320 wxRect& operator+=(const wxRect& rect);
321
322 public:
323 int x, y, width, height;
324 };
325
326 // ---------------------------------------------------------------------------
327 // Management of pens, brushes and fonts
328 // ---------------------------------------------------------------------------
329
330 typedef wxInt8 wxDash;
331
332 class WXDLLEXPORT wxPenList : public wxList
333 {
334 DECLARE_DYNAMIC_CLASS(wxPenList)
335
336 public:
337 wxPenList() { }
338 ~wxPenList();
339
340 void AddPen(wxPen *pen);
341 void RemovePen(wxPen *pen);
342 wxPen *FindOrCreatePen(const wxColour& colour, int width, int style);
343 };
344
345 class WXDLLEXPORT wxBrushList : public wxList
346 {
347 DECLARE_DYNAMIC_CLASS(wxBrushList)
348
349 public:
350 wxBrushList() { }
351 ~wxBrushList();
352
353 void AddBrush(wxBrush *brush);
354 void RemoveBrush(wxBrush *brush);
355 wxBrush *FindOrCreateBrush(const wxColour& colour, int style);
356 };
357
358 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
359
360 class WXDLLEXPORT wxFontList : public wxList
361 {
362 DECLARE_DYNAMIC_CLASS(wxFontList)
363
364 public:
365 wxFontList() { }
366 ~wxFontList();
367
368 void AddFont(wxFont *font);
369 void RemoveFont(wxFont *font);
370 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
371 bool underline = FALSE,
372 const wxString& face = wxEmptyString,
373 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
374 };
375
376 class WXDLLEXPORT wxColourDatabase : public wxList
377 {
378 DECLARE_CLASS(wxColourDatabase)
379
380 public:
381 wxColourDatabase(int type);
382 ~wxColourDatabase() ;
383
384 // Not const because it may add a name to the database
385 wxColour *FindColour(const wxString& colour) ;
386 wxString FindName(const wxColour& colour) const;
387 void Initialize();
388 #ifdef __WXPM__
389 // PM keeps its own type of colour table
390 long* m_palTable;
391 size_t m_nSize;
392 #endif
393 };
394
395 class WXDLLEXPORT wxBitmapList : public wxList
396 {
397 DECLARE_DYNAMIC_CLASS(wxBitmapList)
398
399 public:
400 wxBitmapList();
401 ~wxBitmapList();
402
403 void AddBitmap(wxBitmap *bitmap);
404 void RemoveBitmap(wxBitmap *bitmap);
405 };
406
407 class WXDLLEXPORT wxResourceCache: public wxList
408 {
409 public:
410 wxResourceCache() { }
411 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
412 ~wxResourceCache();
413
414 private:
415 DECLARE_DYNAMIC_CLASS(wxResourceCache)
416 };
417
418 // ---------------------------------------------------------------------------
419 // global variables
420 // ---------------------------------------------------------------------------
421
422 // Lists of GDI objects
423 WXDLLEXPORT_DATA(extern wxPenList*) wxThePenList;
424 WXDLLEXPORT_DATA(extern wxBrushList*) wxTheBrushList;
425 WXDLLEXPORT_DATA(extern wxFontList*) wxTheFontList;
426 WXDLLEXPORT_DATA(extern wxBitmapList*) wxTheBitmapList;
427
428 // Stock objects
429 WXDLLEXPORT_DATA(extern wxFont*) wxNORMAL_FONT;
430 WXDLLEXPORT_DATA(extern wxFont*) wxSMALL_FONT;
431 WXDLLEXPORT_DATA(extern wxFont*) wxITALIC_FONT;
432 WXDLLEXPORT_DATA(extern wxFont*) wxSWISS_FONT;
433
434 WXDLLEXPORT_DATA(extern wxPen*) wxRED_PEN;
435 WXDLLEXPORT_DATA(extern wxPen*) wxCYAN_PEN;
436 WXDLLEXPORT_DATA(extern wxPen*) wxGREEN_PEN;
437 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_PEN;
438 WXDLLEXPORT_DATA(extern wxPen*) wxWHITE_PEN;
439 WXDLLEXPORT_DATA(extern wxPen*) wxTRANSPARENT_PEN;
440 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_DASHED_PEN;
441 WXDLLEXPORT_DATA(extern wxPen*) wxGREY_PEN;
442 WXDLLEXPORT_DATA(extern wxPen*) wxMEDIUM_GREY_PEN;
443 WXDLLEXPORT_DATA(extern wxPen*) wxLIGHT_GREY_PEN;
444
445 WXDLLEXPORT_DATA(extern wxBrush*) wxBLUE_BRUSH;
446 WXDLLEXPORT_DATA(extern wxBrush*) wxGREEN_BRUSH;
447 WXDLLEXPORT_DATA(extern wxBrush*) wxWHITE_BRUSH;
448 WXDLLEXPORT_DATA(extern wxBrush*) wxBLACK_BRUSH;
449 WXDLLEXPORT_DATA(extern wxBrush*) wxGREY_BRUSH;
450 WXDLLEXPORT_DATA(extern wxBrush*) wxMEDIUM_GREY_BRUSH;
451 WXDLLEXPORT_DATA(extern wxBrush*) wxLIGHT_GREY_BRUSH;
452 WXDLLEXPORT_DATA(extern wxBrush*) wxTRANSPARENT_BRUSH;
453 WXDLLEXPORT_DATA(extern wxBrush*) wxCYAN_BRUSH;
454 WXDLLEXPORT_DATA(extern wxBrush*) wxRED_BRUSH;
455
456 WXDLLEXPORT_DATA(extern wxColour*) wxBLACK;
457 WXDLLEXPORT_DATA(extern wxColour*) wxWHITE;
458 WXDLLEXPORT_DATA(extern wxColour*) wxRED;
459 WXDLLEXPORT_DATA(extern wxColour*) wxBLUE;
460 WXDLLEXPORT_DATA(extern wxColour*) wxGREEN;
461 WXDLLEXPORT_DATA(extern wxColour*) wxCYAN;
462 WXDLLEXPORT_DATA(extern wxColour*) wxLIGHT_GREY;
463
464 // 'Null' objects
465 WXDLLEXPORT_DATA(extern wxBitmap) wxNullBitmap;
466 WXDLLEXPORT_DATA(extern wxIcon) wxNullIcon;
467 WXDLLEXPORT_DATA(extern wxCursor) wxNullCursor;
468 WXDLLEXPORT_DATA(extern wxPen) wxNullPen;
469 WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
470 WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
471 WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
472 WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
473
474 // Stock cursors types
475 WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;
476 WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
477 WXDLLEXPORT_DATA(extern wxCursor*) wxCROSS_CURSOR;
478
479 WXDLLEXPORT_DATA(extern wxColourDatabase*) wxTheColourDatabase;
480
481 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
482
483 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
484 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
485
486 // The list of objects which should be deleted
487 WXDLLEXPORT_DATA(extern wxList) wxPendingDelete;
488
489 // ---------------------------------------------------------------------------
490 // global functions
491 // ---------------------------------------------------------------------------
492
493 // resource management
494 extern void WXDLLEXPORT wxInitializeStockObjects();
495 extern void WXDLLEXPORT wxInitializeStockLists();
496 extern void WXDLLEXPORT wxDeleteStockObjects();
497 extern void WXDLLEXPORT wxDeleteStockLists();
498
499 // is the display colour (or monochrome)?
500 extern bool WXDLLEXPORT wxColourDisplay();
501
502 // Returns depth of screen
503 extern int WXDLLEXPORT wxDisplayDepth();
504 #define wxGetDisplayDepth wxDisplayDepth
505
506 // get the display size
507 extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
508 extern wxSize WXDLLEXPORT wxGetDisplaySize();
509 extern void WXDLLEXPORT wxDisplaySizeMM(int *width, int *height);
510 extern wxSize WXDLLEXPORT wxGetDisplaySizeMM();
511
512 // set global cursor
513 extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
514
515 #endif
516 // _WX_GDICMNH__