# HG changeset patch # User Sean Egan # Date 1070644158 0 # Node ID 9d6ba1c44cb7af8c3b2b93cd23b8a414b706960d # Parent 9b3c8ef311058c696db740f3906f524293045da2 [gaim-migrate @ 8411] This is cool. WYSIWYGing your default formatting. committer: Tailor Script diff -r 9b3c8ef31105 -r 9d6ba1c44cb7 src/gtkconv.c --- a/src/gtkconv.c Fri Dec 05 17:07:47 2003 +0000 +++ b/src/gtkconv.c Fri Dec 05 17:09:18 2003 +0000 @@ -367,6 +367,70 @@ return FALSE; } +static void default_formatize(GaimConversation *conv) { + GaimGtkConversation *c = GAIM_GTK_CONVERSATION(conv); + GaimConnection *gc = gaim_conversation_get_gc(conv); + + if (gc && gc->flags & GAIM_CONNECTION_HTML) { + if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_bold")) { + gtk_imhtml_toggle_bold(GTK_IMHTML(c->entry)); + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic")) { + gtk_imhtml_toggle_italic(GTK_IMHTML(c->entry)); + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline")) { + gtk_imhtml_toggle_underline(GTK_IMHTML(c->entry)); + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_strikethrough")) { + /* Tell me noone uses by default ... maybe I won't do + _toggle_strikethrough and not let them */ + /* g_snprintf(buf2, limit, "%s", buf); + strcpy(buf, buf2); */ + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_font") || c->has_font) { + gtk_imhtml_toggle_fontface(GTK_IMHTML(c->entry), c->fontface); + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_size")) { + int i = 3; + if (gaim_prefs_get_int("/gaim/gtk/conversations/font_size") < 3) { + while (gaim_prefs_get_int("/gaim/gtk/conversations/font_size") < i) { + gtk_imhtml_font_shrink(GTK_IMHTML(c->entry)); + i--; + } + } + + while (gaim_prefs_get_int("/gaim/gtk/conversations/font_size") > i) { + gtk_imhtml_font_grow(GTK_IMHTML(c->entry)); + i++; + } + + } + + if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_fgcolor")) { + char *color = g_strdup_printf("#%02x%02x%02x", + c->fg_color.red / 256, + c->fg_color.green / 256, + c->fg_color.blue / 256); + gtk_imhtml_toggle_forecolor(GTK_IMHTML(c->entry), color); + g_free(color); + } + + if (!(gc->flags & GAIM_CONNECTION_NO_BGCOLOR) && gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_bgcolor")) { + char *color = g_strdup_printf("#%02x%02x%02x", + c->bg_color.red / 256, + c->bg_color.green / 256, + c->bg_color.blue / 256); + gtk_imhtml_toggle_backcolor(GTK_IMHTML(c->entry), color); + g_free(color); + } + } +} + static void send_cb(GtkWidget *widget, GaimConversation *conv) { @@ -408,66 +472,6 @@ return; } - buf2 = g_malloc(limit); - - if (gc && gc->flags & GAIM_CONNECTION_HTML) { - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_bold")) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic")) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline")) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_strikethrough")) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_font") || - gtkconv->has_font) { - - g_snprintf(buf2, limit, - "%s", gtkconv->fontface, buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_size")) { - g_snprintf(buf2, limit, - "%s", - gaim_prefs_get_int("/gaim/gtk/conversations/font_size"), - buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_fgcolor")) { - g_snprintf(buf2, limit, - "%s", - gtkconv->fg_color.red / 256, - gtkconv->fg_color.green / 256, - gtkconv->fg_color.blue / 256, buf); - strcpy(buf, buf2); - } - - if (!(gc->flags & GAIM_CONNECTION_NO_BGCOLOR) && gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_bgcolor")) { - g_snprintf(buf2, limit, - "%s", - gtkconv->bg_color.red / 256, - gtkconv->bg_color.green / 256, - gtkconv->bg_color.blue / 256, buf); - strcpy(buf, buf2); - } - } - - g_free(buf2); - if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conv_im_send(GAIM_CONV_IM(conv), buf); else @@ -479,6 +483,7 @@ g_free(buf); gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); + default_formatize(conv); } static void @@ -3566,6 +3571,7 @@ g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); gtk_imhtml_set_editable(GTK_IMHTML(gtkconv->entry), TRUE); gaim_setup_imhtml(gtkconv->entry); + default_formatize(conv); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD_CHAR); gtk_widget_set_size_request(gtkconv->entry, -1, @@ -3665,6 +3671,7 @@ gtkconv->entry = gtk_imhtml_new(NULL, NULL); gtk_imhtml_set_editable(GTK_IMHTML(gtkconv->entry), TRUE); gaim_setup_imhtml(gtkconv->entry); + default_formatize(conv); gtkconv->entry_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD_CHAR); diff -r 9b3c8ef31105 -r 9d6ba1c44cb7 src/gtkimhtml.c --- a/src/gtkimhtml.c Fri Dec 05 17:07:47 2003 +0000 +++ b/src/gtkimhtml.c Fri Dec 05 17:09:18 2003 +0000 @@ -372,6 +372,7 @@ /* Mozilla asks that we start our text/html with the Unicode byte order mark */ str = g_string_append_unichar(str, 0xfeff); str = g_string_append(str, text); + str = g_string_append_unichar(str, 0x0000); char *selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); g_string_free(str, TRUE); @@ -408,6 +409,39 @@ g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); } +static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, GtkIMHtml *imhtml) +{ + char *text; + guint16 c; + if (selection_data->length < 0) { + text = gtk_clipboard_wait_for_text(clipboard); + printf("%s\n", text); + } else { + text = g_malloc((selection_data->format / 8) * selection_data->length); + memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); + printf("%s\n", text); + } + + memcpy (&c, text, 2); + if (c == 0xfeff) { + /* This is UCS2 */ + char *utf8 = g_convert(text, selection_data->length * (selection_data->format / 8), "UTF-8", "UCS-2", NULL, NULL, NULL); + g_free(text); + text = utf8; + } + gtk_imhtml_append_text_with_images(imhtml, text, 0, NULL); +} + + +static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) +{ + + GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); + gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), + paste_received_cb, imhtml); + g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); +} + static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) { GtkClipboard *clipboard; @@ -519,6 +553,7 @@ g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); #if GTK_CHECK_VERSION(2,2,0) g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); + g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); #endif gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK);