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