changeset 311:0a8b4edc4732

[gaim-migrate @ 321] Per-conversation font and color dialogs. Thanks fflew! :) committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 02 Jun 2000 06:08:29 +0000
parents 27efd816ff48
children 3069be4c291e
files ChangeLog TODO src/conversation.c src/dialogs.c src/gaim.h
diffstat 5 files changed, 145 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jun 02 05:33:39 2000 +0000
+++ b/ChangeLog	Fri Jun 02 06:08:29 2000 +0000
@@ -7,6 +7,7 @@
 	* Pressing enter once again sends a message in buddy chatrooms (oops)
 	* More fixes for the change on the AOL sign-on process. 
 	* Fixed bug where GAIM sometimes doesn't find a font to use.
+	* Per-conversation font and color dialogs (thanks fflewddur)
 
 version 0.9.17 (05/31/2000):
 	* Automagic feature to check for new versions has been removed
--- a/TODO	Fri Jun 02 05:33:39 2000 +0000
+++ b/TODO	Fri Jun 02 06:08:29 2000 +0000
@@ -5,4 +5,3 @@
 	Locale Support
 	Make Buddy Chat Prettier
 	Icons for buddy list (I forget what this was)
-	Make per-conversation colour dialogs
--- a/src/conversation.c	Fri Jun 02 05:33:39 2000 +0000
+++ b/src/conversation.c	Fri Jun 02 06:08:29 2000 +0000
@@ -208,6 +208,10 @@
 void delete_conversation(struct conversation *cnv)
 {
         conversations = g_list_remove(conversations, cnv);
+	if (cnv->color_dialog)
+		gtk_widget_destroy(cnv->color_dialog);
+	if (cnv->font_dialog)
+		gtk_widget_destroy(cnv->font_dialog);
         g_free(cnv);
 }
 
@@ -246,8 +250,8 @@
                 if (c->strike)
                         gtk_widget_set_sensitive(c->strike, ((font_options & OPT_FONT_STRIKE)) ? FALSE : TRUE);
 
-                if (c->font)
-                        gtk_widget_set_sensitive(c->font, ((font_options & OPT_FONT_FACE)) ? TRUE : FALSE);
+/*                if (c->font)
+                        gtk_widget_set_sensitive(c->font, ((font_options & OPT_FONT_FACE)) ? TRUE : FALSE);*/
 		
 		cnv = cnv->next;
 	}
@@ -340,7 +344,6 @@
 	delete_conversation(c);
 	return FALSE;
 }
-	
 
 static void color_callback(GtkWidget *widget, struct conversation *c)
 {
@@ -492,8 +495,9 @@
 	quiet_set(c->strike, FALSE);
 	quiet_set(c->italic, FALSE);
 	quiet_set(c->underline, FALSE);
+	quiet_set(c->font, FALSE);
 	quiet_set(c->palette, FALSE);
-        quiet_set(c->link, FALSE);
+	quiet_set(c->link, FALSE);
         
 	if (c->makesound && (sound_options & OPT_SOUND_SEND))
 		play_sound(SEND);
@@ -669,19 +673,24 @@
 	gtk_widget_grab_focus(entry);
 }
 
-static void toggle_color(GtkWidget *color, GtkWidget *entry)
+static void toggle_color(GtkWidget *color, struct conversation *c)
 {
-        if (state_lock)
+	if (state_lock)
                 return;
-        if (GTK_TOGGLE_BUTTON(color)->active)
-		show_color_dialog(entry, color);
+	if (GTK_TOGGLE_BUTTON(color)->active)
+		show_color_dialog(c, color);
 	else
-		advance_past(entry, "<FONT COLOR>", "</FONT>" );
+		advance_past(c->entry, "<FONT COLOR>", "</FONT>" );
 }
 
-static void toggle_font(GtkWidget *font, GtkWidget *entry)
+static void toggle_font(GtkWidget *font, struct conversation *c)
 {
-	show_font_dialog(entry, font);
+	if (state_lock)
+		return;
+	if (GTK_TOGGLE_BUTTON(font)->active)
+		show_font_dialog(c, font);
+	else
+		advance_past(c->entry, "<FONT FACE>", "</FONT>");
 	
 	return;
 }
