A few OS/2 additions to enable the colour database to work with PM.
[wxWidgets.git] / src / common / gdicmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gdicmn.cpp
3 // Purpose: Common GDI classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "gdicmn.h"
14 #endif
15
16 #ifdef __VMS
17 #define XtDisplay XTDISPLAY
18 #endif
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/event.h"
28 #include "wx/gdicmn.h"
29 #include "wx/brush.h"
30 #include "wx/pen.h"
31 #include "wx/bitmap.h"
32 #include "wx/icon.h"
33 #include "wx/cursor.h"
34 #include "wx/font.h"
35 #include "wx/palette.h"
36 #include "wx/app.h"
37 #include "wx/dc.h"
38 #include "wx/utils.h"
39 #include "wx/settings.h"
40
41 #include "wx/log.h"
42 #include <string.h>
43
44 #ifdef __WXMSW__
45 #include <windows.h>
46 #endif
47
48 #ifdef __WXMOTIF__
49 #ifdef __VMS__
50 #pragma message disable nosimpint
51 #endif
52 #include <Xm/Xm.h>
53 #ifdef __VMS__
54 #pragma message enable nosimpint
55 #endif
56 #endif
57
58 IMPLEMENT_CLASS(wxColourDatabase, wxList)
59 IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
60 IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
61 IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
62 IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
63 IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList)
64
65 IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
66
67 wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight)
68 {
69 x = topLeft.x;
70 y = topLeft.y;
71 width = bottomRight.x - topLeft.x + 1;
72 height = bottomRight.y - topLeft.y + 1;
73
74 if (width < 0)
75 {
76 width = -width;
77 x -= width;
78 }
79
80 if (height < 0)
81 {
82 height = -height;
83 y -= height;
84 }
85 }
86
87 wxRect::wxRect(const wxPoint& point, const wxSize& size)
88 {
89 x = point.x; y = point.y;
90 width = size.x; height = size.y;
91 }
92
93 bool wxRect::operator==(const wxRect& rect) const
94 {
95 return ((x == rect.x) &&
96 (y == rect.y) &&
97 (width == rect.width) &&
98 (height == rect.height));
99 }
100
101 wxRect& wxRect::operator += (const wxRect& rect)
102 {
103 *this = (*this + rect);
104 return ( *this ) ;
105 }
106
107 wxRect wxRect::operator + (const wxRect& rect) const
108 {
109 int x1 = wxMin(this->x, rect.x);
110 int y1 = wxMin(this->y, rect.y);
111 int y2 = wxMax(y+height, rect.height+rect.y);
112 int x2 = wxMax(x+width, rect.width+rect.x);
113 return wxRect(x1, y1, x2-x1, y2-y1);
114 }
115
116 bool wxRect::Inside(int cx, int cy) const
117 {
118 return ( (cx >= x) && (cy >= y)
119 && ((cy - y) < height)
120 && ((cx - x) < width)
121 );
122 }
123
124 wxColourDatabase::wxColourDatabase (int type) : wxList (type)
125 {
126 }
127
128 wxColourDatabase::~wxColourDatabase ()
129 {
130 // Cleanup Colour allocated in Initialize()
131 wxNode *node = First ();
132 while (node)
133 {
134 wxColour *col = (wxColour *) node->Data ();
135 wxNode *next = node->Next ();
136 delete col;
137 node = next;
138 }
139 #ifdef __WXPM__
140 delete [] m_palTable;
141 #endif
142 }
143
144 // Colour database stuff
145 void wxColourDatabase::Initialize ()
146 {
147 static const struct wxColourDesc
148 {
149 const wxChar *name;
150 int r,g,b;
151 }
152 wxColourTable[] =
153 {
154 {wxT("AQUAMARINE"),112, 219, 147},
155 {wxT("BLACK"),0, 0, 0},
156 {wxT("BLUE"), 0, 0, 255},
157 {wxT("BLUE VIOLET"), 159, 95, 159},
158 {wxT("BROWN"), 165, 42, 42},
159 {wxT("CADET BLUE"), 95, 159, 159},
160 {wxT("CORAL"), 255, 127, 0},
161 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
162 {wxT("CYAN"), 0, 255, 255},
163 {wxT("DARK GREY"), 47, 47, 47}, // ?
164
165 {wxT("DARK GREEN"), 47, 79, 47},
166 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
167 {wxT("DARK ORCHID"), 153, 50, 204},
168 {wxT("DARK SLATE BLUE"), 107, 35, 142},
169 {wxT("DARK SLATE GREY"), 47, 79, 79},
170 {wxT("DARK TURQUOISE"), 112, 147, 219},
171 {wxT("DIM GREY"), 84, 84, 84},
172 {wxT("FIREBRICK"), 142, 35, 35},
173 {wxT("FOREST GREEN"), 35, 142, 35},
174 {wxT("GOLD"), 204, 127, 50},
175 {wxT("GOLDENROD"), 219, 219, 112},
176 {wxT("GREY"), 128, 128, 128},
177 {wxT("GREEN"), 0, 255, 0},
178 {wxT("GREEN YELLOW"), 147, 219, 112},
179 {wxT("INDIAN RED"), 79, 47, 47},
180 {wxT("KHAKI"), 159, 159, 95},
181 {wxT("LIGHT BLUE"), 191, 216, 216},
182 {wxT("LIGHT GREY"), 192, 192, 192},
183 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
184 {wxT("LIME GREEN"), 50, 204, 50},
185 {wxT("LIGHT MAGENTA"), 255, 0, 255},
186 {wxT("MAGENTA"), 255, 0, 255},
187 {wxT("MAROON"), 142, 35, 107},
188 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
189 {wxT("MEDIUM GREY"), 100, 100, 100},
190 {wxT("MEDIUM BLUE"), 50, 50, 204},
191 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
192 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
193 {wxT("MEDIUM ORCHID"), 147, 112, 219},
194 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
195 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
196 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
197 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
198 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
199 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
200 {wxT("NAVY"), 35, 35, 142},
201 {wxT("ORANGE"), 204, 50, 50},
202 {wxT("ORANGE RED"), 255, 0, 127},
203 {wxT("ORCHID"), 219, 112, 219},
204 {wxT("PALE GREEN"), 143, 188, 143},
205 {wxT("PINK"), 188, 143, 234},
206 {wxT("PLUM"), 234, 173, 234},
207 {wxT("PURPLE"), 176, 0, 255},
208 {wxT("RED"), 255, 0, 0},
209 {wxT("SALMON"), 111, 66, 66},
210 {wxT("SEA GREEN"), 35, 142, 107},
211 {wxT("SIENNA"), 142, 107, 35},
212 {wxT("SKY BLUE"), 50, 153, 204},
213 {wxT("SLATE BLUE"), 0, 127, 255},
214 {wxT("SPRING GREEN"), 0, 255, 127},
215 {wxT("STEEL BLUE"), 35, 107, 142},
216 {wxT("TAN"), 219, 147, 112},
217 {wxT("THISTLE"), 216, 191, 216},
218 {wxT("TURQUOISE"), 173, 234, 234},
219 {wxT("VIOLET"), 79, 47, 79},
220 {wxT("VIOLET RED"), 204, 50, 153},
221 {wxT("WHEAT"), 216, 216, 191},
222 {wxT("WHITE"), 255, 255, 255},
223 {wxT("YELLOW"), 255, 255, 0},
224 {wxT("YELLOW GREEN"), 153, 204, 50},
225 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
226 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
227 {wxT("LIGHT MAGENTA"), 255, 0, 255},
228 {wxT("MEDIUM GREY"), 100, 100, 100},
229 };
230
231 for ( size_t n = 0; n < WXSIZEOF(wxColourTable); n++ )
232 {
233 const wxColourDesc& cc = wxColourTable[n];
234 Append(cc.name, new wxColour(cc.r,cc.g,cc.b));
235 }
236 #ifdef __WXPM__
237 m_palTable = new long[n];
238 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
239 {
240 const wxColourDesc& cc = wxColourTable[n];
241 m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b);
242 }
243 m_nSize = n;
244 #endif
245 }
246
247 /*
248 * Changed by Ian Brown, July 1994.
249 *
250 * When running under X, the Colour Database starts off empty. The X server
251 * is queried for the colour first time after which it is entered into the
252 * database. This allows our client to use the server colour database which
253 * is hopefully gamma corrected for the display being used.
254 */
255
256 wxColour *wxColourDatabase::FindColour(const wxString& colour)
257 {
258 // VZ: make the comparaison case insensitive and also match both grey and
259 // gray
260 wxString colName = colour;
261 colName.MakeUpper();
262 wxString colName2 = colName;
263 if ( !colName2.Replace(_T("GRAY"), _T("GREY")) )
264 colName2.clear();
265
266 wxNode *node = First();
267 while ( node )
268 {
269 const wxChar *key = node->GetKeyString();
270 if ( colName == key || colName2 == key )
271 {
272 return (wxColour *)node->Data();
273 }
274
275 node = node->Next();
276 }
277
278 #ifdef __WXMSW__
279 return NULL;
280 #endif
281 #ifdef __WXPM__
282 return NULL;
283 #endif
284
285 // TODO for other implementations. This should really go into
286 // platform-specific directories.
287 #ifdef __WXMAC__
288 return NULL;
289 #endif
290 #ifdef __WXSTUBS__
291 return NULL;
292 #endif
293
294 #ifdef __WXGTK__
295 wxColour *col = new wxColour( colour );
296
297 if (!(col->Ok())) {
298 delete col;
299 return (wxColour *) NULL;
300 }
301 Append( colour, col );
302 return col;
303 #endif
304
305 #ifdef __X__
306 XColor xcolour;
307
308 #ifdef __WXMOTIF__
309 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
310 #endif
311 #ifdef __XVIEW__
312 Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
313 Xv_opaque root_window = xv_get(screen, XV_ROOT);
314 Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
315 #endif
316
317 /* MATTHEW: [4] Use wxGetMainColormap */
318 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))
319 return NULL;
320
321 unsigned char r = (unsigned char)(xcolour.red >> 8);
322 unsigned char g = (unsigned char)(xcolour.green >> 8);
323 unsigned char b = (unsigned char)(xcolour.blue >> 8);
324
325 wxColour *col = new wxColour(r, g, b);
326 Append(colour, col);
327
328 return col;
329 #endif // __X__
330 }
331
332 wxString wxColourDatabase::FindName (const wxColour& colour) const
333 {
334 wxString name;
335
336 unsigned char red = colour.Red ();
337 unsigned char green = colour.Green ();
338 unsigned char blue = colour.Blue ();
339
340 for (wxNode * node = First (); node; node = node->Next ())
341 {
342 wxColour *col = (wxColour *) node->Data ();
343
344 if (col->Red () == red && col->Green () == green && col->Blue () == blue)
345 {
346 const wxChar *found = node->GetKeyString();
347 if ( found )
348 {
349 name = found;
350
351 break;
352 }
353 }
354 }
355
356 return name;
357 }
358
359 void wxInitializeStockLists () {
360 wxTheBrushList = new wxBrushList;
361 wxThePenList = new wxPenList;
362 wxTheFontList = new wxFontList;
363 wxTheBitmapList = new wxBitmapList;
364 }
365
366 void wxInitializeStockObjects ()
367 {
368 #ifdef __WXMOTIF__
369 #endif
370 #ifdef __X__
371 // TODO
372 // wxFontPool = new XFontPool;
373 #endif
374
375 // why under MSW fonts shouldn't have the standard system size?
376 /*
377 #ifdef __WXMSW__
378 static const int sizeFont = 10;
379 #else
380 #endif
381 */
382 #if defined(__WXPM__)
383 static const int sizeFont = 12;
384 wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL);
385 #else
386 wxNORMAL_FONT = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
387 static const int sizeFont = wxNORMAL_FONT->GetPointSize();
388 #endif
389
390 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
391 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
392 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
393
394 wxRED_PEN = new wxPen ("RED", 1, wxSOLID);
395 wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID);
396 wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID);
397 wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID);
398 wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID);
399 wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT);
400 wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH);
401 wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID);
402 wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID);
403 wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID);
404
405 wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID);
406 wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID);
407 wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID);
408 wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID);
409 wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT);
410 wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID);
411 wxRED_BRUSH = new wxBrush ("RED", wxSOLID);
412 wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID);
413 wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID);
414 wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID);
415
416 wxBLACK = new wxColour ("BLACK");
417 wxWHITE = new wxColour ("WHITE");
418 wxRED = new wxColour ("RED");
419 wxBLUE = new wxColour ("BLUE");
420 wxGREEN = new wxColour ("GREEN");
421 wxCYAN = new wxColour ("CYAN");
422 wxLIGHT_GREY = new wxColour ("LIGHT GREY");
423
424 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
425 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
426 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
427 }
428
429 void wxDeleteStockObjects ()
430 {
431 wxDELETE(wxNORMAL_FONT);
432 wxDELETE(wxSMALL_FONT);
433 wxDELETE(wxITALIC_FONT);
434 wxDELETE(wxSWISS_FONT);
435
436 wxDELETE(wxRED_PEN);
437 wxDELETE(wxCYAN_PEN);
438 wxDELETE(wxGREEN_PEN);
439 wxDELETE(wxBLACK_PEN);
440 wxDELETE(wxWHITE_PEN);
441 wxDELETE(wxTRANSPARENT_PEN);
442 wxDELETE(wxBLACK_DASHED_PEN);
443 wxDELETE(wxGREY_PEN);
444 wxDELETE(wxMEDIUM_GREY_PEN);
445 wxDELETE(wxLIGHT_GREY_PEN);
446
447 wxDELETE(wxBLUE_BRUSH);
448 wxDELETE(wxGREEN_BRUSH);
449 wxDELETE(wxWHITE_BRUSH);
450 wxDELETE(wxBLACK_BRUSH);
451 wxDELETE(wxTRANSPARENT_BRUSH);
452 wxDELETE(wxCYAN_BRUSH);
453 wxDELETE(wxRED_BRUSH);
454 wxDELETE(wxGREY_BRUSH);
455 wxDELETE(wxMEDIUM_GREY_BRUSH);
456 wxDELETE(wxLIGHT_GREY_BRUSH);
457
458 wxDELETE(wxBLACK);
459 wxDELETE(wxWHITE);
460 wxDELETE(wxRED);
461 wxDELETE(wxBLUE);
462 wxDELETE(wxGREEN);
463 wxDELETE(wxCYAN);
464 wxDELETE(wxLIGHT_GREY);
465
466 wxDELETE(wxSTANDARD_CURSOR);
467 wxDELETE(wxHOURGLASS_CURSOR);
468 wxDELETE(wxCROSS_CURSOR);
469 }
470
471 void wxDeleteStockLists() {
472 wxDELETE(wxTheBrushList);
473 wxDELETE(wxThePenList);
474 wxDELETE(wxTheFontList);
475 wxDELETE(wxTheBitmapList);
476 }
477
478 wxBitmapList::wxBitmapList ()
479 {
480 }
481
482 wxBitmapList::~wxBitmapList ()
483 {
484 wxNode *node = First ();
485 while (node)
486 {
487 wxBitmap *bitmap = (wxBitmap *) node->Data ();
488 wxNode *next = node->Next ();
489 if (bitmap->GetVisible())
490 delete bitmap;
491 node = next;
492 }
493 }
494
495 // Pen and Brush lists
496 wxPenList::~wxPenList ()
497 {
498 wxNode *node = First ();
499 while (node)
500 {
501 wxPen *pen = (wxPen *) node->Data ();
502 wxNode *next = node->Next ();
503 if (pen->GetVisible())
504 delete pen;
505 node = next;
506 }
507 }
508
509 void wxPenList::AddPen (wxPen * pen)
510 {
511 Append (pen);
512 }
513
514 void wxPenList::RemovePen (wxPen * pen)
515 {
516 DeleteObject (pen);
517 }
518
519 wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
520 {
521 for (wxNode * node = First (); node; node = node->Next ())
522 {
523 wxPen *each_pen = (wxPen *) node->Data ();
524 if (each_pen &&
525 each_pen->GetVisible() &&
526 each_pen->GetWidth () == width &&
527 each_pen->GetStyle () == style &&
528 each_pen->GetColour ().Red () == colour.Red () &&
529 each_pen->GetColour ().Green () == colour.Green () &&
530 each_pen->GetColour ().Blue () == colour.Blue ())
531 return each_pen;
532 }
533 wxPen *pen = new wxPen (colour, width, style);
534
535 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
536 // because we created it within FindOrCreatePen. Safeguards against
537 // returning a pointer to an automatic variable and hanging on to it
538 // (dangling pointer).
539 pen->SetVisible(TRUE);
540
541 return pen;
542 }
543
544 wxBrushList::~wxBrushList ()
545 {
546 wxNode *node = First ();
547 while (node)
548 {
549 wxBrush *brush = (wxBrush *) node->Data ();
550 wxNode *next = node->Next ();
551 if (brush->GetVisible())
552 delete brush;
553 node = next;
554 }
555 }
556
557 void wxBrushList::AddBrush (wxBrush * brush)
558 {
559 Append (brush);
560 }
561
562 wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
563 {
564 for (wxNode * node = First (); node; node = node->Next ())
565 {
566 wxBrush *each_brush = (wxBrush *) node->Data ();
567 if (each_brush &&
568 each_brush->GetVisible() &&
569 each_brush->GetStyle () == style &&
570 each_brush->GetColour ().Red () == colour.Red () &&
571 each_brush->GetColour ().Green () == colour.Green () &&
572 each_brush->GetColour ().Blue () == colour.Blue ())
573 return each_brush;
574 }
575
576 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
577 // because we created it within FindOrCreateBrush. Safeguards against
578 // returning a pointer to an automatic variable and hanging on to it
579 // (dangling pointer).
580 wxBrush *brush = new wxBrush (colour, style);
581
582 brush->SetVisible(TRUE);
583
584 return brush;
585 }
586
587 void wxBrushList::RemoveBrush (wxBrush * brush)
588 {
589 DeleteObject (brush);
590 }
591
592 wxFontList::~wxFontList ()
593 {
594 wxNode *node = First ();
595 while (node)
596 {
597 // Only delete objects that are 'visible', i.e.
598 // that have been created using FindOrCreate...,
599 // where the pointers are expected to be shared
600 // (and therefore not deleted by any one part of an app).
601 wxFont *font = (wxFont *) node->Data ();
602 wxNode *next = node->Next ();
603 if (font->GetVisible())
604 delete font;
605 node = next;
606 }
607 }
608
609 void wxFontList::AddFont (wxFont * font)
610 {
611 Append (font);
612 }
613
614 void wxFontList::RemoveFont (wxFont * font)
615 {
616 DeleteObject (font);
617 }
618
619 wxFont *wxFontList::FindOrCreateFont(int pointSize,
620 int family,
621 int style,
622 int weight,
623 bool underline,
624 const wxString& facename,
625 wxFontEncoding encoding)
626 {
627 wxFont *font = (wxFont *)NULL;
628 wxNode *node;
629 for ( node = First(); node; node = node->Next() )
630 {
631 font = (wxFont *)node->Data();
632 if ( font->GetVisible() &&
633 font->Ok() &&
634 font->GetPointSize () == pointSize &&
635 font->GetStyle () == style &&
636 font->GetWeight () == weight &&
637 font->GetUnderlined () == underline )
638 {
639 int fontFamily = font->GetFamily();
640
641 #if defined(__WXGTK__)
642 // under GTK the default family is wxSWISS, so looking for a font
643 // with wxDEFAULT family should return a wxSWISS one instead of
644 // creating a new one
645 bool same = (fontFamily == family) ||
646 (fontFamily == wxSWISS && family == wxDEFAULT);
647 #else // !GTK
648 // VZ: but why elsewhere do we require an exact match? mystery...
649 bool same = fontFamily == family;
650 #endif // GTK/!GTK
651
652 // empty facename matches anything at all: this is bad because
653 // depending on which fonts are already created, we might get back
654 // a different font if we create it with empty facename, but it is
655 // still better than never matching anything in the cache at all
656 // in this case
657 if ( same && !!facename )
658 {
659 const wxString& fontFace = font->GetFaceName();
660
661 // empty facename matches everything
662 same = !fontFace || fontFace == facename;
663 }
664
665 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
666 {
667 // have to match the encoding too
668 same = font->GetEncoding() == encoding;
669 }
670
671 if ( same )
672 {
673 return font;
674 }
675 }
676 }
677
678 if ( !node )
679 {
680 // font not found, create the new one
681 font = new wxFont(pointSize, family, style, weight,
682 underline, facename, encoding);
683
684 // and mark it as being cacheable
685 font->SetVisible(TRUE);
686 }
687
688 return font;
689 }
690
691 void wxBitmapList::AddBitmap(wxBitmap *bitmap)
692 {
693 Append(bitmap);
694 }
695
696 void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
697 {
698 DeleteObject(bitmap);
699 }
700
701 wxSize wxGetDisplaySize()
702 {
703 int x, y;
704 wxDisplaySize(& x, & y);
705 return wxSize(x, y);
706 }
707
708 wxSize wxGetDisplaySizeMM()
709 {
710 int x, y;
711 wxDisplaySizeMM(& x, & y);
712 return wxSize(x, y);
713 }
714
715 wxResourceCache::~wxResourceCache ()
716 {
717 wxNode *node = First ();
718 while (node) {
719 wxObject *item = (wxObject *)node->Data();
720 delete item;
721
722 node = node->Next ();
723 }
724 }
725