int OleInterop.IDataObject.GetCanonicalFormatEtc(OleInterop.FORMATETC[] pformatectIn, OleInterop.FORMATETC[] pformatetcOut) { if (null != oleData) return oleData.GetCanonicalFormatEtc(pformatectIn, pformatetcOut); // Check that the arrays are not null and with only one element. if ((null == pformatectIn) || (pformatectIn.Length != 1) || (null == pformatetcOut) || (pformatetcOut.Length != 1)) throw new ArgumentException(); BclComTypes.FORMATETC bclFormatIn = StructConverter.OleFormatETC2Bcl(ref pformatectIn[0]); BclComTypes.FORMATETC bclFormatOut; int hr = bclData.GetCanonicalFormatEtc(ref bclFormatIn, out bclFormatOut); NativeMethods.ThrowOnFailure(hr); pformatetcOut[0] = StructConverter.BclFormatETC2Ole(ref bclFormatOut); return hr; }
/// <summary> /// Provides a first chance to tell the shell that this window is capable of handling certain commands. Implements IOleCommandTarget.QueryStatus /// </summary> protected int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, MSOLE.OLECMD[] prgCmds, IntPtr pCmdText) { int hr = VSConstants.S_OK; bool handled = true; // Only handle commands from the Office 97 Command Set (aka VSStandardCommandSet97). if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { // There typically is only one command passed in to this array - in any case, we only care // about the first command. MSOLE.OLECMD cmd = prgCmds[0]; switch ((VSConstants.VSStd97CmdID)cmd.cmdID) { case VSConstants.VSStd97CmdID.Delete: // Always support this command, disabling it if necessary per the control. cmd.cmdf = (uint)(MSOLE.OLECMDF.OLECMDF_SUPPORTED | (myEditor.CanDelete ? MSOLE.OLECMDF.OLECMDF_ENABLED : 0)); prgCmds[0] = cmd; break; case VSConstants.VSStd97CmdID.EditLabel: // Support this command regardless of the current state of the inline editor. // If we do not do this, then an F2 keypress with an editor already open will // report the command as disabled and we would need to use IVsUIShell.UpdateCommandUI // whenever an editor closed to reenable the command. cmd.cmdf = (int)(MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED); prgCmds[0] = cmd; break; default: // Inform the shell that we don't support any other commands. handled = false; hr = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED; break; } } else { // Inform the shell that we don't recognize this command group. handled = false; hr = (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP; } if (!handled) { Debug.Assert(ErrorHandler.Failed(hr)); ModelingDocData docData = CurrentDocument; Microsoft.VisualStudio.Modeling.Shell.UndoManager undoManager; MSOLE.IOleCommandTarget forwardTo; if ((docData != null && null != (undoManager = docData.UndoManager) && null != (forwardTo = undoManager.VSUndoManager as MSOLE.IOleCommandTarget)) || null != (forwardTo = GetService(typeof(MSOLE.IOleCommandTarget)) as MSOLE.IOleCommandTarget)) { // If the command wasn't handled already, forward it to the undo manager. hr = forwardTo.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } } return hr; }
int OleInterop.IDataObject.EnumFormatEtc(uint dwDirection, out OleInterop.IEnumFORMATETC ppenumFormatEtc) { if (null != oleData) return oleData.EnumFormatEtc(dwDirection, out ppenumFormatEtc); BclComTypes.IEnumFORMATETC bclEnum = bclData.EnumFormatEtc((BclComTypes.DATADIR)dwDirection); if (null == bclEnum) { ppenumFormatEtc = null; } else { ppenumFormatEtc = bclEnum as OleInterop.IEnumFORMATETC; if (null == ppenumFormatEtc) ppenumFormatEtc = (OleInterop.IEnumFORMATETC)(new EnumFORMATETC(bclEnum)); } return NativeMethods.S_OK; }
/// <summary> /// Implements <see cref="IVsToolboxUser.IsSupported"/> /// </summary> protected int IsSupported(OLE.IDataObject pDO) { IDataObject data = pDO as IDataObject; if (data == null) { data = new DataObject(pDO); } IToolboxService toolboxService; if (null != (toolboxService = ToolboxService)) { if (toolboxService.IsSupported(data, ToolboxFilterManager.ToolboxFilters)) { return VSConstants.S_OK; } } return VSConstants.E_FAIL; }
/// <summary> /// Implements <see cref="IVsToolboxUser.ItemPicked"/> /// </summary> protected static int ItemPicked(OLE.IDataObject pDO) { return VSConstants.S_OK; }
void OleInterop.IDataObject.SetData(OleInterop.FORMATETC[] pFormatetc, OleInterop.STGMEDIUM[] pmedium, int fRelease) { if (null != oleData) { oleData.SetData(pFormatetc, pmedium, fRelease); return; } if ((null == pFormatetc) || (1 != pFormatetc.Length) || (null == pmedium) || (1 != pmedium.Length)) throw new ArgumentException(); BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); BclComTypes.STGMEDIUM bclMedium = StructConverter.OleSTGMEDIUM2Bcl(ref pmedium[0]); bclData.SetData(ref bclFormat, ref bclMedium, (fRelease == 0) ? false : true); }
internal static BclComTypes.STATDATA OleSTATDATA2Bcl(ref OleInterop.STATDATA oleData) { BclComTypes.STATDATA bclData; if (null == oleData.pAdvSink) { bclData.advSink = null; } else { bclData.advSink = oleData.pAdvSink as BclComTypes.IAdviseSink; if (null == bclData.advSink) bclData.advSink = (BclComTypes.IAdviseSink)(new AdviseSink(oleData.pAdvSink)); } bclData.advf = (BclComTypes.ADVF)oleData.ADVF; bclData.connection = (int)oleData.dwConnection; bclData.formatetc = OleFormatETC2Bcl(ref oleData.FORMATETC); return bclData; }
// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // Next int OleInterop.IEnumFORMATETC.Next(uint celt, OleInterop.FORMATETC[] rgelt, uint[] pceltFetched) { if (null != oleEnum) { return oleEnum.Next(celt, rgelt, pceltFetched); } BclComTypes.FORMATETC[] bclStat = new BclComTypes.FORMATETC[celt]; int[] fetched = new int[1]; int hr = bclEnum.Next((int)celt, bclStat, fetched); if (NativeMethods.Failed(hr)) return hr; if (null != pceltFetched) pceltFetched[0] = (uint)fetched[0]; for (int i = 0; i < fetched[0]; i++) { rgelt[i] = StructConverter.BclFormatETC2Ole(ref bclStat[i]); } return hr; }
internal EnumSTATDATA(OleInterop.IEnumSTATDATA oleEnum) { if (null == oleEnum) throw new ArgumentNullException("Microsoft.VisualStudio.OLE.Interop.IEnumSTATDATA"); this.oleEnum = oleEnum; this.bclEnum = oleEnum as BclComTypes.IEnumSTATDATA; }
internal EnumFORMATETC(OleInterop.IEnumFORMATETC oleEnum) { if (null == oleEnum) throw new ArgumentNullException("Microsoft.VisualStudio.OLE.Interop.IEnumFORMATETC"); this.oleEnum = oleEnum; this.bclEnum = oleEnum as BclComTypes.IEnumFORMATETC; }
////////////////////////////////////////////////////////////// // Clone void OleInterop.IEnumFORMATETC.Clone(out OleInterop.IEnumFORMATETC ppEnum) { ppEnum = null; if (null != oleEnum) { oleEnum.Clone(out ppEnum); } else { BclComTypes.IEnumFORMATETC bclCloned; bclEnum.Clone(out bclCloned); ppEnum = bclCloned as OleInterop.IEnumFORMATETC; if (null == ppEnum) ppEnum = (OleInterop.IEnumFORMATETC)(new EnumFORMATETC(bclCloned)); } }
// ////////////////////////////////////////////////////////////// void IOleAdviseSink.OnRename(OleInterop.IMoniker pmk) { if (null != oleSink) { oleSink.OnRename(pmk); } else { // TODO: Use the IMoniker converter when ready. bclSink.OnRename(null); } }
// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // OnDataChange // void IOleAdviseSink.OnDataChange(OleInterop.FORMATETC[] pFormatetc, OleInterop.STGMEDIUM[] pStgmed) { if (null != oleSink) { oleSink.OnDataChange(pFormatetc, pStgmed); } else { // In order to call the version of this interface defined in the BCL // each array must contain exactly one object. if ((null == pFormatetc) || (null == pStgmed)) throw new ArgumentNullException(""); if ((1 != pFormatetc.Length) || (1 != pStgmed.Length)) throw new InvalidOperationException(); // Convert the parameters BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); BclComTypes.STGMEDIUM bclMedium = StructConverter.OleSTGMEDIUM2Bcl(ref pStgmed[0]); // Now we can call the method on the BCL interface bclSink.OnDataChange(ref bclFormat, ref bclMedium); // Now we have to copy the parameters back into the original structures. pFormatetc[0] = StructConverter.BclFormatETC2Ole(ref bclFormat); pStgmed[0] = StructConverter.BclSTGMEDIUM2Ole(ref bclMedium); } }
int MSOLE.IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, MSOLE.OLECMD[] prgCmds, IntPtr pCmdText) { return QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
void OleInterop.IDataObject.GetDataHere(OleInterop.FORMATETC[] pFormatetc, OleInterop.STGMEDIUM[] pRemoteMedium) { if (null != oleData) { oleData.GetDataHere(pFormatetc, pRemoteMedium); return; } // Check that the arrays are not null and with only one element. if ((null == pFormatetc) || (pFormatetc.Length != 1) || (null == pRemoteMedium) || (pRemoteMedium.Length != 1)) throw new ArgumentException(); // Call the method on the BCL interface BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); BclComTypes.STGMEDIUM bclMedium = StructConverter.OleSTGMEDIUM2Bcl(ref pRemoteMedium[0]); bclData.GetDataHere(ref bclFormat, ref bclMedium); pRemoteMedium[0] = StructConverter.BclSTGMEDIUM2Ole(ref bclMedium); }
////////////////////////////////////////////////////////////// // Clone void OleInterop.IEnumSTATDATA.Clone(out OleInterop.IEnumSTATDATA ppEnum) { ppEnum = null; if (null != oleEnum) { oleEnum.Clone(out ppEnum); } else { BclComTypes.IEnumSTATDATA bclCloned; bclEnum.Clone(out bclCloned); ppEnum = bclCloned as OleInterop.IEnumSTATDATA; if (null == ppEnum) ppEnum = (OleInterop.IEnumSTATDATA)(new EnumSTATDATA(bclCloned)); } }
int OleInterop.IDataObject.QueryGetData(OleInterop.FORMATETC[] pFormatetc) { if (null != oleData) return oleData.QueryGetData(pFormatetc); if ((null == pFormatetc) || (1 != pFormatetc.Length)) throw new ArgumentException(); BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); return bclData.QueryGetData(ref bclFormat); }
// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // Next int OleInterop.IEnumSTATDATA.Next(uint celt, OleInterop.STATDATA[] rgelt, out uint pceltFetched) { pceltFetched = 0; if (null != oleEnum) { return oleEnum.Next(celt, rgelt, out pceltFetched); } BclComTypes.STATDATA[] bclStat = new BclComTypes.STATDATA[celt]; int[] fetched = { (int)pceltFetched }; int hr = bclEnum.Next((int)celt, bclStat, fetched); if (NativeMethods.Failed(hr)) return hr; pceltFetched = (uint)fetched[0]; for (int i = 0; i < pceltFetched; i++) { rgelt[i] = StructConverter.BclSTATDATA2Ole(ref bclStat[i]); } return hr; }
internal static BclComTypes.FORMATETC OleFormatETC2Bcl(ref OleInterop.FORMATETC oleFormat) { BclComTypes.FORMATETC bclFormat; bclFormat.cfFormat = (short)oleFormat.cfFormat; bclFormat.dwAspect = (BclComTypes.DVASPECT)oleFormat.dwAspect; bclFormat.lindex = oleFormat.lindex; bclFormat.ptd = oleFormat.ptd; bclFormat.tymed = (BclComTypes.TYMED)oleFormat.tymed; return bclFormat; }
internal Ole2BclDataObject(OleInterop.IDataObject oleData) { if (null == oleData) throw new ArgumentNullException("Microsoft.VisualStudio.OLE.Interop.IDataObject"); this.oleData = oleData; //this.bclData = oleData as BclComTypes.IDataObject; this.bclData = null; }
internal static BclComTypes.STGMEDIUM OleSTGMEDIUM2Bcl(ref OleInterop.STGMEDIUM oleMedium) { BclComTypes.STGMEDIUM bclMedium; bclMedium.pUnkForRelease = oleMedium.pUnkForRelease; bclMedium.tymed = (BclComTypes.TYMED)oleMedium.tymed; bclMedium.unionmember = oleMedium.unionmember; return bclMedium; }
int OleInterop.IDataObject.DAdvise(OleInterop.FORMATETC[] pFormatetc, uint ADVF, OleInterop.IAdviseSink pAdvSink, out uint pdwConnection) { if (null != oleData) return oleData.DAdvise(pFormatetc, ADVF, pAdvSink, out pdwConnection); // We have to call the method in the BCL version of the interface, so we need to // convert the parameters to the other type of structure. // As first make sure that the array contains exactly one element. if ((null == pFormatetc) || (pFormatetc.Length != 1)) throw new ArgumentException(); // Now convert the patameters BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); BclComTypes.IAdviseSink bclSink = pAdvSink as BclComTypes.IAdviseSink; if (null == bclSink) bclSink = new AdviseSink(pAdvSink); int connection; int hr = bclData.DAdvise(ref bclFormat, (BclComTypes.ADVF)(ADVF), bclSink, out connection); pdwConnection = (uint)connection; return hr; }
int IVsToolboxUser.IsSupported(OLE.IDataObject pDO) { return IsSupported(pDO); }
int OleInterop.IDataObject.EnumDAdvise(out OleInterop.IEnumSTATDATA ppenumAdvise) { if (null != oleData) return oleData.EnumDAdvise(out ppenumAdvise); // Call the BCL version of the method BclComTypes.IEnumSTATDATA bclEnum; int hr = bclData.EnumDAdvise(out bclEnum); NativeMethods.ThrowOnFailure(hr); if (null == bclEnum) { ppenumAdvise = null; } else { ppenumAdvise = bclEnum as OleInterop.IEnumSTATDATA; if (null == ppenumAdvise) ppenumAdvise = (OleInterop.IEnumSTATDATA)(new EnumSTATDATA(bclEnum)); } return hr; }
int IVsToolboxUser.ItemPicked(OLE.IDataObject pDO) { return ItemPicked(pDO); }
/// <summary> /// Provides a first chance to tell the shell that this window is capable of handling certain commands. Implements IOleCommandTarget.QueryStatus /// </summary> protected int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, MSOLE.OLECMD[] prgCmds, IntPtr pCmdText) { int hr = VSConstants.S_OK; bool handled = true; // Only handle commands from the Office 97 Command Set (aka VSStandardCommandSet97). if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { // There typically is only one command passed in to this array - in any case, we only care // about the first command. MSOLE.OLECMD cmd = prgCmds[0]; MSOLE.OLECMDF flags = 0; ReadingRichTextBox activeRichTextEditor = myActiveInlineEditor as ReadingRichTextBox; switch ((VSConstants.VSStd97CmdID)cmd.cmdID) { case VSConstants.VSStd97CmdID.Cut: if (activeRichTextEditor != null) { flags = (myRichTextSelected && !myRichTextProtected) ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED; } break; case VSConstants.VSStd97CmdID.Copy: if (activeRichTextEditor != null) { flags = myRichTextSelected ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED; } break; case VSConstants.VSStd97CmdID.Paste: if (activeRichTextEditor != null) { flags = (!myRichTextProtected && (Clipboard.ContainsText(TextDataFormat.Text) || Clipboard.ContainsText(TextDataFormat.UnicodeText))) ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED; } break; case VSConstants.VSStd97CmdID.SelectAll: if (activeRichTextEditor != null) { flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED; } break; case VSConstants.VSStd97CmdID.Redo: case VSConstants.VSStd97CmdID.MultiLevelRedo: case VSConstants.VSStd97CmdID.MultiLevelUndo: if (activeRichTextEditor != null) { flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED; } break; case VSConstants.VSStd97CmdID.Undo: if (activeRichTextEditor != null) { flags = activeRichTextEditor.CanUndo ? MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED : MSOLE.OLECMDF.OLECMDF_SUPPORTED; } break; case VSConstants.VSStd97CmdID.Delete: // Inform the shell that we should have a chance to handle the delete command. if (!this.myForm.ReadingEditor.EditingFactType.IsEmpty) { flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED; } break; case VSConstants.VSStd97CmdID.EditLabel: // Support this command regardless of the current state of the inline editor. // If we do not do this, then an F2 keypress with an editor already open will // report the command as disabled and we would need to use IVsUIShell.UpdateCommandUI // whenever an editor closed to reenable the command. flags = MSOLE.OLECMDF.OLECMDF_SUPPORTED | MSOLE.OLECMDF.OLECMDF_ENABLED; break; } if (flags == 0) { // Inform the shell that we don't support the command. handled = false; hr = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED; } else { cmd.cmdf = (uint)flags; prgCmds[0] = cmd; } } else { // Inform the shell that we don't recognize this command group. handled = false; hr = (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP; } if (!handled) { Debug.Assert(ErrorHandler.Failed(hr)); ModelingDocData docData = CurrentDocument; Microsoft.VisualStudio.Modeling.Shell.UndoManager undoManager; MSOLE.IOleCommandTarget forwardTo; if ((docData != null && null != (undoManager = docData.UndoManager) && null != (forwardTo = undoManager.VSUndoManager as MSOLE.IOleCommandTarget)) || null != (forwardTo = GetService(typeof(MSOLE.IOleCommandTarget)) as MSOLE.IOleCommandTarget)) { // If the command wasn't handled already, forward it to the undo manager. hr = forwardTo.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } } return hr; }