1 #include "gntbutton.h"
2 #include "gnt.h"
3 #include "gntkeys.h"
4 #include "gnttree.h"
5 #include "gntbox.h"
6
7 static gboolean
key_pressed(GntWidget * widget,const char * text,gpointer null)8 key_pressed(GntWidget *widget, const char *text, gpointer null)
9 {
10 GntWidget *w = null;
11 GntWidget *box = gnt_box_new(FALSE, FALSE);
12 GntWidget *label = gnt_label_new("so wassup!!");
13
14 gnt_box_add_widget(GNT_BOX(box), label);
15 gnt_widget_set_has_border(box, TRUE);
16 gnt_widget_set_has_shadow(box, TRUE);
17 gnt_box_set_title(GNT_BOX(box), "This is a test");
18
19 gnt_widget_show(box);
20 #if 0
21
22 gnt_widget_set_focus(w, TRUE);
23
24 /* XXX: This is to just test stuff */
25 if (text[0] == 27)
26 {
27 if (strcmp(text+1, GNT_KEY_LEFT) == 0 && w->priv.x)
28 (w->priv.x)--;
29 else if (strcmp(text+1, GNT_KEY_RIGHT) == 0)
30 (w->priv.x)++;
31 else if (strcmp(text+1, GNT_KEY_UP) == 0 && w->priv.y)
32 (w->priv.y)--;
33 else if (strcmp(text+1, GNT_KEY_DOWN) == 0)
34 (w->priv.y)++;
35 }
36
37 gnt_widget_draw(w);
38 #endif
39
40 return FALSE;
41 }
42
43 static void
button1(GntWidget * widget,gpointer null)44 button1(GntWidget *widget, gpointer null)
45 {
46 printf("OLAAA");
47 gnt_widget_destroy(null);
48 }
49
50 static void
button2(GntWidget * widget,gpointer null)51 button2(GntWidget *widget, gpointer null)
52 {
53 printf("BOOYAA");
54 }
55
56 static gboolean
w_scroll(GntWidget * tree)57 w_scroll(GntWidget *tree)
58 {
59 g_return_val_if_fail(GNT_IS_TREE(tree), FALSE);
60 gnt_tree_scroll(GNT_TREE(tree), 1);
61 /*wscrl(tree->window, 1);*/
62 /*box(tree->window, ACS_VLINE, ACS_HLINE);*/
63 /*wrefresh(tree->window);*/
64 /*char *s = 0;*/
65 /**s = 'a';*/
66 return TRUE;
67 }
68
main()69 int main()
70 {
71 gnt_init();
72
73 GntWidget *widget = gnt_button_new("Button 1");
74 GntWidget *widget2 = gnt_button_new("Button 2 has a longish text with a UTF-8 thing …");
75 GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\nSo this is, like,\nthe third line!! \\o/");
76 GntWidget *vbox, *hbox, *tree;
77 WINDOW *test;
78
79 box(stdscr, 0, 0);
80 wrefresh(stdscr);
81
82 vbox = gnt_box_new(FALSE, FALSE);
83 hbox = gnt_box_new(FALSE, TRUE);
84
85 gnt_widget_set_name(vbox, "vbox");
86 gnt_widget_set_name(hbox, "hbox");
87 gnt_widget_set_name(widget, "widget");
88 gnt_widget_set_name(widget2, "widget2");
89
90 gnt_box_add_widget(GNT_BOX(vbox), widget);
91 gnt_box_add_widget(GNT_BOX(vbox), widget2);
92
93 gnt_box_add_widget(GNT_BOX(hbox), label);
94 /*gnt_box_add_widget(GNT_BOX(hbox), vbox);*/
95
96 gnt_box_add_widget(GNT_BOX(hbox), gnt_entry_new("a"));
97
98 tree = gnt_tree_new();
99 gnt_box_add_widget(GNT_BOX(hbox), tree);
100
101 gnt_tree_add_row_after(GNT_TREE(tree), "a", "a", NULL, NULL);
102 gnt_tree_add_row_after(GNT_TREE(tree), "c", "c", NULL, NULL);
103 gnt_tree_add_row_after(GNT_TREE(tree), "d", "d", NULL, NULL);
104 gnt_tree_add_row_after(GNT_TREE(tree), "e", "e", "a", NULL);
105 gnt_tree_add_row_after(GNT_TREE(tree), "b", "b", "d", NULL);
106
107 gnt_widget_set_has_border(hbox, TRUE);
108 gnt_widget_set_has_shadow(hbox, TRUE);
109 gnt_box_set_title(GNT_BOX(hbox), "111111111111111111111111111111111111111111111111111111111111111This is the title …");
110
111 /*gnt_widget_set_take_focus(vbox, TRUE);*/
112 /*gnt_widget_set_take_focus(hbox, TRUE);*/
113 /*gnt_widget_set_position(hbox, 10, 10);*/
114
115 gnt_widget_show(hbox);
116
117 g_signal_connect(hbox, "key_pressed", G_CALLBACK(key_pressed), tree);
118 g_signal_connect(widget, "activate", G_CALLBACK(button1), hbox);
119 g_signal_connect(widget2, "activate", G_CALLBACK(button2), hbox);
120
121 /*g_timeout_add(1000, (GSourceFunc)w_scroll, tree);*/
122
123 gnt_main();
124
125 return 0;
126 }
127
128