Mercurial > pidgin
annotate finch/libgnt/test/tv.c @ 24425:f3c48d7db093
Fix CID #367
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 14 Nov 2008 06:44:44 +0000 |
parents | 5a0c058c10e6 |
children | a8cc50c2279f |
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" | |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18510
diff
changeset
|
8 #include "gntutils.h" |
15817 | 9 |
10 static gboolean | |
11 key_pressed(GntWidget *w, const char *key, GntWidget *view) | |
12 { | |
13 if (key[0] == '\r' && key[1] == 0) | |
14 { | |
15 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), | |
16 gnt_entry_get_text(GNT_ENTRY(w)), | |
17 GNT_TEXT_FLAG_UNDERLINE | GNT_TEXT_FLAG_HIGHLIGHT); | |
18 gnt_entry_add_to_history(GNT_ENTRY(w), gnt_entry_get_text(GNT_ENTRY(w))); | |
19 gnt_text_view_next_line(GNT_TEXT_VIEW(view)); | |
20 gnt_entry_clear(GNT_ENTRY(w)); | |
21 if (gnt_text_view_get_lines_below(GNT_TEXT_VIEW(view)) <= 1) | |
22 gnt_text_view_scroll(GNT_TEXT_VIEW(view), 0); | |
23 gnt_entry_remove_suggest(GNT_ENTRY(w), "acb"); | |
24 | |
25 return TRUE; | |
26 } | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
27 else if (strcmp(key, "\033" "e") == 0) |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
28 { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
29 if (fork() == 0) { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
30 endwin(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
31 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
|
32 fflush(stdout); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
33 getch(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
34 refresh(); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
35 exit(0); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
36 } |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
37 } |
15817 | 38 else if (key[0] == 27) |
39 { | |
40 if (strcmp(key, GNT_KEY_UP) == 0) | |
41 gnt_text_view_scroll(GNT_TEXT_VIEW(view), -1); | |
42 else if (strcmp(key, GNT_KEY_DOWN) == 0) | |
43 gnt_text_view_scroll(GNT_TEXT_VIEW(view), 1); | |
44 else | |
45 return FALSE; | |
46 return TRUE; | |
47 } | |
48 | |
49 return FALSE; | |
50 } | |
51 | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
52 static void |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
53 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
|
54 { |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
55 if (start == entry->start) |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
56 gnt_widget_key_pressed(GNT_WIDGET(entry), ": "); |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
57 } |
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
58 |
15817 | 59 int main() |
60 { | |
61 GntWidget *hbox, *entry, *view; | |
62 | |
63 #ifdef STANDALONE | |
64 freopen(".error", "w", stderr); | |
65 | |
66 gnt_init(); | |
67 #endif | |
68 | |
69 hbox = gnt_box_new(FALSE, TRUE); | |
70 gnt_widget_set_name(hbox, "hbox"); | |
71 gnt_box_set_toplevel(GNT_BOX(hbox), TRUE); | |
72 gnt_box_set_fill(GNT_BOX(hbox), FALSE); | |
73 gnt_box_set_title(GNT_BOX(hbox), "Textview test"); | |
74 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
75 | |
76 entry = gnt_entry_new(NULL); | |
77 gnt_widget_set_name(entry, "entry"); | |
78 GNT_WIDGET_SET_FLAGS(entry, GNT_WIDGET_CAN_TAKE_FOCUS); | |
79 | |
18510
f104e1d45d85
Changes to the test apps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
80 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
|
81 |
15817 | 82 gnt_entry_set_word_suggest(GNT_ENTRY(entry), TRUE); |
83 gnt_entry_set_always_suggest(GNT_ENTRY(entry), FALSE); | |
84 gnt_entry_add_suggest(GNT_ENTRY(entry), "a"); | |
85 gnt_entry_add_suggest(GNT_ENTRY(entry), "ab"); | |
86 gnt_entry_add_suggest(GNT_ENTRY(entry), "abe"); | |
87 gnt_entry_add_suggest(GNT_ENTRY(entry), "abc"); | |
88 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcde"); | |
89 gnt_entry_add_suggest(GNT_ENTRY(entry), "abcd"); | |
90 gnt_entry_add_suggest(GNT_ENTRY(entry), "acb"); | |
91 | |
92 view = gnt_text_view_new(); | |
93 gnt_widget_set_name(view, "view"); | |
94 | |
95 gnt_widget_set_size(view, 20, 15); | |
96 gnt_widget_set_size(entry, 20, 1); | |
97 | |
98 gnt_box_add_widget(GNT_BOX(hbox), view); | |
99 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
100 gnt_box_add_widget(GNT_BOX(hbox), gnt_button_new("OK")); | |
101 | |
102 gnt_widget_show(hbox); | |
103 | |
104 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
|
105 gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(view), entry); |
15817 | 106 g_signal_connect_after(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), view); |
107 | |
108 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "\n", GNT_TEXT_FLAG_NORMAL); | |
109 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
110 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 1st line\n", GNT_TEXT_FLAG_NORMAL); | |
111 | |
112 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
113 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 2nd line\n", GNT_TEXT_FLAG_NORMAL); | |
114 | |
21722
5a0c058c10e6
Use colors in textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
115 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
5a0c058c10e6
Use colors in textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
116 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 3rd line\n", GNT_TEXT_FLAG_NORMAL | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
15817 | 117 |
118 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "plugins: ", GNT_TEXT_FLAG_BOLD); | |
119 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(view), "this is the 4th line\n", GNT_TEXT_FLAG_NORMAL); | |
120 | |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18510
diff
changeset
|
121 gnt_util_parse_xhtml_to_textview("<p><b>Ohoy hoy!!</b><br/><p>I think this is going to</p> <u> WORK!!! </u><a href='www.google.com'>check this out!!</a></p>", GNT_TEXT_VIEW(view)); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18510
diff
changeset
|
122 |
15817 | 123 #ifdef STANDALONE |
124 gnt_main(); | |
125 | |
126 gnt_quit(); | |
127 #endif | |
128 | |
129 return 0; | |
130 } | |
131 |