X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fstrio.c;h=c3ea0c7faee01ed23975dbab7cd006c0000db6f3;hb=5f41c5c8a1280cd63101414b2131cf03384feda2;hp=d440832b69f9739c372cfc7794a66d34d87c94d2;hpb=bf5bc4b0d129685482eefea499f39f874744e2fd;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/strio.c b/libchimara/strio.c index d440832..c3ea0c7 100644 --- a/libchimara/strio.c +++ b/libchimara/strio.c @@ -220,6 +220,44 @@ write_buffer_to_stream(strid_t str, gchar *buf, glui32 len) /* Text grid/buffer windows */ case wintype_TextGrid: + { + gchar *utf8 = convert_latin1_to_utf8(buf, len); + if(utf8 != NULL) { + /* Deal with newlines */ + int i; + gchar *line = utf8; + for(i=0; iwindow, line); + flush_window_buffer(str->window); + + /* Move cursor position forward to the next line */ + gdk_threads_enter(); + GtkTextIter cursor_pos; + GtkTextView *textview = GTK_TEXT_VIEW(str->window->widget); + GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview); + GtkTextMark *cursor_mark = gtk_text_buffer_get_mark(buffer, "cursor_position"); + + gtk_text_buffer_get_iter_at_mark( buffer, &cursor_pos, cursor_mark); + gtk_text_view_forward_display_line(textview, &cursor_pos); + gtk_text_view_backward_display_line_start(textview, &cursor_pos); + gtk_text_buffer_move_mark(buffer, cursor_mark, &cursor_pos); + gdk_threads_leave(); + + line = utf8 + (i < len-1 ? (i+1):(len-1)); + } + } + + /* No more newlines left. */ + write_utf8_to_window_buffer(str->window, line); + g_free(utf8); + } + + str->write_count += len; + } + break; + case wintype_TextBuffer: { gchar *utf8 = convert_latin1_to_utf8(buf, len); @@ -676,8 +714,8 @@ glk_get_char_stream(strid_t str) * glk_get_char_stream_uni: * @str: An input stream. * - * Reads one character from the stream @str. The result will be between 0 and - * 0x7FFFFFFF. If the end of the stream has been reached, the result will be -1. + * Reads one character from the stream @str. If the end of the stream has been + * reached, the result will be -1. * * Returns: A value between 0 and 0x7FFFFFFF, or -1 on end of stream. */ @@ -1198,6 +1236,14 @@ glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len) * good for much anyhow. * * + * glk_stream_get_position() on a window stream will always return zero. + * + * + * It might make more sense to return the number of characters written to the + * window, but existing libraries do not support this and it's not really + * worth adding the feature. + * + * * Returns: position of the read/write mark in @str. */ glui32 @@ -1211,6 +1257,8 @@ glk_stream_get_position(strid_t str) return str->mark; case STREAM_TYPE_FILE: return ftell(str->file_pointer); + case STREAM_TYPE_WINDOW: + return 0; default: ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type); return 0; @@ -1242,6 +1290,9 @@ glk_stream_get_position(strid_t str) * * Again, in Latin-1 streams, characters are bytes. In Unicode streams, * characters are 32-bit words, or four bytes each. + * + * A window stream doesn't have a movable mark, so calling + * glk_stream_set_position() has no effect. */ void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode) @@ -1279,6 +1330,8 @@ glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode) WARNING("Seek failed on file stream"); break; } + case STREAM_TYPE_WINDOW: + break; /* Quietly do nothing */ default: ILLEGAL_PARAM("Seeking illegal on stream type: %u", str->type); return;