- Fixed a bug that made Nitfol crash since [130]
[rodin/chimara.git] / libchimara / window.c
index 53f264dc91200ebdfcce700dfdc7db822d2d3b2b..b3995f09189b8234982a3df80977ef9114f487b8 100644 (file)
@@ -35,7 +35,7 @@ window_new_common(glui32 rock)
 }
 
 static void
-window_close_common(winid_t win)
+window_close_common(winid_t win, gboolean destroy_node)
 {
        ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
@@ -45,7 +45,8 @@ window_close_common(winid_t win)
         win->disprock.ptr = NULL;
     }
 
-       g_node_destroy(win->window_node);
+       if(destroy_node)
+               g_node_destroy(win->window_node);
        win->magic = MAGIC_FREE;
        g_free(win);
 }
@@ -458,6 +459,7 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                case wintype_TextGrid:
                {
                    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_NONE );
                    gtk_text_view_set_editable( GTK_TEXT_VIEW(textview), FALSE );
@@ -479,6 +481,9 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        /* 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 );
+
+                       /* Create the styles available to the window stream */
+                       style_init_textgrid(textbuffer);
                }
                    break;
                
@@ -522,7 +527,7 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        (for line input) */
                        gtk_text_buffer_create_tag(textbuffer, "uneditable", "editable", FALSE, "editable-set", TRUE, NULL);
 
-                       /* Create the default styles available to the window stream */
+                       /* Create the styles available to the window stream */
                        style_init_textbuffer(textbuffer);
 
                        /* Mark the position where the user will input text */
@@ -656,7 +661,7 @@ free_winids_below(winid_t win)
                free_winids_below(win->window_node->children->data);
                free_winids_below(win->window_node->children->next->data);
        }
-       window_close_common(win);
+       window_close_common(win, FALSE);
 }
 
 /**
@@ -770,14 +775,14 @@ glk_window_close(winid_t win, stream_result_t *result)
                                g_node_append(new_parent_node, sibling_node);
                }
 
-               window_close_common( (winid_t) pair_node->data );
+               window_close_common( (winid_t) pair_node->data, TRUE);
        } 
        else /* it was the root window */
        {
                glk_data->root_window = NULL;
        }
 
-       window_close_common(win);
+       window_close_common(win, FALSE);
 
        /* Schedule a redraw */
        g_mutex_lock(glk_data->arrange_lock);
@@ -895,17 +900,26 @@ glk_window_clear(winid_t win)
 
 /**
  * glk_set_window:
- * @win: A window.
+ * @win: A window, or %NULL.
  *
  * Sets the current stream to @win's window stream. It is exactly equivalent to
  * |[ #glk_stream_set_current(#glk_window_get_stream(@win)) ]| 
  * See <link linkend="chimara-Streams">Streams</link>.
+ *
+ * <note><title>Chimara</title>
+ * <para>
+ *   Although this is not mentioned in the specification, @win may also be 
+ *   %NULL, in which case the current stream is also set to %NULL.
+ * </para></note>
  */
 void
 glk_set_window(winid_t win)
 {
-       VALID_WINDOW(win, return);
-       glk_stream_set_current( glk_window_get_stream(win) );
+       VALID_WINDOW_OR_NULL(win, return);
+       if(win)
+               glk_stream_set_current( glk_window_get_stream(win) );
+       else
+               glk_stream_set_current(NULL);
 }
 
 /**