示例#1
0
 private void PasteHandler(object sender, Forms.KeyEventArgs e)
 {
     if (e.Control && e.KeyCode == Keys.V)
     {
         richTextEditorBox.Paste(DataFormats.GetFormat(DataFormats.Text));
         e.Handled = true;
     }
 }
            public FormatEnumerator(IDataObject parent, string[] formats)
            {
                Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, $"FormatEnumerator: Constructed: {parent}, string[{(formats?.Length ?? 0)}]");

                _parent = parent;

                if (formats != null)
                {
                    for (int i = 0; i < formats.Length; i++)
                    {
                        string    format = formats[i];
                        FORMATETC temp   = new FORMATETC
                        {
                            cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id)),
                            dwAspect = DVASPECT.DVASPECT_CONTENT,
                            ptd      = IntPtr.Zero,
                            lindex   = -1
                        };

                        if (format.Equals(DataFormats.Bitmap))
                        {
                            temp.tymed = TYMED.TYMED_GDI;
                        }
                        else if (format.Equals(DataFormats.Text) ||
                                 format.Equals(DataFormats.UnicodeText) ||
                                 format.Equals(DataFormats.StringFormat) ||
                                 format.Equals(DataFormats.Rtf) ||
                                 format.Equals(DataFormats.CommaSeparatedValue) ||
                                 format.Equals(DataFormats.FileDrop) ||
                                 format.Equals(CF_DEPRECATED_FILENAME) ||
                                 format.Equals(CF_DEPRECATED_FILENAMEW))
                        {
                            temp.tymed = TYMED.TYMED_HGLOBAL;
                        }
                        else
                        {
                            temp.tymed = TYMED.TYMED_HGLOBAL;
                        }

                        _formats.Add(temp);
                    }
                }
            }
            private bool GetDataPresentInner(string format)
            {
                Debug.Assert(_innerData is not null, "You must have an innerData on all DataObjects");
                FORMATETC formatetc = new FORMATETC
                {
                    cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id)),
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1
                };

                for (int i = 0; i < s_allowedTymeds.Length; i++)
                {
                    formatetc.tymed |= s_allowedTymeds[i];
                }

                int hr = QueryGetDataUnsafe(ref formatetc);

                return(hr == (int)HRESULT.S_OK);
            }
示例#4
0
        private void GetDataIntoOleStructs(ref FORMATETC formatetc,
                                           ref STGMEDIUM medium)
        {
            if (GetTymedUseable(formatetc.tymed) && GetTymedUseable(medium.tymed))
            {
                string format = DataFormats.GetFormat(formatetc.cfFormat).Name;

                if (GetDataPresent(format))
                {
                    object data = GetData(format);

                    if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != 0)
                    {
                        HRESULT hr = SaveDataToHandle(data, format, ref medium);
                        if (hr.Failed())
                        {
                            Marshal.ThrowExceptionForHR((int)hr);
                        }
                    }
                    else if ((formatetc.tymed & TYMED.TYMED_GDI) != 0)
                    {
                        if (format.Equals(DataFormats.Bitmap) && data is Bitmap bm &&
                            bm != null)
                        {
                            // save bitmap
                            medium.unionmember = (IntPtr)GetCompatibleBitmap(bm);
                        }
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR((int)HRESULT.DV_E_TYMED);
                    }
                }
                else
                {
                    Marshal.ThrowExceptionForHR((int)HRESULT.DV_E_FORMATETC);
                }
            }
            else
            {
                Marshal.ThrowExceptionForHR((int)HRESULT.DV_E_TYMED);
            }
        }
            /// <summary>
            ///  Uses HGLOBALs and retrieves the specified format from the bound IComDataObject.
            /// </summary>
            private object?GetDataFromOleHGLOBAL(string format, out bool done)
            {
                done = false;
                Debug.Assert(_innerData is not null, "You must have an innerData on all DataObjects");

                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = TYMED.TYMED_HGLOBAL;

                object?data = null;

                if ((int)HRESULT.S_OK == QueryGetDataUnsafe(ref formatetc))
                {
                    try
                    {
                        _innerData.GetData(ref formatetc, out medium);

                        if (medium.tymed == TYMED.TYMED_HGLOBAL && medium.unionmember != IntPtr.Zero)
                        {
                            data = GetDataFromHGLOBAL(format, medium.unionmember);
                        }
                    }
                    catch (RestrictedTypeDeserializationException)
                    {
                        done = true;
                    }
                    catch
                    {
                    }
                    finally
                    {
                        Ole32.ReleaseStgMedium(ref medium);
                    }
                }

                return(data);
            }
