X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c27126c7bca4ff702f6a185bb2cfba303ae20a62..9869c26285dc51d13607cddaa04f65ce983653a5:/include/wx/private/markupparserattr.h diff --git a/include/wx/private/markupparserattr.h b/include/wx/private/markupparserattr.h index 8f078efb7d..d433879daf 100644 --- a/include/wx/private/markupparserattr.h +++ b/include/wx/private/markupparserattr.h @@ -3,7 +3,6 @@ // Purpose: Classes mapping markup attributes to wxFont/wxColour. // Author: Vadim Zeitlin // Created: 2011-02-18 -// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ // Copyright: (c) 2011 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -78,8 +77,8 @@ public: virtual void OnUnderlinedStart() { DoChangeFont(&wxFont::Underlined); } virtual void OnUnderlinedEnd() { DoEndAttr(); } - virtual void OnStrikethroughStart() { } // TODO: No support in wxFont yet. - virtual void OnStrikethroughEnd() { } + virtual void OnStrikethroughStart() { DoChangeFont(&wxFont::Strikethrough); } + virtual void OnStrikethroughEnd() { DoEndAttr(); } virtual void OnBigStart() { DoChangeFont(&wxFont::Larger); } virtual void OnBigEnd() { DoEndAttr(); } @@ -101,14 +100,17 @@ public: if ( !spanAttr.m_fontFace.empty() ) font.SetFaceName(spanAttr.m_fontFace); - DoApplyToFont(spanAttr.m_isBold, font, &wxFont::SetWeight, - wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_BOLD); + FontModifier()(spanAttr.m_isBold, + font, &wxFont::SetWeight, + wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_BOLD); - DoApplyToFont(spanAttr.m_isItalic, font, &wxFont::SetStyle, - wxFONTSTYLE_NORMAL, wxFONTSTYLE_ITALIC); + FontModifier()(spanAttr.m_isItalic, + font, &wxFont::SetStyle, + wxFONTSTYLE_NORMAL, wxFONTSTYLE_ITALIC); - DoApplyToFont(spanAttr.m_isUnderlined, font, &wxFont::SetUnderlined, - false, true); + FontModifier()(spanAttr.m_isUnderlined, + font, &wxFont::SetUnderlined, + false, true); // TODO: No support for strike-through yet. @@ -191,28 +193,35 @@ private: OnAttrEnd(attr); } + // A helper class used to apply the given function to a wxFont object + // depending on the value of an OptionalBool. template - void - DoApplyToFont(wxMarkupSpanAttributes::OptionalBool isIt, - wxFont& font, - void (wxFont::*func)(T), - T noValue, - T yesValue) + struct FontModifier { - switch ( isIt ) - { - case wxMarkupSpanAttributes::Unspecified: - break; + FontModifier() { } - case wxMarkupSpanAttributes::No: - (font.*func)(noValue); - break; - - case wxMarkupSpanAttributes::Yes: - (font.*func)(yesValue); - break; + void operator()(wxMarkupSpanAttributes::OptionalBool isIt, + wxFont& font, + void (wxFont::*func)(T), + T noValue, + T yesValue) + { + switch ( isIt ) + { + case wxMarkupSpanAttributes::Unspecified: + break; + + case wxMarkupSpanAttributes::No: + (font.*func)(noValue); + break; + + case wxMarkupSpanAttributes::Yes: + (font.*func)(yesValue); + break; + } } - } + }; + wxStack m_attrs;