// 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 <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
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(); }
if ( !spanAttr.m_fontFace.empty() )
font.SetFaceName(spanAttr.m_fontFace);
- DoApplyToFont<wxFontWeight>(spanAttr.m_isBold, font, &wxFont::SetWeight,
- wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_BOLD);
+ FontModifier<wxFontWeight>()(spanAttr.m_isBold,
+ font, &wxFont::SetWeight,
+ wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_BOLD);
- DoApplyToFont<wxFontStyle>(spanAttr.m_isItalic, font, &wxFont::SetStyle,
- wxFONTSTYLE_NORMAL, wxFONTSTYLE_ITALIC);
+ FontModifier<wxFontStyle>()(spanAttr.m_isItalic,
+ font, &wxFont::SetStyle,
+ wxFONTSTYLE_NORMAL, wxFONTSTYLE_ITALIC);
- DoApplyToFont(spanAttr.m_isUnderlined, font, &wxFont::SetUnderlined,
- false, true);
+ FontModifier<bool>()(spanAttr.m_isUnderlined,
+ font, &wxFont::SetUnderlined,
+ false, true);
// TODO: No support for strike-through yet.
OnAttrEnd(attr);
}
+ // A helper class used to apply the given function to a wxFont object
+ // depending on the value of an OptionalBool.
template <typename T>
- 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<Attr> m_attrs;