354 lines
9.9 KiB
C#
354 lines
9.9 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using CPF.Drawing;
|
|||
|
using CPF.ReoGrid.Rendering;
|
|||
|
using CPF.ReoGrid.Utility;
|
|||
|
|
|||
|
namespace CPF.ReoGrid
|
|||
|
{
|
|||
|
public class ControlAppearanceStyle
|
|||
|
{
|
|||
|
internal ReoGridControl CurrentControl { get; set; }
|
|||
|
|
|||
|
internal Dictionary<ControlAppearanceColors, Color> Colors
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return this.colors;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
this.colors = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool GetColor(ControlAppearanceColors colorKey, out Color color)
|
|||
|
{
|
|||
|
return this.colors.TryGetValue(colorKey, out color);
|
|||
|
}
|
|||
|
|
|||
|
public void SetColor(ControlAppearanceColors colorKey, Color color)
|
|||
|
{
|
|||
|
this.colors[colorKey] = color;
|
|||
|
ReoGridControl currentControl = this.CurrentControl;
|
|||
|
if (currentControl != null)
|
|||
|
{
|
|||
|
currentControl.ApplyControlStyle();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Color this[ControlAppearanceColors colorKey]
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
Color color;
|
|||
|
bool flag = this.colors.TryGetValue(colorKey, out color);
|
|||
|
Color result;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
result = color;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = Color.Black;
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
this.SetColor(colorKey, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool TryGetColor(ControlAppearanceColors key, out Color color)
|
|||
|
{
|
|||
|
return this.colors.TryGetValue(key, out color);
|
|||
|
}
|
|||
|
|
|||
|
public float SelectionBorderWidth { get; set; }
|
|||
|
|
|||
|
private ControlAppearanceStyle()
|
|||
|
{
|
|||
|
this.SelectionBorderWidth = 3f;
|
|||
|
}
|
|||
|
|
|||
|
public ControlAppearanceStyle(Color mainTheme, Color salientTheme, bool useSystemHighlight)
|
|||
|
{
|
|||
|
Color color = ColorUtility.LightColor(mainTheme);
|
|||
|
Color value = ColorUtility.LightLightColor(mainTheme);
|
|||
|
Color value2 = ColorUtility.LightLightLightColor(mainTheme);
|
|||
|
Color value3 = ColorUtility.DarkColor(mainTheme);
|
|||
|
Color value4 = ColorUtility.DarkDarkColor(mainTheme);
|
|||
|
Color color2 = ColorUtility.LightColor(salientTheme);
|
|||
|
Color value5 = ColorUtility.LightLightColor(salientTheme);
|
|||
|
Color value6 = ColorUtility.LightLightLightColor(salientTheme);
|
|||
|
Color color3 = ColorUtility.DarkColor(salientTheme);
|
|||
|
Color color4 = ColorUtility.DarkDarkColor(salientTheme);
|
|||
|
Color value7 = ColorUtility.ChangeColorBrightness(mainTheme, 0.5f);
|
|||
|
this.colors[ControlAppearanceColors.LeadHeadNormal] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.LeadHeadSelected] = value3;
|
|||
|
this.colors[ControlAppearanceColors.LeadHeadIndicatorStart] = value6;
|
|||
|
this.colors[ControlAppearanceColors.LeadHeadIndicatorEnd] = value5;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadSplitter] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadNormalStart] = value2;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadNormalEnd] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadSelectedStart] = value6;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadSelectedEnd] = salientTheme;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadFullSelectedStart] = value6;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadFullSelectedEnd] = value5;
|
|||
|
this.colors[ControlAppearanceColors.ColHeadText] = value4;
|
|||
|
this.colors[ControlAppearanceColors.RowHeadSplitter] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.RowHeadNormal] = value;
|
|||
|
this.colors[ControlAppearanceColors.RowHeadHover] = ColorUtility.DarkColor(mainTheme);
|
|||
|
this.colors[ControlAppearanceColors.RowHeadSelected] = color2;
|
|||
|
this.colors[ControlAppearanceColors.RowHeadFullSelected] = value5;
|
|||
|
this.colors[ControlAppearanceColors.RowHeadText] = value4;
|
|||
|
if (useSystemHighlight)
|
|||
|
{
|
|||
|
this.colors[ControlAppearanceColors.SelectionFill] = Color.FromColor(30, StaticResources.SystemColor_Highlight);
|
|||
|
this.colors[ControlAppearanceColors.SelectionBorder] = Color.FromColor(180, StaticResources.SystemColor_Highlight);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.colors[ControlAppearanceColors.SelectionFill] = ColorUtility.FromAlphaColor(30, color3);
|
|||
|
this.colors[ControlAppearanceColors.SelectionBorder] = ColorUtility.FromAlphaColor(180, color2);
|
|||
|
}
|
|||
|
this.colors[ControlAppearanceColors.GridBackground] = value7;
|
|||
|
this.colors[ControlAppearanceColors.GridLine] = ColorUtility.ChangeColorBrightness(mainTheme, 0.4f);
|
|||
|
this.colors[ControlAppearanceColors.GridText] = StaticResources.SystemColor_WindowText;
|
|||
|
this.colors[ControlAppearanceColors.OutlineButtonBorder] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.OutlinePanelBackground] = value;
|
|||
|
this.colors[ControlAppearanceColors.OutlinePanelBorder] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.OutlineButtonText] = color3;
|
|||
|
this.colors[ControlAppearanceColors.SheetTabBackground] = value;
|
|||
|
this.colors[ControlAppearanceColors.SheetTabText] = StaticResources.SystemColor_WindowText;
|
|||
|
this.colors[ControlAppearanceColors.SheetTabBorder] = mainTheme;
|
|||
|
this.colors[ControlAppearanceColors.SheetTabSelected] = value7;
|
|||
|
this.SelectionBorderWidth = 3f;
|
|||
|
}
|
|||
|
|
|||
|
internal Color GetColHeadStartColor(bool isHover, bool isSelected, bool isFullSelected, bool isInvalid)
|
|||
|
{
|
|||
|
Color result;
|
|||
|
if (isFullSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadFullSelectedStart];
|
|||
|
}
|
|||
|
else if (isSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadSelectedStart];
|
|||
|
}
|
|||
|
else if (isHover)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadHoverStart];
|
|||
|
}
|
|||
|
else if (isInvalid)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadInvalidStart];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadNormalStart];
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
internal Color GetColHeadEndColor(bool isHover, bool isSelected, bool isFullSelected, bool isInvalid)
|
|||
|
{
|
|||
|
Color result;
|
|||
|
if (isFullSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadFullSelectedEnd];
|
|||
|
}
|
|||
|
else if (isSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadSelectedEnd];
|
|||
|
}
|
|||
|
else if (isHover)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadHoverEnd];
|
|||
|
}
|
|||
|
else if (isInvalid)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadInvalidEnd];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.ColHeadNormalEnd];
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
internal Color GetRowHeadEndColor(bool isHover, bool isSelected, bool isFullSelected, bool isInvalid)
|
|||
|
{
|
|||
|
Color result;
|
|||
|
if (isFullSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.RowHeadFullSelected];
|
|||
|
}
|
|||
|
else if (isSelected)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.RowHeadSelected];
|
|||
|
}
|
|||
|
else if (isHover)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.RowHeadHover];
|
|||
|
}
|
|||
|
else if (isInvalid)
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.RowHeadInvalid];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = this.colors[ControlAppearanceColors.RowHeadNormal];
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public static ControlAppearanceStyle CreateDefaultControlStyle()
|
|||
|
{
|
|||
|
return new ControlAppearanceStyle
|
|||
|
{
|
|||
|
colors = new Dictionary<ControlAppearanceColors, Color>
|
|||
|
{
|
|||
|
{
|
|||
|
ControlAppearanceColors.LeadHeadNormal,
|
|||
|
Color.Lavender
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.LeadHeadSelected,
|
|||
|
Color.Lavender
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.LeadHeadIndicatorStart,
|
|||
|
Color.Gainsboro
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.LeadHeadIndicatorEnd,
|
|||
|
Color.Silver
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadSplitter,
|
|||
|
Color.LightSteelBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadNormalStart,
|
|||
|
Color.White
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadNormalEnd,
|
|||
|
Color.Lavender
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadHoverStart,
|
|||
|
Color.LightGoldenrodYellow
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadHoverEnd,
|
|||
|
Color.Goldenrod
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadSelectedStart,
|
|||
|
Color.LightGoldenrodYellow
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadSelectedEnd,
|
|||
|
Color.Goldenrod
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadFullSelectedStart,
|
|||
|
Color.WhiteSmoke
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadFullSelectedEnd,
|
|||
|
Color.LemonChiffon
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.ColHeadText,
|
|||
|
Color.DarkBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadSplitter,
|
|||
|
Color.LightSteelBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadNormal,
|
|||
|
Color.AliceBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadHover,
|
|||
|
Color.LightSteelBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadSelected,
|
|||
|
Color.PaleGoldenrod
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadFullSelected,
|
|||
|
Color.LemonChiffon
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.RowHeadText,
|
|||
|
Color.DarkBlue
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.GridText,
|
|||
|
Color.Black
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.GridBackground,
|
|||
|
Color.White
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.GridLine,
|
|||
|
Color.FromArgb(byte.MaxValue, 208, 215, 229)
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SelectionBorder,
|
|||
|
ColorUtility.FromAlphaColor(180, StaticResources.SystemColor_Highlight)
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SelectionFill,
|
|||
|
ColorUtility.FromAlphaColor(30, StaticResources.SystemColor_Highlight)
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.OutlineButtonBorder,
|
|||
|
Color.Black
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.OutlinePanelBackground,
|
|||
|
StaticResources.SystemColor_Control
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.OutlinePanelBorder,
|
|||
|
Color.Silver
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.OutlineButtonText,
|
|||
|
StaticResources.SystemColor_WindowText
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SheetTabText,
|
|||
|
StaticResources.SystemColor_WindowText
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SheetTabBorder,
|
|||
|
StaticResources.SystemColor_Highlight
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SheetTabBackground,
|
|||
|
Color.White
|
|||
|
},
|
|||
|
{
|
|||
|
ControlAppearanceColors.SheetTabSelected,
|
|||
|
StaticResources.SystemColor_Window
|
|||
|
}
|
|||
|
},
|
|||
|
SelectionBorderWidth = 3f
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
private Dictionary<ControlAppearanceColors, Color> colors = new Dictionary<ControlAppearanceColors, Color>(100);
|
|||
|
}
|
|||
|
}
|