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
        protected override void OnBeforeExpand(TreeViewCancelEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (e.Node.ImageIndex == ClosedFolderImageIndex)
                {
                    e.Node.ImageIndex         = OpenFolderImageIndex;
                    e.Node.SelectedImageIndex = e.Node.ImageIndex;
                }

                ComPtrTreeNode comPtrTreeNode = e.Node as ComPtrTreeNode;

                if (comPtrTreeNode != null)
                {
                    ComTreeNode[] childNodes = GetChildren(comPtrTreeNode);
                    CleanupAndRemoveNodes(comPtrTreeNode.Nodes);
                    comPtrTreeNode.Nodes.AddRange(childNodes);
                }
            }
            catch
            {
            }

            base.OnBeforeExpand(e);
        }
Exemplo n.º 3
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.º 4
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.º 5
0
        public ComTreeNode AddRootNode(ComPtr p, string caption)
        {
            ComPtrTreeNode comObjectRootTreeNode = new ComPtrTreeNode(caption, p);

            comObjectRootTreeNode.Nodes.Add("...");
            Nodes.Add(comObjectRootTreeNode);
            SelectedNode = comObjectRootTreeNode;
            comObjectRootTreeNode.Expand();

            return(comObjectRootTreeNode);
        }
Exemplo n.º 6
0
        public void CleanupAndRemoveNodes(TreeNodeCollection nodes)
        {
            foreach (TreeNode node in nodes)
            {
                CleanupAndRemoveNodes(node.Nodes);

                ComPtrTreeNode comObjectTreeNode = node as ComPtrTreeNode;

                if ((comObjectTreeNode != null) && (comObjectTreeNode.ComPtr.IsInvalid == false))
                {
                    comObjectTreeNode.ComPtr.Dispose();
                }
            }

            nodes.Clear();
        }
Exemplo n.º 7
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.º 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
        public ComTreeNode AddRootNode(ComPtr p, string caption)
        {
            ComPtrTreeNode comObjectRootTreeNode = new ComPtrTreeNode(caption, p);

            comObjectRootTreeNode.Nodes.Add("...");
            Nodes.Add(comObjectRootTreeNode);
            SelectedNode = comObjectRootTreeNode;
            comObjectRootTreeNode.Expand();

            return comObjectRootTreeNode;
        }
Exemplo n.º 10
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.º 11
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;
            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);
            }
        }