Added encoding parameter to wxFontList::FindOrCreateFont
[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 #include "wx/font.h"
30
31 // ---------------------------------------------------------------------------
32 // forward declarations
33 // ---------------------------------------------------------------------------
34
35 class WXDLLEXPORT wxBitmap;
36 class WXDLLEXPORT wxBrush;
37 class WXDLLEXPORT wxColour;
38 class WXDLLEXPORT wxCursor;
39 class WXDLLEXPORT wxFont;
40 class WXDLLEXPORT wxIcon;
41 class WXDLLEXPORT wxPalette;
42 class WXDLLEXPORT wxPen;
43 class WXDLLEXPORT wxRegion;
44 class WXDLLEXPORT wxString;
45
46 // ---------------------------------------------------------------------------
47 // constants
48 // ---------------------------------------------------------------------------
49
50 // Bitmap flags
51 enum
52 {
53 wxBITMAP_TYPE_BMP = 1,
54 wxBITMAP_TYPE_BMP_RESOURCE,
55 wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
56 wxBITMAP_TYPE_ICO,
57 wxBITMAP_TYPE_ICO_RESOURCE,
58 wxBITMAP_TYPE_CUR,
59 wxBITMAP_TYPE_CUR_RESOURCE,
60 wxBITMAP_TYPE_XBM,
61 wxBITMAP_TYPE_XBM_DATA,
62 wxBITMAP_TYPE_XPM,
63 wxBITMAP_TYPE_XPM_DATA,
64 wxBITMAP_TYPE_TIF,
65 wxBITMAP_TYPE_TIF_RESOURCE,
66 wxBITMAP_TYPE_GIF,
67 wxBITMAP_TYPE_GIF_RESOURCE,
68 wxBITMAP_TYPE_PNG,
69 wxBITMAP_TYPE_PNG_RESOURCE,
70 wxBITMAP_TYPE_JPEG,
71 wxBITMAP_TYPE_JPEG_RESOURCE,
72 wxBITMAP_TYPE_PNM,
73 wxBITMAP_TYPE_PNM_RESOURCE,
74 wxBITMAP_TYPE_PCX,
75 wxBITMAP_TYPE_PCX_RESOURCE,
76 wxBITMAP_TYPE_PICT,
77 wxBITMAP_TYPE_PICT_RESOURCE,
78 wxBITMAP_TYPE_ICON,
79 wxBITMAP_TYPE_ICON_RESOURCE,
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_BULLSEYE,
91 wxCURSOR_CHAR,
92 wxCURSOR_CROSS,
93 wxCURSOR_HAND,
94 wxCURSOR_IBEAM,
95 wxCURSOR_LEFT_BUTTON,
96 wxCURSOR_MAGNIFIER,
97 wxCURSOR_MIDDLE_BUTTON,
98 wxCURSOR_NO_ENTRY,
99 wxCURSOR_PAINT_BRUSH,
100 wxCURSOR_PENCIL,
101 wxCURSOR_POINT_LEFT,
102 wxCURSOR_POINT_RIGHT,
103 wxCURSOR_QUESTION_ARROW,
104 wxCURSOR_RIGHT_BUTTON,
105 wxCURSOR_SIZENESW,
106 wxCURSOR_SIZENS,
107 wxCURSOR_SIZENWSE,
108 wxCURSOR_SIZEWE,
109 wxCURSOR_SIZING,
110 wxCURSOR_SPRAYCAN,
111 wxCURSOR_WAIT,
112 wxCURSOR_WATCH,
113 wxCURSOR_BLANK,
114 #ifdef __WXGTK__
115 wxCURSOR_DEFAULT, // standard X11 cursor
116 #endif
117 #ifdef __X__
118 // Not yet implemented for Windows
119 wxCURSOR_CROSS_REVERSE,
120 wxCURSOR_DOUBLE_ARROW,
121 wxCURSOR_BASED_ARROW_UP,
122 wxCURSOR_BASED_ARROW_DOWN,
123 #endif // X11
124
125 wxCURSOR_MAX
126 };
127
128 // ---------------------------------------------------------------------------
129 // macros
130 // ---------------------------------------------------------------------------
131
132 /* Useful macro for creating icons portably, for example:
133
134 wxIcon *icon = new wxICON(mondrian);
135
136 expands into:
137
138 wxIcon *icon = new wxIcon("mondrian"); // On wxMSW
139 wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK
140 */
141
142 #ifdef __WXMSW__
143 // Load from a resource
144 #define wxICON(X) wxIcon("" #X "")
145 #elif defined(__WXPM__)
146 // Load from a resource
147 #define wxICON(X) wxIcon("" #X "")
148 #elif defined(__WXGTK__)
149 // Initialize from an included XPM
150 #define wxICON(X) wxIcon( (const char**) X##_xpm )
151 #elif defined(__WXMOTIF__)
152 // Initialize from an included XPM
153 #define wxICON(X) wxIcon( X##_xpm )
154 #else
155 // This will usually mean something on any platform
156 #define wxICON(X) wxIcon("" #X "")
157 #endif // platform
158
159 /* Another macro: this one is for portable creation of bitmaps. We assume that
160 under Unix bitmaps live in XPMs and under Windows they're in ressources.
161 */
162
163 #if defined(__WXMSW__) || defined(__WXPM__)
164 #define wxBITMAP(name) wxBitmap(#name, wxBITMAP_TYPE_RESOURCE)
165 #else // !(Windows || OS2)
166 #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
167 #endif // platform
168
169 // ===========================================================================
170 // classes
171 // ===========================================================================
172
173 // ---------------------------------------------------------------------------
174 // wxSize
175 // ---------------------------------------------------------------------------
176 class WXDLLEXPORT wxSize
177 {
178 public:
179 // members are public for compatibility (don't use them directly,
180 // especially that there names were chosen very unfortunately - they should
181 // have been called width and height)
182 int x, y;
183
184 // constructors
185 wxSize() { x = y = 0; }
186 wxSize(int xx, int yy) { Set(xx, yy); }
187
188 // no copy ctor or assignment operator - the defaults are ok
189 bool operator==(const wxSize& sz) const { return x == sz.x && y == sz.y; }
190
191 // FIXME are these really useful? If they're, we should have += &c as well
192 wxSize operator+(const wxSize& sz) { return wxSize(x + sz.x, y + sz.y); }
193 wxSize operator-(const wxSize& sz) { return wxSize(x - sz.x, y - sz.y); }
194
195 // accessors
196 void Set(int xx, int yy) { x = xx; y = yy; }
197 void SetWidth(int w) { x = w; }
198 void SetHeight(int h) { y = h; }
199
200 int GetWidth() const { return x; }
201 int GetHeight() const { return y; }
202
203 // compatibility
204 int GetX() const { return x; }
205 int GetY() const { return y; }
206 };
207
208 // ---------------------------------------------------------------------------
209 // Point classes: with real or integer coordinates
210 // ---------------------------------------------------------------------------
211
212 class WXDLLEXPORT wxRealPoint
213 {
214 public:
215 double x;
216 double y;
217
218 wxRealPoint() { x = y = 0.0; };
219 wxRealPoint(double xx, double yy) { x = xx; y = yy; };
220
221 wxRealPoint operator+(const wxRealPoint& pt) { return wxRealPoint(x + pt.x, y + pt.y); }
222 wxRealPoint operator-(const wxRealPoint& pt) { return wxRealPoint(x - pt.x, y - pt.y); }
223
224 bool operator==(const wxRealPoint& pt) const { return x == pt.x && y == pt.y; }
225 };
226
227 class WXDLLEXPORT wxPoint
228 {
229 public:
230 int x, y;
231
232 wxPoint() { x = y = 0; };
233 wxPoint(int xx, int 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(int xx, int yy, int ww, int 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 int GetX() const { return x; }
270 void SetX(int xx) { x = xx; }
271
272 int GetY() const { return y; }
273 void SetY(int yy) { y = yy; }
274
275 int GetWidth() const { return width; }
276 void SetWidth(int w) { width = w; }
277
278 int GetHeight() const { return height; }
279 void SetHeight(int 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 int GetLeft() const { return x; }
287 int GetTop() const { return y; }
288 int GetBottom() const { return y + height - 1; }
289 int GetRight() const { return x + width - 1; }
290
291 void SetLeft(int left) { x = left; }
292 void SetRight(int right) { width = right - x + 1; }
293 void SetTop(int top) { y = top; }
294 void SetBottom(int 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 int 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 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
353 };
354
355 class WXDLLEXPORT wxColourDatabase : public wxList
356 {
357 DECLARE_CLASS(wxColourDatabase)
358
359 public:
360 wxColourDatabase(int type);
361 ~wxColourDatabase() ;
362
363 // Not const because it may add a name to the database
364 wxColour *FindColour(const wxString& colour) ;
365 wxString FindName(const wxColour& colour) const;
366 void Initialize();
367 };
368
369 class WXDLLEXPORT wxBitmapList : public wxList
370 {
371 DECLARE_DYNAMIC_CLASS(wxBitmapList)
372
373 public:
374 wxBitmapList();
375 ~wxBitmapList();
376
377 void AddBitmap(wxBitmap *bitmap);
378 void RemoveBitmap(wxBitmap *bitmap);
379 };
380
381 class WXDLLEXPORT wxResourceCache: public wxList
382 {
383 public:
384 wxResourceCache() { }
385 wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
386 ~wxResourceCache();
387
388 private:
389 DECLARE_DYNAMIC_CLASS(wxResourceCache)
390 };
391
392 // ---------------------------------------------------------------------------
393 // global variables
394 // ---------------------------------------------------------------------------
395
396 // Lists of GDI objects
397 WXDLLEXPORT_DATA(extern wxPenList*) wxThePenList;
398 WXDLLEXPORT_DATA(extern wxBrushList*) wxTheBrushList;
399 WXDLLEXPORT_DATA(extern wxFontList*) wxTheFontList;
400 WXDLLEXPORT_DATA(extern wxBitmapList*) wxTheBitmapList;
401
402 // Stock objects
403 WXDLLEXPORT_DATA(extern wxFont*) wxNORMAL_FONT;
404 WXDLLEXPORT_DATA(extern wxFont*) wxSMALL_FONT;
405 WXDLLEXPORT_DATA(extern wxFont*) wxITALIC_FONT;
406 WXDLLEXPORT_DATA(extern wxFont*) wxSWISS_FONT;
407
408 WXDLLEXPORT_DATA(extern wxPen*) wxRED_PEN;
409 WXDLLEXPORT_DATA(extern wxPen*) wxCYAN_PEN;
410 WXDLLEXPORT_DATA(extern wxPen*) wxGREEN_PEN;
411 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_PEN;
412 WXDLLEXPORT_DATA(extern wxPen*) wxWHITE_PEN;
413 WXDLLEXPORT_DATA(extern wxPen*) wxTRANSPARENT_PEN;
414 WXDLLEXPORT_DATA(extern wxPen*) wxBLACK_DASHED_PEN;
415 WXDLLEXPORT_DATA(extern wxPen*) wxGREY_PEN;
416 WXDLLEXPORT_DATA(extern wxPen*) wxMEDIUM_GREY_PEN;
417 WXDLLEXPORT_DATA(extern wxPen*) wxLIGHT_GREY_PEN;
418
419 WXDLLEXPORT_DATA(extern wxBrush*) wxBLUE_BRUSH;
420 WXDLLEXPORT_DATA(extern wxBrush*) wxGREEN_BRUSH;
421 WXDLLEXPORT_DATA(extern wxBrush*) wxWHITE_BRUSH;
422 WXDLLEXPORT_DATA(extern wxBrush*) wxBLACK_BRUSH;
423 WXDLLEXPORT_DATA(extern wxBrush*) wxGREY_BRUSH;
424 WXDLLEXPORT_DATA(extern wxBrush*) wxMEDIUM_GREY_BRUSH;
425 WXDLLEXPORT_DATA(extern wxBrush*) wxLIGHT_GREY_BRUSH;
426 WXDLLEXPORT_DATA(extern wxBrush*) wxTRANSPARENT_BRUSH;
427 WXDLLEXPORT_DATA(extern wxBrush*) wxCYAN_BRUSH;
428 WXDLLEXPORT_DATA(extern wxBrush*) wxRED_BRUSH;
429
430 WXDLLEXPORT_DATA(extern wxColour*) wxBLACK;
431 WXDLLEXPORT_DATA(extern wxColour*) wxWHITE;
432 WXDLLEXPORT_DATA(extern wxColour*) wxRED;
433 WXDLLEXPORT_DATA(extern wxColour*) wxBLUE;
434 WXDLLEXPORT_DATA(extern wxColour*) wxGREEN;
435 WXDLLEXPORT_DATA(extern wxColour*) wxCYAN;
436 WXDLLEXPORT_DATA(extern wxColour*) wxLIGHT_GREY;
437
438 // 'Null' objects
439 WXDLLEXPORT_DATA(extern wxBitmap) wxNullBitmap;
440 WXDLLEXPORT_DATA(extern wxIcon) wxNullIcon;
441 WXDLLEXPORT_DATA(extern wxCursor) wxNullCursor;
442 WXDLLEXPORT_DATA(extern wxPen) wxNullPen;
443 WXDLLEXPORT_DATA(extern wxBrush) wxNullBrush;
444 WXDLLEXPORT_DATA(extern wxPalette) wxNullPalette;
445 WXDLLEXPORT_DATA(extern wxFont) wxNullFont;
446 WXDLLEXPORT_DATA(extern wxColour) wxNullColour;
447
448 // Stock cursors types
449 WXDLLEXPORT_DATA(extern wxCursor*) wxSTANDARD_CURSOR;
450 WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
451 WXDLLEXPORT_DATA(extern wxCursor*) wxCROSS_CURSOR;
452
453 WXDLLEXPORT_DATA(extern wxColourDatabase*) wxTheColourDatabase;
454
455 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
456
457 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
458 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
459
460 // The list of objects which should be deleted
461 WXDLLEXPORT_DATA(extern wxList) wxPendingDelete;
462
463 // ---------------------------------------------------------------------------
464 // global functions
465 // ---------------------------------------------------------------------------
466
467 // resource management
468 extern void WXDLLEXPORT wxInitializeStockObjects();
469 extern void WXDLLEXPORT wxInitializeStockLists();
470 extern void WXDLLEXPORT wxDeleteStockObjects();
471 extern void WXDLLEXPORT wxDeleteStockLists();
472
473 // is the display colour (or monochrome)?
474 extern bool WXDLLEXPORT wxColourDisplay();
475
476 // Returns depth of screen
477 extern int WXDLLEXPORT wxDisplayDepth();
478 #define wxGetDisplayDepth wxDisplayDepth
479
480 // get the diaplay size
481 extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
482 extern wxSize WXDLLEXPORT wxGetDisplaySize();
483
484 // set global cursor
485 extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
486
487 #endif
488 // _WX_GDICMNH__