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