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