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