Mercurial > pidgin
annotate finch/libgnt/test/tv.c @ 18781:8b0663abb488
add tooltip to buddy icon in conversation too
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 02 Aug 2007 19:15:40 +0000 |
parents | f104e1d45d85 |
children | fda2d2d99850 |
rev | line source |
---|---|
15817 | 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 } | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
26 else if (strcmp(key, "\033" "e") == 0) |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
27 { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
28 if (fork() == 0) { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
29 endwin(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
30 printf("%s\n", GNT_TEXT_VIEW(view)->string->str); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
31 fflush(stdout); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
32 getch(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
33 refresh(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
34 exit(0); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
35 } |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
36 } |
15817 | 37 else if (key[0] == 27) |
38 { | |
39 if (strcmp(key, GNT_KEY_UP) == 0) | |
40 gnt_text_view_scroll(GNT_TEXT_VIEW(view), -1); | |
41 else if (strcmp(key, GNT_KEY_DOWN) == 0) | |
42 gnt_text_view_scroll(GNT_TEXT_VIEW(view), 1); | |
43 else | |
44 return FALSE; | |
45 return TRUE; | |
46 } | |
47 | |
48 return FALSE; | |
49 } | |
50 | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
51 static void |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
52 completion_cb(GntEntry *entry, const char *start, const char *end) |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
53 { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
54 if (start == entry->start) |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
55 gnt_widget_key_pressed(GNT_WIDGET(entry), ": "); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
56 } |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
57 |
15817 | 58 int main() |
59 { | |
60 GntWidget *hbox, *entry, *view; | |
61 | |
62 #ifdef STANDALONE | |
63 freopen(".error", "w", stderr); | |
64 | |
65 gnt_init(); | |
66 #endif | |
67 | |
68 hbox = gnt_box_new(FALSE, TRUE); | |
69 gnt_widget_set_name(hbox, "hbox"); | |
70 gnt_box_set_toplevel(GNT_BOX(hbox), TRUE); | |
71 gnt_box_set_fill(GNT_BOX(hbox), FALSE); | |
72 gnt_box_set_title(GNT_BOX(hbox), "Textview test"); | |
73 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
74 | |
75 entry = gnt_entry_new(NULL); | |
76 gnt_widget_set_name(entry, "entry"); | |
77 GNT_WIDGET_SET_FLAGS(entry, GNT_WIDGET_CAN_TAKE_FOCUS); | |
78 | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
79 g_signal_connect(G_OBJECT(entry), "completion", G_CALLBACK(completion_cb), NULL); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
80 |
15817 | 81 gnt_entry_set_word_suggest(GNT_ENTRY(entry), TRUE); |
82 gnt_entry_set_always_suggest(GNT_ENTRY(entry), FALSE); | |
83 gnt_entry_add_suggest(GNT_ENTRY(entry), "a"); | |
84 gnt_entry_add_suggest(GNT_ENTRY(entry), "ab"); | |
85 gnt_entry_add_suggest(GNT_ENTRY(entry), "abe"); | |
86 gnt_entry_add_suggest(GNT_ENTRY(entry), "abc"); | |
87 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcde"); | |
88 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcd"); | |
89 gnt_entry_add_suggest(GNT_ENTRY(entry), "acb"); | |
90 | |
91 view = gnt_text_view_new(); | |
92 gnt_widget_set_name(view, "view"); | |
93 | |
94 gnt_widget_set_size(view, 20, 15); | |
95 gnt_widget_set_size(entry, 20, 1); | |
96 | |
97 gnt_box_add_widget(GNT_BOX(hbox), view); | |
98 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
99 gnt_box_add_widget(GNT_BOX(hbox), gnt_button_new("OK")); | |
100 | |
101 gnt_widget_show(hbox); | |
102 | |
103 gnt_entry_set_history_length(GNT_ENTRY(entry), -1); | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
104 gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(view), entry); |
15817 | 105 g_signal_connect_after(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), view); |
106 | |
107 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "\n", GNT_TEXT_FLAG_NORMAL); | |
108 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
109 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 1st line\n", GNT_TEXT_FLAG_NORMAL); | |
110 | |
111 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
112 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 2nd line\n", GNT_TEXT_FLAG_NORMAL); | |
113 | |
114 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
115 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 3rd line\n", GNT_TEXT_FLAG_NORMAL); | |
116 | |
117 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
118 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 4th line\n", GNT_TEXT_FLAG_NORMAL); | |
119 | |
120 #ifdef STANDALONE | |
121 gnt_main(); | |
122 | |
123 gnt_quit(); | |
124 #endif | |
125 | |
126 return 0; | |
127 } | |
128 |