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