From 5b35ad19c4df4ce9a971dfaea2223e6d431f138e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 5 Jun 2010 12:48:01 +0000 Subject: [PATCH] [7.2.442] Copy/paste with OpenOffice doesn't work. Problem: Copy/paste with OpenOffice doesn't work. Solution: Do not offer the HTML target when it is not supported. (James Vega) Patch 7.2.442 (after 7.2.201) --- src/gui_gtk_x11.c | 90 ++++++++++++++++++++++++++++++++++++----------- src/option.c | 7 ++++ src/proto/gui_gtk_x11.pro | 2 ++ src/version.c | 2 ++ 4 files changed, 81 insertions(+), 20 deletions(-) diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index f905eaf6..991d2a03 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -1433,6 +1433,10 @@ selection_received_cb(GtkWidget *widget UNUSED, } #endif /* !HAVE_GTK2 */ + /* Chop off any traiing NUL bytes. OpenOffice sends these. */ + while (len > 0 && text[len - 1] == NUL) + --len; + clip_yank_selection(motion_type, text, (long)len, cbd); received_selection = RS_OK; vim_free(tmpbuf); @@ -3463,6 +3467,66 @@ gui_mch_set_curtab(nr) #endif /* FEAT_GUI_TABLINE */ /* + * Add selection targets for PRIMARY and CLIPBOARD selections. + */ + void +gui_gtk_set_selection_targets(void) +{ + int i, j = 0; + int n_targets = N_SELECTION_TARGETS; + GtkTargetEntry targets[N_SELECTION_TARGETS]; + + for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) + { +#ifdef FEAT_MBYTE + /* OpenOffice tries to use TARGET_HTML and fails when it doesn't + * return something, instead of trying another target. Therefore only + * offer TARGET_HTML when it works. */ + if (!clip_html && selection_targets[i].info == TARGET_HTML) + n_targets--; + else +#endif + targets[j++] = selection_targets[i]; + } + + gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); + gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); + gtk_selection_add_targets(gui.drawarea, + (GdkAtom)GDK_SELECTION_PRIMARY, + targets, n_targets); + gtk_selection_add_targets(gui.drawarea, + (GdkAtom)clip_plus.gtk_sel_atom, + targets, n_targets); +} + +/* + * Set up for receiving DND items. + */ + void +gui_gtk_set_dnd_targets(void) +{ + int i, j = 0; + int n_targets = N_DND_TARGETS; + GtkTargetEntry targets[N_DND_TARGETS]; + + for (i = 0; i < (int)N_DND_TARGETS; ++i) + { +#ifdef FEAT_MBYTE + if (!clip_html && selection_targets[i].info == TARGET_HTML) + n_targets--; + else +#endif + targets[j++] = dnd_targets[i]; + } + + gtk_drag_dest_unset(gui.drawarea); + gtk_drag_dest_set(gui.drawarea, + GTK_DEST_DEFAULT_ALL, + targets, n_targets, + GDK_ACTION_COPY); +} + +/* * Initialize the GUI. Create all the windows, set up all the callbacks etc. * Returns OK for success, FAIL when the GUI can't be started. */ @@ -3925,15 +3989,7 @@ gui_mch_init(void) gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", GTK_SIGNAL_FUNC(selection_received_cb), NULL); - /* - * Add selection targets for PRIMARY and CLIPBOARD selections. - */ - gtk_selection_add_targets(gui.drawarea, - (GdkAtom)GDK_SELECTION_PRIMARY, - selection_targets, N_SELECTION_TARGETS); - gtk_selection_add_targets(gui.drawarea, - (GdkAtom)clip_plus.gtk_sel_atom, - selection_targets, N_SELECTION_TARGETS); + gui_gtk_set_selection_targets(); gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", GTK_SIGNAL_FUNC(selection_get_cb), NULL); @@ -4057,7 +4113,6 @@ check_startup_plug_hints(gpointer data UNUSED) return TRUE; } - /* * Open the GUI window which was created by a call to gui_mch_init(). */ @@ -4225,13 +4280,8 @@ gui_mch_open(void) GTK_SIGNAL_FUNC(form_configure_event), NULL); #ifdef FEAT_DND - /* - * Set up for receiving DND items. - */ - gtk_drag_dest_set(gui.drawarea, - GTK_DEST_DEFAULT_ALL, - dnd_targets, N_DND_TARGETS, - GDK_ACTION_COPY); + /* Set up for receiving DND items. */ + gui_gtk_set_dnd_targets(); gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", GTK_SIGNAL_FUNC(drag_data_received_cb), NULL); @@ -4428,7 +4478,7 @@ gui_mch_set_shellsize(int width, int height, /* this will cause the proper resizement to happen too */ update_window_manager_hints(0, 0); -#else /* HAVE_GTK2 */ +#else /* this will cause the proper resizement to happen too */ if (gtk_socket_id == 0) update_window_manager_hints(0, 0); @@ -4444,14 +4494,14 @@ gui_mch_set_shellsize(int width, int height, else update_window_manager_hints(width, height); -#if 0 +# if 0 if (!resize_idle_installed) { g_idle_add_full(GDK_PRIORITY_EVENTS + 10, &force_shell_resize_idle, NULL, NULL); resize_idle_installed = TRUE; } -#endif +# endif /* * Wait until all events are processed to prevent a crash because the * real size of the drawing area doesn't reflect Vim's internal ideas. diff --git a/src/option.c b/src/option.c index f93d839c..06560a74 100644 --- a/src/option.c +++ b/src/option.c @@ -7112,6 +7112,13 @@ check_clipboard_option() clip_html = new_html; vim_free(clip_exclude_prog); clip_exclude_prog = new_exclude_prog; +#ifdef FEAT_GUI_GTK + if (gui.in_use) + { + gui_gtk_set_selection_targets(); + gui_gtk_set_dnd_targets(); + } +#endif } else vim_free(new_exclude_prog); diff --git a/src/proto/gui_gtk_x11.pro b/src/proto/gui_gtk_x11.pro index 93b65bf7..d80ba82e 100644 --- a/src/proto/gui_gtk_x11.pro +++ b/src/proto/gui_gtk_x11.pro @@ -9,6 +9,8 @@ void gui_mch_show_tabline __ARGS((int showit)); int gui_mch_showing_tabline __ARGS((void)); void gui_mch_update_tabline __ARGS((void)); void gui_mch_set_curtab __ARGS((int nr)); +void gui_gtk_set_selection_targets __ARGS((void)); +void gui_gtk_set_dnd_targets __ARGS((void)); int gui_mch_init __ARGS((void)); void gui_mch_forked __ARGS((void)); void gui_mch_new_colors __ARGS((void)); diff --git a/src/version.c b/src/version.c index a552719d..856230a5 100644 --- a/src/version.c +++ b/src/version.c @@ -682,6 +682,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 442, +/**/ 441, /**/ 440, -- 2.11.4.GIT