]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/private/markupparserattr.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / private / markupparserattr.h
index 8f078efb7da25ae5e150fe461dd9e4c8f0246e1a..d433879daf8e89af0b45303d900b9fb9da322bb3 100644 (file)
@@ -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 <vadim@wxwidgets.org>
 // 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<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.
 
@@ -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 <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;