From 4e75a5cdfd897af12af8c0e927ada7315da81de8 Mon Sep 17 00:00:00 2001 From: Matthew Brush Date: Mon, 28 Mar 2011 18:39:37 -0700 Subject: Fix X PRIMARY selection issue when Scintilla widget is unrealized/re-realized. When the widget is unrealized (for ex. with gtk_container_remove), the GdkWindows used in the widget are destroyed and when the widget is realized again (for ex. with gtk_container_add), the GdkWindows are re-created. This commit moves the gtk_selection_add_targets() calls into the RealizeThis function, so that when the widget is realized again, the selection targets are re-added on the new GdkWindow. Also add gtk_selection_clear_targets() into UnRealizeThis to remove the registered targets before the GdkWindow is destroyed. References: http://mail.gnome.org/archives/gtk-devel-list/2002-March/msg00078.html http://mail.gnome.org/archives/anjuta-devel-list/2002-March/msg00066.html http://git.geany.org/geany/tree/plugins/splitwindow.c#n310 --- gtk/ScintillaGTK.cxx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 55ce3f7d1..42f9bc756 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -420,6 +420,14 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { gtk_widget_realize(widtxt); gtk_widget_realize(PWidget(scrollbarv)); gtk_widget_realize(PWidget(scrollbarh)); + + gtk_selection_add_targets(widget, GDK_SELECTION_PRIMARY, + clipboardCopyTargets, nClipboardCopyTargets); + +#ifndef USE_GTK_CLIPBOARD + gtk_selection_add_targets(widget, atomClipboard, + clipboardPasteTargets, nClipboardPasteTargets); +#endif } void ScintillaGTK::Realize(GtkWidget *widget) { @@ -429,6 +437,14 @@ void ScintillaGTK::Realize(GtkWidget *widget) { void ScintillaGTK::UnRealizeThis(GtkWidget *widget) { try { + + gtk_selection_clear_targets(widget, GDK_SELECTION_PRIMARY); + +#ifndef USE_GTK_CLIPBOARD + gtk_selection_clear_targets(widget, atomClipboard); +#endif + + if (IS_WIDGET_MAPPED(widget)) { gtk_widget_unmap(widget); } @@ -670,14 +686,6 @@ void ScintillaGTK::Initialise() { gtk_widget_grab_focus(PWidget(wMain)); - gtk_selection_add_targets(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY, - clipboardCopyTargets, nClipboardCopyTargets); - -#ifndef USE_GTK_CLIPBOARD - gtk_selection_add_targets(GTK_WIDGET(PWidget(wMain)), atomClipboard, - clipboardPasteTargets, nClipboardPasteTargets); -#endif - gtk_drag_dest_set(GTK_WIDGET(PWidget(wMain)), GTK_DEST_DEFAULT_ALL, clipboardPasteTargets, nClipboardPasteTargets, static_cast(GDK_ACTION_COPY | GDK_ACTION_MOVE)); -- cgit v1.2.3