/// <include file='doc\SelectionService.uex' path='docs/doc[@for="SelectionService.GetObjects"]/*' />
        /// <devdoc>
        ///     Returns an array of objects.
        /// </devdoc>
        void ISelectionContainer.GetObjects(int flags, int cObjects, IntPtr objects)
        {
            int cnt = 0;

            switch (flags)
            {
            case __GETOBJS.ALL:
                if (container != null)
                {
                    ComponentCollection components = container.Components;
                    foreach (IComponent comp in components)
                    {
                        cnt++;

                        if (cnt > cObjects)
                        {
                            break;
                        }

                        Marshal.WriteIntPtr(objects, Marshal.GetIUnknownForObject(comp));
                        objects = (IntPtr)((long)objects + IntPtr.Size);
                    }
                }
                break;

            case __GETOBJS.SELECTED:
                ICollection comps = GetSelectedComponents();

                int ipSize = IntPtr.Size;

                foreach (object o in comps)
                {
                    cnt++;

                    if (cnt > cObjects)
                    {
                        break;
                    }

                    Marshal.WriteIntPtr(objects, Marshal.GetIUnknownForObject(o));

                    objects = (IntPtr)((long)objects + ipSize);
                }
                break;

            default:
                throw new COMException("Invalid flags", NativeMethods.E_INVALIDARG);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="grfCreateDoc"></param>
        /// <param name="pszMkDocument"></param>
        /// <param name="pszPhysicalView"></param>
        /// <param name="pvHier"></param>
        /// <param name="itemid"></param>
        /// <param name="punkDocDataExisting"></param>
        /// <param name="ppunkDocView"></param>
        /// <param name="ppunkDocData"></param>
        /// <param name="pbstrEditorCaption"></param>
        /// <param name="pguidCmdUI"></param>
        /// <param name="pgrfCDW"></param>
        /// <returns></returns>
        public virtual int CreateEditorInstance(
            uint createEditorFlags,
            string documentMoniker,
            string physicalView,
            IVsHierarchy hierarchy,
            uint itemid,
            IntPtr docDataExisting,
            out IntPtr docView,
            out IntPtr docData,
            out string editorCaption,
            out Guid commandUIGuid,
            out int createDocumentWindowFlags)
        {
            // Initialize output parameters
            docView                   = IntPtr.Zero;
            docData                   = IntPtr.Zero;
            commandUIGuid             = Guid.Empty;
            createDocumentWindowFlags = 0;
            editorCaption             = null;

            // Validate inputs
            if ((createEditorFlags & (uint)(VSConstants.CEF.OpenFile | VSConstants.CEF.Silent)) == 0)
            {
                return(VSConstants.E_INVALIDARG);
            }

            if (docDataExisting != IntPtr.Zero && PromptEncodingOnLoad)
            {
                return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
            }

            // Get a text buffer
            IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker);

            // Assign docData IntPtr to either existing docData or the new text buffer
            if (docDataExisting != IntPtr.Zero)
            {
                docData = docDataExisting;
                Marshal.AddRef(docData);
            }
            else
            {
                docData = Marshal.GetIUnknownForObject(textLines);
            }

            try
            {
                object docViewObject = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid);
                docView = Marshal.GetIUnknownForObject(docViewObject);
            }
            finally
            {
                if (docView == IntPtr.Zero)
                {
                    if (docDataExisting != docData && docData != IntPtr.Zero)
                    {
                        // Cleanup the instance of the docData that we have addref'ed
                        Marshal.Release(docData);
                        docData = IntPtr.Zero;
                    }
                }
            }
            return(VSConstants.S_OK);
        }
