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