private Image FromXImage(IXImage img) { using (var str = new MemoryStream(img.Buffer)) { return(Image.FromStream(str)); } }
private void TryCreateIcons(IIconsCreator iconsConverter) { IXImage icon = null; this.GetType().TryGetAttribute <IconAttribute>(a => { icon = a.Icon; }); if (icon == null) { icon = Defaults.Icon; } //TODO: create different icons for highlighted and suppressed var regular = icon; var highlighted = icon; var suppressed = icon; //Creation of icons may fail if user doesn't have write permissions or icon is locked try { iconsConverter.ConvertIcon(new MacroFeatureIcon(icon, MacroFeatureIconInfo.RegularName)); iconsConverter.ConvertIcon(new MacroFeatureIcon(highlighted, MacroFeatureIconInfo.HighlightedName)); iconsConverter.ConvertIcon(new MacroFeatureIcon(suppressed, MacroFeatureIconInfo.SuppressedName)); iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(icon, MacroFeatureIconInfo.RegularName)); iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(highlighted, MacroFeatureIconInfo.HighlightedName)); iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(suppressed, MacroFeatureIconInfo.SuppressedName)); } catch (Exception ex) { Logger.Log(ex); } }
internal static IXImage GetCommandIcon(this CommandItemInfo info, IIconsProvider[] iconsProviders) { IXImage icon = null; try { var provider = iconsProviders.FirstOrDefault(p => p.Matches(info.IconPath)); if (provider != null) { icon = provider.GetIcon(info.IconPath); } } catch { } if (icon == null) { if (info is CommandMacroInfo) { icon = new ImageEx(ImageIcon.ImageToByteArray(Resources.macro_icon_default), Resources.macro_vector); } else if (info is CommandGroupInfo) { icon = new ImageEx(ImageIcon.ImageToByteArray(Resources.group_icon_default), Resources.macros_vector); } } return(icon); }
private void GetControlAttribution(Type ctrlType, out string title, out IXImage icon) { title = ""; if (ctrlType.TryGetAttribute(out DisplayNameAttribute att)) { title = att.DisplayName; } if (string.IsNullOrEmpty(title)) { title = ctrlType.Name; } icon = null; if (ctrlType.TryGetAttribute(out IconAttribute iconAtt)) { icon = iconAtt.Icon; } if (icon == null) { icon = Defaults.Icon; } }
internal static Image FromXImage(IXImage img) { using (var str = new MemoryStream(img.Buffer)) { return(Image.FromStream(str)); } }
/// <summary> /// Icon size constructor with source image, target size and optional base name /// </summary> /// <param name="srcImage">Source image</param> /// <param name="targetSize">Target size of the image</param> /// <param name="baseName">Base name of the image</param> internal IconSpec(IXImage srcImage, Size targetSize, int offset = 0, string baseName = "") { SourceImage = srcImage; TargetSize = targetSize; Offset = offset; Name = CreateFileName(baseName, targetSize); }
internal static TWrapper HostControl <TWrapper>(Type ctrlType, Func <object, System.Windows.Forms.Control, string, IXImage, TWrapper> ctrlHost, Func <string, string, IXImage, TWrapper> comCtrlHost) { var title = ""; if (ctrlType.TryGetAttribute(out DisplayNameAttribute att)) { title = att.DisplayName; } if (string.IsNullOrEmpty(title)) { title = ctrlType.Name; } IXImage icon = null; if (ctrlType.TryGetAttribute(out IconAttribute iconAtt)) { icon = iconAtt.Icon; } if (icon == null) { icon = Defaults.Icon; } if (typeof(System.Windows.Forms.Control).IsAssignableFrom(ctrlType)) { if (typeof(System.Windows.Forms.UserControl).IsAssignableFrom(ctrlType) && ctrlType.IsComVisible()) { return(comCtrlHost.Invoke(ctrlType.GetProgId(), title, icon)); } else { var winCtrl = (System.Windows.Forms.Control)Activator.CreateInstance(ctrlType); return(ctrlHost.Invoke(winCtrl, winCtrl, title, icon)); } } else if (typeof(System.Windows.UIElement).IsAssignableFrom(ctrlType)) { var wpfCtrl = (System.Windows.UIElement)Activator.CreateInstance(ctrlType); var host = new System.Windows.Forms.Integration.ElementHost(); host.Child = wpfCtrl; return(ctrlHost.Invoke(wpfCtrl, host, title, icon)); } else { throw new NotSupportedException($"Only {typeof(System.Windows.Forms.Control).FullName} or {typeof(System.Windows.UIElement).FullName} are supported"); } }
/// <inheritdoc/> public string[] ConvertIconsGroup(IIcon[] icons) { if (icons == null || !icons.Any()) { throw new ArgumentNullException(nameof(icons)); } IIconSpec[,] iconsDataGroup = null; var transparencyKey = icons.First().TransparencyKey; for (int i = 0; i < icons.Length; i++) { if (icons[i].TransparencyKey != transparencyKey) { throw new IconTransparencyMismatchException(i); } var data = icons[i].GetIconSizes().ToArray(); if (iconsDataGroup == null) { iconsDataGroup = new IIconSpec[data.Length, icons.Length]; } for (int j = 0; j < data.Length; j++) { iconsDataGroup[j, i] = data[j]; } } var iconsPaths = new string[iconsDataGroup.GetLength(0)]; for (int i = 0; i < iconsDataGroup.GetLength(0); i++) { var imgs = new IXImage[iconsDataGroup.GetLength(1)]; for (int j = 0; j < iconsDataGroup.GetLength(1); j++) { imgs[j] = iconsDataGroup[i, j].SourceImage; } iconsPaths[i] = Path.Combine(IconsFolder, iconsDataGroup[i, 0].Name); CreateBitmap(imgs, iconsPaths[i], iconsDataGroup[i, 0].TargetSize, iconsDataGroup[i, 0].Offset, transparencyKey, iconsDataGroup[i, 0].Mask); } return(iconsPaths); }
public IconExAttribute(Type resType, string svgResName, string imgResName) { var img = ResourceHelper.GetResource <Image>(resType, imgResName); byte[] imgBuffer = null; using (var ms = new MemoryStream()) { img.Save(ms, img.RawFormat); imgBuffer = ms.ToArray(); } var svgBuffer = ResourceHelper.GetResource <byte[]>(resType, svgResName); Icon = new ImageEx(imgBuffer, svgBuffer); }
protected override string HostNetControl(Control winCtrlHost, TControl ctrl, string title, IXImage image) { using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>()) { var imgPath = iconsConv.ConvertIcon(new FeatMgrViewIcon(image)).First(); if (m_CtrlProvider.ProvideNetControl(m_ModelViewMgr, winCtrlHost, title)) { return(title); } else { throw new NetControlHostException(winCtrlHost.Handle); } } }
protected override ITaskpaneView HostComControl(string progId, string title, IXImage image, out TControl specCtrl) { using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>()) { var taskPaneView = CreateTaskPaneView(iconsConv, image, title); specCtrl = (TControl)m_ControlProvider.ProvideComControl(taskPaneView, progId); if (specCtrl == null) { throw new ComControlHostException(progId); } return(taskPaneView); } }
private ITaskpaneView CreateTaskPaneView(IIconsCreator iconConv, IXImage icon, string title) { if (icon == null) { if (Spec.Icon != null) { icon = Spec.Icon; } } if (string.IsNullOrEmpty(title)) { title = Spec.Title; } ITaskpaneView taskPaneView; if (m_App.Sw.SupportsHighResIcons(CompatibilityUtils.HighResIconsScope_e.TaskPane)) { string[] taskPaneIconImages = null; if (icon != null) { taskPaneIconImages = iconConv.ConvertIcon(new TaskPaneHighResIcon(icon)); } taskPaneView = m_App.Sw.CreateTaskpaneView3(taskPaneIconImages, title); } else { var taskPaneIconImage = ""; if (icon != null) { taskPaneIconImage = iconConv.ConvertIcon(new TaskPaneIcon(icon)).First(); } taskPaneView = m_App.Sw.CreateTaskpaneView2(taskPaneIconImage, title); } LoadButtons(taskPaneView, m_App.Sw); return(taskPaneView); }
protected override string HostComControl(string progId, string title, IXImage image, out TControl specCtrl) { using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>()) { var imgPath = iconsConv.ConvertIcon(new FeatMgrViewIcon(image)).First(); specCtrl = (TControl)m_CtrlProvider.ProvideComControl(m_ModelViewMgr, progId, title); if (specCtrl != null) { return(title); } else { throw new ComControlHostException(progId); } } }
protected override void SetSpecificValue(Image value) { IXImage img = null; if (value == null) { img = Defaults.Icon; } else { img = ResourceHelper.FromBytes(ImageToByteArray(value)); } var icons = m_IconsConv.ConvertIcon(new ControlIcon(img, m_Size)); SwSpecificControl.SetBitmapByName(icons[0], icons[1]); m_Image = value; }
private BitmapImage ConvertImage(IXImage img) { try { if (img != null && img.Buffer != null) { using (var memStr = new MemoryStream(img.Buffer)) { memStr.Seek(0, SeekOrigin.Begin); return(Image.FromStream(memStr).ToBitmapImage()); } } else { return(null); } } catch { return(null); } }
internal static IXImage GetCommandIcon(this CommandItemInfo info, IIconsProvider[] iconsProviders, IFilePathResolver pathResolver, string workDir) { IXImage icon = null; try { if (!string.IsNullOrEmpty(info.IconPath)) { var iconPath = pathResolver.Resolve(info.IconPath, workDir); var provider = iconsProviders.FirstOrDefault(p => p.Matches(iconPath)); if (provider != null) { icon = provider.GetIcon(iconPath); } } } catch { } if (icon == null) { if (info is CommandMacroInfo) { icon = new ImageEx(Resources.macro_icon_default.GetBytes(), Resources.macro_vector); } else if (info is CommandGroupInfo) { icon = new ImageEx(Resources.group_icon_default.GetBytes(), Resources.macros_vector); } } return(icon); }
public PropertyInfoControlDescriptor(PropertyInfo prpInfo) { m_PrpInfo = prpInfo; var customAtts = m_PrpInfo.GetCustomAttributes(true) ?? new object[0]; DisplayName = customAtts.OfType <DisplayNameAttribute>().FirstOrDefault()?.DisplayName; if (string.IsNullOrEmpty(DisplayName)) { DisplayName = m_PrpInfo.PropertyType.GetCustomAttribute <DisplayNameAttribute>(true)?.DisplayName; } Description = customAtts.OfType <DescriptionAttribute>().FirstOrDefault()?.Description; if (string.IsNullOrEmpty(Description)) { Description = m_PrpInfo.PropertyType.GetCustomAttribute <DescriptionAttribute>(true)?.Description; } Icon = customAtts.OfType <IconAttribute>().FirstOrDefault()?.Icon; Attributes = customAtts?.OfType <IAttribute>().ToArray(); }
protected virtual Image CreateImage(IXImage icon, Size size, ColorMaskDelegate mask, Color background) { var img = FromXImage(icon); if (mask != null) { img = ReplaceColor(img, mask); } else { void ConflictingBackgroundPixelMask(ref byte r, ref byte g, ref byte b, ref byte a) { if (r == background.R && g == background.G && b == background.B && a == background.A) { b = (byte)((b == 0) ? 1 : (b - 1)); } } img = ReplaceColor(img, ConflictingBackgroundPixelMask); } return(img); }
internal BitmapButtonIcon(IXImage icon, int width, int height) { Icon = icon; m_Width = width; m_Height = height; }
internal ControlIcon(IXImage icon) : this(icon, new Size(24, 24)) { }
protected override ITaskpaneView HostNetControl(Control winCtrlHost, TControl ctrl, string title, IXImage image) { using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>()) { var taskPaneView = CreateTaskPaneView(iconsConv, image, title); if (!m_ControlProvider.ProvideNetControl(taskPaneView, winCtrlHost)) { throw new NetControlHostException(winCtrlHost.Handle); } return(taskPaneView); } }
internal ControlIcon(IXImage icon, Size size) { Icon = icon; m_Size = size; }
/// <param name="resType">Type of the static class (usually Resources)</param> /// <param name="masterResName">Resource name of the master icon</param> public IconAttribute(Type resType, string masterResName) { Icon = ResourceHelper.GetResource <IXImage>(resType, masterResName); }
/// <summary> /// Constructor to be used in dynamic controls /// </summary> /// <param name="icon"></param> public IconAttribute(IXImage icon) { Icon = icon; }
internal MacroFeatureSuppressedHighResIcon(IXImage icon, string baseName) : base(icon, baseName) { }
internal FeatMgrViewIcon(IXImage icon) { m_Icon = icon; }
internal TabIcon(IXImage icon) { Icon = icon; }
internal CommandGroupIcon(IXImage icon) { m_Icon = icon; }
internal BitmapButtonHighResIcon(IXImage icon, int width, int height) : base(icon, width, height) { }
internal MacroFeatureIcon(IXImage icon, string baseName) { m_BaseName = baseName; m_Icon = icon; }