[Gtk-sharp-list] Howto use WaitForTargets

einKI.ml einKI.ml at gmx.net
Sat Jul 1 13:28:37 EDT 2006


Hi


> I tried to get all targets the clipboard currently supports through the
> WaitForTargets Method.
> 
> public bool WaitForTargets (Gdk.Atom targets, out int n_targets)
> 
> I am sursprised why it only takes a Gdk.Atom as parameter instead of a
> Gdk.Atom[] like the function form the C-API (GdkAtom**).
I now used PInvoke to get my own method. But I would still be interested
if anyone can tell me how to use the Gtk# Method.

If somebody want to use my method the code is here
It is not tested but should work on Windows and AMD64 too.

class ClipboardUtil
{
	public static string[] GetTargets(Gtk.Clipboard cp)
	{
		int count;
		IntPtr ptr;
		string[] ret;
		
		gtk_clipboard_wait_for_targets(cp.Handle,out ptr,out count);
		if(count <=0)  return new string[0];
		ret = new string[count];
		
		unsafe {
			byte* p = (byte*)ptr.ToPointer();
			int i=0;
			
			while(count-- > 0)
			{
				ret[i] = gdk_atom_name(new IntPtr(*p));
				p+=IntPtr.Size;
				i++;
			}
		}
		
		return ret;
	}
	
	#region PInvoke
		#if WIN32
			[DllImport("libgtk-win32-2.0.so")]
			extern static bool gtk_clipboard_wait_for_targets(IntPtr cp,out
IntPtr atoms,out int numbers);
	
			[DllImport("libgdk-win32-2.0.so")]
			extern static string gdk_atom_name (int ptr);
		#else
			[DllImport("libgtk-x11-2.0.so")]
			extern static bool gtk_clipboard_wait_for_targets(IntPtr cp,out
IntPtr atoms,out int numbers);
	
			[DllImport("libgdk-x11-2.0.so")]
			extern static string gdk_atom_name (IntPtr ptr);
		#endif
	#endregion
}



More information about the Gtk-sharp-list mailing list