Beispiel #1
0
        /// <summary>
        /// Checks whether a style component in the style manager is used by a style
        /// </summary>
        /// <param name="component">Component to check</param>
        /// <returns>If true, the component is in use</returns>
        private bool IsUsedByStyle(AbstractStyle component)
        {
            Style s;
            bool  match = false;
            int   hash  = component.GetHashCode();
            int   len   = styles.Count;

            for (int i = 0; i < len; i++)
            {
                s = (Style)styles[i];
                if (component.GetType() == typeof(Style.Border))
                {
                    if (s.CurrentBorder.GetHashCode() == hash)
                    {
                        match = true; break;
                    }
                }
                else if (component.GetType() == typeof(Style.CellXf))
                {
                    if (s.CurrentCellXf.GetHashCode() == hash)
                    {
                        match = true; break;
                    }
                }
                if (component.GetType() == typeof(Style.Fill))
                {
                    if (s.CurrentFill.GetHashCode() == hash)
                    {
                        match = true; break;
                    }
                }
                if (component.GetType() == typeof(Style.Font))
                {
                    if (s.CurrentFont.GetHashCode() == hash)
                    {
                        match = true; break;
                    }
                }
                if (component.GetType() == typeof(Style.NumberFormat))
                {
                    if (s.CurrentNumberFormat.GetHashCode() == hash)
                    {
                        match = true; break;
                    }
                }
            }
            return(match);
        }
        /// <summary>
        /// Adds a style component and determines the appropriate type of it automatically
        /// </summary>
        /// <param name="component">Style component to add to the collections</param>
        /// <exception cref="StyleException">Throws a StyleException if an unknown style component type was passed</exception>

        public void AddStyleComponent(AbstractStyle component)
        {
            Type t = component.GetType();

            if (t == typeof(CellXf))
            {
                cellXfs.Add(component as CellXf);
            }
            else if (t == typeof(NumberFormat))
            {
                numberFormats.Add(component as NumberFormat);
            }
            else if (t == typeof(Style))
            {
                styles.Add(component as Style);
            }
            else if (t == typeof(Border))
            {
                borders.Add(component as Border);
            }
            else if (t == typeof(Fill))
            {
                fills.Add(component as Fill);
            }
            else if (t == typeof(Font))
            {
                fonts.Add(component as Font);
            }
            else
            {
                throw new StyleException(StyleException.GENERAL, "The style definition of the type '" + t.ToString() + "' is unknown or not implemented yet");
            }
        }
Beispiel #3
0
 /// <summary>
 /// Adds a style component to a style
 /// </summary>
 /// <param name="baseStyle">Style to append a component</param>
 /// <param name="newComponent">Component to add to the baseStyle</param>
 /// <returns>Returns the managed style of the style manager</returns>
 public Style AddStyleComponent(Style baseStyle, AbstractStyle newComponent)
 {
     if (newComponent.GetType() == typeof(Border))
     {
         baseStyle.CurrentBorder = (Border)newComponent;
     }
     else if (newComponent.GetType() == typeof(CellXf))
     {
         baseStyle.CurrentCellXf = (CellXf)newComponent;
     }
     else if (newComponent.GetType() == typeof(Fill))
     {
         baseStyle.CurrentFill = (Fill)newComponent;
     }
     else if (newComponent.GetType() == typeof(Font))
     {
         baseStyle.CurrentFont = (Font)newComponent;
     }
     else if (newComponent.GetType() == typeof(NumberFormat))
     {
         baseStyle.CurrentNumberFormat = (NumberFormat)newComponent;
     }
     return(styleManager.AddStyle(baseStyle));
 }
Beispiel #4
0
        /// <summary>
        /// Adds a style component to the manager
        /// </summary>
        /// <param name="style">Component to add</param>
        /// <returns>Hash of the added or determined component</returns>
        private int AddStyleComponent(AbstractStyle style)
        {
            int hash = style.GetHashCode();

            if (style.GetType() == typeof(Style.Border))
            {
                if (GetComponentByHash(ref borders, hash) == null)
                {
                    borders.Add(style);
                }
                Reorganize(ref borders);
            }
            else if (style.GetType() == typeof(Style.CellXf))
            {
                if (GetComponentByHash(ref cellXfs, hash) == null)
                {
                    cellXfs.Add(style);
                }
                Reorganize(ref cellXfs);
            }
            else if (style.GetType() == typeof(Style.Fill))
            {
                if (GetComponentByHash(ref fills, hash) == null)
                {
                    fills.Add(style);
                }
                Reorganize(ref fills);
            }
            else if (style.GetType() == typeof(Style.Font))
            {
                if (GetComponentByHash(ref fonts, hash) == null)
                {
                    fonts.Add(style);
                }
                Reorganize(ref fonts);
            }
            else if (style.GetType() == typeof(Style.NumberFormat))
            {
                if (GetComponentByHash(ref numberFormats, hash) == null)
                {
                    numberFormats.Add(style);
                }
                Reorganize(ref numberFormats);
            }
            else if (style.GetType() == typeof(Style))
            {
                Style s = (Style)style;
                if (styleNames.Contains(s.Name) == true)
                {
                    throw new StyleException("StyleAlreadyExistsException", "The style with the name '" + s.Name + "' already exists");
                }
                if (GetComponentByHash(ref styles, hash) == null)
                {
                    int?id;
                    if (s.InternalID.HasValue == false)
                    {
                        id           = int.MaxValue;
                        s.InternalID = id;
                    }
                    else
                    {
                        id = s.InternalID.Value;
                    }
                    int temp = AddStyleComponent(s.CurrentBorder, id);
                    s.CurrentBorder       = (Style.Border)GetComponentByHash(ref borders, temp);
                    temp                  = AddStyleComponent(s.CurrentCellXf, id);
                    s.CurrentCellXf       = (Style.CellXf)GetComponentByHash(ref cellXfs, temp);
                    temp                  = AddStyleComponent(s.CurrentFill, id);
                    s.CurrentFill         = (Style.Fill)GetComponentByHash(ref fills, temp);
                    temp                  = AddStyleComponent(s.CurrentFont, id);
                    s.CurrentFont         = (Style.Font)GetComponentByHash(ref fonts, temp);
                    temp                  = AddStyleComponent(s.CurrentNumberFormat, id);
                    s.CurrentNumberFormat = (Style.NumberFormat)GetComponentByHash(ref numberFormats, temp);
                    styles.Add(s);
                }
                Reorganize(ref styles);
                hash = s.GetHashCode();
            }
            return(hash);
        }