X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=src%2Finput.c;h=8956c2c53438dad52dd3446d88acd3012c54a1f3;hb=8bf874cd9d56a5850bc474df37642170a4c20b28;hp=22f321cc1488a672ea66078cf56296989febd8c1;hpb=39b042ec7971c1a0ca083ac46a094e18ac24eed2;p=rodin%2Fchimara.git diff --git a/src/input.c b/src/input.c index 22f321c..8956c2c 100644 --- a/src/input.c +++ b/src/input.c @@ -1,3 +1,4 @@ +#include "charset.h" #include "input.h" /** glk_request_char_event: @@ -203,14 +204,9 @@ glk_request_line_event_uni(winid_t win, glui32 *buf, glui32 maxlen, glui32 initl gchar *utf8; if(initlen > 0) { - GError *error = NULL; - utf8 = g_ucs4_to_utf8(buf, initlen, NULL, NULL, &error); - + utf8 = convert_ucs4_to_utf8(buf, initlen); if(utf8 == NULL) - { - g_warning("Error during unicode->utf8 conversion: %s", error->message); return; - } } else utf8 = g_strdup(""); @@ -236,10 +232,20 @@ on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win) /* If this is a text grid window, and line input is active, then redirect the key press to the line input GtkEntry */ if( win->type == wintype_TextGrid && (win->input_request_type == INPUT_REQUEST_LINE || win->input_request_type == INPUT_REQUEST_LINE_UNICODE) ) { - gboolean retval = TRUE; - g_signal_emit_by_name(win->input_entry, "key-press-event", event, &retval); + if(event->keyval == GDK_Up || event->keyval == GDK_KP_Up + || event->keyval == GDK_Down || event->keyval == GDK_KP_Down + || event->keyval == GDK_Left || event->keyval == GDK_KP_Left + || event->keyval == GDK_Right || event->keyval == GDK_KP_Right + || event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab + || event->keyval == GDK_Page_Up || event->keyval == GDK_KP_Page_Up + || event->keyval == GDK_Page_Down || event->keyval == GDK_KP_Page_Down + || event->keyval == GDK_Home || event->keyval == GDK_KP_Home + || event->keyval == GDK_End || event->keyval == GDK_KP_End) + return FALSE; /* Don't redirect these keys */ gtk_widget_grab_focus(win->input_entry); gtk_editable_set_position(GTK_EDITABLE(win->input_entry), -1); + gboolean retval = TRUE; + g_signal_emit_by_name(win->input_entry, "key-press-event", event, &retval); return retval; /* Block this key event if the entry handled it */ } if(win->input_request_type != INPUT_REQUEST_CHARACTER && @@ -315,14 +321,11 @@ end_line_input_request(winid_t win, const gchar *inserted_text) /* Convert the string from UTF-8 to Latin-1 or Unicode */ if(win->input_request_type == INPUT_REQUEST_LINE) { - GError *error = NULL; - gchar *latin1; gsize bytes_written; - latin1 = g_convert_with_fallback(inserted_text, -1, "ISO-8859-1", "UTF-8", "?", NULL, &bytes_written, &error); + gchar *latin1 = convert_utf8_to_latin1(inserted_text, &bytes_written); if(latin1 == NULL) { - g_warning("Error during utf8->latin1 conversion: %s", error->message); event_throw(evtype_LineInput, win, 0, 0); return; } @@ -339,21 +342,18 @@ end_line_input_request(winid_t win, const gchar *inserted_text) } else if(win->input_request_type == INPUT_REQUEST_LINE_UNICODE) { - gunichar *unicode; glong items_written; - unicode = g_utf8_to_ucs4_fast(inserted_text, -1, &items_written); + gunichar *unicode = convert_utf8_to_ucs4(inserted_text, &items_written); if(unicode == NULL) { - g_warning("Error during utf8->unicode conversion"); event_throw(evtype_LineInput, win, 0, 0); return; } /* Place input in the echo stream */ - /* TODO: glk_put_string_stream_uni not implemented yet if(win->echo_stream != NULL) - glk_put_string_stream_uni(window->echo_stream, unicode);*/ + glk_put_string_stream_uni(win->echo_stream, unicode); /* Copy the string (but not the NULL at the end) */ int copycount = MIN(win->line_input_buffer_max_len, items_written); @@ -368,7 +368,10 @@ end_line_input_request(winid_t win, const gchar *inserted_text) } /* Internal function: Callback for signal insert-text on a text buffer window. -Runs after the default handler has already inserted the text.*/ +Runs after the default handler has already inserted the text. +FIXME: This function assumes that newline was the last character typed into the +window. That assumption is wrong if, for example, text containing a newline was +pasted into the window. */ void after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar *text, gint len, winid_t win) { @@ -386,6 +389,7 @@ after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position"); gtk_text_buffer_get_iter_at_mark(window_buffer, &start_iter, input_position); gtk_text_buffer_get_end_iter(window_buffer, &end_iter); + gtk_text_iter_backward_cursor_position(&end_iter); /* don't include \n */ inserted_text = gtk_text_buffer_get_text(window_buffer, &start_iter, &end_iter, FALSE);