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