Mercurial > pidgin.yaz
diff pidgin/gtkimhtml.c @ 25427:2cf7d6a20e68
Add a GtkIMHtml function that causes the widget to actually insert a
newline when the user presses the return key. This is used in the
saved status editor and the gtkrequest html input box.
Implementing this was kind of a pain. I think it would be better if
gtkimhtml.c didn't do anything with return and we changed gtkconv to
watch for that key press and send the message.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 28 Jan 2009 08:57:55 +0000 |
parents | 7942287364c2 |
children | 8c8948b9f602 |
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c Wed Jan 28 08:31:47 2009 +0000 +++ b/pidgin/gtkimhtml.c Wed Jan 28 08:57:55 2009 +0000 @@ -5837,3 +5837,35 @@ return link->tag; } +static gboolean return_add_newline_cb(GtkWidget *widget, gpointer data) +{ + GtkTextBuffer *buffer; + GtkTextMark *mark; + GtkTextIter iter; + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); + + /* Delete any currently selected text */ + gtk_text_buffer_delete_selection(buffer, TRUE, TRUE); + + /* Insert a newline at the current cursor position */ + mark = gtk_text_buffer_get_insert(buffer); + gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); + gtk_imhtml_insert_html_at_iter(GTK_IMHTML(widget), "\n", 0, &iter); + + /* + * If we just newlined ourselves past the end of the visible area + * then scroll down so the cursor is in view. + */ + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(widget), + gtk_text_buffer_get_insert(buffer), + 0, FALSE, 0.0, 0.0); + + return TRUE; +} + +void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml) +{ + g_signal_connect(G_OBJECT(imhtml), "message_send", + G_CALLBACK(return_add_newline_cb), NULL); +}