changeset 10181:5b33637b69fd

[gaim-migrate @ 11296] Update a few more places to use the gtkimhtml factory thingy. Look at the changes to gtkrequest.c to see how much duplicate code this removes... committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 14 Nov 2004 20:29:28 +0000
parents 04516341e9a5
children 4085b2cda8f1
files src/gtklog.c src/gtknotify.c src/gtkprefs.c src/gtkrequest.c src/gtkutils.c
diffstat 5 files changed, 45 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtklog.c	Sun Nov 14 20:26:27 2004 +0000
+++ b/src/gtklog.c	Sun Nov 14 20:29:28 2004 +0000
@@ -256,7 +256,7 @@
 	GtkTreeViewColumn *col;
 	GaimGtkLogViewer *lv = NULL;
 	GtkTreeSelection *sel;
-	GtkWidget *icon, *label, *pane, *sw, *button;
+	GtkWidget *icon, *label, *pane, *sw, *button, *frame;
 	GList *logs;
 	char *text ,*ttext;
 	struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1);
@@ -268,6 +268,7 @@
 		log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
 	} else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
 		gtk_window_present(GTK_WINDOW(lv->window));
+		g_free(ht);
 		return;
 	}
 
@@ -330,34 +331,29 @@
 	g_signal_connect (G_OBJECT (sel), "changed",
 			  G_CALLBACK (log_select_cb),
 			  lv);
+	gaim_set_accessible_label(lv->treeview, label);
 
-	/* Viewer ************/
+	/* A fancy little box ************/
 	vbox = gtk_vbox_new(FALSE, 6);
 	gtk_paned_add2(GTK_PANED(pane), vbox);
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
-	lv->imhtml = gtk_imhtml_new(NULL, NULL);
+
+	/* Viewer ************/
+	frame = gaim_gtk_create_imhtml(FALSE, &lv->imhtml, NULL);
 	gtk_widget_set_name(lv->imhtml, "gaim_gtklog_imhtml");
-	gtk_container_add(GTK_CONTAINER(sw), lv->imhtml);
-	gaim_setup_imhtml(lv->imhtml);
 	gtk_widget_set_size_request(lv->imhtml, 320, 200);
+	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+	gtk_widget_show(frame);
 
 	/* Search box **********/
 	hbox = gtk_hbox_new(FALSE, 6);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 	lv->entry = gtk_entry_new();
 	gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0);
-	g_signal_connect(GTK_ENTRY(lv->entry), "activate",
-			  G_CALLBACK (search_cb), lv);
 	button = gtk_button_new_from_stock(GTK_STOCK_FIND);
-	g_signal_connect (GTK_BUTTON (button), "activate",
-			  G_CALLBACK (search_cb), lv);
-	g_signal_connect (GTK_BUTTON (button), "clicked",
-			  G_CALLBACK (search_cb), lv);
 	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-	gaim_set_accessible_label (lv->treeview, label);
+	g_signal_connect(GTK_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv);
+	g_signal_connect(GTK_BUTTON(button), "activate", G_CALLBACK(search_cb), lv);
+	g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(search_cb), lv);
 
 	gtk_widget_show_all(lv->window);
 }
@@ -368,11 +364,11 @@
 	GtkCellRenderer *rend;
 	GtkTreeViewColumn *col;
 	GtkTreeSelection *sel;
-	GtkWidget *label, *pane, *sw, *button;
+	GtkWidget *label, *pane, *sw, *button, *frame;
 	char *text;
 	GList *accounts = NULL;
 
-	if(syslog_viewer){
+	if (syslog_viewer != NULL) {
 		gtk_window_present(GTK_WINDOW(syslog_viewer->window));
 		return;
 	}
@@ -440,35 +436,30 @@
 			  G_CALLBACK (log_select_cb),
 			  syslog_viewer);
 
-	/* Viewer ************/
+	/* A fancy little box ************/
 	vbox = gtk_vbox_new(FALSE, 6);
 	gtk_paned_add2(GTK_PANED(pane), vbox);
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
-	syslog_viewer->imhtml = gtk_imhtml_new(NULL, NULL);
+
+	/* Viewer ************/
+	frame = gaim_gtk_create_imhtml(FALSE, &syslog_viewer->imhtml, NULL);
 	gtk_widget_set_name(syslog_viewer->imhtml, "gaim_gtklog_imhtml");
-	gtk_container_add(GTK_CONTAINER(sw), syslog_viewer->imhtml);
-	gaim_setup_imhtml(syslog_viewer->imhtml);
 	gtk_widget_set_size_request(syslog_viewer->imhtml, 400, 200);