示例#6
0
        internal static bool IsFormatValid(FORMATETC[] formats)
        {
            Debug.Assert(formats != null, "Null returned from GetFormats");
            if (formats.Length <= 4)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    short format = formats[i].cfFormat;
                    if (format != NativeMethods.CF_TEXT &&
                        format != NativeMethods.CF_UNICODETEXT &&
                        format != DataFormats.GetFormat("System.String").Id&&
                        format != DataFormats.GetFormat("Csv").Id)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(false);
        }
示例#7
0
        internal static void SetDataObjectImpl(object data, bool copy)
        {
            var converter = new XplatUI.ObjectToClipboard(ConvertToClipboardData);

            var clipboard_handle = XplatUI.ClipboardOpen(false);

            XplatUI.ClipboardStore(clipboard_handle, null, 0, null, copy);              // Empty clipboard

            if (data is IDataObject idata)
            {
                XplatUI.ClipboardStore(clipboard_handle, idata, DataFormats.GetFormat(IDataObjectFormat).Id, converter, copy);
            }
            else
            {
                var format = DataFormats.Format.Find(data.GetType().FullName);
                var id     = (format != null) && (format.Name != DataFormats.StringFormat) ? format.Id : -1;
                XplatUI.ClipboardStore(clipboard_handle, data, id, converter, copy);
            }

            XplatUI.ClipboardClose(clipboard_handle);
        }
示例#8
0
        //RichTextBox 插入图片
        public void ShowInsertImageDlg()
        {
            OpenFileDialog OpenFileDialog1 = new OpenFileDialog();

            OpenFileDialog1.Title       = "Select Image";
            OpenFileDialog1.Filter      = "BMP File|*.BMP|JPEG File|*.JPG|GIF File|*.GIF|PNG File|*.PNG|ICO File|*.ICO|Image File|*.BMP;*.DIB;*.RLE;*.JPG;*.JPEG;*.JPE;*.JFIF;*.GIF;*.EMF;*.WMF;*.TIF;*.PNG;*.ICO|All File|*.*";
            OpenFileDialog1.FilterIndex = 6;
            if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string strImagePath = OpenFileDialog1.FileName;
                Image  img;
                img = Image.FromFile(strImagePath);
                Clipboard.SetDataObject(img);
                DataFormats.Format df;
                df = DataFormats.GetFormat(DataFormats.Bitmap);
                if (this.CanPaste(df))
                {
                    this.Paste(df);
                }
            }
        }
示例#9
0
        internal static IDataObject GetDataObject(bool primary_selection)
        {
            IDataObject data = null;

            var clipboard_handle = XplatUI.ClipboardOpen(primary_selection);

            var formats = XplatUI.ClipboardAvailableFormats(clipboard_handle);

            if (formats != null)
            {
                var format    = DataFormats.GetFormat(IDataObjectFormat).Id;
                var converter = new XplatUI.ClipboardToObject(ConvertFromClipboardData);
                if (XplatUI.ClipboardRetrieve(clipboard_handle, format, converter) is IDataObject idata)
                {
                    data = idata;
                }
            }

            XplatUI.ClipboardClose(clipboard_handle);

            return(data ?? new DataObject());
        }
