Exemplo n.º 1
0
        private void SetImageIndex(ComTreeNode comTreeNode)
        {
            ComPtrTreeNode      comPtrTreeNode      = comTreeNode as ComPtrTreeNode;
            ComMethodTreeNode   comMethodTreeNode   = comTreeNode as ComMethodTreeNode;
            ComPropertyTreeNode comPropertyTreeNode = comTreeNode as ComPropertyTreeNode;
            ComPtrItemTreeNode  comPtrItemTreeNode  = comTreeNode as ComPtrItemTreeNode;

            if (comPtrTreeNode != null)
            {
                comPtrTreeNode.ImageIndex = comPtrTreeNode.ComPtr.IsInvalid ? NullObjectImageIndex : ObjectImageIndex;

                if (comPtrTreeNode.IsCollection)
                {
                    comPtrTreeNode.ImageIndex = comPtrTreeNode.IsEmptyCollection ? NullCollectionImageIndex : CollectionImageIndex;
                }
            }
            else if (comMethodTreeNode != null)
            {
                comMethodTreeNode.ImageIndex = MethodImageIndex;
            }
            else if (comPropertyTreeNode != null)
            {
                comPropertyTreeNode.ImageIndex = PropertyImageIndex;
            }
            else if (comPtrItemTreeNode != null)
            {
                comPtrItemTreeNode.ImageIndex = comPtrTreeNode.ComPtr.IsInvalid ? NullObjectImageIndex : ObjectImageIndex;
            }

            comTreeNode.SelectedImageIndex = comTreeNode.ImageIndex;
        }
