From 7eb8aeb8b172c3772a2b42364c5a1333007d310f Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 8 Apr 2010 18:47:41 +0000 Subject: [PATCH] using statically allocated font objects for speedup git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63917 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/font.h | 6 +++--- src/generic/listctrl.cpp | 3 +-- src/generic/treectlg.cpp | 2 +- src/osx/carbon/font.cpp | 14 +++++--------- src/osx/carbon/gdiobj.cpp | 6 ++---- src/osx/carbon/listctrl_mac.cpp | 3 ++- src/osx/dataview_osx.cpp | 3 ++- src/osx/listbox_osx.cpp | 3 ++- src/osx/window_osx.cpp | 21 +++++++++------------ 9 files changed, 27 insertions(+), 34 deletions(-) diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index bcd86e775a..4d6f07fbc1 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -27,7 +27,7 @@ enum wxOSXSystemFont wxOSX_SYSTEM_FONT_MINI, wxOSX_SYSTEM_FONT_MINI_BOLD, wxOSX_SYSTEM_FONT_LABELS, - wxOSX_SYSTEM_FONT_VIEWS + wxOSX_SYSTEM_FONT_VIEWS, }; @@ -36,6 +36,8 @@ class WXDLLIMPEXP_CORE wxFont : public wxFontBase public: // ctors and such wxFont() { } + + wxFont( wxOSXSystemFont systemFont ); #if wxOSX_USE_COCOA wxFont(WX_NSFont nsfont); @@ -94,8 +96,6 @@ public: bool Create(const wxNativeFontInfo& info); - bool CreateSystemFont(wxOSXSystemFont font); - virtual ~wxFont(); // implement base class pure virtuals diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 3804bf0e6f..ae17c83a8a 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -4307,8 +4307,7 @@ void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded() ); #if defined( __WXMAC__ ) - wxFont font; - font.CreateSystemFont( wxOSX_SYSTEM_FONT_SMALL ); + static wxFont font( wxOSX_SYSTEM_FONT_SMALL ); m_headerWin->SetFont( font ); #endif diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index da93936fdf..a393dc0fbb 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -973,7 +973,7 @@ void wxGenericTreeCtrl::Init() m_lastOnSame = false; #if defined( __WXMAC__ ) - m_normalFont.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS); + m_normalFont = wxFont(wxOSX_SYSTEM_FONT_VIEWS); #else m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); #endif diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index f8c6f5f347..725afb6699 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -499,6 +499,11 @@ bool wxFont::Create(const wxNativeFontInfo& info) return true; } +wxFont::wxFont(wxOSXSystemFont font) +{ + m_refData = new wxFontRefData( font, 0 ); +} + wxFont::wxFont(const wxString& fontdesc) { wxNativeFontInfo info; @@ -557,15 +562,6 @@ bool wxFont::Create(int pointSize, return true; } -bool wxFont::CreateSystemFont(wxOSXSystemFont font) -{ - UnRef(); - - m_refData = new wxFontRefData( font, 0 ); - - return true; -} - wxFont::~wxFont() { } diff --git a/src/osx/carbon/gdiobj.cpp b/src/osx/carbon/gdiobj.cpp index 31ec9c8017..4a7a3db352 100644 --- a/src/osx/carbon/gdiobj.cpp +++ b/src/osx/carbon/gdiobj.cpp @@ -59,12 +59,10 @@ const wxFont* wxStockGDIMac::GetFont(Item item) switch (item) { case FONT_NORMAL: - font = new wxFont; - font->CreateSystemFont(wxOSX_SYSTEM_FONT_NORMAL); + font = new wxFont(wxOSX_SYSTEM_FONT_NORMAL); break; case FONT_SMALL: - font = new wxFont; - font->CreateSystemFont(wxOSX_SYSTEM_FONT_SMALL); + font = new wxFont(wxOSX_SYSTEM_FONT_SMALL); break; default: font = const_cast(super::GetFont(item)); diff --git a/src/osx/carbon/listctrl_mac.cpp b/src/osx/carbon/listctrl_mac.cpp index 2734d0ac64..e66650820e 100644 --- a/src/osx/carbon/listctrl_mac.cpp +++ b/src/osx/carbon/listctrl_mac.cpp @@ -797,7 +797,8 @@ wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS); + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index bde6716c21..91c22b7e43 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -614,7 +614,8 @@ wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS); + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } diff --git a/src/osx/listbox_osx.cpp b/src/osx/listbox_osx.cpp index 43006895ab..1394c13019 100644 --- a/src/osx/listbox_osx.cpp +++ b/src/osx/listbox_osx.cpp @@ -275,7 +275,8 @@ wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS); + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 864bb128f9..7fe1edcc41 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -338,36 +338,33 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; #endif - wxFont font ; - - wxOSXSystemFont systemFont = wxOSX_SYSTEM_FONT_NORMAL ; - + switch ( variant ) { case wxWINDOW_VARIANT_NORMAL : - systemFont = wxOSX_SYSTEM_FONT_NORMAL ; + static wxFont sysNormal(wxOSX_SYSTEM_FONT_NORMAL); + SetFont(sysNormal) ; break ; case wxWINDOW_VARIANT_SMALL : - systemFont = wxOSX_SYSTEM_FONT_SMALL ; + static wxFont sysSmall(wxOSX_SYSTEM_FONT_SMALL); + SetFont(sysSmall) ; break ; case wxWINDOW_VARIANT_MINI : - systemFont = wxOSX_SYSTEM_FONT_MINI ; + static wxFont sysMini(wxOSX_SYSTEM_FONT_MINI); + SetFont(sysMini) ; break ; case wxWINDOW_VARIANT_LARGE : - systemFont = wxOSX_SYSTEM_FONT_NORMAL ; + static wxFont sysLarge(wxOSX_SYSTEM_FONT_NORMAL); + SetFont(sysLarge) ; break ; default: wxFAIL_MSG(wxT("unexpected window variant")); break ; } - - font.CreateSystemFont( systemFont ) ; - - SetFont( font ) ; } void wxWindowMac::MacUpdateControlFont() -- 2.45.2