changeset 5046:44945824ba60

[gaim-migrate @ 5394] javabsp fixed im image scaling I fixed im image saving, and the button annoyingly staying toggled committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 06 Apr 2003 02:09:56 +0000
parents ad42102dd85f
children 4faa311cf6b2
files src/gtkconv.c src/gtkimhtml.c src/gtkimhtml.h
diffstat 3 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Sun Apr 06 01:27:56 2003 +0000
+++ b/src/gtkconv.c	Sun Apr 06 02:09:56 2003 +0000
@@ -171,6 +171,8 @@
 	gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(gtkconv->entry_buffer),
 									 buf, -1);
 	g_free(buf);
+
+	set_toggle(gtkconv->toolbar.image, FALSE);
 }
 
 static gint
@@ -202,26 +204,26 @@
 
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
 
-	window = gtk_file_selection_new(_("Gaim - Insert Image"));
-	g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir());
-	gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
-
-	g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-					  "user_data", conv);
-	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-					 "clicked", G_CALLBACK(do_insert_image_cb), window);
-	g_signal_connect_swapped(
-			G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button),
-			"clicked", G_CALLBACK(gtk_widget_destroy), window);
-
-	gtk_widget_show(window);
-/*
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.image),
-								FALSE);
-								*/
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.image))) {
+		window = gtk_file_selection_new(_("Gaim - Insert Image"));
+		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir());
+		gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
+
+		g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
+				"user_data", conv);
+		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
+				"clicked", G_CALLBACK(do_insert_image_cb), window);
+		g_signal_connect_swapped(
+				G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button),
+				"clicked", G_CALLBACK(gtk_widget_destroy), window);
+
+		gtk_widget_show(window);
+	} else {
+		gtk_widget_grab_focus(gtkconv->entry);
+	}
 }
 
-static void
+	static void
 insert_link_cb(GtkWidget *w, struct gaim_conversation *conv)
 {
 	struct gaim_gtk_conversation *gtkconv;
--- a/src/gtkimhtml.c	Sun Apr 06 01:27:56 2003 +0000
+++ b/src/gtkimhtml.c	Sun Apr 06 02:09:56 2003 +0000
@@ -1433,12 +1433,15 @@
 	GTK_IMHTML_SCALABLE(im_image)->scale = gaim_im_image_scale;
 	GTK_IMHTML_SCALABLE(im_image)->add_to = gaim_im_image_add_to;
 	GTK_IMHTML_SCALABLE(im_image)->free = gaim_im_image_free;
+
+	im_image->pixbuf = img;
 	im_image->image = image;
 	im_image->width = gdk_pixbuf_get_width(img);
 	im_image->height = gdk_pixbuf_get_height(img);
 	im_image->mark = NULL;
 	im_image->filename = filename;
 
+	g_object_ref(img);
 	return GTK_IMHTML_SCALABLE(im_image);
 }
 
@@ -1447,7 +1450,6 @@
 	gaim_im_image *image = (gaim_im_image *)scale;
 
 	if(image->width > width || image->height > height){
-		GdkPixbuf *old_image = gtk_image_get_pixbuf(image->image);
 		GdkPixbuf *new_image = NULL;
 		float factor;
 		int new_width = image->width, new_height = image->height;
@@ -1463,7 +1465,7 @@
 			new_width = new_width * factor;
 		}
 
-		new_image = gdk_pixbuf_scale_simple(old_image, new_width, new_height, GDK_INTERP_BILINEAR);
+		new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
 		gtk_image_set_from_pixbuf(image->image, new_image);
 		g_object_unref(G_OBJECT(new_image));
 	}
@@ -1472,9 +1474,8 @@
 void gaim_im_image_free(GtkIMHtmlScalable *scale)
 {
 	gaim_im_image *image = (gaim_im_image *)scale;
-/*
-	g_object_unref(image->image);
-*/
+
+	g_object_unref(image->pixbuf);
 	g_free(image->filename);
 	g_free(scale);
 }
@@ -1587,7 +1588,7 @@
 		type = g_strdup("png");
 	}
 
-	gdk_pixbuf_save(gtk_image_get_pixbuf(image->image), filename, type, &error, NULL);
+	gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL);
 
 	if(error){
 		gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
--- a/src/gtkimhtml.h	Sun Apr 06 01:27:56 2003 +0000
+++ b/src/gtkimhtml.h	Sun Apr 06 02:09:56 2003 +0000
@@ -136,6 +136,7 @@
 typedef struct {
 	GtkIMHtmlScalable scalable;
 	GtkImage *image;
+	GdkPixbuf *pixbuf;
 	GtkTextMark *mark;
 	gchar *filename;
 	int width;