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