public override IEnumerable <TransferDataType> GetTypesAvailable()
 {
     foreach (var t in NSPasteboard.GeneralPasteboard.Types)
     {
         yield return(TransferDataType.FromId(t));
     }
 }
Beispiel #2
0
 public static Gtk.TargetList BuildTargetTable(TransferDataType[] types)
 {
     var tl = new Gtk.TargetList ();
     foreach (var tt in types)
         tl.AddTable (CreateTargetEntries (tt));
     return tl;
 }
Beispiel #3
0
 IEnumerable <Gdk.Atom> GetAtomsForType(TransferDataType type)
 {
     foreach (Gtk.TargetEntry te in (Gtk.TargetEntry[])Util.BuildTargetTable(new TransferDataType[] { type }))
     {
         yield return(Gdk.Atom.Intern(te.Target, false));
     }
 }
Beispiel #4
0
        public object GetData(TransferDataType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            while (!IsTypeAvailable(type))
            {
                Thread.Sleep(1);
            }

            if (type == TransferDataType.Image)
            {
                return(WindowsClipboard.GetImage());
            }
            if (type == TransferDataType.Rtf)
            {
                return(WindowsClipboard.GetText(TextDataFormat.Rtf));
            }
            if (type == TransferDataType.Text)
            {
                if (WindowsClipboard.ContainsText(TextDataFormat.UnicodeText))
                {
                    return(WindowsClipboard.GetText());
                }

                return(WindowsClipboard.GetText(TextDataFormat.Text));
            }

            throw new NotImplementedException();
        }
Beispiel #5
0
		public override bool IsTypeAvailable (TransferDataType type)
		{
			if (type == null)
				throw new ArgumentNullException ("type");

			return WindowsClipboard.ContainsData (type.ToWpfDataFormat ());
		}
Beispiel #6
0
		public override void SetData (TransferDataType type, Func<object> dataSource)
		{
			var pboard = NSPasteboard.GeneralPasteboard;
			pboard.ClearContents ();
			owner.DataSource = dataSource;
			pboard.AddTypes (new[] { type.ToUTI () }, owner);
		}
Beispiel #7
0
		public override void SetData (TransferDataType type, Func<object> dataSource)
		{
			if (type == null)
				throw new ArgumentNullException ("type");
			if (dataSource == null)
				throw new ArgumentNullException ("dataSource");
			if (type == TransferDataType.Html) {
				WindowsClipboard.SetData (type.ToWpfDataFormat (), GenerateCFHtml (dataSource ().ToString ()));
			} else if (type == TransferDataType.Image) {
				var img = dataSource() as Xwt.Drawing.Image;
				if (img != null)
				{
					var src = img.ToBitmap().GetBackend() as WpfImage;
					WindowsClipboard.SetData (type.ToWpfDataFormat (), src.MainFrame);
				}
>>>>>>> f981e414c3bfee29f5dc508cd099be9b67e0bc9e
			} else {
				if(type == TransferDataType.Uri) {
					currentDataObject.SetFileDropList((StringCollection)(dataSource()));
				} else {
					currentDataObject.SetData(type.ToWpfDataFormat(), dataSource());
				}
			}
			WindowsClipboard.SetDataObject(currentDataObject);

		}
Beispiel #8
0
 private ResoucesInfo(TransferDataType resoucesType, TransferPolicy policy, long postion, long length) : base(policy.MillisecondsTimeout)
 {
     this.Rid          = GUIDEx.GetGUIDHashCode();
     this.ResoucesType = resoucesType;
     this.Policy       = policy;
     this.Postion      = postion;
     this.Length       = length;
 }
Beispiel #9
0
 public DataRequest(Gtk.Clipboard clipboard, AsyncCallback callback, object state, TransferDataType type, Gdk.Atom[] atoms)
 {
     this.callback  = callback;
     this.type      = type;
     AsyncState     = state;
     this.atoms     = atoms;
     this.clipboard = clipboard;
     RequestData();
 }
Beispiel #10
0
        public override object GetData(TransferDataType type)
        {
            if (type == null)
                throw new ArgumentNullException ("type");

            while (!IsTypeAvailable (type))
                Thread.Sleep (1);

            return WindowsClipboard.GetData (type.ToWpfDataFormat ());
        }
Beispiel #11
0
        public override IAsyncResult BeginGetData(TransferDataType type, AsyncCallback callback, object state)
        {
            if (type == null)
                throw new ArgumentNullException ("type");
            if (callback == null)
                throw new ArgumentNullException ("callback");

            return Task<object>.Factory.StartNew (s => GetData (type), state)
                .ContinueWith (t => callback (t));
        }
