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