@@ -780,11 +789,18 @@
 		quiet_set(c->italic, FALSE);
      
 	if (invert_tags(entry, "<FONT COLOR", "</FONT>", 0))
-                quiet_set(c->palette, TRUE);
-        else if (count_tag(entry, "<FONT COLOR", "</FONT>"))
-                quiet_set(c->palette, TRUE);
-        else
-                quiet_set(c->palette, FALSE);
+		quiet_set(c->palette, TRUE);
+ 	else if (count_tag(entry, "<FONT COLOR", "</FONT>"))
+		quiet_set(c->palette, TRUE);
+	else
+		quiet_set(c->palette, FALSE);
+	
+	if (invert_tags(entry, "<FONT FACE", "</FONT>", 0))
+		quiet_set(c->font, TRUE);
+	else if (count_tag(entry, "<FONT FACE", "</FONT>"))
+		quiet_set(c->font, TRUE);
+	else
+		quiet_set(c->font, FALSE);
 
 	if (invert_tags(entry, "<A HREF", "</A>", 0))
 		quiet_set(c->link, TRUE);
@@ -1077,8 +1093,11 @@
 	small = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Small", "Decrease font size", "Small", small_p, GTK_SIGNAL_FUNC(do_small), entry);
 	normal = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Normal", "Normal font size", "Normal", normal_p, GTK_SIGNAL_FUNC(do_normal), entry);
 	big = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Big", "Increase font size", "Big", big_p, GTK_SIGNAL_FUNC(do_big), entry);
-	font = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Font", "Select Font", "Font", font_p, GTK_SIGNAL_FUNC(toggle_font), entry);
-	gtk_object_set_user_data(GTK_OBJECT(font), c);
+	font = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
+						GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
+						NULL, "Font", "Select Font",
+						"Font", font_p, GTK_SIGNAL_FUNC(toggle_font), c);
+
 	if (!(font_options & OPT_FONT_FACE))
 		gtk_widget_set_sensitive(GTK_WIDGET(font), FALSE);
 	
@@ -1089,7 +1108,7 @@
 	palette = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
 					    GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
 					    NULL, "Color", "Text Color",
-				 	    "Color", palette_p, GTK_SIGNAL_FUNC(toggle_color), entry); 
+				 	    "Color", palette_p, GTK_SIGNAL_FUNC(toggle_color), c);
 	wood = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
 					    GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
 					    NULL, "Logging", "Enable logging",
@@ -1189,9 +1208,6 @@
 	gtk_box_pack_start(GTK_BOX(vbox2), entry, TRUE, TRUE, 5);
 	gtk_box_pack_start(GTK_BOX(vbox2), bbox, FALSE, FALSE, 5);
 
-	
-
-
 	gtk_widget_show(send);
 	gtk_widget_show(info);
 	gtk_widget_show(warn);
@@ -1203,7 +1219,9 @@
 	gtk_widget_show(vbox);
 	gtk_widget_show(entry);
 	gtk_widget_show(text);
-	
+
+	c->font_dialog = NULL;
+	c->color_dialog = NULL;	
 	
 	gtk_container_add(GTK_CONTAINER(win), paned);
         gtk_container_border_width(GTK_CONTAINER(win), 10);
--- a/src/dialogs.c	Fri Jun 02 05:33:39 2000 +0000
+++ b/src/dialogs.c	Fri Jun 02 06:08:29 2000 +0000
@@ -44,7 +44,7 @@
 
 static GtkWidget *imdialog = NULL; /*I only want ONE of these :) */
 static GList *dialogwindows = NULL;
-static GtkWidget *linkdialog, *colordialog, *exportdialog, *importdialog, *logdialog, *fontdialog;
+static GtkWidget *linkdialog, *exportdialog, *importdialog, *logdialog;
 
 static void accept_callback(GtkWidget *widget, struct file_transfer *t);
 
