private ItemFormat GetItemFormat(object item) { IResource res = (IResource)item; lock ( _formatCache ) { ItemFormat format = (ItemFormat)_formatCache [item]; if (format == null) { if (res.HasProp(Core.Props.IsUnread)) { format = GetUnreadItemFormat(res); } else if (Core.FormattingRuleManager != null) { format = Core.FormattingRuleManager.GetFormattingInfo(res); } if (format == null) { format = _defaultItemFormat; } _formatCache [item] = format; } return(format); } }
public Color GetItemBackColor(object item) { ItemFormat format = GetItemFormat(item); if (format != null) { return(format.BackColor); } return(SystemColors.Window); }
public FontStyle GetItemFont(object item) { ItemFormat format = GetItemFormat(item); if (format != null) { return(format.FontStyle); } return(FontStyle.Regular); }
public static FormatCategory FormatToCategory(ItemFormat format) { lock (_dictFormatToCategory) { if (_dictFormatToCategory.Count == 0) { List <FieldInfo> listFields = typeof(ItemFormat).GetFields().ToList(); foreach (ItemFormat f in EnumUtils.GetAll <ItemFormat>()) { FieldInfo field = listFields.FirstOrDefault(x => x.Name == f.ToString()); ItemFormatAttribute attr = field?.GetCustomAttribute <ItemFormatAttribute>(); _dictFormatToCategory[f] = attr?.ListCategories?.FirstOrDefault() ?? FormatCategory.Unknown; } } _dictFormatToCategory.TryGetValue(format, out FormatCategory cate); return(cate); } }
public static string FormatToDisplay(ItemFormat format) { lock (_dictFormatToDisplay) { if (_dictFormatToDisplay.Count == 0) { List <FieldInfo> listFields = typeof(ItemFormat).GetFields().ToList(); foreach (ItemFormat f in EnumUtils.GetAll <ItemFormat>()) { FieldInfo field = listFields.FirstOrDefault(x => x.Name == f.ToString()); ItemFormatAttribute attr = field?.GetCustomAttribute <ItemFormatAttribute>(); _dictFormatToDisplay[f] = string.IsNullOrWhiteSpace(attr?.FormatDisplay) ? "Other" : attr.FormatDisplay; } } _dictFormatToDisplay.TryGetValue(format, out string display); return(display ?? ""); } }
private bool AddFormat(int length, ItemFormat itemFormat) { byte lengthByte = GetNumberOfLengthByte(length); if (lengthByte == 4) { return(false); } byte ret = (byte)((byte)itemFormat << 2 | lengthByte); msgData.Add(ret); for (byte b = (byte)lengthByte; b > 0; b--) { byte retLen = (byte)(length >> (b - 1) * 8 & 0xFF); msgData.Add(retLen); } return(true); }
private static ItemFormat GetRuleFormat(IResource rule) { ItemFormat fi = new ItemFormat(); if (rule.HasProp("IsBold")) { fi.FontStyle |= FontStyle.Bold; } if (rule.HasProp("IsItalic")) { fi.FontStyle |= FontStyle.Italic; } if (rule.HasProp("IsUnderline")) { fi.FontStyle |= FontStyle.Underline; } if (rule.HasProp("IsStrikeout")) { fi.FontStyle |= FontStyle.Strikeout; } if (rule.HasProp("ForeColor")) { fi.ForeColor = Utils.ColorFromString(rule.GetStringProp("ForeColor")); } else { fi.ForeColor = Color.Black; } if (rule.HasProp("BackColor")) { fi.BackColor = Utils.ColorFromString(rule.GetStringProp("BackColor")); } else { fi.BackColor = Color.White; } return(fi); }
internal ItemFormat GetUnreadItemFormat(IResource res) { ItemFormat itemFormat = null; if (Core.FormattingRuleManager != null) { itemFormat = Core.FormattingRuleManager.GetFormattingInfo(res); } if (itemFormat == null) { return(_unreadItemFormat); } ItemFormat unreadFormat = (ItemFormat)_unreadFormats [itemFormat]; if (unreadFormat == null) { unreadFormat = new ItemFormat(itemFormat.FontStyle | FontStyle.Bold, itemFormat.ForeColor, itemFormat.BackColor); _unreadFormats [itemFormat] = unreadFormat; } return(unreadFormat); }
public static String StyleDefinition(String name, Alignment horizontal, Border border, Color font, Boolean bold, Color background, ItemFormat format) { String style = "<Style ss:ID=\"" + name + "\">" + "\r\n" + CellAlignment(horizontal) + border.GetStringValue() + FontCell(font, bold) + Background(background); switch (format) { case ItemFormat.SmallDate: style += "<NumberFormat ss:Format=\"d/m/yy\\ h\\.mm;@\"/>" + "\r\n"; break; case ItemFormat.ExtendedDate: style += "<NumberFormat ss:Format=\"d/m/yy\\ h\\.mm;@\"/>" + "\r\n"; break; case ItemFormat.Time: style += "<NumberFormat ss:Format=\"[$-F400]h:mm:ss\\ AM/PM\"/>" + "\r\n"; break; } style += "\r\n" + "</Style>"; return(style); }
private HashMap _formatCache = new HashMap(); // IResource -> ItemFormat public ItemFormatCache() { _defaultItemFormat = new ItemFormat(FontStyle.Regular, SystemColors.WindowText, SystemColors.Window); _unreadItemFormat = new ItemFormat(FontStyle.Bold, SystemColors.WindowText, SystemColors.Window); }
} // Dummy constructor public MenuGenericItemModel(bool isLoop, ItemFormat funcFormat, FilterMatching funcFilter, Action <int, T> onSelect) { }