diff --git a/ChangeLog b/ChangeLog index 356f5e1247..a78ce47346 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-03-22 Michael Natterer + + * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): count down + from G_MAXUINT to avoid clashes with application-added DND + targets. + + * gtk/gtktextview.c (gtk_text_view_init): set an empty + GtkTargetList on the drag_dest so it is not NULL when a derived + class' init() function is called. + + (gtk_text_view_target_list_notify): copy the text buffer's paste + targets into the view's destinstion target list (preserving + application-added DND targets), instead of replacing the view's + target list. Fixes bug #334399. + 2006-03-21 Anders Carlsson * gtk/Makefile.am: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 356f5e1247..a78ce47346 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,18 @@ +2006-03-22 Michael Natterer + + * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): count down + from G_MAXUINT to avoid clashes with application-added DND + targets. + + * gtk/gtktextview.c (gtk_text_view_init): set an empty + GtkTargetList on the drag_dest so it is not NULL when a derived + class' init() function is called. + + (gtk_text_view_target_list_notify): copy the text buffer's paste + targets into the view's destinstion target list (preserving + application-added DND targets), instead of replacing the view's + target list. Fixes bug #334399. + 2006-03-21 Anders Carlsson * gtk/Makefile.am: diff --git a/gtk/gtktextbuffer.h b/gtk/gtktextbuffer.h index 7d69a600d5..79f969ccfa 100644 --- a/gtk/gtktextbuffer.h +++ b/gtk/gtktextbuffer.h @@ -43,12 +43,15 @@ G_BEGIN_DECLS /* these values are used as "info" for the targets contained in the * lists returned by gtk_text_buffer_get_copy,paste_target_list() + * + * the enum counts down from G_MAXUINT to avoid clashes with application + * added drag destinations which usually start at 0. */ typedef enum { - GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS, - GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT, - GTK_TEXT_BUFFER_TARGET_INFO_TEXT + GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXUINT - 0, + GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = G_MAXUINT - 1, + GTK_TEXT_BUFFER_TARGET_INFO_TEXT = G_MAXUINT - 2 } GtkTextBufferTargetInfo; typedef struct _GtkTextBTree GtkTextBTree; diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 3049fae6dc..9b029f4ef6 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -1044,9 +1044,8 @@ gtk_text_view_class_init (GtkTextViewClass *klass) static void gtk_text_view_init (GtkTextView *text_view) { - GtkWidget *widget; - - widget = GTK_WIDGET (text_view); + GtkWidget *widget = GTK_WIDGET (text_view); + GtkTargetList *target_list; GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); @@ -1065,6 +1064,10 @@ gtk_text_view_init (GtkTextView *text_view) gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY | GDK_ACTION_MOVE); + target_list = gtk_target_list_new (NULL, 0); + gtk_drag_dest_set_target_list (widget, target_list); + gtk_target_list_unref (target_list); + text_view->virtual_cursor_x = -1; text_view->virtual_cursor_y = -1; @@ -6159,6 +6162,7 @@ gtk_text_view_drag_motion (GtkWidget *widget, GtkTextIter end; GdkRectangle target_rect; gint bx, by; + GdkAtom target; GdkDragAction suggested_action = 0; text_view = GTK_TEXT_VIEW (widget); @@ -6180,8 +6184,10 @@ gtk_text_view_drag_motion (GtkWidget *widget, &newplace, bx, by); - if (gtk_drag_dest_find_target (widget, context, - gtk_drag_dest_get_target_list (widget)) == GDK_NONE) + target = gtk_drag_dest_find_target (widget, context, + gtk_drag_dest_get_target_list (widget)); + + if (target == GDK_NONE) { /* can't accept any of the offered targets */ } @@ -6887,7 +6893,45 @@ gtk_text_view_target_list_notify (GtkTextBuffer *buffer, const GParamSpec *pspec, gpointer data) { - gtk_drag_dest_set_target_list (data, gtk_text_buffer_get_paste_target_list (buffer)); + GtkWidget *widget = GTK_WIDGET (data); + GtkTargetList *view_list; + GtkTargetList *buffer_list; + GList *list; + + view_list = gtk_drag_dest_get_target_list (widget); + buffer_list = gtk_text_buffer_get_paste_target_list (buffer); + + if (view_list) + gtk_target_list_ref (view_list); + else + view_list = gtk_target_list_new (NULL, 0); + + list = view_list->list; + while (list) + { + GtkTargetPair *pair = list->data; + guint info; + + list = g_list_next (list); /* get next element before removing */ + + for (info = GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS; + info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT; + info--) + { + if (pair->info == info) + gtk_target_list_remove (view_list, pair->target); + } + } + + for (list = buffer_list->list; list; list = g_list_next (list)) + { + GtkTargetPair *pair = list->data; + + gtk_target_list_add (view_list, pair->target, pair->flags, pair->info); + } + + gtk_drag_dest_set_target_list (widget, view_list); + gtk_target_list_unref (view_list); } static void