@@ -245,6 +245,18 @@
 /*  Destroys                                                              */
 /*------------------------------------------------------------------------*/
 
+static gint delete_event_dialog(GtkWidget *w, GdkEventAny *e, struct conversation *c)
+{
+	dialogwindows = g_list_remove(dialogwindows, w);
+	gtk_widget_destroy(w);
+	
+	if (GTK_IS_COLOR_SELECTION_DIALOG(w))
+		c->color_dialog = NULL;
+	if (GTK_IS_FONT_SELECTION_DIALOG(w))
+		c->font_dialog = NULL;
+
+	return FALSE;
+}
 
 static void destroy_dialog(GtkWidget *w, GtkWidget *w2)
 {
@@ -267,14 +279,14 @@
 	if (dest == logdialog)
 		logdialog = NULL;
 
-	if (dest == colordialog)
-		colordialog = NULL;
+/*	if (GTK_COLOR_SELECTION_DIALOG(dest))
+		color_dialog = NULL;*/
 
 	if (dest == linkdialog)
 		linkdialog = NULL;
 	
-	if (dest == fontdialog)
-		fontdialog = NULL;
+/*	if (dest == fontdialog)
+		fontdialog = NULL;*/
 
         dialogwindows = g_list_remove(dialogwindows, dest);
         gtk_widget_destroy(dest);
@@ -305,10 +317,11 @@
 		destroy_dialog(NULL, linkdialog);
 		linkdialog = NULL;
 	}
-	if (colordialog) {
+/* is this needed? */
+/*	if (colordialog) {
 		destroy_dialog(NULL, colordialog);
 		colordialog = NULL;
-	}
+	}*/
 
         if (exportdialog) {
                 destroy_dialog(NULL, exportdialog);
@@ -324,11 +337,11 @@
 		destroy_dialog(NULL, logdialog);
 		logdialog = NULL;
 	}
-
-	if (fontdialog) {
+/* is this needed? */
+/*	if (fontdialog) {
 		destroy_dialog(NULL, fontdialog);
 		fontdialog = NULL;
-	}
+	}*/
 }
 
 static void do_warn(GtkWidget *widget, struct warning *w)
@@ -1874,84 +1887,84 @@
 /* Color Selection Dialog                               */
 /*------------------------------------------------------*/
 
-void cancel_color(GtkWidget *widget, GtkWidget *color)
+void cancel_color(GtkWidget *widget, struct conversation *c)
 {
- 	if (color)
-        {
-        	set_state_lock(1);
-        	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(color), FALSE);
-        	set_state_lock(0);
+ 	if (c->palette && widget)
+	{
+		set_state_lock(1);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->palette), FALSE);
+		set_state_lock(0);
 	}
-	destroy_dialog(NULL, colordialog);
+	dialogwindows = g_list_remove(dialogwindows, c->color_dialog);
+	gtk_widget_destroy(c->color_dialog);
+	c->color_dialog = NULL;
 }
 
-
-
 void do_color(GtkWidget *widget, GtkColorSelection *colorsel)
 {
-        gdouble color[3];
+	gdouble color[3];
 	GdkColor text_color;
-	GtkWidget *entry;
+	struct conversation *c;
 	char *open_tag;
 
 	open_tag = g_malloc(30);
 
-        gtk_color_selection_get_color (colorsel, color);
+	gtk_color_selection_get_color (colorsel, color);
 
-        entry = gtk_object_get_user_data(GTK_OBJECT(colorsel));
-	
-        text_color.red = ((guint16)(color[0]*65535))>>8;
-        text_color.green = ((guint16)(color[1]*65535))>>8;
-		text_color.blue = ((guint16)(color[2]*65535))>>8;
+	c = gtk_object_get_user_data(GTK_OBJECT(colorsel));
+	GTK_IS_EDITABLE(c->entry);
+
+	text_color.red = ((guint16)(color[0]*65535))>>8;
+	text_color.green = ((guint16)(color[1]*65535))>>8;
+	text_color.blue = ((guint16)(color[2]*65535))>>8;
 	
 	g_snprintf(open_tag, 23, "<FONT COLOR=\"#%02X%02X%02X\">", text_color.red, text_color.green, text_color.blue);
-
-	surround(entry, open_tag, "</FONT>");
+	surround(c->entry, open_tag, "</FONT>");
 	sprintf(debug_buff,"#%02X%02X%02X\n", text_color.red, text_color.green, text_color.blue);
 	debug_print(debug_buff);
-        g_free(open_tag);
-	cancel_color(NULL, NULL);
+	g_free(open_tag);
+	cancel_color(NULL, c);
 }
 
 
