Mercurial > pidgin
changeset 25936: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 | 17168b8379f2 |
files | ChangeLog.API pidgin/gtkimhtml.c pidgin/gtkimhtml.h pidgin/gtkrequest.c pidgin/gtksavedstatuses.c |
diffstat | 5 files changed, 48 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog.API Wed Jan 28 08:31:47 2009 +0000 +++ b/ChangeLog.API Wed Jan 28 08:57:55 2009 +0000 @@ -47,6 +47,7 @@ * gtk_imhtml_link_get_url, gtk_imhtml_link_get_text_tag, gtk_imhtml_link_activate functions to process GtkIMHtmlLink objects from GtkIMHtml protocol callbacks. + * gtk_imhtml_set_return_inserts_newline * pidgin_blist_set_theme * pidgin_blist_get_theme * pidgin_sound_is_customized
--- 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); +}
--- a/pidgin/gtkimhtml.h Wed Jan 28 08:31:47 2009 +0000 +++ b/pidgin/gtkimhtml.h Wed Jan 28 08:57:55 2009 +0000 @@ -948,6 +948,17 @@ */ gboolean gtk_imhtml_link_activate(GtkIMHtmlLink *link); +/** + * By default this widget intercepts presses of the "return" key and + * emits the "message_send" signal instead. If you don't want this + * behavior, and you want the standard GtkTextView behavior of + * inserting a newline into the buffer, then call this function. + * + * @param imhtml The GtkIMHtml where you want the "return" key to add + * newline and not emit the "message_send" signal. + */ +void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml); + /*@}*/ #ifdef __cplusplus
--- a/pidgin/gtkrequest.c Wed Jan 28 08:31:47 2009 +0000 +++ b/pidgin/gtkrequest.c Wed Jan 28 08:57:55 2009 +0000 @@ -384,6 +384,8 @@ gtk_imhtml_append_text(GTK_IMHTML(entry), default_value, GTK_IMHTML_NO_SCROLL); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); + + gtk_imhtml_set_return_inserts_newline(GTK_IMHTML(entry)); } else { if (multiline) {
--- a/pidgin/gtksavedstatuses.c Wed Jan 28 08:31:47 2009 +0000 +++ b/pidgin/gtksavedstatuses.c Wed Jan 28 08:57:55 2009 +0000 @@ -1218,6 +1218,8 @@ gtk_container_set_focus_chain(GTK_CONTAINER(hbox), focus_chain); g_list_free(focus_chain); + gtk_imhtml_set_return_inserts_newline(dialog->message); + if ((saved_status != NULL) && (purple_savedstatus_get_message(saved_status) != NULL)) gtk_imhtml_append_text(GTK_IMHTML(text), purple_savedstatus_get_message(saved_status), 0);