Mercurial > pidgin.yaz
comparison finch/libgnt/test/tv.c @ 15818:0e3a8505ebbe
renamed gaim-text to finch
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 18 Mar 2007 19:38:15 +0000 |
parents | |
children | f104e1d45d85 |
comparison
equal
deleted
inserted
replaced
15817:317e7613e581 | 15818:0e3a8505ebbe |
---|---|
1 #include "gntbutton.h" | |
2 #include "gnt.h" | |
3 #include "gntkeys.h" | |
4 #include "gnttree.h" | |
5 #include "gntbox.h" | |
6 #include "gntentry.h" | |
7 #include "gnttextview.h" | |
8 | |
9 static gboolean | |
10 key_pressed(GntWidget *w, const char *key, GntWidget *view) | |
11 { | |
12 if (key[0] == '\r' && key[1] == 0) | |
13 { | |
14 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), | |
15 gnt_entry_get_text(GNT_ENTRY(w)), | |
16 GNT_TEXT_FLAG_UNDERLINE | GNT_TEXT_FLAG_HIGHLIGHT); | |
17 gnt_entry_add_to_history(GNT_ENTRY(w), gnt_entry_get_text(GNT_ENTRY(w))); | |
18 gnt_text_view_next_line(GNT_TEXT_VIEW(view)); | |
19 gnt_entry_clear(GNT_ENTRY(w)); | |
20 if (gnt_text_view_get_lines_below(GNT_TEXT_VIEW(view)) <= 1) | |
21 gnt_text_view_scroll(GNT_TEXT_VIEW(view), 0); | |
22 gnt_entry_remove_suggest(GNT_ENTRY(w), "acb"); | |
23 | |
24 return TRUE; | |
25 } | |
26 else if (key[0] == 27) | |
27 { | |
28 if (strcmp(key, GNT_KEY_UP) == 0) | |
29 gnt_text_view_scroll(GNT_TEXT_VIEW(view), -1); | |
30 else if (strcmp(key, GNT_KEY_DOWN) == 0) | |
31 gnt_text_view_scroll(GNT_TEXT_VIEW(view), 1); | |
32 else | |
33 return FALSE; | |
34 return TRUE; | |
35 } | |
36 | |
37 return FALSE; | |
38 } | |
39 | |
40 int main() | |
41 { | |
42 GntWidget *hbox, *entry, *view; | |
43 | |
44 #ifdef STANDALONE | |
45 freopen(".error", "w", stderr); | |
46 | |
47 gnt_init(); | |
48 #endif | |
49 | |
50 hbox = gnt_box_new(FALSE, TRUE); | |
51 gnt_widget_set_name(hbox, "hbox"); | |
52 gnt_box_set_toplevel(GNT_BOX(hbox), TRUE); | |
53 gnt_box_set_fill(GNT_BOX(hbox), FALSE); | |
54 gnt_box_set_title(GNT_BOX(hbox), "Textview test"); | |
55 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
56 | |
57 entry = gnt_entry_new(NULL); | |
58 gnt_widget_set_name(entry, "entry"); | |
59 GNT_WIDGET_SET_FLAGS(entry, GNT_WIDGET_CAN_TAKE_FOCUS); | |
60 | |
61 gnt_entry_set_word_suggest(GNT_ENTRY(entry), TRUE); | |
62 gnt_entry_set_always_suggest(GNT_ENTRY(entry), FALSE); | |
63 gnt_entry_add_suggest(GNT_ENTRY(entry), "a"); | |
64 gnt_entry_add_suggest(GNT_ENTRY(entry), "ab"); | |
65 gnt_entry_add_suggest(GNT_ENTRY(entry), "abe"); | |
66 gnt_entry_add_suggest(GNT_ENTRY(entry), "abc"); | |
67 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcde"); | |
68 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcd"); | |
69 gnt_entry_add_suggest(GNT_ENTRY(entry), "acb"); | |
70 | |
71 view = gnt_text_view_new(); | |
72 gnt_widget_set_name(view, "view"); | |
73 | |
74 gnt_widget_set_size(view, 20, 15); | |
75 gnt_widget_set_size(entry, 20, 1); | |
76 | |
77 gnt_box_add_widget(GNT_BOX(hbox), view); | |
78 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
79 gnt_box_add_widget(GNT_BOX(hbox), gnt_button_new("OK")); | |
80 | |
81 gnt_widget_show(hbox); | |
82 | |
83 gnt_entry_set_history_length(GNT_ENTRY(entry), -1); | |
84 g_signal_connect_after(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), view); | |
85 | |
86 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "\n", GNT_TEXT_FLAG_NORMAL); | |
87 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
88 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 1st line\n", GNT_TEXT_FLAG_NORMAL); | |
89 | |
90 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
91 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 2nd line\n", GNT_TEXT_FLAG_NORMAL); | |
92 | |
93 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
94 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 3rd line\n", GNT_TEXT_FLAG_NORMAL); | |
95 | |
96 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
97 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 4th line\n", GNT_TEXT_FLAG_NORMAL); | |
98 | |
99 #ifdef STANDALONE | |
100 gnt_main(); | |
101 | |
102 gnt_quit(); | |
103 #endif | |
104 | |
105 return 0; | |
106 } | |
107 |