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