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