+	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+	gtk_widget_show(frame);
 
 	/* Search box **********/
 	hbox = gtk_hbox_new(FALSE, 6);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 	syslog_viewer->entry = gtk_entry_new();
 	gtk_box_pack_start(GTK_BOX(hbox), syslog_viewer->entry, TRUE, TRUE, 0);
-	g_signal_connect (GTK_ENTRY (syslog_viewer->entry), "activate",
-			  G_CALLBACK (search_cb),
-			  syslog_viewer);
 	button = gtk_button_new_from_stock(GTK_STOCK_FIND);
-	g_signal_connect (GTK_BUTTON (button), "activate",
-			  G_CALLBACK (search_cb),
-			  syslog_viewer);
-	g_signal_connect (GTK_BUTTON (button), "clicked",
-			  G_CALLBACK (search_cb),
-			  syslog_viewer);
 	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+	g_signal_connect(GTK_ENTRY(syslog_viewer->entry), "activate",
+					 G_CALLBACK(search_cb), syslog_viewer);
+	g_signal_connect(GTK_BUTTON(button), "activate",
+					 G_CALLBACK(search_cb), syslog_viewer);
+	g_signal_connect(GTK_BUTTON(button), "clicked",
+					 G_CALLBACK(search_cb), syslog_viewer);
 
 	gtk_widget_show_all(syslog_viewer->window);
 }
--- a/src/gtknotify.c	Sun Nov 14 20:26:27 2004 +0000
+++ b/src/gtknotify.c	Sun Nov 14 20:29:28 2004 +0000
@@ -301,7 +301,7 @@
 	GtkWidget *label;
 	GtkWidget *button;
 	GtkWidget *imhtml;
-	GtkWidget *sw;
+	GtkWidget *frame;
 	int options = 0;
 	char label_text[2048];
 	char *linked_text;
@@ -334,23 +334,12 @@
 	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
 	gtk_widget_show(label);
 
-	/* Setup the scrolled window that we're putting the gtkimhtml in. */
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
-								   GTK_POLICY_NEVER,
-								   GTK_POLICY_ALWAYS);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
-										GTK_SHADOW_IN);
-	gtk_widget_set_size_request(sw, 300, 250);
-	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
-	gtk_widget_show(sw);
-
-	/* Now build that gtkimhtml */
-	imhtml = gtk_imhtml_new(NULL, NULL);
+	/* Add the imhtml */
+	frame = gaim_gtk_create_imhtml(FALSE, &imhtml, NULL);
 	gtk_widget_set_name(imhtml, "gaim_gtknotify_imhtml");
-	gtk_container_add(GTK_CONTAINER(sw), imhtml);
-	gtk_widget_show(imhtml);
-	gaim_setup_imhtml(imhtml);
+	gtk_widget_set_size_request(imhtml, 300, 250);
+	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+	gtk_widget_show(frame);
 
 	/* Add the Close button. */
 	button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
@@ -362,7 +351,6 @@
 	g_signal_connect(G_OBJECT(window), "key_press_event",
 					 G_CALLBACK(formatted_input_cb), NULL);
 
-
 	/* Add the text to the gtkimhtml */
 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors"))
 		options ^= GTK_IMHTML_NO_COLOURS;
@@ -378,8 +366,7 @@
 
 	/* Make sure URLs are clickable */
 	linked_text = gaim_markup_linkify(text);
-	gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text,
-									   options);
+	gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text, options);
 	g_free(linked_text);
 
 	/* Show the window */
--- a/src/gtkprefs.c	Sun Nov 14 20:26:27 2004 +0000
+++ b/src/gtkprefs.c	Sun Nov 14 20:29:28 2004 +0000
@@ -706,7 +706,7 @@
 }
 
 static void
-formatting_reset_cb(GtkWidget *w, GtkWidget* imhtml) {
+formatting_reset_cb(GtkWidget *w, GtkWidget *imhtml) {
 	gboolean bold, italic, uline;
 	bold = italic = uline = FALSE;
 
@@ -776,7 +776,6 @@
 	GtkWidget *vbox, *fontvbox;
 	GtkWidget *imhtml;
 	GtkWidget *toolbar;
-	GtkWidget *sw;
 	GtkWidget *frame;
 	GtkWidget *option;
 	GtkWidget *button;
@@ -804,33 +803,15 @@
 	option = gaim_gtk_prefs_checkbox(_("_Send default formatting with outgoing messages"),
 									 "/gaim/gtk/conversations/send_formatting", vbox);
 
-	frame = gtk_frame_new(NULL);
-	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
-	gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
 
 	fontvbox = gtk_vbox_new(FALSE, 0);
-	gtk_container_add(GTK_CONTAINER(frame), fontvbox);
-
-	toolbar = gtk_imhtmltoolbar_new();
-	gtk_box_pack_start(GTK_BOX(fontvbox), toolbar, FALSE, FALSE, 0);
-
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
-				       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_NONE);
-	gtk_box_pack_start(GTK_BOX(fontvbox), sw, TRUE, TRUE, 0);
-
-	imhtml = gtk_imhtml_new(NULL, NULL);
+	gtk_container_add(GTK_CONTAINER(vbox), fontvbox);
+
+	frame = gaim_gtk_create_imhtml(TRUE, &imhtml, &toolbar);
 	gtk_widget_set_name(imhtml, "gaim_gtkprefs_font_imhtml");
-	gtk_imhtml_set_editable(GTK_IMHTML(imhtml), TRUE);
-	gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), GTK_IMHTML_ALL ^ GTK_IMHTML_IMAGE);
 	gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(imhtml), TRUE);
