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