]> git.saurik.com Git - wxWidgets.git/blob - src/common/gdicmn.cpp
add wxMouseEvent::GetClickCount() and implement it for wxMac
[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_DYNAMIC_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), wxSOLID);
537 break;
538 case BRUSH_BLUE:
539 brush = new wxBrush(*GetColour(COLOUR_BLUE), wxSOLID);
540 break;
541 case BRUSH_CYAN:
542 brush = new wxBrush(*GetColour(COLOUR_CYAN), wxSOLID);
543 break;
544 case BRUSH_GREEN:
545 brush = new wxBrush(*GetColour(COLOUR_GREEN), wxSOLID);
546 break;
547 case BRUSH_GREY:
548 brush = new wxBrush(wxColour(wxT("GREY")), wxSOLID);
549 break;
550 case BRUSH_LIGHTGREY:
551 brush = new wxBrush(*GetColour(COLOUR_LIGHTGREY), wxSOLID);
552 break;
553 case BRUSH_MEDIUMGREY:
554 brush = new wxBrush(wxColour(wxT("MEDIUM GREY")), wxSOLID);
555 break;
556 case BRUSH_RED:
557 brush = new wxBrush(*GetColour(COLOUR_RED), wxSOLID);
558 break;
559 case BRUSH_TRANSPARENT:
560 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxTRANSPARENT);
561 break;
562 case BRUSH_WHITE:
563 brush = new wxBrush(*GetColour(COLOUR_WHITE), wxSOLID);
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, wxSOLID);
669 break;
670 case PEN_BLACKDASHED:
671 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxSHORT_DASH);
672 break;
673 case PEN_CYAN:
674 pen = new wxPen(*GetColour(COLOUR_CYAN), 1, wxSOLID);
675 break;
676 case PEN_GREEN:
677 pen = new wxPen(*GetColour(COLOUR_GREEN), 1, wxSOLID);
678 break;
679 case PEN_GREY:
680 pen = new wxPen(wxColour(wxT("GREY")), 1, wxSOLID);
681 break;
682 case PEN_LIGHTGREY:
683 pen = new wxPen(*GetColour(COLOUR_LIGHTGREY), 1, wxSOLID);
684 break;
685 case PEN_MEDIUMGREY:
686 pen = new wxPen(wxColour(wxT("MEDIUM GREY")), 1, wxSOLID);
687 break;
688 case PEN_RED:
689 pen = new wxPen(*GetColour(COLOUR_RED), 1, wxSOLID);
690 break;
691 case PEN_TRANSPARENT:
692 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxTRANSPARENT);
693 break;
694 case PEN_WHITE:
695 pen = new wxPen(*GetColour(COLOUR_WHITE), 1, wxSOLID);
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, int style)
738 {
739 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
740 {
741 wxPen *each_pen = (wxPen *) node->GetData ();
742 if (
743 each_pen->GetWidth () == width &&
744 each_pen->GetStyle () == style &&
745 each_pen->GetColour ().Red () == colour.Red () &&
746 each_pen->GetColour ().Green () == colour.Green () &&
747 each_pen->GetColour ().Blue () == colour.Blue ())
748 return each_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, int style)
763 {
764 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
765 {
766 wxBrush *each_brush = (wxBrush *) node->GetData ();
767 if (
768 each_brush->GetStyle () == style &&
769 each_brush->GetColour ().Red () == colour.Red () &&
770 each_brush->GetColour ().Green () == colour.Green () &&
771 each_brush->GetColour ().Blue () == colour.Blue ())
772 return each_brush;
773 }
774
775 wxBrush* brush = NULL;
776 wxBrush brushTmp(colour, style);
777 if (brushTmp.Ok())
778 {
779 brush = new wxBrush(brushTmp);
780 list.Append(brush);
781 }
782
783 return brush;
784 }
785
786 wxFont *wxFontList::FindOrCreateFont(int pointSize,
787 int family,
788 int style,
789 int weight,
790 bool underline,
791 const wxString& facename,
792 wxFontEncoding encoding)
793 {
794 wxFont *font;
795 wxList::compatibility_iterator node;
796 for (node = list.GetFirst(); node; node = node->GetNext())
797 {
798 font = (wxFont *)node->GetData();
799 if (
800 font->GetPointSize () == pointSize &&
801 font->GetStyle () == style &&
802 font->GetWeight () == weight &&
803 font->GetUnderlined () == underline )
804 {
805 int fontFamily = font->GetFamily();
806
807 #if defined(__WXGTK__)
808 // under GTK the default family is wxSWISS, so looking for a font
809 // with wxDEFAULT family should return a wxSWISS one instead of
810 // creating a new one
811 bool same = (fontFamily == family) ||
812 (fontFamily == wxSWISS && family == wxDEFAULT);
813 #else // !GTK
814 // VZ: but why elsewhere do we require an exact match? mystery...
815 bool same = fontFamily == family;
816 #endif // GTK/!GTK
817
818 // empty facename matches anything at all: this is bad because
819 // depending on which fonts are already created, we might get back
820 // a different font if we create it with empty facename, but it is
821 // still better than never matching anything in the cache at all
822 // in this case
823 if ( same && !facename.empty() )
824 {
825 const wxString& fontFace = font->GetFaceName();
826
827 // empty facename matches everything
828 same = !fontFace || fontFace == facename;
829 }
830
831 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
832 {
833 // have to match the encoding too
834 same = font->GetEncoding() == encoding;
835 }
836
837 if ( same )
838 {
839 return font;
840 }
841 }
842 }
843
844 // font not found, create the new one
845 font = NULL;
846 wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding);
847 if (fontTmp.Ok())
848 {
849 font = new wxFont(fontTmp);
850 list.Append(font);
851 }
852
853 return font;
854 }
855
856 #if WXWIN_COMPATIBILITY_2_6
857 void wxBrushList::AddBrush(wxBrush*) { }
858 void wxBrushList::RemoveBrush(wxBrush*) { }
859 void wxFontList::AddFont(wxFont*) { }
860 void wxFontList::RemoveFont(wxFont*) { }
861 void wxPenList::AddPen(wxPen*) { }
862 void wxPenList::RemovePen(wxPen*) { }
863 #endif
864
865 wxSize wxGetDisplaySize()
866 {
867 int x, y;
868 wxDisplaySize(& x, & y);
869 return wxSize(x, y);
870 }
871
872 wxRect wxGetClientDisplayRect()
873 {
874 int x, y, width, height;
875 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
876 return wxRect(x, y, width, height);
877 }
878
879 wxSize wxGetDisplaySizeMM()
880 {
881 int x, y;
882 wxDisplaySizeMM(& x, & y);
883 return wxSize(x, y);
884 }
885
886 wxResourceCache::~wxResourceCache ()
887 {
888 wxList::compatibility_iterator node = GetFirst ();
889 while (node) {
890 wxObject *item = (wxObject *)node->GetData();
891 delete item;
892
893 node = node->GetNext ();
894 }
895 }