[Mono-list] Some questions about clipboards and gtk-sharp

Philip Van Hoof spamfrommailing@freax.org
09 Jun 2003 13:38:28 +0200


On Sun, 2003-06-08 at 14:00, Philip Van Hoof wrote:
> Hi there,

Okay.. that was me yesterday getting angry because stuff was not doing
what it suppose to do. So perhaps I was a little bit to harsh about the
subject. I am sorry for that ;).

I've forgot the Application.Init() which fixed most of the Gtk.Clipboard
issues. Once that worked I've managed to fix the casting issues too .. 

So yes; I got it working and yes the Gtk.Clipboard bindings do seem to
work (aldo, I still find them pretty difficult for what I needed them
for).

The cast turned out to be pretty easy .. 

In case you are interested in how I got it working .. here is the link
to the ViewCVS of the file :

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/gcm/Gcm.Net/Daemon/ClipboardManager.cs


I still don't know how I can get the correct size of a Atom
programmatically, so I just took 4 bytes for that. It also seems that
SelectionData.length is the length of SelectionData.Data in bytes (for
example if WaitForData("TARGETS") gives me 7 TARGET atoms then
SelectionData.length seems to be 28 in stead of 7 because 7 * 4 = 28. I
remember that the C Gtk+ API will give me 7 in stead of 28 (but, I can
be wrong: first check in case you are going to fix this)

So what I do ...

int sizeof_atom=4;

SelectionData targets = clipboard.WaitForContents
	(Atom.Intern ("TARGETS", false));

for(int counter = 0; counter < (targets.length); counter+=sizeof_atom)
{
	Atom a = new Atom ((IntPtr)targets.Data[counter]);

	Console.Write("Atom=" + a.Name());

	Gtk.SelectionData data = 
		this.clipboard.WaitForContents (a);
}



> The issues that I have are ..

> * targets = clipboard.WaitForContents (Atom.Intern ("TARGETS", false))
> does not work at all.

That was because I forgot Application.Init()

> clipboard is instantiated with Clipboard.Get(Atom.Clipboard("CLIPBOARD",
> false)).

> * I cannot know the size of a Gdk.Atom and I assume that the

I will just use 4 for that. I hope it's platform independant :-\

> In C#'s case I don't know if targets.length is the size of targets.Data
> or if it's the value which X passed ? (So is this converted to the
> amount of Bytes that have been received or does the C# API just copied
> the value from the Gtk+ API to the SelectionData.length ?). 

It's the amount of Bytes

> if a SelectionData.length is -1 and you want the property 
> SelectionData.Data then it will throw a very wierd exception which won't
> explain the programmer what the heck is wrong. I had to dig gtk-sharp
> sources to get a very vague idea of what "could" be wrong.


This is still a problem ! With many targets-atoms (for example the
MULTIPLE target) SelectionData.Data will throw this Exception in stead
of returning null ! It's a "public" property so IMHO it should never
throw an Exception unless something "major" has not been initialized
yet. We don't want the programmer to know that "if" the
SelectionData.type is "MULTIPLE" that she should NOT try the
SelectionData.Data or else it will throw an Exception .. thats crazy!
A.t.m. it's even more obvious in C (there, you just always check for
NULL first)!


> Ick.. I am really really not sure how much of all this will actually
> work :)


Well, it works.. hehe


> Please do not start thinking that I now hate Gtk-Sharp .. it's just that
> the GtkClipboard, GtkSelection and GtkAtom wrappings really REALLY
> dissapoint me a lot...

They still dissapoint me .. because it's not easy to get things working
thus Gtk-Sharp is missing it's point here: It SHOULD be easy else we are
doing the wrong thing with this library-binding.


> So until this GtkClipboard wrapping works .. I don't belive that any
> major desktop application will get working if it uses gtk-sharp.

Okay well.. let's say that the average Gtk+ programmer will get things
working .. but not yet the average System.Windows.Forms developer who
want's to develop something using Gtk-Sharp.

> Of course I am interested in helping with fixing the gtk-sharp
> wrappings.. So is, at this moment, somebody maintaining gtk-sharp?


idd



Again, sorry if I was to harsh ... I still love Gtk-Sharp and Mono! :-)






.. a lot (but I love my girlfriend more!!, imagine her reading that I
love a freakin programming environment more .. auwch!)

-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
work: Philip dot VanHoof at cronos dot be
http://www.freax.be, http://www.freax.eu.org