示例#10
0
        internal IStream GetStream(System.Runtime.InteropServices.ComTypes.IDataObject cdata, int index)
        {
            var format = new FORMATETC
            {
                cfFormat = (short)DataFormats.GetFormat(CFSTR_FILECONTENTS).Id,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                tymed    = TYMED.TYMED_ISTREAM,
                lindex   = index
            };

            cdata.GetData(ref format, out STGMEDIUM medium);

            if (medium.tymed == format.tymed)
            {
                if (Marshal.GetObjectForIUnknown(medium.unionmember) is IStream stream)
                {
                    return(stream);
                }
            }

            return(null);
        }
示例#11
0
        int IComDataObject.QueryGetData(ref FORMATETC formatetc)
        {
            Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "QueryGetData");
            if (innerData is OleConverter)
            {
                return(((OleConverter)innerData).OleDataObject.QueryGetData(ref formatetc));
            }

            if (formatetc.dwAspect == DVASPECT.DVASPECT_CONTENT)
            {
                if (GetTymedUseable(formatetc.tymed))
                {
                    if (formatetc.cfFormat == 0)
                    {
                        Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "QueryGetData::returning S_FALSE because cfFormat == 0");
                        return((int)HRESULT.S_FALSE);
                    }
                    else if (!GetDataPresent(DataFormats.GetFormat(formatetc.cfFormat).Name))
                    {
                        return((int)HRESULT.DV_E_FORMATETC);
                    }
                }
                else
                {
                    return((int)HRESULT.DV_E_TYMED);
                }
            }
            else
            {
                return((int)HRESULT.DV_E_DVASPECT);
            }
#if DEBUG
            int format = unchecked ((ushort)formatetc.cfFormat);
            Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "QueryGetData::cfFormat " + format.ToString(CultureInfo.InvariantCulture) + " found");
#endif
            return((int)HRESULT.S_OK);
        }
	public bool CanPaste(DataFormats.Format clipFormat)
	{
		throw new NotImplementedException("CanPaste");
	}
示例#13
0
		internal bool Paste (IDataObject clip, DataFormats.Format format, bool obey_length)
		{
			string		s;

			if (clip == null)
				return false;

			if (format == null) {
				if ((this is RichTextBox) && clip.GetDataPresent(DataFormats.Rtf)) {
					format = DataFormats.GetFormat(DataFormats.Rtf);
				} else if ((this is RichTextBox) && clip.GetDataPresent (DataFormats.Bitmap)) {
					format = DataFormats.GetFormat (DataFormats.Bitmap);
				} else if (clip.GetDataPresent(DataFormats.UnicodeText)) {
					format = DataFormats.GetFormat(DataFormats.UnicodeText);
				} else if (clip.GetDataPresent(DataFormats.Text)) {
					format = DataFormats.GetFormat(DataFormats.Text);
				} else {
					return false;
				}
			} else {
				if ((format.Name == DataFormats.Rtf) && !(this is RichTextBox)) {
					return false;
				}

				if (!clip.GetDataPresent(format.Name)) {
					return false;
				}
			}

			if (format.Name == DataFormats.Rtf) {
				document.undo.BeginUserAction (Locale.GetText ("Paste"));
				((RichTextBox)this).SelectedRtf = (string)clip.GetData(DataFormats.Rtf);
				document.undo.EndUserAction ();
				Modified = true;
				return true;
			} else if (format.Name == DataFormats.Bitmap) {
				document.undo.BeginUserAction (Locale.GetText ("Paste"));
				//	document.InsertImage (document.caret.line, document.caret.pos, (Image) clip.GetData (DataFormats.Bitmap));
				document.MoveCaret (CaretDirection.CharForward);
				document.undo.EndUserAction ();
				return true;
			} else if (format.Name == DataFormats.UnicodeText) {
				s = (string)clip.GetData(DataFormats.UnicodeText);
			} else if (format.Name == DataFormats.Text) {
				s = (string)clip.GetData(DataFormats.Text);
			} else {
				return false;
			}

			if (!obey_length) {
				document.undo.BeginUserAction (Locale.GetText ("Paste"));
				this.SelectedText = s;
				document.undo.EndUserAction ();
			} else {
				if ((s.Length + (document.Length - SelectedText.Length)) < max_length) {
					document.undo.BeginUserAction (Locale.GetText ("Paste"));
					this.SelectedText = s;
					document.undo.EndUserAction ();
				} else if ((document.Length - SelectedText.Length) < max_length) {
					document.undo.BeginUserAction (Locale.GetText ("Paste"));
					this.SelectedText = s.Substring (0, max_length - (document.Length - SelectedText.Length));
					document.undo.EndUserAction ();
				}
			}

			Modified = true;
			return true;
		}
