* sample/TestDnd.cs: New.

* gtk/TargetEntry.custom: New.

* glue/dragcontext.c: New.

* glib/Object.cs: New public property TypeName in class Object.

* gdk/DragContext.custom: New.

svn path=/trunk/gtk-sharp/; revision=20754
This commit is contained in:
Ettore Perazzoli 2003-12-03 20:23:25 +00:00
parent cff58b1cb2
commit 7a10147c5c
8 changed files with 774 additions and 4 deletions

View File

@ -1,3 +1,15 @@
2003-12-03 Ettore Perazzoli <ettore@ximian.com>
* sample/TestDnd.cs: New.
* gtk/TargetEntry.custom: New.
* glue/dragcontext.c: New.
* glib/Object.cs: New public property TypeName in class Object.
* gdk/DragContext.custom: New.
2003-11-30 Mike Kestner <mkestner@speakeasy.net>
* art/art-symbols.xml : add some simple types to clean up generation.

104
gdk/DragContext.custom Normal file
View File

@ -0,0 +1,104 @@
//
// gdk/DragContext.custom
//
// Author: Ettore Perazzoli <ettore@ximian.com>
//
// Copyright (C) 2003 Novell, Inc.
[DllImport("gtksharpglue")]
static extern DragProtocol gtksharp_drag_context_get_protocol (IntPtr ptr);
public unsafe DragProtocol DragProtocol {
get {
return gtksharp_drag_context_get_protocol (this.Handle);
}
}
[DllImport("gtksharpglue")]
static extern bool gtksharp_drag_context_get_is_source (IntPtr ptr);
public bool IsSource {
get {
return gtksharp_drag_context_get_is_source (this.Handle);
}
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_drag_context_get_source_window (IntPtr ptr);
public Gdk.Window SourceWindow {
get {
return GLib.Object.GetObject (gtksharp_drag_context_get_source_window (this.Handle), false) as Gdk.Window;
}
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_drag_context_get_dest_window (IntPtr ptr);
public Gdk.Window DestWindow {
get {
return GLib.Object.GetObject (gtksharp_drag_context_get_dest_window (this.Handle), false) as Gdk.Window;
}
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_drag_context_get_targets (IntPtr ptr);
public Atom [] Targets {
get {
GLib.List list = new GLib.List (gtksharp_drag_context_get_targets (this.Handle), typeof (Atom));
Atom [] entries = new Atom [list.Count];
int i = 0;
foreach (Atom a in list)
entries [i ++] = a;
return entries;
}
}
[DllImport("gtksharpglue")]
static extern DragAction gtksharp_drag_context_get_actions (IntPtr ptr);
public DragAction Actions {
get {
return gtksharp_drag_context_get_actions (this.Handle);
}
}
[DllImport("gtksharpglue")]
static extern DragAction gtksharp_drag_context_get_suggested_action (IntPtr ptr);
public DragAction SuggestedAction {
get {
return gtksharp_drag_context_get_suggested_action (this.Handle);
}
}
[DllImport("gtksharpglue")]
static extern DragAction gtksharp_drag_context_get_action (IntPtr ptr);
public DragAction Action {
get {
return gtksharp_drag_context_get_action (this.Handle);
}
}
[DllImport("gtksharpglue")]
static extern uint gtksharp_drag_context_get_start_time (IntPtr ptr);
public uint StartTime {
get {
return gtksharp_drag_context_get_start_time (this.Handle);
}
}

View File

@ -66,7 +66,7 @@ namespace GLib {
foreach (Object o in objects){
if (o._obj == IntPtr.Zero)
continue;
g_object_unref (o._obj);
o._obj = IntPtr.Zero;
}
@ -246,6 +246,15 @@ namespace GLib {
}
}
[DllImport("gtksharpglue")]
static extern IntPtr gtksharp_get_type_name (IntPtr raw);
public string TypeName {
get {
return Marshal.PtrToStringAnsi (gtksharp_get_type_name (Raw));
}
}
/// <summary>
/// GetGType Method
/// </summary>

View File

@ -7,6 +7,7 @@ BASESOURCES = \
colorseldialog.c \
combo.c \
dialog.c \
dragcontext.c \
error.c \
event.c \
fileselection.c \

86
glue/dragcontext.c Normal file
View File

@ -0,0 +1,86 @@
/* dragcontext.c: Glue for accessing fields in a GdkDragContext.
*
* Author: Ettore Perazzoli <ettore@ximian.com>
*
* (C) 2003 Novell, Inc.
*/
#include <gdk/gdkdnd.h>
GdkDragProtocol gtksharp_drag_context_get_protocol (GdkDragContext *context);
GdkDragProtocol
gtksharp_drag_context_get_protocol (GdkDragContext *context)
{
return context->protocol;
}
gboolean gtksharp_drag_context_get_is_source (GdkDragContext *context);
gboolean
gtksharp_drag_context_get_is_source (GdkDragContext *context)
{
return context->is_source;
}
GdkWindow *
gtksharp_drag_context_get_source_window (GdkDragContext *context)
{
return context->source_window;
}
GdkWindow *gtksharp_drag_context_get_dest_window (GdkDragContext *context);
GdkWindow *
gtksharp_drag_context_get_dest_window (GdkDragContext *context)
{
return context->dest_window;
}
GList *gtksharp_drag_context_get_targets (GdkDragContext *context);
GList *
gtksharp_drag_context_get_targets (GdkDragContext *context)
{
return context->targets;
}
GdkDragAction gtksharp_drag_context_get_actions (GdkDragContext *context);
GdkDragAction
gtksharp_drag_context_get_actions (GdkDragContext *context)
{
return context->actions;
}
GdkDragAction gtksharp_drag_context_get_suggested_action (GdkDragContext *context);
GdkDragAction
gtksharp_drag_context_get_suggested_action (GdkDragContext *context)
{
return context->suggested_action;
}
GdkDragAction gtksharp_drag_context_get_action (GdkDragContext *context);
GdkDragAction
gtksharp_drag_context_get_action (GdkDragContext *context)
{
return context->action;
}
guint32 gtksharp_drag_context_get_start_time (GdkDragContext *context);
guint32
gtksharp_drag_context_get_start_time (GdkDragContext *context)
{
return context->start_time;
}

15
gtk/TargetEntry.custom Normal file
View File

@ -0,0 +1,15 @@
// Gtk.Window.custom - Gtk Window class customizations
//
// Author: Ettore Perazzoli <ettore@ximian.com>
//
// (c) 2003 Novell, Inc.
//
// This code is inserted after the automatically generated code.
public TargetEntry (string target, Gtk.TargetFlags flags, uint info)
{
this.target = target;
this.flags = flags;
this.info = info;
}

View File

@ -18,7 +18,7 @@ windows:
$(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /r:../gdk/gdk-sharp.dll HelloWorld.cs
$(CSC) /unsafe /out:button.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll ButtonApp.cs
linux: gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe $(GNOME_TARGETS) $(GLADE_TARGETS)
linux: gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe $(GNOME_TARGETS) $(GLADE_TARGETS)
@ENABLE_GNOME_TRUE@ $(MAKE) -C gconf
@ENABLE_GNOME_TRUE@ $(MAKE) -C rsvg
@ -33,7 +33,7 @@ canvas-example.exe: CanvasExample.cs
fifteen.exe: Fifteen.cs
$(MCS) --unsafe -o fifteen.exe $(local_paths) $(all_assemblies) Fifteen.cs
print.exe: PrintSample.cs
$(MCS) --unsafe -o print.exe $(local_paths) $(all_assemblies) PrintSample.cs
@ -67,6 +67,9 @@ glade-viewer.exe: GladeViewer.cs
glade-test.exe: GladeTest.cs test.glade
$(MCS) --unsafe -resource:test.glade -o glade-test.exe $(local_paths) $(all_assemblies) GladeTest.cs
testdnd.exe: TestDnd.cs
$(MCS) -g --unsafe -o testdnd.exe $(local_paths) $(all_assemblies) TestDnd.cs
clean:
rm -f *.exe
@ENABLE_GNOME_TRUE@ $(MAKE) -C gconf clean
@ -81,4 +84,4 @@ unix:
install: linux
@ENABLE_GNOME_TRUE@ $(MAKE) -C gconf install

540
sample/TestDnd.cs Normal file
View File

@ -0,0 +1,540 @@
using Gtk;
using Gdk;
using GtkSharp;
using GLib;
using System;
public class TestDnd {
private static readonly string [] drag_icon_xpm = new string [] {
"36 48 9 1",
" c None",
". c #020204",
"+ c #8F8F90",
"@ c #D3D3D2",
"# c #AEAEAC",
"$ c #ECECEC",
"% c #A2A2A4",
"& c #FEFEFC",
"* c #BEBEBC",
" .....................",
" ..&&&&&&&&&&&&&&&&&&&.",
" ...&&&&&&&&&&&&&&&&&&&.",
" ..&.&&&&&&&&&&&&&&&&&&&.",
" ..&&.&&&&&&&&&&&&&&&&&&&.",
" ..&&&.&&&&&&&&&&&&&&&&&&&.",
" ..&&&&.&&&&&&&&&&&&&&&&&&&.",
" ..&&&&&.&&&@&&&&&&&&&&&&&&&.",
" ..&&&&&&.*$%$+$&&&&&&&&&&&&&.",
" ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.",
" ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.",
" ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.",
" ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.",
" ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
" ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
"................&$@&&&@&&&&&&&&&&&&.",
".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.",
".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.",
".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.",
".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&@%&%$&&&&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&&+&$+&$&@&$@&&$@&&&&&&&&&&.",
".&&&&&&&&&+&&#@%#+@#@*$%&+$&&&&&&&&.",
".&&&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&.",
".&&&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&.",
".&&&&&&&&@#@@$&*@&@#@#$#*#$&&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&&&.",
".&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&&&&&.",
".&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&.",
".&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&&&&&.",
".&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&&&&&.",
".&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&.",
".&&&&&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&.",
".&&&&&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&.",
".&&&&&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&.",
".&&&&&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&.",
".&&&&&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
"...................................."
};
private static readonly string [] trashcan_closed_xpm = new string [] {
"64 80 17 1",
" c None",
". c #030304",
"+ c #5A5A5C",
"@ c #323231",
"# c #888888",
"$ c #1E1E1F",
"% c #767677",
"& c #494949",
"* c #9E9E9C",
"= c #111111",
"- c #3C3C3D",
"; c #6B6B6B",
"> c #949494",
", c #282828",
"' c #808080",
") c #545454",
"! c #AEAEAC",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ==......=$$...=== ",
" ..$------)+++++++++++++@$$... ",
" ..=@@-------&+++++++++++++++++++-.... ",
" =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$ ",
" .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&.. ",
" $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@ ",
" .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$ ",
" +------++++++++++++++++++++++++++++++;;%%%;;##*!. ",
" =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>). ",
" .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@. ",
" =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%== ",
" .&....=-+++++%;;####''''''''''##'%%%)..#. ",
" .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!. ",
" .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
" =.++++++++++++++!++++!++++!+++!++.= ",
" $..+++++++++++++++!++++++...$ ",
" $$=.............=$$ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
private static readonly string [] trashcan_open_xpm = new string [] {
"64 80 17 1",
" c None",
". c #030304",
"+ c #5A5A5C",
"@ c #323231",
"# c #888888",
"$ c #1E1E1F",
"% c #767677",
"& c #494949",
"* c #9E9E9C",
"= c #111111",
"- c #3C3C3D",
"; c #6B6B6B",
"> c #949494",
", c #282828",
"' c #808080",
") c #545454",
"! c #AEAEAC",
" ",
" ",
" ",
" ",
" ",
" ",
" .=.==.,@ ",
" ==.,@-&&&)-= ",
" .$@,&++;;;%>*- ",
" $,-+)+++%%;;'#+. ",
" =---+++++;%%%;%##@. ",
" @)++++++++;%%%%'#%$ ",
" $&++++++++++;%%;%##@= ",
" ,-++++)+++++++;;;'#%) ",
" @+++&&--&)++++;;%'#'-. ",
" ,&++-@@,,,,-)++;;;'>'+, ",
" =-++&@$@&&&&-&+;;;%##%+@ ",
" =,)+)-,@@&+++++;;;;%##%&@ ",
" @--&&,,@&)++++++;;;;'#)@ ",
" ---&)-,@)+++++++;;;%''+, ",
" $--&)+&$-+++++++;;;%%'';- ",
" .,-&+++-$&++++++;;;%''%&= ",
" $,-&)++)-@++++++;;%''%), ",
" =,@&)++++&&+++++;%'''+$@&++++++ ",
" .$@-++++++++++++;'#';,........=$@&++++ ",
" =$@@&)+++++++++++'##-.................=&++ ",
" .$$@-&)+++++++++;%#+$.....................=)+ ",
" $$,@-)+++++++++;%;@=........................,+ ",
" .$$@@-++++++++)-)@=............................ ",
" $,@---)++++&)@===............................,. ",
" $-@---&)))-$$=..............................=)!. ",
" --&-&&,,$=,==...........................=&+++!. ",
" =,=$..=$+)+++++&@$=.............=$@&+++++!++!. ",
" .)-++-+++++++++++++++++++++++++++!++!++!. ",
" .+-++-+++++++++++++++++++++++!+++!++!++!. ",
" .+-++-+++-+++++++++!+++!!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
" =.++++++++++++++!++++!++++!+++!++.= ",
" $..+++++++++++++++!++++++...$ ",
" $$==...........==$$ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
private static Pixbuf trashcan_open_pixbuf;
private static Pixbuf trashcan_closed_pixbuf;
private static bool have_drag;
enum TargetType {
String,
RootWindow
};
private static TargetEntry [] target_table = new TargetEntry [] {
new TargetEntry ("STRING", 0, (uint) TargetType.String ),
new TargetEntry ("text/plain", 0, (uint) TargetType.String),
new TargetEntry ("application/x-rootwindow-drop", 0, (uint) TargetType.RootWindow)
};
private static void HandleTargetDragLeave (object sender, DragLeaveArgs args)
{
Console.WriteLine ("leave");
have_drag = false;
// FIXME? Kinda wonky binding.
(sender as Gtk.Image).FromPixbuf = trashcan_closed_pixbuf;
}
private static void HandleTargetDragMotion (object sender, DragMotionArgs args)
{
if (! have_drag) {
have_drag = true;
// FIXME? Kinda wonky binding.
(sender as Gtk.Image).FromPixbuf = trashcan_open_pixbuf;
}
Widget source_widget = Gtk.Drag.GetSourceWidget (args.Context);
Console.WriteLine ("motion, source {0}", source_widget == null ? "null" : source_widget.TypeName);
Atom [] targets = args.Context.Targets;
foreach (Atom a in targets)
Console.WriteLine (a.Name ()); // FIXME shouldn't Name be a property?
Gdk.Drag.Status (args.Context, args.Context.SuggestedAction, args.Time);
args.RetVal = true;
}
private static void HandleTargetDragDrop (object sender, DragDropArgs args)
{
Console.WriteLine ("drop");
have_drag = false;
(sender as Gtk.Image).FromPixbuf = trashcan_closed_pixbuf;
#if BROKEN // Context.Targets is not defined in the bindings
if (Context.Targets.Length != 0) {
Drag.GetData (sender, context, Context.Targets.Data as Gdk.Atom, args.Time);
args.RetVal = true;
}
#endif
args.RetVal = false;
}
private static void HandleTargetDragDataReceived (object sender, DragDataReceivedArgs args)
{
if (args.SelectionData.length >=0 && args.SelectionData.format == 8) {
Console.WriteLine ("Received {0} in trashcan", args.SelectionData);
Gtk.Drag.Finish (args.Context, true, false, args.Time);
}
Gtk.Drag.Finish (args.Context, false, false, args.Time);
}
private static void HandleLabelDragDataReceived (object sender, DragDataReceivedArgs args)
{
if (args.SelectionData.length >=0 && args.SelectionData.format == 8) {
Console.WriteLine ("Received {0} in label", args.SelectionData);
Gtk.Drag.Finish (args.Context, true, false, args.Time);
}
Gtk.Drag.Finish (args.Context, false, false, args.Time);
}
private static void HandleSourceDragDataGet (object sender, DragDataGetArgs args)
{
if (args.Info == (uint) TargetType.RootWindow)
Console.WriteLine ("I was dropped on the rootwin");
else
args.SelectionData.Text = "I'm data!";
}
// The following is a rather elaborate example demonstrating/testing
// changing of the window heirarchy during a drag - in this case,
// via a "spring-loaded" popup window.
private static Gtk.Window popup_window = null;
private static bool popped_up = false;
private static bool in_popup = false;
private static uint popdown_timer = 0;
private static uint popup_timer = 0;
private static bool HandlePopdownCallback ()
{
popdown_timer = 0;
popup_window.Hide ();
popped_up = false;
return false;
}
private static void HandlePopupMotion (object sender, DragMotionArgs args)
{
if (! in_popup) {
in_popup = true;
if (popdown_timer != 0) {
Console.WriteLine ("removed popdown");
GLib.Source.Remove (popdown_timer);
popdown_timer = 0;
}
}
args.RetVal = true;
}
private static void HandlePopupLeave (object sender, DragLeaveArgs args)
{
if (in_popup) {
in_popup = false;
if (popdown_timer == 0) {
Console.WriteLine ("added popdown");
popdown_timer = GLib.Timeout.Add (500, new TimeoutHandler (HandlePopdownCallback));
}
}
}
private static bool HandlePopupCallback ()
{
if (! popped_up) {
if (popup_window == null) {
Button button;
Table table;
popup_window = new Gtk.Window (Gtk.WindowType.Popup);
popup_window.SetPosition (WindowPosition.Mouse);
table = new Table (3, 3, false);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
string label = String.Format ("{0},{1}", i, j);
button = Button.NewWithLabel (label);
table.Attach (button, (uint) i, (uint) i + 1, (uint) j, (uint) j + 1,
AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill,
0, 0);
Gtk.Drag.DestSet (button, DestDefaults.All,
target_table, DragAction.Copy | DragAction.Move);
button.DragMotion += new DragMotionHandler (HandlePopupMotion);
button.DragLeave += new DragLeaveHandler (HandlePopupLeave);
}
table.ShowAll ();
popup_window.Add (table);
}
popup_window.Show ();
popped_up = true;
}
popdown_timer = GLib.Timeout.Add (500, new TimeoutHandler (HandlePopdownCallback));
popup_timer = 0;
return false;
}
private static void HandlePopsiteMotion (object sender, DragMotionArgs args)
{
if (popup_timer == 0)
popup_timer = GLib.Timeout.Add (500, new TimeoutHandler (HandlePopupCallback));
args.RetVal = true;
}
private static void HandlePopsiteLeave (object sender, DragLeaveArgs args)
{
if (popup_timer != 0) {
Gtk.Timeout.Remove (popup_timer);
popup_timer = 0;
}
}
private static void HandleSourceDragDataDelete (object sender, DragDataDeleteArgs args)
{
Console.WriteLine ("Delete the data!");
}
public static void Main (string [] args)
{
Gtk.Window window;
Table table;
Label label;
Gtk.Image pixmap;
Button button;
Pixbuf drag_icon_pixbuf;
Application.Init ();
window = new Gtk.Window (Gtk.WindowType.Toplevel);
//g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
table = new Table (2, 2, false);
window.Add (table);
// FIXME should get a string[], not a string.
drag_icon_pixbuf = new Pixbuf (drag_icon_xpm);
trashcan_open_pixbuf = new Pixbuf (trashcan_open_xpm);
trashcan_closed_pixbuf = new Pixbuf (trashcan_closed_xpm);
label = new Label ("Drop Here\n");
Gtk.Drag.DestSet (label, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
label.DragDataReceived += new DragDataReceivedHandler (HandleLabelDragDataReceived);
table.Attach (label, 0, 1, 0, 1, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
label = new Label ("Popup\n");
Gtk.Drag.DestSet (label, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
table.Attach (label, 1, 2, 1, 2,
AttachOptions.Expand | AttachOptions.Fill,
AttachOptions.Expand | AttachOptions.Fill, 0, 0);
label.DragMotion += new DragMotionHandler (HandlePopsiteMotion);
label.DragLeave += new DragLeaveHandler (HandlePopsiteLeave);
pixmap = new Gtk.Image (trashcan_closed_pixbuf);
Gtk.Drag.DestSet (pixmap, 0, null, 0);
table.Attach (pixmap, 1, 2, 0, 1,
AttachOptions.Expand | AttachOptions.Fill,
AttachOptions.Expand | AttachOptions.Fill, 0, 0);
pixmap.DragLeave += new DragLeaveHandler (HandleTargetDragLeave);
pixmap.DragMotion += new DragMotionHandler (HandleTargetDragMotion);
pixmap.DragDrop += new DragDropHandler (HandleTargetDragDrop);
pixmap.DragDataReceived += new DragDataReceivedHandler (HandleTargetDragDataReceived);
button = new Button ("Drag Here\n");
Gtk.Drag.SourceSet (button, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
target_table, DragAction.Copy | DragAction.Move);
// FIXME can I pass a pixbuf here instead?
// Gtk.Drag.SourceSetIcon (button, window.Colormap, drag_icon, drag_mask);
table.Attach (button, 0, 1, 1, 2,
AttachOptions.Expand | AttachOptions.Fill,
AttachOptions.Expand | AttachOptions.Fill, 0, 0);
button.DragDataGet += new DragDataGetHandler (HandleSourceDragDataGet);
button.DragDataDelete += new DragDataDeleteHandler (HandleSourceDragDataDelete);
window.ShowAll ();
Application.Run ();
}
}