From: Vadim Zeitlin Date: Mon, 12 Oct 2009 13:59:13 +0000 (+0000) Subject: Added wxDCFontChanger ctor not changing font. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ca4adfd06220c55f95c4b950f35447f7b4328bb7 Added wxDCFontChanger ctor not changing font. This is similar to the existing wxDCTextColourChanger ctor not changing colour and is useful in the same kind of situations: when the font may or not be changed. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dc.h b/include/wx/dc.h index 4981bda64a..82f4848adf 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1377,8 +1377,21 @@ private: class WXDLLIMPEXP_CORE wxDCFontChanger { public: - wxDCFontChanger(wxDC& dc, const wxFont& font) : m_dc(dc), m_fontOld(dc.GetFont()) + wxDCFontChanger(wxDC& dc) + : m_dc(dc), m_fontOld() { + } + + wxDCFontChanger(wxDC& dc, const wxFont& font) + : m_dc(dc), m_fontOld(dc.GetFont()) + { + m_dc.SetFont(font); + } + + void Set(const wxFont& font) + { + if ( !m_fontOld.Ok() ) + m_fontOld = m_dc.GetFont(); m_dc.SetFont(font); } diff --git a/interface/wx/dc.h b/interface/wx/dc.h index 704e5b06a4..4e75b0ee3e 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -1493,6 +1493,18 @@ public: class wxDCFontChanger { public: + /** + Trivial constructor not changing anything. + + This constructor is useful if you don't know beforehand if the font + needs to be changed or not. It simply creates the object which won't do + anything in its destructor unless Set() is called -- in which case it + would reset the previous font. + + @since 2.9.1 + */ + wxDCFontChanger(wxDC& dc); + /** Sets @a font on the given @a dc, storing the old one. @@ -1504,7 +1516,18 @@ public: wxDCFontChanger(wxDC& dc, const wxFont& font); /** - Restores the colour originally selected in the DC passed to the ctor. + Set the font to use. + + This method is meant to be called once only and only on the objects + created with the constructor overload not taking wxColour argument and + has the same effect as the other constructor, i.e. sets the font to + the given @a font and ensures that the old value is restored when this + object is destroyed. + */ + void Set(const wxFont& font); + + /** + Restores the font originally selected in the DC passed to the ctor. */ ~wxDCFontChanger(); };