GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Oct 26, 2014 3:00 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: drag n' drop
PostPosted: Tue Mar 10, 2009 5:41 pm 
Offline
GTK+ Guru

Joined: Thu Aug 07, 2008 12:23 am
Posts: 103
Location: NYC
I would like to use a textarea as a generic drag n' drop destination, so that (for example) the user could drag n' drop a text file from nautilus into the text area to load the file.

I've started looking through various parts of the API and a few tutorials, but I thought I'd ask and see if some nice person has done this before and might provide me with a better starting place -- after all, in the end it probably won't be more than a couple dozen lines of code, but the available information is (as par the course) so badly assembled that it will take me days to sort out...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 5:54 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

While I was learning about Gtk, I stumbled upon this article:
http://live.gnome.org/GnomeLove/DragNDropTutorial

And I must say this article is perfect tutorial - explanation and sample code are just perfect.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 7:21 pm 
Offline
GTK+ Guru

Joined: Thu Aug 07, 2008 12:23 am
Posts: 103
Location: NYC
I can almost hear myself whining in that post ;)

The tutorial you refer to is fine, it's a basic explanation with a decent piece of actual code.

What I was hoping for: some more information pertaining to recieving a drop from an application I didn't write, without having to go thru the nautilus source or something. After all, at least w/r/t linux, I would hope this would be fairly standardized. I can get the textarea to detect a drag into from outside, but "the drop" is just not happening, and it now appears I will just have to take take shots in the dark at how to do the communication, because there appears to be no way to just accept anything from the source so I can decipher whatever protocols, et. al. are in use amongst the GNOME apps. I had assumed:
Code:
GtkTargetEntry dropsite={"text/plain",GTK_TARGET_OTHER_APP,0};

would be general enough, but apparently not.

Should I just start plugging in mime types? Technically that string could be anything...I can't even start guessing here.

There must (or at least, really really should be) a source of information about what target info GNOME expects. I can presume all I want, which seems counter-productive and somewhat contrary to the spirit of "open source" (although I guess I'm free to go thru the open source).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 9:02 pm 
Offline
GTK+ Guru

Joined: Thu Aug 07, 2008 12:23 am
Posts: 103
Location: NYC
Well, it's starting to work out. :D

My initial problem was because the whole drag n' drop mechanism gets short circuited if the textarea is set "none editable" (I suppose the intention is limit the user's intentions and not the programmer's, but oh well), and I can see no way around that...

So I have to use the window itself, which is not what I would prefer. Slightly silly system.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 3:11 pm 
Offline
GTK+ Guru

Joined: Thu Aug 07, 2008 12:23 am
Posts: 103
Location: NYC
The easy way out was to use "motion" and "leave" signals to turn editable on and off.

The other weird thing about this is that the strings from GNOME apps (stock lenny install) have a "\r" (ASCII 13) at the end of them...arrghh, hard to notice. (my other linux drive has no GNOME and gtk+ built from source, and uses no "\r").

Anyway, since there is not too much on site about this, I will write a simple DnD demo soon building on that tutorial, w/r/t cross application drag and drop in X windows...

Hey it's done:
http://www.gtkforums.com/viewtopic.php?p=8364#8364


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group