annotate console/libgnt/test.c @ 14317:c8ddda5d8ec8

[gaim-migrate @ 17010] This should allow mouse-events to work for everyone. Also, you can click on any window to bring it to focus. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 24 Aug 2006 02:35:15 +0000
parents c1e3f7c75c3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gntbutton.h"
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2 #include "gnt.h"
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 #include "gntkeys.h"
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 #include "gnttree.h"
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
5 #include "gntbox.h"
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7 static gboolean
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 key_pressed(GntWidget *widget, const char *text, gpointer null)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 GntWidget *w = null;
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
11 GntWidget *box = gnt_box_new(FALSE, FALSE);
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
12 GntWidget *label = gnt_label_new("so wassup!!");
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
13
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
14 gnt_box_add_widget(GNT_BOX(box), label);
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
15 GNT_WIDGET_UNSET_FLAGS(box, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
16 gnt_box_set_title(GNT_BOX(box), "This is a test");
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
17
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
18 gnt_widget_show(box);
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
19 #if 0
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 gnt_widget_set_focus(w, TRUE);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 /* XXX: This is to just test stuff */
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 if (text[0] == 27)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 if (strcmp(text+1, GNT_KEY_LEFT) == 0 && w->priv.x)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 (w->priv.x)--;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 else if (strcmp(text+1, GNT_KEY_RIGHT) == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 (w->priv.x)++;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 else if (strcmp(text+1, GNT_KEY_UP) == 0 && w->priv.y)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 (w->priv.y)--;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 else if (strcmp(text+1, GNT_KEY_DOWN) == 0)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 (w->priv.y)++;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 gnt_widget_draw(w);
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
37 #endif
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 return FALSE;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 button1(GntWidget *widget, gpointer null)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 printf("OLAAA");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 gnt_widget_destroy(null);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49 static void
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 button2(GntWidget *widget, gpointer null)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 printf("BOOYAA");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 static gboolean
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 w_scroll(GntWidget *tree)
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 g_return_val_if_fail(GNT_IS_TREE(tree), FALSE);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 gnt_tree_scroll(GNT_TREE(tree), 1);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 /*wscrl(tree->window, 1);*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 /*box(tree->window, ACS_VLINE, ACS_HLINE);*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 /*wrefresh(tree->window);*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 /*char *s = 0;*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 /**s = 'a';*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 return TRUE;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68 int main()
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 {
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70 gnt_init();
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 GntWidget *widget = gnt_button_new("Button 1");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 GntWidget *widget2 = gnt_button_new("Button 2 has a longish text with a UTF-8 thing …");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\nSo this is, like,\nthe third line!! \\o/");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 GntWidget *vbox, *hbox, *tree;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76 WINDOW *test;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 box(stdscr, 0, 0);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79 wrefresh(stdscr);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 vbox = gnt_box_new(FALSE, FALSE);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 hbox = gnt_box_new(FALSE, TRUE);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 gnt_widget_set_name(vbox, "vbox");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 gnt_widget_set_name(hbox, "hbox");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 gnt_widget_set_name(widget, "widget");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 gnt_widget_set_name(widget2, "widget2");
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
89 gnt_box_add_widget(GNT_BOX(vbox), widget);
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
90 gnt_box_add_widget(GNT_BOX(vbox), widget2);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
92 gnt_box_add_widget(GNT_BOX(hbox), label);
13855
5b288502a382 [gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
93 /*gnt_box_add_widget(GNT_BOX(hbox), vbox);*/
5b288502a382 [gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
94
5b288502a382 [gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
95 gnt_box_add_widget(GNT_BOX(hbox), gnt_entry_new("a"));
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 tree = gnt_tree_new();
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
98 gnt_box_add_widget(GNT_BOX(hbox), tree);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100 gnt_tree_add_row_after(GNT_TREE(tree), "a", "a", NULL, NULL);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 gnt_tree_add_row_after(GNT_TREE(tree), "c", "c", NULL, NULL);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102 gnt_tree_add_row_after(GNT_TREE(tree), "d", "d", NULL, NULL);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 gnt_tree_add_row_after(GNT_TREE(tree), "e", "e", "a", NULL);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 gnt_tree_add_row_after(GNT_TREE(tree), "b", "b", "d", NULL);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
13851
41753203a94d [gaim-migrate @ 16310]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13850
diff changeset
107 gnt_box_set_title(GNT_BOX(hbox), "111111111111111111111111111111111111111111111111111111111111111This is the title …");
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 /*gnt_widget_set_take_focus(vbox, TRUE);*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 /*gnt_widget_set_take_focus(hbox, TRUE);*/
13855
5b288502a382 [gaim-migrate @ 16314]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13851
diff changeset
111 /*gnt_widget_set_position(hbox, 10, 10);*/
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113 gnt_widget_show(hbox);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114
13860
c1e3f7c75c3f [gaim-migrate @ 16321]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13855
diff changeset
115 g_signal_connect(hbox, "key_pressed", G_CALLBACK(key_pressed), tree);
13850
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 g_signal_connect(widget, "activate", G_CALLBACK(button1), hbox);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 g_signal_connect(widget2, "activate", G_CALLBACK(button2), hbox);
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119 /*g_timeout_add(1000, (GSourceFunc)w_scroll, tree);*/
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 gnt_main();
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 return 0;
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 }
0e1e59770cb0 [gaim-migrate @ 16308]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125