- /* Retrieve the text that was input */
- GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position");
- GtkTextIter start_iter;
- GtkTextIter end_iter;
- gtk_text_buffer_get_iter_at_mark(window_buffer, &start_iter, input_position);
- gtk_text_buffer_get_end_iter(window_buffer, &end_iter);
- gchar *inserted_text = gtk_text_buffer_get_text(window_buffer, &start_iter, &end_iter, FALSE);
-
- /* 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);
- g_free(inserted_text);
-
- if(latin1 == NULL)
- {
- error_dialog(NULL, error, "Error during utf8->latin1 conversion: ");
- event_throw(evtype_LineInput, win, 0, 0);
- return;
- }
-
- /* Place input in the echo stream */
- if(win->echo_stream != NULL)
- glk_put_string_stream(win->echo_stream, latin1);
-
- /* Copy the string (but not the NULL at the end) */
- int copycount = MIN(win->line_input_buffer_max_len, bytes_written - 1);
- memcpy(win->line_input_buffer, latin1, copycount);
- g_free(latin1);
- event_throw(evtype_LineInput, win, copycount, 0);
- }
- 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);
- g_free(inserted_text);
-
- if(unicode == NULL)
- {
- error_dialog(NULL, NULL, "Error during utf8->unicode conversion");
- event_throw(evtype_LineInput, win, 0, 0);
- return;
- }
-
- /* Place input in the echo stream */
- /* TODO: fixme
- if(win->echo_stream != NULL)
- glk_put_string_stream_uni(window->echo_stream, unicode);*/
-
- /* Copy the string (but not the NULL at the end) */
- int copycount = MIN(win->line_input_buffer_max_len, items_written);
- memcpy(win->line_input_buffer_unicode, unicode, copycount * sizeof(gunichar));
- g_free(unicode);
- event_throw(evtype_LineInput, win, copycount, 0);
- }
- else
- g_warning("%s: Wrong input request type.", __func__);
-
- win->input_request_type = INPUT_REQUEST_NONE;