示例#14
0
		/// <summary>
		/// Given a toolbox item "unique ID" and a data format identifier, returns the content of
		/// the data format. 
		/// </summary>
		/// <param name="itemId">The unique ToolboxItem to retrieve data for</param>
		/// <param name="format">The desired format of the resulting data</param>
		protected override object GetToolboxItemData(string itemId, DataFormats.Format format)
		{
			Debug.Assert(toolboxHelper != null, "Toolbox helper is not initialized");
		
			// Retrieve the specified ToolboxItem from the DSL
			return toolboxHelper.GetToolboxItemData(itemId, format);
		}
示例#15
0
            /// <summary>
            ///  Uses IStream and retrieves the specified format from the bound IComDataObject.
            /// </summary>
            private unsafe object?GetDataFromOleIStream(string format)
            {
                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = TYMED.TYMED_ISTREAM;

                // Limit the # of exceptions we may throw below.
                if ((int)HRESULT.S_OK != QueryGetDataUnsafe(ref formatetc))
                {
                    return(null);
                }

                try
                {
                    _innerData.GetData(ref formatetc, out medium);
                }
                catch
                {
                    return(null);
                }

                Ole32.IStream?pStream = null;
                IntPtr        hglobal = IntPtr.Zero;

                try
                {
                    if (medium.tymed == TYMED.TYMED_ISTREAM && medium.unionmember != IntPtr.Zero)
                    {
                        pStream = (Ole32.IStream)Marshal.GetObjectForIUnknown(medium.unionmember);
                        pStream.Stat(out Ole32.STATSTG sstg, Ole32.STATFLAG.DEFAULT);

                        hglobal = Kernel32.GlobalAlloc(
                            Kernel32.GMEM.MOVEABLE | Kernel32.GMEM.DDESHARE | Kernel32.GMEM.ZEROINIT,
                            (uint)sstg.cbSize);
                        // not throwing here because the other out of memory condition on GlobalAlloc
                        // happens inside innerData.GetData and gets turned into a null return value
                        if (hglobal == IntPtr.Zero)
                        {
                            return(null);
                        }
                        IntPtr ptr = Kernel32.GlobalLock(hglobal);
                        pStream.Read((byte *)ptr, (uint)sstg.cbSize, null);
                        Kernel32.GlobalUnlock(hglobal);

                        return(GetDataFromHGLOBAL(format, hglobal));
                    }

                    return(null);
                }
                finally
                {
                    if (hglobal != IntPtr.Zero)
                    {
                        Kernel32.GlobalFree(hglobal);
                    }

                    if (pStream is not null)
                    {
                        Marshal.ReleaseComObject(pStream);
                    }

                    Ole32.ReleaseStgMedium(ref medium);
                }
            }