-
-	gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), imhtml);
-	gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default");
-	gaim_setup_imhtml(imhtml);
 	gtk_imhtml_append_text(GTK_IMHTML(imhtml), _("This is how your outgoing message text will appear when you use protocols that support formatting. :)"), 0);
-	gtk_container_add(GTK_CONTAINER(sw), imhtml);
+	gtk_box_pack_start(GTK_BOX(fontvbox), frame, FALSE, FALSE, 0);
 
 	button = gtk_button_new_with_mnemonic(_("_Clear Formatting"));
 	gtk_box_pack_start(GTK_BOX(fontvbox), button, FALSE, FALSE, 0);
--- a/src/gtkrequest.c	Sun Nov 14 20:26:27 2004 +0000
+++ b/src/gtkrequest.c	Sun Nov 14 20:29:28 2004 +0000
@@ -336,52 +336,15 @@
 
 	if ((data->u.input.hint != NULL) && (!strcmp(data->u.input.hint, "html"))) {
 		GtkWidget *frame;
-		GtkWidget *vbox2;
-		GtkWidget *sep;
-		GtkWidget *sw;
 
-		/* Thin frame surrounding the toolbar and imhtml */
-		frame = gtk_frame_new(NULL);
-		gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
+		/* imhtml */
+		frame = gaim_gtk_create_imhtml(TRUE, &entry, &toolbar);
+		gtk_widget_set_size_request(entry, 320, 130);
+		gtk_widget_set_name(entry, "gaim_gtkrequest_imhtml");
+		if (default_value != NULL)
+			gtk_imhtml_append_text(GTK_IMHTML(entry), default_value, GTK_IMHTML_NO_SCROLL);
 		gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
 		gtk_widget_show(frame);
-
-		vbox2 = gtk_vbox_new(FALSE, 0);
-		gtk_container_add(GTK_CONTAINER(frame), vbox2);
-		gtk_widget_show(vbox2);
-
-		sw = gtk_scrolled_window_new(NULL, NULL);
-		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
-									   GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
-		gtk_widget_set_size_request(sw, 320, 130);
-
-		/* Toolbar */
-		toolbar = gtk_imhtmltoolbar_new();
-		gtk_box_pack_start(GTK_BOX(vbox2), toolbar, FALSE, FALSE, 0);
-
-		/* Separator */
-		sep = gtk_hseparator_new();
-		gtk_box_pack_start(GTK_BOX(vbox2), sep, FALSE, FALSE, 0);
-		gtk_widget_show(sep);
-
-		/* GtkIMHtml */
-		entry = gtk_imhtml_new(NULL, NULL);
-		gtk_widget_set_name(entry, "gaim_gtkrequest_imhtml");
-		gtk_imhtml_set_editable(GTK_IMHTML(entry), TRUE);
-
-		gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), entry);
-
-		if (default_value != NULL)
-			gtk_imhtml_append_text(GTK_IMHTML(entry), default_value, GTK_IMHTML_NO_SCROLL);
-
-		gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(entry), GTK_WRAP_WORD_CHAR);
-
-		gtk_box_pack_start(GTK_BOX(vbox2), sw, TRUE, TRUE, 0);
-
-		if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-			gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(entry));
-
-		gtk_container_add(GTK_CONTAINER(sw), entry);
 	}
 	else {
 		if (multiline) {
--- a/src/gtkutils.c	Sun Nov 14 20:26:27 2004 +0000
+++ b/src/gtkutils.c	Sun Nov 14 20:29:28 2004 +0000
@@ -158,7 +158,7 @@
 	if (imhtml_ret != NULL)
 		*imhtml_ret = imhtml;
 
-	if (toolbar_ret != NULL)
+	if (editable && (toolbar_ret != NULL))
 		*toolbar_ret = toolbar;
 
 	return frame;