Commentaar toegevoegd aan code en tevens Gtk-Doc comments voor alle
[projects/chimara/chimara.git] / src / window.c
1 #include "window.h"
2
3 /* Global tree of all windows */
4 static GNode *root_window = NULL;
5
6 /**
7  * glk_window_open:
8  * @split: The window to split to create the new window. Must be 0 if there
9  * are no windows yet.
10  * @method: Position of the new window and method of size computation. One of
11  * #winmethod_Above, #winmethod_Below, #winmethod_Left, or #winmethod_Right
12  * OR'ed with #winmethod_Fixed or #winmethod_Proportional. If @wintype is
13  * #wintype_Blank, then #winmethod_Fixed is not allowed.
14  * @size: Size of the new window, in percentage points if @method is
15  * #winmethod_Proportional, otherwise in characters if @wintype is 
16  * #wintype_TextBuffer or #wintype_TextGrid, or pixels if @wintype is
17  * #wintype_Graphics.
18  * @wintype: Type of the new window. One of #wintype_Blank, #wintype_TextGrid,
19  * #wintype_TextBuffer, or #wintype_Graphics.
20  * @rock: The new window's rock value.
21  *
22  * If there are no windows, create a new root window. @split must be 0, and
23  * @method and @size are ignored. Otherwise, split window @split into two, with
24  * position, size, and type specified by @method, @size, and @wintype. See the
25  * Glk documentation for the window placement algorithm.
26  *
27  * Returns: the new window.
28  */
29 winid_t
30 glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, 
31                 glui32 rock)
32 {
33         extern GtkBuilder *builder;
34
35         if(split)
36         {
37                 g_warning("glk_window_open: splitting of windows not implemented");
38                 return NULL;
39         }
40
41         if(root_window != NULL)
42         {
43                 g_warning("glk_window_open: there is already a window");
44                 return NULL;
45         }
46         /* We only create one window and don't support any more than that */
47         winid_t new_window = g_new0(struct glk_window_struct, 1);
48         root_window = g_node_new(new_window);
49
50         new_window->rock = rock;
51         new_window->window_type = wintype;
52
53         GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") );                      
54         if(vbox == NULL)
55         {
56                 error_dialog(NULL, NULL, "Could not find vbox");
57                 return NULL;
58         }
59
60         switch(wintype)
61         {
62                 case wintype_TextBuffer:
63                 {
64                         /* We need to put these declarations inside their own scope */
65                         GtkWidget *scroll_window = gtk_scrolled_window_new(NULL, NULL);
66                         GtkWidget *window = gtk_text_view_new();
67                         gtk_container_add( GTK_CONTAINER(scroll_window), window );
68                         gtk_box_pack_end(vbox, scroll_window, TRUE, TRUE, 0);
69                         gtk_widget_show_all(scroll_window);
70
71                         new_window->widget = window;
72                         new_window->window_stream = window_stream_new(new_window);
73                         new_window->echo_stream = NULL;
74                         new_window->input_request_type = INPUT_REQUEST_NONE;
75                         new_window->line_input_buffer = NULL;
76                         new_window->line_input_buffer_unicode = NULL;
77                 }
78                         break;
79                 default:
80                         g_warning("glk_window_open: unsupported window type");
81                         g_free(new_window);
82                         return NULL;
83         }
84
85         new_window->window_node = root_window;
86
87         return new_window;
88 }
89
90 /**
91  * glk_set_window:
92  * @win: A window.
93  *
94  * Sets the current stream to @win's window stream.
95  */
96 void
97 glk_set_window(winid_t win)
98 {
99         glk_stream_set_current( glk_window_get_stream(win) );
100 }
101
102 /**
103  * glk_window_get_stream:
104  * @win: A window.
105  *
106  * Gets the stream associated with @win.
107  *
108  * Returns: The window stream.
109  */
110 strid_t glk_window_get_stream(winid_t win)
111 {
112         return win->window_stream;
113 }
114