1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "gdicmn.h"
17 #define XtDisplay XTDISPLAY
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/gdicmn.h"
31 #include "wx/bitmap.h"
33 #include "wx/cursor.h"
35 #include "wx/palette.h"
39 #include "wx/settings.h"
40 #include "wx/hashmap.h"
45 #if defined(__WXMSW__)
46 #include "wx/msw/wrapwin.h"
51 #pragma message disable nosimpint
55 #pragma message enable nosimpint
64 #include "wx/mac/private.h"
65 #include "wx/mac/uma.h"
68 #if wxUSE_EXTENDED_RTTI
72 template<> void wxStringReadValue(const wxString
&s
, wxPoint
&data
)
74 wxSscanf(s
, wxT("%d,%d"), &data
.x
, &data
.y
) ;
77 template<> void wxStringWriteValue(wxString
&s
, const wxPoint
&data
)
79 s
= wxString::Format(wxT("%d,%d"), data
.x
, data
.y
) ;
82 wxCUSTOM_TYPE_INFO(wxPoint
, wxToStringConverter
<wxPoint
> , wxFromStringConverter
<wxPoint
>)
84 template<> void wxStringReadValue(const wxString
&s
, wxSize
&data
)
86 wxSscanf(s
, wxT("%d,%d"), &data
.x
, &data
.y
) ;
89 template<> void wxStringWriteValue(wxString
&s
, const wxSize
&data
)
91 s
= wxString::Format(wxT("%d,%d"), data
.x
, data
.y
) ;
94 wxCUSTOM_TYPE_INFO(wxSize
, wxToStringConverter
<wxSize
> , wxFromStringConverter
<wxSize
>)
98 IMPLEMENT_ABSTRACT_CLASS(wxDCBase
, wxObject
)
100 wxRect::wxRect(const wxPoint
& point1
, const wxPoint
& point2
)
104 width
= point2
.x
- point1
.x
;
105 height
= point2
.y
- point1
.y
;
122 bool wxRect::operator==(const wxRect
& rect
) const
124 return ((x
== rect
.x
) &&
126 (width
== rect
.width
) &&
127 (height
== rect
.height
));
130 wxRect
wxRect::operator+(const wxRect
& rect
) const
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
);
139 wxRect
& wxRect::Union(const wxRect
& rect
)
141 // ignore empty rectangles: union with an empty rectangle shouldn't extend
142 // this one to (0, 0)
143 if ( !width
|| !height
)
147 else if ( rect
.width
&& rect
.height
)
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
);
159 //else: we're not empty and rect is empty
164 wxRect
& wxRect::Inflate(wxCoord dx
, wxCoord dy
)
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)
178 // what else can we do?
187 bool wxRect::Inside(int cx
, int cy
) const
189 return ( (cx
>= x
) && (cy
>= y
)
190 && ((cy
- y
) < height
)
191 && ((cx
- x
) < width
)
195 wxRect
& wxRect::Intersect(const wxRect
& rect
)
204 if ( x2
> rect
.GetRight() )
205 x2
= rect
.GetRight();
206 if ( y2
> rect
.GetBottom() )
207 y2
= rect
.GetBottom();
212 if ( width
<= 0 || height
<= 0 )
221 bool wxRect::Intersects(const wxRect
& rect
) const
223 wxRect r
= Intersect(rect
);
225 // if there is no intersection, both width and height are 0
229 // ============================================================================
231 // ============================================================================
233 // ----------------------------------------------------------------------------
234 // wxColourDatabase ctor/dtor
235 // ----------------------------------------------------------------------------
237 wxColourDatabase::wxColourDatabase ()
239 // will be created on demand in Initialize()
243 wxColourDatabase::~wxColourDatabase ()
247 WX_CLEAR_HASH_MAP(wxStringToColourHashMap
, *m_map
);
253 delete [] m_palTable
;
257 // Colour database stuff
258 void wxColourDatabase::Initialize()
262 // already initialized
266 m_map
= new wxStringToColourHashMap
;
268 static const struct wxColourDesc
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}, // ?
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}
350 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
352 const wxColourDesc
& cc
= wxColourTable
[n
];
353 (*m_map
)[cc
.name
] = new wxColour(cc
.r
, cc
.g
, cc
.b
);
357 m_palTable
= new long[n
];
358 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
360 const wxColourDesc
& cc
= wxColourTable
[n
];
361 m_palTable
[n
] = OS2RGB(cc
.r
,cc
.g
,cc
.b
);
367 // ----------------------------------------------------------------------------
368 // wxColourDatabase operations
369 // ----------------------------------------------------------------------------
371 void wxColourDatabase::AddColour(const wxString
& name
, const wxColour
& colour
)
375 // canonicalize the colour names before using them as keys: they should be
377 wxString colName
= name
;
380 // ... and we also allow both grey/gray
381 wxString colNameAlt
= colName
;
382 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
384 // but in this case it is not necessary so avoid extra search below
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() )
393 *(it
->second
) = colour
;
397 (*m_map
)[colName
] = new wxColour(colour
);
401 wxColour
wxColourDatabase::Find(const wxString
& colour
) const
403 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
406 // first look among the existing colours
408 // make the comparaison case insensitive and also match both grey and gray
409 wxString colName
= colour
;
411 wxString colNameAlt
= colName
;
412 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
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
);
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
);
428 self
->AddColour(colour
, col
);
433 // TODO: move this to wxColour::CreateByName()
437 Display
*display
= XtDisplay((Widget
) wxTheApp
->GetTopLevelWidget()) ;
440 Display
* display
= (Display
*) wxGetDisplay();
442 /* MATTHEW: [4] Use wxGetMainColormap */
443 if (!XParseColor(display
, (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) display
), colour
.ToAscii() ,&xcolour
))
447 unsigned char r
= (unsigned char)(xcolour
.red
);
448 unsigned char g
= (unsigned char)(xcolour
.green
);
449 unsigned char b
= (unsigned char)(xcolour
.blue
);
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);
456 wxColour
col(r
, g
, b
);
457 AddColour(colour
, col
);
460 #else // other platform
465 wxString
wxColourDatabase::FindName(const wxColour
& colour
) const
467 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
470 typedef wxStringToColourHashMap::iterator iterator
;
472 for ( iterator it
= m_map
->begin(), en
= m_map
->end(); it
!= en
; ++it
)
474 if ( *(it
->second
) == colour
)
478 return wxEmptyString
;
481 // ----------------------------------------------------------------------------
482 // deprecated wxColourDatabase methods
483 // ----------------------------------------------------------------------------
485 wxColour
*wxColourDatabase::FindColour(const wxString
& name
)
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"));
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
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
505 static wxColour s_col
;
511 return new wxColour(s_col
);
514 // ============================================================================
516 // ============================================================================
518 void wxInitializeStockLists()
520 wxTheColourDatabase
= new wxColourDatabase
;
522 wxTheBrushList
= new wxBrushList
;
523 wxThePenList
= new wxPenList
;
524 wxTheFontList
= new wxFontList
;
525 wxTheBitmapList
= new wxBitmapList
;
528 void wxInitializeStockObjects ()
534 // wxFontPool = new XFontPool;
537 // why under MSW fonts shouldn't have the standard system size?
540 static const int sizeFont = 10;
544 #if defined(__WXMAC__)
545 // retrieve size of system font for all stock fonts
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
) );
557 wxNORMAL_FONT
= new wxFont () ;
558 wxNORMAL_FONT
->MacCreateThemeFont( kThemeSystemFont
);
560 #elif defined(__WXPM__)
561 static const int sizeFont
= 12;
563 wxNORMAL_FONT
= new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
564 static const int sizeFont
= wxNORMAL_FONT
->GetPointSize();
567 #if defined(__WXPM__)
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
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
) );
583 wxSMALL_FONT
= new wxFont () ;
584 wxSMALL_FONT
->MacCreateThemeFont( kThemeSmallSystemFont
);
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
);
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
);
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
);
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"));
622 wxSTANDARD_CURSOR
= new wxCursor (wxCURSOR_ARROW
);
623 wxHOURGLASS_CURSOR
= new wxCursor (wxCURSOR_WAIT
);
624 wxCROSS_CURSOR
= new wxCursor (wxCURSOR_CROSS
);
627 void wxDeleteStockObjects ()
629 wxDELETE(wxNORMAL_FONT
);
630 wxDELETE(wxSMALL_FONT
);
631 wxDELETE(wxITALIC_FONT
);
632 wxDELETE(wxSWISS_FONT
);
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
);
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
);
662 wxDELETE(wxLIGHT_GREY
);
664 wxDELETE(wxSTANDARD_CURSOR
);
665 wxDELETE(wxHOURGLASS_CURSOR
);
666 wxDELETE(wxCROSS_CURSOR
);
669 void wxDeleteStockLists()
671 wxDELETE(wxTheBrushList
);
672 wxDELETE(wxThePenList
);
673 wxDELETE(wxTheFontList
);
674 wxDELETE(wxTheBitmapList
);
677 // ============================================================================
678 // wxTheXXXList stuff (semi-obsolete)
679 // ============================================================================
681 wxBitmapList::~wxBitmapList ()
683 wxList::compatibility_iterator node
= GetFirst ();
686 wxBitmap
*bitmap
= (wxBitmap
*) node
->GetData ();
687 wxList::compatibility_iterator next
= node
->GetNext ();
688 if (bitmap
->GetVisible())
694 // Pen and Brush lists
695 wxPenList::~wxPenList ()
697 wxList::compatibility_iterator node
= GetFirst ();
700 wxPen
*pen
= (wxPen
*) node
->GetData ();
701 wxList::compatibility_iterator next
= node
->GetNext ();
702 if (pen
->GetVisible())
708 void wxPenList::AddPen (wxPen
* pen
)
713 void wxPenList::RemovePen (wxPen
* pen
)
718 wxPen
*wxPenList::FindOrCreatePen (const wxColour
& colour
, int width
, int style
)
720 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
722 wxPen
*each_pen
= (wxPen
*) node
->GetData ();
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 ())
733 wxPen
*pen
= new wxPen (colour
, width
, style
);
736 // don't save the invalid pens in the list
744 // we'll delete it ourselves later
745 pen
->SetVisible(true);
750 wxBrushList::~wxBrushList ()
752 wxList::compatibility_iterator node
= GetFirst ();
755 wxBrush
*brush
= (wxBrush
*) node
->GetData ();
756 wxList::compatibility_iterator next
= node
->GetNext ();
757 if (brush
&& brush
->GetVisible())
763 void wxBrushList::AddBrush (wxBrush
* brush
)
768 wxBrush
*wxBrushList::FindOrCreateBrush (const wxColour
& colour
, int style
)
770 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
772 wxBrush
*each_brush
= (wxBrush
*) node
->GetData ();
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 ())
782 wxBrush
*brush
= new wxBrush (colour
, style
);
786 // don't put the brushes we failed to create into the list
794 // we'll delete it ourselves later
795 brush
->SetVisible(true);
800 void wxBrushList::RemoveBrush (wxBrush
* brush
)
802 DeleteObject (brush
);
805 wxFontList::~wxFontList ()
807 wxList::compatibility_iterator node
= GetFirst ();
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())
822 void wxFontList::AddFont (wxFont
* font
)
827 void wxFontList::RemoveFont (wxFont
* font
)
832 wxFont
*wxFontList::FindOrCreateFont(int pointSize
,
837 const wxString
& facename
,
838 wxFontEncoding encoding
)
840 wxFont
*font
= (wxFont
*)NULL
;
841 wxList::compatibility_iterator node
;
842 for ( node
= GetFirst(); node
; node
= node
->GetNext() )
844 font
= (wxFont
*)node
->GetData();
845 if ( font
->GetVisible() &&
847 font
->GetPointSize () == pointSize
&&
848 font
->GetStyle () == style
&&
849 font
->GetWeight () == weight
&&
850 font
->GetUnderlined () == underline
)
852 int fontFamily
= font
->GetFamily();
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
);
861 // VZ: but why elsewhere do we require an exact match? mystery...
862 bool same
= fontFamily
== family
;
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
870 if ( same
&& !facename
.empty() )
872 const wxString
& fontFace
= font
->GetFaceName();
874 // empty facename matches everything
875 same
= !fontFace
|| fontFace
== facename
;
878 if ( same
&& (encoding
!= wxFONTENCODING_DEFAULT
) )
880 // have to match the encoding too
881 same
= font
->GetEncoding() == encoding
;
893 // font not found, create the new one
894 font
= new wxFont(pointSize
, family
, style
, weight
,
895 underline
, facename
, encoding
);
899 // and mark it as being cacheable
900 font
->SetVisible(true);
906 void wxBitmapList::AddBitmap(wxBitmap
*bitmap
)
911 void wxBitmapList::RemoveBitmap(wxBitmap
*bitmap
)
913 DeleteObject(bitmap
);
916 wxSize
wxGetDisplaySize()
919 wxDisplaySize(& x
, & y
);
923 wxRect
wxGetClientDisplayRect()
925 int x
, y
, width
, height
;
926 wxClientDisplayRect(&x
, &y
, &width
, &height
); // call plat-specific version
927 return wxRect(x
, y
, width
, height
);
930 wxSize
wxGetDisplaySizeMM()
933 wxDisplaySizeMM(& x
, & y
);
937 wxResourceCache::~wxResourceCache ()
939 wxList::compatibility_iterator node
= GetFirst ();
941 wxObject
*item
= (wxObject
*)node
->GetData();
944 node
= node
->GetNext ();