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