Esempio n. 1
0
        private void RefreshNode(ComTypeTreeNode node)
        {
            SetImageIndex(node);

            if (node is ComTypeLibraryTreeNode)
            {
                ComTypeLibraryTreeNode comTypeLibraryTreeNode = (ComTypeLibraryTreeNode)node;
                ComTypeLibrary         comTypeLibrary         = comTypeLibraryTreeNode.ComTypeLibrary;

                foreach (ComTypeInfo comTypeInfo in comTypeLibrary.ComTypeInfos)
                {
                    if (comTypeInfo.IsHidden)
                    {
                        continue;
                    }

                    ComTypeInfoTreeNode comTypeInfoTreeNode = new ComTypeInfoTreeNode(comTypeInfo);
                    comTypeLibraryTreeNode.Nodes.Add(comTypeInfoTreeNode);
                    RefreshNode(comTypeInfoTreeNode);
                }
            }
            else if (node is ComTypeInfoTreeNode)
            {
                ComTypeInfoTreeNode comTypeInfoTreeNode = (ComTypeInfoTreeNode)node;
                ComTypeInfo         comTypeInfo         = comTypeInfoTreeNode.ComTypeInfo;

                foreach (ComImplementedTypeInfo comImplementedTypeInfo in comTypeInfo.ImplementedTypes)
                {
                    ComTypeInfoTreeNode impComTypeInfoTreeNode = new ComTypeInfoTreeNode(comImplementedTypeInfo.ComTypeInfo);
                    comTypeInfoTreeNode.Nodes.Add(impComTypeInfoTreeNode);
                    RefreshNode(impComTypeInfoTreeNode);
                }
            }
        }
Esempio n. 2
0
 public ComTypeInfoTreeNode(ComTypeInfo comTypeInfo)
     : base()
 {
     _comTypeInfo = comTypeInfo;
     Text         = _comTypeInfo.Name;
     FullText     = _comTypeInfo.FullName;
 }
Esempio 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();
            }
        }
Esempio n. 4
0
        private void SetImageIndex(ComTypeTreeNode comTypeTreeNode)
        {
            ComTypeLibraryTreeNode  comTypeLibraryTreeNode  = comTypeTreeNode as ComTypeLibraryTreeNode;
            ComTypeInfoTreeNode     comTypeInfoTreeNode     = comTypeTreeNode as ComTypeInfoTreeNode;
            ComFunctionInfoTreeNode comFunctionInfoTreeNode = comTypeTreeNode as ComFunctionInfoTreeNode;
            ComPropertyInfoTreeNode comPropertyInfoTreeNode = comTypeTreeNode as ComPropertyInfoTreeNode;
            ComVariableInfoTreeNode comVariableInfoTreeNode = comTypeTreeNode as ComVariableInfoTreeNode;

            if (comTypeLibraryTreeNode != null)
            {
                comTypeTreeNode.ImageIndex = ComTypeNodeNamespaceImageIndex;
            }
            else if (comTypeInfoTreeNode != null)
            {
                ComTypeInfo comTypeInfo = comTypeInfoTreeNode.ComTypeInfo;

                if (comTypeInfo.IsCoClass)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeClassImageIndex;
                }
                else if (comTypeInfo.IsDispatch)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeInterfaceImageIndex;
                }
                else if (comTypeInfo.IsInterface)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeInterfaceImageIndex;
                }
                else if (comTypeInfo.IsEnum)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeEnumImageIndex;
                }
                else if (comTypeInfo.IsAlias)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeAliasImageIndex;
                }
                else if (comTypeInfo.IsRecord)
                {
                    comTypeTreeNode.ImageIndex = ComTypeNodeStructureImageIndex;
                }
            }
            else if (comFunctionInfoTreeNode != null)
            {
                comTypeTreeNode.ImageIndex = ComTypeNodeMethodImageIndex;
            }
            else if (comPropertyInfoTreeNode != null)
            {
                comTypeTreeNode.ImageIndex = ComTypeNodePropertyImageIndex;
            }
            else if (comVariableInfoTreeNode != null)
            {
                comVariableInfoTreeNode.ImageIndex = ComTypeNodeConstantImageIndex;
            }

            comTypeTreeNode.SelectedImageIndex = comTypeTreeNode.ImageIndex;
        }
Esempio n. 5
0
        public void DescribeComTypeInfo(ComTypeInfo comTypeInfo)
        {
            Clear();

            if (comTypeInfo is ComAliasInfo)
            {
                AppendText("Alias ");
            }
            else if (comTypeInfo is ComCoClassInfo)
            {
                AppendText("CoClass ");
            }
            else if (comTypeInfo is ComEnumInfo)
            {
                AppendText("Enum ");
            }
            else if (comTypeInfo is ComDispatchInfo)
            {
                AppendText("Dispatch interface ");
            }
            else if (comTypeInfo is ComInterfaceInfo)
            {
                AppendText("Interface ");
            }
            //else if (comTypeInfo is ComMaxInfo)
            //{
            //}
            else if (comTypeInfo is ComModuleInfo)
            {
                AppendText("Module ");
            }
            else if (comTypeInfo is ComRecordInfo)
            {
                AppendText("Struct ");
            }
            else if (comTypeInfo is ComUnionInfo)
            {
                AppendText("Union ");
            }

            //Interface Application
            //    Member of SolidEdgeFramework
            //    Provides the properties and methods necessary for a Visual Basic user to drive Solid Edge programmatically.

            AppendText(comTypeInfo.Name, ForeColor, FontStyle.Bold);
            AppendText(Environment.NewLine);
            AppendText("    Member of ");
            InsertLink(comTypeInfo.ComTypeLibrary.Name);
            AppendText(Environment.NewLine);

            WriteSummary(comTypeInfo.Description);
            WriteGuid(comTypeInfo.Guid);
        }
