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