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