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