From c48d6cdf1fd6b249e95af88e0988fc46fc87b5b9 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Wed, 26 Nov 2008 15:54:08 +0000 Subject: [PATCH] documented the wxDCBrushChanger, wxDCPenChanger, wxDCTextColourChanger; introduced a wxDCFontChanger git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56980 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 28 ++++++++++ interface/wx/dc.h | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/include/wx/dc.h b/include/wx/dc.h index f780315d50..ab19b30997 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1252,4 +1252,32 @@ private: DECLARE_NO_COPY_CLASS(wxDCClipper) }; +// ---------------------------------------------------------------------------- +// helper class: you can use it to temporarily change the DC font and +// restore it automatically when the object goes out of scope +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxDCFontChanger +{ +public: + wxDCFontChanger(wxDC& dc, const wxFont& font) : m_dc(dc), m_fontOld(dc.GetFont()) + { + m_dc.SetFont(font); + } + + ~wxDCFontChanger() + { + if ( m_fontOld.Ok() ) + m_dc.SetFont(m_fontOld); + } + +private: + wxDC& m_dc; + + wxFont m_fontOld; + + DECLARE_NO_COPY_CLASS(wxDCFontChanger) +}; + + #endif // _WX_DC_H_BASE_ diff --git a/interface/wx/dc.h b/interface/wx/dc.h index 55d29cb45c..0fa93ce917 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -1131,5 +1131,139 @@ public: wxDCClipper(wxDC& dc, const wxRect& rect); wxDCClipper(wxDC& dc, int x, int y, int w, int h); //@} + + /** + Destroys the clipping region associated with the DC passed to the ctor. + */ + ~wxDCClipper(); +}; + + +/** + @class wxDCBrushChanger + + wxDCBrushChanger is a small helper class for setting a brush on a wxDC + and unsetting it automatically in the destructor, restoring the previous one. + + @library{wxcore} + @category{gdi} + + @see wxDC::SetBrush() +*/ +class wxDCBrushChanger +{ +public: + /** + Sets @a brush on the given @a dc, storing the old one. + + @param dc + The DC where the brush must be temporary set. + @param brush + The brush to set. + */ + wxDCBrushChanger(wxDC& dc, const wxBrush& brush); + + /** + Restores the brush originally selected in the DC passed to the ctor. + */ + ~wxDCBrushChanger(); +}; + + +/** + @class wxDCPenChanger + + wxDCPenChanger is a small helper class for setting a pen on a wxDC + and unsetting it automatically in the destructor, restoring the previous one. + + @library{wxcore} + @category{gdi} + + @see wxDC::SetPen() +*/ +class wxDCPenChanger +{ +public: + /** + Sets @a pen on the given @a dc, storing the old one. + + @param dc + The DC where the pen must be temporary set. + @param pen + The pen to set. + */ + wxDCPenChanger(wxDC& dc, const wxPen& pen); + + /** + Restores the pen originally selected in the DC passed to the ctor. + */ + ~wxDCPenChanger(); +}; + + + +/** + @class wxDCTextColourChanger + + wxDCTextColourChanger is a small helper class for setting a foreground + text colour on a wxDC and unsetting it automatically in the destructor, + restoring the previous one. + + @library{wxcore} + @category{gdi} + + @see wxDC::SetTextForeground() +*/ +class wxDCTextColourChanger +{ +public: + /** + Sets @a col on the given @a dc, storing the old one. + + @param dc + The DC where the colour must be temporary set. + @param col + The colour to set. + */ + wxDCTextColourChanger(wxDC& dc, const wxColour& col); + + /** + Restores the colour originally selected in the DC passed to the ctor. + */ + ~wxDCTextColourChanger(); +}; + + + +/** + @class wxDCFontChanger + + wxDCFontChanger is a small helper class for setting a font on a wxDC and + unsetting it automatically in the destructor, restoring the previous one. + + @since 2.9.0 + + @library{wxcore} + @category{gdi} + + @see wxDC::SetFont() +*/ +class wxDCFontChanger +{ +public: + /** + Sets @a font on the given @a dc, storing the old one. + + @param dc + The DC where the font must be temporary set. + @param font + The font to set. + */ + wxDCFontChanger(wxDC& dc, const wxFont& font); + + /** + Restores the colour originally selected in the DC passed to the ctor. + */ + ~wxDCFontChanger(); }; -- 2.45.2