-void show_color_dialog(GtkWidget *entry, GtkWidget *color)
+void show_color_dialog(struct conversation *c, GtkWidget *color)
 {
-        GtkWidget *colorsel;
-
-        if (!colordialog) {
-     
+	GtkWidget *colorsel;
 
-		colordialog = gtk_color_selection_dialog_new("Select Text Color");
-                colorsel = GTK_COLOR_SELECTION_DIALOG(colordialog)->colorsel;
-		
-		/* XXX: Modality is evil, but we need it until we have
-		 * per-conversation color dialogs */
-
-		gtk_window_set_modal(GTK_WINDOW(colordialog), TRUE);
+    if (!c->color_dialog)
+	{
+    	c->color_dialog = gtk_color_selection_dialog_new("Select Text Color");
+		colorsel = GTK_COLOR_SELECTION_DIALOG(c->color_dialog)->colorsel;
 
-                gtk_object_set_user_data(GTK_OBJECT(colorsel), entry);
+		gtk_object_set_user_data(GTK_OBJECT(colorsel), c);
 		
-                gtk_signal_connect(GTK_OBJECT(colordialog), "delete_event", GTK_SIGNAL_FUNC(cancel_color), color);
-
-                gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(colordialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_color), colorsel);
+		gtk_signal_connect(GTK_OBJECT(c->color_dialog), "delete_event", GTK_SIGNAL_FUNC(delete_event_dialog), c);
+		gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(c->color_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_color), colorsel);
+		gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(c->color_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_color), c);
 
-                gtk_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(colordialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_color), color);
-                gtk_widget_realize(colordialog);
-		aol_icon(colordialog->window);
+		gtk_widget_realize(c->color_dialog);
+		aol_icon(c->color_dialog->window);
+	}
 
-        }
-
-        gtk_widget_show(colordialog);
-        gdk_window_raise(colordialog->window);
+	gtk_widget_show(c->color_dialog);
+	gdk_window_raise(c->color_dialog->window);
 }
 
 /*------------------------------------------------------------------------*/
 /*  Font Selection Dialog                                                 */
 /*------------------------------------------------------------------------*/
 
-void cancel_font(GtkWidget *widget, GtkWidget *window)
+void cancel_font(GtkWidget *widget, struct conversation *c)
 {	
-	destroy_dialog(NULL, fontdialog);
+	if (c->font && widget)
+	{
+		set_state_lock(1);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->font), FALSE);
+		set_state_lock(0);
+	}
+	dialogwindows = g_list_remove(dialogwindows, c->font_dialog);
+	gtk_widget_destroy(c->font_dialog);
+	c->font_dialog = NULL;	
 }
 
 void apply_font(GtkWidget *widget, GtkFontSelection *fontsel)
@@ -2003,38 +2016,40 @@
 		save_prefs();
 	}
 	
-	cancel_font(widget, NULL);
+	cancel_font(NULL, c);
 }
 