示例#16
0
		public static void PrintFormatInfo(DataFormats.Format f) {
			Console.WriteLine("Format ID: " + f.Id + ", Name: " + f.Name);
		}
 private void PasteUnsafe(DataFormats.Format clipFormat, int hIcon)
 {
     System.Windows.Forms.NativeMethods.REPASTESPECIAL lParam = null;
     if (hIcon != 0)
     {
         lParam = new System.Windows.Forms.NativeMethods.REPASTESPECIAL {
             dwAspect = 4,
             dwParam = hIcon
         };
     }
     System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x440, clipFormat.Id, lParam);
 }
 /// <summary>
 /// Pastes the contents of the Clipboard in the specified Clipboard format.
 /// </summary>
 /// <param name="clipFormat">The Clipboard format in which the data should be obtained from the Clipboard.</param>
 public void Paste(DataFormats.Format clipFormat)
 {
     _richTextBox.Paste(clipFormat);
 }
 /// <summary>
 /// Determines whether you can paste information from the Clipboard in the specified data format.
 /// </summary>
 /// <param name="clipFormat">One of the System.Windows.Forms.DataFormats.Format values.</param>
 /// <returns>true if you can paste data from the Clipboard in the specified data format; otherwise, false.</returns>
 public bool CanPaste(DataFormats.Format clipFormat)
 {
     return _richTextBox.CanPaste(clipFormat);
 }
示例#20
0
        static XplatUI()
        {
            // Compose name with current domain id because on Win32 we register class name
            // and name must be unique to process. If we load MWF into multiple appdomains
            // and try to register same class name we fail.
//			default_class_name = "SWFClass" + System.Threading.Thread.GetDomainID ().ToString ();

            if (RunningOnUnix)
            {
                //if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null) {
                //        driver=XplatUIX11_new.GetInstance ();
                //} else
                var loadable = Environment.GetEnvironmentVariable("MONO_MWF_DRIVER");
                if (loadable != null)
                {
                    var a  = System.Reflection.Assembly.LoadFile(loadable);
                    var mi = a?.GetType("Bootstrap")?.GetMethod("CreateInstance");
                    if (mi != null)
                    {
                        driver = (XplatUIDriver)mi.Invoke(null, null);
                    }
                }
                else
                {
                    if (Environment.GetEnvironmentVariable("MONO_MWF_MAC_FORCE_X11") != null)
                    {
                        driver = XplatUIX11.GetInstance();
                    }
                    else
                    {
                        IntPtr buf = Marshal.AllocHGlobal(8192);
                        // This is a hacktastic way of getting sysname from uname ()
                        if (uname(buf) != 0)
                        {
                            // WTF: We cannot run uname
                            driver = XplatUIX11.GetInstance();
                        }
                        else
                        {
                            string os = Marshal.PtrToStringAnsi(buf);
                            if (os == "Darwin")
                            {
                                driver = XplatUICarbon.GetInstance();
                            }
                            else
                            {
                                driver = XplatUIX11.GetInstance();
                            }
                        }
                        Marshal.FreeHGlobal(buf);
                    }
                }
            }
            else
            {
                driver = XplatUIWin32.GetInstance();
            }

            driver.InitializeDriver();

            // Initialize things that need to be done after the driver is ready
            DataFormats.GetFormat(0);

            // Signal that the Application loop can be run.
            // This allows UIA to initialize a11y support for MWF
            // before the main loop begins.
            Application.FirePreRun();
        }
 internal static bool IsFormatValid(FORMATETC[] formats)
 {
     if ((formats == null) || (formats.Length > 4))
     {
         return(false);
     }
     for (int i = 0; i < formats.Length; i++)
     {
         short cfFormat = formats[i].cfFormat;
         if (((cfFormat != 1) && (cfFormat != 13)) && ((cfFormat != DataFormats.GetFormat("System.String").Id) && (cfFormat != DataFormats.GetFormat("Csv").Id)))
         {
             return(false);
         }
     }
     return(true);
 }
示例#22
0
 /// <summary>
 /// Pastes the contents of the Clipboard in the specified Clipboard format. 
 /// </summary>
 /// <param name="clipFormat"></param>
 public void Paste(DataFormats.Format clipFormat)
 {
     _RichTextBox.Paste(clipFormat);
     UpdateScrollBarsDelayed();
 }
