]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
add wxUSE_DATAVIEWCTRL check to fix a hundred compilation errors
[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
b0d7707b 61#include "wx/listimpl.cpp"
a76c2f37 62WX_DEFINE_LIST(wxPointList)
b0d7707b
RR
63
64
cb73e600
SC
65#if wxUSE_EXTENDED_RTTI
66
67// wxPoint
68
69template<> void wxStringReadValue(const wxString &s , wxPoint &data )
70{
5d3e7b52 71 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
72}
73
74template<> void wxStringWriteValue(wxString &s , const wxPoint &data )
75{
5d3e7b52 76 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
77}
78
8805dbab 79wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>)
cb73e600
SC
80
81template<> void wxStringReadValue(const wxString &s , wxSize &data )
82{
5d3e7b52 83 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
84}
85
86template<> void wxStringWriteValue(wxString &s , const wxSize &data )
87{
5d3e7b52 88 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
89}
90
8805dbab 91wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>)
cb73e600
SC
92
93#endif
94
d7a7546b 95wxRect::wxRect(const wxPoint& point1, const wxPoint& point2)
c801d85f 96{
5d3e7b52
WS
97 x = point1.x;
98 y = point1.y;
99 width = point2.x - point1.x;
100 height = point2.y - point1.y;
8bbe427f 101
5d3e7b52
WS
102 if (width < 0)
103 {
104 width = -width;
105 x = point2.x;
106 }
107 width++;
8bbe427f 108
5d3e7b52
WS
109 if (height < 0)
110 {
111 height = -height;
112 y = point2.y;
113 }
114 height++;
c801d85f
KB
115}
116
df83b840
VZ
117wxRect& wxRect::Union(const wxRect& rect)
118{
c71ce675
VZ
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 )
df83b840
VZ
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 }
c71ce675 137 //else: we're not empty and rect is empty
df83b840
VZ
138
139 return *this;
140}
141
1e6feb95
VZ
142wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
143{
8673a125
VZ
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 }
1e6feb95
VZ
171
172 return *this;
173}
174
22a35096 175bool wxRect::Contains(int cx, int cy) const
dcb44466 176{
45816ddd
VZ
177 return ( (cx >= x) && (cy >= y)
178 && ((cy - y) < height)
179 && ((cx - x) < width)
180 );
dcb44466
JS
181}
182
22a35096 183bool wxRect::Contains(const wxRect& rect) const
869b59fc 184{
22a35096 185 return Contains(rect.GetTopLeft()) && Contains(rect.GetBottomRight());
869b59fc
VS
186}
187
1e6feb95
VZ
188wxRect& 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
214bool 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
bc5e942b
VZ
222wxRect& wxRect::operator+=(const wxRect& rect)
223{
224 *this = *this + rect;
225 return *this;
226}
227
228
229wxRect& wxRect::operator*=(const wxRect& rect)
230{
231 *this = *this * rect;
232 return *this;
233}
234
235
236wxRect 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
245wxRect 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
c50f92d0
VZ
254// ============================================================================
255// wxColourDatabase
256// ============================================================================
257
c50f92d0
VZ
258// ----------------------------------------------------------------------------
259// wxColourDatabase ctor/dtor
260// ----------------------------------------------------------------------------
222ed1d6
MB
261
262wxColourDatabase::wxColourDatabase ()
c801d85f 263{
c50f92d0
VZ
264 // will be created on demand in Initialize()
265 m_map = NULL;
c801d85f
KB
266}
267
6a6c0a8b 268wxColourDatabase::~wxColourDatabase ()
c801d85f 269{
c50f92d0
VZ
270 if ( m_map )
271 {
272 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
273
274 delete m_map;
275 }
222ed1d6 276
19bf0c69
DW
277#ifdef __WXPM__
278 delete [] m_palTable;
279#endif
c801d85f
KB
280}
281
282// Colour database stuff
c50f92d0 283void wxColourDatabase::Initialize()
c801d85f 284{
c50f92d0
VZ
285 if ( m_map )
286 {
287 // already initialized
288 return;
289 }
290
291 m_map = new wxStringToColourHashMap;
292
f6bcfd97
BP
293 static const struct wxColourDesc
294 {
295 const wxChar *name;
5c519b6c 296 unsigned char r,g,b;
f6bcfd97
BP
297 }
298 wxColourTable[] =
299 {
5e2ab1ea 300 {wxT("AQUAMARINE"),112, 219, 147},
f6bcfd97
BP
301 {wxT("BLACK"),0, 0, 0},
302 {wxT("BLUE"), 0, 0, 255},
5e2ab1ea 303 {wxT("BLUE VIOLET"), 159, 95, 159},
f6bcfd97 304 {wxT("BROWN"), 165, 42, 42},
5e2ab1ea
VZ
305 {wxT("CADET BLUE"), 95, 159, 159},
306 {wxT("CORAL"), 255, 127, 0},
307 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
f6bcfd97 308 {wxT("CYAN"), 0, 255, 255},
5e2ab1ea
VZ
309 {wxT("DARK GREY"), 47, 47, 47}, // ?
310
311 {wxT("DARK GREEN"), 47, 79, 47},
312 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
f6bcfd97 313 {wxT("DARK ORCHID"), 153, 50, 204},
5e2ab1ea 314 {wxT("DARK SLATE BLUE"), 107, 35, 142},
f6bcfd97 315 {wxT("DARK SLATE GREY"), 47, 79, 79},
5e2ab1ea
VZ
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},
f6bcfd97 323 {wxT("GREEN"), 0, 255, 0},
5e2ab1ea
VZ
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},
f6bcfd97 332 {wxT("MAGENTA"), 255, 0, 255},
5e2ab1ea
VZ
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},
59571b71 351 {wxT("PINK"), 255, 192, 203},
5e2ab1ea
VZ
352 {wxT("PLUM"), 234, 173, 234},
353 {wxT("PURPLE"), 176, 0, 255},
f6bcfd97 354 {wxT("RED"), 255, 0, 0},
5e2ab1ea
VZ
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},
f6bcfd97 360 {wxT("SPRING GREEN"), 0, 255, 127},
5e2ab1ea
VZ
361 {wxT("STEEL BLUE"), 35, 107, 142},
362 {wxT("TAN"), 219, 147, 112},
f6bcfd97 363 {wxT("THISTLE"), 216, 191, 216},
5e2ab1ea
VZ
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},
f6bcfd97
BP
368 {wxT("WHITE"), 255, 255, 255},
369 {wxT("YELLOW"), 255, 255, 0},
aad6765c 370 {wxT("YELLOW GREEN"), 153, 204, 50}
f6bcfd97
BP
371 };
372
c50f92d0 373 size_t n;
bf2c4b94
DW
374
375 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
f6bcfd97
BP
376 {
377 const wxColourDesc& cc = wxColourTable[n];
c50f92d0 378 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
f6bcfd97 379 }
c50f92d0 380
19bf0c69
DW
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
c801d85f
KB
390}
391
c50f92d0
VZ
392// ----------------------------------------------------------------------------
393// wxColourDatabase operations
394// ----------------------------------------------------------------------------
222ed1d6 395
c50f92d0 396void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
222ed1d6 397{
c50f92d0 398 Initialize();
222ed1d6 399
c50f92d0
VZ
400 // canonicalize the colour names before using them as keys: they should be
401 // in upper case
8f520a56
MB
402 wxString colName = name;
403 colName.MakeUpper();
c50f92d0
VZ
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 }
8f520a56
MB
412
413 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
414 if ( it == m_map->end() && !colNameAlt.empty() )
415 it = m_map->find(colNameAlt);
8f520a56
MB
416 if ( it != m_map->end() )
417 {
c50f92d0
VZ
418 *(it->second) = colour;
419 }
420 else // new colour
421 {
5767e836 422 (*m_map)[colName] = new wxColour(colour);
8f520a56 423 }
8f520a56
MB
424}
425
c50f92d0 426wxColour wxColourDatabase::Find(const wxString& colour) const
c801d85f 427{
c50f92d0
VZ
428 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
429 self->Initialize();
430
c50f92d0 431 // make the comparaison case insensitive and also match both grey and gray
f6bcfd97
BP
432 wxString colName = colour;
433 colName.MakeUpper();
c50f92d0
VZ
434 wxString colNameAlt = colName;
435 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
436 colNameAlt.clear();
f6bcfd97 437
222ed1d6 438 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
439 if ( it == m_map->end() && !colNameAlt.empty() )
440 it = m_map->find(colNameAlt);
222ed1d6 441 if ( it != m_map->end() )
c50f92d0 442 return *(it->second);
34138703 443
40989e46
WS
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 !
c50f92d0 449 return wxNullColour;
c801d85f
KB
450}
451
c50f92d0 452wxString wxColourDatabase::FindName(const wxColour& colour) const
c801d85f 453{
c50f92d0
VZ
454 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
455 self->Initialize();
8bbe427f 456
222ed1d6
MB
457 typedef wxStringToColourHashMap::iterator iterator;
458
c50f92d0 459 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
a23fd0e1 460 {
c50f92d0 461 if ( *(it->second) == colour )
222ed1d6 462 return it->first;
a23fd0e1 463 }
c801d85f 464
222ed1d6 465 return wxEmptyString;
c801d85f
KB
466}
467
c50f92d0
VZ
468// ----------------------------------------------------------------------------
469// deprecated wxColourDatabase methods
470// ----------------------------------------------------------------------------
471
ca3e85cf 472#if WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
473wxColour *wxColourDatabase::FindColour(const wxString& name)
474{
98de2b68
DS
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
492e2a5b
VZ
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
98de2b68 492
492e2a5b
VZ
493 static wxColour s_col;
494
495 s_col = Find(name);
496 if ( !s_col.Ok() )
c50f92d0
VZ
497 return NULL;
498
98de2b68 499 return new wxColour(s_col);
c50f92d0 500}
ca3e85cf 501#endif // WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
502
503// ============================================================================
504// stock objects
505// ============================================================================
506
f516d986
VZ
507static wxStockGDI gs_wxStockGDI_instance;
508wxStockGDI* wxStockGDI::ms_instance = &gs_wxStockGDI_instance;
509wxObject* wxStockGDI::ms_stockObject[ITEMCOUNT];
510
511wxStockGDI::wxStockGDI()
7ecb8b06 512{
f516d986 513}
1c193821 514
f516d986
VZ
515wxStockGDI::~wxStockGDI()
516{
a3622daa 517}
c801d85f 518
f516d986 519void wxStockGDI::DeleteAll()
a3622daa 520{
f516d986
VZ
521 for (unsigned i = 0; i < ITEMCOUNT; i++)
522 {
523 delete ms_stockObject[i];
524 ms_stockObject[i] = NULL;
525 }
526}
c801d85f 527
f516d986
VZ
528const 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}
696e1ea0 572
f516d986
VZ
573const 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
609const 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
633const 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}
c801d85f 659
f516d986
VZ
660const 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;
c801d85f
KB
703}
704
f516d986 705void wxInitializeStockLists()
c801d85f 706{
f516d986
VZ
707 wxTheColourDatabase = new wxColourDatabase;
708
709 wxTheBrushList = new wxBrushList;
710 wxThePenList = new wxPenList;
711 wxTheFontList = new wxFontList;
a3622daa
VZ
712}
713
7ecb8b06
VZ
714void wxDeleteStockLists()
715{
5d3e7b52
WS
716 wxDELETE(wxTheBrushList);
717 wxDELETE(wxThePenList);
718 wxDELETE(wxTheFontList);
c801d85f
KB
719}
720
7ecb8b06
VZ
721// ============================================================================
722// wxTheXXXList stuff (semi-obsolete)
723// ============================================================================
724
1de8d512 725wxGDIObjListBase::wxGDIObjListBase()
c801d85f 726{
c801d85f
KB
727}
728
1de8d512 729wxGDIObjListBase::~wxGDIObjListBase()
c801d85f 730{
1de8d512 731 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
c801d85f 732 {
1de8d512 733 delete wx_static_cast(wxObject*, node->GetData());
c801d85f
KB
734 }
735}
736
debe6624 737wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
c801d85f 738{
b685c0a6
VZ
739 for ( wxList::compatibility_iterator node = list.GetFirst();
740 node;
741 node = node->GetNext() )
13b6e335 742 {
b685c0a6
VZ
743 wxPen * const pen = (wxPen *) node->GetData();
744 if ( pen->GetWidth () == width &&
745 pen->GetStyle () == style &&
746 pen->GetColour() == colour )
747 return pen;
13b6e335
VZ
748 }
749
1de8d512
VZ
750 wxPen* pen = NULL;
751 wxPen penTmp(colour, width, style);
752 if (penTmp.Ok())
c801d85f 753 {
1de8d512
VZ
754 pen = new wxPen(penTmp);
755 list.Append(pen);
c801d85f 756 }
c801d85f 757
13b6e335 758 return pen;
c801d85f
KB
759}
760
debe6624 761wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
c801d85f 762{
b685c0a6
VZ
763 for ( wxList::compatibility_iterator node = list.GetFirst();
764 node;
765 node = node->GetNext() )
c801d85f 766 {
b685c0a6
VZ
767 wxBrush * const brush = (wxBrush *) node->GetData ();
768 if ( brush->GetStyle () == style && brush->GetColour() == colour )
769 return brush;
c801d85f 770 }
6d167489 771
1de8d512
VZ
772 wxBrush* brush = NULL;
773 wxBrush brushTmp(colour, style);
774 if (brushTmp.Ok())
13b6e335 775 {
1de8d512
VZ
776 brush = new wxBrush(brushTmp);
777 list.Append(brush);
13b6e335 778 }
6d167489 779
13b6e335 780 return brush;
c801d85f
KB
781}
782
f6bcfd97
BP
783wxFont *wxFontList::FindOrCreateFont(int pointSize,
784 int family,
785 int style,
786 int weight,
787 bool underline,
788 const wxString& facename,
789 wxFontEncoding encoding)
c801d85f 790{
1de8d512 791 wxFont *font;
222ed1d6 792 wxList::compatibility_iterator node;
1de8d512 793 for (node = list.GetFirst(); node; node = node->GetNext())
c801d85f 794 {
b1d4dd7a 795 font = (wxFont *)node->GetData();
1de8d512 796 if (
f6bcfd97
BP
797 font->GetPointSize () == pointSize &&
798 font->GetStyle () == style &&
799 font->GetWeight () == weight &&
800 font->GetUnderlined () == underline )
801 {
802 int fontFamily = font->GetFamily();
803
619d0528 804#if defined(__WXGTK__)
f6bcfd97
BP
805 // under GTK the default family is wxSWISS, so looking for a font
806 // with wxDEFAULT family should return a wxSWISS one instead of
807 // creating a new one
808 bool same = (fontFamily == family) ||
809 (fontFamily == wxSWISS && family == wxDEFAULT);
810#else // !GTK
811 // VZ: but why elsewhere do we require an exact match? mystery...
812 bool same = fontFamily == family;
813#endif // GTK/!GTK
814
815 // empty facename matches anything at all: this is bad because
816 // depending on which fonts are already created, we might get back
817 // a different font if we create it with empty facename, but it is
818 // still better than never matching anything in the cache at all
819 // in this case
8d8fbb9d 820 if ( same && !facename.empty() )
f6bcfd97
BP
821 {
822 const wxString& fontFace = font->GetFaceName();
823
824 // empty facename matches everything
825 same = !fontFace || fontFace == facename;
826 }
827
828 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
829 {
830 // have to match the encoding too
831 same = font->GetEncoding() == encoding;
832 }
833
834 if ( same )
835 {
836 return font;
837 }
838 }
c801d85f 839 }
6d167489 840
1de8d512
VZ
841 // font not found, create the new one
842 font = NULL;
843 wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding);
844 if (fontTmp.Ok())
f6bcfd97 845 {
1de8d512
VZ
846 font = new wxFont(fontTmp);
847 list.Append(font);
f6bcfd97 848 }
6d167489 849
f6bcfd97 850 return font;
c801d85f
KB
851}
852
1de8d512
VZ
853#if WXWIN_COMPATIBILITY_2_6
854void wxBrushList::AddBrush(wxBrush*) { }
855void wxBrushList::RemoveBrush(wxBrush*) { }
856void wxFontList::AddFont(wxFont*) { }
857void wxFontList::RemoveFont(wxFont*) { }
858void wxPenList::AddPen(wxPen*) { }
859void wxPenList::RemovePen(wxPen*) { }
860#endif
c801d85f 861
6a6c0a8b
JS
862wxSize wxGetDisplaySize()
863{
864 int x, y;
865 wxDisplaySize(& x, & y);
866 return wxSize(x, y);
867}
868
ec5d7799
RD
869wxRect wxGetClientDisplayRect()
870{
871 int x, y, width, height;
872 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
873 return wxRect(x, y, width, height);
874}
875
904a68b6
RL
876wxSize wxGetDisplaySizeMM()
877{
878 int x, y;
879 wxDisplaySizeMM(& x, & y);
880 return wxSize(x, y);
881}
882
8bbe427f
VZ
883wxResourceCache::~wxResourceCache ()
884{
222ed1d6 885 wxList::compatibility_iterator node = GetFirst ();
f6bcfd97 886 while (node) {
b1d4dd7a 887 wxObject *item = (wxObject *)node->GetData();
f6bcfd97 888 delete item;
a3622daa 889
b1d4dd7a 890 node = node->GetNext ();
a3622daa 891 }
a3622daa 892}