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