# Drag and drop across instances of an application

**URL:** <https://www.ruby-forum.com/t/drag-and-drop-across-instances-of-an-application/93101>\
**Category:** Ruby-Gnome 2\
**Created:** [April 27, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/drag-and-drop-across-instances-of-an-application/93101 "2007-04-27T15:47:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [April 27, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/drag-and-drop-across-instances-of-an-application/93101/1 "2007-04-27T15:47:20Z")

</div>

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:🪟: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](http://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/](http://sourceforge.net/powerbar/db2/)
