7b976d0627b563eb043bbfe99d9942261ce2b862
[rodin/chimara.git] / tests / styletest.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <assert.h>
5 #include <libchimara/glk.h>
6
7 void print_help();
8 void do_style_test();
9 void do_link_test();
10 void do_mouse_test();
11
12 winid_t mainwin;
13 winid_t statuswin;
14
15 void glk_main(void)
16 {
17         char stringbuffer[128];
18     event_t ev;
19     mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
20     if(!mainwin)
21         return;
22
23         statuswin = glk_window_open(mainwin, winmethod_Above | winmethod_Fixed, 3, wintype_TextGrid, 1);
24     
25     glk_set_window(mainwin);
26     
27     char *buffer = calloc(256, sizeof(char));
28     assert(buffer);
29     
30     glk_put_string("Welcome to the style test\n");
31         glk_put_string("int finish_text_grid_line_input(winid_t win, gboolean\n          11 static void cancel_old_input_request(winid_t win);\n         12 \n            13 /* Internal function: code common to both flavors of char ev\n                              14 void\n                                15 request_char_event_common(winid_t win, gboolean unicode)\n                            16 {\n                                   17     VALID_WINDOW(win, return);\n                                  18     g_return_if_fail(win->type != wintype_TextBuffer || win-\n                                        19 \n                                    20     cancel_old_input_request(win);\n                                          21 \n                                                22     flush_window_buffer(win);\n                                               23 \n                                            24     ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key\n                                                25 \n                                                        26     win->input_request_type = unicode? INPUT_REQUEST_CHARACT\n                                                        27     g_signal_handler_unblock( win->widget, win->char_input_k\n                                                        28 \n                                                            29     gdk_threads_enter();\n                                                                30 \n                                                            31     /*\n                                                              32     if(win->type == wintype_TextBuffer)\n                                                             33     {\n                                                                   34         GtkTextBuffer *buffer = gtk_text_view_get_buffer( GT\n                                                                        35         GtkTextIter iter;\n                                                                           36         gtk_text_buffer_get_end_iter(buffer, &iter);\n                                                                        37         gtk_text_buffer_place_cursor(buffer, &iter);\n                                                                            38         gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win\n                                                                                39         // Why doesn't this always work?? \n                                                                                  40     } */\n                   41 \n                    42     gtk_widget_grab_focus( GTK_WIDGET(win->widget) );\n    43     gdk_threads_leave();\n    44 \n                                            47 }\n                                               48 \n                                            49 /**\n                                                 50  * glk_request_char_event:\n                                                  51  * @win: A window to request char events from.\n                                                  52  *\n                                                          53  * Request input of a Latin-1 character or special key. A wi\n                                                        54  * requests for both character and line input at the same ti\n                                                        55  * requests for character input of both types (Latin-1 and U\n                                                            56  * illegal to call glk_request_char_event() if the window al\n                                                                57  * request for either character or\n");
32     glk_request_line_event(mainwin, buffer, 255, 0);
33     while(strncmp(buffer, "quit", 4)) 
34     {
35         glk_select(&ev);
36         if(ev.type == evtype_LineInput)
37         {
38                         if( !strncmp(buffer, "help", 4) ) {
39                                 print_help();
40                         }
41                         else if( !strncmp(buffer, "style", 4) ) {
42                                 do_style_test();
43                         }
44                         else if( !strncmp(buffer, "link", 4) ) {
45                                 do_link_test();
46                         }
47                         else if( !strncmp(buffer, "mouse", 4) ) {
48                                 do_mouse_test();
49                         }
50                         else {
51                                 glk_put_string("Huh?\n");
52                         }
53                 glk_request_line_event(mainwin, buffer, 255, 0);
54         }
55                 else if(ev.type == evtype_Hyperlink)
56                 {
57                         glk_cancel_line_event(mainwin, NULL);
58                         snprintf(stringbuffer, 128, "Link %d was clicked\n", ev.val1);
59                         glk_put_string(stringbuffer);
60                 glk_request_line_event(mainwin, buffer, 255, 0);
61                 }
62                 else if(ev.type == evtype_MouseInput)
63                 {
64                         glk_cancel_line_event(mainwin, NULL);
65                         snprintf(stringbuffer, 128, "Mouse click: x=%d, y=%d\n", ev.val1, ev.val2);
66                         glk_put_string(stringbuffer);
67                 glk_request_line_event(mainwin, buffer, 255, 0);
68                 }
69     }
70
71     glk_cancel_line_event(mainwin, NULL);
72     glk_window_clear(mainwin);
73     free(buffer);
74 }
75
76 void
77 do_style_test() {
78         glk_set_style(style_Normal);
79         glk_put_string("Normal\n");
80
81         glk_set_style(style_Emphasized);
82         glk_put_string("Emphasized\n");
83
84         glk_set_style(style_Preformatted);
85         glk_put_string("Preformatted\n");
86
87         glk_set_style(style_Header);
88         glk_put_string("Header\n");
89
90         glk_set_style(style_Subheader);
91         glk_put_string("Subheader\n");
92
93         glk_set_style(style_Alert);
94         glk_put_string("Alert\n");
95
96         glk_set_style(style_Note);
97         glk_put_string("Note\n");
98
99         glk_set_style(style_BlockQuote);
100         glk_put_string("BlockQuote\n");
101
102         glk_set_style(style_Input);
103         glk_put_string("Input\n");
104
105         glk_set_style(style_User1);
106         glk_put_string("User1\n");
107
108         glk_set_style(style_User2);
109         glk_put_string("User2\n");
110
111         glk_set_style(style_Normal);
112 }
113
114 void
115 do_link_test() {
116     glk_set_window(mainwin);
117         glk_set_hyperlink(1);
118         glk_put_string("This is link 1\n");
119         glk_set_hyperlink(2);
120         glk_put_string("This is link 2\n");
121         glk_set_hyperlink(0);
122
123     glk_set_window(statuswin);
124         glk_set_hyperlink(3);
125         glk_window_move_cursor(statuswin, 0, 0);
126         glk_put_string("This is link 3\n");
127         glk_set_hyperlink(4);
128         glk_window_move_cursor(statuswin, 0, 1);
129         glk_put_string("This is link 4\n");
130         glk_set_hyperlink(0);
131
132         glk_request_hyperlink_event(mainwin);
133         glk_request_hyperlink_event(statuswin);
134
135     glk_set_window(mainwin);
136 }
137
138 void
139 do_mouse_test() {
140     glk_set_window(statuswin);
141         glk_window_move_cursor(statuswin, 0, 0);
142         glk_put_string("Click me......\n");
143         glk_request_mouse_event(statuswin);
144         glk_set_window(mainwin);
145 }
146
147 void
148 print_help() {
149         glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - mouse (perform mouse test)\n - quit (quit the program)\n");
150 }