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