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