changeset 7750:14cc6614af93

[gaim-migrate @ 8395] And this completes the proper way to handle setting my own clipboard data such that it won't screw up Windows and be all hacky. However, this copy stuff will make smileys no longer copy in plaintext. That's easy to fix, though. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 04 Dec 2003 20:43:27 +0000
parents ddda7537918e
children d691cb95ee67
files src/gtkimhtml.c src/gtkimhtml.h
diffstat 2 files changed, 23 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Thu Dec 04 20:31:49 2003 +0000
+++ b/src/gtkimhtml.c	Thu Dec 04 20:43:27 2003 +0000
@@ -357,15 +357,6 @@
 }
 
 #if GTK_CHECK_VERSION(2,2,0)
-static GtkIMHtmlCopyable *gtk_imhtml_copyable_new(GtkIMHtml *imhtml, GtkTextMark *mark, const gchar *text) 
-{
-	GtkIMHtmlCopyable *copy = g_malloc(sizeof(GtkIMHtmlCopyable));
-	copy->mark = mark;
-	copy->text = g_strdup(text);
-	imhtml->copyables = g_slist_append(imhtml->copyables, copy);
-	return copy;
-}
-
 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) {
 	GtkTextIter start, end;
 	GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
@@ -393,25 +384,40 @@
 
 static void gtk_imhtml_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml)
 {
+	GtkTextIter insert;
+	GtkTextIter selection_bound;
+	
+	gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert,
+					  gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"));
+	gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound,
+					  gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"));
+	
+	if (!gtk_text_iter_equal (&insert, &selection_bound))
+		gtk_text_buffer_move_mark (imhtml->text_buffer,
+					   gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"),
+					   &insert);
 }
 
 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard)
 {
-	gtk_clipboard_set_with_owner(clipboard ? clipboard :  
-				     gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), 
+	gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), 
 				     selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), 
 				     (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
-				     (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, G_OBJECT(imhtml));
+				     (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
 
 	g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
 }
 
 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man)
 {
-	GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (imhtml),
-							    GDK_SELECTION_PRIMARY);
-	gtk_text_buffer_remove_selection_clipboard (imhtml->text_buffer, clipboard);	
-	copy_clipboard_cb(imhtml, gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
+	GtkClipboard *clipboard;
+	if ((clipboard = gtk_widget_get_clipboard (GTK_WIDGET (imhtml),
+						   GDK_SELECTION_PRIMARY)))
+		gtk_text_buffer_remove_selection_clipboard (imhtml->text_buffer, clipboard);	
+	gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), 
+				     selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), 
+				     (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
+				     (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, G_OBJECT(imhtml));
 	return FALSE;
 }
 #endif
@@ -431,9 +437,6 @@
 {
 	GtkIMHtml *imhtml = GTK_IMHTML(object);
 	GList *scalables;
-#if GTK_CHECK_VERSION(2,2,0)
-	GSList *copyables;
-#endif
 	
 	g_hash_table_destroy(imhtml->smiley_data);
 	gtk_smiley_tree_destroy(imhtml->default_smilies);
@@ -451,13 +454,6 @@
 		scale->free(scale);
 	}
 	
-#if GTK_CHECK_VERSION(2,2,0)
-	for (copyables = imhtml->copyables; copyables; copyables = copyables->next) {
-		GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data);
-		g_free(copy->text);
-		g_free(copy);
-	}
-#endif
 	g_list_free(imhtml->scalables);
 	G_OBJECT_CLASS(parent_class)->finalize (object);
 }
@@ -543,9 +539,7 @@
 	imhtml->format_spans = NULL;
 	
 	imhtml->scalables = NULL;
-#if GTK_CHECK_VERSION(2,2,0)
-	imhtml->copyables = NULL;
-#endif
+
 	gtk_imhtml_set_editable(imhtml, FALSE);
 	
 }
@@ -1512,11 +1506,6 @@
 			if (icon) {
 				gtk_widget_show(icon);
 				gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor);
-#if GTK_CHECK_VERSION(2,2,0)
-				gtk_imhtml_copyable_new(imhtml, 
-							gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE), 
-							ws);
-#endif
 			}
 			
 			copy = iter;
@@ -2311,11 +2300,6 @@
 	if (icon) {
 		gtk_widget_show(icon);
 		gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor);
-#if GTK_CHECK_VERSION(2,2,0)
-		gtk_imhtml_copyable_new(imhtml, 
-					gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE), 
-					smiley);
-#endif
 	}
 }
 
--- a/src/gtkimhtml.h	Thu Dec 04 20:31:49 2003 +0000
+++ b/src/gtkimhtml.h	Thu Dec 04 20:43:27 2003 +0000
@@ -37,7 +37,6 @@
 #define GTK_IS_IMHTML(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_IMHTML))
 #define GTK_IS_IMHTML_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_IMHTML))
 #define GTK_IMHTML_SCALABLE(obj)   ((GtkIMHtmlScalable *)obj)
-#define GTK_IMHTML_COPYABLE(obj)   ((GtkIMHtmlCopyable *)obj)
 
 typedef struct _GtkIMHtml			GtkIMHtml;
 typedef struct _GtkIMHtmlClass		GtkIMHtmlClass;
@@ -47,7 +46,6 @@
 typedef struct _GtkIMHtmlScalable	GtkIMHtmlScalable;
 typedef struct _GtkIMHtmlImage		GtkIMHtmlImage;
 typedef struct _GtkIMHtmlHr			GtkIMHtmlHr;
-typedef struct _GtkIMHtmlCopyable       GtkIMHtmlCopyable;
 
 
 typedef struct {
@@ -80,8 +78,6 @@
 	GList *scalables;
 	GdkRectangle old_rect;
 
-	GSList *copyables;
-
 	gchar *search_string;
 
 	gboolean editable;
@@ -131,11 +127,6 @@
 	void (*free)(struct _GtkIMHtmlScalable *);
 };
 
-struct _GtkIMHtmlCopyable {
-	GtkTextMark *mark;
-	char *text;
-};
-
 struct _GtkIMHtmlImage {
 	GtkIMHtmlScalable scalable;
 	GtkImage *image;