示例#23
0
        public static void Main()
        {
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Bitmap));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.CommaSeparatedValue));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Dib));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Dif));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.EnhancedMetafile));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.FileDrop));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Html));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Locale));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.MetafilePict));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.OemText));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Palette));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.PenData));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Riff));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Rtf));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Serializable));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.StringFormat));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.SymbolicLink));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Text));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.Tiff));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.UnicodeText));
            PrintFormatInfo(DataFormats.GetFormat(DataFormats.WaveAudio));

            // Add our own format
            PrintFormatInfo(DataFormats.GetFormat("Birthday"));

            // Test some basic stuff
            DataObject dobj;
            Control    c;
            string     rtf;

            c   = new Control();
            rtf = "\\r\\t\\f  string";

            // Load the data object
            dobj = new DataObject(DataFormats.Text, "I am text");
            dobj.SetData(c.GetType(), c);
            dobj.SetData(DataFormats.Rtf, rtf);

            PrintFormats("GetFormats(): ", dobj.GetFormats());                                                           // Count should be 5
            PrintFormats("GetFormats(true): ", dobj.GetFormats(true));                                                   // Count should be 5
            PrintFormats("GetFormats(false): ", dobj.GetFormats(false));                                                 // Count should be 3

            Console.WriteLine("GetDataPresent(typeof(string)): {0}", dobj.GetDataPresent(typeof(string)));               // We expect true
            Console.WriteLine("GetDataPresent(DataFormats.Text): {0}", dobj.GetDataPresent(DataFormats.Text));           // We expect true
            Console.WriteLine("GetDataPresent(DataFormats.WaveAudio): {0}", dobj.GetDataPresent(DataFormats.WaveAudio)); // We expect false

            Console.WriteLine("GetData(DataFormats.Rtf): {0}", dobj.GetData(DataFormats.Rtf));                           // We expect "\r\t\f  string"

            clipboard clip = new clipboard();

            PrintClipboardContents();

            IDataObject data;

            data = Clipboard.GetDataObject();

            if (data != null && data.GetDataPresent(DataFormats.Bitmap))
            {
                image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
            }

            Bitmap i = new Bitmap("test.bmp");
            string s = "bummerä";

            Clipboard.SetDataObject(s);

            Application.Run(clip);
        }
	public void Paste(DataFormats.Format clipFormat)
	{
		throw new NotImplementedException("Paste");
	}
示例#25
0
        /// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.Paste"]/*' />
        /// <devdoc>
        ///     Pastes the contents of the clipboard in the given clipboard format.
        /// </devdoc>
        public void Paste(DataFormats.Format clipFormat) {
            Debug.WriteLineIf(IntSecurity.SecurityDemand.TraceVerbose, "ClipboardRead Demanded");
            IntSecurity.ClipboardRead.Demand();

            PasteUnsafe(clipFormat, 0);
        }
示例#26
0
		/// <summary>
		/// Given a toolbox item "unique ID" and a data format identifier, returns the content of
		/// the data format. 
		/// </summary>
		/// <param name="itemId">The unique ToolboxItem to retrieve data for</param>
		/// <param name="format">The desired format of the resulting data</param>
		public virtual object GetToolboxItemData(string itemId, DataFormats.Format format)
		{
			DslDesign::ModelingToolboxItem item = null;

			global::System.Resources.ResourceManager resourceManager = global::Microsoft.Practices.ServiceFactory.HostDesigner.HostDesignerDomainModel.SingletonResourceManager;
			global::System.Globalization.CultureInfo resourceCulture = global::System.Globalization.CultureInfo.CurrentUICulture;

			System.Windows.Forms.IDataObject tbxDataObj;

			//get the toolbox item
			item = GetToolboxItem(itemId);

			if (item != null)
			{
				ToolboxItemContainer container = new ToolboxItemContainer(item);
				tbxDataObj = container.ToolboxData;

				if (tbxDataObj.GetDataPresent(format.Name))
				{
					return tbxDataObj.GetData(format.Name);
				}
				else 
				{
					string invalidFormatString = resourceManager.GetString("UnsupportedToolboxFormat", resourceCulture);
					throw new InvalidOperationException(string.Format(resourceCulture, invalidFormatString, format.Name));
				}
			}

			string errorFormatString = resourceManager.GetString("UnresolvedToolboxItem", resourceCulture);
			throw new InvalidOperationException(string.Format(resourceCulture, errorFormatString, itemId));
		}		