Exemplo n.º 2
0
        private void UpdateRichTextBox(ComTreeNode node)
        {
            try
            {
                typeInfoRichTextBox.Clear();

                if (node == null)
                {
                    return;
                }

                ComTypeInfo     comTypeInfo     = null;
                ComPropertyInfo comPropertyInfo = null;
                ComFunctionInfo comFunctionInfo = null;

                if (node is ComPtrItemTreeNode)
                {
                    comFunctionInfo = ((ComPtrItemTreeNode)node).ComFunctionInfo;
                }
                else if (node is ComMethodTreeNode)
                {
                    comFunctionInfo = ((ComMethodTreeNode)node).ComFunctionInfo;
                }
                else if (node is ComPropertyTreeNode)
                {
                    comPropertyInfo = ((ComPropertyTreeNode)node).ComPropertyInfo;
                }
                else if (node is ComPtrTreeNode)
                {
                    ComPtrTreeNode comObjectPropertyTreeNode = (ComPtrTreeNode)node;

                    if (comObjectPropertyTreeNode.ComPropertyInfo != null)
                    {
                        comPropertyInfo = comObjectPropertyTreeNode.ComPropertyInfo;
                    }
                    else
                    {
                        comTypeInfo = comObjectPropertyTreeNode.ComPtr.TryGetComTypeInfo();
                    }
                }

                if (comTypeInfo != null)
                {
                    typeInfoRichTextBox.DescribeComTypeInfo(comTypeInfo);
                }
                else if (comPropertyInfo != null)
                {
                    typeInfoRichTextBox.DescribeComPropertyInfo(comPropertyInfo);
                }
                else if (comFunctionInfo != null)
                {
                    typeInfoRichTextBox.DescribeComFunctionInfo(comFunctionInfo);
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }
        }
Exemplo n.º 3
0
        private ComTreeNode[] GetChildren(ComPtrTreeNode node)
        {
            if (node == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            ComTreeNode[] childNodes = new ComTreeNode[] { };

            try
            {
                childNodes = GetChildren(node.ComPtr);
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            List <ComTreeNode> filteredComTreeNodes = new List <ComTreeNode>();

            foreach (ComTreeNode childNode in childNodes)
            {
                ComPtrTreeNode      comPtrTreeNode      = childNode as ComPtrTreeNode;
                ComPropertyTreeNode comPropertyTreeNode = childNode as ComPropertyTreeNode;

                if (comPtrTreeNode != null)
                {
                    if ((comPtrTreeNode.ComPtr.IsInvalid) && (_showNullObjects == false))
                    {
                        continue;
                    }

                    if (comPtrTreeNode.IsCollection)
                    {
                        if ((comPtrTreeNode.IsEmptyCollection) && (_showEmptyCollections == false))
                        {
                            continue;
                        }
                    }
                }
                else if (comPropertyTreeNode != null)
                {
                    if (_showProperties == false)
                    {
                        continue;
                    }
                }

                filteredComTreeNodes.Add(childNode);
            }

            SetImageIndex(filteredComTreeNodes.ToArray());

            return(filteredComTreeNodes.ToArray());
        }
Exemplo n.º 4
0
        //private void HandleRightClick(TreeNode node, Point p)
        //{
        //    if (node == null) return;

        //    if (node is ComPtrTreeNode)
        //    {
        //        HandleRightClick((ComPtrTreeNode)node, p);
        //    }
        //}

        //private void HandleRightClick(ComPtrTreeNode comPtrTreeNode, Point p)
        //{
        //    if (comPtrTreeNode == null) return;
        //    if (comPtrTreeNode.ComFunctionInfo == null) return;

        //    ComFunctionInfo getFunction = comPtrTreeNode.ComFunctionInfo;

        //    if (comPtrTreeNode.ComPtr.IsInvalid)
        //    {
        //        if (getFunction.Parameters.Length == 1)
        //        {
        //            ComParameterInfo returnParameter = getFunction.ReturnParameter;
        //            ComParameterInfo firstParameter = getFunction.Parameters[0];

        //            ComTypeInfo cti = ComTypeManager.Instance.LookupUserDefined(firstParameter.ELEMDESC.tdesc, getFunction.ComTypeInfo);

        //            if ((cti != null) && (cti.IsEnum))
        //            {
        //                ContextMenu menu = new ContextMenu();
        //                MenuItem invokeMenuItem = new MenuItem("Invoke");

        //                foreach (ComVariableInfo comVariableInfo in cti.Variables)
        //                {
        //                    MenuItem menuItem = new MenuItem(comVariableInfo.Name);
        //                    menuItem.Click += menuItem_Click;
        //                    menuItem.Tag = new object[] { comPtrTreeNode, comVariableInfo };
        //                    invokeMenuItem.MenuItems.Add(menuItem);
        //                }

        //                menu.MenuItems.Add(invokeMenuItem);
        //                menu.Show(this, p);
        //            }
        //        }
        //    }
        //}

        //void menuItem_Click(object sender, EventArgs e)
        //{
        //    MenuItem menuItem = sender as MenuItem;
        //    object[] args = menuItem.Tag as object[];

        //    if (args.Length == 2)
        //    {
        //        ComPtrTreeNode comPtrTreeNode = args[0] as ComPtrTreeNode;
        //        ComVariableInfo comVariableInfo = args[1] as ComVariableInfo;

        //        if ((comPtrTreeNode != null) && (comVariableInfo != null))
        //        {
        //        }
        //    }
        //}

        private void DrawNodeExpander(ComTreeNode node, Graphics graphics, Rectangle rect)
        {
            if (node.IsExpanded)
            {
                graphics.DrawImage(Resources.Collapse_16x16, rect.X + 2, rect.Y + 2);
            }
            else
            {
                if (node.Nodes.Count > 0)
                {
                    graphics.DrawImage(Resources.Expand_16x16, rect.X + 2, rect.Y + 2);
                }
            }
        }
Exemplo n.º 5
0
        void toolStripNavigationButton_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripButton button = sender as ToolStripButton;

                if (button != null)
                {
                    ComTreeNode node = button.Tag as ComTreeNode;
                    if (node != null)
                    {
                        node.EnsureVisible();
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }
        }
Exemplo n.º 6
0
        private void UpdateToolStrip(ComTreeNode node)
        {
            try
            {
                List <ToolStripItem> baseToolStripItems = new List <ToolStripItem>();
                List <ToolStripItem> newToolStripItems  = new List <ToolStripItem>();

                int index = toolStrip.Items.IndexOf(separatorNavigation);

                for (int i = 0; i <= index; i++)
                {
                    baseToolStripItems.Add(toolStrip.Items[i]);
                }

                while (node != null)
                {
                    ToolStripButton button = new ToolStripButton(node.Caption);
                    button.ToolTipText  = String.Format("{0} ({1})", node.Caption, node.TypeFullName);
                    button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;

                    int imageIndex = node.ImageIndex == -1 ? 0 : node.ImageIndex;

                    button.Image  = comTreeView.ImageList.Images[imageIndex];
                    button.Tag    = node;
                    button.Click += toolStripNavigationButton_Click;
                    newToolStripItems.Insert(0, button);

                    node = node.Parent as ComTreeNode;
                }

                baseToolStripItems.AddRange(newToolStripItems);
                toolStrip.Items.Clear();
                toolStrip.Items.AddRange(baseToolStripItems.ToArray());
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }
        }
Exemplo n.º 7
0
        private void comTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            comPropertyGrid.SelectedObject = null;

            ComTreeNode comTreeNode = e.Node as ComTreeNode;

            if (comTreeNode != null)
            {
                UpdateToolStrip(comTreeNode);
                UpdateRichTextBox(comTreeNode);

                try
                {
                    if (comTreeNode is ComPtrTreeNode)
                    {
                        comPropertyGrid.SelectedObject = ((ComPtrTreeNode)comTreeNode).ComPtr;
                    }
                }
                catch
                {
                    GlobalExceptionHandler.HandleException();
                }
            }
        }
Exemplo n.º 8
0
        private ComTreeNode GetChild(ComPtr comPtr, ComPropertyInfo comPropertyInfo)
        {
            if (comPtr == null)
            {
                return(null);
            }
            if (comPropertyInfo == null)
            {
                return(null);
            }
            if (comPtr.IsInvalid)
            {
                return(null);
            }

            ComFunctionInfo getFunctionInfo = comPropertyInfo.GetFunction;

            if (getFunctionInfo == null)
            {
                return(null);
            }
            if (getFunctionInfo.IsRestricted)
            {
                return(null);
            }

            ComTreeNode comTreeNode   = null;
            object      propertyValue = null;

            if (getFunctionInfo.Parameters.Length == 0)
            {
                try
                {
                    comPtr.TryInvokePropertyGet(getFunctionInfo.DispId, out propertyValue);
                }
                catch
                {
                    GlobalExceptionHandler.HandleException();
                }

                if (propertyValue == null)
                {
                    switch (getFunctionInfo.ReturnParameter.VariantType)
                    {
                    case VarEnum.VT_DISPATCH:
                    case VarEnum.VT_PTR:
                    case VarEnum.VT_ARRAY:
                    case VarEnum.VT_UNKNOWN:
                        propertyValue = new ComPtr(IntPtr.Zero);
                        break;
                    }
                }

                if (propertyValue is ComPtr)
                {
                    comTreeNode = new ComPtrTreeNode(comPropertyInfo, (ComPtr)propertyValue);

                    if (((ComPtr)propertyValue).IsInvalid == false)
                    {
                        comTreeNode.Nodes.Add(String.Empty);
                    }
                }
                else
                {
                    comTreeNode = new ComPropertyTreeNode(comPropertyInfo, propertyValue);
                }
            }
            else
            {
                switch (getFunctionInfo.ReturnParameter.VariantType)
                {
                case VarEnum.VT_DISPATCH:
                case VarEnum.VT_PTR:
                case VarEnum.VT_ARRAY:
                case VarEnum.VT_UNKNOWN:
                    comTreeNode = new ComPtrTreeNode(comPropertyInfo, new ComPtr());
                    break;

                default:
                    comTreeNode = new ComPropertyTreeNode(comPropertyInfo, null);
                    break;
                }
            }

            return(comTreeNode);
        }
Exemplo n.º 9
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            List <ComTreeNode> childNodes = new List <ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    List <ComTreeNode> collectionChildNodes = new List <ComTreeNode>();
                    int count      = comPtr.TryGetItemCount();
                    int foundCount = 0;

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            object returnValue = null;

                            // Solid Edge is supposed to be 1 based index.
                            for (int i = 1; i <= count; i++)
                            {
                                returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        collectionChildNodes.Add(comPtrItemTreeNode);
                                        foundCount++;
                                    }
                                }
                            }

                            try
                            {
                                // Some collections are 0 based.
                                // Application->Customization->RibbonBarThemes seems to be 0 based.
                                if (foundCount == (count - 1))
                                {
                                    returnValue = null;
                                    if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { 0 }, out returnValue)))
                                    {
                                        ComPtr pItem = returnValue as ComPtr;
                                        if ((pItem != null) && (pItem.IsInvalid == false))
                                        {
                                            ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                            comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, 0);
                                            comPtrItemTreeNode.Nodes.Add("...");
                                            collectionChildNodes.Insert(0, comPtrItemTreeNode);
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }

                    childNodes.AddRange(collectionChildNodes.ToArray());
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted)
                        {
                            continue;
                        }

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(childNodes.ToArray());
        }
