1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #define XtDisplay XTDISPLAY
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/gdicmn.h"
27 #include "wx/bitmap.h"
29 #include "wx/cursor.h"
31 #include "wx/palette.h"
35 #include "wx/settings.h"
36 #include "wx/hashmap.h"
41 #if defined(__WXMSW__)
42 #include "wx/msw/wrapwin.h"
47 #pragma message disable nosimpint
51 #pragma message enable nosimpint
60 #include "wx/mac/private.h"
61 #include "wx/mac/uma.h"
64 #if wxUSE_EXTENDED_RTTI
68 template<> void wxStringReadValue(const wxString
&s
, wxPoint
&data
)
70 wxSscanf(s
, wxT("%d,%d"), &data
.x
, &data
.y
) ;
73 template<> void wxStringWriteValue(wxString
&s
, const wxPoint
&data
)
75 s
= wxString::Format(wxT("%d,%d"), data
.x
, data
.y
) ;
78 wxCUSTOM_TYPE_INFO(wxPoint
, wxToStringConverter
<wxPoint
> , wxFromStringConverter
<wxPoint
>)
80 template<> void wxStringReadValue(const wxString
&s
, wxSize
&data
)
82 wxSscanf(s
, wxT("%d,%d"), &data
.x
, &data
.y
) ;
85 template<> void wxStringWriteValue(wxString
&s
, const wxSize
&data
)
87 s
= wxString::Format(wxT("%d,%d"), data
.x
, data
.y
) ;
90 wxCUSTOM_TYPE_INFO(wxSize
, wxToStringConverter
<wxSize
> , wxFromStringConverter
<wxSize
>)
94 IMPLEMENT_ABSTRACT_CLASS(wxDCBase
, wxObject
)
96 wxRect::wxRect(const wxPoint
& point1
, const wxPoint
& point2
)
100 width
= point2
.x
- point1
.x
;
101 height
= point2
.y
- point1
.y
;
118 bool wxRect::operator==(const wxRect
& rect
) const
120 return ((x
== rect
.x
) &&
122 (width
== rect
.width
) &&
123 (height
== rect
.height
));
126 wxRect
wxRect::operator+(const wxRect
& rect
) const
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
);
135 wxRect
& wxRect::Union(const wxRect
& rect
)
137 // ignore empty rectangles: union with an empty rectangle shouldn't extend
138 // this one to (0, 0)
139 if ( !width
|| !height
)
143 else if ( rect
.width
&& rect
.height
)
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
);
155 //else: we're not empty and rect is empty
160 wxRect
& wxRect::Inflate(wxCoord dx
, wxCoord dy
)
164 // Don't allow deflate to eat more width than we have,
165 // a well-defined rectangle cannot have negative width.
171 // The inflate is valid.
178 // Don't allow deflate to eat more height than we have,
179 // a well-defined rectangle cannot have negative height.
185 // The inflate is valid.
193 bool wxRect::Inside(int cx
, int cy
) const
195 return ( (cx
>= x
) && (cy
>= y
)
196 && ((cy
- y
) < height
)
197 && ((cx
- x
) < width
)
201 wxRect
& wxRect::Intersect(const wxRect
& rect
)
210 if ( x2
> rect
.GetRight() )
211 x2
= rect
.GetRight();
212 if ( y2
> rect
.GetBottom() )
213 y2
= rect
.GetBottom();
218 if ( width
<= 0 || height
<= 0 )
227 bool wxRect::Intersects(const wxRect
& rect
) const
229 wxRect r
= Intersect(rect
);
231 // if there is no intersection, both width and height are 0
235 // ============================================================================
237 // ============================================================================
239 // ----------------------------------------------------------------------------
240 // wxColourDatabase ctor/dtor
241 // ----------------------------------------------------------------------------
243 wxColourDatabase::wxColourDatabase ()
245 // will be created on demand in Initialize()
249 wxColourDatabase::~wxColourDatabase ()
253 WX_CLEAR_HASH_MAP(wxStringToColourHashMap
, *m_map
);
259 delete [] m_palTable
;
263 // Colour database stuff
264 void wxColourDatabase::Initialize()
268 // already initialized
272 m_map
= new wxStringToColourHashMap
;
274 static const struct wxColourDesc
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}, // ?
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}
356 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
358 const wxColourDesc
& cc
= wxColourTable
[n
];
359 (*m_map
)[cc
.name
] = new wxColour(cc
.r
, cc
.g
, cc
.b
);
363 m_palTable
= new long[n
];
364 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
366 const wxColourDesc
& cc
= wxColourTable
[n
];
367 m_palTable
[n
] = OS2RGB(cc
.r
,cc
.g
,cc
.b
);
373 // ----------------------------------------------------------------------------
374 // wxColourDatabase operations
375 // ----------------------------------------------------------------------------
377 void wxColourDatabase::AddColour(const wxString
& name
, const wxColour
& colour
)
381 // canonicalize the colour names before using them as keys: they should be
383 wxString colName
= name
;
386 // ... and we also allow both grey/gray
387 wxString colNameAlt
= colName
;
388 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
390 // but in this case it is not necessary so avoid extra search below
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() )
399 *(it
->second
) = colour
;
403 (*m_map
)[colName
] = new wxColour(colour
);
407 wxColour
wxColourDatabase::Find(const wxString
& colour
) const
409 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
412 // first look among the existing colours
414 // make the comparaison case insensitive and also match both grey and gray
415 wxString colName
= colour
;
417 wxString colNameAlt
= colName
;
418 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
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
);
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
);
434 self
->AddColour(colour
, col
);
439 // TODO: move this to wxColour::CreateByName()
443 Display
*display
= XtDisplay((Widget
) wxTheApp
->GetTopLevelWidget()) ;
446 Display
* display
= (Display
*) wxGetDisplay();
448 /* MATTHEW: [4] Use wxGetMainColormap */
449 if (!XParseColor(display
, (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) display
), colour
.ToAscii() ,&xcolour
))
453 unsigned char r
= (unsigned char)(xcolour
.red
);
454 unsigned char g
= (unsigned char)(xcolour
.green
);
455 unsigned char b
= (unsigned char)(xcolour
.blue
);
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);
462 wxColour
col(r
, g
, b
);
463 AddColour(colour
, col
);
466 #else // other platform
471 wxString
wxColourDatabase::FindName(const wxColour
& colour
) const
473 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
476 typedef wxStringToColourHashMap::iterator iterator
;
478 for ( iterator it
= m_map
->begin(), en
= m_map
->end(); it
!= en
; ++it
)
480 if ( *(it
->second
) == colour
)
484 return wxEmptyString
;
487 // ----------------------------------------------------------------------------
488 // deprecated wxColourDatabase methods
489 // ----------------------------------------------------------------------------
491 wxColour
*wxColourDatabase::FindColour(const wxString
& name
)
493 // This function is deprecated, use Find() instead.
494 // Formerly this function sometimes would return a deletable pointer and
495 // sometimes a non-deletable one (when returning a colour from the database).
496 // Trying to delete the latter anyway results in problems, so probably
497 // nobody ever freed the pointers. Currently it always returns a new
498 // instance, which means there will be memory leaks.
499 wxLogDebug(wxT("wxColourDataBase::FindColour():")
500 wxT(" Please use wxColourDataBase::Find() instead"));
502 // using a static variable here is not the most elegant solution but unless
503 // we want to make wxStringToColourHashMap public (i.e. move it to the
504 // header) so that we could have a member function returning
505 // wxStringToColourHashMap::iterator, there is really no good way to do it
508 // and knowing that this function is going to disappear in the next release
509 // anyhow I don't want to waste time on this
511 static wxColour s_col
;
517 return new wxColour(s_col
);
520 // ============================================================================
522 // ============================================================================
524 void wxInitializeStockLists()
526 wxTheColourDatabase
= new wxColourDatabase
;
528 wxTheBrushList
= new wxBrushList
;
529 wxThePenList
= new wxPenList
;
530 wxTheFontList
= new wxFontList
;
531 wxTheBitmapList
= new wxBitmapList
;
534 void wxInitializeStockObjects ()
540 // wxFontPool = new XFontPool;
543 // why under MSW fonts shouldn't have the standard system size?
546 static const int sizeFont = 10;
550 #if defined(__WXMAC__)
551 // retrieve size of system font for all stock fonts
558 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
559 sizeFont
= fontSize
;
560 #ifdef __WXMAC_CLASSIC__
561 wxNORMAL_FONT
= new wxFont (fontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal(fontName
) );
563 wxNORMAL_FONT
= new wxFont () ;
564 wxNORMAL_FONT
->MacCreateThemeFont( kThemeSystemFont
);
566 #elif defined(__WXPM__)
567 static const int sizeFont
= 12;
569 wxNORMAL_FONT
= new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
570 static const int sizeFont
= wxNORMAL_FONT
->GetPointSize();
573 #if defined(__WXPM__)
575 // Basic OS/2 has a fairly limited number of fonts and these are as good
576 // as I can do to get something that looks halfway "wx" normal
578 wxNORMAL_FONT
= new wxFont (sizeFont
, wxMODERN
, wxNORMAL
, wxBOLD
);
579 wxSMALL_FONT
= new wxFont (sizeFont
- 4, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
580 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
581 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
582 #elif defined(__WXMAC__)
583 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
584 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
585 #ifdef __WXMAC_CLASSIC__
586 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
587 wxSMALL_FONT
= new wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) );
589 wxSMALL_FONT
= new wxFont () ;
590 wxSMALL_FONT
->MacCreateThemeFont( kThemeSmallSystemFont
);
593 wxSMALL_FONT
= new wxFont (sizeFont
- 2, wxSWISS
, wxNORMAL
, wxNORMAL
);
594 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
595 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
);
598 wxRED_PEN
= new wxPen (wxT("RED"), 1, wxSOLID
);
599 wxCYAN_PEN
= new wxPen (wxT("CYAN"), 1, wxSOLID
);
600 wxGREEN_PEN
= new wxPen (wxT("GREEN"), 1, wxSOLID
);
601 wxBLACK_PEN
= new wxPen (wxT("BLACK"), 1, wxSOLID
);
602 wxWHITE_PEN
= new wxPen (wxT("WHITE"), 1, wxSOLID
);
603 wxTRANSPARENT_PEN
= new wxPen (wxT("BLACK"), 1, wxTRANSPARENT
);
604 wxBLACK_DASHED_PEN
= new wxPen (wxT("BLACK"), 1, wxSHORT_DASH
);
605 wxGREY_PEN
= new wxPen (wxT("GREY"), 1, wxSOLID
);
606 wxMEDIUM_GREY_PEN
= new wxPen (wxT("MEDIUM GREY"), 1, wxSOLID
);
607 wxLIGHT_GREY_PEN
= new wxPen (wxT("LIGHT GREY"), 1, wxSOLID
);
609 wxBLUE_BRUSH
= new wxBrush (wxT("BLUE"), wxSOLID
);
610 wxGREEN_BRUSH
= new wxBrush (wxT("GREEN"), wxSOLID
);
611 wxWHITE_BRUSH
= new wxBrush (wxT("WHITE"), wxSOLID
);
612 wxBLACK_BRUSH
= new wxBrush (wxT("BLACK"), wxSOLID
);
613 wxTRANSPARENT_BRUSH
= new wxBrush (wxT("BLACK"), wxTRANSPARENT
);
614 wxCYAN_BRUSH
= new wxBrush (wxT("CYAN"), wxSOLID
);
615 wxRED_BRUSH
= new wxBrush (wxT("RED"), wxSOLID
);
616 wxGREY_BRUSH
= new wxBrush (wxT("GREY"), wxSOLID
);
617 wxMEDIUM_GREY_BRUSH
= new wxBrush (wxT("MEDIUM GREY"), wxSOLID
);
618 wxLIGHT_GREY_BRUSH
= new wxBrush (wxT("LIGHT GREY"), wxSOLID
);
620 wxBLACK
= new wxColour (wxT("BLACK"));
621 wxWHITE
= new wxColour (wxT("WHITE"));
622 wxRED
= new wxColour (wxT("RED"));
623 wxBLUE
= new wxColour (wxT("BLUE"));
624 wxGREEN
= new wxColour (wxT("GREEN"));
625 wxCYAN
= new wxColour (wxT("CYAN"));
626 wxLIGHT_GREY
= new wxColour (wxT("LIGHT GREY"));
628 wxSTANDARD_CURSOR
= new wxCursor (wxCURSOR_ARROW
);
629 wxHOURGLASS_CURSOR
= new wxCursor (wxCURSOR_WAIT
);
630 wxCROSS_CURSOR
= new wxCursor (wxCURSOR_CROSS
);
633 void wxDeleteStockObjects ()
635 wxDELETE(wxNORMAL_FONT
);
636 wxDELETE(wxSMALL_FONT
);
637 wxDELETE(wxITALIC_FONT
);
638 wxDELETE(wxSWISS_FONT
);
641 wxDELETE(wxCYAN_PEN
);
642 wxDELETE(wxGREEN_PEN
);
643 wxDELETE(wxBLACK_PEN
);
644 wxDELETE(wxWHITE_PEN
);
645 wxDELETE(wxTRANSPARENT_PEN
);
646 wxDELETE(wxBLACK_DASHED_PEN
);
647 wxDELETE(wxGREY_PEN
);
648 wxDELETE(wxMEDIUM_GREY_PEN
);
649 wxDELETE(wxLIGHT_GREY_PEN
);
651 wxDELETE(wxBLUE_BRUSH
);
652 wxDELETE(wxGREEN_BRUSH
);
653 wxDELETE(wxWHITE_BRUSH
);
654 wxDELETE(wxBLACK_BRUSH
);
655 wxDELETE(wxTRANSPARENT_BRUSH
);
656 wxDELETE(wxCYAN_BRUSH
);
657 wxDELETE(wxRED_BRUSH
);
658 wxDELETE(wxGREY_BRUSH
);
659 wxDELETE(wxMEDIUM_GREY_BRUSH
);
660 wxDELETE(wxLIGHT_GREY_BRUSH
);
668 wxDELETE(wxLIGHT_GREY
);
670 wxDELETE(wxSTANDARD_CURSOR
);
671 wxDELETE(wxHOURGLASS_CURSOR
);
672 wxDELETE(wxCROSS_CURSOR
);
675 void wxDeleteStockLists()
677 wxDELETE(wxTheBrushList
);
678 wxDELETE(wxThePenList
);
679 wxDELETE(wxTheFontList
);
680 wxDELETE(wxTheBitmapList
);
683 // ============================================================================
684 // wxTheXXXList stuff (semi-obsolete)
685 // ============================================================================
687 wxBitmapList::~wxBitmapList ()
689 wxList::compatibility_iterator node
= GetFirst ();
692 wxBitmap
*bitmap
= (wxBitmap
*) node
->GetData ();
693 wxList::compatibility_iterator next
= node
->GetNext ();
694 if (bitmap
->GetVisible())
700 // Pen and Brush lists
701 wxPenList::~wxPenList ()
703 wxList::compatibility_iterator node
= GetFirst ();
706 wxPen
*pen
= (wxPen
*) node
->GetData ();
707 wxList::compatibility_iterator next
= node
->GetNext ();
708 if (pen
->GetVisible())
714 void wxPenList::AddPen (wxPen
* pen
)
719 void wxPenList::RemovePen (wxPen
* pen
)
724 wxPen
*wxPenList::FindOrCreatePen (const wxColour
& colour
, int width
, int style
)
726 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
728 wxPen
*each_pen
= (wxPen
*) node
->GetData ();
730 each_pen
->GetVisible() &&
731 each_pen
->GetWidth () == width
&&
732 each_pen
->GetStyle () == style
&&
733 each_pen
->GetColour ().Red () == colour
.Red () &&
734 each_pen
->GetColour ().Green () == colour
.Green () &&
735 each_pen
->GetColour ().Blue () == colour
.Blue ())
739 wxPen
*pen
= new wxPen (colour
, width
, style
);
742 // don't save the invalid pens in the list
750 // we'll delete it ourselves later
751 pen
->SetVisible(true);
756 wxBrushList::~wxBrushList ()
758 wxList::compatibility_iterator node
= GetFirst ();
761 wxBrush
*brush
= (wxBrush
*) node
->GetData ();
762 wxList::compatibility_iterator next
= node
->GetNext ();
763 if (brush
&& brush
->GetVisible())
769 void wxBrushList::AddBrush (wxBrush
* brush
)
774 wxBrush
*wxBrushList::FindOrCreateBrush (const wxColour
& colour
, int style
)
776 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
778 wxBrush
*each_brush
= (wxBrush
*) node
->GetData ();
780 each_brush
->GetVisible() &&
781 each_brush
->GetStyle () == style
&&
782 each_brush
->GetColour ().Red () == colour
.Red () &&
783 each_brush
->GetColour ().Green () == colour
.Green () &&
784 each_brush
->GetColour ().Blue () == colour
.Blue ())
788 wxBrush
*brush
= new wxBrush (colour
, style
);
792 // don't put the brushes we failed to create into the list
800 // we'll delete it ourselves later
801 brush
->SetVisible(true);
806 void wxBrushList::RemoveBrush (wxBrush
* brush
)
808 DeleteObject (brush
);
811 wxFontList::~wxFontList ()
813 wxList::compatibility_iterator node
= GetFirst ();
816 // Only delete objects that are 'visible', i.e.
817 // that have been created using FindOrCreate...,
818 // where the pointers are expected to be shared
819 // (and therefore not deleted by any one part of an app).
820 wxFont
*font
= (wxFont
*) node
->GetData ();
821 wxList::compatibility_iterator next
= node
->GetNext ();
822 if (font
->GetVisible())
828 void wxFontList::AddFont (wxFont
* font
)
833 void wxFontList::RemoveFont (wxFont
* font
)
838 wxFont
*wxFontList::FindOrCreateFont(int pointSize
,
843 const wxString
& facename
,
844 wxFontEncoding encoding
)
846 wxFont
*font
= (wxFont
*)NULL
;
847 wxList::compatibility_iterator node
;
848 for ( node
= GetFirst(); node
; node
= node
->GetNext() )
850 font
= (wxFont
*)node
->GetData();
851 if ( font
->GetVisible() &&
853 font
->GetPointSize () == pointSize
&&
854 font
->GetStyle () == style
&&
855 font
->GetWeight () == weight
&&
856 font
->GetUnderlined () == underline
)
858 int fontFamily
= font
->GetFamily();
860 #if defined(__WXGTK__)
861 // under GTK the default family is wxSWISS, so looking for a font
862 // with wxDEFAULT family should return a wxSWISS one instead of
863 // creating a new one
864 bool same
= (fontFamily
== family
) ||
865 (fontFamily
== wxSWISS
&& family
== wxDEFAULT
);
867 // VZ: but why elsewhere do we require an exact match? mystery...
868 bool same
= fontFamily
== family
;
871 // empty facename matches anything at all: this is bad because
872 // depending on which fonts are already created, we might get back
873 // a different font if we create it with empty facename, but it is
874 // still better than never matching anything in the cache at all
876 if ( same
&& !facename
.empty() )
878 const wxString
& fontFace
= font
->GetFaceName();
880 // empty facename matches everything
881 same
= !fontFace
|| fontFace
== facename
;
884 if ( same
&& (encoding
!= wxFONTENCODING_DEFAULT
) )
886 // have to match the encoding too
887 same
= font
->GetEncoding() == encoding
;
899 // font not found, create the new one
900 font
= new wxFont(pointSize
, family
, style
, weight
,
901 underline
, facename
, encoding
);
905 // and mark it as being cacheable
906 font
->SetVisible(true);
912 void wxBitmapList::AddBitmap(wxBitmap
*bitmap
)
917 void wxBitmapList::RemoveBitmap(wxBitmap
*bitmap
)
919 DeleteObject(bitmap
);
922 wxSize
wxGetDisplaySize()
925 wxDisplaySize(& x
, & y
);
929 wxRect
wxGetClientDisplayRect()
931 int x
, y
, width
, height
;
932 wxClientDisplayRect(&x
, &y
, &width
, &height
); // call plat-specific version
933 return wxRect(x
, y
, width
, height
);
936 wxSize
wxGetDisplaySizeMM()
939 wxDisplaySizeMM(& x
, & y
);
943 wxResourceCache::~wxResourceCache ()
945 wxList::compatibility_iterator node
= GetFirst ();
947 wxObject
*item
= (wxObject
*)node
->GetData();
950 node
= node
->GetNext ();