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