Ejemplo n.º 1
0
 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);
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
 internal static Image FromXImage(IXImage img)
 {
     using (var str = new MemoryStream(img.Buffer))
     {
         return(Image.FromStream(str));
     }
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        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");
            }
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
                }
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
                }
            }
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
 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);
     }
 }
Ejemplo n.º 16
0
        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();
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
 internal BitmapButtonIcon(IXImage icon, int width, int height)
 {
     Icon     = icon;
     m_Width  = width;
     m_Height = height;
 }
Ejemplo n.º 20
0
 internal ControlIcon(IXImage icon)
     : this(icon, new Size(24, 24))
 {
 }
Ejemplo n.º 21
0
        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);
            }
        }
Ejemplo n.º 22
0
 internal ControlIcon(IXImage icon, Size size)
 {
     Icon   = icon;
     m_Size = size;
 }
Ejemplo n.º 23
0
 /// <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);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor to be used in dynamic controls
 /// </summary>
 /// <param name="icon"></param>
 public IconAttribute(IXImage icon)
 {
     Icon = icon;
 }
Ejemplo n.º 25
0
 internal MacroFeatureSuppressedHighResIcon(IXImage icon, string baseName) : base(icon, baseName)
 {
 }
Ejemplo n.º 26
0
 internal FeatMgrViewIcon(IXImage icon)
 {
     m_Icon = icon;
 }
Ejemplo n.º 27
0
 internal TabIcon(IXImage icon)
 {
     Icon = icon;
 }
Ejemplo n.º 28
0
 internal CommandGroupIcon(IXImage icon)
 {
     m_Icon = icon;
 }
Ejemplo n.º 29
0
 internal BitmapButtonHighResIcon(IXImage icon, int width, int height)
     : base(icon, width, height)
 {
 }
Ejemplo n.º 30
0
 internal MacroFeatureIcon(IXImage icon, string baseName)
 {
     m_BaseName = baseName;
     m_Icon     = icon;
 }