- /* Move the input_position mark to the end of the window_buffer */
- GtkTextMark *input_position = gtk_text_buffer_get_mark(window_buffer, "input_position");
- GtkTextIter end_iter;
- gtk_text_buffer_get_end_iter(window_buffer, &end_iter);
- gtk_text_buffer_move_mark(window_buffer, input_position, &end_iter);
-
- /* Set the entire contents of the window_buffer as uneditable
- * (so input can only be entered at the end) */
- GtkTextIter start_iter;
- gtk_text_buffer_get_start_iter(window_buffer, &start_iter);
- gtk_text_buffer_remove_tag_by_name(window_buffer, "uneditable", &start_iter, &end_iter);
- gtk_text_buffer_apply_tag_by_name(window_buffer, "uneditable", &start_iter, &end_iter);
-
- /* Insert pre-entered text if needed */
- if(insert)
- gtk_text_buffer_insert(window_buffer, &end_iter, inserttext, -1);
+ GtkTextMark *cursor = gtk_text_buffer_get_mark(buffer, "cursor_position");
+ GtkTextIter start_iter, end_iter;
+ gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, cursor);
+
+ /* Determine the maximum length of the line input */
+ gint cursorpos = gtk_text_iter_get_line_offset(&start_iter);
+ /* Odd; the Glk spec says the maximum input length is
+ windowwidth - 1 - cursorposition. I say no, because if cursorposition is
+ zero, then the input should fill the whole line. FIXME??? */
+ win->input_length = MIN(win->width - cursorpos, win->line_input_buffer_max_len);
+ end_iter = start_iter;
+ gtk_text_iter_set_line_offset(&end_iter, cursorpos + win->input_length);
+
+ /* Erase the text currently in the input field and replace it with a GtkEntry */
+ gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
+ win->input_anchor = gtk_text_buffer_create_child_anchor(buffer, &start_iter);
+ win->input_entry = gtk_entry_new();
+ /* Set the entry's font to match that of the window */
+ GtkRcStyle *style = gtk_widget_get_modifier_style(win->widget); /* Don't free */
+ gtk_widget_modify_font(win->input_entry, style->font_desc);
+ /* Make the entry as small as possible to fit with the text */
+ gtk_entry_set_has_frame(GTK_ENTRY(win->input_entry), FALSE);
+ GtkBorder border = { 0, 0, 0, 0 };
+ gtk_entry_set_inner_border(GTK_ENTRY(win->input_entry), &border);
+ gtk_entry_set_max_length(GTK_ENTRY(win->input_entry), win->input_length);
+ gtk_entry_set_width_chars(GTK_ENTRY(win->input_entry), win->input_length);
+
+ /* Insert pre-entered text if needed */
+ if(insert)
+ gtk_entry_set_text(GTK_ENTRY(win->input_entry), inserttext);
+
+ /* Set background color of entry (TODO: implement as property) */
+ GdkColor background;
+ gdk_color_parse("grey", &background);
+ gtk_widget_modify_base(win->input_entry, GTK_STATE_NORMAL, &background);
+
+ g_signal_connect(win->input_entry, "activate", G_CALLBACK(on_input_entry_activate), win);
+
+ gtk_widget_show(win->input_entry);
+ gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(win->widget), win->input_entry, win->input_anchor);