- if(win->input_request_type == INPUT_REQUEST_LINE || win->input_request_type == INPUT_REQUEST_LINE_UNICODE)
- {
- if(win->type == wintype_TextBuffer)
- {
- /* Remove signal handlers */
- GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
- g_signal_handler_block(window_buffer, win->insert_text_handler);
-
- /* Make the window uneditable again and retrieve the text that was input */
- gchar *inserted_text;
- GtkTextIter start_iter, end_iter;
-
- gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), FALSE);
- 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);
-
- cancel_line_input_request(win, inserted_text, event);
- g_free(inserted_text);
- }
- else if(win->type == wintype_TextGrid)
- {
- GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
-
- gchar *text = g_strdup( gtk_entry_get_text( GTK_ENTRY(win->input_entry) ) );
- /* Move the focus back into the text view */
- gtk_widget_grab_focus(win->widget);
- /* Remove entry widget from text view */
- gtk_container_remove(GTK_CONTAINER(win->widget), win->input_entry);
- win->input_entry = NULL;
- /* Delete the child anchor */
- GtkTextIter start, end;
- gtk_text_buffer_get_iter_at_child_anchor(buffer, &start, win->input_anchor);
- end = start;
- gtk_text_iter_forward_char(&end); /* Point after the child anchor */
- gtk_text_buffer_delete(buffer, &start, &end);
- win->input_anchor = NULL;
-
- gchar *spaces = g_strnfill(win->input_length - g_utf8_strlen(text, -1), ' ');
- gchar *text_to_insert = g_strconcat(text, spaces, NULL);
- g_free(spaces);
- gtk_text_buffer_insert(buffer, &start, text_to_insert, -1);
- g_free(text_to_insert);
-
- g_signal_handler_block( G_OBJECT(win->widget), win->keypress_handler );
-
- cancel_line_input_request(win, text, event);
- g_free(text);
- }
+ event->type = evtype_None;
+ event->win = win;
+ event->val1 = 0;
+ event->val2 = 0;
+
+ g_signal_handler_block( G_OBJECT(win->widget), win->keypress_handler );
+
+ int chars_written = 0;
+
+ if(win->type == wintype_TextGrid) {
+ g_signal_handler_block( G_OBJECT(win->widget), win->keypress_handler );
+ chars_written = flush_text_grid(win);
+ } else if(win->type == wintype_TextBuffer) {
+ GtkTextBuffer *window_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
+ g_signal_handler_block(window_buffer, win->insert_text_handler);
+ chars_written = flush_text_buffer(win);
+ }
+
+ if(chars_written > 0) {
+ event->type = evtype_LineInput;
+ event->val1 = chars_written;