-void show_font_dialog(GtkWidget *widget, GtkWidget *font)
+void show_font_dialog(struct conversation *c, GtkWidget *font)
 {
 	GtkWidget *fontsel;
 	
-	fontdialog = gtk_font_selection_dialog_new("Select Font");
-	fontsel = GTK_FONT_SELECTION_DIALOG(fontdialog)->fontsel;
+	if (!c->font_dialog)
+	{
+		c->font_dialog = gtk_font_selection_dialog_new("Select Font");
+		fontsel = GTK_FONT_SELECTION_DIALOG(c->font_dialog)->fontsel;
 
-	if (font)
-		gtk_object_set_user_data(GTK_OBJECT(fontsel), gtk_object_get_user_data(GTK_OBJECT(font)));
-	else
-		gtk_object_set_user_data(GTK_OBJECT(fontsel), NULL);
+		if (font)
+			gtk_object_set_user_data(GTK_OBJECT(fontsel), c);
+		else
+			gtk_object_set_user_data(GTK_OBJECT(fontsel), NULL);
 			
-	gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, DEFAULT_FONT_NAME);	
-	gtk_window_set_modal(GTK_WINDOW(fontdialog), TRUE);
-	gtk_signal_connect(GTK_OBJECT(fontdialog), "delete_event", GTK_SIGNAL_FUNC(cancel_font), font);
-	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontdialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(apply_font), fontsel);
-	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontdialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_font), font);
+		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, DEFAULT_FONT_NAME);	
+		
+		gtk_signal_connect(GTK_OBJECT(c->font_dialog), "delete_event", GTK_SIGNAL_FUNC(delete_event_dialog), c);
+		gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(apply_font), fontsel);
+		gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_font), c);
 	
-	if (fontname)
-		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, fontname);
-	else
-		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, DEFAULT_FONT_NAME);		
+		if (fontname)
+			gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, fontname);
+		else
+			gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, DEFAULT_FONT_NAME);		
 		
-	gtk_widget_realize(fontdialog);
+		gtk_widget_realize(c->font_dialog);
 	
-	aol_icon(fontdialog->window);
-		
-	gtk_widget_show(fontdialog);
-	gdk_window_raise(fontdialog->window);
+		aol_icon(c->font_dialog->window);
+	}	
+	gtk_widget_show(c->font_dialog);
+	gdk_window_raise(c->font_dialog->window);
 }
 
 /*------------------------------------------------------------------------*/
--- a/src/gaim.h	Fri Jun 02 05:33:39 2000 +0000
+++ b/src/gaim.h	Fri Jun 02 06:08:29 2000 +0000
@@ -219,12 +219,12 @@
 };
 
 struct conversation {
-        GtkWidget *window;
-        char name[80];
+	GtkWidget *window;
+	char name[80];
 	GtkWidget *text;
-        GtkWidget *entry;
+	GtkWidget *entry;
 	GtkWidget *italic;
-        GtkWidget *bold;
+	GtkWidget *bold;
 	GtkWidget *underline;
 	GtkWidget *palette;
 	GtkWidget *link;
@@ -232,6 +232,8 @@
     GtkWidget *log_button;
 	GtkWidget *strike;
 	GtkWidget *font;
+	GtkWidget *color_dialog;
+	GtkWidget *font_dialog;
 
 	char current_fontface[64];
 	char current_fontname[64];
@@ -339,7 +341,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 318 $"
+#define REVISION "gaim:$Revision: 321 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -668,14 +670,14 @@
 extern void show_register_dialog();
 extern void show_set_info();
 extern void show_set_dir();
-extern void show_color_dialog(GtkWidget *entry, GtkWidget *color);
+extern void show_color_dialog(struct conversation *c, GtkWidget *color);
 extern void create_away_mess(GtkWidget *, void *);
 extern void show_ee_dialog(int);
 extern void show_add_link(GtkWidget *, GtkWidget *);
 extern void show_change_passwd();
 
-extern void show_font_dialog(GtkWidget *widget, GtkWidget *font);
-extern void cancel_font(GtkWidget *widget, GtkWidget *font);
+extern void show_font_dialog(struct conversation *c, GtkWidget *font);
+extern void cancel_font(GtkWidget *widget, struct conversation *c);
 extern void apply_font(GtkWidget *widget, GtkFontSelection *fontsel);
 
 /* Functions in rvous.c */