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