]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gdicmn.h
restored previously removed inline
[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{
6d167489
VZ
53 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
54 wxBITMAP_TYPE_BMP,
f03fc89f
VZ
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,
bcc46c75
SB
73 wxBITMAP_TYPE_PNM,
74 wxBITMAP_TYPE_PNM_RESOURCE,
6523d119
GRG
75 wxBITMAP_TYPE_PCX,
76 wxBITMAP_TYPE_PCX_RESOURCE,
6d167489
VZ
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,
f03fc89f
VZ
83 wxBITMAP_TYPE_ANY = 50
84};
85
c801d85f 86// Standard cursors
f03fc89f
VZ
87enum 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,
ae53c98c
KB
115#ifdef __WXGTK__
116 wxCURSOR_DEFAULT, // standard X11 cursor
117#endif
c801d85f 118#ifdef __X__
f03fc89f
VZ
119 // Not yet implemented for Windows
120 wxCURSOR_CROSS_REVERSE,
121 wxCURSOR_DOUBLE_ARROW,
122 wxCURSOR_BASED_ARROW_UP,
ea804aad 123 wxCURSOR_BASED_ARROW_DOWN,
f03fc89f
VZ
124#endif // X11
125
126 wxCURSOR_MAX
127};
128
943d28e4
VZ
129#ifndef __WXGTK__
130 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
131#endif
132
f03fc89f
VZ
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 "")
1777b9bb
DW
150#elif defined(__WXPM__)
151 // Load from a resource
152 #define wxICON(X) wxIcon("" #X "")
f03fc89f
VZ
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
0c5d3e1c
VZ
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)
d015713e 170#elif defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
bab537dc
VS
171 // Initialize from an included XPM
172 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
b8aa1680 173#else // other platforms
0c5d3e1c
VZ
174 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
175#endif // platform
176
f03fc89f
VZ
177// ===========================================================================
178// classes
179// ===========================================================================
c801d85f 180
f03fc89f
VZ
181// ---------------------------------------------------------------------------
182// wxSize
183// ---------------------------------------------------------------------------
6a6c0a8b 184class WXDLLEXPORT wxSize
c801d85f
KB
185{
186public:
cc775580
VZ
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)
72cdf4c9 190 int x, y;
f03fc89f
VZ
191
192 // constructors
193 wxSize() { x = y = 0; }
72cdf4c9 194 wxSize(int xx, int yy) { Set(xx, yy); }
f03fc89f
VZ
195
196 // no copy ctor or assignment operator - the defaults are ok
f03fc89f
VZ
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
cc775580 203 // accessors
72cdf4c9
VZ
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; }
cc775580 207
72cdf4c9
VZ
208 int GetWidth() const { return x; }
209 int GetHeight() const { return y; }
f03fc89f 210
cc775580 211 // compatibility
72cdf4c9
VZ
212 int GetX() const { return x; }
213 int GetY() const { return y; }
c801d85f
KB
214};
215
f03fc89f
VZ
216// ---------------------------------------------------------------------------
217// Point classes: with real or integer coordinates
218// ---------------------------------------------------------------------------
764a3a49 219
6a6c0a8b 220class WXDLLEXPORT wxRealPoint
c801d85f 221{
f03fc89f
VZ
222public:
223 double x;
224 double y;
225
226 wxRealPoint() { x = y = 0.0; };
227 wxRealPoint(double xx, double yy) { x = xx; y = yy; };
228
f6bcfd97
BP
229 wxRealPoint operator+(const wxRealPoint& pt) const { return wxRealPoint(x + pt.x, y + pt.y); }
230 wxRealPoint operator-(const wxRealPoint& pt) const { return wxRealPoint(x - pt.x, y - pt.y); }
f03fc89f
VZ
231
232 bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; }
c801d85f
KB
233};
234
6a6c0a8b 235class WXDLLEXPORT wxPoint
c801d85f 236{
f03fc89f 237public:
72cdf4c9 238 int x, y;
6a6c0a8b 239
f03fc89f 240 wxPoint() { x = y = 0; };
72cdf4c9 241 wxPoint(int xx, int yy) { x = xx; y = yy; };
f03fc89f
VZ
242
243 // no copy ctor or assignment operator - the defaults are ok
6a6c0a8b 244
764a3a49
VZ
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)
f6bcfd97
BP
250 wxPoint operator+(const wxPoint& p) const { return wxPoint(x + p.x, y + p.y); }
251 wxPoint operator-(const wxPoint& p) const { return wxPoint(x - p.x, y - p.y); }
f03fc89f 252
764a3a49
VZ
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; }
c801d85f
KB
255};
256
257#if WXWIN_COMPATIBILITY
f03fc89f
VZ
258 #define wxIntPoint wxPoint
259 #define wxRectangle wxRect
260#endif // WXWIN_COMPATIBILITY
261
262// ---------------------------------------------------------------------------
263// wxRect
264// ---------------------------------------------------------------------------
c801d85f 265
6a6c0a8b
JS
266class WXDLLEXPORT wxRect
267{
c801d85f 268public:
a23fd0e1 269 wxRect() { x = y = width = height = 0; }
72cdf4c9 270 wxRect(int xx, int yy, int ww, int hh)
a23fd0e1 271 { x = xx; y = yy; width = ww; height = hh; }
f03fc89f
VZ
272 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
273 wxRect(const wxPoint& pos, const wxSize& size);
a23fd0e1
VZ
274
275 // default copy ctor and assignment operators ok
c801d85f 276
72cdf4c9
VZ
277 int GetX() const { return x; }
278 void SetX(int xx) { x = xx; }
c801d85f 279
72cdf4c9
VZ
280 int GetY() const { return y; }
281 void SetY(int yy) { y = yy; }
c801d85f 282
72cdf4c9
VZ
283 int GetWidth() const { return width; }
284 void SetWidth(int w) { width = w; }
c801d85f 285
72cdf4c9
VZ
286 int GetHeight() const { return height; }
287 void SetHeight(int h) { height = h; }
f03fc89f 288
dcb44466
JS
289 wxPoint GetPosition() const { return wxPoint(x, y); }
290 wxSize GetSize() const { return wxSize(width, height); }
f03fc89f 291
72cdf4c9
VZ
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; }
f03fc89f 296
72cdf4c9
VZ
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; }
dcb44466 301
45816ddd
VZ
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
764a3a49
VZ
312 bool operator==(const wxRect& rect) const;
313 bool operator!=(const wxRect& rect) const { return !(*this == rect); }
f03fc89f 314
7742598f 315 bool Inside(int cx, int cy) const;
59a12e90 316 bool Inside(const wxPoint& pt) const { return Inside(pt.x, pt.y); }
45816ddd
VZ
317 wxRect operator+(const wxRect& rect) const;
318 wxRect& operator+=(const wxRect& rect);
72cdf4c9 319
f03fc89f 320public:
72cdf4c9 321 int x, y, width, height;
f03fc89f 322};
c801d85f 323
f03fc89f 324// ---------------------------------------------------------------------------
c801d85f 325// Management of pens, brushes and fonts
f03fc89f
VZ
326// ---------------------------------------------------------------------------
327
236a9de3
RL
328typedef wxInt8 wxDash;
329
f03fc89f 330class WXDLLEXPORT wxPenList : public wxList
c801d85f 331{
f03fc89f
VZ
332 DECLARE_DYNAMIC_CLASS(wxPenList)
333
334public:
335 wxPenList() { }
336 ~wxPenList();
337
338 void AddPen(wxPen *pen);
339 void RemovePen(wxPen *pen);
340 wxPen *FindOrCreatePen(const wxColour& colour, int width, int style);
c801d85f
KB
341};
342
f03fc89f 343class WXDLLEXPORT wxBrushList : public wxList
c801d85f 344{
f03fc89f
VZ
345 DECLARE_DYNAMIC_CLASS(wxBrushList)
346
347public:
348 wxBrushList() { }
349 ~wxBrushList();
350
351 void AddBrush(wxBrush *brush);
352 void RemoveBrush(wxBrush *brush);
353 wxBrush *FindOrCreateBrush(const wxColour& colour, int style);
c801d85f
KB
354};
355
9d2f3c71 356WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
c801d85f 357
f03fc89f 358class WXDLLEXPORT wxFontList : public wxList
c801d85f 359{
f03fc89f
VZ
360 DECLARE_DYNAMIC_CLASS(wxFontList)
361
362public:
363 wxFontList() { }
364 ~wxFontList();
365
366 void AddFont(wxFont *font);
367 void RemoveFont(wxFont *font);
368 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
369 bool underline = FALSE,
37bebc11
RD
370 const wxString& face = wxEmptyString,
371 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
c801d85f
KB
372};
373
f03fc89f 374class WXDLLEXPORT wxColourDatabase : public wxList
c801d85f 375{
f03fc89f
VZ
376 DECLARE_CLASS(wxColourDatabase)
377
378public:
379 wxColourDatabase(int type);
380 ~wxColourDatabase() ;
381
382 // Not const because it may add a name to the database
383 wxColour *FindColour(const wxString& colour) ;
384 wxString FindName(const wxColour& colour) const;
385 void Initialize();
19bf0c69
DW
386#ifdef __WXPM__
387 // PM keeps its own type of colour table
388 long* m_palTable;
389 size_t m_nSize;
390#endif
c801d85f
KB
391};
392
f03fc89f 393class WXDLLEXPORT wxBitmapList : public wxList
c801d85f 394{
f03fc89f 395 DECLARE_DYNAMIC_CLASS(wxBitmapList)
c801d85f 396
f03fc89f
VZ
397public:
398 wxBitmapList();
399 ~wxBitmapList();
400
401 void AddBitmap(wxBitmap *bitmap);
402 void RemoveBitmap(wxBitmap *bitmap);
c801d85f
KB
403};
404
f03fc89f
VZ
405class WXDLLEXPORT wxResourceCache: public wxList
406{
407public:
408 wxResourceCache() { }
409 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
410 ~wxResourceCache();
411
412private:
413 DECLARE_DYNAMIC_CLASS(wxResourceCache)
414};
415
416// ---------------------------------------------------------------------------
417// global variables
418// ---------------------------------------------------------------------------
419
c801d85f 420// Lists of GDI objects
f03fc89f
VZ
421WXDLLEXPORT_DATA(extern wxPenList*) wxThePenList;
422WXDLLEXPORT_DATA(extern wxBrushList*) wxTheBrushList;
423WXDLLEXPORT_DATA(extern wxFontList*) wxTheFontList;
424WXDLLEXPORT_DATA(extern wxBitmapList*) wxTheBitmapList;
c801d85f
KB
425
426// Stock objects
f03fc89f
VZ
427WXDLLEXPORT_DATA(extern wxFont*) wxNORMAL_FONT;
428WXDLLEXPORT_DATA(extern wxFont*) wxSMALL_FONT;
429WXDLLEXPORT_DATA(extern wxFont*) wxITALIC_FONT;
430WXDLLEXPORT_DATA(extern wxFont*) wxSWISS_FONT;
431
432WXDLLEXPORT_DATA(extern wxPen*) wxRED_PEN;
433WXDLLEXPORT_DATA(extern wxPen*) wxCYAN_PEN;
434WXDLLEXPORT_DATA(extern wxPen*) wxGREEN_PEN;
435WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_PEN;
436WXDLLEXPORT_DATA(extern wxPen*) wxWHITE_PEN;
437WXDLLEXPORT_DATA(extern wxPen*) wxTRANSPARENT_PEN;
438WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_DASHED_PEN;
439WXDLLEXPORT_DATA(extern wxPen*) wxGREY_PEN;
440WXDLLEXPORT_DATA(extern wxPen*) wxMEDIUM_GREY_PEN;
441WXDLLEXPORT_DATA(extern wxPen*) wxLIGHT_GREY_PEN;
442
443WXDLLEXPORT_DATA(extern wxBrush*) wxBLUE_BRUSH;
444WXDLLEXPORT_DATA(extern wxBrush*) wxGREEN_BRUSH;
445WXDLLEXPORT_DATA(extern wxBrush*) wxWHITE_BRUSH;
446WXDLLEXPORT_DATA(extern wxBrush*) wxBLACK_BRUSH;
447WXDLLEXPORT_DATA(extern wxBrush*) wxGREY_BRUSH;
448WXDLLEXPORT_DATA(extern wxBrush*) wxMEDIUM_GREY_BRUSH;
449WXDLLEXPORT_DATA(extern wxBrush*) wxLIGHT_GREY_BRUSH;
450WXDLLEXPORT_DATA(extern wxBrush*) wxTRANSPARENT_BRUSH;
451WXDLLEXPORT_DATA(extern wxBrush*) wxCYAN_BRUSH;
452WXDLLEXPORT_DATA(extern wxBrush*) wxRED_BRUSH;
453
454WXDLLEXPORT_DATA(extern wxColour*) wxBLACK;
455WXDLLEXPORT_DATA(extern wxColour*) wxWHITE;
456WXDLLEXPORT_DATA(extern wxColour*) wxRED;
457WXDLLEXPORT_DATA(extern wxColour*) wxBLUE;
458WXDLLEXPORT_DATA(extern wxColour*) wxGREEN;
459WXDLLEXPORT_DATA(extern wxColour*) wxCYAN;
460WXDLLEXPORT_DATA(extern wxColour*) wxLIGHT_GREY;
c801d85f
KB
461
462// 'Null' objects
f03fc89f
VZ
463WXDLLEXPORT_DATA(extern wxBitmap) wxNullBitmap;
464WXDLLEXPORT_DATA(extern wxIcon) wxNullIcon;
465WXDLLEXPORT_DATA(extern wxCursor) wxNullCursor;
466WXDLLEXPORT_DATA(extern wxPen) wxNullPen;
467WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
468WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
469WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
470WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
c801d85f
KB
471
472// Stock cursors types
f03fc89f
VZ
473WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;
474WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
475WXDLLEXPORT_DATA(extern wxCursor*) wxCROSS_CURSOR;
476
477WXDLLEXPORT_DATA(extern wxColourDatabase*) wxTheColourDatabase;
478
479WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
c801d85f 480
f03fc89f
VZ
481WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
482WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
483
484// The list of objects which should be deleted
485WXDLLEXPORT_DATA(extern wxList) wxPendingDelete;
486
487// ---------------------------------------------------------------------------
488// global functions
489// ---------------------------------------------------------------------------
490
491// resource management
6a6c0a8b 492extern void WXDLLEXPORT wxInitializeStockObjects();
a3622daa 493extern void WXDLLEXPORT wxInitializeStockLists();
6a6c0a8b 494extern void WXDLLEXPORT wxDeleteStockObjects();
a3622daa 495extern void WXDLLEXPORT wxDeleteStockLists();
c801d85f 496
f03fc89f 497// is the display colour (or monochrome)?
6a6c0a8b 498extern bool WXDLLEXPORT wxColourDisplay();
c801d85f
KB
499
500// Returns depth of screen
6a6c0a8b
JS
501extern int WXDLLEXPORT wxDisplayDepth();
502#define wxGetDisplayDepth wxDisplayDepth
c801d85f 503
904a68b6 504// get the display size
c801d85f 505extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
6a6c0a8b 506extern wxSize WXDLLEXPORT wxGetDisplaySize();
904a68b6
RL
507extern void WXDLLEXPORT wxDisplaySizeMM(int *width, int *height);
508extern wxSize WXDLLEXPORT wxGetDisplaySizeMM();
c801d85f 509
f03fc89f 510// set global cursor
c801d85f
KB
511extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
512
c801d85f 513#endif
34138703 514 // _WX_GDICMNH__