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