Beispiel #1
0
        internal int           Index; //stores at 1 the first entry, that is biff8 entry 8.

        internal bool ColorIsValid(TExcelColor aColor, IFlexCelPalette xls)
        {
            int RealIndex = Index < 1 ? Index + 8 : Index;

            if (RealIndex <= 0 || RealIndex > 56)
            {
                return(false);
            }
            if (LastColorStored != aColor)
            {
                return(false);
            }
            Color c = xls.GetColorPalette(RealIndex);

            //If the color is Theme, it could have changed if the theme palette changed.
            if (aColor.ColorType == TColorType.Theme)
            {
                if (xls.GetColorTheme(aColor.Theme) != LastColorInTheme)
                {
                    return(false);
                }
            }

            return(c.ToArgb() == LastColorInPalette);
        }
Beispiel #2
0
        internal int GetBiff8ColorIndex(IFlexCelPalette xls, TAutomaticColor autoType)
        {
            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            switch (ColorType)
            {
            case TColorType.RGB:
                unchecked
                {
                    Color cRGB = ColorUtil.FromArgb((int)((uint)(0xFF000000 | FRGB)));
                    return(xls.NearestColorIndex(ApplyTint(cRGB)) - 1 + 8);      // nearestcolorindex returns 1-based
                }

            case TColorType.Automatic:
                return(GetAutomaticColorIndex(autoType));

            case TColorType.Theme:
                return(xls.NearestColorIndex(ApplyTint(xls.GetColorTheme(FTheme).ToColor(xls))) - 1 + 8);

            case TColorType.Indexed:
                return(FIndex - 1 + 8);     //findex is 1-based too.
            }

            return(1);
        }
Beispiel #3
0
        internal int GetBiff8ColorIndex(IFlexCelPalette xls, TAutomaticColor autoType, ref TColorIndexCache IndexCache)
        {
            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            if (IndexCache.ColorIsValid(this, xls))
            {
                return(IndexCache.Index - 1 + 8);
            }

            int ColorIndex = GetBiff8ColorIndex(xls, autoType);

            IndexCache.LastColorStored    = this;
            IndexCache.LastColorInPalette = ToColor(xls).ToArgb();
            IndexCache.Index = ColorIndex + 1 - 8; //IndexCache is the same base as index.
            if (ColorType == TColorType.Theme)
            {
                IndexCache.LastColorInTheme = xls.GetColorTheme(Theme);
            }

            return(ColorIndex);
        }
Beispiel #4
0
        /// <summary>
        /// Returns the value of this class as a system color.
        /// </summary>
        /// <param name="xls">Excel file containing the themes and palettes for the color indexes.</param>
        /// <param name="automaticColor">Color to be returned if this structure has an automatic color.</param>
        /// <returns></returns>
        public Color ToColor(IFlexCelPalette xls, Color automaticColor)
        {
            if (automaticColor != ColorUtil.Empty && IsAutomatic)
            {
                return(ApplyTint(automaticColor));
            }

            if (xls == null)
            {
                xls = TDummyFlexCelPalette.Instance;
            }
            Color Result = automaticColor;

            switch (ColorType)
            {
            case TColorType.RGB:
                unchecked
                {
                    Result = ColorUtil.FromArgb((int)((uint)(0xFF000000 | FRGB)));
                }
                break;

            case TColorType.Automatic:
                Result = GetAutomaticRGB();
                break;

            case TColorType.Theme:
                Result = xls.GetColorTheme(FTheme).ToColor(xls);
                break;

            case TColorType.Indexed:
                Result = xls.GetColorPalette(Index);
                break;
            }

            return(ApplyTint(Result));
        }