]> git.saurik.com Git - wxWidgets.git/blob - src/common/gdicmn.cpp
compilation fixes - wxGTK compiles but not links
[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 wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
117 {
118 x -= dx;
119 y -= dy;
120 width += 2*dx;
121 height += 2*dy;
122
123 // check that we didn't make the rectangle invalid by accident (you almost
124 // never want to have negative coords and never want negative size)
125 wxASSERT_MSG( x >= 0 && y >= 0 && width >= 0 && height >= 0,
126 _T("wxRect::Inflate() resulted in an invalid rectangle!") );
127
128 return *this;
129 }
130
131 bool wxRect::Inside(int cx, int cy) const
132 {
133 return ( (cx >= x) && (cy >= y)
134 && ((cy - y) < height)
135 && ((cx - x) < width)
136 );
137 }
138
139 wxRect& wxRect::Intersect(const wxRect& rect)
140 {
141 int x2 = GetRight(),
142 y2 = GetBottom();
143
144 if ( x < rect.x )
145 x = rect.x;
146 if ( y < rect.y )
147 y = rect.y;
148 if ( x2 > rect.GetRight() )
149 x2 = rect.GetRight();
150 if ( y2 > rect.GetBottom() )
151 y2 = rect.GetBottom();
152
153 width = x2 - x + 1;
154 height = y2 - y + 1;
155
156 if ( width <= 0 || height <= 0 )
157 {
158 width =
159 height = 0;
160 }
161
162 return *this;
163 }
164
165 bool wxRect::Intersects(const wxRect& rect) const
166 {
167 wxRect r = Intersect(rect);
168
169 // if there is no intersection, both width and height are 0
170 return r.width != 0;
171 }
172
173 wxColourDatabase::wxColourDatabase (int type) : wxList (type)
174 {
175 }
176
177 wxColourDatabase::~wxColourDatabase ()
178 {
179 // Cleanup Colour allocated in Initialize()
180 wxNode *node = First ();
181 while (node)
182 {
183 wxColour *col = (wxColour *) node->Data ();
184 wxNode *next = node->Next ();
185 delete col;
186 node = next;
187 }
188 #ifdef __WXPM__
189 delete [] m_palTable;
190 #endif
191 }
192
193 // Colour database stuff
194 void wxColourDatabase::Initialize ()
195 {
196 static const struct wxColourDesc
197 {
198 const wxChar *name;
199 int r,g,b;
200 }
201 wxColourTable[] =
202 {
203 {wxT("AQUAMARINE"),112, 219, 147},
204 {wxT("BLACK"),0, 0, 0},
205 {wxT("BLUE"), 0, 0, 255},
206 {wxT("BLUE VIOLET"), 159, 95, 159},
207 {wxT("BROWN"), 165, 42, 42},
208 {wxT("CADET BLUE"), 95, 159, 159},
209 {wxT("CORAL"), 255, 127, 0},
210 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
211 {wxT("CYAN"), 0, 255, 255},
212 {wxT("DARK GREY"), 47, 47, 47}, // ?
213
214 {wxT("DARK GREEN"), 47, 79, 47},
215 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
216 {wxT("DARK ORCHID"), 153, 50, 204},
217 {wxT("DARK SLATE BLUE"), 107, 35, 142},
218 {wxT("DARK SLATE GREY"), 47, 79, 79},
219 {wxT("DARK TURQUOISE"), 112, 147, 219},
220 {wxT("DIM GREY"), 84, 84, 84},
221 {wxT("FIREBRICK"), 142, 35, 35},
222 {wxT("FOREST GREEN"), 35, 142, 35},
223 {wxT("GOLD"), 204, 127, 50},
224 {wxT("GOLDENROD"), 219, 219, 112},
225 {wxT("GREY"), 128, 128, 128},
226 {wxT("GREEN"), 0, 255, 0},
227 {wxT("GREEN YELLOW"), 147, 219, 112},
228 {wxT("INDIAN RED"), 79, 47, 47},
229 {wxT("KHAKI"), 159, 159, 95},
230 {wxT("LIGHT BLUE"), 191, 216, 216},
231 {wxT("LIGHT GREY"), 192, 192, 192},
232 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
233 {wxT("LIME GREEN"), 50, 204, 50},
234 {wxT("LIGHT MAGENTA"), 255, 0, 255},
235 {wxT("MAGENTA"), 255, 0, 255},
236 {wxT("MAROON"), 142, 35, 107},
237 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
238 {wxT("MEDIUM GREY"), 100, 100, 100},
239 {wxT("MEDIUM BLUE"), 50, 50, 204},
240 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
241 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
242 {wxT("MEDIUM ORCHID"), 147, 112, 219},
243 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
244 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
245 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
246 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
247 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
248 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
249 {wxT("NAVY"), 35, 35, 142},
250 {wxT("ORANGE"), 204, 50, 50},
251 {wxT("ORANGE RED"), 255, 0, 127},
252 {wxT("ORCHID"), 219, 112, 219},
253 {wxT("PALE GREEN"), 143, 188, 143},
254 {wxT("PINK"), 188, 143, 234},
255 {wxT("PLUM"), 234, 173, 234},
256 {wxT("PURPLE"), 176, 0, 255},
257 {wxT("RED"), 255, 0, 0},
258 {wxT("SALMON"), 111, 66, 66},
259 {wxT("SEA GREEN"), 35, 142, 107},
260 {wxT("SIENNA"), 142, 107, 35},
261 {wxT("SKY BLUE"), 50, 153, 204},
262 {wxT("SLATE BLUE"), 0, 127, 255},
263 {wxT("SPRING GREEN"), 0, 255, 127},
264 {wxT("STEEL BLUE"), 35, 107, 142},
265 {wxT("TAN"), 219, 147, 112},
266 {wxT("THISTLE"), 216, 191, 216},
267 {wxT("TURQUOISE"), 173, 234, 234},
268 {wxT("VIOLET"), 79, 47, 79},
269 {wxT("VIOLET RED"), 204, 50, 153},
270 {wxT("WHEAT"), 216, 216, 191},
271 {wxT("WHITE"), 255, 255, 255},
272 {wxT("YELLOW"), 255, 255, 0},
273 {wxT("YELLOW GREEN"), 153, 204, 50},
274 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
275 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
276 {wxT("LIGHT MAGENTA"), 255, 0, 255},
277 {wxT("MEDIUM GREY"), 100, 100, 100},
278 };
279
280 size_t n;
281
282 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
283 {
284 const wxColourDesc& cc = wxColourTable[n];
285 Append(cc.name, new wxColour(cc.r,cc.g,cc.b));
286 }
287 #ifdef __WXPM__
288 m_palTable = new long[n];
289 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
290 {
291 const wxColourDesc& cc = wxColourTable[n];
292 m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b);
293 }
294 m_nSize = n;
295 #endif
296 }
297
298 /*
299 * Changed by Ian Brown, July 1994.
300 *
301 * When running under X, the Colour Database starts off empty. The X server
302 * is queried for the colour first time after which it is entered into the
303 * database. This allows our client to use the server colour database which
304 * is hopefully gamma corrected for the display being used.
305 */
306
307 wxColour *wxColourDatabase::FindColour(const wxString& colour)
308 {
309 // VZ: make the comparaison case insensitive and also match both grey and
310 // gray
311 wxString colName = colour;
312 colName.MakeUpper();
313 wxString colName2 = colName;
314 if ( !colName2.Replace(_T("GRAY"), _T("GREY")) )
315 colName2.clear();
316
317 wxNode *node = First();
318 while ( node )
319 {
320 const wxChar *key = node->GetKeyString();
321 if ( colName == key || colName2 == key )
322 {
323 return (wxColour *)node->Data();
324 }
325
326 node = node->Next();
327 }
328
329 #ifdef __WXMSW__
330 return NULL;
331 #endif
332 #ifdef __WXPM__
333 return NULL;
334 #endif
335 #ifdef __WXMGL__
336 return NULL;
337 #endif
338
339 // TODO for other implementations. This should really go into
340 // platform-specific directories.
341 #ifdef __WXMAC__
342 return NULL;
343 #endif
344 #ifdef __WXSTUBS__
345 return NULL;
346 #endif
347
348 #ifdef __WXGTK__
349 wxColour *col = new wxColour( colour );
350
351 if (!(col->Ok())) {
352 delete col;
353 return (wxColour *) NULL;
354 }
355 Append( colour, col );
356 return col;
357 #endif
358
359 #ifdef __X__
360 XColor xcolour;
361
362 #ifdef __WXMOTIF__
363 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
364 #endif
365 #ifdef __XVIEW__
366 Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
367 Xv_opaque root_window = xv_get(screen, XV_ROOT);
368 Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
369 #endif
370
371 /* MATTHEW: [4] Use wxGetMainColormap */
372 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))
373 return NULL;
374
375 unsigned char r = (unsigned char)(xcolour.red >> 8);
376 unsigned char g = (unsigned char)(xcolour.green >> 8);
377 unsigned char b = (unsigned char)(xcolour.blue >> 8);
378
379 wxColour *col = new wxColour(r, g, b);
380 Append(colour, col);
381
382 return col;
383 #endif // __X__
384 }
385
386 wxString wxColourDatabase::FindName (const wxColour& colour) const
387 {
388 wxString name;
389
390 unsigned char red = colour.Red ();
391 unsigned char green = colour.Green ();
392 unsigned char blue = colour.Blue ();
393
394 for (wxNode * node = First (); node; node = node->Next ())
395 {
396 wxColour *col = (wxColour *) node->Data ();
397
398 if (col->Red () == red && col->Green () == green && col->Blue () == blue)
399 {
400 const wxChar *found = node->GetKeyString();
401 if ( found )
402 {
403 name = found;
404
405 break;
406 }
407 }
408 }
409
410 return name;
411 }
412
413 void wxInitializeStockLists () {
414 wxTheBrushList = new wxBrushList;
415 wxThePenList = new wxPenList;
416 wxTheFontList = new wxFontList;
417 wxTheBitmapList = new wxBitmapList;
418 }
419
420 void wxInitializeStockObjects ()
421 {
422 #ifdef __WXMOTIF__
423 #endif
424 #ifdef __X__
425 // TODO
426 // wxFontPool = new XFontPool;
427 #endif
428
429 // why under MSW fonts shouldn't have the standard system size?
430 /*
431 #ifdef __WXMSW__
432 static const int sizeFont = 10;
433 #else
434 #endif
435 */
436 #if defined(__WXPM__) || defined(__WXMAC__)
437 static const int sizeFont = 12;
438 wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL);
439 #else
440 wxNORMAL_FONT = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
441 static const int sizeFont = wxNORMAL_FONT->GetPointSize();
442 #endif
443
444 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
445 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
446 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
447
448 wxRED_PEN = new wxPen ("RED", 1, wxSOLID);
449 wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID);
450 wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID);
451 wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID);
452 wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID);
453 wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT);
454 wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH);
455 wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID);
456 wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID);
457 wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID);
458
459 wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID);
460 wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID);
461 wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID);
462 wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID);
463 wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT);
464 wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID);
465 wxRED_BRUSH = new wxBrush ("RED", wxSOLID);
466 wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID);
467 wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID);
468 wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID);
469
470 wxBLACK = new wxColour ("BLACK");
471 wxWHITE = new wxColour ("WHITE");
472 wxRED = new wxColour ("RED");
473 wxBLUE = new wxColour ("BLUE");
474 wxGREEN = new wxColour ("GREEN");
475 wxCYAN = new wxColour ("CYAN");
476 wxLIGHT_GREY = new wxColour ("LIGHT GREY");
477
478 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
479 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
480 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
481 }
482
483 void wxDeleteStockObjects ()
484 {
485 wxDELETE(wxNORMAL_FONT);
486 wxDELETE(wxSMALL_FONT);
487 wxDELETE(wxITALIC_FONT);
488 wxDELETE(wxSWISS_FONT);
489
490 wxDELETE(wxRED_PEN);
491 wxDELETE(wxCYAN_PEN);
492 wxDELETE(wxGREEN_PEN);
493 wxDELETE(wxBLACK_PEN);
494 wxDELETE(wxWHITE_PEN);
495 wxDELETE(wxTRANSPARENT_PEN);
496 wxDELETE(wxBLACK_DASHED_PEN);
497 wxDELETE(wxGREY_PEN);
498 wxDELETE(wxMEDIUM_GREY_PEN);
499 wxDELETE(wxLIGHT_GREY_PEN);
500
501 wxDELETE(wxBLUE_BRUSH);
502 wxDELETE(wxGREEN_BRUSH);
503 wxDELETE(wxWHITE_BRUSH);
504 wxDELETE(wxBLACK_BRUSH);
505 wxDELETE(wxTRANSPARENT_BRUSH);
506 wxDELETE(wxCYAN_BRUSH);
507 wxDELETE(wxRED_BRUSH);
508 wxDELETE(wxGREY_BRUSH);
509 wxDELETE(wxMEDIUM_GREY_BRUSH);
510 wxDELETE(wxLIGHT_GREY_BRUSH);
511
512 wxDELETE(wxBLACK);
513 wxDELETE(wxWHITE);
514 wxDELETE(wxRED);
515 wxDELETE(wxBLUE);
516 wxDELETE(wxGREEN);
517 wxDELETE(wxCYAN);
518 wxDELETE(wxLIGHT_GREY);
519
520 wxDELETE(wxSTANDARD_CURSOR);
521 wxDELETE(wxHOURGLASS_CURSOR);
522 wxDELETE(wxCROSS_CURSOR);
523 }
524
525 void wxDeleteStockLists() {
526 wxDELETE(wxTheBrushList);
527 wxDELETE(wxThePenList);
528 wxDELETE(wxTheFontList);
529 wxDELETE(wxTheBitmapList);
530 }
531
532 wxBitmapList::wxBitmapList ()
533 {
534 }
535
536 wxBitmapList::~wxBitmapList ()
537 {
538 wxNode *node = First ();
539 while (node)
540 {
541 wxBitmap *bitmap = (wxBitmap *) node->Data ();
542 wxNode *next = node->Next ();
543 if (bitmap->GetVisible())
544 delete bitmap;
545 node = next;
546 }
547 }
548
549 // Pen and Brush lists
550 wxPenList::~wxPenList ()
551 {
552 wxNode *node = First ();
553 while (node)
554 {
555 wxPen *pen = (wxPen *) node->Data ();
556 wxNode *next = node->Next ();
557 if (pen->GetVisible())
558 delete pen;
559 node = next;
560 }
561 }
562
563 void wxPenList::AddPen (wxPen * pen)
564 {
565 Append (pen);
566 }
567
568 void wxPenList::RemovePen (wxPen * pen)
569 {
570 DeleteObject (pen);
571 }
572
573 wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
574 {
575 for (wxNode * node = First (); node; node = node->Next ())
576 {
577 wxPen *each_pen = (wxPen *) node->Data ();
578 if (each_pen &&
579 each_pen->GetVisible() &&
580 each_pen->GetWidth () == width &&
581 each_pen->GetStyle () == style &&
582 each_pen->GetColour ().Red () == colour.Red () &&
583 each_pen->GetColour ().Green () == colour.Green () &&
584 each_pen->GetColour ().Blue () == colour.Blue ())
585 return each_pen;
586 }
587
588 wxPen *pen = new wxPen (colour, width, style);
589 if ( !pen->Ok() )
590 {
591 // don't save the invalid pens in the list
592 delete pen;
593
594 return NULL;
595 }
596
597 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
598 // because we created it within FindOrCreatePen. Safeguards against
599 // returning a pointer to an automatic variable and hanging on to it
600 // (dangling pointer).
601 pen->SetVisible(TRUE);
602
603 return pen;
604 }
605
606 wxBrushList::~wxBrushList ()
607 {
608 wxNode *node = First ();
609 while (node)
610 {
611 wxBrush *brush = (wxBrush *) node->Data ();
612 wxNode *next = node->Next ();
613 if (brush->GetVisible())
614 delete brush;
615 node = next;
616 }
617 }
618
619 void wxBrushList::AddBrush (wxBrush * brush)
620 {
621 Append (brush);
622 }
623
624 wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
625 {
626 for (wxNode * node = First (); node; node = node->Next ())
627 {
628 wxBrush *each_brush = (wxBrush *) node->Data ();
629 if (each_brush &&
630 each_brush->GetVisible() &&
631 each_brush->GetStyle () == style &&
632 each_brush->GetColour ().Red () == colour.Red () &&
633 each_brush->GetColour ().Green () == colour.Green () &&
634 each_brush->GetColour ().Blue () == colour.Blue ())
635 return each_brush;
636 }
637
638 wxBrush *brush = new wxBrush (colour, style);
639
640 if ( !brush->Ok() )
641 {
642 // don't put the brushes we failed to create into the list
643 delete brush;
644
645 return NULL;
646 }
647
648 brush->SetVisible(TRUE);
649
650 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
651 // because we created it within FindOrCreateBrush. Safeguards against
652 // returning a pointer to an automatic variable and hanging on to it
653 // (dangling pointer).
654 return brush;
655 }
656
657 void wxBrushList::RemoveBrush (wxBrush * brush)
658 {
659 DeleteObject (brush);
660 }
661
662 wxFontList::~wxFontList ()
663 {
664 wxNode *node = First ();
665 while (node)
666 {
667 // Only delete objects that are 'visible', i.e.
668 // that have been created using FindOrCreate...,
669 // where the pointers are expected to be shared
670 // (and therefore not deleted by any one part of an app).
671 wxFont *font = (wxFont *) node->Data ();
672 wxNode *next = node->Next ();
673 if (font->GetVisible())
674 delete font;
675 node = next;
676 }
677 }
678
679 void wxFontList::AddFont (wxFont * font)
680 {
681 Append (font);
682 }
683
684 void wxFontList::RemoveFont (wxFont * font)
685 {
686 DeleteObject (font);
687 }
688
689 wxFont *wxFontList::FindOrCreateFont(int pointSize,
690 int family,
691 int style,
692 int weight,
693 bool underline,
694 const wxString& facename,
695 wxFontEncoding encoding)
696 {
697 wxFont *font = (wxFont *)NULL;
698 wxNode *node;
699 for ( node = First(); node; node = node->Next() )
700 {
701 font = (wxFont *)node->Data();
702 if ( font->GetVisible() &&
703 font->Ok() &&
704 font->GetPointSize () == pointSize &&
705 font->GetStyle () == style &&
706 font->GetWeight () == weight &&
707 font->GetUnderlined () == underline )
708 {
709 int fontFamily = font->GetFamily();
710
711 #if defined(__WXGTK__)
712 // under GTK the default family is wxSWISS, so looking for a font
713 // with wxDEFAULT family should return a wxSWISS one instead of
714 // creating a new one
715 bool same = (fontFamily == family) ||
716 (fontFamily == wxSWISS && family == wxDEFAULT);
717 #else // !GTK
718 // VZ: but why elsewhere do we require an exact match? mystery...
719 bool same = fontFamily == family;
720 #endif // GTK/!GTK
721
722 // empty facename matches anything at all: this is bad because
723 // depending on which fonts are already created, we might get back
724 // a different font if we create it with empty facename, but it is
725 // still better than never matching anything in the cache at all
726 // in this case
727 if ( same && !!facename )
728 {
729 const wxString& fontFace = font->GetFaceName();
730
731 // empty facename matches everything
732 same = !fontFace || fontFace == facename;
733 }
734
735 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
736 {
737 // have to match the encoding too
738 same = font->GetEncoding() == encoding;
739 }
740
741 if ( same )
742 {
743 return font;
744 }
745 }
746 }
747
748 if ( !node )
749 {
750 // font not found, create the new one
751 font = new wxFont(pointSize, family, style, weight,
752 underline, facename, encoding);
753
754 // and mark it as being cacheable
755 font->SetVisible(TRUE);
756 }
757
758 return font;
759 }
760
761 void wxBitmapList::AddBitmap(wxBitmap *bitmap)
762 {
763 Append(bitmap);
764 }
765
766 void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
767 {
768 DeleteObject(bitmap);
769 }
770
771 wxSize wxGetDisplaySize()
772 {
773 int x, y;
774 wxDisplaySize(& x, & y);
775 return wxSize(x, y);
776 }
777
778 wxRect wxGetClientDisplayRect()
779 {
780 int x, y, width, height;
781 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
782 return wxRect(x, y, width, height);
783 }
784
785 wxSize wxGetDisplaySizeMM()
786 {
787 int x, y;
788 wxDisplaySizeMM(& x, & y);
789 return wxSize(x, y);
790 }
791
792 wxResourceCache::~wxResourceCache ()
793 {
794 wxNode *node = First ();
795 while (node) {
796 wxObject *item = (wxObject *)node->Data();
797 delete item;
798
799 node = node->Next ();
800 }
801 }
802