System.Windows.Forms.XplatUIX11.TranslatePropertyToClipboard C# (CSharp) Method

TranslatePropertyToClipboard() private method

private TranslatePropertyToClipboard ( IntPtr property ) : void
property IntPtr
return void
		private void TranslatePropertyToClipboard(IntPtr property) {
			IntPtr			actual_atom;
			int			actual_format;
			IntPtr			nitems;
			IntPtr			bytes_after;
			IntPtr			prop = IntPtr.Zero;

			Clipboard.Item = null;

			XGetWindowProperty(DisplayHandle, FosterParent, property, IntPtr.Zero, new IntPtr (0x7fffffff), true, (IntPtr)Atom.AnyPropertyType, out actual_atom, out actual_format, out nitems, out bytes_after, ref prop);

			if ((long)nitems > 0) {
				if (property == (IntPtr)Atom.XA_STRING) {
					Clipboard.Item = Marshal.PtrToStringAnsi(prop);
				} else if (property == (IntPtr)Atom.XA_BITMAP) {
					// FIXME - convert bitmap to image
				} else if (property == (IntPtr)Atom.XA_PIXMAP) {
					// FIXME - convert pixmap to image
				} else if (property == OEMTEXT) {
					Clipboard.Item = Marshal.PtrToStringAnsi(prop);
				} else if (property == UTF8_STRING) {
					byte [] buffer = new byte [(int)nitems];
					for (int i = 0; i < (int)nitems; i++)
						buffer [i] = Marshal.ReadByte (prop, i);
					Clipboard.Item = Encoding.UTF8.GetString (buffer);
				} else if (property == UTF16_STRING) {
					Clipboard.Item = Marshal.PtrToStringUni (prop, Encoding.Unicode.GetMaxCharCount ((int)nitems));
				} else if (property == RICHTEXTFORMAT)
					Clipboard.Item = Marshal.PtrToStringAnsi(prop);
				else if (DataFormats.ContainsFormat (property.ToInt32 ())) {
					if (DataFormats.GetFormat (property.ToInt32 ()).is_serializable) {
						MemoryStream memory_stream = new MemoryStream ((int)nitems);
						for (int i = 0; i < (int)nitems; i++)
							memory_stream.WriteByte (Marshal.ReadByte (prop, i));

						memory_stream.Position = 0;
						BinaryFormatter formatter = new BinaryFormatter ();
						Clipboard.Item = formatter.Deserialize (memory_stream);
						memory_stream.Close ();
					}
				}

				XFree(prop);
			}
		}
XplatUIX11