]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
Fix horizontal mouse wheel scrolling in wxGTK.
[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
55d99c7a 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
c801d85f
KB
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
670f9935 15 #pragma hdrstop
c801d85f
KB
16#endif
17
18#include "wx/gdicmn.h"
5819f832 19#include "wx/gdiobj.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"
52734360 27 #include "wx/iconbndl.h"
c8326d64 28 #include "wx/cursor.h"
9eddec69 29 #include "wx/settings.h"
0bca0373 30 #include "wx/bitmap.h"
7cf41a5d 31 #include "wx/colour.h"
48a1108e 32 #include "wx/font.h"
d43be80d 33 #include "wx/math.h"
e4db172a
WS
34#endif
35
5819f832 36
8f884a0d 37IMPLEMENT_ABSTRACT_CLASS(wxGDIObject, wxObject)
5819f832
VS
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
a5664fd6 254wxRealPoint::wxRealPoint(const wxPoint& pt)
ce00f59b 255 : x(pt.x), y(pt.y)
a5664fd6
FM
256{
257}
258
c50f92d0
VZ
259// ============================================================================
260// wxColourDatabase
261// ============================================================================
262
c50f92d0
VZ
263// ----------------------------------------------------------------------------
264// wxColourDatabase ctor/dtor
265// ----------------------------------------------------------------------------
222ed1d6
MB
266
267wxColourDatabase::wxColourDatabase ()
c801d85f 268{
c50f92d0
VZ
269 // will be created on demand in Initialize()
270 m_map = NULL;
c801d85f
KB
271}
272
6a6c0a8b 273wxColourDatabase::~wxColourDatabase ()
c801d85f 274{
c50f92d0
VZ
275 if ( m_map )
276 {
277 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
278
279 delete m_map;
280 }
222ed1d6 281
19bf0c69
DW
282#ifdef __WXPM__
283 delete [] m_palTable;
284#endif
c801d85f
KB
285}
286
287// Colour database stuff
c50f92d0 288void wxColourDatabase::Initialize()
c801d85f 289{
c50f92d0
VZ
290 if ( m_map )
291 {
292 // already initialized
293 return;
294 }
295
296 m_map = new wxStringToColourHashMap;
297
f6bcfd97
BP
298 static const struct wxColourDesc
299 {
300 const wxChar *name;
5c519b6c 301 unsigned char r,g,b;
f6bcfd97
BP
302 }
303 wxColourTable[] =
304 {
5e2ab1ea 305 {wxT("AQUAMARINE"),112, 219, 147},
f6bcfd97
BP
306 {wxT("BLACK"),0, 0, 0},
307 {wxT("BLUE"), 0, 0, 255},
5e2ab1ea 308 {wxT("BLUE VIOLET"), 159, 95, 159},
f6bcfd97 309 {wxT("BROWN"), 165, 42, 42},
5e2ab1ea
VZ
310 {wxT("CADET BLUE"), 95, 159, 159},
311 {wxT("CORAL"), 255, 127, 0},
312 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
f6bcfd97 313 {wxT("CYAN"), 0, 255, 255},
5e2ab1ea
VZ
314 {wxT("DARK GREY"), 47, 47, 47}, // ?
315
316 {wxT("DARK GREEN"), 47, 79, 47},
317 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
f6bcfd97 318 {wxT("DARK ORCHID"), 153, 50, 204},
5e2ab1ea 319 {wxT("DARK SLATE BLUE"), 107, 35, 142},
f6bcfd97 320 {wxT("DARK SLATE GREY"), 47, 79, 79},
5e2ab1ea
VZ
321 {wxT("DARK TURQUOISE"), 112, 147, 219},
322 {wxT("DIM GREY"), 84, 84, 84},
323 {wxT("FIREBRICK"), 142, 35, 35},
324 {wxT("FOREST GREEN"), 35, 142, 35},
325 {wxT("GOLD"), 204, 127, 50},
326 {wxT("GOLDENROD"), 219, 219, 112},
327 {wxT("GREY"), 128, 128, 128},
f6bcfd97 328 {wxT("GREEN"), 0, 255, 0},
5e2ab1ea
VZ
329 {wxT("GREEN YELLOW"), 147, 219, 112},
330 {wxT("INDIAN RED"), 79, 47, 47},
331 {wxT("KHAKI"), 159, 159, 95},
332 {wxT("LIGHT BLUE"), 191, 216, 216},
333 {wxT("LIGHT GREY"), 192, 192, 192},
334 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
335 {wxT("LIME GREEN"), 50, 204, 50},
336 {wxT("LIGHT MAGENTA"), 255, 0, 255},
f6bcfd97 337 {wxT("MAGENTA"), 255, 0, 255},
5e2ab1ea
VZ
338 {wxT("MAROON"), 142, 35, 107},
339 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
340 {wxT("MEDIUM GREY"), 100, 100, 100},
341 {wxT("MEDIUM BLUE"), 50, 50, 204},
342 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
343 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
344 {wxT("MEDIUM ORCHID"), 147, 112, 219},
345 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
346 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
347 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
348 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
349 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
350 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
351 {wxT("NAVY"), 35, 35, 142},
352 {wxT("ORANGE"), 204, 50, 50},
353 {wxT("ORANGE RED"), 255, 0, 127},
354 {wxT("ORCHID"), 219, 112, 219},
355 {wxT("PALE GREEN"), 143, 188, 143},
59571b71 356 {wxT("PINK"), 255, 192, 203},
5e2ab1ea
VZ
357 {wxT("PLUM"), 234, 173, 234},
358 {wxT("PURPLE"), 176, 0, 255},
f6bcfd97 359 {wxT("RED"), 255, 0, 0},
5e2ab1ea
VZ
360 {wxT("SALMON"), 111, 66, 66},
361 {wxT("SEA GREEN"), 35, 142, 107},
362 {wxT("SIENNA"), 142, 107, 35},
363 {wxT("SKY BLUE"), 50, 153, 204},
364 {wxT("SLATE BLUE"), 0, 127, 255},
f6bcfd97 365 {wxT("SPRING GREEN"), 0, 255, 127},
5e2ab1ea
VZ
366 {wxT("STEEL BLUE"), 35, 107, 142},
367 {wxT("TAN"), 219, 147, 112},
f6bcfd97 368 {wxT("THISTLE"), 216, 191, 216},
5e2ab1ea
VZ
369 {wxT("TURQUOISE"), 173, 234, 234},
370 {wxT("VIOLET"), 79, 47, 79},
371 {wxT("VIOLET RED"), 204, 50, 153},
372 {wxT("WHEAT"), 216, 216, 191},
f6bcfd97
BP
373 {wxT("WHITE"), 255, 255, 255},
374 {wxT("YELLOW"), 255, 255, 0},
aad6765c 375 {wxT("YELLOW GREEN"), 153, 204, 50}
f6bcfd97
BP
376 };
377
c50f92d0 378 size_t n;
bf2c4b94
DW
379
380 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
f6bcfd97
BP
381 {
382 const wxColourDesc& cc = wxColourTable[n];
c50f92d0 383 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
f6bcfd97 384 }
c50f92d0 385
19bf0c69
DW
386#ifdef __WXPM__
387 m_palTable = new long[n];
388 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
389 {
390 const wxColourDesc& cc = wxColourTable[n];
391 m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b);
392 }
393 m_nSize = n;
394#endif
c801d85f
KB
395}
396
c50f92d0
VZ
397// ----------------------------------------------------------------------------
398// wxColourDatabase operations
399// ----------------------------------------------------------------------------
222ed1d6 400
c50f92d0 401void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
222ed1d6 402{
c50f92d0 403 Initialize();
222ed1d6 404
c50f92d0
VZ
405 // canonicalize the colour names before using them as keys: they should be
406 // in upper case
8f520a56
MB
407 wxString colName = name;
408 colName.MakeUpper();
c50f92d0
VZ
409
410 // ... and we also allow both grey/gray
411 wxString colNameAlt = colName;
9a83f860 412 if ( !colNameAlt.Replace(wxT("GRAY"), wxT("GREY")) )
c50f92d0
VZ
413 {
414 // but in this case it is not necessary so avoid extra search below
415 colNameAlt.clear();
416 }
8f520a56
MB
417
418 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
419 if ( it == m_map->end() && !colNameAlt.empty() )
420 it = m_map->find(colNameAlt);
8f520a56
MB
421 if ( it != m_map->end() )
422 {
c50f92d0
VZ
423 *(it->second) = colour;
424 }
425 else // new colour
426 {
5767e836 427 (*m_map)[colName] = new wxColour(colour);
8f520a56 428 }
8f520a56
MB
429}
430
c50f92d0 431wxColour wxColourDatabase::Find(const wxString& colour) const
c801d85f 432{
c50f92d0
VZ
433 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
434 self->Initialize();
435
c50f92d0 436 // make the comparaison case insensitive and also match both grey and gray
f6bcfd97
BP
437 wxString colName = colour;
438 colName.MakeUpper();
c50f92d0 439 wxString colNameAlt = colName;
9a83f860 440 if ( !colNameAlt.Replace(wxT("GRAY"), wxT("GREY")) )
c50f92d0 441 colNameAlt.clear();
f6bcfd97 442
222ed1d6 443 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
444 if ( it == m_map->end() && !colNameAlt.empty() )
445 it = m_map->find(colNameAlt);
222ed1d6 446 if ( it != m_map->end() )
c50f92d0 447 return *(it->second);
34138703 448
40989e46
WS
449 // we did not find any result in existing colours:
450 // we won't use wxString -> wxColour conversion because the
451 // wxColour::Set(const wxString &) function which does that conversion
452 // internally uses this function (wxColourDatabase::Find) and we want
453 // to avoid infinite recursion !
c50f92d0 454 return wxNullColour;
c801d85f
KB
455}
456
c50f92d0 457wxString wxColourDatabase::FindName(const wxColour& colour) const
c801d85f 458{
c50f92d0
VZ
459 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
460 self->Initialize();
8bbe427f 461
222ed1d6
MB
462 typedef wxStringToColourHashMap::iterator iterator;
463
c50f92d0 464 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
a23fd0e1 465 {
c50f92d0 466 if ( *(it->second) == colour )
222ed1d6 467 return it->first;
a23fd0e1 468 }
c801d85f 469
222ed1d6 470 return wxEmptyString;
c801d85f
KB
471}
472
c50f92d0
VZ
473// ----------------------------------------------------------------------------
474// deprecated wxColourDatabase methods
475// ----------------------------------------------------------------------------
476
ca3e85cf 477#if WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
478wxColour *wxColourDatabase::FindColour(const wxString& name)
479{
98de2b68
DS
480 // This function is deprecated, use Find() instead.
481 // Formerly this function sometimes would return a deletable pointer and
482 // sometimes a non-deletable one (when returning a colour from the database).
483 // Trying to delete the latter anyway results in problems, so probably
484 // nobody ever freed the pointers. Currently it always returns a new
485 // instance, which means there will be memory leaks.
486 wxLogDebug(wxT("wxColourDataBase::FindColour():")
487 wxT(" Please use wxColourDataBase::Find() instead"));
488
492e2a5b
VZ
489 // using a static variable here is not the most elegant solution but unless
490 // we want to make wxStringToColourHashMap public (i.e. move it to the
491 // header) so that we could have a member function returning
492 // wxStringToColourHashMap::iterator, there is really no good way to do it
493 // otherwise
494 //
495 // and knowing that this function is going to disappear in the next release
496 // anyhow I don't want to waste time on this
98de2b68 497
492e2a5b
VZ
498 static wxColour s_col;
499
500 s_col = Find(name);
a1b806b9 501 if ( !s_col.IsOk() )
c50f92d0
VZ
502 return NULL;
503
98de2b68 504 return new wxColour(s_col);
c50f92d0 505}
ca3e85cf 506#endif // WXWIN_COMPATIBILITY_2_6
c50f92d0
VZ
507
508// ============================================================================
509// stock objects
510// ============================================================================
511
f516d986
VZ
512static wxStockGDI gs_wxStockGDI_instance;
513wxStockGDI* wxStockGDI::ms_instance = &gs_wxStockGDI_instance;
514wxObject* wxStockGDI::ms_stockObject[ITEMCOUNT];
515
516wxStockGDI::wxStockGDI()
7ecb8b06 517{
f516d986 518}
1c193821 519
f516d986
VZ
520wxStockGDI::~wxStockGDI()
521{
a3622daa 522}
c801d85f 523
f516d986 524void wxStockGDI::DeleteAll()
a3622daa 525{
f516d986
VZ
526 for (unsigned i = 0; i < ITEMCOUNT; i++)
527 {
5276b0a5 528 wxDELETE(ms_stockObject[i]);
f516d986
VZ
529 }
530}
c801d85f 531
f516d986
VZ
532const wxBrush* wxStockGDI::GetBrush(Item item)
533{
5c33522f 534 wxBrush* brush = static_cast<wxBrush*>(ms_stockObject[item]);
f516d986
VZ
535 if (brush == NULL)
536 {
537 switch (item)
538 {
539 case BRUSH_BLACK:
04ee05f9 540 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxBRUSHSTYLE_SOLID);
f516d986
VZ
541 break;
542 case BRUSH_BLUE:
04ee05f9 543 brush = new wxBrush(*GetColour(COLOUR_BLUE), wxBRUSHSTYLE_SOLID);
f516d986
VZ
544 break;
545 case BRUSH_CYAN:
04ee05f9 546 brush = new wxBrush(*GetColour(COLOUR_CYAN), wxBRUSHSTYLE_SOLID);
f516d986
VZ
547 break;
548 case BRUSH_GREEN:
04ee05f9 549 brush = new wxBrush(*GetColour(COLOUR_GREEN), wxBRUSHSTYLE_SOLID);
f516d986 550 break;
86028025
FM
551 case BRUSH_YELLOW:
552 brush = new wxBrush(*GetColour(COLOUR_YELLOW), wxBRUSHSTYLE_SOLID);
553 break;
f516d986 554 case BRUSH_GREY:
04ee05f9 555 brush = new wxBrush(wxColour(wxT("GREY")), wxBRUSHSTYLE_SOLID);
f516d986
VZ
556 break;
557 case BRUSH_LIGHTGREY:
04ee05f9 558 brush = new wxBrush(*GetColour(COLOUR_LIGHTGREY), wxBRUSHSTYLE_SOLID);
f516d986
VZ
559 break;
560 case BRUSH_MEDIUMGREY:
04ee05f9 561 brush = new wxBrush(wxColour(wxT("MEDIUM GREY")), wxBRUSHSTYLE_SOLID);
f516d986
VZ
562 break;
563 case BRUSH_RED:
04ee05f9 564 brush = new wxBrush(*GetColour(COLOUR_RED), wxBRUSHSTYLE_SOLID);
f516d986
VZ
565 break;
566 case BRUSH_TRANSPARENT:
04ee05f9 567 brush = new wxBrush(*GetColour(COLOUR_BLACK), wxBRUSHSTYLE_TRANSPARENT);
f516d986
VZ
568 break;
569 case BRUSH_WHITE:
04ee05f9 570 brush = new wxBrush(*GetColour(COLOUR_WHITE), wxBRUSHSTYLE_SOLID);
f516d986
VZ
571 break;
572 default:
573 wxFAIL;
574 }
575 ms_stockObject[item] = brush;
576 }
577 return brush;
578}
696e1ea0 579
f516d986
VZ
580const wxColour* wxStockGDI::GetColour(Item item)
581{
5c33522f 582 wxColour* colour = static_cast<wxColour*>(ms_stockObject[item]);
f516d986
VZ
583 if (colour == NULL)
584 {
585 switch (item)
586 {
587 case COLOUR_BLACK:
588 colour = new wxColour(0, 0, 0);
589 break;
590 case COLOUR_BLUE:
591 colour = new wxColour(0, 0, 255);
592 break;
593 case COLOUR_CYAN:
594 colour = new wxColour(wxT("CYAN"));
595 break;
596 case COLOUR_GREEN:
597 colour = new wxColour(0, 255, 0);
598 break;
86028025
FM
599 case COLOUR_YELLOW:
600 colour = new wxColour(255, 255, 0);
601 break;
f516d986
VZ
602 case COLOUR_LIGHTGREY:
603 colour = new wxColour(wxT("LIGHT GREY"));
604 break;
605 case COLOUR_RED:
606 colour = new wxColour(255, 0, 0);
607 break;
608 case COLOUR_WHITE:
609 colour = new wxColour(255, 255, 255);
610 break;
611 default:
612 wxFAIL;
613 }
614 ms_stockObject[item] = colour;
615 }
616 return colour;
617}
618
619const wxCursor* wxStockGDI::GetCursor(Item item)
620{
5c33522f 621 wxCursor* cursor = static_cast<wxCursor*>(ms_stockObject[item]);
f516d986
VZ
622 if (cursor == NULL)
623 {
624 switch (item)
625 {
626 case CURSOR_CROSS:
627 cursor = new wxCursor(wxCURSOR_CROSS);
628 break;
629 case CURSOR_HOURGLASS:
630 cursor = new wxCursor(wxCURSOR_WAIT);
631 break;
632 case CURSOR_STANDARD:
633 cursor = new wxCursor(wxCURSOR_ARROW);
634 break;
635 default:
636 wxFAIL;
637 }
638 ms_stockObject[item] = cursor;
639 }
640 return cursor;
641}
642
643const wxFont* wxStockGDI::GetFont(Item item)
644{
5c33522f 645 wxFont* font = static_cast<wxFont*>(ms_stockObject[item]);
f516d986
VZ
646 if (font == NULL)
647 {
648 switch (item)
649 {
650 case FONT_ITALIC:
651 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxROMAN, wxITALIC, wxNORMAL);
652 break;
653 case FONT_NORMAL:
654 font = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
655 break;
656 case FONT_SMALL:
85a92283
VZ
657 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize()
658 // Using the font 2 points smaller than the normal one
659 // results in font so small as to be unreadable under MSW.
660 // We might want to actually use -1 under the other
661 // platforms too but for now be conservative and keep -2
662 // there for compatibility with the old behaviour as the
663 // small font seems to be readable enough there as it is.
664#ifdef __WXMSW__
665 - 1,
666#else
667 - 2,
668#endif
669 wxSWISS, wxNORMAL, wxNORMAL);
f516d986
VZ
670 break;
671 case FONT_SWISS:
672 font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxSWISS, wxNORMAL, wxNORMAL);
673 break;
674 default:
675 wxFAIL;
676 }
677 ms_stockObject[item] = font;
678 }
679 return font;
680}
c801d85f 681
f516d986
VZ
682const wxPen* wxStockGDI::GetPen(Item item)
683{
5c33522f 684 wxPen* pen = static_cast<wxPen*>(ms_stockObject[item]);
f516d986
VZ
685 if (pen == NULL)
686 {
687 switch (item)
688 {
689 case PEN_BLACK:
82cddbd9 690 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_SOLID);
f516d986
VZ
691 break;
692 case PEN_BLACKDASHED:
82cddbd9 693 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_SHORT_DASH);
f516d986 694 break;
d8184587
FM
695 case PEN_BLUE:
696 pen = new wxPen(*GetColour(COLOUR_BLUE), 1, wxPENSTYLE_SOLID);
697 break;
f516d986 698 case PEN_CYAN:
82cddbd9 699 pen = new wxPen(*GetColour(COLOUR_CYAN), 1, wxPENSTYLE_SOLID);
f516d986
VZ
700 break;
701 case PEN_GREEN:
82cddbd9 702 pen = new wxPen(*GetColour(COLOUR_GREEN), 1, wxPENSTYLE_SOLID);
f516d986 703 break;
86028025
FM
704 case PEN_YELLOW:
705 pen = new wxPen(*GetColour(COLOUR_YELLOW), 1, wxPENSTYLE_SOLID);
706 break;
f516d986 707 case PEN_GREY:
82cddbd9 708 pen = new wxPen(wxColour(wxT("GREY")), 1, wxPENSTYLE_SOLID);
f516d986
VZ
709 break;
710 case PEN_LIGHTGREY:
82cddbd9 711 pen = new wxPen(*GetColour(COLOUR_LIGHTGREY), 1, wxPENSTYLE_SOLID);
f516d986
VZ
712 break;
713 case PEN_MEDIUMGREY:
82cddbd9 714 pen = new wxPen(wxColour(wxT("MEDIUM GREY")), 1, wxPENSTYLE_SOLID);
f516d986
VZ
715 break;
716 case PEN_RED:
82cddbd9 717 pen = new wxPen(*GetColour(COLOUR_RED), 1, wxPENSTYLE_SOLID);
f516d986
VZ
718 break;
719 case PEN_TRANSPARENT:
82cddbd9 720 pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxPENSTYLE_TRANSPARENT);
f516d986
VZ
721 break;
722 case PEN_WHITE:
82cddbd9 723 pen = new wxPen(*GetColour(COLOUR_WHITE), 1, wxPENSTYLE_SOLID);
f516d986
VZ
724 break;
725 default:
726 wxFAIL;
727 }
728 ms_stockObject[item] = pen;
729 }
730 return pen;
c801d85f
KB
731}
732
f516d986 733void wxInitializeStockLists()
c801d85f 734{
f516d986
VZ
735 wxTheColourDatabase = new wxColourDatabase;
736
737 wxTheBrushList = new wxBrushList;
738 wxThePenList = new wxPenList;
739 wxTheFontList = new wxFontList;
a3622daa
VZ
740}
741
7ecb8b06
VZ
742void wxDeleteStockLists()
743{
5d3e7b52
WS
744 wxDELETE(wxTheBrushList);
745 wxDELETE(wxThePenList);
746 wxDELETE(wxTheFontList);
41d0b41d
FM
747
748 // wxTheColourDatabase is cleaned up by wxAppBase::CleanUp()
c801d85f
KB
749}
750
7ecb8b06
VZ
751// ============================================================================
752// wxTheXXXList stuff (semi-obsolete)
753// ============================================================================
754
1de8d512 755wxGDIObjListBase::wxGDIObjListBase()
c801d85f 756{
c801d85f
KB
757}
758
1de8d512 759wxGDIObjListBase::~wxGDIObjListBase()
c801d85f 760{
1de8d512 761 for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
c801d85f 762 {
5c33522f 763 delete static_cast<wxObject*>(node->GetData());
c801d85f
KB
764 }
765}
766
82cddbd9 767wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, wxPenStyle style)
c801d85f 768{
b685c0a6
VZ
769 for ( wxList::compatibility_iterator node = list.GetFirst();
770 node;
771 node = node->GetNext() )
13b6e335 772 {
b685c0a6
VZ
773 wxPen * const pen = (wxPen *) node->GetData();
774 if ( pen->GetWidth () == width &&
775 pen->GetStyle () == style &&
776 pen->GetColour() == colour )
777 return pen;
13b6e335
VZ
778 }
779
1de8d512
VZ
780 wxPen* pen = NULL;
781 wxPen penTmp(colour, width, style);
a1b806b9 782 if (penTmp.IsOk())
c801d85f 783 {
1de8d512
VZ
784 pen = new wxPen(penTmp);
785 list.Append(pen);
c801d85f 786 }
c801d85f 787
13b6e335 788 return pen;
c801d85f
KB
789}
790
3e6858cd 791wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, wxBrushStyle style)
c801d85f 792{
b685c0a6
VZ
793 for ( wxList::compatibility_iterator node = list.GetFirst();
794 node;
795 node = node->GetNext() )
c801d85f 796 {
b685c0a6 797 wxBrush * const brush = (wxBrush *) node->GetData ();
3e6858cd 798 if ( brush->GetStyle() == style && brush->GetColour() == colour )
b685c0a6 799 return brush;
c801d85f 800 }
6d167489 801
1de8d512
VZ
802 wxBrush* brush = NULL;
803 wxBrush brushTmp(colour, style);
a1b806b9 804 if (brushTmp.IsOk())
13b6e335 805 {
1de8d512
VZ
806 brush = new wxBrush(brushTmp);
807 list.Append(brush);
13b6e335 808 }
6d167489 809
13b6e335 810 return brush;
c801d85f
KB
811}
812
f6bcfd97 813wxFont *wxFontList::FindOrCreateFont(int pointSize,
82cddbd9
FM
814 wxFontFamily family,
815 wxFontStyle style,
816 wxFontWeight weight,
f6bcfd97
BP
817 bool underline,
818 const wxString& facename,
819 wxFontEncoding encoding)
c801d85f 820{
00dc8bac
VZ
821 // In all ports but wxOSX, the effective family of a font created using
822 // wxFONTFAMILY_DEFAULT is wxFONTFAMILY_SWISS so this is what we need to
823 // use for comparison.
824 //
825 // In wxOSX the original wxFONTFAMILY_DEFAULT seems to be kept and it uses
826 // a different font than wxFONTFAMILY_SWISS anyhow so we just preserve it.
827#ifndef __WXOSX__
828 if ( family == wxFONTFAMILY_DEFAULT )
829 family = wxFONTFAMILY_SWISS;
830#endif // !__WXOSX__
831
1de8d512 832 wxFont *font;
222ed1d6 833 wxList::compatibility_iterator node;
1de8d512 834 for (node = list.GetFirst(); node; node = node->GetNext())
c801d85f 835 {
b1d4dd7a 836 font = (wxFont *)node->GetData();
1de8d512 837 if (
f6bcfd97
BP
838 font->GetPointSize () == pointSize &&
839 font->GetStyle () == style &&
840 font->GetWeight () == weight &&
841 font->GetUnderlined () == underline )
842 {
00dc8bac 843 bool same = font->GetFamily() == family;
f6bcfd97
BP
844
845 // empty facename matches anything at all: this is bad because
846 // depending on which fonts are already created, we might get back
847 // a different font if we create it with empty facename, but it is
848 // still better than never matching anything in the cache at all
849 // in this case
8d8fbb9d 850 if ( same && !facename.empty() )
f6bcfd97
BP
851 {
852 const wxString& fontFace = font->GetFaceName();
853
854 // empty facename matches everything
855 same = !fontFace || fontFace == facename;
856 }
857
858 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
859 {
860 // have to match the encoding too
861 same = font->GetEncoding() == encoding;
862 }
863
864 if ( same )
865 {
866 return font;
867 }
868 }
c801d85f 869 }
6d167489 870
1de8d512
VZ
871 // font not found, create the new one
872 font = NULL;
873 wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding);
a1b806b9 874 if (fontTmp.IsOk())
f6bcfd97 875 {
1de8d512
VZ
876 font = new wxFont(fontTmp);
877 list.Append(font);
f6bcfd97 878 }
6d167489 879
f6bcfd97 880 return font;
c801d85f
KB
881}
882
1de8d512
VZ
883#if WXWIN_COMPATIBILITY_2_6
884void wxBrushList::AddBrush(wxBrush*) { }
885void wxBrushList::RemoveBrush(wxBrush*) { }
886void wxFontList::AddFont(wxFont*) { }
887void wxFontList::RemoveFont(wxFont*) { }
888void wxPenList::AddPen(wxPen*) { }
889void wxPenList::RemovePen(wxPen*) { }
890#endif
c801d85f 891
6a6c0a8b
JS
892wxSize wxGetDisplaySize()
893{
894 int x, y;
895 wxDisplaySize(& x, & y);
896 return wxSize(x, y);
897}
898
ec5d7799
RD
899wxRect wxGetClientDisplayRect()
900{
901 int x, y, width, height;
902 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
903 return wxRect(x, y, width, height);
904}
905
904a68b6
RL
906wxSize wxGetDisplaySizeMM()
907{
908 int x, y;
909 wxDisplaySizeMM(& x, & y);
910 return wxSize(x, y);
911}
912
40fcf546
VS
913wxSize wxGetDisplayPPI()
914{
915 const wxSize pixels = wxGetDisplaySize();
916 const wxSize mm = wxGetDisplaySizeMM();
917
d43be80d
VZ
918 return wxSize((int)((pixels.x * inches2mm) / mm.x),
919 (int)((pixels.y * inches2mm) / mm.y));
40fcf546
VS
920}
921
8bbe427f
VZ
922wxResourceCache::~wxResourceCache ()
923{
222ed1d6 924 wxList::compatibility_iterator node = GetFirst ();
f6bcfd97 925 while (node) {
b1d4dd7a 926 wxObject *item = (wxObject *)node->GetData();
f6bcfd97 927 delete item;
a3622daa 928
b1d4dd7a 929 node = node->GetNext ();
a3622daa 930 }
a3622daa 931}