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