示例#27
0
 public static Object Get(DataFormats.Format Format)
 {
     return Clipboard.GetData(Format.Name);
 }
 public void Paste(DataFormats.Format clipFormat)
 {
     System.Windows.Forms.IntSecurity.ClipboardRead.Demand();
     this.PasteUnsafe(clipFormat, 0);
 }
示例#29
0
 public static bool ClipboardContains(DataFormats.Format Format)
 {
     return Clipboard.ContainsData(Format.Name);
 }
示例#30
0
            /// <summary>
            ///  Retrieves the specified format data from the bound IComDataObject, from
            ///  other sources that IStream and HGLOBAL... this is really just a place
            ///  to put the "special" formats like BITMAP, ENHMF, etc.
            /// </summary>
            private object?GetDataFromOleOther(string format)
            {
                Debug.Assert(_innerData is not null, "You must have an innerData on all DataObjects");

                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                TYMED tymed = (TYMED)0;

                if (format.Equals(DataFormats.Bitmap))
                {
                    tymed = TYMED.TYMED_GDI;
                }

                if (tymed == (TYMED)0)
                {
                    return(null);
                }

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = tymed;

                object?data = null;

                if ((int)HRESULT.S_OK == QueryGetDataUnsafe(ref formatetc))
                {
                    try
                    {
                        _innerData.GetData(ref formatetc, out medium);
                    }
                    catch
                    {
                    }
                }

                try
                {
                    if (medium.tymed == TYMED.TYMED_GDI && medium.unionmember != IntPtr.Zero)
                    {
                        if (format.Equals(DataFormats.Bitmap))
                        {
                            // ASURT 140870 -- GDI+ doesn't own this HBITMAP, but we can't
                            // delete it while the object is still around.  So we have to do the really expensive
                            // thing of cloning the image so we can release the HBITMAP.

                            // This bitmap is created by the com object which originally copied the bitmap to the
                            // clipboard. We call Add here, since DeleteObject calls Remove.
                            Image clipboardImage = Image.FromHbitmap(medium.unionmember);
                            if (clipboardImage is not null)
                            {
                                Image firstImage = clipboardImage;
                                clipboardImage = (Image)clipboardImage.Clone();
                                firstImage.Dispose();
                            }

                            data = clipboardImage;
                        }
                    }
                }
                finally
                {
                    Ole32.ReleaseStgMedium(ref medium);
                }

                return(data);
            }
 public bool CanPaste(DataFormats.Format clipFormat)
 {
     return (((int) ((long) base.SendMessage(0x432, clipFormat.Id, 0))) != 0);
 }