Beispiel #12
0
		public override void SetData (TransferDataType type, Func<object> dataSource)
		{
			clipboard.SetWithData ((Gtk.TargetEntry[])Util.BuildTargetTable (new TransferDataType[] { type }), 
			  delegate (Gtk.Clipboard cb, Gtk.SelectionData data, uint id) {
				TransferDataType ttype = Util.AtomToType (data.Target.Name);
				if (ttype == type)
					Util.SetSelectionData (data, data.Target.Name, dataSource ());
			},
			delegate {
			});
		}
Beispiel #13
0
		public override void SetData (TransferDataType type, Func<object> dataSource, bool cleanClipboardFirst = true)
		{
			var pboard = NSPasteboard.GeneralPasteboard;
			if(cleanClipboardFirst) {
				pboard.ClearContents();
			}
			var owner = new PasteboardOwner();
			owner.DataSource = dataSource;

			pboard.AddTypes (new[] { type.ToUTI () }, owner);
		}
Beispiel #14
0
 public override IEnumerable <TransferDataType> GetTypesAvailable()
 {
     Gdk.Atom [] result = null;
     ClipboardTargetsReceivedFuncWrapper.RequestTargets(clipboard, (clipboard, atoms, n_atoms) => {
         result = atoms;
     });
     clipboard.WaitIsTargetAvailable(null);
     foreach (var a in result)
     {
         yield return(TransferDataType.FromId(a.Name));
     }
 }
Beispiel #15
0
		public override void SetData (TransferDataType type, Func<object> dataSource)
		{
			if (type == null)
				throw new ArgumentNullException ("type");
			if (dataSource == null)
				throw new ArgumentNullException ("dataSource");
			if (type == TransferDataType.Html) {
				WindowsClipboard.SetData (type.ToWpfDataFormat (), GenerateCFHtml (dataSource ().ToString ()));
			} else {
				WindowsClipboard.SetData (type.ToWpfDataFormat (), dataSource ());
			}
		}
Beispiel #16
0
		public override bool IsTypeAvailable (TransferDataType type)
		{
			if (type == TransferDataType.Text)
				return clipboard.WaitIsTextAvailable ();
			if (type == TransferDataType.Image)
				return clipboard.WaitIsImageAvailable ();
			
			foreach (var at in GetAtomsForType (type)) {
				if (clipboard.WaitIsTargetAvailable (at))
					return true;
			}
			return false;
		}
Beispiel #17
0
 public void SetData(TransferDataType type, Func <object> dataSource)
 {
     clipboard.SetWithData((Gtk.TargetEntry[])Util.BuildTargetTable(new TransferDataType[] { type }),
                           delegate(Gtk.Clipboard cb, Gtk.SelectionData data, uint id) {
         TransferDataType ttype = Util.AtomToType(data.Target.Name);
         if (ttype == type)
         {
             Util.SetSelectionData(data, data.Target.Name, dataSource());
         }
     },
                           delegate {
     });
 }
        /// <summary>
        /// Gets the value identified by a specific transfer data type.
        /// </summary>
        /// <returns>The transferred value, or <c>null</c> if the store contains no value with the specific type.</returns>
        /// <param name="type">The specific transfer data type.</param>
        object GetValue(TransferDataType type)
        {
            object val;

            if (data.TryGetValue(type, out val))
            {
                if (val != null)
                {
                    return(val);
                }
            }
            return(null);
        }
Beispiel #19
0
        public object GetValue(TransferDataType type)
        {
            var swftype = type.ToSwf();
            var value   = Data.GetData(swftype);

            if (swftype == "HTML Format")
            {
                // hack to correct decoding error in Data.GetData
                var bytes = Encoding.GetEncoding("Windows-1252").GetBytes((string)value);
                value = Encoding.UTF8.GetString(bytes);
            }
            return(value);
        }
Beispiel #20
0
        public override object GetData(TransferDataType type)
        {
            if (type == null)
                throw new ArgumentNullException ("type");

            if (!IsTypeAvailable (type))
                return null;

            var data = WindowsClipboard.GetData (type.ToWpfDataFormat ());

            if (type == TransferDataType.Image)
                return ApplicationContext.Toolkit.WrapImage(ImageHandler.LoadFromImageSource((System.Windows.Media.ImageSource)data));
            return data;
        }
Beispiel #21
0
        public override object GetData(TransferDataType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!IsTypeAvailable(type))
            {
                return(null);
            }

            return(WindowsClipboard.GetData(type.ToSwf()));
        }
