[balsa/wip/gtk4: 69/351] More drag-and-drop changes
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4: 69/351] More drag-and-drop changes
- Date: Wed, 23 May 2018 21:22:44 +0000 (UTC)
commit 67883eae2b58e800b4d6e983a572ce40bb2a0a58
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Fri Nov 17 15:13:48 2017 -0500
More drag-and-drop changes
libbalsa/address.c | 41 ++++++++++++++----------
libbalsa/address.h | 3 +-
src/ab-main.c | 39 ++++++++++++----------
src/balsa-index.c | 11 +++---
src/balsa-mblist.c | 25 +++++++++-----
src/main-window.c | 40 ++++++++++++-----------
src/sendmsg-window.c | 85 ++++++++++++++++++++++++++-----------------------
7 files changed, 135 insertions(+), 109 deletions(-)
---
diff --git a/libbalsa/address.c b/libbalsa/address.c
index b85220a..8efcaaf 100644
--- a/libbalsa/address.c
+++ b/libbalsa/address.c
@@ -862,14 +862,18 @@ add_row(GtkWidget*button, gpointer data)
}
GtkTargetEntry libbalsa_address_target_list[] = {
- {"text/plain", 0, LIBBALSA_ADDRESS_TRG_STRING },
- {"x-application/x-addr", GTK_TARGET_SAME_APP,LIBBALSA_ADDRESS_TRG_ADDRESS}
+ {"text/plain", 0 },
+ {"x-application/x-addr", GTK_TARGET_SAME_APP}
};
static void
-addrlist_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
- gint x, gint y, GtkSelectionData * selection_data,
- guint target_type, guint32 time, gpointer data)
+addrlist_drag_received_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint32 time,
+ gpointer data)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
@@ -879,14 +883,17 @@ addrlist_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
printf("drag_received:\n");
/* Deal with what we are given from source */
- if(selection_data
- && gtk_selection_data_get_length(selection_data) >= 0) {
- switch (target_type) {
- case LIBBALSA_ADDRESS_TRG_ADDRESS:
- addr = *(LibBalsaAddress **)
- gtk_selection_data_get_data(selection_data);
- if(addr && addr->address_list) {
- g_print ("string: %s\n", (gchar*)addr->address_list->data);
+ if (selection_data != NULL
+ && gtk_selection_data_get_length(selection_data) >= 0) {
+ GdkAtom target;
+
+ target = gtk_selection_data_get_target(selection_data);
+
+ if (target == gdk_atom_intern("x-application/x-addr", TRUE)) {
+ addr = *(LibBalsaAddress **) gtk_selection_data_get_data(selection_data);
+
+ if (addr != NULL && addr->address_list != NULL) {
+ g_print ("string: %s\n", (gchar*) addr->address_list->data);
gtk_list_store_insert_with_values(GTK_LIST_STORE(model),
&iter, 99999,
0,
@@ -894,11 +901,11 @@ addrlist_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
-1);
dnd_success = TRUE;
}
- break;
- case LIBBALSA_ADDRESS_TRG_STRING:
+ } else if (target == gdk_atom_intern("text/plain", TRUE) ||
+ target == gdk_atom_intern("STRING", TRUE)) {
g_print("text/plain target not implemented.\n");
- break;
- default: g_print ("nothing good");
+ } else {
+ g_print ("nothing good");
}
}
diff --git a/libbalsa/address.h b/libbalsa/address.h
index 9118f32..1a9597e 100644
--- a/libbalsa/address.h
+++ b/libbalsa/address.h
@@ -118,7 +118,8 @@ void libbalsa_address_set_edit_entries(const LibBalsaAddress * address,
enum {
LIBBALSA_ADDRESS_TRG_STRING,
- LIBBALSA_ADDRESS_TRG_ADDRESS
+ LIBBALSA_ADDRESS_TRG_ADDRESS,
+ LIBBALSA_ADDRESS_TRG_NONE
};
extern GtkTargetEntry libbalsa_address_target_list[2];
diff --git a/src/ab-main.c b/src/ab-main.c
index 5f6bc1c..f968a01 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -674,36 +674,39 @@ list_row_activated_cb(GtkTreeView *tree, gpointer data)
}
static void
-addrlist_drag_get_cb(GtkWidget* widget, GdkDragContext* drag_context,
- GtkSelectionData* sel_data, guint target_type,
- guint time, gpointer user_data)
+addrlist_drag_get_cb(GtkWidget * widget,
+ GdkDragContext * drag_context,
+ GtkSelectionData * sel_data,
+ guint time,
+ gpointer user_data)
{
- GtkTreeView *addrlist;
- GtkTreeModel *model;
- GtkTreeSelection *selection;
- GtkTreeIter iter;
- LibBalsaAddress *address;
- GValue gv = {0,};
+ GdkAtom target;
- g_return_if_fail (widget != NULL);
- addrlist = GTK_TREE_VIEW(widget);
+ target = gtk_selection_data_get_target(sel_data);
- switch (target_type) {
- case LIBBALSA_ADDRESS_TRG_ADDRESS:
+ if (target == gdk_atom_intern("x-application/x-addr", TRUE)) {
+ GtkTreeView *addrlist;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GValue gv = {0,};
+ LibBalsaAddress *address;
+
+ addrlist = GTK_TREE_VIEW(widget);
selection = gtk_tree_view_get_selection(addrlist);
if(!gtk_tree_selection_get_selected(selection, &model, &iter))
return;
gtk_tree_model_get_value(model, &iter, LIST_COLUMN_ADDRESS, &gv);
address = LIBBALSA_ADDRESS(g_value_get_object(&gv));
gtk_selection_data_set(sel_data,
- gtk_selection_data_get_target(sel_data),
+ target,
8, (const guchar *) &address,
sizeof(LibBalsaAddress*));
- break;
- case LIBBALSA_ADDRESS_TRG_STRING:
+ } else if (target == gdk_atom_intern("text/plain", TRUE) ||
+ target == gdk_atom_intern("STRING", TRUE)) {
g_print("Text/plain cannot be sent.\n");
- break;
- default: g_print("Do not know what to do!\n");
+ } else {
+ g_print("Do not know what to do!\n");
}
}
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 816a3d2..7fce10d 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -106,13 +106,12 @@ enum {
};
static GtkTargetEntry index_drag_types[] = {
- {"x-application/x-message-list", GTK_TARGET_SAME_APP, TARGET_MESSAGES}
+ {"x-application/x-message-list", GTK_TARGET_SAME_APP}
};
static void bndx_drag_cb(GtkWidget* widget,
GdkDragContext* drag_context,
GtkSelectionData* data,
- guint info,
guint time,
gpointer user_data);
@@ -768,9 +767,11 @@ bndx_column_resize(GtkWidget * widget, GtkAllocation * allocation,
* Currently supports DND only within the application.
*/
static void
-bndx_drag_cb(GtkWidget * widget, GdkDragContext * drag_context,
- GtkSelectionData * data, guint info, guint time,
- gpointer user_data)
+bndx_drag_cb(GtkWidget * widget,
+ GdkDragContext * drag_context,
+ GtkSelectionData * data,
+ guint time,
+ gpointer user_data)
{
BalsaIndex *index;
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index 2922565..ba9ce07 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -76,7 +76,7 @@ enum {
static gint balsa_mblist_signals[LAST_SIGNAL] = { 0 };
static GtkTargetEntry bmbl_drop_types[] = {
- {"x-application/x-message-list", GTK_TARGET_SAME_APP, TARGET_MESSAGES}
+ {"x-application/x-message-list", GTK_TARGET_SAME_APP}
};
static GtkTreeViewClass *parent_class = NULL;
@@ -112,10 +112,13 @@ static gboolean bmbl_button_press_cb(GtkWidget * widget,
static void bmbl_column_resize(GtkWidget * widget, GtkAllocation * allocation,
gint baseline, GtkAllocation * clip,
gpointer data);
-static void bmbl_drag_cb(GtkWidget * widget, GdkDragContext * context,
- gint x, gint y,
- GtkSelectionData * selection_data, guint info,
- guint32 time, gpointer data);
+static void bmbl_drag_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint32 time,
+ gpointer data);
static void bmbl_row_activated_cb(GtkTreeView * tree_view,
GtkTreePath * path,
GtkTreeViewColumn * column,
@@ -789,9 +792,13 @@ bmbl_column_resize(GtkWidget * widget, GtkAllocation * allocation,
* to copy.
* */
static void
-bmbl_drag_cb(GtkWidget * widget, GdkDragContext * context,
- gint x, gint y, GtkSelectionData * selection_data,
- guint info, guint32 time, gpointer data)
+bmbl_drag_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint32 time,
+ gpointer data)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
@@ -803,7 +810,7 @@ bmbl_drag_cb(GtkWidget * widget, GdkDragContext * context,
BalsaIndex *orig_index;
GArray *selected;
- if (!selection_data || !gtk_selection_data_get_data(selection_data))
+ if (selection_data == NULL || gtk_selection_data_get_data(selection_data) == NULL)
/* Drag'n'drop is weird... */
return;
diff --git a/src/main-window.c b/src/main-window.c
index 6c12ba9..22ae1b4 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -81,13 +81,9 @@ enum {
LAST_SIGNAL
};
-enum {
- TARGET_MESSAGES
-};
-
#define NUM_DROP_TYPES 1
static GtkTargetEntry notebook_drop_types[NUM_DROP_TYPES] = {
- {"x-application/x-message-list", GTK_TARGET_SAME_APP, TARGET_MESSAGES}
+ {"x-application/x-message-list", GTK_TARGET_SAME_APP}
};
/* Define thread-related globals, including dialogs */
@@ -165,16 +161,19 @@ static void bw_notebook_switch_page_cb(GtkWidget * notebook,
static void bw_send_msg_window_destroy_cb(GtkWidget * widget, gpointer data);
static BalsaIndex *bw_notebook_find_page(GtkNotebook * notebook,
gint x, gint y);
-static void bw_notebook_drag_received_cb(GtkWidget* widget,
- GdkDragContext* context,
- gint x, gint y,
- GtkSelectionData* selection_data,
- guint info, guint32 time,
- gpointer data);
-static gboolean bw_notebook_drag_motion_cb(GtkWidget* widget,
- GdkDragContext* context,
- gint x, gint y, guint time,
- gpointer user_data);
+static void bw_notebook_drag_received_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint32 time,
+ gpointer data);
+static gboolean bw_notebook_drag_motion_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ guint time,
+ gpointer user_data);
static GtkWidget *bw_notebook_label_new (BalsaMailboxNode* mbnode);
@@ -4547,10 +4546,13 @@ bw_notebook_find_page (GtkNotebook* notebook, gint x, gint y)
* over, then transfers them.
**/
static void
-bw_notebook_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
- gint x, gint y,
- GtkSelectionData * selection_data, guint info,
- guint32 time, gpointer data)
+bw_notebook_drag_received_cb(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint32 time,
+ gpointer data)
{
BalsaIndex* index;
LibBalsaMailbox* mailbox;
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index aa73ade..f887f67 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -148,20 +148,19 @@ static void sw_buffer_set_undo(BalsaSendmsg * bsmsg, gboolean undo,
enum {
TARGET_MESSAGES,
TARGET_URI_LIST,
- TARGET_EMAIL,
TARGET_STRING
};
static GtkTargetEntry drop_types[] = {
- {"x-application/x-message-list", GTK_TARGET_SAME_APP, TARGET_MESSAGES},
- {"text/uri-list", 0, TARGET_URI_LIST},
- { "STRING", 0, TARGET_STRING },
- { "text/plain", 0, TARGET_STRING },
+ { "x-application/x-message-list", GTK_TARGET_SAME_APP},
+ { "text/uri-list", 0},
+ { "STRING", 0},
+ { "text/plain", 0}
};
static GtkTargetEntry email_field_drop_types[] = {
- { "STRING", 0, TARGET_STRING },
- { "text/plain", 0, TARGET_STRING }
+ { "STRING", 0},
+ { "text/plain", 0}
};
static void lang_set_cb(GtkWidget *widget, BalsaSendmsg *bsmsg);
@@ -2191,11 +2190,15 @@ attachments_add(GtkWidget * widget,
GtkSelectionData * selection_data,
guint info, guint32 time, BalsaSendmsg * bsmsg)
{
+ GdkAtom target;
gboolean drag_result = TRUE;
if (balsa_app.debug)
printf("attachments_add: info %d\n", info);
- if (info == TARGET_MESSAGES) {
+
+ target = gtk_selection_data_get_target(selection_data);
+
+ if (target == gdk_atom_intern("x-application/x-message-list", TRUE)) {
BalsaIndex *index =
*(BalsaIndex **) gtk_selection_data_get_data(selection_data);
LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
@@ -2217,37 +2220,38 @@ attachments_add(GtkWidget * widget,
g_object_unref(message);
}
balsa_index_selected_msgnos_free(index, selected);
- } else if (info == TARGET_URI_LIST) {
- GSList *uri_list =
- uri2gslist((gchar *)
- gtk_selection_data_get_data(selection_data));
- for (; uri_list; uri_list = g_slist_next(uri_list)) {
+ } else if (target == gdk_atom_intern("text/uri-list", TRUE)) {
+ GSList *uri_list, *list;
+
+ list = uri2gslist((gchar *) gtk_selection_data_get_data(selection_data));
+ for (uri_list = list; uri_list != NULL; uri_list = uri_list->next) {
add_attachment(bsmsg, uri_list->data, FALSE, NULL);
g_free(uri_list->data);
}
- g_slist_free(uri_list);
- } else if( info == TARGET_STRING) {
- gchar *url =
- rfc2396_uri((gchar *)
- gtk_selection_data_get_data(selection_data));
+ g_slist_free(list);
+ } else if (target == gdk_atom_intern("STRING", TRUE) ||
+ target == gdk_atom_intern("text/plain", TRUE)) {
+ gchar *url = rfc2396_uri((gchar *) gtk_selection_data_get_data(selection_data));
if (url)
add_urlref_attachment(bsmsg, url);
else
drag_result = FALSE;
}
+
gtk_drag_finish(context, drag_result, FALSE, time);
}
/* to_add - address-view D&D callback; we assume it's a To: address */
static void
-to_add(GtkWidget * widget,
- GdkDragContext * context,
- gint x,
- gint y,
+to_add(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
GtkSelectionData * selection_data,
- guint info, guint32 time)
+ guint32 time)
{
+ GdkAtom target;
gboolean drag_result = FALSE;
#ifdef DEBUG
@@ -2255,13 +2259,16 @@ to_add(GtkWidget * widget,
g_print("%s atom name %s\n", __func__,
gdk_atom_name(gtk_selection_data_get_target(selection_data)));
#endif
- if (info == TARGET_STRING) {
+
+ target = gtk_selection_data_get_target(selection_data);
+
+ if (target == gdk_atom_intern("STRING", TRUE) ||
+ target == gdk_atom_intern("text/plain", TRUE)) {
const gchar *address;
address =
(const gchar *) gtk_selection_data_get_data(selection_data);
- libbalsa_address_view_add_from_string(LIBBALSA_ADDRESS_VIEW
- (widget), "To:", address);
+ libbalsa_address_view_add_from_string(LIBBALSA_ADDRESS_VIEW(widget), "To:", address);
drag_result = TRUE;
}
gtk_drag_finish(context, drag_result, FALSE, time);
@@ -2753,21 +2760,24 @@ has_file_attached(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
/* drag_data_quote - text area D&D callback */
static void
-drag_data_quote(GtkWidget * widget,
- GdkDragContext * context,
- gint x,
- gint y,
+drag_data_quote(GtkWidget * widget,
+ GdkDragContext * context,
+ gint x,
+ gint y,
GtkSelectionData * selection_data,
- guint info, guint32 time, BalsaSendmsg * bsmsg)
+ guint32 time,
+ BalsaSendmsg * bsmsg)
{
+ GdkAtom target;
GtkTextBuffer *buffer;
BalsaIndex *index;
LibBalsaMailbox *mailbox;
GArray *selected;
guint i;
- switch(info) {
- case TARGET_MESSAGES:
+ target = gtk_selection_data_get_target(selection_data);
+
+ if (target == gdk_atom_intern(drop_types[TARGET_MESSAGES].target, TRUE)) {
index =
*(BalsaIndex **) gtk_selection_data_get_data(selection_data);
mailbox = index->mailbox_node->mailbox;
@@ -2789,8 +2799,7 @@ drag_data_quote(GtkWidget * widget,
g_string_free(body, TRUE);
}
balsa_index_selected_msgnos_free(index, selected);
- break;
- case TARGET_URI_LIST: {
+ } else if (target == gdk_atom_intern(drop_types[TARGET_URI_LIST].target, TRUE)) {
GSList *uri_list =
uri2gslist((gchar *)
gtk_selection_data_get_data(selection_data));
@@ -2811,11 +2820,7 @@ drag_data_quote(GtkWidget * widget,
g_slist_foreach(uri_list, (GFunc) g_free, NULL);
g_slist_free(uri_list);
}
- break;
- case TARGET_EMAIL:
- case TARGET_STRING: /* perhaps we should allow dropping in these, too? */
- default: return;
- }
+
gtk_drag_finish(context, TRUE, FALSE, time);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]