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