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