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
)
168 // Don't allow deflate to eat more width than we have,
169 // a well-defined rectangle cannot have negative width.
175 // The inflate is valid.
182 // Don't allow deflate to eat more height than we have,
183 // a well-defined rectangle cannot have negative height.
189 // The inflate is valid.
197 bool wxRect::Inside(int cx
, int cy
) const
199 return ( (cx
>= x
) && (cy
>= y
)
200 && ((cy
- y
) < height
)
201 && ((cx
- x
) < width
)
205 wxRect
& wxRect::Intersect(const wxRect
& rect
)
214 if ( x2
> rect
.GetRight() )
215 x2
= rect
.GetRight();
216 if ( y2
> rect
.GetBottom() )
217 y2
= rect
.GetBottom();
222 if ( width
<= 0 || height
<= 0 )
231 bool wxRect::Intersects(const wxRect
& rect
) const
233 wxRect r
= Intersect(rect
);
235 // if there is no intersection, both width and height are 0
239 // ============================================================================
241 // ============================================================================
243 // ----------------------------------------------------------------------------
244 // wxColourDatabase ctor/dtor
245 // ----------------------------------------------------------------------------
247 wxColourDatabase::wxColourDatabase ()
249 // will be created on demand in Initialize()
253 wxColourDatabase::~wxColourDatabase ()
257 WX_CLEAR_HASH_MAP(wxStringToColourHashMap
, *m_map
);
263 delete [] m_palTable
;
267 // Colour database stuff
268 void wxColourDatabase::Initialize()
272 // already initialized
276 m_map
= new wxStringToColourHashMap
;
278 static const struct wxColourDesc
285 {wxT("AQUAMARINE"),112, 219, 147},
286 {wxT("BLACK"),0, 0, 0},
287 {wxT("BLUE"), 0, 0, 255},
288 {wxT("BLUE VIOLET"), 159, 95, 159},
289 {wxT("BROWN"), 165, 42, 42},
290 {wxT("CADET BLUE"), 95, 159, 159},
291 {wxT("CORAL"), 255, 127, 0},
292 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
293 {wxT("CYAN"), 0, 255, 255},
294 {wxT("DARK GREY"), 47, 47, 47}, // ?
296 {wxT("DARK GREEN"), 47, 79, 47},
297 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
298 {wxT("DARK ORCHID"), 153, 50, 204},
299 {wxT("DARK SLATE BLUE"), 107, 35, 142},
300 {wxT("DARK SLATE GREY"), 47, 79, 79},
301 {wxT("DARK TURQUOISE"), 112, 147, 219},
302 {wxT("DIM GREY"), 84, 84, 84},
303 {wxT("FIREBRICK"), 142, 35, 35},
304 {wxT("FOREST GREEN"), 35, 142, 35},
305 {wxT("GOLD"), 204, 127, 50},
306 {wxT("GOLDENROD"), 219, 219, 112},
307 {wxT("GREY"), 128, 128, 128},
308 {wxT("GREEN"), 0, 255, 0},
309 {wxT("GREEN YELLOW"), 147, 219, 112},
310 {wxT("INDIAN RED"), 79, 47, 47},
311 {wxT("KHAKI"), 159, 159, 95},
312 {wxT("LIGHT BLUE"), 191, 216, 216},
313 {wxT("LIGHT GREY"), 192, 192, 192},
314 {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
315 {wxT("LIME GREEN"), 50, 204, 50},
316 {wxT("LIGHT MAGENTA"), 255, 0, 255},
317 {wxT("MAGENTA"), 255, 0, 255},
318 {wxT("MAROON"), 142, 35, 107},
319 {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
320 {wxT("MEDIUM GREY"), 100, 100, 100},
321 {wxT("MEDIUM BLUE"), 50, 50, 204},
322 {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
323 {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
324 {wxT("MEDIUM ORCHID"), 147, 112, 219},
325 {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
326 {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
327 {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
328 {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
329 {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
330 {wxT("MIDNIGHT BLUE"), 47, 47, 79},
331 {wxT("NAVY"), 35, 35, 142},
332 {wxT("ORANGE"), 204, 50, 50},
333 {wxT("ORANGE RED"), 255, 0, 127},
334 {wxT("ORCHID"), 219, 112, 219},
335 {wxT("PALE GREEN"), 143, 188, 143},
336 {wxT("PINK"), 188, 143, 234},
337 {wxT("PLUM"), 234, 173, 234},
338 {wxT("PURPLE"), 176, 0, 255},
339 {wxT("RED"), 255, 0, 0},
340 {wxT("SALMON"), 111, 66, 66},
341 {wxT("SEA GREEN"), 35, 142, 107},
342 {wxT("SIENNA"), 142, 107, 35},
343 {wxT("SKY BLUE"), 50, 153, 204},
344 {wxT("SLATE BLUE"), 0, 127, 255},
345 {wxT("SPRING GREEN"), 0, 255, 127},
346 {wxT("STEEL BLUE"), 35, 107, 142},
347 {wxT("TAN"), 219, 147, 112},
348 {wxT("THISTLE"), 216, 191, 216},
349 {wxT("TURQUOISE"), 173, 234, 234},
350 {wxT("VIOLET"), 79, 47, 79},
351 {wxT("VIOLET RED"), 204, 50, 153},
352 {wxT("WHEAT"), 216, 216, 191},
353 {wxT("WHITE"), 255, 255, 255},
354 {wxT("YELLOW"), 255, 255, 0},
355 {wxT("YELLOW GREEN"), 153, 204, 50}
360 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
362 const wxColourDesc
& cc
= wxColourTable
[n
];
363 (*m_map
)[cc
.name
] = new wxColour(cc
.r
, cc
.g
, cc
.b
);
367 m_palTable
= new long[n
];
368 for ( n
= 0; n
< WXSIZEOF(wxColourTable
); n
++ )
370 const wxColourDesc
& cc
= wxColourTable
[n
];
371 m_palTable
[n
] = OS2RGB(cc
.r
,cc
.g
,cc
.b
);
377 // ----------------------------------------------------------------------------
378 // wxColourDatabase operations
379 // ----------------------------------------------------------------------------
381 void wxColourDatabase::AddColour(const wxString
& name
, const wxColour
& colour
)
385 // canonicalize the colour names before using them as keys: they should be
387 wxString colName
= name
;
390 // ... and we also allow both grey/gray
391 wxString colNameAlt
= colName
;
392 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
394 // but in this case it is not necessary so avoid extra search below
398 wxStringToColourHashMap::iterator it
= m_map
->find(colName
);
399 if ( it
== m_map
->end() && !colNameAlt
.empty() )
400 it
= m_map
->find(colNameAlt
);
401 if ( it
!= m_map
->end() )
403 *(it
->second
) = colour
;
407 (*m_map
)[colName
] = new wxColour(colour
);
411 wxColour
wxColourDatabase::Find(const wxString
& colour
) const
413 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
416 // first look among the existing colours
418 // make the comparaison case insensitive and also match both grey and gray
419 wxString colName
= colour
;
421 wxString colNameAlt
= colName
;
422 if ( !colNameAlt
.Replace(_T("GRAY"), _T("GREY")) )
425 wxStringToColourHashMap::iterator it
= m_map
->find(colName
);
426 if ( it
== m_map
->end() && !colNameAlt
.empty() )
427 it
= m_map
->find(colNameAlt
);
428 if ( it
!= m_map
->end() )
429 return *(it
->second
);
431 // if we didn't find it, query the system, maybe it knows about it
432 #if defined(__WXGTK__) || defined(__X__)
433 wxColour col
= wxColour::CreateByName(colour
);
438 self
->AddColour(colour
, col
);
443 // TODO: move this to wxColour::CreateByName()
447 Display
*display
= XtDisplay((Widget
) wxTheApp
->GetTopLevelWidget()) ;
450 Display
* display
= (Display
*) wxGetDisplay();
452 /* MATTHEW: [4] Use wxGetMainColormap */
453 if (!XParseColor(display
, (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) display
), colour
.ToAscii() ,&xcolour
))
457 unsigned char r
= (unsigned char)(xcolour
.red
);
458 unsigned char g
= (unsigned char)(xcolour
.green
);
459 unsigned char b
= (unsigned char)(xcolour
.blue
);
461 unsigned char r
= (unsigned char)(xcolour
.red
>> 8);
462 unsigned char g
= (unsigned char)(xcolour
.green
>> 8);
463 unsigned char b
= (unsigned char)(xcolour
.blue
>> 8);
466 wxColour
col(r
, g
, b
);
467 AddColour(colour
, col
);
470 #else // other platform
475 wxString
wxColourDatabase::FindName(const wxColour
& colour
) const
477 wxColourDatabase
* const self
= wxConstCast(this, wxColourDatabase
);
480 typedef wxStringToColourHashMap::iterator iterator
;
482 for ( iterator it
= m_map
->begin(), en
= m_map
->end(); it
!= en
; ++it
)
484 if ( *(it
->second
) == colour
)
488 return wxEmptyString
;
491 // ----------------------------------------------------------------------------
492 // deprecated wxColourDatabase methods
493 // ----------------------------------------------------------------------------
495 wxColour
*wxColourDatabase::FindColour(const wxString
& name
)
497 // This function is deprecated, use Find() instead.
498 // Formerly this function sometimes would return a deletable pointer and
499 // sometimes a non-deletable one (when returning a colour from the database).
500 // Trying to delete the latter anyway results in problems, so probably
501 // nobody ever freed the pointers. Currently it always returns a new
502 // instance, which means there will be memory leaks.
503 wxLogDebug(wxT("wxColourDataBase::FindColour():")
504 wxT(" Please use wxColourDataBase::Find() instead"));
506 // using a static variable here is not the most elegant solution but unless
507 // we want to make wxStringToColourHashMap public (i.e. move it to the
508 // header) so that we could have a member function returning
509 // wxStringToColourHashMap::iterator, there is really no good way to do it
512 // and knowing that this function is going to disappear in the next release
513 // anyhow I don't want to waste time on this
515 static wxColour s_col
;
521 return new wxColour(s_col
);
524 // ============================================================================
526 // ============================================================================
528 void wxInitializeStockLists()
530 wxTheColourDatabase
= new wxColourDatabase
;
532 wxTheBrushList
= new wxBrushList
;
533 wxThePenList
= new wxPenList
;
534 wxTheFontList
= new wxFontList
;
535 wxTheBitmapList
= new wxBitmapList
;
538 void wxInitializeStockObjects ()
544 // wxFontPool = new XFontPool;
547 // why under MSW fonts shouldn't have the standard system size?
550 static const int sizeFont = 10;
554 #if defined(__WXMAC__)
555 // retrieve size of system font for all stock fonts
562 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
563 sizeFont
= fontSize
;
564 #ifdef __WXMAC_CLASSIC__
565 wxNORMAL_FONT
= new wxFont (fontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal(fontName
) );
567 wxNORMAL_FONT
= new wxFont () ;
568 wxNORMAL_FONT
->MacCreateThemeFont( kThemeSystemFont
);
570 #elif defined(__WXPM__)
571 static const int sizeFont
= 12;
573 wxNORMAL_FONT
= new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
574 static const int sizeFont
= wxNORMAL_FONT
->GetPointSize();
577 #if defined(__WXPM__)
579 // Basic OS/2 has a fairly limited number of fonts and these are as good
580 // as I can do to get something that looks halfway "wx" normal
582 wxNORMAL_FONT
= new wxFont (sizeFont
, wxMODERN
, wxNORMAL
, wxBOLD
);
583 wxSMALL_FONT
= new wxFont (sizeFont
- 4, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
584 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
585 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
586 #elif defined(__WXMAC__)
587 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
); /* Helv */
588 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
589 #ifdef __WXMAC_CLASSIC__
590 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
591 wxSMALL_FONT
= new wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) );
593 wxSMALL_FONT
= new wxFont () ;
594 wxSMALL_FONT
->MacCreateThemeFont( kThemeSmallSystemFont
);
597 wxSMALL_FONT
= new wxFont (sizeFont
- 2, wxSWISS
, wxNORMAL
, wxNORMAL
);
598 wxITALIC_FONT
= new wxFont (sizeFont
, wxROMAN
, wxITALIC
, wxNORMAL
);
599 wxSWISS_FONT
= new wxFont (sizeFont
, wxSWISS
, wxNORMAL
, wxNORMAL
);
602 wxRED_PEN
= new wxPen (wxT("RED"), 1, wxSOLID
);
603 wxCYAN_PEN
= new wxPen (wxT("CYAN"), 1, wxSOLID
);
604 wxGREEN_PEN
= new wxPen (wxT("GREEN"), 1, wxSOLID
);
605 wxBLACK_PEN
= new wxPen (wxT("BLACK"), 1, wxSOLID
);
606 wxWHITE_PEN
= new wxPen (wxT("WHITE"), 1, wxSOLID
);
607 wxTRANSPARENT_PEN
= new wxPen (wxT("BLACK"), 1, wxTRANSPARENT
);
608 wxBLACK_DASHED_PEN
= new wxPen (wxT("BLACK"), 1, wxSHORT_DASH
);
609 wxGREY_PEN
= new wxPen (wxT("GREY"), 1, wxSOLID
);
610 wxMEDIUM_GREY_PEN
= new wxPen (wxT("MEDIUM GREY"), 1, wxSOLID
);
611 wxLIGHT_GREY_PEN
= new wxPen (wxT("LIGHT GREY"), 1, wxSOLID
);
613 wxBLUE_BRUSH
= new wxBrush (wxT("BLUE"), wxSOLID
);
614 wxGREEN_BRUSH
= new wxBrush (wxT("GREEN"), wxSOLID
);
615 wxWHITE_BRUSH
= new wxBrush (wxT("WHITE"), wxSOLID
);
616 wxBLACK_BRUSH
= new wxBrush (wxT("BLACK"), wxSOLID
);
617 wxTRANSPARENT_BRUSH
= new wxBrush (wxT("BLACK"), wxTRANSPARENT
);
618 wxCYAN_BRUSH
= new wxBrush (wxT("CYAN"), wxSOLID
);
619 wxRED_BRUSH
= new wxBrush (wxT("RED"), wxSOLID
);
620 wxGREY_BRUSH
= new wxBrush (wxT("GREY"), wxSOLID
);
621 wxMEDIUM_GREY_BRUSH
= new wxBrush (wxT("MEDIUM GREY"), wxSOLID
);
622 wxLIGHT_GREY_BRUSH
= new wxBrush (wxT("LIGHT GREY"), wxSOLID
);
624 wxBLACK
= new wxColour (wxT("BLACK"));
625 wxWHITE
= new wxColour (wxT("WHITE"));
626 wxRED
= new wxColour (wxT("RED"));
627 wxBLUE
= new wxColour (wxT("BLUE"));
628 wxGREEN
= new wxColour (wxT("GREEN"));
629 wxCYAN
= new wxColour (wxT("CYAN"));
630 wxLIGHT_GREY
= new wxColour (wxT("LIGHT GREY"));
632 wxSTANDARD_CURSOR
= new wxCursor (wxCURSOR_ARROW
);
633 wxHOURGLASS_CURSOR
= new wxCursor (wxCURSOR_WAIT
);
634 wxCROSS_CURSOR
= new wxCursor (wxCURSOR_CROSS
);
637 void wxDeleteStockObjects ()
639 wxDELETE(wxNORMAL_FONT
);
640 wxDELETE(wxSMALL_FONT
);
641 wxDELETE(wxITALIC_FONT
);
642 wxDELETE(wxSWISS_FONT
);
645 wxDELETE(wxCYAN_PEN
);
646 wxDELETE(wxGREEN_PEN
);
647 wxDELETE(wxBLACK_PEN
);
648 wxDELETE(wxWHITE_PEN
);
649 wxDELETE(wxTRANSPARENT_PEN
);
650 wxDELETE(wxBLACK_DASHED_PEN
);
651 wxDELETE(wxGREY_PEN
);
652 wxDELETE(wxMEDIUM_GREY_PEN
);
653 wxDELETE(wxLIGHT_GREY_PEN
);
655 wxDELETE(wxBLUE_BRUSH
);
656 wxDELETE(wxGREEN_BRUSH
);
657 wxDELETE(wxWHITE_BRUSH
);
658 wxDELETE(wxBLACK_BRUSH
);
659 wxDELETE(wxTRANSPARENT_BRUSH
);
660 wxDELETE(wxCYAN_BRUSH
);
661 wxDELETE(wxRED_BRUSH
);
662 wxDELETE(wxGREY_BRUSH
);
663 wxDELETE(wxMEDIUM_GREY_BRUSH
);
664 wxDELETE(wxLIGHT_GREY_BRUSH
);
672 wxDELETE(wxLIGHT_GREY
);
674 wxDELETE(wxSTANDARD_CURSOR
);
675 wxDELETE(wxHOURGLASS_CURSOR
);
676 wxDELETE(wxCROSS_CURSOR
);
679 void wxDeleteStockLists()
681 wxDELETE(wxTheBrushList
);
682 wxDELETE(wxThePenList
);
683 wxDELETE(wxTheFontList
);
684 wxDELETE(wxTheBitmapList
);
687 // ============================================================================
688 // wxTheXXXList stuff (semi-obsolete)
689 // ============================================================================
691 wxBitmapList::~wxBitmapList ()
693 wxList::compatibility_iterator node
= GetFirst ();
696 wxBitmap
*bitmap
= (wxBitmap
*) node
->GetData ();
697 wxList::compatibility_iterator next
= node
->GetNext ();
698 if (bitmap
->GetVisible())
704 // Pen and Brush lists
705 wxPenList::~wxPenList ()
707 wxList::compatibility_iterator node
= GetFirst ();
710 wxPen
*pen
= (wxPen
*) node
->GetData ();
711 wxList::compatibility_iterator next
= node
->GetNext ();
712 if (pen
->GetVisible())
718 void wxPenList::AddPen (wxPen
* pen
)
723 void wxPenList::RemovePen (wxPen
* pen
)
728 wxPen
*wxPenList::FindOrCreatePen (const wxColour
& colour
, int width
, int style
)
730 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
732 wxPen
*each_pen
= (wxPen
*) node
->GetData ();
734 each_pen
->GetVisible() &&
735 each_pen
->GetWidth () == width
&&
736 each_pen
->GetStyle () == style
&&
737 each_pen
->GetColour ().Red () == colour
.Red () &&
738 each_pen
->GetColour ().Green () == colour
.Green () &&
739 each_pen
->GetColour ().Blue () == colour
.Blue ())
743 wxPen
*pen
= new wxPen (colour
, width
, style
);
746 // don't save the invalid pens in the list
754 // we'll delete it ourselves later
755 pen
->SetVisible(true);
760 wxBrushList::~wxBrushList ()
762 wxList::compatibility_iterator node
= GetFirst ();
765 wxBrush
*brush
= (wxBrush
*) node
->GetData ();
766 wxList::compatibility_iterator next
= node
->GetNext ();
767 if (brush
&& brush
->GetVisible())
773 void wxBrushList::AddBrush (wxBrush
* brush
)
778 wxBrush
*wxBrushList::FindOrCreateBrush (const wxColour
& colour
, int style
)
780 for (wxList::compatibility_iterator node
= GetFirst (); node
; node
= node
->GetNext ())
782 wxBrush
*each_brush
= (wxBrush
*) node
->GetData ();
784 each_brush
->GetVisible() &&
785 each_brush
->GetStyle () == style
&&
786 each_brush
->GetColour ().Red () == colour
.Red () &&
787 each_brush
->GetColour ().Green () == colour
.Green () &&
788 each_brush
->GetColour ().Blue () == colour
.Blue ())
792 wxBrush
*brush
= new wxBrush (colour
, style
);
796 // don't put the brushes we failed to create into the list
804 // we'll delete it ourselves later
805 brush
->SetVisible(true);
810 void wxBrushList::RemoveBrush (wxBrush
* brush
)
812 DeleteObject (brush
);
815 wxFontList::~wxFontList ()
817 wxList::compatibility_iterator node
= GetFirst ();
820 // Only delete objects that are 'visible', i.e.
821 // that have been created using FindOrCreate...,
822 // where the pointers are expected to be shared
823 // (and therefore not deleted by any one part of an app).
824 wxFont
*font
= (wxFont
*) node
->GetData ();
825 wxList::compatibility_iterator next
= node
->GetNext ();
826 if (font
->GetVisible())
832 void wxFontList::AddFont (wxFont
* font
)
837 void wxFontList::RemoveFont (wxFont
* font
)
842 wxFont
*wxFontList::FindOrCreateFont(int pointSize
,
847 const wxString
& facename
,
848 wxFontEncoding encoding
)
850 wxFont
*font
= (wxFont
*)NULL
;
851 wxList::compatibility_iterator node
;
852 for ( node
= GetFirst(); node
; node
= node
->GetNext() )
854 font
= (wxFont
*)node
->GetData();
855 if ( font
->GetVisible() &&
857 font
->GetPointSize () == pointSize
&&
858 font
->GetStyle () == style
&&
859 font
->GetWeight () == weight
&&
860 font
->GetUnderlined () == underline
)
862 int fontFamily
= font
->GetFamily();
864 #if defined(__WXGTK__)
865 // under GTK the default family is wxSWISS, so looking for a font
866 // with wxDEFAULT family should return a wxSWISS one instead of
867 // creating a new one
868 bool same
= (fontFamily
== family
) ||
869 (fontFamily
== wxSWISS
&& family
== wxDEFAULT
);
871 // VZ: but why elsewhere do we require an exact match? mystery...
872 bool same
= fontFamily
== family
;
875 // empty facename matches anything at all: this is bad because
876 // depending on which fonts are already created, we might get back
877 // a different font if we create it with empty facename, but it is
878 // still better than never matching anything in the cache at all
880 if ( same
&& !facename
.empty() )
882 const wxString
& fontFace
= font
->GetFaceName();
884 // empty facename matches everything
885 same
= !fontFace
|| fontFace
== facename
;
888 if ( same
&& (encoding
!= wxFONTENCODING_DEFAULT
) )
890 // have to match the encoding too
891 same
= font
->GetEncoding() == encoding
;
903 // font not found, create the new one
904 font
= new wxFont(pointSize
, family
, style
, weight
,
905 underline
, facename
, encoding
);
909 // and mark it as being cacheable
910 font
->SetVisible(true);
916 void wxBitmapList::AddBitmap(wxBitmap
*bitmap
)
921 void wxBitmapList::RemoveBitmap(wxBitmap
*bitmap
)
923 DeleteObject(bitmap
);
926 wxSize
wxGetDisplaySize()
929 wxDisplaySize(& x
, & y
);
933 wxRect
wxGetClientDisplayRect()
935 int x
, y
, width
, height
;
936 wxClientDisplayRect(&x
, &y
, &width
, &height
); // call plat-specific version
937 return wxRect(x
, y
, width
, height
);
940 wxSize
wxGetDisplaySizeMM()
943 wxDisplaySizeMM(& x
, & y
);
947 wxResourceCache::~wxResourceCache ()
949 wxList::compatibility_iterator node
= GetFirst ();
951 wxObject
*item
= (wxObject
*)node
->GetData();
954 node
= node
->GetNext ();