Beispiel #22
0
		public override void SetData(TransferDataType type, Func<object> dataSource, bool cleanClipboardFirst = true) {
			if(type == null)
				throw new ArgumentNullException("type");
			if(dataSource == null)
				throw new ArgumentNullException("dataSource");

			if(cleanClipboardFirst) {
				WindowsClipboard.Clear();
				currentDataObject = new DataObject();
			}

			if(type == TransferDataType.Html) {
				currentDataObject.SetData(type.ToWpfDataFormat(), GenerateCFHtml(dataSource().ToString()));
=======
Beispiel #23
0
		public override object GetData (TransferDataType type)
		{
			if (type == TransferDataType.Text)
				return clipboard.WaitForText ();
			if (type == TransferDataType.Text)
				return clipboard.WaitForImage ();
			
			TransferDataStore store = new TransferDataStore ();
			
			foreach (var at in GetAtomsForType (type)) {
				var data = clipboard.WaitForContents (at);
				Util.GetSelectionData (ApplicationContext, data, store);
			}
			return ((ITransferData)store).GetValue (type);
		}
Beispiel #24
0
        public override IEnumerable <TransferDataType> GetTypesAvailable()
        {
            var dataObject = WindowsClipboard.GetDataObject();

            if (dataObject == null)
            {
                yield break;
            }

            var formats = dataObject.GetFormats(false);

            foreach (var f in formats)
            {
                yield return(TransferDataType.FromId(f));
            }
        }
Beispiel #25
0
        public void SetData(TransferDataType type, Func <object> dataSource)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }

            if (type == TransferDataType.Image)
            {
                BitmapSource bmp = dataSource() as BitmapSource;
                if (bmp == null)
                {
                    throw new ArgumentException("data is not the incorrect type", "data");
                }

                WindowsClipboard.SetImage(bmp);
                return;
            }

            if (type == TransferDataType.Text)
            {
                string text = dataSource() as string;
                if (text == null)
                {
                    throw new ArgumentException("data is not the correct type", "data");
                }

                WindowsClipboard.SetText(text);
                return;
            }

            if (type == TransferDataType.Text)
            {
                string text = dataSource() as string;
                if (text == null)
                {
                    throw new ArgumentException("data is not the correct type", "data");
                }

                WindowsClipboard.SetText(text, TextDataFormat.Rtf);
                return;
            }
        }
Beispiel #26
0
        internal static TransferDataType[] GetDragTypes(Gdk.Atom[] dropTypes)
        {
            List <TransferDataType> types = new List <TransferDataType> ();

            foreach (var dt in dropTypes)
            {
                TransferDataType type;
                if (atomToType.TryGetValue(dt.Name, out type))
                {
                    types.Add(type);
                }
                else
                {
                    types.Add(TransferDataType.FromId(dt.Name));
                }
            }
            return(types.ToArray());
        }
Beispiel #27
0
 public override void SetData(TransferDataType type, Func <object> dataSource)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (dataSource == null)
     {
         throw new ArgumentNullException("dataSource");
     }
     if (type == TransferDataType.Html)
     {
         WindowsClipboard.SetData(type.ToWpfDataFormat(), GenerateCFHtml(dataSource().ToString()));
     }
     else
     {
         WindowsClipboard.SetData(type.ToWpfDataFormat(), dataSource());
     }
 }
Beispiel #28
0
        public object GetData(TransferDataType type)
        {
            if (type == null)
                throw new ArgumentNullException ("type");

            while (!IsTypeAvailable (type))
                Thread.Sleep (1);

            if (type == TransferDataType.Image)
                return WindowsClipboard.GetImage ();
            if (type == TransferDataType.Rtf)
                return WindowsClipboard.GetText (TextDataFormat.Rtf);
            if (type == TransferDataType.Text) {
                if (WindowsClipboard.ContainsText (TextDataFormat.UnicodeText))
                    return WindowsClipboard.GetText();

                return WindowsClipboard.GetText (TextDataFormat.Text);
            }

            throw new NotImplementedException();
        }
Beispiel #29
0
		public override object GetData (TransferDataType type)
		{
			if (type == TransferDataType.Uri)
				return (Uri)NSUrl.FromPasteboard (NSPasteboard.GeneralPasteboard);

			var data = NSPasteboard.GeneralPasteboard.GetDataForType (type.ToUTI ());
			if (data == null)
				return null;

			if (type == TransferDataType.Text)
				return data.ToString ();
			if (type == TransferDataType.Image)
				return new NSImage (data);

			unsafe {
				var bytes = new byte [data.Length];
				using (var stream = new UnmanagedMemoryStream ((byte*)data.Bytes, bytes.Length))
					stream.Read (bytes, 0, bytes.Length);
				return TransferDataSource.DeserializeValue (bytes);
			}
		}
Beispiel #30
0
        public void SetDragSource(TransferDataType [] types, DragDropAction dragAction)
        {
            if (DragDropInfo.AutodetectDrag)
                return; // Drag auto detect has been already activated.

            DragDropInfo.AutodetectDrag = true;
            Widget.MouseUp += WidgetMouseUpForDragHandler;
            Widget.MouseMove += WidgetMouseMoveForDragHandler;
        }
Beispiel #31
0
 public override IAsyncResult BeginGetData(TransferDataType type, AsyncCallback callback, object state)
 {
     throw new NotImplementedException ();
 }
