コード例 #1
0
 static bool IsFileOpenMenuEnabled()
 {
     CustomUI.CommandBars       commandBars    = CustomUI.ExcelCommandBarUtil.GetCommandBars();
     CustomUI.CommandBar        worksheetMenu  = commandBars[1]; // Worksheet Menu Bar
     CustomUI.CommandBarControl openMenuButton = worksheetMenu.FindControl(Missing.Value, /* ID:= */ 23, Missing.Value, Missing.Value, /* Recursive:= */ true);
     return(openMenuButton.Enabled);
 }
コード例 #2
0
 private static void ApplyControlAttributes(CommandBarControl control, XmlNode xmlNode, GetImageDelegate getImage)
 {
     foreach (XmlAttribute att in xmlNode.Attributes)
     {
         ApplyControlAttribute(control, att.Name, att.Value, getImage);
     }
 }
コード例 #3
0
ファイル: ExcelCommandBars.cs プロジェクト: uaqeel/ZeusXL
        // Normalizes the before value.
        // If before is missing or an int, already OK.
        // If it is a string, find the control in this collection and return its index.
        private object FindControlIndexBefore(object before /* should be int or Missing or string referring to control in this collection */)
        {
            if (before is Missing || before is int)
            {
                return(before);
            }

            object beforeIndex = Missing.Value;

            if (before is string)
            {
                for (int i = 1; i <= Count(); i++)
                {
                    CommandBarControl control = this[i];
                    string            caption = control.Caption;
                    if (!String.IsNullOrEmpty(caption))
                    {
                        if (caption.Replace("&", "") == ((string)before).Replace("&", ""))
                        {
                            // This is the one!
                            beforeIndex = i;
                            break;
                        }
                    }
                }
            }
            return(beforeIndex);
        }
コード例 #4
0
ファイル: ExcelCommandBars.cs プロジェクト: uaqeel/ZeusXL
        internal CommandBarControl FindOrAdd(MsoControlType controlType, string name, object Id, object Parameter, object Before, object Temporary)
        {
            if (name != null)
            {
                // Try to find an existing control with this name
                string findName = name.Replace("&", "");
                for (int i = 1; i <= Count(); i++)
                {
                    CommandBarControl control = this[i];
                    string            caption = control.Caption;
                    if (!String.IsNullOrEmpty(caption))
                    {
                        if (caption.Replace("&", "") == findName)
                        {
                            return(control);
                        }
                    }
                }
            }

            object /*CommandBarControl*/ newControl = _type.InvokeMember("Add", BindingFlags.InvokeMethod, null, _object,
                                                                         new object[] { controlType, Id, Parameter, Before, Temporary });

            return(CommandBarControl.CreateCommandBarControl(controlType, newControl));
        }
コード例 #5
0
 public CommandBarControl this[string name]
 {
     get
     {
         object commandBarControl = _type.InvokeMember("", BindingFlags.GetProperty, null, _object, new object[] { name });
         return(CommandBarControl.CreateCommandBarControl(commandBarControl));
     }
 }
コード例 #6
0
 public CommandBarControl this[int id]
 {
     get
     {
         object commandBarControl = ComObjectTtpe.InvokeMember(
             "", BindingFlags.GetProperty, null, ComObject, new object[] { id });
         return(CommandBarControl.CreateCommandBarControl(commandBarControl));
     }
 }
コード例 #7
0
        private static void ApplyControlAttribute(CommandBarControl control, string attribute, string value, GetImageDelegate getImage)
        {
            switch (attribute)
            {
            case "caption":
                control.Caption = value;
                break;

            case "height":
                int height;
                if (int.TryParse(value, out height))
                {
                    control.Height = height;
                }
                else
                {
                    Debug.Print("Could not parse 'height' attribute: {0}", value);
                }
                break;

            case "onAction":
                control.OnAction = value;
                break;

            case "enabled":
                bool enabled;
                if (bool.TryParse(value, out enabled))
                {
                    control.Enabled = enabled;
                }
                else
                {
                    Debug.Print("Could not parse 'enabled' attribute: {0}", value);
                }
                break;

            case "beginGroup":
                bool beginGroup;
                if (bool.TryParse(value, out beginGroup))
                {
                    control.BeginGroup = beginGroup;
                }
                else
                {
                    Debug.Print("Could not parse 'beginGroup' attribute: {0}", value);
                }
                break;

            case "helpFile":
                control.HelpFile = value;
                break;

            case "helpContextId":
                int helpContextId;
                if (int.TryParse(value, out helpContextId))
                {
                    control.HelpContextId = helpContextId;
                }
                else
                {
                    Debug.Print("Could not parse 'helpContextId' attribute: {0}", value);
                }
                break;

            case "tag":
                control.Tag = value;
                break;

            case "tooltipText":
                control.TooltipText = value;
                break;

            case "shortcutText":
                if (control is CommandBarButton)
                {
                    (control as CommandBarButton).ShortcutText = value;
                }
                else
                {
                    Debug.Print("shortcutText only supported on Buttons");
                }
                break;

            case "faceId":
                if (control is CommandBarButton)
                {
                    int faceId;
                    if (int.TryParse(value, out faceId))
                    {
                        (control as CommandBarButton).FaceId = faceId;
                    }
                    else
                    {
                        Debug.Print("Could not parse 'faceId' attribute: {0}", value);
                    }
                }
                else
                {
                    Debug.Print("faceId only supported on Buttons");
                }
                break;

            case "image":
                if (control is CommandBarButton)
                {
                    Bitmap image = getImage(value);
                    if (image != null)
                    {
                        (control as CommandBarButton).SetButtonImage(image);
                    }
                    else
                    {
                        Debug.Print("Could not find or load image {0}", value);
                    }
                }
                else
                {
                    Debug.Print("image only supported on Buttons");
                }
                break;

            case "style":
            case "MsoButtonStyle":      // Compatible with original style code.
                if (control is CommandBarButton)
                {
                    if (Enum.IsDefined(typeof(MsoButtonStyle), value))
                    {
                        (control as CommandBarButton).Style = (MsoButtonStyle)Enum.Parse(typeof(MsoButtonStyle), value, false);
                    }
                    else
                    {
                        (control as CommandBarButton).Style = MsoButtonStyle.msoButtonAutomatic;
                    }
                }
                else
                {
                    Debug.Print("style only supported on Buttons");
                }
                break;

            default:
                Debug.Print("Unknown attribute '{0}' - ignoring.", attribute);
                break;
            }
        }