示例#32
0
        /// <include file='doc\Package.uex' path='docs/doc[@for="Package.GetToolboxItemData"]' />
        /// <devdoc>
        /// Given a toolbox item "unique ID" and a data format identifier, returns the content of
        /// the data format.  If this is not implemented, the shell will fall back to a call to
        /// IVsPackage.ResetDefaults (which invokes the ToolboxInitialized or ToolboxUpgraded
        /// event).
        /// </devdoc>
        protected virtual object GetToolboxItemData(string itemId, DataFormats.Format format)
        {
            if (string.IsNullOrEmpty(itemId)) {
                throw new ArgumentNullException("itemId");
            }

            // Try cache first
            System.Windows.Forms.IDataObject tbxDataObj;
            if (_tbxItemDataCache.TryGetValue(itemId, out tbxDataObj)) {
                if (tbxDataObj.GetDataPresent(format.Name)) {
                    return tbxDataObj.GetData(format.Name);
                }
                else {
                    throw new InvalidOperationException(string.Format(Resources.Culture, Resources.Toolbox_UnsupportedFormat, format.Name));
                }
            }

            string typeName;
            string assemblyName;
            int idx = itemId.IndexOf(",");
            if (idx == -1) {
                Debug.Fail("Invalid toolbox item ID: " + itemId);
                throw new InvalidOperationException(string.Format(Resources.Culture, Resources.Toolbox_InvalidItemId, itemId));
            }
            else {
                typeName = itemId.Substring(0, idx).Trim();
                assemblyName = itemId.Substring(idx + 1).Trim();
            }

            if (assemblyName.IndexOf(",") == -1) {
                // Must use the assembly enumeration service to locate the assembly.
                Microsoft.VisualStudio.AssemblyEnumerationService enumSvc =
                    new Microsoft.VisualStudio.AssemblyEnumerationService(this);
                foreach (AssemblyName an in enumSvc.GetAssemblyNames(assemblyName)) {
                    assemblyName = an.FullName;
                    break;
                }
            }

            Assembly a = Assembly.Load(assemblyName);
            Debug.Assert(a != null, "Assembly " + assemblyName + " not found on machine");

            if (a != null) {
                Type t = a.GetType(typeName);
                Debug.Assert(t != null, "Type " + itemId + " not found on machine");
                if (t != null) {
                    ToolboxItem item = ToolboxService.GetToolboxItem(t);
                    Debug.Assert(item != null, "Tool " + assemblyName + ":" + itemId + " does not offer a toolbox item");
                    if (item != null) {
                        ToolboxItemContainer container = new ToolboxItemContainer(item);
                        tbxDataObj = container.ToolboxData;
                        // Missed in cache, so save it in cache now
                        _tbxItemDataCache.Add(itemId, tbxDataObj);

                        if (tbxDataObj.GetDataPresent(format.Name)) {
                            return tbxDataObj.GetData(format.Name);
                        }
                        else {
                            throw new InvalidOperationException(string.Format(Resources.Culture, Resources.Toolbox_UnsupportedFormat, format.Name));
                        }
                    }
                }
            }

            throw new InvalidOperationException(string.Format(Resources.Culture, Resources.Toolbox_ItemNotFound, itemId));
        }
示例#33
0
		public void Paste(DataFormats.Format clipFormat) {
			base.Paste(Clipboard.GetDataObject(), clipFormat, false);
		}
示例#34
0
        /// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.Paste1"]/*' />
        /// <devdoc>
        /// Note that this doesn't make a security demand: functions that call this should.
        /// </devdoc>
        private void PasteUnsafe(DataFormats.Format clipFormat, int hIcon) {
            NativeMethods.REPASTESPECIAL rps = null;

            if (hIcon != 0) {
                rps = new NativeMethods.REPASTESPECIAL();
                rps.dwAspect = DVASPECT_ICON;
                rps.dwParam = hIcon;
            }
            UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), RichTextBoxConstants.EM_PASTESPECIAL, clipFormat.Id, rps);
        }
示例#35
0
		public bool CanPaste(DataFormats.Format clipFormat) {
			if ((clipFormat.Name == DataFormats.Rtf) ||
				(clipFormat.Name == DataFormats.Text) ||
				(clipFormat.Name == DataFormats.UnicodeText)) {
					return true;
			}
			return false;
		}
示例#36
0
        /// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.CanPaste"]/*' />
        /// <devdoc>
        ///     Returns a boolean indicating whether the RichTextBoxConstants control can paste the
        ///     given clipboard format.
        /// </devdoc>
        public bool CanPaste(DataFormats.Format clipFormat) {
            bool b = false;
            b = unchecked( (int) (long)SendMessage(RichTextBoxConstants.EM_CANPASTE, clipFormat.Id, 0)) != 0;

            return b;
        }
示例#37
0
 public new void Paste(DataFormats.Format format)
 {
     Paste();
 }