]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
somebody added #ifdefed #pragma to disable warnings about // in c source, instead...
[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
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
2432b92d 23#include "wx/event.h"
c801d85f
KB
24#include "wx/gdicmn.h"
25#include "wx/brush.h"
26#include "wx/pen.h"
27#include "wx/bitmap.h"
28#include "wx/icon.h"
29#include "wx/cursor.h"
30#include "wx/font.h"
31#include "wx/palette.h"
46ccb510 32#include "wx/app.h"
b0e0d661 33#include "wx/dc.h"
b93d0c64 34#include "wx/utils.h"
c801d85f 35
cb38104e 36#include "wx/log.h"
c801d85f
KB
37#include <string.h>
38
2049ba38 39#ifdef __WXMSW__
c801d85f
KB
40#include <windows.h>
41#endif
42
46ccb510 43#ifdef __WXMOTIF__
338dd992
JJ
44#ifdef __VMS__
45#pragma message disable nosimpint
46#endif
46ccb510 47#include <Xm/Xm.h>
338dd992
JJ
48#ifdef __VMS__
49#pragma message enable nosimpint
50#endif
46ccb510
JS
51#endif
52
a23fd0e1
VZ
53 IMPLEMENT_CLASS(wxColourDatabase, wxList)
54 IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
55 IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
56 IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
57 IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
58 IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList)
59
60 IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
c801d85f 61
c801d85f
KB
62wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight)
63{
64 x = topLeft.x;
65 y = topLeft.y;
66 width = bottomRight.x - topLeft.x;
67 height = bottomRight.y - topLeft.y;
8bbe427f 68
c801d85f
KB
69 if (width < 0)
70 {
71 width = -width;
72 x -= width;
73 }
8bbe427f 74
c801d85f
KB
75 if (height < 0)
76 {
77 height = -height;
3e418ffc 78 y -= height;
c801d85f
KB
79 }
80}
81
82wxRect::wxRect(const wxPoint& point, const wxSize& size)
83{
84 x = point.x; y = point.y;
85 width = size.x; height = size.y;
86}
87
a23fd0e1 88bool wxRect::operator==(const wxRect& rect) const
c801d85f
KB
89{
90 return ((x == rect.x) &&
91 (y == rect.y) &&
92 (width == rect.width) &&
93 (height == rect.height));
94}
95
dcb44466 96const wxRect& wxRect::operator += (const wxRect& rect)
619d0528
RD
97{
98 *this = (*this + rect);
dcb44466
JS
99 return ( *this ) ;
100}
101
102wxRect wxRect::operator + (const wxRect& rect) const
619d0528 103{
b93d0c64
JS
104 int x1 = wxMin(this->x, rect.x);
105 int y1 = wxMin(this->y, rect.y);
106 int y2 = wxMax(y+height, rect.height+rect.y);
107 int x2 = wxMax(x+width, rect.width+rect.x);
dcb44466
JS
108 return wxRect(x1, y1, x2-x1, y2-y1);
109}
110
111bool wxRect::Inside(int cx, int cy) const
112{
113 return ( (cx >= x) && (cy >= y)
114 && ((cy - y) < height)
115 && ((cx - x) < width)
116 );
117}
118
a23fd0e1 119wxColourDatabase::wxColourDatabase (int type) : wxList (type)
c801d85f
KB
120{
121}
122
6a6c0a8b 123wxColourDatabase::~wxColourDatabase ()
c801d85f
KB
124{
125 // Cleanup Colour allocated in Initialize()
126 wxNode *node = First ();
127 while (node)
128 {
129 wxColour *col = (wxColour *) node->Data ();
130 wxNode *next = node->Next ();
131 delete col;
132 node = next;
133 }
134}
135
136// Colour database stuff
6a6c0a8b 137void wxColourDatabase::Initialize ()
c801d85f
KB
138{
139 // Don't initialize for X: colours are found
140 // in FindColour below.
141 // Added: Not all
8bbe427f 142
c801d85f 143 struct cdef {
50920146 144 wxChar *name;
c801d85f
KB
145 int r,g,b;
146 };
147 cdef cc;
148 static cdef table[]={
8bbe427f 149
66bd6b93 150// #ifdef __WXMSW__
223d09f6
KB
151 {wxT("AQUAMARINE"),112, 219, 147},
152 {wxT("BLACK"),0, 0, 0},
153 {wxT("BLUE"), 0, 0, 255},
154 {wxT("BLUE VIOLET"), 159, 95, 159},
155 {wxT("BROWN"), 165, 42, 42},
156 {wxT("CADET BLUE"), 95, 159, 159},
157 {wxT("CORAL"), 255, 127, 0},
158 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
159 {wxT("CYAN"), 0, 255, 255},
160 {wxT("DARK GREY"), 47, 47, 47}, // ?
161
162 {wxT("DARK GREEN"), 47, 79, 47},
163 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
164 {wxT("DARK ORCHID"), 153, 50, 204},
165 {wxT("DARK SLATE BLUE"), 107, 35, 142},
166 {wxT("DARK SLATE GREY"), 47, 79, 79},
167 {wxT("DARK TURQUOISE"), 112, 147, 219},
168 {wxT("DIM GREY"), 84, 84, 84},
169 {wxT("FIREBRICK"), 142, 35, 35},
170 {wxT("FOREST GREEN"), 35, 142, 35},
171 {wxT("GOLD"), 204, 127, 50},
172 {wxT("GOLDENROD"), 219, 219, 112},
173 {wxT("GREY"), 128, 128, 128},
174 {wxT("GREEN"), 0, 255, 0},
175 {wxT("GREEN YELLOW"), 147, 219, 112},
176 {wxT("INDIAN RED"), 79, 47, 47},
177 {wxT("KHAKI"), 159, 159, 95},
178 {wxT("LIGHT BLUE"), 191, 216, 216},
179 {wxT("LIGHT GREY"), 192, 192, 192},
180 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
181 {wxT("LIME GREEN"), 50, 204, 50},
182 {wxT("LIGHT MAGENTA"), 255, 0, 255},
183 {wxT("MAGENTA"), 255, 0, 255},
184 {wxT("MAROON"), 142, 35, 107},
185 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
186 {wxT("MEDIUM GREY"), 100, 100, 100},
187 {wxT("MEDIUM BLUE"), 50, 50, 204},
188 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
189 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
190 {wxT("MEDIUM ORCHID"), 147, 112, 219},
191 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
192 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
193 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
194 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
195 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
196 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
197 {wxT("NAVY"), 35, 35, 142},
198 {wxT("ORANGE"), 204, 50, 50},
199 {wxT("ORANGE RED"), 255, 0, 127},
200 {wxT("ORCHID"), 219, 112, 219},
201 {wxT("PALE GREEN"), 143, 188, 143},
202 {wxT("PINK"), 188, 143, 234},
203 {wxT("PLUM"), 234, 173, 234},
204 {wxT("PURPLE"), 176, 0, 255},
205 {wxT("RED"), 255, 0, 0},
206 {wxT("SALMON"), 111, 66, 66},
207 {wxT("SEA GREEN"), 35, 142, 107},
208 {wxT("SIENNA"), 142, 107, 35},
209 {wxT("SKY BLUE"), 50, 153, 204},
210 {wxT("SLATE BLUE"), 0, 127, 255},
211 {wxT("SPRING GREEN"), 0, 255, 127},
212 {wxT("STEEL BLUE"), 35, 107, 142},
213 {wxT("TAN"), 219, 147, 112},
214 {wxT("THISTLE"), 216, 191, 216},
215 {wxT("TURQUOISE"), 173, 234, 234},
216 {wxT("VIOLET"), 79, 47, 79},
217 {wxT("VIOLET RED"), 204, 50, 153},
218 {wxT("WHEAT"), 216, 216, 191},
219 {wxT("WHITE"), 255, 255, 255},
220 {wxT("YELLOW"), 255, 255, 0},
221 {wxT("YELLOW GREEN"), 153, 204, 50},
66bd6b93 222// #endif
c801d85f 223
2049ba38 224#if defined(__WXGTK__) || defined(__X__)
223d09f6
KB
225 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
226 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
227 {wxT("LIGHT MAGENTA"), 255, 0, 255},
228 {wxT("MEDIUM GREY"), 100, 100, 100},
c801d85f 229#endif
8bbe427f 230
c801d85f
KB
231 {0,0,0,0}
232 };
233 int i;
234 for (i=0;cc=table[i],cc.name!=0;i++)
235 {
236 Append(cc.name,new wxColour(cc.r,cc.g,cc.b));
237 }
238
239}
240
241/*
242 * Changed by Ian Brown, July 1994.
243 *
244 * When running under X, the Colour Database starts off empty. The X server
245 * is queried for the colour first time after which it is entered into the
246 * database. This allows our client to use the server colour database which
247 * is hopefully gamma corrected for the display being used.
248 */
249
250wxColour *wxColourDatabase::FindColour(const wxString& colour)
251{
1c4a764c
VZ
252 // VZ: make the comparaison case insensitive
253 wxString str = colour;
254 str.MakeUpper();
255
256 wxNode *node = Find(str);
c801d85f
KB
257 if (node)
258 return (wxColour *)node->Data();
8bbe427f 259
2049ba38 260#ifdef __WXMSW__
c801d85f
KB
261 else return NULL;
262#endif
913df6f2
DW
263#ifdef __WXPM__
264 else return NULL;
265#endif
c801d85f 266
34138703
JS
267// TODO for other implementations. This should really go into
268// platform-specific directories.
169935ad
SC
269#ifdef __WXMAC__
270 else return NULL;
271#endif
34138703
JS
272#ifdef __WXSTUBS__
273 else return NULL;
274#endif
275
2049ba38 276#ifdef __WXGTK__
c801d85f
KB
277 else {
278 wxColour *col = new wxColour( colour );
8bbe427f 279
c801d85f
KB
280 if (!(col->Ok())) {
281 delete col;
c67daf87 282 return (wxColour *) NULL;
c801d85f
KB
283 }
284 Append( colour, col );
285 return col;
286 }
287#endif
288
289#ifdef __X__
290 else {
291 XColor xcolour;
292
2049ba38 293#ifdef __WXMOTIF__
46ccb510 294 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
c801d85f 295#endif
1c4a764c
VZ
296#ifdef __XVIEW__
297 Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
298 Xv_opaque root_window = xv_get(screen, XV_ROOT);
299 Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
300#endif
c801d85f
KB
301
302 /* MATTHEW: [4] Use wxGetMainColormap */
46ccb510 303 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))
c801d85f
KB
304 return NULL;
305
306 unsigned char r = (unsigned char)(xcolour.red >> 8);
307 unsigned char g = (unsigned char)(xcolour.green >> 8);
308 unsigned char b = (unsigned char)(xcolour.blue >> 8);
309
310 wxColour *col = new wxColour(r, g, b);
311 Append(colour, col);
312
313 return col;
314 }
315#endif
316}
317
318wxString wxColourDatabase::FindName (const wxColour& colour) const
319{
a23fd0e1 320 wxString name;
8bbe427f 321
a23fd0e1
VZ
322 unsigned char red = colour.Red ();
323 unsigned char green = colour.Green ();
324 unsigned char blue = colour.Blue ();
8bbe427f 325
a23fd0e1
VZ
326 for (wxNode * node = First (); node; node = node->Next ())
327 {
328 wxColour *col = (wxColour *) node->Data ();
329
330 if (col->Red () == red && col->Green () == green && col->Blue () == blue)
8bbe427f 331 {
a23fd0e1
VZ
332 const wxChar *found = node->GetKeyString();
333 if ( found )
334 {
335 name = found;
336
337 break;
338 }
8bbe427f 339 }
a23fd0e1 340 }
c801d85f 341
a23fd0e1 342 return name;
c801d85f
KB
343}
344
a3622daa 345void wxInitializeStockLists () {
c801d85f
KB
346 wxTheBrushList = new wxBrushList;
347 wxThePenList = new wxPenList;
348 wxTheFontList = new wxFontList;
349 wxTheBitmapList = new wxBitmapList;
a3622daa 350}
c801d85f 351
a3622daa
VZ
352void wxInitializeStockObjects ()
353{
2049ba38 354#ifdef __WXMOTIF__
c801d85f
KB
355#endif
356#ifdef __X__
46ccb510
JS
357 // TODO
358 // wxFontPool = new XFontPool;
c801d85f
KB
359#endif
360
696e1ea0
VZ
361 // why under MSW fonts shouldn't have the standard system size?
362#ifdef __WXMSW__
363 static const int sizeFont = 10;
364#else
365 static const int sizeFont = 12;
366#endif
367
368 wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL);
369 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
370 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
371 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
c801d85f
KB
372
373 wxRED_PEN = new wxPen ("RED", 1, wxSOLID);
374 wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID);
375 wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID);
376 wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID);
377 wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID);
378 wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT);
379 wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH);
380 wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID);
381 wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID);
382 wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID);
383
384 wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID);
385 wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID);
386 wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID);
387 wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID);
388 wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT);
389 wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID);
390 wxRED_BRUSH = new wxBrush ("RED", wxSOLID);
391 wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID);
392 wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID);
393 wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID);
394
395 wxBLACK = new wxColour ("BLACK");
396 wxWHITE = new wxColour ("WHITE");
397 wxRED = new wxColour ("RED");
398 wxBLUE = new wxColour ("BLUE");
399 wxGREEN = new wxColour ("GREEN");
400 wxCYAN = new wxColour ("CYAN");
401 wxLIGHT_GREY = new wxColour ("LIGHT GREY");
402
403 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
404 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
405 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
406}
407
8bbe427f 408void wxDeleteStockObjects ()
c801d85f 409{
a3622daa
VZ
410 wxDELETE(wxNORMAL_FONT);
411 wxDELETE(wxSMALL_FONT);
412 wxDELETE(wxITALIC_FONT);
413 wxDELETE(wxSWISS_FONT);
414
415 wxDELETE(wxRED_PEN);
416 wxDELETE(wxCYAN_PEN);
417 wxDELETE(wxGREEN_PEN);
418 wxDELETE(wxBLACK_PEN);
419 wxDELETE(wxWHITE_PEN);
420 wxDELETE(wxTRANSPARENT_PEN);
421 wxDELETE(wxBLACK_DASHED_PEN);
422 wxDELETE(wxGREY_PEN);
423 wxDELETE(wxMEDIUM_GREY_PEN);
424 wxDELETE(wxLIGHT_GREY_PEN);
425
426 wxDELETE(wxBLUE_BRUSH);
427 wxDELETE(wxGREEN_BRUSH);
428 wxDELETE(wxWHITE_BRUSH);
429 wxDELETE(wxBLACK_BRUSH);
430 wxDELETE(wxTRANSPARENT_BRUSH);
431 wxDELETE(wxCYAN_BRUSH);
432 wxDELETE(wxRED_BRUSH);
433 wxDELETE(wxGREY_BRUSH);
434 wxDELETE(wxMEDIUM_GREY_BRUSH);
435 wxDELETE(wxLIGHT_GREY_BRUSH);
436
437 wxDELETE(wxBLACK);
438 wxDELETE(wxWHITE);
439 wxDELETE(wxRED);
440 wxDELETE(wxBLUE);
441 wxDELETE(wxGREEN);
442 wxDELETE(wxCYAN);
443 wxDELETE(wxLIGHT_GREY);
444
445 wxDELETE(wxSTANDARD_CURSOR);
446 wxDELETE(wxHOURGLASS_CURSOR);
447 wxDELETE(wxCROSS_CURSOR);
448}
449
450void wxDeleteStockLists() {
451 wxDELETE(wxTheBrushList);
452 wxDELETE(wxThePenList);
453 wxDELETE(wxTheFontList);
454 wxDELETE(wxTheBitmapList);
c801d85f
KB
455}
456
6a6c0a8b 457wxBitmapList::wxBitmapList ()
c801d85f
KB
458{
459}
460
6a6c0a8b 461wxBitmapList::~wxBitmapList ()
c801d85f
KB
462{
463 wxNode *node = First ();
464 while (node)
465 {
466 wxBitmap *bitmap = (wxBitmap *) node->Data ();
467 wxNode *next = node->Next ();
4c444f19
JS
468 if (bitmap->GetVisible())
469 delete bitmap;
c801d85f
KB
470 node = next;
471 }
472}
473
474// Pen and Brush lists
6a6c0a8b 475wxPenList::~wxPenList ()
c801d85f
KB
476{
477 wxNode *node = First ();
478 while (node)
479 {
480 wxPen *pen = (wxPen *) node->Data ();
481 wxNode *next = node->Next ();
4c444f19
JS
482 if (pen->GetVisible())
483 delete pen;
c801d85f
KB
484 node = next;
485 }
486}
487
488void wxPenList::AddPen (wxPen * pen)
489{
490 Append (pen);
491}
492
493void wxPenList::RemovePen (wxPen * pen)
494{
495 DeleteObject (pen);
496}
497
debe6624 498wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
c801d85f
KB
499{
500 for (wxNode * node = First (); node; node = node->Next ())
501 {
502 wxPen *each_pen = (wxPen *) node->Data ();
6d167489
VZ
503 if (each_pen &&
504 each_pen->GetVisible() &&
8bbe427f
VZ
505 each_pen->GetWidth () == width &&
506 each_pen->GetStyle () == style &&
507 each_pen->GetColour ().Red () == colour.Red () &&
508 each_pen->GetColour ().Green () == colour.Green () &&
509 each_pen->GetColour ().Blue () == colour.Blue ())
510 return each_pen;
c801d85f
KB
511 }
512 wxPen *pen = new wxPen (colour, width, style);
513
514 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
515 // because we created it within FindOrCreatePen. Safeguards against
516 // returning a pointer to an automatic variable and hanging on to it
517 // (dangling pointer).
518 pen->SetVisible(TRUE);
6d167489 519
c801d85f
KB
520 return pen;
521}
522
6a6c0a8b 523wxBrushList::~wxBrushList ()
c801d85f
KB
524{
525 wxNode *node = First ();
526 while (node)
527 {
528 wxBrush *brush = (wxBrush *) node->Data ();
529 wxNode *next = node->Next ();
4c444f19
JS
530 if (brush->GetVisible())
531 delete brush;
c801d85f
KB
532 node = next;
533 }
534}
535
536void wxBrushList::AddBrush (wxBrush * brush)
537{
538 Append (brush);
539}
540
debe6624 541wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
c801d85f
KB
542{
543 for (wxNode * node = First (); node; node = node->Next ())
544 {
545 wxBrush *each_brush = (wxBrush *) node->Data ();
6d167489
VZ
546 if (each_brush &&
547 each_brush->GetVisible() &&
8bbe427f
VZ
548 each_brush->GetStyle () == style &&
549 each_brush->GetColour ().Red () == colour.Red () &&
550 each_brush->GetColour ().Green () == colour.Green () &&
551 each_brush->GetColour ().Blue () == colour.Blue ())
552 return each_brush;
c801d85f 553 }
6d167489 554
c801d85f
KB
555 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
556 // because we created it within FindOrCreateBrush. Safeguards against
557 // returning a pointer to an automatic variable and hanging on to it
558 // (dangling pointer).
559 wxBrush *brush = new wxBrush (colour, style);
6d167489 560
c801d85f 561 brush->SetVisible(TRUE);
6d167489 562
c801d85f
KB
563 return brush;
564}
565
c801d85f
KB
566void wxBrushList::RemoveBrush (wxBrush * brush)
567{
568 DeleteObject (brush);
569}
570
6a6c0a8b 571wxFontList::~wxFontList ()
c801d85f 572{
6d167489
VZ
573 wxNode *node = First ();
574 while (node)
c801d85f 575 {
6d167489
VZ
576 // Only delete objects that are 'visible', i.e.
577 // that have been created using FindOrCreate...,
578 // where the pointers are expected to be shared
579 // (and therefore not deleted by any one part of an app).
580 wxFont *font = (wxFont *) node->Data ();
581 wxNode *next = node->Next ();
582 if (font->GetVisible())
583 delete font;
584 node = next;
585 }
c801d85f
KB
586}
587
588void wxFontList::AddFont (wxFont * font)
589{
590 Append (font);
591}
592
593void wxFontList::RemoveFont (wxFont * font)
594{
595 DeleteObject (font);
596}
597
598wxFont *wxFontList::
37bebc11 599 FindOrCreateFont (int PointSize, int FamilyOrFontId, int Style, int Weight, bool underline, const wxString& Face, wxFontEncoding encoding)
c801d85f
KB
600{
601 for (wxNode * node = First (); node; node = node->Next ())
602 {
603 wxFont *each_font = (wxFont *) node->Data ();
6d167489
VZ
604 if (each_font &&
605 each_font->GetVisible() &&
606 each_font->Ok() &&
8bbe427f
VZ
607 each_font->GetPointSize () == PointSize &&
608 each_font->GetStyle () == Style &&
609 each_font->GetWeight () == Weight &&
610 each_font->GetUnderlined () == underline &&
619d0528
RD
611#if defined(__WXGTK__)
612 (each_font->GetFamily() == FamilyOrFontId ||
6d167489 613 (each_font->GetFamily() == wxSWISS && FamilyOrFontId == wxDEFAULT)) &&
619d0528
RD
614#else
615 each_font->GetFamily() == FamilyOrFontId &&
616#endif
37bebc11
RD
617 ((each_font->GetFaceName() == wxT("")) || each_font->GetFaceName() == Face) &&
618 (encoding == wxFONTENCODING_DEFAULT || each_font->GetEncoding() == encoding))
8bbe427f 619 return each_font;
c801d85f 620 }
37bebc11 621 wxFont *font = new wxFont (PointSize, FamilyOrFontId, Style, Weight, underline, Face, encoding);
6d167489 622
c801d85f 623 font->SetVisible(TRUE);
6d167489 624
c801d85f
KB
625 return font;
626}
627
628void wxBitmapList::AddBitmap(wxBitmap *bitmap)
8bbe427f
VZ
629{
630 Append(bitmap);
631}
632
c801d85f 633void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
8bbe427f
VZ
634{
635 DeleteObject(bitmap);
636}
c801d85f 637
6a6c0a8b
JS
638wxSize wxGetDisplaySize()
639{
640 int x, y;
641 wxDisplaySize(& x, & y);
642 return wxSize(x, y);
643}
644
8bbe427f
VZ
645wxResourceCache::~wxResourceCache ()
646{
a3622daa
VZ
647 wxNode *node = First ();
648 while (node) {
649 wxGDIObject *item = (wxGDIObject *)node->Data();
650 if (item->IsKindOf(CLASSINFO(wxBrush))) {
651 wxBrush *brush = (wxBrush *)item;
652 delete brush;
653 }
654
655 if (item->IsKindOf(CLASSINFO(wxFont))) {
656 wxFont *font = (wxFont *)item;
657 delete font;
658 }
659
660 if (item->IsKindOf(CLASSINFO(wxBitmap))) {
661 wxBitmap *bitmap = (wxBitmap *)item;
662 delete bitmap;
663 }
664
665 if (item->IsKindOf(CLASSINFO(wxColour))) {
666 wxColour *colour = (wxColour *)item;
667 delete colour;
668 }
669
670 wxNode *next = node->Next ();
671 node = next;
672 }
673}
674