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