>From 4711211ba80a6d88f5bf8a4be8b2216df275d1b2 Mon Sep 17 00:00:00 2001
From: Matthew Brush <matthewbrush@gmail.com>
Date: Wed, 30 Mar 2011 19:48:02 -0700
Subject: [PATCH 1/2] Apply patches needed to support re-releazing Scintilla widgets.

Patches needed to support unrealizing and re-realizing Scintilla
widgets in the Split Window plugin.  These changes were merged
upstream and will not be required in the future.
---
 .../0001-Fix-PRIMARY-selection-on-realize.patch    |   70 ++++++++++++++++++++
 scintilla/0002-Fix-cursors-on-realize.patch        |   40 +++++++++++
 scintilla/gtk/ScintillaGTK.cxx                     |   36 ++++++++--
 3 files changed, 138 insertions(+), 8 deletions(-)
 create mode 100644 scintilla/0001-Fix-PRIMARY-selection-on-realize.patch
 create mode 100644 scintilla/0002-Fix-cursors-on-realize.patch

diff --git a/scintilla/0001-Fix-PRIMARY-selection-on-realize.patch b/scintilla/0001-Fix-PRIMARY-selection-on-realize.patch
new file mode 100644
index 0000000..fe8a1e3
--- /dev/null
+++ b/scintilla/0001-Fix-PRIMARY-selection-on-realize.patch
@@ -0,0 +1,70 @@
+# HG changeset patch
+# User Matthew Brush <matthewbrush@gmail.com>
+# Date 1301362777 25200
+# Node ID f4b6785eea540df855dda717f1886d59758d1cc3
+# Parent  b4b219312338521cd5afd3f92c2cb314cd498727
+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
+
+diff -r b4b219312338 -r f4b6785eea54 gtk/ScintillaGTK.cxx
+--- a/gtk/ScintillaGTK.cxx	Sun Mar 27 12:57:55 2011 +1100
++++ b/gtk/ScintillaGTK.cxx	Mon Mar 28 18:39:37 2011 -0700
+@@ -420,6 +420,14 @@
+ 	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::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 @@
+ 
+ 	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<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE));
diff --git a/scintilla/0002-Fix-cursors-on-realize.patch b/scintilla/0002-Fix-cursors-on-realize.patch
new file mode 100644
index 0000000..1502484
--- /dev/null
+++ b/scintilla/0002-Fix-cursors-on-realize.patch
@@ -0,0 +1,40 @@
+# HG changeset patch
+# User Matthew Brush <matthewbrush@gmail.com>
+# Date 1301379167 25200
+# Node ID b3677caa0e3e606346bbcd1a44988fee37bac254
+# Parent  f4b6785eea540df855dda717f1886d59758d1cc3
+Reset cursors when Scintilla widget is realized.
+
+Solves problem which occurs when Scintilla widget is unrealized and then
+re-realized and the cursor is left at GDK_XTERM even over the scrollbars.
+When the Scintilla widget is unrealized it's GdkWindows are destroyed and
+so the previous cursors are lost.  This commit forces default cursors on
+the text and scrollbar windows when the widget is realized.
+
+References:
+http://www.mail-archive.com/scintilla-interest@lyra.org/msg01364.html
+http://git.geany.org/geany/tree/plugins/splitwindow.c#n310
+http://www.mail-archive.com/geany@uvena.de/msg00821.html
+
+diff -r f4b6785eea54 -r b3677caa0e3e gtk/ScintillaGTK.cxx
+--- a/gtk/ScintillaGTK.cxx	Mon Mar 28 18:39:37 2011 -0700
++++ b/gtk/ScintillaGTK.cxx	Mon Mar 28 23:12:47 2011 -0700
+@@ -421,6 +421,18 @@
+ 	gtk_widget_realize(PWidget(scrollbarv));
+ 	gtk_widget_realize(PWidget(scrollbarh));
+ 
++	cursor = gdk_cursor_new(GDK_XTERM);
++	gdk_window_set_cursor(PWidget(wText)->window, cursor);
++	gdk_cursor_unref(cursor);
++
++	cursor = gdk_cursor_new(GDK_LEFT_PTR);
++	gdk_window_set_cursor(PWidget(scrollbarv)->window, cursor);
++	gdk_cursor_unref(cursor);
++
++	cursor = gdk_cursor_new(GDK_LEFT_PTR);
++	gdk_window_set_cursor(PWidget(scrollbarh)->window, cursor);
++	gdk_cursor_unref(cursor);
++
+ 	gtk_selection_add_targets(widget, GDK_SELECTION_PRIMARY,
+ 	                          clipboardCopyTargets, nClipboardCopyTargets);
+ 
diff --git a/scintilla/gtk/ScintillaGTK.cxx b/scintilla/gtk/ScintillaGTK.cxx
index c288488..1cf96b8 100644
--- a/scintilla/gtk/ScintillaGTK.cxx
+++ b/scintilla/gtk/ScintillaGTK.cxx
@@ -416,6 +416,26 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
 	gtk_widget_realize(widtxt);
 	gtk_widget_realize(PWidget(scrollbarv));
 	gtk_widget_realize(PWidget(scrollbarh));
+
+	cursor = gdk_cursor_new(GDK_XTERM);
+	gdk_window_set_cursor(PWidget(wText)->window, cursor);
+	gdk_cursor_unref(cursor);
+
+	cursor = gdk_cursor_new(GDK_LEFT_PTR);
+	gdk_window_set_cursor(PWidget(scrollbarv)->window, cursor);
+	gdk_cursor_unref(cursor);
+
+	cursor = gdk_cursor_new(GDK_LEFT_PTR);
+	gdk_window_set_cursor(PWidget(scrollbarh)->window, cursor);
+	gdk_cursor_unref(cursor);
+
+	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) {
@@ -425,6 +445,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);
 		}
@@ -668,14 +696,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<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE));
-- 
1.7.1

