protected override PropertyManagerPageBitmapButtonControl CreateControl( IPropertyManagerPageBitmapButton swCtrl, IAttributeSet atts, SwPropertyManagerPageHandler handler, short height) { var bmpAtt = atts.Get <BitmapButtonAttribute>(); if (bmpAtt.StandardIcon.HasValue) { swCtrl.SetStandardBitmaps((int)bmpAtt.StandardIcon.Value); } else { var bmpWidth = bmpAtt.Width; var bmpHeight = bmpAtt.Height; var icon = AdjustIcon(IconsConverter.FromXImage(bmpAtt.Icon ?? Defaults.Icon), bmpWidth, bmpHeight); if (m_App.IsVersionNewerOrEqual(Enums.SwVersion_e.Sw2016)) { var icons = m_IconsConv.ConvertIcon(new BitmapButtonHighResIcon(icon, bmpWidth, bmpHeight)); var imgList = icons.Take(6).ToArray(); var maskImgList = icons.Skip(6).ToArray(); swCtrl.SetBitmapsByName3(imgList, maskImgList); } else { var icons = m_IconsConv.ConvertIcon(new BitmapButtonIcon(icon, bmpWidth, bmpHeight)); swCtrl.SetBitmapsByName2(icons[0], icons[1]); } } return(new PropertyManagerPageBitmapButtonControl(atts.Id, atts.Tag, swCtrl, handler)); }
private void CreateIcons(CommandGroup cmdGroup, CommandGroupSpec cmdBar, IconsConverter iconsConv) { var mainIcon = cmdBar.Icon; if (mainIcon == null) { mainIcon = Defaults.Icon; } Image[] iconList = null; if (cmdBar.Commands != null) { iconList = cmdBar.Commands.Select(c => IconsConverter.FromXImage(c.Icon ?? Defaults.Icon)).ToArray(); } //NOTE: if commands are not used, main icon will fail if toolbar commands image list is not specified, so it is required to specify it explicitly if (CompatibilityUtils.SupportsHighResIcons(m_App.Sw, CompatibilityUtils.HighResIconsScope_e.CommandManager)) { var iconsList = iconsConv.ConvertIcon(new CommandGroupHighResIcon(IconsConverter.FromXImage(mainIcon))); cmdGroup.MainIconList = iconsList; if (iconList != null && iconList.Any()) { cmdGroup.IconList = iconsConv.ConvertIconsGroup( iconList.Select(i => new CommandGroupHighResIcon(i)).ToArray()); } else { cmdGroup.IconList = iconsList; } } else { var mainIconPath = iconsConv.ConvertIcon(new CommandGroupIcon(IconsConverter.FromXImage(mainIcon))); var smallIcon = mainIconPath[0]; var largeIcon = mainIconPath[1]; cmdGroup.SmallMainIcon = smallIcon; cmdGroup.LargeMainIcon = largeIcon; if (iconList != null && iconList.Any()) { var iconListPath = iconsConv.ConvertIconsGroup(iconList.Select(i => new CommandGroupIcon(i)).ToArray()); var smallIconList = iconListPath[0]; var largeIconList = iconListPath[1]; cmdGroup.SmallIconList = smallIconList; cmdGroup.LargeIconList = largeIconList; } else { cmdGroup.SmallIconList = smallIcon; cmdGroup.LargeIconList = largeIcon; } } }
private void CreateIcons(CommandGroup cmdGroup, ICommandGroupSpec cmdBar, IconsConverter iconsConv) { var mainIcon = cmdBar.Icon; CommandGroupIcon[] iconList = null; if (cmdBar.Commands != null) { iconList = cmdBar.Commands.Select(c => c.Icon).ToArray(); } //NOTE: if commands are not used, main icon will fail if toolbar commands image list is not specified, so it is required to specify it explicitly if (App.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.CommandManager)) { var iconsList = iconsConv.ConvertIcon(mainIcon, true); cmdGroup.MainIconList = iconsList; if (iconList != null && iconList.Any()) { cmdGroup.IconList = iconsConv.ConvertIconsGroup(iconList, true); } else { cmdGroup.IconList = iconsList; } } else { var mainIconPath = iconsConv.ConvertIcon(mainIcon, false); var smallIcon = mainIconPath[0]; var largeIcon = mainIconPath[1]; cmdGroup.SmallMainIcon = smallIcon; cmdGroup.LargeMainIcon = largeIcon; if (iconList != null && iconList.Any()) { var iconListPath = iconsConv.ConvertIconsGroup(iconList, true); var smallIconList = iconListPath[0]; var largeIconList = iconListPath[1]; cmdGroup.SmallIconList = smallIconList; cmdGroup.LargeIconList = largeIconList; } else { cmdGroup.SmallIconList = smallIcon; cmdGroup.LargeIconList = largeIcon; } } }
private void CreateIcons(CommandGroup cmdGroup, Type cmdGroupType, Enum[] cmds, IconsConverter iconsConv) { IIcon mainIcon = null; if (!cmdGroupType.TryGetAttribute <IconAttribute>(a => mainIcon = a.Icon)) { //TODO: add default icon mainIcon = new MasterIcon() { Icon = new System.Drawing.Bitmap(12, 12) }; } var iconList = cmds.Select(c => { IIcon cmdIcon = null; if (!c.TryGetAttribute <IconAttribute>(a => cmdIcon = a.Icon)) { //TODO: add default icon cmdIcon = new MasterIcon() { Icon = new System.Drawing.Bitmap(12, 12) }; } return(cmdIcon); }).ToArray(); if (m_App.SupportsHighResIcons()) { var iconsList = iconsConv.ConvertIcon(mainIcon, true); cmdGroup.MainIconList = iconsList; cmdGroup.IconList = iconsConv.ConvertIconsGroup(iconList, true); } else { var mainIconPath = iconsConv.ConvertIcon(mainIcon, false); var smallIcon = mainIconPath[0]; var largeIcon = mainIconPath[1]; cmdGroup.SmallMainIcon = smallIcon; cmdGroup.LargeMainIcon = largeIcon; var iconListPath = iconsConv.ConvertIconsGroup(iconList, true); var smallIconList = iconListPath[0]; var largeIconList = iconListPath[1]; cmdGroup.SmallIconList = smallIconList; cmdGroup.LargeIconList = largeIconList; } }
protected override PropertyManagerPageGroupBase Create(PropertyManagerPagePage page, IAttributeSet atts) { const int OPTIONS_NOT_USED = 0; var icon = atts.BoundMemberInfo?.TryGetAttribute <IconAttribute>()?.Icon; if (icon == null) { icon = atts.BoundType?.TryGetAttribute <IconAttribute>()?.Icon; } string iconPath = ""; if (icon != null) { iconPath = m_IconsConv.ConvertIcon(new TabIcon(icon)).First(); //NOTE: tab icon must be in 256 color bitmap, otherwise it is not displayed TryConvertIconTo8bit(iconPath); } var tab = page.Page.AddTab(atts.Id, atts.Name, iconPath, OPTIONS_NOT_USED) as IPropertyManagerPageTab; return(new PropertyManagerPageTabControl(atts.Id, atts.Tag, page.Handler, tab, page.App, page)); }
public ISwFeatureMgrTab <TControl> CreateFeatureManagerTab <TControl>(ISwDocument doc) { var mdlViewMgr = doc.Model.ModelViewManager; using (var iconsConv = new IconsConverter()) { return(CustomControlHelper.HostControl <TControl, SwFeatureMgrTab <TControl> >( (c, h, t, i) => { var imgPath = iconsConv.ConvertIcon(new FeatMgrViewIcon(i)).First(); var featMgr = mdlViewMgr.CreateFeatureMgrWindowFromHandlex64( imgPath, h.Handle.ToInt64(), t, (int)swFeatMgrPane_e.swFeatMgrPaneBottom) as IFeatMgrView; if (featMgr != null) { return new SwFeatureMgrTab <TControl>(c, featMgr, doc); } else { throw new NetControlHostException(h.Handle); } }, (p, t, i) => { var imgPath = iconsConv.ConvertIcon(new FeatMgrViewIcon(i)).First(); var featMgr = mdlViewMgr.CreateFeatureMgrControl3(imgPath, p, "", t, (int)swFeatMgrPane_e.swFeatMgrPaneBottom) as IFeatMgrView; TControl ctrl = default; if (featMgr != null) { ctrl = (TControl)featMgr.GetControl(); } if (ctrl == null) { throw new ComControlHostException(p); } return new SwFeatureMgrTab <TControl>(ctrl, featMgr, doc); })); } }
protected override void SetSpecificValue(Image value) { if (value == null) { value = Resources.DefaultBitmap; } var icons = m_IconsConv.ConvertIcon(new ControlIcon(value, m_Size), true); SwSpecificControl.SetBitmapByName(icons[0], icons[1]); m_Image = value; }
protected override void SetSpecificValue(Image value) { if (value == null) { value = IconsConverter.FromXImage(Defaults.Icon); } var icons = m_IconsConv.ConvertIcon(new ControlIcon(value, m_Size)); SwSpecificControl.SetBitmapByName(icons[0], icons[1]); m_Image = value; }
private void TryCreateIcons() { var iconsConverter = new IconsConverter( MacroFeatureIconInfo.GetLocation(this.GetType()), false); IIcon regIcon = null; IIcon highIcon = null; IIcon suppIcon = null; this.GetType().TryGetAttribute <IconAttribute>(a => { regIcon = a.Regular; highIcon = a.Highlighted; suppIcon = a.Suppressed; }); if (regIcon == null) { //TODO: load default } if (highIcon == null) { highIcon = regIcon; } if (suppIcon == null) { suppIcon = regIcon; } //Creation of icons may fail if user doesn't have write permissions or icon is locked try { iconsConverter.ConvertIcon(regIcon, true); iconsConverter.ConvertIcon(suppIcon, true); iconsConverter.ConvertIcon(highIcon, true); iconsConverter.ConvertIcon(regIcon, false); iconsConverter.ConvertIcon(suppIcon, false); iconsConverter.ConvertIcon(highIcon, false); } catch { } }
private void TryCreateIcons() { var iconsConverter = new IconsConverter( MacroFeatureIconInfo.GetLocation(this.GetType()), false); System.Drawing.Image icon = null; this.GetType().TryGetAttribute <IconAttribute>(a => { icon = IconsConverter.FromXImage(a.Icon); }); if (icon == null) { icon = IconsConverter.FromXImage(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); } }
/// <inheritdoc/> public ITaskpaneView CreateTaskPane <TControl, TCmdEnum>(Action <TCmdEnum> cmdHandler, out TControl ctrl) where TControl : UserControl, new() where TCmdEnum : IComparable, IFormattable, IConvertible { var tooltip = ""; CommandGroupIcon taskPaneIcon = null; var getTaskPaneDisplayData = new Action <Type, bool>((t, d) => { if (taskPaneIcon == null) { taskPaneIcon = DisplayInfoExtractor.ExtractCommandDisplayIcon <TaskPaneIconAttribute, CommandGroupIcon>( t, i => new TaskPaneMasterIcon(i), a => a.Icon, d); } if (string.IsNullOrEmpty(tooltip)) { if (!t.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName)) { t.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description); } } }); if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e)) { getTaskPaneDisplayData.Invoke(typeof(TCmdEnum), false); } getTaskPaneDisplayData.Invoke(typeof(TControl), true); ITaskpaneView taskPaneView = null; ITaskPaneHandler taskPaneHandler = null; m_Logger.Log($"Creating task pane for {typeof(TControl).FullName} type"); using (var iconConv = new IconsConverter()) { if (App.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane)) { var taskPaneIconImages = iconConv.ConvertIcon(taskPaneIcon, true); taskPaneView = App.CreateTaskpaneView3(taskPaneIconImages, tooltip); } else { var taskPaneIconImage = iconConv.ConvertIcon(taskPaneIcon, false)[0]; taskPaneView = App.CreateTaskpaneView2(taskPaneIconImage, tooltip); } taskPaneHandler = new TaskPaneHandler <TCmdEnum>(App, taskPaneView, cmdHandler, iconConv, m_Logger); } if (typeof(TControl).IsComVisible()) { var progId = typeof(TControl).GetProgId(); ctrl = taskPaneView.AddControl(progId, "") as TControl; if (ctrl == null) { throw new NullReferenceException( $"Failed to create COM control from {progId}. Make sure that COM component is properly registered"); } } else { ctrl = new TControl(); ctrl.CreateControl(); var handle = ctrl.Handle; if (!taskPaneView.DisplayWindowFromHandle(handle.ToInt32())) { throw new NullReferenceException($"Failed to host .NET control (handle {handle}) in task pane"); } } taskPaneHandler.Disposed += OnTaskPaneHandlerDisposed; m_TaskPanes.Add(taskPaneHandler); return(taskPaneView); }
private void AssignControlAttributes(TControlSw ctrl, ControlOptionsAttribute opts, IAttributeSet atts) { var swCtrl = ctrl as IPropertyManagerPageControl; if (opts.BackgroundColor != 0) { swCtrl.BackgroundColor = ConvertColor(opts.BackgroundColor); } if (opts.TextColor != 0) { swCtrl.TextColor = ConvertColor(opts.TextColor); } if (opts.Left != -1) { swCtrl.Left = opts.Left; } if (opts.Top != -1) { swCtrl.Top = opts.Top; } if (opts.Width != -1) { swCtrl.Width = opts.Width; } if (opts.ResizeOptions != 0) { swCtrl.OptionsForResize = (int)opts.ResizeOptions; } ControlIcon icon = null; var commonIcon = atts.BoundMemberInfo?.TryGetAttribute <IconAttribute>()?.Icon; if (commonIcon != null) { icon = new ControlIcon(commonIcon); } if (atts.Has <ControlAttributionAttribute>()) { var attribution = atts.Get <ControlAttributionAttribute>(); if (attribution.StandardIcon != 0) { swCtrl.SetStandardPictureLabel((int)attribution.StandardIcon); } //else if (attribution.Icon != null) //{ // icon = attribution.Icon; //} } if (icon != null) { var icons = m_IconConv.ConvertIcon(icon); var res = swCtrl.SetPictureLabelByName(icons[0], icons[1]); Debug.Assert(res); } }
protected override PropertyManagerPagePage Create(IAttributeSet atts) { int err = -1; swPropertyManagerPageOptions_e opts; TitleIcon titleIcon = null; IconAttribute commIconAtt; if (atts.BoundType.TryGetAttribute(out commIconAtt)) { if (commIconAtt.Icon != null) { titleIcon = new TitleIcon(IconsConverter.FromXImage(commIconAtt.Icon)); } } if (atts.Has <PageOptionsAttribute>()) { var optsAtt = atts.Get <PageOptionsAttribute>(); //TODO: implement conversion opts = (swPropertyManagerPageOptions_e)optsAtt.Options; } else { //TODO: implement conversion opts = (swPropertyManagerPageOptions_e)(PageOptions_e.OkayButton | PageOptions_e.CancelButton); } var helpLink = ""; var whatsNewLink = ""; if (atts.Has <HelpAttribute>()) { var helpAtt = atts.Get <HelpAttribute>(); if (!string.IsNullOrEmpty(helpAtt.WhatsNewLink)) { if (!opts.HasFlag(swPropertyManagerPageOptions_e.swPropertyManagerOptions_WhatsNew)) { opts |= swPropertyManagerPageOptions_e.swPropertyManagerOptions_WhatsNew; } } helpLink = helpAtt.HelpLink; whatsNewLink = helpAtt.WhatsNewLink; } var page = m_App.CreatePropertyManagerPage(atts.Name, (int)opts, m_Handler, ref err) as IPropertyManagerPage2; if (titleIcon != null) { var iconPath = m_IconsConv.ConvertIcon(titleIcon).First(); page.SetTitleBitmap2(iconPath); } if (atts.Has <MessageAttribute>()) { var msgAtt = atts.Get <MessageAttribute>(); page.SetMessage3(msgAtt.Text, (int)msgAtt.Visibility, (int)msgAtt.Expanded, msgAtt.Caption); } else if (!string.IsNullOrEmpty(atts.Description)) { page.SetMessage3(atts.Description, (int)swPropertyManagerPageMessageVisibility.swMessageBoxVisible, (int)swPropertyManagerPageMessageExpanded.swMessageBoxExpand, ""); } return(new PropertyManagerPagePage(page, m_Handler, m_App, helpLink, whatsNewLink)); }
private void AssignControlAttributes(TControlSw ctrl, ControlOptionsAttribute opts, IAttributeSet atts) { var swCtrl = ctrl as IPropertyManagerPageControl; if (opts.BackgroundColor != 0) { swCtrl.BackgroundColor = ConvertColor(opts.BackgroundColor); } if (opts.TextColor != 0) { swCtrl.TextColor = ConvertColor(opts.TextColor); } if (opts.Left != -1) { swCtrl.Left = opts.Left; } if (opts.Top != -1) { swCtrl.Top = opts.Top; } if (opts.Width != -1) { swCtrl.Width = opts.Width; } if (opts.ResizeOptions != 0) { swCtrl.OptionsForResize = (int)opts.ResizeOptions; } ControlIcon icon = null; var commonIcon = atts.BoundMemberInfo?.TryGetAttribute <IconAttribute>()?.Icon; if (commonIcon != null) { icon = new ControlIcon(IconsConverter.FromXImage(commonIcon)); } var hasIcon = false; if (atts.Has <StandardControlIconAttribute>()) { var attribution = atts.Get <StandardControlIconAttribute>(); if (attribution.Label != 0) { hasIcon = true; swCtrl.SetStandardPictureLabel((int)attribution.Label); } } if (icon != null) { hasIcon = true; var icons = m_IconConv.ConvertIcon(icon); var res = swCtrl.SetPictureLabelByName(icons[0], icons[1]); Debug.Assert(res); } if (!hasIcon) { var defIcon = GetDefaultBitmapLabel(atts); if (defIcon.HasValue) { swCtrl.SetStandardPictureLabel((int)defIcon.Value); } } }
private void TryCreateIcons() { var iconsConverter = new IconsConverter( MacroFeatureIconInfo.GetLocation(this.GetType()), false); MacroFeatureIcon regIcon = null; MacroFeatureIcon highIcon = null; MacroFeatureIcon suppIcon = null; this.GetType().TryGetAttribute <FeatureIconAttribute>(a => { regIcon = a.Regular; highIcon = a.Highlighted; suppIcon = a.Suppressed; }); if (regIcon == null) { Image icon = null; this.GetType().TryGetAttribute <Common.Attributes.IconAttribute>(a => { icon = a.Icon; }); if (icon == null) { icon = Resources.default_icon; } regIcon = new MasterIcon(MacroFeatureIconInfo.RegularName) { Icon = icon }; } if (highIcon == null) { highIcon = regIcon.Clone(MacroFeatureIconInfo.HighlightedName); } if (suppIcon == null) { suppIcon = regIcon.Clone(MacroFeatureIconInfo.SuppressedName); } //Creation of icons may fail if user doesn't have write permissions or icon is locked try { iconsConverter.ConvertIcon(regIcon, true); iconsConverter.ConvertIcon(suppIcon, true); iconsConverter.ConvertIcon(highIcon, true); iconsConverter.ConvertIcon(regIcon, false); iconsConverter.ConvertIcon(suppIcon, false); iconsConverter.ConvertIcon(highIcon, false); } catch (Exception ex) { Logger.Log(ex); } }
internal TaskPaneHandler(ISldWorks app, ITaskpaneView taskPaneView, Action <TCmdEnum> cmdHandler, IconsConverter iconsConv, ILogger logger) { m_Logger = logger; m_TaskPaneView = taskPaneView; m_CmdHandler = cmdHandler; if (!typeof(TCmdEnum).IsEnum) { throw new ArgumentException($"{typeof(TCmdEnum)} must be an enumeration"); } if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e) && cmdHandler != null) { var enumValues = Enum.GetValues(typeof(TCmdEnum)); m_Commands = enumValues.Cast <TCmdEnum>().ToArray(); foreach (Enum cmdEnum in enumValues) { //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands var icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>( cmdEnum, i => new MasterIcon(i), a => a.Icon); var tooltip = ""; if (!cmdEnum.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName)) { cmdEnum.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description); } if (!cmdEnum.TryGetAttribute <TaskPaneStandardButtonAttribute>(a => { if (!m_TaskPaneView.AddStandardButton((int)a.Icon, tooltip)) { throw new InvalidOperationException($"Failed to add standard button for {cmdEnum}"); } })) { if (app.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane)) { var imageList = iconsConv.ConvertIcon(icon, true); if (!m_TaskPaneView.AddCustomButton2(imageList, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum} with highres icon"); } } else { var imagePath = iconsConv.ConvertIcon(icon, false)[0]; if (!m_TaskPaneView.AddCustomButton(imagePath, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum}"); } } } } (m_TaskPaneView as TaskpaneView).TaskPaneToolbarButtonClicked += OnTaskPaneToolbarButtonClicked; } (m_TaskPaneView as TaskpaneView).TaskPaneDestroyNotify += OnTaskPaneDestroyNotify; }