comparison src/gtkconv.c @ 12899:83de40f1c0df

[gaim-migrate @ 15252] Inspired by SF Patch #1406992 from Sadrul Fixes Bug #1406932 This removes/resets formatting as necessary when the active conversation changes. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 17 Jan 2006 01:42:46 +0000
parents e9b0c90ce58a
children 3bf3f489b64b
comparison
equal deleted inserted replaced
12898:e3b4e6787dff 12899:83de40f1c0df
1984 1984
1985 static void 1985 static void
1986 gaim_gtkconv_set_active_conversation(GaimConversation *conv) 1986 gaim_gtkconv_set_active_conversation(GaimConversation *conv)
1987 { 1987 {
1988 GaimGtkConversation *gtkconv; 1988 GaimGtkConversation *gtkconv;
1989 GaimConversation *old_conv;
1990 GtkIMHtml *entry;
1989 const char *protocol_name; 1991 const char *protocol_name;
1990 1992
1991 g_return_if_fail(conv != NULL); 1993 g_return_if_fail(conv != NULL);
1992 1994
1993 gtkconv = GAIM_GTK_CONVERSATION(conv); 1995 gtkconv = GAIM_GTK_CONVERSATION(conv);
1994 1996 old_conv = gtkconv->active_conv;
1995 if (gtkconv->active_conv == conv) 1997
1998 if (old_conv == conv)
1996 return; 1999 return;
1997 2000
1998 gaim_conversation_close_logs(gtkconv->active_conv); 2001 gaim_conversation_close_logs(old_conv);
1999
2000 gtkconv->active_conv = conv; 2002 gtkconv->active_conv = conv;
2001 2003
2002 gaim_conversation_set_logging(conv, 2004 gaim_conversation_set_logging(conv,
2003 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging))); 2005 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging)));
2004 2006
2007 entry = GTK_IMHTML(gtkconv->entry);
2005 protocol_name = gaim_account_get_protocol_name(conv->account); 2008 protocol_name = gaim_account_get_protocol_name(conv->account);
2006 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), protocol_name); 2009 gtk_imhtml_set_protocol_name(entry, protocol_name);
2007 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol_name); 2010 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol_name);
2011
2012 if (!(conv->features & GAIM_CONNECTION_HTML))
2013 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry));
2014 else if (conv->features & GAIM_CONNECTION_FORMATTING_WBFO &&
2015 !(old_conv->features & GAIM_CONNECTION_FORMATTING_WBFO))
2016 {
2017 /* The old conversation allowed formatting on parts of the
2018 * buffer, but the new one only allows it on the whole
2019 * buffer. This code saves the formatting from the current
2020 * position of the cursor, clears the formatting, then
2021 * applies the saved formatting to the entire buffer. */
2022
2023 gboolean bold;
2024 gboolean italic;
2025 gboolean underline;
2026 char *fontface = gtk_imhtml_get_current_fontface(entry);
2027 char *forecolor = gtk_imhtml_get_current_forecolor(entry);
2028 char *backcolor = gtk_imhtml_get_current_backcolor(entry);
2029 char *background = gtk_imhtml_get_current_background(entry);
2030 gint fontsize = gtk_imhtml_get_current_fontsize(entry);
2031 gboolean bold2;
2032 gboolean italic2;
2033 gboolean underline2;
2034
2035 gtk_imhtml_get_current_format(entry, &bold, &italic, &underline);
2036
2037 /* Clear existing formatting */
2038 gtk_imhtml_clear_formatting(entry);
2039
2040 /* Apply saved formatting to the whole buffer. */
2041
2042 gtk_imhtml_get_current_format(entry, &bold2, &italic2, &underline2);
2043
2044 if (bold != bold2)
2045 gtk_imhtml_toggle_bold(entry);
2046
2047 if (italic != italic2)
2048 gtk_imhtml_toggle_italic(entry);
2049
2050 if (underline != underline2)
2051 gtk_imhtml_toggle_underline(entry);
2052
2053 gtk_imhtml_toggle_fontface(entry, fontface);
2054
2055 if (!(conv->features & GAIM_CONNECTION_NO_FONTSIZE))
2056 gtk_imhtml_font_set_size(entry, fontsize);
2057
2058 gtk_imhtml_toggle_forecolor(entry, forecolor);
2059
2060 if (!(conv->features & GAIM_CONNECTION_NO_BGCOLOR))
2061 {
2062 gtk_imhtml_toggle_backcolor(entry, backcolor);
2063 gtk_imhtml_toggle_background(entry, background);
2064 }
2065
2066 g_free(fontface);
2067 g_free(forecolor);
2068 g_free(backcolor);
2069 g_free(background);
2070 }
2071 else
2072 {
2073 /* This is done in default_formatize, which is called from clear_formatting_cb,
2074 * which is (obviously) a clear_formatting signal handler. However, if we're
2075 * here, we didn't call gtk_imhtml_clear_formatting() (because we want to
2076 * preserve the formatting exactly as it is), so we have to do this now. */
2077 gtk_imhtml_set_whole_buffer_formatting_only(entry,
2078 (conv->features & GAIM_CONNECTION_FORMATTING_WBFO));
2079 }
2008 2080
2009 gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-switched", conv); 2081 gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-switched", conv);
2010 } 2082 }
2011 2083
2012 void 2084 void