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