]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
Split wxLocale into wxLocale and wxTranslations.
[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"
5819f832 20#include "wx/gdiobj.h"
e4db172a
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/log.h"
f5590243 24 #include "wx/pen.h"
c64755ed 25 #include "wx/brush.h"
559a723c 26 #include "wx/palette.h"
923d28da 27 #include "wx/icon.h"
52734360 28 #include "wx/iconbndl.h"
c8326d64 29 #include "wx/cursor.h"
9eddec69 30 #include "wx/settings.h"
0bca0373 31 #include "wx/bitmap.h"
7cf41a5d 32 #include "wx/colour.h"
48a1108e 33 #include "wx/font.h"
d43be80d 34 #include "wx/math.h"
e4db172a
WS
35#endif
36
5819f832 37
8f884a0d 38IMPLEMENT_ABSTRACT_CLASS(wxGDIObject, wxObject)
5819f832
VS
39
40
e7445ff8
PC
41WXDLLIMPEXP_DATA_CORE(wxBrushList*) wxTheBrushList;
42WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList;
43WXDLLIMPEXP_DATA_CORE(wxPenList*) wxThePenList;
44
45WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase;
46
47WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap;
48WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush;
49WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour;
50WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor;
51WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont;
52WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon;
53WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen;
54#if wxUSE_PALETTE
55WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette;
46ccb510 56#endif
52734360 57WXDLLIMPEXP_DATA_CORE(wxIconBundle) wxNullIconBundle;
46ccb510 58
e7445ff8
PC
59const wxSize wxDefaultSize(wxDefaultCoord, wxDefaultCoord);
60const wxPoint wxDefaultPosition(wxDefaultCoord, wxDefaultCoord);
7266b672 61
b0d7707b 62#include "wx/listimpl.cpp"
a76c2f37 63WX_DEFINE_LIST(wxPointList)
b0d7707b
RR
64
65
cb73e600
SC
66#if wxUSE_EXTENDED_RTTI
67
68// wxPoint
69
70template<> void wxStringReadValue(const wxString &s , wxPoint &data )
71{
5d3e7b52 72 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
73}
74
75template<> void wxStringWriteValue(wxString &s , const wxPoint &data )
76{
5d3e7b52 77 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
78}
79
8805dbab 80wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>)
cb73e600
SC
81
82template<> void wxStringReadValue(const wxString &s , wxSize &data )
83{
5d3e7b52 84 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
85}
86
87template<> void wxStringWriteValue(wxString &s , const wxSize &data )
88{
5d3e7b52 89 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
90}
91
8805dbab 92wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>)
cb73e600
SC
93
94#endif
95
d7a7546b 96wxRect::wxRect(const wxPoint& point1, const wxPoint& point2)
c801d85f 97{
5d3e7b52
WS
98 x = point1.x;
99 y = point1.y;
100 width = point2.x - point1.x;
101 height = point2.y - point1.y;
8bbe427f 102
5d3e7b52
WS
103 if (width < 0)
104 {
105 width = -width;
106 x = point2.x;
107 }
108 width++;
8bbe427f 109
5d3e7b52
WS
110 if (height < 0)
111 {
112 height = -height;
113 y = point2.y;
114 }
115 height++;
c801d85f
KB
116}
117
df83b840
VZ
118wxRect& wxRect::Union(const wxRect& rect)
119{
c71ce675
VZ
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 )
df83b840
VZ
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 }
c71ce675 138 //else: we're not empty and rect is empty
df83b840
VZ
139
140 return *this;
141}
142
1e6feb95
VZ
143wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
144{
8673a125
VZ
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 }
1e6feb95
VZ
172
173 return *this;
174}
175
22a35096 176bool wxRect::Contains(int cx, int cy) const
dcb44466 177{
45816ddd
VZ
178 return ( (cx >= x) && (cy >= y)
179 && ((cy - y) < height)
180 && ((cx - x) < width)
181 );
dcb44466
JS
182}
183
22a35096 184bool wxRect::Contains(const wxRect& rect) const
869b59fc 185{
22a35096 186 return Contains(rect.GetTopLeft()) && Contains(rect.GetBottomRight());
869b59fc
VS
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
bc5e942b
VZ
223wxRect& wxRect::operator+=(const wxRect& rect)
224{
225 *this = *this + rect;
226 return *this;
227}
228
229
230wxRect& wxRect::operator*=(const wxRect& rect)
231{
232 *this = *this * rect;
233 return *this;
234}
235
236
237wxRect 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
246wxRect 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
c50f92d0
VZ
255// ============================================================================
256// wxColourDatabase
257// ============================================================================
258
c50f92d0
VZ
259// ----------------------------------------------------------------------------
260// wxColourDatabase ctor/dtor
261// ----------------------------------------------------------------------------
222ed1d6
MB
262
263wxColourDatabase::wxColourDatabase ()
c801d85f 264{
c50f92d0
VZ
265 // will be created on demand in Initialize()
266 m_map = NULL;
c801d85f
KB
267}
268
6a6c0a8b 269wxColourDatabase::~wxColourDatabase ()
c801d85f 270{
c50f92d0
VZ
271 if ( m_map )
272 {
273 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
274
275 delete m_map;
276 }
222ed1d6 277
19bf0c69
DW
278#ifdef __WXPM__
279 delete [] m_palTable;
280#endif
c801d85f
KB
281}
282
283// Colour database stuff
c50f92d0 284void wxColourDatabase::Initialize()
c801d85f 285{
c50f92d0
VZ
286 if ( m_map )
287 {
288 // already initialized
289 return;
290 }
291
292 m_map = new wxStringToColourHashMap;
293
f6bcfd97
BP
294 static const struct wxColourDesc
295 {
296 const wxChar *name;
5c519b6c 297 unsigned char r,g,b;
f6bcfd97
BP
298 }
299 wxColourTable[] =
300 {
5e2ab1ea 301 {wxT("AQUAMARINE"),112, 219, 147},
f6bcfd97
BP
302 {wxT("BLACK"),0, 0, 0},
303 {wxT("BLUE"), 0, 0, 255},
5e2ab1ea 304 {wxT("BLUE VIOLET"), 159, 95, 159},
f6bcfd97 305 {wxT("BROWN"), 165, 42, 42},
5e2ab1ea
VZ
306 {wxT("CADET BLUE"), 95, 159, 159},
307 {wxT("CORAL"), 255, 127, 0},
308 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
f6bcfd97 309 {wxT("CYAN"), 0, 255, 255},
5e2ab1ea
VZ
310 {wxT("DARK GREY"), 47, 47, 47}, // ?
311
312 {wxT("DARK GREEN"), 47, 79, 47},
313 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
f6bcfd97 314 {wxT("DARK ORCHID"), 153, 50, 204},
5e2ab1ea 315 {wxT("DARK SLATE BLUE"), 107, 35, 142},
f6bcfd97 316 {wxT("DARK SLATE GREY"), 47, 79, 79},
5e2ab1ea
VZ
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},
f6bcfd97 324 {wxT("GREEN"), 0, 255, 0},
5e2ab1ea
VZ
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},
f6bcfd97 333 {wxT("MAGENTA"), 255, 0, 255},
5e2ab1ea
VZ
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},
59571b71 352 {wxT("PINK"), 255, 192, 203},
5e2ab1ea
VZ
353 {wxT("PLUM"), 234, 173, 234},
354 {wxT("PURPLE"), 176, 0, 255},
f6bcfd97 355 {wxT("RED"), 255, 0, 0},
5e2ab1ea
VZ
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},
f6bcfd97 361 {wxT("SPRING GREEN"), 0, 255, 127},
5e2ab1ea
VZ
362 {wxT("STEEL BLUE"), 35, 107, 142},
363 {wxT("TAN"), 219, 147, 112},
f6bcfd97 364 {wxT("THISTLE"), 216, 191, 216},
5e2ab1ea
VZ
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},
f6bcfd97
BP
369 {wxT("WHITE"), 255, 255, 255},
370 {wxT("YELLOW"), 255, 255, 0},
aad6765c 371 {wxT("YELLOW GREEN"), 153, 204, 50}
f6bcfd97
BP
372 };
373
c50f92d0 374 size_t n;
bf2c4b94
DW
375
376 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
f6bcfd97
BP
377 {
378 const wxColourDesc& cc = wxColourTable[n];
c50f92d0 379 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
f6bcfd97 380 }
c50f92d0 381
19bf0c69
DW
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
c801d85f
KB
391}
392
c50f92d0
VZ
393// ----------------------------------------------------------------------------
394// wxColourDatabase operations
395// ----------------------------------------------------------------------------
222ed1d6 396
c50f92d0 397void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
222ed1d6 398{
c50f92d0 399 Initialize();
222ed1d6 400
c50f92d0
VZ
401 // canonicalize the colour names before using them as keys: they should be
402 // in upper case
8f520a56
MB
403 wxString colName = name;
404 colName.MakeUpper();
c50f92d0
VZ
405
406 // ... and we also allow both grey/gray
407 wxString colNameAlt = colName;
9a83f860 408 if ( !colNameAlt.Replace(wxT("GRAY"), wxT("GREY")) )
c50f92d0
VZ
409 {
410 // but in this case it is not necessary so avoid extra search below
411 colNameAlt.clear();
412 }
8f520a56
MB
413
414 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
415 if ( it == m_map->end() && !colNameAlt.empty() )
416 it = m_map->find(colNameAlt);
8f520a56
MB
417 if ( it != m_map->end() )
418 {
c50f92d0
VZ
419 *(it->second) = colour;
420 }
421 else // new colour
422 {
5767e836 423 (*m_map)[colName] = new wxColour(colour);
8f520a56 424 }
8f520a56
MB
425}
426
c50f92d0 427wxColour wxColourDatabase::Find(const wxString& colour) const
c801d85f 428{
c50f92d0
VZ
429 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
430 self->Initialize();
431
c50f92d0 432 // make the comparaison case insensitive and also match both grey and gray
f6bcfd97
BP
433 wxString colName = colour;
434 colName.MakeUpper();
c50f92d0 435 wxString colNameAlt = colName;
9a83f860 436 if ( !colNameAlt.Replace(wxT("GRAY"), wxT("GREY")) )
c50f92d0 437 colNameAlt.clear();
f6bcfd97 438
222ed1d6 439 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
440 if ( it == m_map->end() && !colNameAlt.empty() )
441 it = m_map->find(colNameAlt);
222ed1d6 442 if ( it != m_map->end() )
c50f92d0 443 return *(it->second);
34138703 444
40989e46
WS
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 !
c50f92d0 450 return wxNullColour;
c801d85f
KB
451}
452
c50f92d0 453wxString wxColourDatabase::FindName(const wxColour& colour) const
c801d85f 454{
c50f92d0
VZ
455 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
456 self->Initialize();
8bbe427f 457
222ed1d6
MB
458 typedef wxStringToColourHashMap::iterator iterator;
459
c50f92d0 460 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
a23fd0e1 461 {
c50f92d0 462 if ( *(it->second) == colour )
222ed1d6 463 return it->first;
a23fd0e1 464 }
c801d85f 465
222ed1d6 466 return wxEmptyString;
c801d85f
KB
467}
468
c50f92d0
VZ
469// ----------------------------------------------------------------------------
470// deprecated wxColourDatabase methods
471// ----------------------------------------------------------------------------
472
ca3e85cf 473#if WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
474wxColour *wxColourDatabase::FindColour(const wxString& name)
475{
98de2b68
DS
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
492e2a5b
VZ
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
98de2b68 493
492e2a5b
VZ
494 static wxColour s_col;
495
496 s_col = Find(name);
497 if ( !s_col.Ok() )
c50f92d0
VZ
498 return NULL;
499
98de2b68 500 return new wxColour(s_col);
c50f92d0 501}
ca3e85cf 502#endif // WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
503
504// ============================================================================
505// stock objects
506// ============================================================================
507
f516d986
VZ
508static wxStockGDI gs_wxStockGDI_instance;
509wxStockGDI* wxStockGDI::ms_instance = &gs_wxStockGDI_instance;
510wxObject* wxStockGDI::ms_stockObject[ITEMCOUNT];
511
512wxStockGDI::wxStockGDI()
7ecb8b06 513{
f516d986 514}
1c193821 515
f516d986
VZ
516wxStockGDI::~wxStockGDI()
517{
a3622daa 518}
c801d85f 519
f516d986 520void wxStockGDI::DeleteAll()
a3622daa 521{
f516d986
VZ
522 for (unsigned i = 0; i < ITEMCOUNT; i++)
523 {
524 delete ms_stockObject[i];
525 ms_stockObject[i] = NULL;
526 }
527}
c801d85f 528
f516d986
VZ
529const wxBrush* wxStockGDI::GetBrush(Item item)
530{
5c33522f 531 wxBrush* brush = static_cast<wxBrush*>(ms_stockObject[item]);
f516d986
VZ
532 if (brush == NULL)
533 {
534 switch (item)
535 {
536 case BRUSH_BLACK:
04ee05f9 537 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxBRUSHSTYLE_SOLID);
f516d986
VZ
538 break;
539 case BRUSH_BLUE:
04ee05f9 540 brush = new wxBrush(*GetColour(COLOUR_BLUE), wxBRUSHSTYLE_SOLID);
f516d986
VZ
541 break;
542 case BRUSH_CYAN:
04ee05f9 543 brush = new wxBrush(*GetColour(COLOUR_CYAN), wxBRUSHSTYLE_SOLID);
f516d986
VZ
544 break;
545 case BRUSH_GREEN:
04ee05f9 546 brush = new wxBrush(*GetColour(COLOUR_GREEN), wxBRUSHSTYLE_SOLID);
f516d986 547 break;
86028025
FM
548 case BRUSH_YELLOW:
549 brush = new wxBrush(*GetColour(COLOUR_YELLOW), wxBRUSHSTYLE_SOLID);
550 break;
f516d986 551 case BRUSH_GREY:
04ee05f9 552 brush = new wxBrush(wxColour(wxT("GREY")), wxBRUSHSTYLE_SOLID);
f516d986
VZ
553 break;
554 case BRUSH_LIGHTGREY:
04ee05f9 555 brush = new wxBrush(*GetColour(COLOUR_LIGHTGREY), wxBRUSHSTYLE_SOLID);
f516d986
VZ
556 break;
557 case BRUSH_MEDIUMGREY:
04ee05f9 558 brush = new wxBrush(wxColour(wxT("MEDIUM GREY")), wxBRUSHSTYLE_SOLID);
f516d986
VZ
559 break;
560 case BRUSH_RED:
04ee05f9 561 brush = new wxBrush(*GetColour(COLOUR_RED), wxBRUSHSTYLE_SOLID);
f516d986
VZ
562 break;
563 case BRUSH_TRANSPARENT:
04ee05f9 564 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxBRUSHSTYLE_TRANSPARENT);
f516d986
VZ
565 break;
566 case BRUSH_WHITE:
04ee05f9 567 brush = new wxBrush(*GetColour(COLOUR_WHITE), wxBRUSHSTYLE_SOLID);
f516d986
VZ
568 break;
569 default:
570 wxFAIL;
571 }
572 ms_stockObject[item] = brush;
573 }
574 return brush;
575}
696e1ea0 576
f516d986
VZ
577const wxColour* wxStockGDI::GetColour(Item item)
578{
5c33522f 579 wxColour* colour = static_cast<wxColour*>(ms_stockObject[item]);
f516d986
VZ
580 if (colour == NULL)
581 {
582 switch (item)
583 {
584 case COLOUR_BLACK:
585 colour = new wxColour(0, 0, 0);
586 break;
587 case COLOUR_BLUE:
588 colour = new wxColour(0, 0, 255);
589 break;
590 case COLOUR_CYAN:
591 colour = new wxColour(wxT("CYAN"));
592 break;
593 case COLOUR_GREEN:
594 colour = new wxColour(0, 255, 0);
595 break;
86028025
FM
596 case COLOUR_YELLOW:
597 colour = new wxColour(255, 255, 0);
598 break;
f516d986
VZ
599 case COLOUR_LIGHTGREY:
600 colour = new wxColour(wxT("LIGHT GREY"));
601 break;
602 case COLOUR_RED:
603 colour = new wxColour(255, 0, 0);
604 break;
605 case COLOUR_WHITE:
606 colour = new wxColour(255, 255, 255);
607 break;
608 default:
609 wxFAIL;
610 }
611 ms_stockObject[item] = colour;
612 }
613 return colour;
614}
615
616const wxCursor* wxStockGDI::GetCursor(Item item)
617{
5c33522f 618 wxCursor* cursor = static_cast<wxCursor*>(ms_stockObject[item]);
f516d986
VZ
619 if (cursor == NULL)
620 {
621 switch (item)
622 {
623 case CURSOR_CROSS:
624 cursor = new wxCursor(wxCURSOR_CROSS);
625 break;
626 case CURSOR_HOURGLASS:
627 cursor = new wxCursor(wxCURSOR_WAIT);
628 break;
629 case CURSOR_STANDARD:
630 cursor = new wxCursor(wxCURSOR_ARROW);
631 break;
632 default:
633 wxFAIL;
634 }
635 ms_stockObject[item] = cursor;
636 }
637 return cursor;
638}
639
640const wxFont* wxStockGDI::GetFont(Item item)
641{
5c33522f 642 wxFont* font = static_cast<wxFont*>(ms_stockObject[item]);
f516d986
VZ
643 if (font == NULL)
644 {
645 switch (item)
646 {
647 case FONT_ITALIC:
648 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxROMAN, wxITALIC, wxNORMAL);
649 break;
650 case FONT_NORMAL:
651 font = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
652 break;
653 case FONT_SMALL:
654 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize() - 2, wxSWISS, wxNORMAL, wxNORMAL);
655 break;
656 case FONT_SWISS:
657 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxSWISS, wxNORMAL, wxNORMAL);
658 break;
659 default:
660 wxFAIL;
661 }
662 ms_stockObject[item] = font;
663 }
664 return font;
665}
c801d85f 666
f516d986
VZ
667const wxPen* wxStockGDI::GetPen(Item item)
668{
5c33522f 669 wxPen* pen = static_cast<wxPen*>(ms_stockObject[item]);
f516d986
VZ
670 if (pen == NULL)
671 {
672 switch (item)
673 {
674 case PEN_BLACK:
82cddbd9 675 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_SOLID);
f516d986
VZ
676 break;
677 case PEN_BLACKDASHED:
82cddbd9 678 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_SHORT_DASH);
f516d986 679 break;
d8184587
FM
680 case PEN_BLUE:
681 pen = new wxPen(*GetColour(COLOUR_BLUE), 1, wxPENSTYLE_SOLID);
682 break;
f516d986 683 case PEN_CYAN:
82cddbd9 684 pen = new wxPen(*GetColour(COLOUR_CYAN), 1, wxPENSTYLE_SOLID);
f516d986
VZ
685 break;
686 case PEN_GREEN:
82cddbd9 687 pen = new wxPen(*GetColour(COLOUR_GREEN), 1, wxPENSTYLE_SOLID);
f516d986 688 break;
86028025
FM
689 case PEN_YELLOW:
690 pen = new wxPen(*GetColour(COLOUR_YELLOW), 1, wxPENSTYLE_SOLID);
691 break;
f516d986 692 case PEN_GREY:
82cddbd9 693 pen = new wxPen(wxColour(wxT("GREY")), 1, wxPENSTYLE_SOLID);
f516d986
VZ
694 break;
695 case PEN_LIGHTGREY:
82cddbd9 696 pen = new wxPen(*GetColour(COLOUR_LIGHTGREY), 1, wxPENSTYLE_SOLID);
f516d986
VZ
697 break;
698 case PEN_MEDIUMGREY:
82cddbd9 699 pen = new wxPen(wxColour(wxT("MEDIUM GREY")), 1, wxPENSTYLE_SOLID);
f516d986
VZ
700 break;
701 case PEN_RED:
82cddbd9 702 pen = new wxPen(*GetColour(COLOUR_RED), 1, wxPENSTYLE_SOLID);
f516d986
VZ
703 break;
704 case PEN_TRANSPARENT:
82cddbd9 705 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_TRANSPARENT);
f516d986
VZ
706 break;
707 case PEN_WHITE:
82cddbd9 708 pen = new wxPen(*GetColour(COLOUR_WHITE), 1, wxPENSTYLE_SOLID);
f516d986
VZ
709 break;
710 default:
711 wxFAIL;
712 }
713 ms_stockObject[item] = pen;
714 }
715 return pen;
c801d85f
KB
716}
717
f516d986 718void wxInitializeStockLists()
c801d85f 719{
f516d986
VZ
720 wxTheColourDatabase = new wxColourDatabase;
721
722 wxTheBrushList = new wxBrushList;
723 wxThePenList = new wxPenList;
724 wxTheFontList = new wxFontList;
a3622daa
VZ
725}
726
7ecb8b06
VZ
727void wxDeleteStockLists()
728{
5d3e7b52
WS
729 wxDELETE(wxTheBrushList);
730 wxDELETE(wxThePenList);
731 wxDELETE(wxTheFontList);
41d0b41d
FM
732
733 // wxTheColourDatabase is cleaned up by wxAppBase::CleanUp()
c801d85f
KB
734}
735
7ecb8b06
VZ
736// ============================================================================
737// wxTheXXXList stuff (semi-obsolete)
738// ============================================================================
739
1de8d512 740wxGDIObjListBase::wxGDIObjListBase()
c801d85f 741{
c801d85f
KB
742}
743
1de8d512 744wxGDIObjListBase::~wxGDIObjListBase()
c801d85f 745{
1de8d512 746 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
c801d85f 747 {
5c33522f 748 delete static_cast<wxObject*>(node->GetData());
c801d85f
KB
749 }
750}
751
82cddbd9 752wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, wxPenStyle style)
c801d85f 753{
b685c0a6
VZ
754 for ( wxList::compatibility_iterator node = list.GetFirst();
755 node;
756 node = node->GetNext() )
13b6e335 757 {
b685c0a6
VZ
758 wxPen * const pen = (wxPen *) node->GetData();
759 if ( pen->GetWidth () == width &&
760 pen->GetStyle () == style &&
761 pen->GetColour() == colour )
762 return pen;
13b6e335
VZ
763 }
764
1de8d512
VZ
765 wxPen* pen = NULL;
766 wxPen penTmp(colour, width, style);
767 if (penTmp.Ok())
c801d85f 768 {
1de8d512
VZ
769 pen = new wxPen(penTmp);
770 list.Append(pen);
c801d85f 771 }
c801d85f 772
13b6e335 773 return pen;
c801d85f
KB
774}
775
3e6858cd 776wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, wxBrushStyle style)
c801d85f 777{
b685c0a6
VZ
778 for ( wxList::compatibility_iterator node = list.GetFirst();
779 node;
780 node = node->GetNext() )
c801d85f 781 {
b685c0a6 782 wxBrush * const brush = (wxBrush *) node->GetData ();
3e6858cd 783 if ( brush->GetStyle() == style && brush->GetColour() == colour )
b685c0a6 784 return brush;
c801d85f 785 }
6d167489 786
1de8d512
VZ
787 wxBrush* brush = NULL;
788 wxBrush brushTmp(colour, style);
789 if (brushTmp.Ok())
13b6e335 790 {
1de8d512
VZ
791 brush = new wxBrush(brushTmp);
792 list.Append(brush);
13b6e335 793 }
6d167489 794
13b6e335 795 return brush;
c801d85f
KB
796}
797
f6bcfd97 798wxFont *wxFontList::FindOrCreateFont(int pointSize,
82cddbd9
FM
799 wxFontFamily family,
800 wxFontStyle style,
801 wxFontWeight weight,
f6bcfd97
BP
802 bool underline,
803 const wxString& facename,
804 wxFontEncoding encoding)
c801d85f 805{
1de8d512 806 wxFont *font;
222ed1d6 807 wxList::compatibility_iterator node;
1de8d512 808 for (node = list.GetFirst(); node; node = node->GetNext())
c801d85f 809 {
b1d4dd7a 810 font = (wxFont *)node->GetData();
1de8d512 811 if (
f6bcfd97
BP
812 font->GetPointSize () == pointSize &&
813 font->GetStyle () == style &&
814 font->GetWeight () == weight &&
815 font->GetUnderlined () == underline )
816 {
777819af 817 wxFontFamily fontFamily = (wxFontFamily)font->GetFamily();
f6bcfd97 818
619d0528 819#if defined(__WXGTK__)
f6bcfd97
BP
820 // under GTK the default family is wxSWISS, so looking for a font
821 // with wxDEFAULT family should return a wxSWISS one instead of
822 // creating a new one
823 bool same = (fontFamily == family) ||
04ee05f9 824 (fontFamily == wxFONTFAMILY_SWISS && family == wxFONTFAMILY_DEFAULT);
f6bcfd97
BP
825#else // !GTK
826 // VZ: but why elsewhere do we require an exact match? mystery...
827 bool same = fontFamily == family;
828#endif // GTK/!GTK
829
830 // empty facename matches anything at all: this is bad because
831 // depending on which fonts are already created, we might get back
832 // a different font if we create it with empty facename, but it is
833 // still better than never matching anything in the cache at all
834 // in this case
8d8fbb9d 835 if ( same && !facename.empty() )
f6bcfd97
BP
836 {
837 const wxString& fontFace = font->GetFaceName();
838
839 // empty facename matches everything
840 same = !fontFace || fontFace == facename;
841 }
842
843 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
844 {
845 // have to match the encoding too
846 same = font->GetEncoding() == encoding;
847 }
848
849 if ( same )
850 {
851 return font;
852 }
853 }
c801d85f 854 }
6d167489 855
1de8d512
VZ
856 // font not found, create the new one
857 font = NULL;
858 wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding);
859 if (fontTmp.Ok())
f6bcfd97 860 {
1de8d512
VZ
861 font = new wxFont(fontTmp);
862 list.Append(font);
f6bcfd97 863 }
6d167489 864
f6bcfd97 865 return font;
c801d85f
KB
866}
867
1de8d512
VZ
868#if WXWIN_COMPATIBILITY_2_6
869void wxBrushList::AddBrush(wxBrush*) { }
870void wxBrushList::RemoveBrush(wxBrush*) { }
871void wxFontList::AddFont(wxFont*) { }
872void wxFontList::RemoveFont(wxFont*) { }
873void wxPenList::AddPen(wxPen*) { }
874void wxPenList::RemovePen(wxPen*) { }
875#endif
c801d85f 876
6a6c0a8b
JS
877wxSize wxGetDisplaySize()
878{
879 int x, y;
880 wxDisplaySize(& x, & y);
881 return wxSize(x, y);
882}
883
ec5d7799
RD
884wxRect wxGetClientDisplayRect()
885{
886 int x, y, width, height;
887 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
888 return wxRect(x, y, width, height);
889}
890
904a68b6
RL
891wxSize wxGetDisplaySizeMM()
892{
893 int x, y;
894 wxDisplaySizeMM(& x, & y);
895 return wxSize(x, y);
896}
897
40fcf546
VS
898wxSize wxGetDisplayPPI()
899{
900 const wxSize pixels = wxGetDisplaySize();
901 const wxSize mm = wxGetDisplaySizeMM();
902
d43be80d
VZ
903 return wxSize((int)((pixels.x * inches2mm) / mm.x),
904 (int)((pixels.y * inches2mm) / mm.y));
40fcf546
VS
905}
906
8bbe427f
VZ
907wxResourceCache::~wxResourceCache ()
908{
222ed1d6 909 wxList::compatibility_iterator node = GetFirst ();
f6bcfd97 910 while (node) {
b1d4dd7a 911 wxObject *item = (wxObject *)node->GetData();
f6bcfd97 912 delete item;
a3622daa 913
b1d4dd7a 914 node = node->GetNext ();
a3622daa 915 }
a3622daa 916}