1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
6 * anjuta is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * anjuta is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "anjuta-drop-entry.h"
28 static GtkTargetEntry dnd_target_entries
[] =
42 G_DEFINE_TYPE (AnjutaDropEntry
, anjuta_drop_entry
, GTK_TYPE_ENTRY
);
45 anjuta_drop_entry_init (AnjutaDropEntry
*self
)
47 gtk_drag_dest_set (GTK_WIDGET (self
),
48 GTK_DEST_DEFAULT_MOTION
| GTK_DEST_DEFAULT_HIGHLIGHT
,
50 G_N_ELEMENTS (dnd_target_entries
), GDK_ACTION_COPY
);
54 anjuta_drop_entry_finalize (GObject
*object
)
56 AnjutaDropEntry
*self
;
58 self
= ANJUTA_DROP_ENTRY (object
);
60 G_OBJECT_CLASS (anjuta_drop_entry_parent_class
)->finalize (object
);
64 anjuta_drop_entry_drag_data_received (GtkWidget
*widget
,
65 GdkDragContext
*context
, gint x
, gint y
,
66 GtkSelectionData
*data
, guint target_type
,
75 if ((data
!= NULL
) && (data
->length
>= 0))
77 delete = (context
->action
== GDK_ACTION_MOVE
);
79 if (target_type
== DND_TYPE_STRING
)
81 gtk_entry_set_text (GTK_ENTRY (widget
), (const gchar
*) data
->data
);
86 gtk_drag_finish (context
, success
, delete, time
);
90 anjuta_drop_entry_drag_drop (GtkWidget
*widget
, GdkDragContext
*context
,
91 gint x
, gint y
, guint time
)
95 target_type
= gtk_drag_dest_find_target (widget
, context
, NULL
);
97 if (target_type
!= GDK_NONE
)
98 gtk_drag_get_data (widget
, context
, target_type
, time
);
100 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
106 anjuta_drop_entry_size_request (GtkWidget
*widget
,
107 GtkRequisition
*requisition
)
109 AnjutaDropEntry
*self
;
110 AnjutaDropEntryClass
*klass
;
111 GtkEntryClass
*parent_class
;
113 self
= ANJUTA_DROP_ENTRY (widget
);
114 klass
= ANJUTA_DROP_ENTRY_GET_CLASS (self
);
115 parent_class
= g_type_class_peek_parent (klass
);
117 GTK_WIDGET_CLASS (parent_class
)->size_request (widget
, requisition
);
119 /* Make the entry box 40 pixels tall so that it is easier to drag into. */
120 requisition
->height
= 40;
124 anjuta_drop_entry_class_init (AnjutaDropEntryClass
*klass
)
126 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
127 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS (klass
);
129 object_class
->finalize
= anjuta_drop_entry_finalize
;
130 widget_class
->drag_data_received
= anjuta_drop_entry_drag_data_received
;
131 widget_class
->drag_drop
= anjuta_drop_entry_drag_drop
;
132 widget_class
->size_request
= anjuta_drop_entry_size_request
;
137 anjuta_drop_entry_new (void)
139 return g_object_new (ANJUTA_TYPE_DROP_ENTRY
, NULL
);