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