Beispiel #32
0
 public override bool IsTypeAvailable(TransferDataType type)
 {
     return NSPasteboard.GeneralPasteboard.Types.Contains (type.ToUTI ());
 }
Beispiel #33
0
		public abstract IAsyncResult BeginGetData (TransferDataType type, AsyncCallback callback, object state);
Beispiel #34
0
		public abstract object GetData (TransferDataType type);
Beispiel #35
0
		public abstract bool IsTypeAvailable (TransferDataType type);
Beispiel #36
0
		public override IAsyncResult BeginGetData (TransferDataType type, AsyncCallback callback, object state)
		{
			var atts = GetAtomsForType (type).ToArray ();
			return new DataRequest (ApplicationContext, clipboard, callback, state, type, atts);
		}
Beispiel #37
0
        static Gtk.TargetEntry[] CreateTargetEntries(TransferDataType type)
        {
            lock (dragTargets) {
                Gtk.TargetEntry[] entries;
                if (dragTargets.TryGetValue (type, out entries))
                    return entries;

                uint id = targetIdCounter++;

                if (type == TransferDataType.Uri) {
                    Gtk.TargetList list = new Gtk.TargetList ();
                    list.AddUriTargets (id);
                    entries = (Gtk.TargetEntry[])list;
                }
                else if (type == TransferDataType.Text) {
                    Gtk.TargetList list = new Gtk.TargetList ();
                    list.AddTextTargets (id);
                    //HACK: work around gtk_selection_data_set_text causing crashes on Mac w/ QuickSilver, Clipbard History etc.
                    if (Platform.IsMac) {
                        list.Remove ("COMPOUND_TEXT");
                        list.Remove ("TEXT");
                        list.Remove ("STRING");
                    }
                    entries = (Gtk.TargetEntry[])list;
                }
                else if (type == TransferDataType.Rtf) {
                    Gdk.Atom atom;
                    if (Platform.IsMac)
                        atom = Gdk.Atom.Intern ("NSRTFPboardType", false); //TODO: use public.rtf when dep on MacOS 10.6
                    else
                        atom = Gdk.Atom.Intern ("text/rtf", false);
                    entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (atom, 0, id) };
                }
                else {
                    entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (Gdk.Atom.Intern ("application/" + type.Id, false), 0, id) };
                }

                foreach (var a in entries.Select (e => e.Target))
                    atomToType [a] = type;
                return dragTargets [type] = entries;
            }
        }
Beispiel #38
0
		public override bool IsTypeAvailable (TransferDataType type)
		{
			return NSPasteboard.GeneralPasteboard.CanReadItemWithDataConformingToTypes (new[] { type.ToUTI () });
		}
Beispiel #39
0
		public DataRequest (ApplicationContext context, Gtk.Clipboard clipboard, AsyncCallback callback, object state, TransferDataType type, Gdk.Atom[] atoms)
		{
			this.context = context;
			this.callback = callback;
			this.type = type;
			AsyncState = state;
			this.atoms = atoms;
			this.clipboard = clipboard;
			RequestData ();
		}
Beispiel #40
0
 public void SetDragTarget(TransferDataType [] types, DragDropAction dragAction)
 {
     throw new NotImplementedException ();
 }
Beispiel #41
0
 public void SetDragTarget(TransferDataType [] types, DragDropAction dragAction)
 {
     DragDropInfo.TargetTypes = types == null ? new TransferDataType [0] : types;
     Widget.AllowDrop = true;
 }
Beispiel #42
0
		public abstract void SetData (TransferDataType type, Func<object> dataSource, bool cleanClipboardFirst = true);
Beispiel #43
0
        static void FillDataStore(TransferDataStore store, IDataObject data, TransferDataType [] types)
        {
            foreach (var type in types) {
                string format = type.ToWpfDataFormat ();
                if (!data.GetDataPresent (format)) {
                    // This is a workaround to support type names which don't include the assembly name.
                    // It eases integration with Windows DND.
                    format = NormalizeTypeName (format);
                    if (!data.GetDataPresent (format))
                        continue;
                }

                var value = data.GetData (format);
                if (type == TransferDataType.Text)
                    store.AddText ((string)value);
                else if (type == TransferDataType.Uri) {
                    var uris = ((string [])value).Select (f => new Uri (f)).ToArray ();
                    store.AddUris (uris);
                } else if (value is byte[])
                    store.AddValue (type, (byte[]) value);
                else
                    store.AddValue (type, value);
            }
        }
Beispiel #44
0
		IEnumerable<Gdk.Atom> GetAtomsForType (TransferDataType type)
		{
			foreach (Gtk.TargetEntry te in (Gtk.TargetEntry[])Util.BuildTargetTable (new TransferDataType[] { type }))
				yield return Gdk.Atom.Intern (te.Target, false);
		}