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