Mercurial > pidgin
changeset 7766:9d6ba1c44cb7
[gaim-migrate @ 8411]
This is cool. WYSIWYGing your default formatting.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 05 Dec 2003 17:09:18 +0000 |
parents | 9b3c8ef31105 |
children | 1f4005fcd872 |
files | src/gtkconv.c src/gtkimhtml.c |
diffstat | 2 files changed, 102 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- 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 <s> by default ... maybe I won't do + _toggle_strikethrough and not let them */ + /* g_snprintf(buf2, limit, "<STRIKE>%s</STRIKE>", 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, "<B>%s</B>", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic")) { - g_snprintf(buf2, limit, "<I>%s</I>", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline")) { - g_snprintf(buf2, limit, "<U>%s</U>", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_strikethrough")) { - g_snprintf(buf2, limit, "<STRIKE>%s</STRIKE>", buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_font") || - gtkconv->has_font) { - - g_snprintf(buf2, limit, - "<FONT FACE=\"%s\">%s</FONT>", gtkconv->fontface, buf); - strcpy(buf, buf2); - } - - if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_size")) { - g_snprintf(buf2, limit, - "<FONT SIZE=\"%d\">%s</FONT>", - 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, - "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", - 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, - "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", - 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);
--- 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);