]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
Reverted/commented out unsuccessful defer fix
[wxWidgets.git] / src / common / gdicmn.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: gdicmn.cpp
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
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
13#pragma implementation "gdicmn.h"
14#endif
15
4dff3400
JJ
16#ifdef __VMS
17#define XtDisplay XTDISPLAY
18#endif
19
c801d85f
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24#pragma hdrstop
25#endif
26
2432b92d 27#include "wx/event.h"
c801d85f
KB
28#include "wx/gdicmn.h"
29#include "wx/brush.h"
30#include "wx/pen.h"
31#include "wx/bitmap.h"
32#include "wx/icon.h"
33#include "wx/cursor.h"
34#include "wx/font.h"
35#include "wx/palette.h"
46ccb510 36#include "wx/app.h"
b0e0d661 37#include "wx/dc.h"
b93d0c64 38#include "wx/utils.h"
5100cabf 39#include "wx/settings.h"
222ed1d6 40#include "wx/hashmap.h"
c801d85f 41
cb38104e 42#include "wx/log.h"
c801d85f
KB
43#include <string.h>
44
82ef81ed 45#if defined(__WXMSW__)
9ed0d735 46#include "wx/msw/wrapwin.h"
c801d85f
KB
47#endif
48
46ccb510 49#ifdef __WXMOTIF__
338dd992
JJ
50#ifdef __VMS__
51#pragma message disable nosimpint
52#endif
46ccb510 53#include <Xm/Xm.h>
338dd992
JJ
54#ifdef __VMS__
55#pragma message enable nosimpint
56#endif
46ccb510
JS
57#endif
58
7266b672
JS
59#ifdef __WXX11__
60#include "X11/Xlib.h"
61#endif
62
99fd0d71
SC
63#ifdef __WXMAC__
64#include "wx/mac/private.h"
e4a05ccd 65#include "wx/mac/uma.h"
99fd0d71 66#endif
a23fd0e1 67
cb73e600
SC
68#if wxUSE_EXTENDED_RTTI
69
70// wxPoint
71
72template<> void wxStringReadValue(const wxString &s , wxPoint &data )
73{
5d3e7b52 74 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
75}
76
77template<> void wxStringWriteValue(wxString &s , const wxPoint &data )
78{
5d3e7b52 79 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
80}
81
8805dbab 82wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>)
cb73e600
SC
83
84template<> void wxStringReadValue(const wxString &s , wxSize &data )
85{
5d3e7b52 86 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
cb73e600
SC
87}
88
89template<> void wxStringWriteValue(wxString &s , const wxSize &data )
90{
5d3e7b52 91 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
cb73e600
SC
92}
93
8805dbab 94wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>)
cb73e600
SC
95
96#endif
97
45816ddd 98IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
c801d85f 99
d7a7546b 100wxRect::wxRect(const wxPoint& point1, const wxPoint& point2)
c801d85f 101{
5d3e7b52
WS
102 x = point1.x;
103 y = point1.y;
104 width = point2.x - point1.x;
105 height = point2.y - point1.y;
8bbe427f 106
5d3e7b52
WS
107 if (width < 0)
108 {
109 width = -width;
110 x = point2.x;
111 }
112 width++;
8bbe427f 113
5d3e7b52
WS
114 if (height < 0)
115 {
116 height = -height;
117 y = point2.y;
118 }
119 height++;
c801d85f
KB
120}
121
a23fd0e1 122bool wxRect::operator==(const wxRect& rect) const
c801d85f 123{
5d3e7b52
WS
124 return ((x == rect.x) &&
125 (y == rect.y) &&
126 (width == rect.width) &&
127 (height == rect.height));
c801d85f
KB
128}
129
df83b840 130wxRect wxRect::operator+(const wxRect& rect) const
619d0528 131{
45816ddd
VZ
132 int x1 = wxMin(this->x, rect.x);
133 int y1 = wxMin(this->y, rect.y);
134 int y2 = wxMax(y+height, rect.height+rect.y);
135 int x2 = wxMax(x+width, rect.width+rect.x);
136 return wxRect(x1, y1, x2-x1, y2-y1);
dcb44466
JS
137}
138
df83b840
VZ
139wxRect& wxRect::Union(const wxRect& rect)
140{
c71ce675
VZ
141 // ignore empty rectangles: union with an empty rectangle shouldn't extend
142 // this one to (0, 0)
143 if ( !width || !height )
144 {
145 *this = rect;
146 }
147 else if ( rect.width && rect.height )
df83b840
VZ
148 {
149 int x1 = wxMin(x, rect.x);
150 int y1 = wxMin(y, rect.y);
151 int y2 = wxMax(y + height, rect.height + rect.y);
152 int x2 = wxMax(x + width, rect.width + rect.x);
153
154 x = x1;
155 y = y1;
156 width = x2 - x1;
157 height = y2 - y1;
158 }
c71ce675 159 //else: we're not empty and rect is empty
df83b840
VZ
160
161 return *this;
162}
163
1e6feb95
VZ
164wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy)
165{
8673a125
VZ
166 if (-2*dx>width)
167 {
168 // Don't allow deflate to eat more width than we have,
169 // a well-defined rectangle cannot have negative width.
170 x+=width/2;
171 width=0;
172 }
173 else
174 {
175 // The inflate is valid.
176 x-=dx;
177 width+=2*dx;
178 }
179
180 if (-2*dy>height)
181 {
182 // Don't allow deflate to eat more height than we have,
183 // a well-defined rectangle cannot have negative height.
184 y+=height/2;
185 height=0;
186 }
187 else
188 {
189 // The inflate is valid.
190 y-=dy;
191 height+=2*dy;
192 }
1e6feb95
VZ
193
194 return *this;
195}
196
dcb44466
JS
197bool wxRect::Inside(int cx, int cy) const
198{
45816ddd
VZ
199 return ( (cx >= x) && (cy >= y)
200 && ((cy - y) < height)
201 && ((cx - x) < width)
202 );
dcb44466
JS
203}
204
1e6feb95
VZ
205wxRect& wxRect::Intersect(const wxRect& rect)
206{
207 int x2 = GetRight(),
208 y2 = GetBottom();
209
210 if ( x < rect.x )
211 x = rect.x;
212 if ( y < rect.y )
213 y = rect.y;
214 if ( x2 > rect.GetRight() )
215 x2 = rect.GetRight();
216 if ( y2 > rect.GetBottom() )
217 y2 = rect.GetBottom();
218
219 width = x2 - x + 1;
220 height = y2 - y + 1;
221
222 if ( width <= 0 || height <= 0 )
223 {
224 width =
225 height = 0;
226 }
227
228 return *this;
229}
230
231bool wxRect::Intersects(const wxRect& rect) const
232{
233 wxRect r = Intersect(rect);
234
235 // if there is no intersection, both width and height are 0
236 return r.width != 0;
237}
238
c50f92d0
VZ
239// ============================================================================
240// wxColourDatabase
241// ============================================================================
242
c50f92d0
VZ
243// ----------------------------------------------------------------------------
244// wxColourDatabase ctor/dtor
245// ----------------------------------------------------------------------------
222ed1d6
MB
246
247wxColourDatabase::wxColourDatabase ()
c801d85f 248{
c50f92d0
VZ
249 // will be created on demand in Initialize()
250 m_map = NULL;
c801d85f
KB
251}
252
6a6c0a8b 253wxColourDatabase::~wxColourDatabase ()
c801d85f 254{
c50f92d0
VZ
255 if ( m_map )
256 {
257 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
258
259 delete m_map;
260 }
222ed1d6 261
19bf0c69
DW
262#ifdef __WXPM__
263 delete [] m_palTable;
264#endif
c801d85f
KB
265}
266
267// Colour database stuff
c50f92d0 268void wxColourDatabase::Initialize()
c801d85f 269{
c50f92d0
VZ
270 if ( m_map )
271 {
272 // already initialized
273 return;
274 }
275
276 m_map = new wxStringToColourHashMap;
277
f6bcfd97
BP
278 static const struct wxColourDesc
279 {
280 const wxChar *name;
5c519b6c 281 unsigned char r,g,b;
f6bcfd97
BP
282 }
283 wxColourTable[] =
284 {
5e2ab1ea 285 {wxT("AQUAMARINE"),112, 219, 147},
f6bcfd97
BP
286 {wxT("BLACK"),0, 0, 0},
287 {wxT("BLUE"), 0, 0, 255},
5e2ab1ea 288 {wxT("BLUE VIOLET"), 159, 95, 159},
f6bcfd97 289 {wxT("BROWN"), 165, 42, 42},
5e2ab1ea
VZ
290 {wxT("CADET BLUE"), 95, 159, 159},
291 {wxT("CORAL"), 255, 127, 0},
292 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
f6bcfd97 293 {wxT("CYAN"), 0, 255, 255},
5e2ab1ea
VZ
294 {wxT("DARK GREY"), 47, 47, 47}, // ?
295
296 {wxT("DARK GREEN"), 47, 79, 47},
297 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
f6bcfd97 298 {wxT("DARK ORCHID"), 153, 50, 204},
5e2ab1ea 299 {wxT("DARK SLATE BLUE"), 107, 35, 142},
f6bcfd97 300 {wxT("DARK SLATE GREY"), 47, 79, 79},
5e2ab1ea
VZ
301 {wxT("DARK TURQUOISE"), 112, 147, 219},
302 {wxT("DIM GREY"), 84, 84, 84},
303 {wxT("FIREBRICK"), 142, 35, 35},
304 {wxT("FOREST GREEN"), 35, 142, 35},
305 {wxT("GOLD"), 204, 127, 50},
306 {wxT("GOLDENROD"), 219, 219, 112},
307 {wxT("GREY"), 128, 128, 128},
f6bcfd97 308 {wxT("GREEN"), 0, 255, 0},
5e2ab1ea
VZ
309 {wxT("GREEN YELLOW"), 147, 219, 112},
310 {wxT("INDIAN RED"), 79, 47, 47},
311 {wxT("KHAKI"), 159, 159, 95},
312 {wxT("LIGHT BLUE"), 191, 216, 216},
313 {wxT("LIGHT GREY"), 192, 192, 192},
314 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
315 {wxT("LIME GREEN"), 50, 204, 50},
316 {wxT("LIGHT MAGENTA"), 255, 0, 255},
f6bcfd97 317 {wxT("MAGENTA"), 255, 0, 255},
5e2ab1ea
VZ
318 {wxT("MAROON"), 142, 35, 107},
319 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
320 {wxT("MEDIUM GREY"), 100, 100, 100},
321 {wxT("MEDIUM BLUE"), 50, 50, 204},
322 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
323 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
324 {wxT("MEDIUM ORCHID"), 147, 112, 219},
325 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
326 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
327 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
328 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
329 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
330 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
331 {wxT("NAVY"), 35, 35, 142},
332 {wxT("ORANGE"), 204, 50, 50},
333 {wxT("ORANGE RED"), 255, 0, 127},
334 {wxT("ORCHID"), 219, 112, 219},
335 {wxT("PALE GREEN"), 143, 188, 143},
336 {wxT("PINK"), 188, 143, 234},
337 {wxT("PLUM"), 234, 173, 234},
338 {wxT("PURPLE"), 176, 0, 255},
f6bcfd97 339 {wxT("RED"), 255, 0, 0},
5e2ab1ea
VZ
340 {wxT("SALMON"), 111, 66, 66},
341 {wxT("SEA GREEN"), 35, 142, 107},
342 {wxT("SIENNA"), 142, 107, 35},
343 {wxT("SKY BLUE"), 50, 153, 204},
344 {wxT("SLATE BLUE"), 0, 127, 255},
f6bcfd97 345 {wxT("SPRING GREEN"), 0, 255, 127},
5e2ab1ea
VZ
346 {wxT("STEEL BLUE"), 35, 107, 142},
347 {wxT("TAN"), 219, 147, 112},
f6bcfd97 348 {wxT("THISTLE"), 216, 191, 216},
5e2ab1ea
VZ
349 {wxT("TURQUOISE"), 173, 234, 234},
350 {wxT("VIOLET"), 79, 47, 79},
351 {wxT("VIOLET RED"), 204, 50, 153},
352 {wxT("WHEAT"), 216, 216, 191},
f6bcfd97
BP
353 {wxT("WHITE"), 255, 255, 255},
354 {wxT("YELLOW"), 255, 255, 0},
aad6765c 355 {wxT("YELLOW GREEN"), 153, 204, 50}
f6bcfd97
BP
356 };
357
c50f92d0 358 size_t n;
bf2c4b94
DW
359
360 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
f6bcfd97
BP
361 {
362 const wxColourDesc& cc = wxColourTable[n];
c50f92d0 363 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
f6bcfd97 364 }
c50f92d0 365
19bf0c69
DW
366#ifdef __WXPM__
367 m_palTable = new long[n];
368 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
369 {
370 const wxColourDesc& cc = wxColourTable[n];
371 m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b);
372 }
373 m_nSize = n;
374#endif
c801d85f
KB
375}
376
c50f92d0
VZ
377// ----------------------------------------------------------------------------
378// wxColourDatabase operations
379// ----------------------------------------------------------------------------
222ed1d6 380
c50f92d0 381void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
222ed1d6 382{
c50f92d0 383 Initialize();
222ed1d6 384
c50f92d0
VZ
385 // canonicalize the colour names before using them as keys: they should be
386 // in upper case
8f520a56
MB
387 wxString colName = name;
388 colName.MakeUpper();
c50f92d0
VZ
389
390 // ... and we also allow both grey/gray
391 wxString colNameAlt = colName;
392 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
393 {
394 // but in this case it is not necessary so avoid extra search below
395 colNameAlt.clear();
396 }
8f520a56
MB
397
398 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
399 if ( it == m_map->end() && !colNameAlt.empty() )
400 it = m_map->find(colNameAlt);
8f520a56
MB
401 if ( it != m_map->end() )
402 {
c50f92d0
VZ
403 *(it->second) = colour;
404 }
405 else // new colour
406 {
5767e836 407 (*m_map)[colName] = new wxColour(colour);
8f520a56 408 }
8f520a56
MB
409}
410
c50f92d0 411wxColour wxColourDatabase::Find(const wxString& colour) const
c801d85f 412{
c50f92d0
VZ
413 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
414 self->Initialize();
415
416 // first look among the existing colours
417
418 // make the comparaison case insensitive and also match both grey and gray
f6bcfd97
BP
419 wxString colName = colour;
420 colName.MakeUpper();
c50f92d0
VZ
421 wxString colNameAlt = colName;
422 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
423 colNameAlt.clear();
f6bcfd97 424
222ed1d6 425 wxStringToColourHashMap::iterator it = m_map->find(colName);
c50f92d0
VZ
426 if ( it == m_map->end() && !colNameAlt.empty() )
427 it = m_map->find(colNameAlt);
222ed1d6 428 if ( it != m_map->end() )
c50f92d0 429 return *(it->second);
34138703 430
4e6b8309
VZ
431 // if we didn't find it, query the system, maybe it knows about it
432#if defined(__WXGTK__) || defined(__X__)
433 wxColour col = wxColour::CreateByName(colour);
8bbe427f 434
c50f92d0
VZ
435 if ( col.Ok() )
436 {
437 // cache it
438 self->AddColour(colour, col);
439 }
c801d85f 440
c50f92d0
VZ
441 return col;
442#elif defined(__X__)
4e6b8309 443 // TODO: move this to wxColour::CreateByName()
c801d85f
KB
444 XColor xcolour;
445
2049ba38 446#ifdef __WXMOTIF__
46ccb510 447 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
c801d85f 448#endif
7266b672
JS
449#ifdef __WXX11__
450 Display* display = (Display*) wxGetDisplay();
1c4a764c 451#endif
c801d85f 452 /* MATTHEW: [4] Use wxGetMainColormap */
2b5f62a0 453 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour.ToAscii() ,&xcolour))
c50f92d0 454 return NULL;
c801d85f 455
0b5c0e1a
JS
456#if wxUSE_NANOX
457 unsigned char r = (unsigned char)(xcolour.red);
458 unsigned char g = (unsigned char)(xcolour.green);
459 unsigned char b = (unsigned char)(xcolour.blue);
460#else
c801d85f
KB
461 unsigned char r = (unsigned char)(xcolour.red >> 8);
462 unsigned char g = (unsigned char)(xcolour.green >> 8);
463 unsigned char b = (unsigned char)(xcolour.blue >> 8);
0b5c0e1a 464#endif
482ee397 465
c50f92d0 466 wxColour col(r, g, b);
8f520a56 467 AddColour(colour, col);
c801d85f
KB
468
469 return col;
c50f92d0
VZ
470#else // other platform
471 return wxNullColour;
472#endif // platforms
c801d85f
KB
473}
474
c50f92d0 475wxString wxColourDatabase::FindName(const wxColour& colour) const
c801d85f 476{
c50f92d0
VZ
477 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
478 self->Initialize();
8bbe427f 479
222ed1d6
MB
480 typedef wxStringToColourHashMap::iterator iterator;
481
c50f92d0 482 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
a23fd0e1 483 {
c50f92d0 484 if ( *(it->second) == colour )
222ed1d6 485 return it->first;
a23fd0e1 486 }
c801d85f 487
222ed1d6 488 return wxEmptyString;
c801d85f
KB
489}
490
c50f92d0
VZ
491// ----------------------------------------------------------------------------
492// deprecated wxColourDatabase methods
493// ----------------------------------------------------------------------------
494
495wxColour *wxColourDatabase::FindColour(const wxString& name)
496{
98de2b68
DS
497 // This function is deprecated, use Find() instead.
498 // Formerly this function sometimes would return a deletable pointer and
499 // sometimes a non-deletable one (when returning a colour from the database).
500 // Trying to delete the latter anyway results in problems, so probably
501 // nobody ever freed the pointers. Currently it always returns a new
502 // instance, which means there will be memory leaks.
503 wxLogDebug(wxT("wxColourDataBase::FindColour():")
504 wxT(" Please use wxColourDataBase::Find() instead"));
505
492e2a5b
VZ
506 // using a static variable here is not the most elegant solution but unless
507 // we want to make wxStringToColourHashMap public (i.e. move it to the
508 // header) so that we could have a member function returning
509 // wxStringToColourHashMap::iterator, there is really no good way to do it
510 // otherwise
511 //
512 // and knowing that this function is going to disappear in the next release
513 // anyhow I don't want to waste time on this
98de2b68 514
492e2a5b
VZ
515 static wxColour s_col;
516
517 s_col = Find(name);
518 if ( !s_col.Ok() )
c50f92d0
VZ
519 return NULL;
520
98de2b68 521 return new wxColour(s_col);
c50f92d0
VZ
522}
523
524// ============================================================================
525// stock objects
526// ============================================================================
527
7ecb8b06
VZ
528void wxInitializeStockLists()
529{
1c193821 530 wxTheColourDatabase = new wxColourDatabase;
1c193821
JS
531
532 wxTheBrushList = new wxBrushList;
533 wxThePenList = new wxPenList;
534 wxTheFontList = new wxFontList;
535 wxTheBitmapList = new wxBitmapList;
a3622daa 536}
c801d85f 537
a3622daa
VZ
538void wxInitializeStockObjects ()
539{
2049ba38 540#ifdef __WXMOTIF__
c801d85f
KB
541#endif
542#ifdef __X__
46ccb510
JS
543 // TODO
544 // wxFontPool = new XFontPool;
c801d85f
KB
545#endif
546
696e1ea0 547 // why under MSW fonts shouldn't have the standard system size?
5100cabf 548/*
696e1ea0
VZ
549#ifdef __WXMSW__
550 static const int sizeFont = 10;
551#else
696e1ea0 552#endif
5100cabf 553*/
2fe57169 554#if defined(__WXMAC__)
b5c3e56d 555 // retrieve size of system font for all stock fonts
99fd0d71
SC
556 int sizeFont = 12;
557
99fd0d71
SC
558 Str255 fontName ;
559 SInt16 fontSize ;
560 Style fontStyle ;
561
5d3e7b52
WS
562 GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
563 sizeFont = fontSize ;
ca80fdee 564#ifdef __WXMAC_CLASSIC__
d0bfeea6 565 wxNORMAL_FONT = new wxFont (fontSize, wxMODERN, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal(fontName) );
b5c3e56d
SC
566#else
567 wxNORMAL_FONT = new wxFont () ;
568 wxNORMAL_FONT->MacCreateThemeFont( kThemeSystemFont );
569#endif
2fe57169 570#elif defined(__WXPM__)
5d3e7b52 571 static const int sizeFont = 12;
415ca026 572#else
5d3e7b52
WS
573 wxNORMAL_FONT = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
574 static const int sizeFont = wxNORMAL_FONT->GetPointSize();
415ca026 575#endif
696e1ea0 576
2fe57169 577#if defined(__WXPM__)
5d3e7b52
WS
578 /*
579 // Basic OS/2 has a fairly limited number of fonts and these are as good
580 // as I can do to get something that looks halfway "wx" normal
581 */
582 wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxBOLD);
583 wxSMALL_FONT = new wxFont (sizeFont - 4, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
584 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
585 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
955e5433 586#elif defined(__WXMAC__)
d0bfeea6 587 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
99fd0d71 588 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
ca80fdee 589#ifdef __WXMAC_CLASSIC__
5d3e7b52 590 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
44c44c82 591 wxSMALL_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) );
b5c3e56d
SC
592#else
593 wxSMALL_FONT = new wxFont () ;
594 wxSMALL_FONT->MacCreateThemeFont( kThemeSmallSystemFont );
595#endif
2fe57169 596#else
5d3e7b52
WS
597 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
598 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
599 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
2fe57169 600#endif
c801d85f 601
5d3e7b52
WS
602 wxRED_PEN = new wxPen (wxT("RED"), 1, wxSOLID);
603 wxCYAN_PEN = new wxPen (wxT("CYAN"), 1, wxSOLID);
604 wxGREEN_PEN = new wxPen (wxT("GREEN"), 1, wxSOLID);
605 wxBLACK_PEN = new wxPen (wxT("BLACK"), 1, wxSOLID);
606 wxWHITE_PEN = new wxPen (wxT("WHITE"), 1, wxSOLID);
607 wxTRANSPARENT_PEN = new wxPen (wxT("BLACK"), 1, wxTRANSPARENT);
608 wxBLACK_DASHED_PEN = new wxPen (wxT("BLACK"), 1, wxSHORT_DASH);
609 wxGREY_PEN = new wxPen (wxT("GREY"), 1, wxSOLID);
610 wxMEDIUM_GREY_PEN = new wxPen (wxT("MEDIUM GREY"), 1, wxSOLID);
611 wxLIGHT_GREY_PEN = new wxPen (wxT("LIGHT GREY"), 1, wxSOLID);
612
613 wxBLUE_BRUSH = new wxBrush (wxT("BLUE"), wxSOLID);
614 wxGREEN_BRUSH = new wxBrush (wxT("GREEN"), wxSOLID);
615 wxWHITE_BRUSH = new wxBrush (wxT("WHITE"), wxSOLID);
616 wxBLACK_BRUSH = new wxBrush (wxT("BLACK"), wxSOLID);
617 wxTRANSPARENT_BRUSH = new wxBrush (wxT("BLACK"), wxTRANSPARENT);
618 wxCYAN_BRUSH = new wxBrush (wxT("CYAN"), wxSOLID);
619 wxRED_BRUSH = new wxBrush (wxT("RED"), wxSOLID);
620 wxGREY_BRUSH = new wxBrush (wxT("GREY"), wxSOLID);
621 wxMEDIUM_GREY_BRUSH = new wxBrush (wxT("MEDIUM GREY"), wxSOLID);
622 wxLIGHT_GREY_BRUSH = new wxBrush (wxT("LIGHT GREY"), wxSOLID);
623
624 wxBLACK = new wxColour (wxT("BLACK"));
625 wxWHITE = new wxColour (wxT("WHITE"));
626 wxRED = new wxColour (wxT("RED"));
627 wxBLUE = new wxColour (wxT("BLUE"));
628 wxGREEN = new wxColour (wxT("GREEN"));
629 wxCYAN = new wxColour (wxT("CYAN"));
630 wxLIGHT_GREY = new wxColour (wxT("LIGHT GREY"));
631
632 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
633 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
634 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
c801d85f
KB
635}
636
8bbe427f 637void wxDeleteStockObjects ()
c801d85f 638{
5d3e7b52
WS
639 wxDELETE(wxNORMAL_FONT);
640 wxDELETE(wxSMALL_FONT);
641 wxDELETE(wxITALIC_FONT);
642 wxDELETE(wxSWISS_FONT);
643
644 wxDELETE(wxRED_PEN);
645 wxDELETE(wxCYAN_PEN);
646 wxDELETE(wxGREEN_PEN);
647 wxDELETE(wxBLACK_PEN);
648 wxDELETE(wxWHITE_PEN);
649 wxDELETE(wxTRANSPARENT_PEN);
650 wxDELETE(wxBLACK_DASHED_PEN);
651 wxDELETE(wxGREY_PEN);
652 wxDELETE(wxMEDIUM_GREY_PEN);
653 wxDELETE(wxLIGHT_GREY_PEN);
654
655 wxDELETE(wxBLUE_BRUSH);
656 wxDELETE(wxGREEN_BRUSH);
657 wxDELETE(wxWHITE_BRUSH);
658 wxDELETE(wxBLACK_BRUSH);
659 wxDELETE(wxTRANSPARENT_BRUSH);
660 wxDELETE(wxCYAN_BRUSH);
661 wxDELETE(wxRED_BRUSH);
662 wxDELETE(wxGREY_BRUSH);
663 wxDELETE(wxMEDIUM_GREY_BRUSH);
664 wxDELETE(wxLIGHT_GREY_BRUSH);
665
666 wxDELETE(wxBLACK);
667 wxDELETE(wxWHITE);
668 wxDELETE(wxRED);
669 wxDELETE(wxBLUE);
670 wxDELETE(wxGREEN);
671 wxDELETE(wxCYAN);
672 wxDELETE(wxLIGHT_GREY);
673
674 wxDELETE(wxSTANDARD_CURSOR);
675 wxDELETE(wxHOURGLASS_CURSOR);
676 wxDELETE(wxCROSS_CURSOR);
a3622daa
VZ
677}
678
7ecb8b06
VZ
679void wxDeleteStockLists()
680{
5d3e7b52
WS
681 wxDELETE(wxTheBrushList);
682 wxDELETE(wxThePenList);
683 wxDELETE(wxTheFontList);
684 wxDELETE(wxTheBitmapList);
c801d85f
KB
685}
686
7ecb8b06
VZ
687// ============================================================================
688// wxTheXXXList stuff (semi-obsolete)
689// ============================================================================
690
6a6c0a8b 691wxBitmapList::~wxBitmapList ()
c801d85f 692{
5d3e7b52
WS
693 wxList::compatibility_iterator node = GetFirst ();
694 while (node)
c801d85f 695 {
5d3e7b52
WS
696 wxBitmap *bitmap = (wxBitmap *) node->GetData ();
697 wxList::compatibility_iterator next = node->GetNext ();
698 if (bitmap->GetVisible())
699 delete bitmap;
700 node = next;
c801d85f
KB
701 }
702}
703
704// Pen and Brush lists
6a6c0a8b 705wxPenList::~wxPenList ()
c801d85f 706{
5d3e7b52
WS
707 wxList::compatibility_iterator node = GetFirst ();
708 while (node)
c801d85f 709 {
5d3e7b52
WS
710 wxPen *pen = (wxPen *) node->GetData ();
711 wxList::compatibility_iterator next = node->GetNext ();
712 if (pen->GetVisible())
713 delete pen;
714 node = next;
c801d85f
KB
715 }
716}
717
718void wxPenList::AddPen (wxPen * pen)
719{
5d3e7b52 720 Append (pen);
c801d85f
KB
721}
722
723void wxPenList::RemovePen (wxPen * pen)
724{
5d3e7b52 725 DeleteObject (pen);
c801d85f
KB
726}
727
debe6624 728wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
c801d85f 729{
222ed1d6 730 for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
13b6e335 731 {
b1d4dd7a 732 wxPen *each_pen = (wxPen *) node->GetData ();
13b6e335
VZ
733 if (each_pen &&
734 each_pen->GetVisible() &&
735 each_pen->GetWidth () == width &&
736 each_pen->GetStyle () == style &&
737 each_pen->GetColour ().Red () == colour.Red () &&
738 each_pen->GetColour ().Green () == colour.Green () &&
739 each_pen->GetColour ().Blue () == colour.Blue ())
740 return each_pen;
741 }
742
743 wxPen *pen = new wxPen (colour, width, style);
744 if ( !pen->Ok() )
c801d85f 745 {
13b6e335
VZ
746 // don't save the invalid pens in the list
747 delete pen;
748
749 return NULL;
c801d85f 750 }
c801d85f 751
7ecb8b06
VZ
752 AddPen(pen);
753
754 // we'll delete it ourselves later
5d3e7b52 755 pen->SetVisible(true);
6d167489 756
13b6e335 757 return pen;
c801d85f
KB
758}
759
6a6c0a8b 760wxBrushList::~wxBrushList ()
c801d85f 761{
5d3e7b52
WS
762 wxList::compatibility_iterator node = GetFirst ();
763 while (node)
c801d85f 764 {
5d3e7b52
WS
765 wxBrush *brush = (wxBrush *) node->GetData ();
766 wxList::compatibility_iterator next = node->GetNext ();
767 if (brush && brush->GetVisible())
768 delete brush;
769 node = next;
c801d85f
KB
770 }
771}
772
773void wxBrushList::AddBrush (wxBrush * brush)
774{
5d3e7b52 775 Append (brush);
c801d85f
KB
776}
777
debe6624 778wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
c801d85f 779{
222ed1d6 780 for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
c801d85f 781 {
b1d4dd7a 782 wxBrush *each_brush = (wxBrush *) node->GetData ();
13b6e335
VZ
783 if (each_brush &&
784 each_brush->GetVisible() &&
785 each_brush->GetStyle () == style &&
786 each_brush->GetColour ().Red () == colour.Red () &&
787 each_brush->GetColour ().Green () == colour.Green () &&
788 each_brush->GetColour ().Blue () == colour.Blue ())
789 return each_brush;
c801d85f 790 }
6d167489 791
13b6e335
VZ
792 wxBrush *brush = new wxBrush (colour, style);
793
794 if ( !brush->Ok() )
795 {
796 // don't put the brushes we failed to create into the list
797 delete brush;
798
799 return NULL;
800 }
6d167489 801
7ecb8b06
VZ
802 AddBrush(brush);
803
804 // we'll delete it ourselves later
5d3e7b52 805 brush->SetVisible(true);
6d167489 806
13b6e335 807 return brush;
c801d85f
KB
808}
809
c801d85f
KB
810void wxBrushList::RemoveBrush (wxBrush * brush)
811{
5d3e7b52 812 DeleteObject (brush);
c801d85f
KB
813}
814
6a6c0a8b 815wxFontList::~wxFontList ()
c801d85f 816{
222ed1d6 817 wxList::compatibility_iterator node = GetFirst ();
6d167489 818 while (node)
c801d85f 819 {
6d167489
VZ
820 // Only delete objects that are 'visible', i.e.
821 // that have been created using FindOrCreate...,
822 // where the pointers are expected to be shared
823 // (and therefore not deleted by any one part of an app).
b1d4dd7a 824 wxFont *font = (wxFont *) node->GetData ();
222ed1d6 825 wxList::compatibility_iterator next = node->GetNext ();
6d167489
VZ
826 if (font->GetVisible())
827 delete font;
828 node = next;
829 }
c801d85f
KB
830}
831
832void wxFontList::AddFont (wxFont * font)
833{
5d3e7b52 834 Append (font);
c801d85f
KB
835}
836
837void wxFontList::RemoveFont (wxFont * font)
838{
5d3e7b52 839 DeleteObject (font);
c801d85f
KB
840}
841
f6bcfd97
BP
842wxFont *wxFontList::FindOrCreateFont(int pointSize,
843 int family,
844 int style,
845 int weight,
846 bool underline,
847 const wxString& facename,
848 wxFontEncoding encoding)
c801d85f 849{
f6bcfd97 850 wxFont *font = (wxFont *)NULL;
222ed1d6 851 wxList::compatibility_iterator node;
b1d4dd7a 852 for ( node = GetFirst(); node; node = node->GetNext() )
c801d85f 853 {
b1d4dd7a 854 font = (wxFont *)node->GetData();
f6bcfd97
BP
855 if ( font->GetVisible() &&
856 font->Ok() &&
857 font->GetPointSize () == pointSize &&
858 font->GetStyle () == style &&
859 font->GetWeight () == weight &&
860 font->GetUnderlined () == underline )
861 {
862 int fontFamily = font->GetFamily();
863
619d0528 864#if defined(__WXGTK__)
f6bcfd97
BP
865 // under GTK the default family is wxSWISS, so looking for a font
866 // with wxDEFAULT family should return a wxSWISS one instead of
867 // creating a new one
868 bool same = (fontFamily == family) ||
869 (fontFamily == wxSWISS && family == wxDEFAULT);
870#else // !GTK
871 // VZ: but why elsewhere do we require an exact match? mystery...
872 bool same = fontFamily == family;
873#endif // GTK/!GTK
874
875 // empty facename matches anything at all: this is bad because
876 // depending on which fonts are already created, we might get back
877 // a different font if we create it with empty facename, but it is
878 // still better than never matching anything in the cache at all
879 // in this case
8d8fbb9d 880 if ( same && !facename.empty() )
f6bcfd97
BP
881 {
882 const wxString& fontFace = font->GetFaceName();
883
884 // empty facename matches everything
885 same = !fontFace || fontFace == facename;
886 }
887
888 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
889 {
890 // have to match the encoding too
891 same = font->GetEncoding() == encoding;
892 }
893
894 if ( same )
895 {
896 return font;
897 }
898 }
c801d85f 899 }
6d167489 900
f6bcfd97
BP
901 if ( !node )
902 {
903 // font not found, create the new one
904 font = new wxFont(pointSize, family, style, weight,
905 underline, facename, encoding);
906
7ecb8b06
VZ
907 AddFont(font);
908
f6bcfd97 909 // and mark it as being cacheable
5d3e7b52 910 font->SetVisible(true);
f6bcfd97 911 }
6d167489 912
f6bcfd97 913 return font;
c801d85f
KB
914}
915
916void wxBitmapList::AddBitmap(wxBitmap *bitmap)
8bbe427f
VZ
917{
918 Append(bitmap);
919}
920
c801d85f 921void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
8bbe427f
VZ
922{
923 DeleteObject(bitmap);
924}
c801d85f 925
6a6c0a8b
JS
926wxSize wxGetDisplaySize()
927{
928 int x, y;
929 wxDisplaySize(& x, & y);
930 return wxSize(x, y);
931}
932
ec5d7799
RD
933wxRect wxGetClientDisplayRect()
934{
935 int x, y, width, height;
936 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
937 return wxRect(x, y, width, height);
938}
939
904a68b6
RL
940wxSize wxGetDisplaySizeMM()
941{
942 int x, y;
943 wxDisplaySizeMM(& x, & y);
944 return wxSize(x, y);
945}
946
8bbe427f
VZ
947wxResourceCache::~wxResourceCache ()
948{
222ed1d6 949 wxList::compatibility_iterator node = GetFirst ();
f6bcfd97 950 while (node) {
b1d4dd7a 951 wxObject *item = (wxObject *)node->GetData();
f6bcfd97 952 delete item;
a3622daa 953
b1d4dd7a 954 node = node->GetNext ();
a3622daa 955 }
a3622daa
VZ
956}
957