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