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