SvgStyleableElement.cs :  » GUI » SharpVectorGraphics » SharpVectors » Dom » Svg » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SharpVectorGraphics 
SharpVectorGraphics » SharpVectors » Dom » Svg » SvgStyleableElement.cs
using System;
using System.Xml;
using System.Collections;
using System.Text.RegularExpressions;
using System.Diagnostics;
using SharpVectors.Dom.Css;



namespace SharpVectors.Dom.Svg{
  /// <summary>
  /// SvgStyleableElement is an extension to the Svg DOM to create a class for all elements that are styleable.
  /// </summary>
  public class SvgStyleableElement : SvgElement, ISvgStylable
  {
    #region Private static fields
    private static Regex isImportant = new Regex(@"!\s*important$");
    #endregion

    #region Private Fields
    private Hashtable styleProperties = new Hashtable();
    
    #endregion

    #region Constructors
    internal SvgStyleableElement(string prefix, string localname, string ns, SvgDocument doc) : base(prefix, localname, ns, doc) 
    {
    }
    #endregion

    #region Implementation of ISvgStylable
    #region ClassName
    private ISvgAnimatedString className;
    public ISvgAnimatedString ClassName
    {
      get
      {
        if(className == null)
        {
          className = new SvgAnimatedString(GetAttribute("class", String.Empty));
        }
        return className;
      }
    }
    #endregion

    #region PresentationAttributes
    private Hashtable presentationAttributes = new Hashtable();
    public ICssValue GetPresentationAttribute(string name)
    {
      if(!presentationAttributes.ContainsKey(name))
      {
        ICssValue result;
        string attValue = GetAttribute(name, String.Empty).Trim();
        if(attValue != null && attValue.Length > 0)
        {
          if(isImportant.IsMatch(attValue))
          {
            result = null;
          }
          else
          {
            result = CssValue.GetCssValue(attValue, false);
          }
        }
        else
        {
          result = null;
        }
        presentationAttributes[name] = result;

      }
      return presentationAttributes[name] as ICssValue;
    }
    #endregion
    #endregion

    #region GetValues
    public string GetPropertyValue(string name)
    {
      return GetComputedStyle(String.Empty).GetPropertyValue(name);
    }

    public string GetPropertyValue(string name1, string name2)
    {
      string cssString = GetComputedStyle(String.Empty).GetPropertyValue(name1);
      if(cssString == null)
      {
        cssString = GetComputedStyle(String.Empty).GetPropertyValue(name2);
      }

      return cssString;
    }

    public override ICssStyleDeclaration GetComputedStyle(string pseudoElt)
    {
      if(cachedCSD == null)
      {
        CssCollectedStyleDeclaration csd = (CssCollectedStyleDeclaration)base.GetComputedStyle(pseudoElt);
        
        IEnumerator cssPropNames = OwnerDocument.CssPropertyProfile.GetAllPropertyNames().GetEnumerator();
        while(cssPropNames.MoveNext())
        {
          string cssPropName = (string)cssPropNames.Current;
          CssValue cssValue = (CssValue)GetPresentationAttribute(cssPropName);
          if(cssValue != null)
          {
            csd.CollectProperty(cssPropName, 0, cssValue, CssStyleSheetType.NonCssPresentationalHints, String.Empty);
          }
        }

        cachedCSD = csd;
      }
      return cachedCSD;
    }    
    
    #endregion

    #region Update handling
    public override void HandleAttributeChange(XmlAttribute attribute)
    {
      
      if(attribute.NamespaceURI.Length == 0)
      {
        string localName = attribute.LocalName;
        if(presentationAttributes.ContainsKey(localName))
        {
          presentationAttributes.Remove(localName);                    
        }

        switch(attribute.LocalName)
        {
          case "class":
            className = null;
            // class changes need to propogate to children and invalidate CSS
            break;
        }
      }
      base.HandleAttributeChange(attribute);
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.