]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/gdicmn.cpp
bitmap button size was too small when uxtheme functions were used to get the margins
[wxWidgets.git] / src / common / gdicmn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#include "wx/gdicmn.h"
20
21#ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/pen.h"
24 #include "wx/brush.h"
25 #include "wx/palette.h"
26 #include "wx/icon.h"
27 #include "wx/cursor.h"
28 #include "wx/settings.h"
29 #include "wx/bitmap.h"
30 #include "wx/colour.h"
31 #include "wx/font.h"
32#endif
33
34WXDLLIMPEXP_DATA_CORE(wxBrushList*) wxTheBrushList;
35WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList;
36WXDLLIMPEXP_DATA_CORE(wxPenList*) wxThePenList;
37
38WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase;
39
40WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap;
41WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush;
42WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour;
43WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor;
44WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont;
45WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon;
46WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen;
47#if wxUSE_PALETTE
48WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette;
49#endif
50
51const wxSize wxDefaultSize(wxDefaultCoord, wxDefaultCoord);
52const wxPoint wxDefaultPosition(wxDefaultCoord, wxDefaultCoord);
53
54#if wxUSE_EXTENDED_RTTI
55
56// wxPoint
57
58template<> void wxStringReadValue(const wxString &s , wxPoint &data )
59{
60 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
61}
62
63template<> void wxStringWriteValue(wxString &s , const wxPoint &data )
64{
65 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
66}
67
68wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>)
69
70template<> void wxStringReadValue(const wxString &s , wxSize &data )
71{
72 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
73}
74
75template<> void wxStringWriteValue(wxString &s , const wxSize &data )
76{
77 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
78}
79
80wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>)
81
82#endif
83
84wxRect::wxRect(const wxPoint& point1, const wxPoint& point2)
85{
86 x = point1.x;
87 y = point1.y;
88 width = point2.x - point1.x;
89 height = point2.y - point1.y;
90
91 if (width < 0)
92 {
93 width = -width;
94 x = point2.x;
95 }
96 width++;
97
98 if (height < 0)
99 {
100 height = -height;
101 y = point2.y;
102 }
103 height++;
104}
105
106bool wxRect::operator==(const wxRect& rect) const
107{
108 return ((x == rect.x) &&
109 (y == rect.y) &&
110 (width == rect.width) &&
111 (height == rect.height));
112}
113
114wxRect wxRect::operator+(const wxRect& rect) const
115{
116 int x1 = wxMin(this->x, rect.x);
117 int y1 = wxMin(this->y, rect.y);
118 int y2 = wxMax(y+height, rect.height+rect.y);
119 int x2 = wxMax(x+width, rect.width+rect.x);
120 return wxRect(x1, y1, x2-x1, y2-y1);
121}
122
123wxRect& wxRect::Union(const wxRect& rect)
124{
125 // ignore empty rectangles: union with an empty rectangle shouldn't extend
126 // this one to (0, 0)
127 if ( !width || !height )
128 {
129 *this = rect;
130 }
131 else if ( rect.width && rect.height )
132 {
133 int x1 = wxMin(x, rect.x);
134 int y1 = wxMin(y, rect.y);
135 int y2 = wxMax(y + height, rect.height + rect.y);
136 int x2 = wxMax(x + width, rect.width + rect.x);
137
138 x = x1;
139 y = y1;
140 width = x2 - x1;
141 height = y2 - y1;
142 }
143 //else: we're not empty and rect is empty
144
145 return *this;
146}
147
148wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
149{
150 if (-2*dx>width)
151 {
152 // Don't allow deflate to eat more width than we have,
153 // a well-defined rectangle cannot have negative width.
154 x+=width/2;
155 width=0;
156 }
157 else
158 {
159 // The inflate is valid.
160 x-=dx;
161 width+=2*dx;
162 }
163
164 if (-2*dy>height)
165 {
166 // Don't allow deflate to eat more height than we have,
167 // a well-defined rectangle cannot have negative height.
168 y+=height/2;
169 height=0;
170 }
171 else
172 {
173 // The inflate is valid.
174 y-=dy;
175 height+=2*dy;
176 }
177
178 return *this;
179}
180
181bool wxRect::Inside(int cx, int cy) const
182{
183 return ( (cx >= x) && (cy >= y)
184 && ((cy - y) < height)
185 && ((cx - x) < width)
186 );
187}
188
189wxRect& wxRect::Intersect(const wxRect& rect)
190{
191 int x2 = GetRight(),
192 y2 = GetBottom();
193
194 if ( x < rect.x )
195 x = rect.x;
196 if ( y < rect.y )
197 y = rect.y;
198 if ( x2 > rect.GetRight() )
199 x2 = rect.GetRight();
200 if ( y2 > rect.GetBottom() )
201 y2 = rect.GetBottom();
202
203 width = x2 - x + 1;
204 height = y2 - y + 1;
205
206 if ( width <= 0 || height <= 0 )
207 {
208 width =
209 height = 0;
210 }
211
212 return *this;
213}
214
215bool wxRect::Intersects(const wxRect& rect) const
216{
217 wxRect r = Intersect(rect);
218
219 // if there is no intersection, both width and height are 0
220 return r.width != 0;
221}
222
223// ============================================================================
224// wxColourDatabase
225// ============================================================================
226
227// ----------------------------------------------------------------------------
228// wxColourDatabase ctor/dtor
229// ----------------------------------------------------------------------------
230
231wxColourDatabase::wxColourDatabase ()
232{
233 // will be created on demand in Initialize()
234 m_map = NULL;
235}
236
237wxColourDatabase::~wxColourDatabase ()
238{
239 if ( m_map )
240 {
241 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
242
243 delete m_map;
244 }
245
246#ifdef __WXPM__
247 delete [] m_palTable;
248#endif
249}
250
251// Colour database stuff
252void wxColourDatabase::Initialize()
253{
254 if ( m_map )
255 {
256 // already initialized
257 return;
258 }
259
260 m_map = new wxStringToColourHashMap;
261
262 static const struct wxColourDesc
263 {
264 const wxChar *name;
265 unsigned char r,g,b;
266 }
267 wxColourTable[] =
268 {
269 {wxT("AQUAMARINE"),112, 219, 147},
270 {wxT("BLACK"),0, 0, 0},
271 {wxT("BLUE"), 0, 0, 255},
272 {wxT("BLUE VIOLET"), 159, 95, 159},
273 {wxT("BROWN"), 165, 42, 42},
274 {wxT("CADET BLUE"), 95, 159, 159},
275 {wxT("CORAL"), 255, 127, 0},
276 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
277 {wxT("CYAN"), 0, 255, 255},
278 {wxT("DARK GREY"), 47, 47, 47}, // ?
279
280 {wxT("DARK GREEN"), 47, 79, 47},
281 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
282 {wxT("DARK ORCHID"), 153, 50, 204},
283 {wxT("DARK SLATE BLUE"), 107, 35, 142},
284 {wxT("DARK SLATE GREY"), 47, 79, 79},
285 {wxT("DARK TURQUOISE"), 112, 147, 219},
286 {wxT("DIM GREY"), 84, 84, 84},
287 {wxT("FIREBRICK"), 142, 35, 35},
288 {wxT("FOREST GREEN"), 35, 142, 35},
289 {wxT("GOLD"), 204, 127, 50},
290 {wxT("GOLDENROD"), 219, 219, 112},
291 {wxT("GREY"), 128, 128, 128},
292 {wxT("GREEN"), 0, 255, 0},
293 {wxT("GREEN YELLOW"), 147, 219, 112},
294 {wxT("INDIAN RED"), 79, 47, 47},
295 {wxT("KHAKI"), 159, 159, 95},
296 {wxT("LIGHT BLUE"), 191, 216, 216},
297 {wxT("LIGHT GREY"), 192, 192, 192},
298 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
299 {wxT("LIME GREEN"), 50, 204, 50},
300 {wxT("LIGHT MAGENTA"), 255, 0, 255},
301 {wxT("MAGENTA"), 255, 0, 255},
302 {wxT("MAROON"), 142, 35, 107},
303 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
304 {wxT("MEDIUM GREY"), 100, 100, 100},
305 {wxT("MEDIUM BLUE"), 50, 50, 204},
306 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
307 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
308 {wxT("MEDIUM ORCHID"), 147, 112, 219},
309 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
310 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
311 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
312 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
313 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
314 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
315 {wxT("NAVY"), 35, 35, 142},
316 {wxT("ORANGE"), 204, 50, 50},
317 {wxT("ORANGE RED"), 255, 0, 127},
318 {wxT("ORCHID"), 219, 112, 219},
319 {wxT("PALE GREEN"), 143, 188, 143},
320 {wxT("PINK"), 188, 143, 234},
321 {wxT("PLUM"), 234, 173, 234},
322 {wxT("PURPLE"), 176, 0, 255},
323 {wxT("RED"), 255, 0, 0},
324 {wxT("SALMON"), 111, 66, 66},
325 {wxT("SEA GREEN"), 35, 142, 107},
326 {wxT("SIENNA"), 142, 107, 35},
327 {wxT("SKY BLUE"), 50, 153, 204},
328 {wxT("SLATE BLUE"), 0, 127, 255},
329 {wxT("SPRING GREEN"), 0, 255, 127},
330 {wxT("STEEL BLUE"), 35, 107, 142},
331 {wxT("TAN"), 219, 147, 112},
332 {wxT("THISTLE"), 216, 191, 216},
333 {wxT("TURQUOISE"), 173, 234, 234},
334 {wxT("VIOLET"), 79, 47, 79},
335 {wxT("VIOLET RED"), 204, 50, 153},
336 {wxT("WHEAT"), 216, 216, 191},
337 {wxT("WHITE"), 255, 255, 255},
338 {wxT("YELLOW"), 255, 255, 0},
339 {wxT("YELLOW GREEN"), 153, 204, 50}
340 };
341
342 size_t n;
343
344 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
345 {
346 const wxColourDesc& cc = wxColourTable[n];
347 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
348 }
349
350#ifdef __WXPM__
351 m_palTable = new long[n];
352 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
353 {
354 const wxColourDesc& cc = wxColourTable[n];
355 m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b);
356 }
357 m_nSize = n;
358#endif
359}
360
361// ----------------------------------------------------------------------------
362// wxColourDatabase operations
363// ----------------------------------------------------------------------------
364
365void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
366{
367 Initialize();
368
369 // canonicalize the colour names before using them as keys: they should be
370 // in upper case
371 wxString colName = name;
372 colName.MakeUpper();
373
374 // ... and we also allow both grey/gray
375 wxString colNameAlt = colName;
376 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
377 {
378 // but in this case it is not necessary so avoid extra search below
379 colNameAlt.clear();
380 }
381
382 wxStringToColourHashMap::iterator it = m_map->find(colName);
383 if ( it == m_map->end() && !colNameAlt.empty() )
384 it = m_map->find(colNameAlt);
385 if ( it != m_map->end() )
386 {
387 *(it->second) = colour;
388 }
389 else // new colour
390 {
391 (*m_map)[colName] = new wxColour(colour);
392 }
393}
394
395wxColour wxColourDatabase::Find(const wxString& colour) const
396{
397 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
398 self->Initialize();
399
400 // make the comparaison case insensitive and also match both grey and gray
401 wxString colName = colour;
402 colName.MakeUpper();
403 wxString colNameAlt = colName;
404 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
405 colNameAlt.clear();
406
407 wxStringToColourHashMap::iterator it = m_map->find(colName);
408 if ( it == m_map->end() && !colNameAlt.empty() )
409 it = m_map->find(colNameAlt);
410 if ( it != m_map->end() )
411 return *(it->second);
412
413 // we did not find any result in existing colours:
414 // we won't use wxString -> wxColour conversion because the
415 // wxColour::Set(const wxString &) function which does that conversion
416 // internally uses this function (wxColourDatabase::Find) and we want
417 // to avoid infinite recursion !
418 return wxNullColour;
419}
420
421wxString wxColourDatabase::FindName(const wxColour& colour) const
422{
423 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
424 self->Initialize();
425
426 typedef wxStringToColourHashMap::iterator iterator;
427
428 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
429 {
430 if ( *(it->second) == colour )
431 return it->first;
432 }
433
434 return wxEmptyString;
435}
436
437// ----------------------------------------------------------------------------
438// deprecated wxColourDatabase methods
439// ----------------------------------------------------------------------------
440
441#if WXWIN_COMPATIBILITY_2_6
442wxColour *wxColourDatabase::FindColour(const wxString& name)
443{
444 // This function is deprecated, use Find() instead.
445 // Formerly this function sometimes would return a deletable pointer and
446 // sometimes a non-deletable one (when returning a colour from the database).
447 // Trying to delete the latter anyway results in problems, so probably
448 // nobody ever freed the pointers. Currently it always returns a new
449 // instance, which means there will be memory leaks.
450 wxLogDebug(wxT("wxColourDataBase::FindColour():")
451 wxT(" Please use wxColourDataBase::Find() instead"));
452
453 // using a static variable here is not the most elegant solution but unless
454 // we want to make wxStringToColourHashMap public (i.e. move it to the
455 // header) so that we could have a member function returning
456 // wxStringToColourHashMap::iterator, there is really no good way to do it
457 // otherwise
458 //
459 // and knowing that this function is going to disappear in the next release
460 // anyhow I don't want to waste time on this
461
462 static wxColour s_col;
463
464 s_col = Find(name);
465 if ( !s_col.Ok() )
466 return NULL;
467
468 return new wxColour(s_col);
469}
470#endif // WXWIN_COMPATIBILITY_2_6
471
472// ============================================================================
473// stock objects
474// ============================================================================
475
476static wxStockGDI gs_wxStockGDI_instance;
477wxStockGDI* wxStockGDI::ms_instance = &gs_wxStockGDI_instance;
478wxObject* wxStockGDI::ms_stockObject[ITEMCOUNT];
479
480wxStockGDI::wxStockGDI()
481{
482}
483
484wxStockGDI::~wxStockGDI()
485{
486}
487
488void wxStockGDI::DeleteAll()
489{
490 for (unsigned i = 0; i < ITEMCOUNT; i++)
491 {
492 delete ms_stockObject[i];
493 ms_stockObject[i] = NULL;
494 }
495}
496
497const wxBrush* wxStockGDI::GetBrush(Item item)
498{
499 wxBrush* brush = wx_static_cast(wxBrush*, ms_stockObject[item]);
500 if (brush == NULL)
501 {
502 switch (item)
503 {
504 case BRUSH_BLACK:
505 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxSOLID);
506 break;
507 case BRUSH_BLUE:
508 brush = new wxBrush(*GetColour(COLOUR_BLUE), wxSOLID);
509 break;
510 case BRUSH_CYAN:
511 brush = new wxBrush(*GetColour(COLOUR_CYAN), wxSOLID);
512 break;
513 case BRUSH_GREEN:
514 brush = new wxBrush(*GetColour(COLOUR_GREEN), wxSOLID);
515 break;
516 case BRUSH_GREY:
517 brush = new wxBrush(wxColour(wxT("GREY")), wxSOLID);
518 break;
519 case BRUSH_LIGHTGREY:
520 brush = new wxBrush(*GetColour(COLOUR_LIGHTGREY), wxSOLID);
521 break;
522 case BRUSH_MEDIUMGREY:
523 brush = new wxBrush(wxColour(wxT("MEDIUM GREY")), wxSOLID);
524 break;
525 case BRUSH_RED:
526 brush = new wxBrush(*GetColour(COLOUR_RED), wxSOLID);
527 break;
528 case BRUSH_TRANSPARENT:
529 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxTRANSPARENT);
530 break;
531 case BRUSH_WHITE:
532 brush = new wxBrush(*GetColour(COLOUR_WHITE), wxSOLID);
533 break;
534 default:
535 wxFAIL;
536 }
537 ms_stockObject[item] = brush;
538 }
539 return brush;
540}
541
542const wxColour* wxStockGDI::GetColour(Item item)
543{
544 wxColour* colour = wx_static_cast(wxColour*, ms_stockObject[item]);
545 if (colour == NULL)
546 {
547 switch (item)
548 {
549 case COLOUR_BLACK:
550 colour = new wxColour(0, 0, 0);
551 break;
552 case COLOUR_BLUE:
553 colour = new wxColour(0, 0, 255);
554 break;
555 case COLOUR_CYAN:
556 colour = new wxColour(wxT("CYAN"));
557 break;
558 case COLOUR_GREEN:
559 colour = new wxColour(0, 255, 0);
560 break;
561 case COLOUR_LIGHTGREY:
562 colour = new wxColour(wxT("LIGHT GREY"));
563 break;
564 case COLOUR_RED:
565 colour = new wxColour(255, 0, 0);
566 break;
567 case COLOUR_WHITE:
568 colour = new wxColour(255, 255, 255);
569 break;
570 default:
571 wxFAIL;
572 }
573 ms_stockObject[item] = colour;
574 }
575 return colour;
576}
577
578const wxCursor* wxStockGDI::GetCursor(Item item)
579{
580 wxCursor* cursor = wx_static_cast(wxCursor*, ms_stockObject[item]);
581 if (cursor == NULL)
582 {
583 switch (item)
584 {
585 case CURSOR_CROSS:
586 cursor = new wxCursor(wxCURSOR_CROSS);
587 break;
588 case CURSOR_HOURGLASS:
589 cursor = new wxCursor(wxCURSOR_WAIT);
590 break;
591 case CURSOR_STANDARD:
592 cursor = new wxCursor(wxCURSOR_ARROW);
593 break;
594 default:
595 wxFAIL;
596 }
597 ms_stockObject[item] = cursor;
598 }
599 return cursor;
600}
601
602const wxFont* wxStockGDI::GetFont(Item item)
603{
604 wxFont* font = wx_static_cast(wxFont*, ms_stockObject[item]);
605 if (font == NULL)
606 {
607 switch (item)
608 {
609 case FONT_ITALIC:
610 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxROMAN, wxITALIC, wxNORMAL);
611 break;
612 case FONT_NORMAL:
613 font = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
614 break;
615 case FONT_SMALL:
616 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize() - 2, wxSWISS, wxNORMAL, wxNORMAL);
617 break;
618 case FONT_SWISS:
619 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxSWISS, wxNORMAL, wxNORMAL);
620 break;
621 default:
622 wxFAIL;
623 }
624 ms_stockObject[item] = font;
625 }
626 return font;
627}
628
629const wxPen* wxStockGDI::GetPen(Item item)
630{
631 wxPen* pen = wx_static_cast(wxPen*, ms_stockObject[item]);
632 if (pen == NULL)
633 {
634 switch (item)
635 {
636 case PEN_BLACK:
637 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxSOLID);
638 break;
639 case PEN_BLACKDASHED:
640 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxSHORT_DASH);
641 break;
642 case PEN_CYAN:
643 pen = new wxPen(*GetColour(COLOUR_CYAN), 1, wxSOLID);
644 break;
645 case PEN_GREEN:
646 pen = new wxPen(*GetColour(COLOUR_GREEN), 1, wxSOLID);
647 break;
648 case PEN_GREY:
649 pen = new wxPen(wxColour(wxT("GREY")), 1, wxSOLID);
650 break;
651 case PEN_LIGHTGREY:
652 pen = new wxPen(*GetColour(COLOUR_LIGHTGREY), 1, wxSOLID);
653 break;
654 case PEN_MEDIUMGREY:
655 pen = new wxPen(wxColour(wxT("MEDIUM GREY")), 1, wxSOLID);
656 break;
657 case PEN_RED:
658 pen = new wxPen(*GetColour(COLOUR_RED), 1, wxSOLID);
659 break;
660 case PEN_TRANSPARENT:
661 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxTRANSPARENT);
662 break;
663 case PEN_WHITE:
664 pen = new wxPen(*GetColour(COLOUR_WHITE), 1, wxSOLID);
665 break;
666 default:
667 wxFAIL;
668 }
669 ms_stockObject[item] = pen;
670 }
671 return pen;
672}
673
674void wxInitializeStockLists()
675{
676 wxTheColourDatabase = new wxColourDatabase;
677
678 wxTheBrushList = new wxBrushList;
679 wxThePenList = new wxPenList;
680 wxTheFontList = new wxFontList;
681}
682
683void wxDeleteStockLists()
684{
685 wxDELETE(wxTheBrushList);
686 wxDELETE(wxThePenList);
687 wxDELETE(wxTheFontList);
688}
689
690// ============================================================================
691// wxTheXXXList stuff (semi-obsolete)
692// ============================================================================
693
694wxGDIObjListBase::wxGDIObjListBase()
695{
696}
697
698wxGDIObjListBase::~wxGDIObjListBase()
699{
700 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
701 {
702 delete wx_static_cast(wxObject*, node->GetData());
703 }
704}
705
706wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
707{
708 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
709 {
710 wxPen *each_pen = (wxPen *) node->GetData ();
711 if (
712 each_pen->GetWidth () == width &&
713 each_pen->GetStyle () == style &&
714 each_pen->GetColour ().Red () == colour.Red () &&
715 each_pen->GetColour ().Green () == colour.Green () &&
716 each_pen->GetColour ().Blue () == colour.Blue ())
717 return each_pen;
718 }
719
720 wxPen* pen = NULL;
721 wxPen penTmp(colour, width, style);
722 if (penTmp.Ok())
723 {
724 pen = new wxPen(penTmp);
725 list.Append(pen);
726 }
727
728 return pen;
729}
730
731wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
732{
733 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
734 {
735 wxBrush *each_brush = (wxBrush *) node->GetData ();
736 if (
737 each_brush->GetStyle () == style &&
738 each_brush->GetColour ().Red () == colour.Red () &&
739 each_brush->GetColour ().Green () == colour.Green () &&
740 each_brush->GetColour ().Blue () == colour.Blue ())
741 return each_brush;
742 }
743
744 wxBrush* brush = NULL;
745 wxBrush brushTmp(colour, style);
746 if (brushTmp.Ok())
747 {
748 brush = new wxBrush(brushTmp);
749 list.Append(brush);
750 }
751
752 return brush;
753}
754
755wxFont *wxFontList::FindOrCreateFont(int pointSize,
756 int family,
757 int style,
758 int weight,
759 bool underline,
760 const wxString& facename,
761 wxFontEncoding encoding)
762{
763 wxFont *font;
764 wxList::compatibility_iterator node;
765 for (node = list.GetFirst(); node; node = node->GetNext())
766 {
767 font = (wxFont *)node->GetData();
768 if (
769 font->GetPointSize () == pointSize &&
770 font->GetStyle () == style &&
771 font->GetWeight () == weight &&
772 font->GetUnderlined () == underline )
773 {
774 int fontFamily = font->GetFamily();
775
776#if defined(__WXGTK__)
777 // under GTK the default family is wxSWISS, so looking for a font
778 // with wxDEFAULT family should return a wxSWISS one instead of
779 // creating a new one
780 bool same = (fontFamily == family) ||
781 (fontFamily == wxSWISS && family == wxDEFAULT);
782#else // !GTK
783 // VZ: but why elsewhere do we require an exact match? mystery...
784 bool same = fontFamily == family;
785#endif // GTK/!GTK
786
787 // empty facename matches anything at all: this is bad because
788 // depending on which fonts are already created, we might get back
789 // a different font if we create it with empty facename, but it is
790 // still better than never matching anything in the cache at all
791 // in this case
792 if ( same && !facename.empty() )
793 {
794 const wxString& fontFace = font->GetFaceName();
795
796 // empty facename matches everything
797 same = !fontFace || fontFace == facename;
798 }
799
800 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
801 {
802 // have to match the encoding too
803 same = font->GetEncoding() == encoding;
804 }
805
806 if ( same )
807 {
808 return font;
809 }
810 }
811 }
812
813 // font not found, create the new one
814 font = NULL;
815 wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding);
816 if (fontTmp.Ok())
817 {
818 font = new wxFont(fontTmp);
819 list.Append(font);
820 }
821
822 return font;
823}
824
825#if WXWIN_COMPATIBILITY_2_6
826void wxBrushList::AddBrush(wxBrush*) { }
827void wxBrushList::RemoveBrush(wxBrush*) { }
828void wxFontList::AddFont(wxFont*) { }
829void wxFontList::RemoveFont(wxFont*) { }
830void wxPenList::AddPen(wxPen*) { }
831void wxPenList::RemovePen(wxPen*) { }
832#endif
833
834wxSize wxGetDisplaySize()
835{
836 int x, y;
837 wxDisplaySize(& x, & y);
838 return wxSize(x, y);
839}
840
841wxRect wxGetClientDisplayRect()
842{
843 int x, y, width, height;
844 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
845 return wxRect(x, y, width, height);
846}
847
848wxSize wxGetDisplaySizeMM()
849{
850 int x, y;
851 wxDisplaySizeMM(& x, & y);
852 return wxSize(x, y);
853}
854
855wxResourceCache::~wxResourceCache ()
856{
857 wxList::compatibility_iterator node = GetFirst ();
858 while (node) {
859 wxObject *item = (wxObject *)node->GetData();
860 delete item;
861
862 node = node->GetNext ();
863 }
864}