/* 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; i<len; i++) {
+ if(utf8[i] == '\n') {
+ utf8[i] = '\0';
+ write_utf8_to_window_buffer(str->window, 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);
* 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.
*/
* good for much anyhow.
* </para></note>
*
+ * glk_stream_get_position() on a window stream will always return zero.
+ *
+ * <note><para>
+ * 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.
+ * </para></note>
+ *
* Returns: position of the read/write mark in @str.
*/
glui32
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;
*
* 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)
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;