Esempio n. 6
0
        public void ScanForNodeAndSelect(ComTypeInfo comTypeInfo, TreeNodeCollection nodes)
        {
            if (comTypeInfo == null)
            {
                return;
            }
            if (nodes == null)
            {
                return;
            }
            if (_scanComplete == true)
            {
                return;
            }

            foreach (TreeNode node in nodes)
            {
                ComTypeLibraryTreeNode comTypeLibraryTreeNode = node as ComTypeLibraryTreeNode;
                ComTypeInfoTreeNode    comTypeInfoTreeNode    = node as ComTypeInfoTreeNode;

                if (comTypeLibraryTreeNode != null)
                {
                    if (comTypeLibraryTreeNode.ComTypeLibrary.Name.Equals(comTypeInfo.ComTypeLibrary.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        ScanForNodeAndSelect(comTypeInfo, node.Nodes);
                        return;
                    }
                }
                else if (comTypeInfoTreeNode != null)
                {
                    if (comTypeInfoTreeNode.ComTypeInfo.Name.Equals(comTypeInfo.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        _scanComplete = true;
                        node.TreeView.SelectedNode = node;
                        node.EnsureVisible();
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
        void Instance_ComTypeInfoSelected(object sender, ComTypeInfo comTypeInfo)
        {
            _scanComplete = false;

            try
            {
                if (comTypeTreeView.IsFiltered)
                {
                    comTypeTreeView.Filter = String.Empty;
                }

                if (comTypeTreeView.Nodes.Count == 0)
                {
                    comTypeTreeView.RefreshNodes();
                }

                ScanForNodeAndSelect(comTypeInfo, comTypeTreeView.Nodes);
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }
        }
Esempio n. 8
0
        private void comTypeTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            _navigationController.Remove(comTypeListView.Items.OfType <ListViewItem>().ToArray());
            _navigationController.CurrentItem = e.Node;

            ComTypeLibraryTreeNode  comTypeLibraryTreeNode  = e.Node as ComTypeLibraryTreeNode;
            ComTypeInfoTreeNode     comTypeInfoTreeNode     = e.Node as ComTypeInfoTreeNode;
            ComFunctionInfoTreeNode comFunctionInfoTreeNode = e.Node as ComFunctionInfoTreeNode;
            ComPropertyInfoTreeNode comPropertyInfoTreeNode = e.Node as ComPropertyInfoTreeNode;
            ComVariableInfoTreeNode comVariableInfoTreeNode = e.Node as ComVariableInfoTreeNode;

            comTypeListView.SelectedComTypeInfo = null;

            if (comTypeLibraryTreeNode != null)
            {
                typeInfoRichTextBox.DescribeComTypeLibrary(comTypeLibraryTreeNode.ComTypeLibrary);
            }
            else if (comTypeInfoTreeNode != null)
            {
                ComTypeInfo comTypeInfo = comTypeInfoTreeNode.ComTypeInfo;
                comTypeListView.SelectedComTypeInfo = comTypeInfo;
                typeInfoRichTextBox.DescribeComTypeInfo(comTypeInfo);
            }
            else if (comFunctionInfoTreeNode != null)
            {
                typeInfoRichTextBox.DescribeComFunctionInfo(comFunctionInfoTreeNode.ComFunctionInfo);
            }
            else if (comPropertyInfoTreeNode != null)
            {
                typeInfoRichTextBox.DescribeComPropertyInfo(comPropertyInfoTreeNode.ComPropertyInfo);
            }
            else if (comVariableInfoTreeNode != null)
            {
                typeInfoRichTextBox.DescribeComVariableInfo(comVariableInfoTreeNode.ComVariableInfo);
            }
        }
Esempio n. 9
0
        public ComPtrTreeNode(string caption, ComPtr comPtr)
            : base(caption)
        {
            if (comPtr != null)
            {
                _comPtr = comPtr;

                if (_comPtr.IsInvalid == false)
                {
                    ComTypeInfo comTypeInfo = _comPtr.TryGetComTypeInfo();
                    if (comTypeInfo != null)
                    {
                        TypeFullName = comTypeInfo.FullName;
                    }
                    else
                    {
                        TypeFullName = "IUnknown";
                    }

                    _isCollection = _comPtr.TryIsCollection();

                    if (_isCollection)
                    {
                        _collectionCount = _comPtr.TryGetItemCount();
                    }

                    string[] propertyNames = { "Name", "Caption", "StyleName", "ID", "Count", "Environment", "Description", "CommandString" };
                    var      value         = comPtr.TryGetFirstAvailableProperty(propertyNames);

                    if (value != null)
                    {
                        Value = value.ToString();
                    }
                }
            }
        }
Esempio n. 10
0
        private void EnsureScanDefinedMethods()
        {
            if (_comTypeDesc != null && _comTypeDesc.Funcs != null)
            {
                return;
            }

            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(DispatchObject, true);
            if (typeInfo == null)
            {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null)
            {
                lock (s_cacheComTypeDesc)
                {
                    if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true &&
                        _comTypeDesc.Funcs != null)
                    {
                        return;
                    }
                }
            }

            if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)
            {
                // We have typeinfo for custom interface. Get typeinfo for Dispatch interface.
                typeInfo = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(typeInfo);
                typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
            }

            if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS)
            {
                // We have typeinfo for the COClass.  Find the default interface and get typeinfo for default interface.
                typeInfo = ComTypeInfo.GetDispatchTypeInfoFromCoClassTypeInfo(typeInfo);
                typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo, typeAttr);

            ComMethodDesc getItem = null;
            ComMethodDesc setItem = null;
            Hashtable     funcs   = new Hashtable(typeAttr.cFuncs);
            Hashtable     puts    = new Hashtable();
            Hashtable     putrefs = new Hashtable();

            for (int definedFuncIndex = 0; definedFuncIndex < typeAttr.cFuncs; definedFuncIndex++)
            {
                IntPtr funcDescHandleToRelease = IntPtr.Zero;

                try
                {
                    ComTypes.FUNCDESC funcDesc;
                    GetFuncDescForDescIndex(typeInfo, definedFuncIndex, out funcDesc, out funcDescHandleToRelease);

                    if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0)
                    {
                        // This function is not meant for the script user to use.
                        continue;
                    }

                    ComMethodDesc method = new ComMethodDesc(typeInfo, funcDesc);
                    string        name   = method.Name.ToUpper(System.Globalization.CultureInfo.InvariantCulture);

                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT) != 0)
                    {
                        // If there is a getter for this put, use that ReturnType as the
                        // PropertyType.
                        if (funcs.ContainsKey(name))
                        {
                            method.InputType = ((ComMethodDesc)funcs[name]).ReturnType;
                        }

                        puts.Add(name, method);

                        // for the special dispId == 0, we need to store
                        // the method descriptor for the Do(SetItem) binder.
                        if (method.DispId == ComDispIds.DISPID_VALUE && setItem == null)
                        {
                            setItem = method;
                        }

                        continue;
                    }

                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF) != 0)
                    {
                        // If there is a getter for this put, use that ReturnType as the
                        // PropertyType.
                        if (funcs.ContainsKey(name))
                        {
                            method.InputType = ((ComMethodDesc)funcs[name]).ReturnType;
                        }

                        putrefs.Add(name, method);
                        // for the special dispId == 0, we need to store
                        // the method descriptor for the Do(SetItem) binder.
                        if (method.DispId == ComDispIds.DISPID_VALUE && setItem == null)
                        {
                            setItem = method;
                        }

                        continue;
                    }

                    if (funcDesc.memid == ComDispIds.DISPID_NEWENUM)
                    {
                        funcs.Add("GETENUMERATOR", method);
                        continue;
                    }

                    // If there is a setter for this put, update the InputType from our
                    // ReturnType.
                    if (puts.ContainsKey(name))
                    {
                        ((ComMethodDesc)puts[name]).InputType = method.ReturnType;
                    }

                    if (putrefs.ContainsKey(name))
                    {
                        ((ComMethodDesc)putrefs[name]).InputType = method.ReturnType;
                    }

                    funcs.Add(name, method);

                    // for the special dispId == 0, we need to store the method descriptor
                    // for the Do(GetItem) binder.
                    if (funcDesc.memid == ComDispIds.DISPID_VALUE)
                    {
                        getItem = method;
                    }
                }
                finally
                {
                    if (funcDescHandleToRelease != IntPtr.Zero)
                    {
                        typeInfo.ReleaseFuncDesc(funcDescHandleToRelease);
                    }
                }
            }

            lock (s_cacheComTypeDesc)
            {
                ComTypeDesc cachedTypeDesc;
                if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc))
                {
                    _comTypeDesc = cachedTypeDesc;
                }
                else
                {
                    _comTypeDesc = typeDesc;
                    s_cacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }

                _comTypeDesc.Funcs   = funcs;
                _comTypeDesc.Puts    = puts;
                _comTypeDesc.PutRefs = putrefs;
                _comTypeDesc.EnsureGetItem(getItem);
                _comTypeDesc.EnsureSetItem(setItem);
            }
        }
Esempio n. 11
0
 void Instance_ComTypeInfoSelected(object sender, ComTypeInfo comTypeInfo)
 {
     tabControl.SelectedIndex = TabPageTypeBrowserIndex;
 }
Esempio n. 12
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());
        }