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