Exemplo n.º 10
0
        protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            if (e.Node.IsVisible == false)
            {
                return;
            }

            ComTreeNode node = e.Node as ComTreeNode;

            if (node == null)
            {
                return;
            }

            Font      baseFont         = Font;
            FontStyle captionFontStyle = FontStyle.Regular;
            Color     captionColor     = ForeColor;
            Color     caption2Color    = Color.Green;
            //Color pointerColor = Color.DodgerBlue;
            TextFormatFlags textFormatFlags = TextFormatFlags.Left | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter;

            Rectangle rectNode     = node.Bounds;
            Rectangle rectExpander = new Rectangle(Indent * node.Level, rectNode.Y, ItemHeight, ItemHeight);
            Rectangle rectImage    = new Rectangle(rectExpander.X + rectExpander.Width, rectNode.Y, ItemHeight, ItemHeight);

            rectImage.X    = rectNode.X - rectImage.Width;
            rectExpander.X = rectNode.X - rectImage.Width - rectExpander.Width;

            DrawNodeExpander(node, e.Graphics, rectExpander);

            Rectangle rectSelected = rectImage;

            rectSelected.Width = e.Bounds.Width - rectImage.X;

            DrawNodeRectangle(e, rectSelected);

            Image nodeImage = null;

            if (ImageList != null)
            {
                int imageIndex = node.ImageIndex;
                if ((imageIndex == -1) && (ImageList.Images.Count > 0))
                {
                    imageIndex = 0;
                }

                if (imageIndex >= 0)
                {
                    nodeImage = ImageList.Images[imageIndex];
                }
            }

            if (nodeImage != null)
            {
                int z = ItemHeight - rectImage.Height;
                e.Graphics.DrawImage(nodeImage, rectImage.X + 2, rectImage.Y + 2);
            }

            ComPtrTreeNode comPtrTreeNode = node as ComPtrTreeNode;

            if (comPtrTreeNode != null)
            {
                if (node is ComPtrTreeNode)
                {
                    if (comPtrTreeNode.GetFunctionHasParameters)
                    {
                        captionColor = Color.DarkGray;
                    }
                }

                if ((comPtrTreeNode != null) && (comPtrTreeNode.CollectionCount > 0))
                {
                    captionFontStyle = FontStyle.Bold;
                }
            }

            Rectangle rectCaption = rectNode;

            using (Font captionFont = new System.Drawing.Font(baseFont, captionFontStyle))
            {
                rectCaption.Width = TextRenderer.MeasureText(node.Caption, captionFont).Width;
                TextRenderer.DrawText(e.Graphics, node.Caption, captionFont, rectCaption, captionColor, textFormatFlags);

                //Rectangle rectCaption2 = rectCaption;

                if (!String.IsNullOrWhiteSpace(node.Value))
                {
                    string value = String.Format("[{0}]", node.Value);
                    rectCaption.X    += rectCaption.Width;
                    rectCaption.Width = TextRenderer.MeasureText(value, captionFont).Width;
                    TextRenderer.DrawText(e.Graphics, value, captionFont, rectCaption, captionColor, textFormatFlags);
                }
            }

            if (!String.IsNullOrWhiteSpace(node.TypeFullName))
            {
                rectCaption.X    += rectCaption.Width;
                rectCaption.Width = TextRenderer.MeasureText(node.TypeFullName, baseFont).Width;
                TextRenderer.DrawText(e.Graphics, node.TypeFullName, baseFont, rectCaption, caption2Color, textFormatFlags);
            }

            //if (comPtrTreeNode != null)
            //{
            //    var pUnk = comPtrTreeNode.ComPtr.DangerousGetHandle();
            //    string value = String.Format("{0}", pUnk);
            //    rectCaption.X += rectCaption.Width;
            //    rectCaption.Width = TextRenderer.MeasureText(value, baseFont).Width;
            //    TextRenderer.DrawText(e.Graphics, value, baseFont, rectCaption, pointerColor, textFormatFlags);
            //}
        }