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