+
+ gdk_threads_enter();
+
+ /* We only create one window and don't support any more than that */
+ winid_t win = g_new0(struct glk_window_struct, 1);
+ win->rock = rock;
+ win->type = wintype;
+ win->window_node = g_node_new(win);
+
+ switch(wintype)
+ {
+ case wintype_Blank:
+ {
+ /* A blank window will be a label without any text */
+ GtkWidget *label = gtk_label_new("");
+ gtk_widget_show(label);
+
+ win->widget = label;
+ win->frame = label;
+ /* A blank window has no size */
+ win->unit_width = 0;
+ win->unit_height = 0;
+ /* You can print to a blank window's stream, but it does nothing */
+ win->window_stream = window_stream_new(win);
+ win->echo_stream = NULL;
+ }
+ break;
+
+ case wintype_TextGrid:
+ {
+ GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
+ GtkWidget *textview = gtk_text_view_new();
+ GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(textview) );
+
+ gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_NEVER );
+
+ gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR );
+ gtk_text_view_set_editable( GTK_TEXT_VIEW(textview), FALSE );
+
+ gtk_container_add( GTK_CONTAINER(scrolledwindow), textview );
+ gtk_widget_show_all(scrolledwindow);
+
+ /* Set the window's font */
+ /* TODO: Use Pango to pick out a monospace font on the system */
+ PangoFontDescription *font = pango_font_description_from_string("Monospace");
+ gtk_widget_modify_font(textview, font);
+ pango_font_description_free(font);
+
+ win->widget = textview;
+ win->frame = scrolledwindow;
+ text_window_get_char_size( textview, &(win->unit_width), &(win->unit_height) );
+
+ /* Set the other parameters */
+ win->window_stream = window_stream_new(win);
+ win->echo_stream = NULL;
+ win->input_request_type = INPUT_REQUEST_NONE;
+ win->line_input_buffer = NULL;
+ win->line_input_buffer_unicode = NULL;
+
+ /* Connect signal handlers */
+ win->keypress_handler = g_signal_connect( G_OBJECT(textview), "key-press-event", G_CALLBACK(on_window_key_press_event), win );
+ g_signal_handler_block( G_OBJECT(textview), win->keypress_handler );
+
+ win->insert_text_handler = g_signal_connect( G_OBJECT(textview), "key-press-event", G_CALLBACK(on_text_grid_key_press_event), win );
+ g_signal_handler_block( G_OBJECT(textview), win->insert_text_handler );
+
+ /* Create a tag to indicate an editable field in the window (for line input) */
+ gtk_text_buffer_create_tag(textbuffer, "input_field",
+ "background", "grey", "background-set", TRUE,
+ "editable", TRUE, "editable-set", TRUE,
+ NULL);
+ }
+ break;
+
+ case wintype_TextBuffer:
+ {
+ GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
+ GtkWidget *textview = gtk_text_view_new();
+ GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(textview) );
+
+ gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(textview), GTK_WRAP_WORD_CHAR );
+ gtk_text_view_set_editable( GTK_TEXT_VIEW(textview), FALSE );
+
+ gtk_container_add( GTK_CONTAINER(scrolledwindow), textview );
+ gtk_widget_show_all(scrolledwindow);
+
+ win->widget = textview;
+ win->frame = scrolledwindow;
+ text_window_get_char_size( textview, &(win->unit_width), &(win->unit_height) );
+
+ /* Set the other parameters */
+ win->window_stream = window_stream_new(win);
+ win->echo_stream = NULL;
+ win->input_request_type = INPUT_REQUEST_NONE;
+ win->line_input_buffer = NULL;
+ win->line_input_buffer_unicode = NULL;