]> git.saurik.com Git - wxWidgets.git/blame - src/common/gdicmn.cpp
added automatic growing of in-place wxTextCtrls for generic wxListCtrl and wxTreeCtrl
[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
116bool wxRect::Inside(int cx, int cy) const
117{
45816ddd
VZ
118 return ( (cx >= x) && (cy >= y)
119 && ((cy - y) < height)
120 && ((cx - x) < width)
121 );
dcb44466
JS
122}
123
a23fd0e1 124wxColourDatabase::wxColourDatabase (int type) : wxList (type)
c801d85f
KB
125{
126}
127
6a6c0a8b 128wxColourDatabase::~wxColourDatabase ()
c801d85f
KB
129{
130 // Cleanup Colour allocated in Initialize()
131 wxNode *node = First ();
132 while (node)
133 {
134 wxColour *col = (wxColour *) node->Data ();
135 wxNode *next = node->Next ();
136 delete col;
137 node = next;
138 }
139}
140
141// Colour database stuff
6a6c0a8b 142void wxColourDatabase::Initialize ()
c801d85f 143{
f6bcfd97
BP
144 static const struct wxColourDesc
145 {
146 const wxChar *name;
147 int r,g,b;
148 }
149 wxColourTable[] =
150 {
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},
222 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
223 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
224 {wxT("LIGHT MAGENTA"), 255, 0, 255},
225 {wxT("MEDIUM GREY"), 100, 100, 100},
226 };
227
228 for ( size_t n = 0; n < WXSIZEOF(wxColourTable); n++ )
229 {
230 const wxColourDesc& cc = wxColourTable[n];
231 Append(cc.name, new wxColour(cc.r,cc.g,cc.b));
232 }
c801d85f
KB
233}
234
235/*
236 * Changed by Ian Brown, July 1994.
237 *
238 * When running under X, the Colour Database starts off empty. The X server
239 * is queried for the colour first time after which it is entered into the
240 * database. This allows our client to use the server colour database which
241 * is hopefully gamma corrected for the display being used.
242 */
243
244wxColour *wxColourDatabase::FindColour(const wxString& colour)
245{
f6bcfd97
BP
246 // VZ: make the comparaison case insensitive and also match both grey and
247 // gray
248 wxString colName = colour;
249 colName.MakeUpper();
250 wxString colName2 = colName;
251 if ( !colName2.Replace(_T("GRAY"), _T("GREY")) )
252 colName2.clear();
253
254 wxNode *node = First();
255 while ( node )
256 {
257 const wxChar *key = node->GetKeyString();
258 if ( colName == key || colName2 == key )
259 {
260 return (wxColour *)node->Data();
261 }
1c4a764c 262
f6bcfd97
BP
263 node = node->Next();
264 }
8bbe427f 265
2049ba38 266#ifdef __WXMSW__
f6bcfd97 267 return NULL;
c801d85f 268#endif
913df6f2 269#ifdef __WXPM__
f6bcfd97 270 return NULL;
913df6f2 271#endif
c801d85f 272
34138703
JS
273// TODO for other implementations. This should really go into
274// platform-specific directories.
169935ad 275#ifdef __WXMAC__
f6bcfd97 276 return NULL;
169935ad 277#endif
34138703 278#ifdef __WXSTUBS__
f6bcfd97 279 return NULL;
34138703
JS
280#endif
281
2049ba38 282#ifdef __WXGTK__
f6bcfd97 283 wxColour *col = new wxColour( colour );
8bbe427f 284
f6bcfd97 285 if (!(col->Ok())) {
c801d85f 286 delete col;
c67daf87 287 return (wxColour *) NULL;
c801d85f 288 }
f6bcfd97
BP
289 Append( colour, col );
290 return col;
c801d85f
KB
291#endif
292
293#ifdef __X__
c801d85f
KB
294 XColor xcolour;
295
2049ba38 296#ifdef __WXMOTIF__
46ccb510 297 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
c801d85f 298#endif
1c4a764c
VZ
299#ifdef __XVIEW__
300 Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
301 Xv_opaque root_window = xv_get(screen, XV_ROOT);
302 Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
303#endif
c801d85f
KB
304
305 /* MATTHEW: [4] Use wxGetMainColormap */
46ccb510 306 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))
c801d85f
KB
307 return NULL;
308
309 unsigned char r = (unsigned char)(xcolour.red >> 8);
310 unsigned char g = (unsigned char)(xcolour.green >> 8);
311 unsigned char b = (unsigned char)(xcolour.blue >> 8);
312
313 wxColour *col = new wxColour(r, g, b);
314 Append(colour, col);
315
316 return col;
f6bcfd97 317#endif // __X__
c801d85f
KB
318}
319
320wxString wxColourDatabase::FindName (const wxColour& colour) const
321{
a23fd0e1 322 wxString name;
8bbe427f 323
a23fd0e1
VZ
324 unsigned char red = colour.Red ();
325 unsigned char green = colour.Green ();
326 unsigned char blue = colour.Blue ();
8bbe427f 327
a23fd0e1
VZ
328 for (wxNode * node = First (); node; node = node->Next ())
329 {
330 wxColour *col = (wxColour *) node->Data ();
331
332 if (col->Red () == red && col->Green () == green && col->Blue () == blue)
8bbe427f 333 {
a23fd0e1
VZ
334 const wxChar *found = node->GetKeyString();
335 if ( found )
336 {
337 name = found;
338
339 break;
340 }
8bbe427f 341 }
a23fd0e1 342 }
c801d85f 343
a23fd0e1 344 return name;
c801d85f
KB
345}
346
a3622daa 347void wxInitializeStockLists () {
c801d85f
KB
348 wxTheBrushList = new wxBrushList;
349 wxThePenList = new wxPenList;
350 wxTheFontList = new wxFontList;
351 wxTheBitmapList = new wxBitmapList;
a3622daa 352}
c801d85f 353
a3622daa
VZ
354void wxInitializeStockObjects ()
355{
2049ba38 356#ifdef __WXMOTIF__
c801d85f
KB
357#endif
358#ifdef __X__
46ccb510
JS
359 // TODO
360 // wxFontPool = new XFontPool;
c801d85f
KB
361#endif
362
696e1ea0 363 // why under MSW fonts shouldn't have the standard system size?
5100cabf 364/*
696e1ea0
VZ
365#ifdef __WXMSW__
366 static const int sizeFont = 10;
367#else
368 static const int sizeFont = 12;
369#endif
5100cabf
JS
370*/
371
372// wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL);
373 wxNORMAL_FONT = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
374 static const int sizeFont = wxNORMAL_FONT->GetPointSize();
696e1ea0 375
696e1ea0
VZ
376 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
377 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
378 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
c801d85f
KB
379
380 wxRED_PEN = new wxPen ("RED", 1, wxSOLID);
381 wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID);
382 wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID);
383 wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID);
384 wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID);
385 wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT);
386 wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH);
387 wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID);
388 wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID);
389 wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID);
390
391 wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID);
392 wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID);
393 wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID);
394 wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID);
395 wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT);
396 wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID);
397 wxRED_BRUSH = new wxBrush ("RED", wxSOLID);
398 wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID);
399 wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID);
400 wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID);
401
402 wxBLACK = new wxColour ("BLACK");
403 wxWHITE = new wxColour ("WHITE");
404 wxRED = new wxColour ("RED");
405 wxBLUE = new wxColour ("BLUE");
406 wxGREEN = new wxColour ("GREEN");
407 wxCYAN = new wxColour ("CYAN");
408 wxLIGHT_GREY = new wxColour ("LIGHT GREY");
409
410 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
411 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
412 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
413}
414
8bbe427f 415void wxDeleteStockObjects ()
c801d85f 416{
a3622daa
VZ
417 wxDELETE(wxNORMAL_FONT);
418 wxDELETE(wxSMALL_FONT);
419 wxDELETE(wxITALIC_FONT);
420 wxDELETE(wxSWISS_FONT);
421
422 wxDELETE(wxRED_PEN);
423 wxDELETE(wxCYAN_PEN);
424 wxDELETE(wxGREEN_PEN);
425 wxDELETE(wxBLACK_PEN);
426 wxDELETE(wxWHITE_PEN);
427 wxDELETE(wxTRANSPARENT_PEN);
428 wxDELETE(wxBLACK_DASHED_PEN);
429 wxDELETE(wxGREY_PEN);
430 wxDELETE(wxMEDIUM_GREY_PEN);
431 wxDELETE(wxLIGHT_GREY_PEN);
432
433 wxDELETE(wxBLUE_BRUSH);
434 wxDELETE(wxGREEN_BRUSH);
435 wxDELETE(wxWHITE_BRUSH);
436 wxDELETE(wxBLACK_BRUSH);
437 wxDELETE(wxTRANSPARENT_BRUSH);
438 wxDELETE(wxCYAN_BRUSH);
439 wxDELETE(wxRED_BRUSH);
440 wxDELETE(wxGREY_BRUSH);
441 wxDELETE(wxMEDIUM_GREY_BRUSH);
442 wxDELETE(wxLIGHT_GREY_BRUSH);
443
444 wxDELETE(wxBLACK);
445 wxDELETE(wxWHITE);
446 wxDELETE(wxRED);
447 wxDELETE(wxBLUE);
448 wxDELETE(wxGREEN);
449 wxDELETE(wxCYAN);
450 wxDELETE(wxLIGHT_GREY);
451
452 wxDELETE(wxSTANDARD_CURSOR);
453 wxDELETE(wxHOURGLASS_CURSOR);
454 wxDELETE(wxCROSS_CURSOR);
455}
456
457void wxDeleteStockLists() {
458 wxDELETE(wxTheBrushList);
459 wxDELETE(wxThePenList);
460 wxDELETE(wxTheFontList);
461 wxDELETE(wxTheBitmapList);
c801d85f
KB
462}
463
6a6c0a8b 464wxBitmapList::wxBitmapList ()
c801d85f
KB
465{
466}
467
6a6c0a8b 468wxBitmapList::~wxBitmapList ()
c801d85f
KB
469{
470 wxNode *node = First ();
471 while (node)
472 {
473 wxBitmap *bitmap = (wxBitmap *) node->Data ();
474 wxNode *next = node->Next ();
4c444f19
JS
475 if (bitmap->GetVisible())
476 delete bitmap;
c801d85f
KB
477 node = next;
478 }
479}
480
481// Pen and Brush lists
6a6c0a8b 482wxPenList::~wxPenList ()
c801d85f
KB
483{
484 wxNode *node = First ();
485 while (node)
486 {
487 wxPen *pen = (wxPen *) node->Data ();
488 wxNode *next = node->Next ();
4c444f19
JS
489 if (pen->GetVisible())
490 delete pen;
c801d85f
KB
491 node = next;
492 }
493}
494
495void wxPenList::AddPen (wxPen * pen)
496{
497 Append (pen);
498}
499
500void wxPenList::RemovePen (wxPen * pen)
501{
502 DeleteObject (pen);
503}
504
debe6624 505wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
c801d85f
KB
506{
507 for (wxNode * node = First (); node; node = node->Next ())
508 {
509 wxPen *each_pen = (wxPen *) node->Data ();
6d167489
VZ
510 if (each_pen &&
511 each_pen->GetVisible() &&
8bbe427f
VZ
512 each_pen->GetWidth () == width &&
513 each_pen->GetStyle () == style &&
514 each_pen->GetColour ().Red () == colour.Red () &&
515 each_pen->GetColour ().Green () == colour.Green () &&
516 each_pen->GetColour ().Blue () == colour.Blue ())
517 return each_pen;
c801d85f
KB
518 }
519 wxPen *pen = new wxPen (colour, width, style);
520
521 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
522 // because we created it within FindOrCreatePen. Safeguards against
523 // returning a pointer to an automatic variable and hanging on to it
524 // (dangling pointer).
525 pen->SetVisible(TRUE);
6d167489 526
c801d85f
KB
527 return pen;
528}
529
6a6c0a8b 530wxBrushList::~wxBrushList ()
c801d85f
KB
531{
532 wxNode *node = First ();
533 while (node)
534 {
535 wxBrush *brush = (wxBrush *) node->Data ();
536 wxNode *next = node->Next ();
4c444f19
JS
537 if (brush->GetVisible())
538 delete brush;
c801d85f
KB
539 node = next;
540 }
541}
542
543void wxBrushList::AddBrush (wxBrush * brush)
544{
545 Append (brush);
546}
547
debe6624 548wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
c801d85f
KB
549{
550 for (wxNode * node = First (); node; node = node->Next ())
551 {
552 wxBrush *each_brush = (wxBrush *) node->Data ();
6d167489
VZ
553 if (each_brush &&
554 each_brush->GetVisible() &&
8bbe427f
VZ
555 each_brush->GetStyle () == style &&
556 each_brush->GetColour ().Red () == colour.Red () &&
557 each_brush->GetColour ().Green () == colour.Green () &&
558 each_brush->GetColour ().Blue () == colour.Blue ())
559 return each_brush;
c801d85f 560 }
6d167489 561
c801d85f
KB
562 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
563 // because we created it within FindOrCreateBrush. Safeguards against
564 // returning a pointer to an automatic variable and hanging on to it
565 // (dangling pointer).
566 wxBrush *brush = new wxBrush (colour, style);
6d167489 567
c801d85f 568 brush->SetVisible(TRUE);
6d167489 569
c801d85f
KB
570 return brush;
571}
572
c801d85f
KB
573void wxBrushList::RemoveBrush (wxBrush * brush)
574{
575 DeleteObject (brush);
576}
577
6a6c0a8b 578wxFontList::~wxFontList ()
c801d85f 579{
6d167489
VZ
580 wxNode *node = First ();
581 while (node)
c801d85f 582 {
6d167489
VZ
583 // Only delete objects that are 'visible', i.e.
584 // that have been created using FindOrCreate...,
585 // where the pointers are expected to be shared
586 // (and therefore not deleted by any one part of an app).
587 wxFont *font = (wxFont *) node->Data ();
588 wxNode *next = node->Next ();
589 if (font->GetVisible())
590 delete font;
591 node = next;
592 }
c801d85f
KB
593}
594
595void wxFontList::AddFont (wxFont * font)
596{
597 Append (font);
598}
599
600void wxFontList::RemoveFont (wxFont * font)
601{
602 DeleteObject (font);
603}
604
f6bcfd97
BP
605wxFont *wxFontList::FindOrCreateFont(int pointSize,
606 int family,
607 int style,
608 int weight,
609 bool underline,
610 const wxString& facename,
611 wxFontEncoding encoding)
c801d85f 612{
f6bcfd97
BP
613 wxFont *font = (wxFont *)NULL;
614 wxNode *node;
615 for ( node = First(); node; node = node->Next() )
c801d85f 616 {
f6bcfd97
BP
617 font = (wxFont *)node->Data();
618 if ( font->GetVisible() &&
619 font->Ok() &&
620 font->GetPointSize () == pointSize &&
621 font->GetStyle () == style &&
622 font->GetWeight () == weight &&
623 font->GetUnderlined () == underline )
624 {
625 int fontFamily = font->GetFamily();
626
619d0528 627#if defined(__WXGTK__)
f6bcfd97
BP
628 // under GTK the default family is wxSWISS, so looking for a font
629 // with wxDEFAULT family should return a wxSWISS one instead of
630 // creating a new one
631 bool same = (fontFamily == family) ||
632 (fontFamily == wxSWISS && family == wxDEFAULT);
633#else // !GTK
634 // VZ: but why elsewhere do we require an exact match? mystery...
635 bool same = fontFamily == family;
636#endif // GTK/!GTK
637
638 // empty facename matches anything at all: this is bad because
639 // depending on which fonts are already created, we might get back
640 // a different font if we create it with empty facename, but it is
641 // still better than never matching anything in the cache at all
642 // in this case
643 if ( same && !!facename )
644 {
645 const wxString& fontFace = font->GetFaceName();
646
647 // empty facename matches everything
648 same = !fontFace || fontFace == facename;
649 }
650
651 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
652 {
653 // have to match the encoding too
654 same = font->GetEncoding() == encoding;
655 }
656
657 if ( same )
658 {
659 return font;
660 }
661 }
c801d85f 662 }
6d167489 663
f6bcfd97
BP
664 if ( !node )
665 {
666 // font not found, create the new one
667 font = new wxFont(pointSize, family, style, weight,
668 underline, facename, encoding);
669
670 // and mark it as being cacheable
671 font->SetVisible(TRUE);
672 }
6d167489 673
f6bcfd97 674 return font;
c801d85f
KB
675}
676
677void wxBitmapList::AddBitmap(wxBitmap *bitmap)
8bbe427f
VZ
678{
679 Append(bitmap);
680}
681
c801d85f 682void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
8bbe427f
VZ
683{
684 DeleteObject(bitmap);
685}
c801d85f 686
6a6c0a8b
JS
687wxSize wxGetDisplaySize()
688{
689 int x, y;
690 wxDisplaySize(& x, & y);
691 return wxSize(x, y);
692}
693
904a68b6
RL
694wxSize wxGetDisplaySizeMM()
695{
696 int x, y;
697 wxDisplaySizeMM(& x, & y);
698 return wxSize(x, y);
699}
700
8bbe427f
VZ
701wxResourceCache::~wxResourceCache ()
702{
f6bcfd97
BP
703 wxNode *node = First ();
704 while (node) {
705 wxObject *item = (wxObject *)node->Data();
706 delete item;
a3622daa 707
f6bcfd97 708 node = node->Next ();
a3622daa 709 }
a3622daa
VZ
710}
711