Пример #3
0
        public unsafe void CopyFromIndirect(object value)
        {
            VarEnum vt = (VarEnum)(((int)this.VariantType) & ~((int)VarEnum.VT_BYREF));

            if (value == null)
            {
                if (vt == VarEnum.VT_DISPATCH || vt == VarEnum.VT_UNKNOWN || vt == VarEnum.VT_BSTR)
                {
                    *(IntPtr *)this._typeUnion._unionTypes._byref = IntPtr.Zero;
                }
                return;
            }

            if ((vt & VarEnum.VT_ARRAY) != 0)
            {
                Variant vArray;
                Marshal.GetNativeVariantForObject(value, (IntPtr)(void *)&vArray);
                *(IntPtr *)this._typeUnion._unionTypes._byref = vArray._typeUnion._unionTypes._byref;
                return;
            }

            switch (vt)
            {
            case VarEnum.VT_I1:
                *(sbyte *)this._typeUnion._unionTypes._byref = (sbyte)value;
                break;

            case VarEnum.VT_UI1:
                *(byte *)this._typeUnion._unionTypes._byref = (byte)value;
                break;

            case VarEnum.VT_I2:
                *(short *)this._typeUnion._unionTypes._byref = (short)value;
                break;

            case VarEnum.VT_UI2:
                *(ushort *)this._typeUnion._unionTypes._byref = (ushort)value;
                break;

            case VarEnum.VT_BOOL:
                // VARIANT_TRUE  = -1
                // VARIANT_FALSE = 0
                *(short *)this._typeUnion._unionTypes._byref = (bool)value ? (short)-1 : (short)0;
                break;

            case VarEnum.VT_I4:
            case VarEnum.VT_INT:
                *(int *)this._typeUnion._unionTypes._byref = (int)value;
                break;

            case VarEnum.VT_UI4:
            case VarEnum.VT_UINT:
                *(uint *)this._typeUnion._unionTypes._byref = (uint)value;
                break;

            case VarEnum.VT_ERROR:
                *(int *)this._typeUnion._unionTypes._byref = ((ErrorWrapper)value).ErrorCode;
                break;

            case VarEnum.VT_I8:
                *(long *)this._typeUnion._unionTypes._byref = (long)value;
                break;

            case VarEnum.VT_UI8:
                *(ulong *)this._typeUnion._unionTypes._byref = (ulong)value;
                break;

            case VarEnum.VT_R4:
                *(float *)this._typeUnion._unionTypes._byref = (float)value;
                break;

            case VarEnum.VT_R8:
                *(double *)this._typeUnion._unionTypes._byref = (double)value;
                break;

            case VarEnum.VT_DATE:
                *(double *)this._typeUnion._unionTypes._byref = ((DateTime)value).ToOADate();
                break;

            case VarEnum.VT_UNKNOWN:
                *(IntPtr *)this._typeUnion._unionTypes._byref = Marshal.GetIUnknownForObject(value);
                break;

            case VarEnum.VT_DISPATCH:
                *(IntPtr *)this._typeUnion._unionTypes._byref = Marshal.GetIDispatchForObject(value);
                break;

            case VarEnum.VT_BSTR:
                *(IntPtr *)this._typeUnion._unionTypes._byref = Marshal.StringToBSTR((string)value);
                break;

            case VarEnum.VT_CY:
                *(long *)this._typeUnion._unionTypes._byref = decimal.ToOACurrency((decimal)value);
                break;

            case VarEnum.VT_DECIMAL:
                *(decimal *)this._typeUnion._unionTypes._byref = (decimal)value;
                break;

            case VarEnum.VT_VARIANT:
                Marshal.GetNativeVariantForObject(value, this._typeUnion._unionTypes._byref);
                break;

            default:
                throw new ArgumentException();
            }
        }
Пример #4
0
        public void CopyFromIndirect(object value)
        {
            VarEnum enum2 = this.VariantType & ~VarEnum.VT_BYREF;

            if (value == null)
            {
                switch (enum2)
                {
                case VarEnum.VT_DISPATCH:
                case VarEnum.VT_UNKNOWN:
                case VarEnum.VT_BSTR:
                    this._typeUnion._unionTypes._byref[0] = IntPtr.Zero;
                    break;
                }
            }
            else
            {
                switch (enum2)
                {
                case VarEnum.VT_I2:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((short)value);
                    return;

                case VarEnum.VT_I4:
                case VarEnum.VT_INT:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((int)value);
                    return;

                case VarEnum.VT_R4:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((float)value);
                    return;

                case VarEnum.VT_R8:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((double)value);
                    return;

                case VarEnum.VT_CY:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)decimal.ToOACurrency((decimal)value);
                    return;

                case VarEnum.VT_DATE:
                {
                    DateTime time = (DateTime)value;
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)time.ToOADate();
                    return;
                }

                case VarEnum.VT_BSTR:
                    this._typeUnion._unionTypes._byref[0] = Marshal.StringToBSTR((string)value);
                    return;

                case VarEnum.VT_DISPATCH:
                    this._typeUnion._unionTypes._byref[0] = Marshal.GetIDispatchForObject(value);
                    return;

                case VarEnum.VT_ERROR:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((ErrorWrapper)value).ErrorCode;
                    return;

                case VarEnum.VT_BOOL:
                    this._typeUnion._unionTypes._byref[0] = ((bool)value) ? ((IntPtr)(-1)) : IntPtr.Zero;
                    return;

                case VarEnum.VT_UNKNOWN:
                    this._typeUnion._unionTypes._byref[0] = Marshal.GetIUnknownForObject(value);
                    return;

                case VarEnum.VT_DECIMAL:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((decimal)value);
                    return;

                case VarEnum.VT_I1:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((sbyte)value);
                    return;

                case VarEnum.VT_UI1:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((byte)value);
                    return;

                case VarEnum.VT_UI2:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((ushort)value);
                    return;

                case VarEnum.VT_UI4:
                case VarEnum.VT_UINT:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((uint)value);
                    return;

                case VarEnum.VT_I8:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((long)value);
                    return;

                case VarEnum.VT_UI8:
                    this._typeUnion._unionTypes._byref[0] = (IntPtr)((ulong)value);
                    return;
                }
                throw new ArgumentException("invalid argument type");
            }
        }