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