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