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