Drag and drop across instances of an application


#1

Hi,

I have an app (below) which has two windows, each window is an instance
of
the same class. These are set for drag and drop between them
and everything works fine.

But I want to run 2 instances of the application and drag between
the two applications, and it doesn’t work. The drag isn’t accepted.
I replace the Gtk::Drag::TARGET_SAME_APP value with 0, but it has
no effect.

Is is possible to acheive this? If so, what am I missing?

Also (I’ve just noticed) “got a drop!” is printed twice for each drop?
Could
someone please tell me why? Again, I probably missed something out.

I am running ruby 1.8.5, gtk 2.8.18 , ruby-gnome2.0 14 1 (getting old,
but I
had a few problems when trying to upgrade), all on windows xp pro.

Thanks very much,
Martin.

require ‘gtk2’

class WidgetTestView < Gtk::EventBox

def initialize( data_list )
super()

list_box = Gtk::VBox.new( false )

self.add(list_box)

data_list.each{|di| list_box.pack_start( Gtk::Label.new( di ) ) }

Gtk::Drag.source_set(self,
                     Gdk::Window::BUTTON1_MASK | 

Gdk::Window::BUTTON2_MASK,
[ [‘WidgetSelection’,
0, #Gtk::Drag::TARGET_SAME_APP,
1] ,
],

                     Gdk::DragContext::ACTION_COPY | 

Gdk::DragContext::ACTION_MOVE)

Gtk::Drag.dest_set( self,
                    Gtk::Drag::DEST_DEFAULT_ALL ,
                    [ ['WidgetSelection',
                       0, #Gtk::Drag::TARGET_SAME_APP,
                       1 ],
                    ],
                    Gdk::DragContext::ACTION_COPY|Gdk::DragContext::ACTION_MOVE)

self.signal_connect("drag_data_get") do |widget, context, 

selection_data, info, time|
selection_data.set(Gdk::Selection::TYPE_STRING, “hello” )
end

self.signal_connect("drag-data-received") do |w, dc, x, y, 

selectiondata, info, time|
if selectiondata.type == Gdk::Selection::TYPE_STRING
puts “got a drop!”
Gtk::Drag.finish(dc, true, true, 0) # tell someone the dnd is
finished.
end
end
self.signal_connect(“drag-drop”) do |w, dc, x, y, time|
Gtk::Drag.get_data(w, dc, dc.targets[0], time)
end
end
end

Gtk.init
2.times{
data_items = %w{ one two three four five }
list_view = WidgetTestView.new( data_items )
win = Gtk::Window.new
win.add( list_view )
win.show_all
win.signal_connect(“destroy”){ Gtk.main_quit }
}
Gtk.main


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/