Applied patch [ 730697 ] wxRect::AlignIn member
[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 #if defined(__GNUG__) && !defined(__APPLE__)
20 #pragma interface "gdicmn.h"
21 #endif
22
23 #include "wx/setup.h"
24 #include "wx/list.h"
25 #include "wx/string.h"
26 #include "wx/fontenc.h"
27
28 // ---------------------------------------------------------------------------
29 // forward declarations
30 // ---------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxBitmap;
33 class WXDLLEXPORT wxBrush;
34 class WXDLLEXPORT wxColour;
35 class WXDLLEXPORT wxCursor;
36 class WXDLLEXPORT wxFont;
37 class WXDLLEXPORT wxIcon;
38 class WXDLLEXPORT wxPalette;
39 class WXDLLEXPORT wxPen;
40 class WXDLLEXPORT wxRegion;
41 class WXDLLEXPORT wxString;
42
43 // ---------------------------------------------------------------------------
44 // constants
45 // ---------------------------------------------------------------------------
46
47 // Bitmap flags
48 enum wxBitmapType
49 {
50 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
51 wxBITMAP_TYPE_BMP,
52 wxBITMAP_TYPE_BMP_RESOURCE,
53 wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
54 wxBITMAP_TYPE_ICO,
55 wxBITMAP_TYPE_ICO_RESOURCE,
56 wxBITMAP_TYPE_CUR,
57 wxBITMAP_TYPE_CUR_RESOURCE,
58 wxBITMAP_TYPE_XBM,
59 wxBITMAP_TYPE_XBM_DATA,
60 wxBITMAP_TYPE_XPM,
61 wxBITMAP_TYPE_XPM_DATA,
62 wxBITMAP_TYPE_TIF,
63 wxBITMAP_TYPE_TIF_RESOURCE,
64 wxBITMAP_TYPE_GIF,
65 wxBITMAP_TYPE_GIF_RESOURCE,
66 wxBITMAP_TYPE_PNG,
67 wxBITMAP_TYPE_PNG_RESOURCE,
68 wxBITMAP_TYPE_JPEG,
69 wxBITMAP_TYPE_JPEG_RESOURCE,
70 wxBITMAP_TYPE_PNM,
71 wxBITMAP_TYPE_PNM_RESOURCE,
72 wxBITMAP_TYPE_PCX,
73 wxBITMAP_TYPE_PCX_RESOURCE,
74 wxBITMAP_TYPE_PICT,
75 wxBITMAP_TYPE_PICT_RESOURCE,
76 wxBITMAP_TYPE_ICON,
77 wxBITMAP_TYPE_ICON_RESOURCE,
78 wxBITMAP_TYPE_ANI,
79 wxBITMAP_TYPE_IFF,
80 wxBITMAP_TYPE_MACCURSOR,
81 wxBITMAP_TYPE_MACCURSOR_RESOURCE,
82 wxBITMAP_TYPE_ANY = 50
83 };
84
85 // Standard cursors
86 enum wxStockCursor
87 {
88 wxCURSOR_NONE, // should be 0
89 wxCURSOR_ARROW,
90 wxCURSOR_RIGHT_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,
115 #ifdef __WXGTK__
116 wxCURSOR_DEFAULT, // standard X11 cursor
117 #endif
118 #ifdef __WXMAC__
119 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
120 #endif
121 #ifdef __X__
122 // Not yet implemented for Windows
123 wxCURSOR_CROSS_REVERSE,
124 wxCURSOR_DOUBLE_ARROW,
125 wxCURSOR_BASED_ARROW_UP,
126 wxCURSOR_BASED_ARROW_DOWN,
127 #endif // X11
128
129 wxCURSOR_ARROWWAIT,
130
131 wxCURSOR_MAX
132 };
133
134 #ifndef __WXGTK__
135 #define wxCURSOR_DEFAULT wxCURSOR_ARROW
136 #endif
137
138 // ---------------------------------------------------------------------------
139 // macros
140 // ---------------------------------------------------------------------------
141
142 /* Useful macro for creating icons portably, for example:
143
144 wxIcon *icon = new wxICON(mondrian);
145
146 expands into:
147
148 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
149 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
150 */
151
152 #ifdef __WXMSW__
153 // Load from a resource
154 #define wxICON(X) wxIcon(wxT(#X))
155 #elif defined(__WXPM__)
156 // Load from a resource
157 #define wxICON(X) wxIcon(wxT(#X))
158 #elif defined(__WXMGL__)
159 // Initialize from an included XPM
160 #define wxICON(X) wxIcon( (const char**) X##_xpm )
161 #elif defined(__WXGTK__)
162 // Initialize from an included XPM
163 #define wxICON(X) wxIcon( (const char**) X##_xpm )
164 #elif defined(__WXMAC__)
165 // Initialize from an included XPM
166 #define wxICON(X) wxIcon( (const char**) X##_xpm )
167 #elif defined(__WXMOTIF__)
168 // Initialize from an included XPM
169 #define wxICON(X) wxIcon( X##_xpm )
170 #elif defined(__WXX11__)
171 // Initialize from an included XPM
172 #define wxICON(X) wxIcon( X##_xpm )
173 #else
174 // This will usually mean something on any platform
175 #define wxICON(X) wxIcon(wxT(#X))
176 #endif // platform
177
178 /* Another macro: this one is for portable creation of bitmaps. We assume that
179 under Unix bitmaps live in XPMs and under Windows they're in ressources.
180 */
181
182 #if defined(__WXMSW__) || defined(__WXPM__)
183 #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE)
184 #elif defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__) || defined(__WXMAC__) || defined(__WXMGL__)
185 // Initialize from an included XPM
186 #define wxBITMAP(name) wxBitmap( (const char**) name##_xpm )
187 #else // other platforms
188 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
189 #endif // platform
190
191 // ===========================================================================
192 // classes
193 // ===========================================================================
194
195 // ---------------------------------------------------------------------------
196 // wxSize
197 // ---------------------------------------------------------------------------
198
199 class WXDLLEXPORT wxSize
200 {
201 public:
202 // members are public for compatibility, don't use them directly.
203 int x, y;
204
205 // constructors
206 wxSize() : x(0), y(0) { }
207 wxSize(int xx, int yy) : x(xx), y(yy) { }
208
209 // no copy ctor or assignment operator - the defaults are ok
210
211 bool operator==(const wxSize& sz) const { return x == sz.x && y == sz.y; }
212 bool operator!=(const wxSize& sz) const { return x != sz.x || y != sz.y; }
213
214 // FIXME are these really useful? If they're, we should have += &c as well
215 wxSize operator+(const wxSize& sz) { return wxSize(x + sz.x, y + sz.y); }
216 wxSize operator-(const wxSize& sz) { return wxSize(x - sz.x, y - sz.y); }
217
218 // accessors
219 void Set(int xx, int yy) { x = xx; y = yy; }
220 void SetWidth(int w) { x = w; }
221 void SetHeight(int h) { y = h; }
222
223 int GetWidth() const { return x; }
224 int GetHeight() const { return y; }
225
226 // compatibility
227 int GetX() const { return x; }
228 int GetY() const { return y; }
229 };
230
231 // ---------------------------------------------------------------------------
232 // Point classes: with real or integer coordinates
233 // ---------------------------------------------------------------------------
234
235 class WXDLLEXPORT wxRealPoint
236 {
237 public:
238 double x;
239 double y;
240
241 wxRealPoint() : x(0.0), y(0.0) { }
242 wxRealPoint(double xx, double yy) : x(xx), y(yy) { }
243
244 wxRealPoint operator+(const wxRealPoint& pt) const { return wxRealPoint(x + pt.x, y + pt.y); }
245 wxRealPoint operator-(const wxRealPoint& pt) const { return wxRealPoint(x - pt.x, y - pt.y); }
246
247 bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; }
248 bool operator!=(const wxRealPoint& pt) const { return x != pt.x || y != pt.y; }
249 };
250
251 class WXDLLEXPORT wxPoint
252 {
253 public:
254 int x, y;
255
256 wxPoint() : x(0), y(0) { }
257 wxPoint(int xx, int yy) : x(xx), y(yy) { }
258
259 // no copy ctor or assignment operator - the defaults are ok
260
261 // comparison
262 bool operator==(const wxPoint& p) const { return x == p.x && y == p.y; }
263 bool operator!=(const wxPoint& p) const { return !(*this == p); }
264
265 // arithmetic operations (component wise)
266 wxPoint operator+(const wxPoint& p) const { return wxPoint(x + p.x, y + p.y); }
267 wxPoint operator-(const wxPoint& p) const { return wxPoint(x - p.x, y - p.y); }
268
269 wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
270 wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
271 };
272
273 #if WXWIN_COMPATIBILITY
274 #define wxIntPoint wxPoint
275 #define wxRectangle wxRect
276 #endif // WXWIN_COMPATIBILITY
277
278 // ---------------------------------------------------------------------------
279 // wxRect
280 // ---------------------------------------------------------------------------
281
282 class WXDLLEXPORT wxRect
283 {
284 public:
285 wxRect()
286 : x(0), y(0), width(0), height(0)
287 { }
288 wxRect(int xx, int yy, int ww, int hh)
289 : x(xx), y(yy), width(ww), height(hh)
290 { }
291 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
292 wxRect(const wxPoint& pos, const wxSize& size);
293
294 // default copy ctor and assignment operators ok
295
296 int GetX() const { return x; }
297 void SetX(int xx) { x = xx; }
298
299 int GetY() const { return y; }
300 void SetY(int yy) { y = yy; }
301
302 int GetWidth() const { return width; }
303 void SetWidth(int w) { width = w; }
304
305 int GetHeight() const { return height; }
306 void SetHeight(int h) { height = h; }
307
308 wxPoint GetPosition() const { return wxPoint(x, y); }
309 void SetPosition( const wxPoint &p ) { x = p.x; y = p.y; }
310
311 wxSize GetSize() const { return wxSize(width, height); }
312 void SetSize( const wxSize &s ) { width = s.GetWidth(); height = s.GetHeight(); }
313
314 int GetLeft() const { return x; }
315 int GetTop() const { return y; }
316 int GetBottom() const { return y + height - 1; }
317 int GetRight() const { return x + width - 1; }
318
319 void SetLeft(int left) { x = left; }
320 void SetRight(int right) { width = right - x + 1; }
321 void SetTop(int top) { y = top; }
322 void SetBottom(int bottom) { height = bottom - y + 1; }
323
324 // operations with rect
325 wxRect& Inflate(wxCoord dx, wxCoord dy);
326 wxRect& Inflate(wxCoord d) { return Inflate(d, d); }
327 wxRect Inflate(wxCoord dx, wxCoord dy) const
328 {
329 wxRect r = *this;
330 r.Inflate(dx, dy);
331 return r;
332 }
333
334 wxRect& Deflate(wxCoord dx, wxCoord dy) { return Inflate(-dx, -dy); }
335 wxRect& Deflate(wxCoord d) { return Inflate(-d); }
336 wxRect Deflate(wxCoord dx, wxCoord dy) const
337 {
338 wxRect r = *this;
339 r.Deflate(dx, dy);
340 return r;
341 }
342
343 void Offset(wxCoord dx, wxCoord dy) { x += dx; y += dy; }
344 void Offset(const wxPoint& pt) { Offset(pt.x, pt.y); }
345
346 wxRect& Intersect(const wxRect& rect);
347 wxRect Intersect(const wxRect& rect) const
348 {
349 wxRect r = *this;
350 r.Intersect(rect);
351 return r;
352 }
353
354 wxRect operator+(const wxRect& rect) const;
355 wxRect& operator+=(const wxRect& rect);
356
357 // compare rectangles
358 bool operator==(const wxRect& rect) const;
359 bool operator!=(const wxRect& rect) const { return !(*this == rect); }
360
361 // return TRUE if the point is (not strcitly) inside the rect
362 bool Inside(int x, int y) const;
363 bool Inside(const wxPoint& pt) const { return Inside(pt.x, pt.y); }
364
365 // return TRUE if the rectangles have a non empty intersection
366 bool Intersects(const wxRect& rect) const;
367
368 // align in another rectangle according to WX alignment flags.
369 void AlignIn(const wxRect& rect, int align)
370 {
371 if (align & wxALIGN_CENTER_HORIZONTAL) x = rect.x + (rect.width-width)/2;
372 else if (align & wxALIGN_RIGHT) x = rect.x+rect.width - width;
373 else x = rect.x;
374
375 if (align & wxALIGN_CENTER_VERTICAL) y = rect.y + (rect.height-height)/2;
376 else if (align & wxALIGN_BOTTOM) y = rect.y+rect.height - height;
377 else y = rect.y;
378 }
379
380 public:
381 int x, y, width, height;
382 };
383
384 // ---------------------------------------------------------------------------
385 // Management of pens, brushes and fonts
386 // ---------------------------------------------------------------------------
387
388 typedef wxInt8 wxDash;
389
390 class WXDLLEXPORT wxPenList : public wxList
391 {
392 DECLARE_DYNAMIC_CLASS(wxPenList)
393
394 public:
395 wxPenList() { }
396 ~wxPenList();
397
398 void AddPen(wxPen *pen);
399 void RemovePen(wxPen *pen);
400 wxPen *FindOrCreatePen(const wxColour& colour, int width, int style);
401 };
402
403 class WXDLLEXPORT wxBrushList : public wxList
404 {
405 DECLARE_DYNAMIC_CLASS(wxBrushList)
406
407 public:
408 wxBrushList() { }
409 ~wxBrushList();
410
411 void AddBrush(wxBrush *brush);
412 void RemoveBrush(wxBrush *brush);
413 wxBrush *FindOrCreateBrush(const wxColour& colour, int style);
414 };
415
416 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
417
418 class WXDLLEXPORT wxFontList : public wxList
419 {
420 DECLARE_DYNAMIC_CLASS(wxFontList)
421
422 public:
423 wxFontList() { }
424 ~wxFontList();
425
426 void AddFont(wxFont *font);
427 void RemoveFont(wxFont *font);
428 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
429 bool underline = FALSE,
430 const wxString& face = wxEmptyString,
431 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
432 };
433
434 class WXDLLEXPORT wxColourDatabase : public wxList
435 {
436 DECLARE_CLASS(wxColourDatabase)
437
438 public:
439 wxColourDatabase(int type);
440 ~wxColourDatabase() ;
441
442 // Not const because it may add a name to the database
443 wxColour *FindColour(const wxString& colour) ;
444 wxString FindName(const wxColour& colour) const;
445 void Initialize();
446 #ifdef __WXPM__
447 // PM keeps its own type of colour table
448 long* m_palTable;
449 size_t m_nSize;
450 #endif
451 };
452
453 class WXDLLEXPORT wxBitmapList : public wxList
454 {
455 DECLARE_DYNAMIC_CLASS(wxBitmapList)
456
457 public:
458 wxBitmapList();
459 ~wxBitmapList();
460
461 void AddBitmap(wxBitmap *bitmap);
462 void RemoveBitmap(wxBitmap *bitmap);
463 };
464
465 class WXDLLEXPORT wxResourceCache: public wxList
466 {
467 public:
468 wxResourceCache() { }
469 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
470 ~wxResourceCache();
471
472 private:
473 DECLARE_DYNAMIC_CLASS(wxResourceCache)
474 };
475
476 // ---------------------------------------------------------------------------
477 // global variables
478 // ---------------------------------------------------------------------------
479
480 // Lists of GDI objects
481 WXDLLEXPORT_DATA(extern wxPenList*) wxThePenList;
482 WXDLLEXPORT_DATA(extern wxBrushList*) wxTheBrushList;
483 WXDLLEXPORT_DATA(extern wxFontList*) wxTheFontList;
484 WXDLLEXPORT_DATA(extern wxBitmapList*) wxTheBitmapList;
485
486 // Stock objects
487 WXDLLEXPORT_DATA(extern wxFont*) wxNORMAL_FONT;
488 WXDLLEXPORT_DATA(extern wxFont*) wxSMALL_FONT;
489 WXDLLEXPORT_DATA(extern wxFont*) wxITALIC_FONT;
490 WXDLLEXPORT_DATA(extern wxFont*) wxSWISS_FONT;
491
492 WXDLLEXPORT_DATA(extern wxPen*) wxRED_PEN;
493 WXDLLEXPORT_DATA(extern wxPen*) wxCYAN_PEN;
494 WXDLLEXPORT_DATA(extern wxPen*) wxGREEN_PEN;
495 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_PEN;
496 WXDLLEXPORT_DATA(extern wxPen*) wxWHITE_PEN;
497 WXDLLEXPORT_DATA(extern wxPen*) wxTRANSPARENT_PEN;
498 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_DASHED_PEN;
499 WXDLLEXPORT_DATA(extern wxPen*) wxGREY_PEN;
500 WXDLLEXPORT_DATA(extern wxPen*) wxMEDIUM_GREY_PEN;
501 WXDLLEXPORT_DATA(extern wxPen*) wxLIGHT_GREY_PEN;
502
503 WXDLLEXPORT_DATA(extern wxBrush*) wxBLUE_BRUSH;
504 WXDLLEXPORT_DATA(extern wxBrush*) wxGREEN_BRUSH;
505 WXDLLEXPORT_DATA(extern wxBrush*) wxWHITE_BRUSH;
506 WXDLLEXPORT_DATA(extern wxBrush*) wxBLACK_BRUSH;
507 WXDLLEXPORT_DATA(extern wxBrush*) wxGREY_BRUSH;
508 WXDLLEXPORT_DATA(extern wxBrush*) wxMEDIUM_GREY_BRUSH;
509 WXDLLEXPORT_DATA(extern wxBrush*) wxLIGHT_GREY_BRUSH;
510 WXDLLEXPORT_DATA(extern wxBrush*) wxTRANSPARENT_BRUSH;
511 WXDLLEXPORT_DATA(extern wxBrush*) wxCYAN_BRUSH;
512 WXDLLEXPORT_DATA(extern wxBrush*) wxRED_BRUSH;
513
514 WXDLLEXPORT_DATA(extern wxColour*) wxBLACK;
515 WXDLLEXPORT_DATA(extern wxColour*) wxWHITE;
516 WXDLLEXPORT_DATA(extern wxColour*) wxRED;
517 WXDLLEXPORT_DATA(extern wxColour*) wxBLUE;
518 WXDLLEXPORT_DATA(extern wxColour*) wxGREEN;
519 WXDLLEXPORT_DATA(extern wxColour*) wxCYAN;
520 WXDLLEXPORT_DATA(extern wxColour*) wxLIGHT_GREY;
521
522 // 'Null' objects
523 WXDLLEXPORT_DATA(extern wxBitmap) wxNullBitmap;
524 WXDLLEXPORT_DATA(extern wxIcon) wxNullIcon;
525 WXDLLEXPORT_DATA(extern wxCursor) wxNullCursor;
526 WXDLLEXPORT_DATA(extern wxPen) wxNullPen;
527 WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
528 WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
529 WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
530 WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
531
532 // Stock cursors types
533 WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;
534 WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
535 WXDLLEXPORT_DATA(extern wxCursor*) wxCROSS_CURSOR;
536
537 WXDLLEXPORT_DATA(extern wxColourDatabase*) wxTheColourDatabase;
538
539 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
540
541 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
542 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
543
544 // The list of objects which should be deleted
545 WXDLLEXPORT_DATA(extern wxList) wxPendingDelete;
546
547 // ---------------------------------------------------------------------------
548 // global functions
549 // ---------------------------------------------------------------------------
550
551 // resource management
552 extern void WXDLLEXPORT wxInitializeStockObjects();
553 extern void WXDLLEXPORT wxInitializeStockLists();
554 extern void WXDLLEXPORT wxDeleteStockObjects();
555 extern void WXDLLEXPORT wxDeleteStockLists();
556
557 // is the display colour (or monochrome)?
558 extern bool WXDLLEXPORT wxColourDisplay();
559
560 // Returns depth of screen
561 extern int WXDLLEXPORT wxDisplayDepth();
562 #define wxGetDisplayDepth wxDisplayDepth
563
564 // get the display size
565 extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
566 extern wxSize WXDLLEXPORT wxGetDisplaySize();
567 extern void WXDLLEXPORT wxDisplaySizeMM(int *width, int *height);
568 extern wxSize WXDLLEXPORT wxGetDisplaySizeMM();
569
570 // Get position and size of the display workarea
571 extern void WXDLLEXPORT wxClientDisplayRect(int *x, int *y, int *width, int *height);
572 extern wxRect WXDLLEXPORT wxGetClientDisplayRect();
573
574 // set global cursor
575 extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
576
577 #endif
578 // _WX_GDICMNH__