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