[Gtk-sharp-list] Drag and Drop simple example.

Daniel Kornhauser dkor@media.mit.edu
Thu, 30 Oct 2003 01:24:37 -0500


--=-EFpzibDZCfDCLX/tnvjJ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I'm trying to make an simple Drag and Drop example in order to test my
patch for bug 49857 . But I can't make a dnd example work. 

I attempted to port from gtkmm2 to gtk# the following link :

http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch15s05.html

If somebody could help me get this going I would be very grateful.

				Daniel.

--=-EFpzibDZCfDCLX/tnvjJ
Content-Disposition: attachment; filename=dnd.cs
Content-Type: text/plain; name=dnd.cs; charset=
Content-Transfer-Encoding: 7bit

//
// dnd.cs, port of dndwindwo.cc from gtk-mm tutorial
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.


/* Dran And Drop
 *
 * 
 */


using System;

using Gtk;
using Gdk;
using GtkSharp;

namespace GtkDemo 
{
	public class DragAndDropExample	
	{
		
	static int Main (string [] args){
		
		Application.Init ();	
		
		// Create a Window
		Gtk.Window window = new Gtk.Window ("DnD Example");
		window.DeleteEvent += new DeleteEventHandler (WindowDelete);
		window.BorderWidth = 10;
		
		// Add Vertical Box
		HBox hbox = new HBox (false,0);
		window.Add (hbox);
		
		// Add Button and Lable
		Button button = new Button ("Drag Here");
		Label label = new Label("Drop Here");

		// Targets
		TargetEntry te = new TargetEntry ();
		te.flags = (int)TargetFlags.Widget;
		te.target = "STRING"; 
		te.target = "text/plain";
		
		//Drag site://
		
		//Make m_Button_Drag a DnD drag source:
		Gtk.Drag.SourceSet (button, Gdk.ModifierType.Button1Mask, te, 1, Gdk.DragAction.Copy);
		hbox.PackStart(button);
		
		//Connect signals
		button.DragDataGet += new DragDataGetHandler (OnButtonDragGet);
		
		//Drop site://
		
		//Make m_Label_Drop a DnD drop destination:
		Gtk.Drag.DestSetTargetList (label, TargetList.New (te, 1));
		
		//Connect signals:
		label.DragDataReceived += new DragDataReceivedHandler (OnLabelDropDragDataRecieved);
		
		hbox.PackStart(label);
		
		window.ShowAll();
		/* Enter the event loop */
		Application.Run ();

		return 0;

		}
		
		static void OnButtonDragGet (object o,  DragDataGetArgs  args)
		{
			Console.WriteLine(args.Context);
			Console.WriteLine(args.Info);
			Console.WriteLine(args.SelectionData);		
			Console.WriteLine(args.Time);		
		}

		static void OnLabelDropDragDataRecieved (object o, DragDataReceivedArgs args)
		{
			Console.WriteLine(args.Context);
			Console.WriteLine(args.Info);
			Console.WriteLine(args.SelectionData);
			Console.WriteLine(args.X);
			Console.WriteLine(args.Y);
		}
	        static void WindowDelete (object o, DeleteEventArgs args)
		{
			Application.Quit ();
			args.RetVal = true;
		}


	}

}

--=-EFpzibDZCfDCLX/tnvjJ--