annotate finch/libgnt/gntutils.c @ 32805:064eb5d78946

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 0ba3afb8adb303a77581a7872d674c600979a5a6) to branch 'im.pidgin.pidgin' (head 7711a4d267e1fe776387496c764fb63227d70aec)
author Mark Doliner <mark@kingant.net>
date Mon, 31 Oct 2011 01:25:36 +0000
parents a472bc05fa55
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17718
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
1 /**
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
2 * GNT - The GLib Ncurses Toolkit
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
3 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
6 * source distribution.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
7 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
8 * This library is free software; you can redistribute it and/or modify
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
9 * it under the terms of the GNU General Public License as published by
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
11 * (at your option) any later version.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
12 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
13 * This program is distributed in the hope that it will be useful,
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
16 * GNU General Public License for more details.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
17 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
18 * You should have received a copy of the GNU General Public License
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
19 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19380
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17718
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
21 */
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
22
29152
259bbfb423d4 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <paul@darkrain42.org>
parents: 28705
diff changeset
23 #include "config.h"
259bbfb423d4 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <paul@darkrain42.org>
parents: 28705
diff changeset
24
24503
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19680
diff changeset
25 #include "gntinternal.h"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19680
diff changeset
26 #undef GNT_LOG_DOMAIN
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19680
diff changeset
27 #define GNT_LOG_DOMAIN "Utils"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19680
diff changeset
28
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
29 #include "gntbutton.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
30 #include "gntcheckbox.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
31 #include "gntcombobox.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
32 #include "gntentry.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
33 #include "gntlabel.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
34 #include "gntline.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
35 #include "gnttextview.h"
15979
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
36 #include "gnttree.h"
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
37 #include "gntutils.h"
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
38 #include "gntwindow.h"
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
40 #include <stdarg.h>
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #include <stdlib.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 #include <string.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
44 #ifndef NO_LIBXML
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
45 #include <libxml/parser.h>
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
46 #include <libxml/tree.h>
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
47 #endif
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
48
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 void gnt_util_get_text_bound(const char *text, int *width, int *height)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 const char *s = text, *last;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 int count = 1, max = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 /* XXX: ew ... everyone look away */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 last = s;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 if (s)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 while (*s)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 if (*s == '\n' || *s == '\r')
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 count++;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 len = gnt_util_onscreen_width(last, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 if (max < len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 max = len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 last = s + 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 s = g_utf8_next_char(s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 len = gnt_util_onscreen_width(last, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 if (max < len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 max = len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 if (height)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 *height = count;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 if (width)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 *width = max + (count > 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 int gnt_util_onscreen_width(const char *start, const char *end)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 int width = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 if (end == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 end = start + strlen(start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 while (start < end) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 start = g_utf8_next_char(start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 return width;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 int size;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 int width = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 const char *str = string;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 if (len <= 0) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 len = gnt_util_onscreen_width(string, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 while (width < len && *str) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 if (width + size > len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 break;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 str = g_utf8_next_char(str);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 width += size;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 if (w)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 *w = width;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 return str;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 char *gnt_util_onscreen_fit_string(const char *string, int maxw)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 const char *start, *end;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 GString *str;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 if (maxw <= 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 maxw = getmaxx(stdscr) - 4;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 start = string;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 str = g_string_new(NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 while (*start) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 if ((end = strchr(start, '\n')) != NULL ||
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 (end = strchr(start, '\r')) != NULL) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 if (gnt_util_onscreen_width(start, end) > maxw)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 end = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 if (end == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 str = g_string_append_len(str, start, end - start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 if (*end) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 str = g_string_append_c(str, '\n');
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 if (*end == '\n' || *end == '\r')
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 end++;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 start = end;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 return g_string_free(str, FALSE);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 struct duplicate_fns
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 GDupFunc key_dup;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 GDupFunc value_dup;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 GHashTable *table;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 duplicate_values(gpointer key, gpointer value, gpointer data)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 struct duplicate_fns *fns = data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 g_hash_table_insert(fns->table, fns->key_dup ? fns->key_dup(key) : key,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 fns->value_dup ? fns->value_dup(value) : value);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 GDupFunc key_dup, GDupFunc value_dup)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 GHashTable *dest = g_hash_table_new_full(hash, equal, key_d, value_d);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 struct duplicate_fns fns = {key_dup, value_dup, dest};
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 g_hash_table_foreach(src, duplicate_values, &fns);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 return dest;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 GValue *return_accu,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 const GValue *handler_return,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 gpointer dummy)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 gboolean continue_emission;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 gboolean signal_handled;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 signal_handled = g_value_get_boolean (handler_return);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 g_value_set_boolean (return_accu, signal_handled);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 continue_emission = !signal_handled;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 return continue_emission;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
15979
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
189 typedef struct {
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
190 GHashTable *hash;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
191 GntTree *tree;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
192 } BindingView;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
193
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
194 static void
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
195 add_binding(gpointer key, gpointer value, gpointer data)
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
196 {
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
197 BindingView *bv = data;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
198 GntBindableActionParam *act = value;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
199 const char *name = g_hash_table_lookup(bv->hash, act->action);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
200 if (name && *name) {
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
201 const char *k = gnt_key_lookup(key);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
202 if (!k)
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
203 k = key;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
204 gnt_tree_add_row_after(bv->tree, (gpointer)k,
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
205 gnt_tree_create_row(bv->tree, k, name), NULL, NULL);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
206 }
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
207 }
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
208
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
209 static void
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
210 add_action(gpointer key, gpointer value, gpointer data)
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
211 {
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
212 BindingView *bv = data;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
213 g_hash_table_insert(bv->hash, value, key);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
214 }
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
215
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
216 GntWidget *gnt_widget_bindings_view(GntWidget *widget)
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
217 {
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
218 GntBindable *bind = GNT_BINDABLE(widget);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
219 GntWidget *tree = gnt_tree_new_with_columns(2);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
220 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind));
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
221 GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
222 BindingView bv = {hash, GNT_TREE(tree)};
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
223
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
224 gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
225 g_hash_table_foreach(klass->actions, add_action, &bv);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
226 g_hash_table_foreach(klass->bindings, add_binding, &bv);
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
227 if (GNT_TREE(tree)->list == NULL) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
228 gnt_widget_destroy(tree);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
229 tree = NULL;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
230 } else
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
231 gnt_tree_adjust_columns(bv.tree);
15979
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
232 g_hash_table_destroy(hash);
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
233
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
234 return tree;
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
235 }
2c81ebc7bf0b Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
236
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
237 #ifndef NO_LIBXML
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
238 static GntWidget *
18583
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
239 gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[], int max)
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
240 {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
241 GntWidget *widget = NULL;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
242 char *name;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
243 char *id, *prop, *content;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
244 int val;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
245
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
246 if (node == NULL || node->name == NULL || node->type != XML_ELEMENT_NODE)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
247 return NULL;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
248
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
249 name = (char*)node->name;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
250 content = (char*)xmlNodeGetContent(node);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
251 if (strcmp(name + 1, "window") == 0 || strcmp(name + 1, "box") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
252 xmlNode *ch;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
253 char *title;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
254 gboolean vert = (*name == 'v');
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
255
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
256 if (name[1] == 'w')
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
257 widget = gnt_window_box_new(FALSE, vert);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
258 else
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
259 widget = gnt_box_new(FALSE, vert);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
260
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
261 title = (char*)xmlGetProp(node, (xmlChar*)"title");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
262 if (title) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
263 gnt_box_set_title(GNT_BOX(widget), title);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
264 xmlFree(title);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
265 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
266
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
267 prop = (char*)xmlGetProp(node, (xmlChar*)"fill");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
268 if (prop) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
269 if (sscanf(prop, "%d", &val) == 1)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
270 gnt_box_set_fill(GNT_BOX(widget), !!val);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
271 xmlFree(prop);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
272 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
273
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
274 prop = (char*)xmlGetProp(node, (xmlChar*)"align");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
275 if (prop) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
276 if (sscanf(prop, "%d", &val) == 1)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
277 gnt_box_set_alignment(GNT_BOX(widget), val);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
278 xmlFree(prop);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
279 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
280
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
281 prop = (char*)xmlGetProp(node, (xmlChar*)"pad");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
282 if (prop) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
283 if (sscanf(prop, "%d", &val) == 1)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
284 gnt_box_set_pad(GNT_BOX(widget), val);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
285 xmlFree(prop);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
286 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
287
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
288 for (ch = node->children; ch; ch=ch->next)
18583
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
289 gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data, max));
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
290 } else if (strcmp(name, "button") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
291 widget = gnt_button_new(content);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
292 } else if (strcmp(name, "label") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
293 widget = gnt_label_new(content);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
294 } else if (strcmp(name, "entry") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
295 widget = gnt_entry_new(content);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
296 } else if (strcmp(name, "combobox") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
297 widget = gnt_combo_box_new();
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
298 } else if (strcmp(name, "checkbox") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
299 widget = gnt_check_box_new(content);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
300 } else if (strcmp(name, "tree") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
301 widget = gnt_tree_new();
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
302 } else if (strcmp(name, "textview") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
303 widget = gnt_text_view_new();
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
304 } else if (strcmp(name + 1, "line") == 0) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
305 widget = gnt_line_new(*name == 'v');
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
306 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
307
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
308 xmlFree(content);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
309
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
310 if (widget == NULL) {
24503
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19680
diff changeset
311 gnt_warning("Invalid widget name %s", name);
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
312 return NULL;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
313 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
314
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
315 id = (char*)xmlGetProp(node, (xmlChar*)"id");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
316 if (id) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
317 int i;
18583
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
318 if (sscanf(id, "%d", &i) == 1 && i >= 0 && i < max) {
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
319 *data[i] = widget;
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
320 xmlFree(id);
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
321 }
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
322 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
323
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
324 prop = (char*)xmlGetProp(node, (xmlChar*)"border");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
325 if (prop) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
326 int val;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
327 if (sscanf(prop, "%d", &val) == 1) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
328 if (val)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
329 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
330 else
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
331 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
332 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
333 xmlFree(prop);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
334 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
335
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
336 prop = (char*)xmlGetProp(node, (xmlChar*)"shadow");
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
337 if (prop) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
338 int val;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
339 if (sscanf(prop, "%d", &val) == 1) {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
340 if (val)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
341 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
342 else
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
343 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
344 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
345 xmlFree(prop);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
346 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
347
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
348 return widget;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
349 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
350 #endif
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
351
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
352 void gnt_util_parse_widgets(const char *string, int num, ...)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
353 {
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
354 #ifndef NO_LIBXML
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
355 xmlParserCtxtPtr ctxt;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
356 xmlDocPtr doc;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
357 xmlNodePtr node;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
358 va_list list;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
359 GntWidget ***data;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
360 int id;
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
361
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
362 ctxt = xmlNewParserCtxt();
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
363 doc = xmlCtxtReadDoc(ctxt, (xmlChar*)string, NULL, NULL, XML_PARSE_NOBLANKS);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
364
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
365 data = g_new0(GntWidget **, num);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
366
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
367 va_start(list, num);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
368 for (id = 0; id < num; id++)
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
369 data[id] = va_arg(list, gpointer);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
370
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
371 node = xmlDocGetRootElement(doc);
18583
cf7297803a73 Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18511
diff changeset
372 gnt_widget_from_xmlnode(node, data, num);
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
373
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
374 xmlFreeDoc(doc);
28705
8981df90b64c Free up the parsers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24503
diff changeset
375 xmlFreeParserCtxt(ctxt);
16125
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
376 va_end(list);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
377 g_free(data);
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
378 #endif
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
379 }
5f204f55af09 Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15979
diff changeset
380
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: 18873
diff changeset
381 #ifndef NO_LIBXML
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
382 static void
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
383 util_parse_html_to_tv(xmlNode *node, GntTextView *tv, GntTextFormatFlags flag)
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
384 {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
385 const char *name;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
386 char *content;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
387 xmlNode *ch;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
388 char *url = NULL;
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
389 gboolean insert_nl_s = FALSE, insert_nl_e = FALSE;
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: 18873
diff changeset
390
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
391 if (node == NULL || node->name == NULL || node->type != XML_ELEMENT_NODE)
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
392 return;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
393
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
394 name = (char*)node->name;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
395 if (g_ascii_strcasecmp(name, "b") == 0 ||
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
396 g_ascii_strcasecmp(name, "strong") == 0 ||
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
397 g_ascii_strcasecmp(name, "i") == 0 ||
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
398 g_ascii_strcasecmp(name, "blockquote") == 0) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
399 flag |= GNT_TEXT_FLAG_BOLD;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
400 } else if (g_ascii_strcasecmp(name, "u") == 0) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
401 flag |= GNT_TEXT_FLAG_UNDERLINE;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
402 } else if (g_ascii_strcasecmp(name, "br") == 0) {
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
403 insert_nl_e = TRUE;
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: 18873
diff changeset
404 } else if (g_ascii_strcasecmp(name, "a") == 0) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
405 flag |= GNT_TEXT_FLAG_UNDERLINE;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
406 url = (char *)xmlGetProp(node, (xmlChar*)"href");
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
407 } else if (g_ascii_strcasecmp(name, "h1") == 0 ||
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
408 g_ascii_strcasecmp(name, "h2") == 0 ||
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
409 g_ascii_strcasecmp(name, "h3") == 0 ||
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
410 g_ascii_strcasecmp(name, "h4") == 0 ||
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
411 g_ascii_strcasecmp(name, "h5") == 0 ||
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
412 g_ascii_strcasecmp(name, "h6") == 0) {
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
413 insert_nl_s = TRUE;
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
414 insert_nl_e = TRUE;
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
415 } else if (g_ascii_strcasecmp(name, "title") == 0) {
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
416 insert_nl_s = TRUE;
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
417 insert_nl_e = TRUE;
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
418 flag |= GNT_TEXT_FLAG_BOLD | GNT_TEXT_FLAG_UNDERLINE;
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: 18873
diff changeset
419 } else {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
420 /* XXX: Process other possible tags */
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
421 }
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
422
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
423 if (insert_nl_s)
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
424 gnt_text_view_append_text_with_flags(tv, "\n", flag);
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
425
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: 18873
diff changeset
426 for (ch = node->children; ch; ch = ch->next) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
427 if (ch->type == XML_ELEMENT_NODE) {
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
428 util_parse_html_to_tv(ch, tv, flag);
30668
a472bc05fa55 Fix parsing XHTML.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29267
diff changeset
429 } else if (ch->type == XML_TEXT_NODE) {
a472bc05fa55 Fix parsing XHTML.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29267
diff changeset
430 content = (char*)xmlNodeGetContent(ch);
a472bc05fa55 Fix parsing XHTML.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29267
diff changeset
431 gnt_text_view_append_text_with_flags(tv, content, flag);
a472bc05fa55 Fix parsing XHTML.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29267
diff changeset
432 xmlFree(content);
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: 18873
diff changeset
433 }
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
434 }
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
435
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
436 if (url) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
437 char *href = g_strdup_printf(" (%s)", url);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
438 gnt_text_view_append_text_with_flags(tv, href, flag);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
439 g_free(href);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
440 xmlFree(url);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
441 }
19380
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
442
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
443 if (insert_nl_e)
e28db9ae02b3 Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19334
diff changeset
444 gnt_text_view_append_text_with_flags(tv, "\n", flag);
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: 18873
diff changeset
445 }
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
446 #endif
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
447
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
448 gboolean gnt_util_parse_xhtml_to_textview(const char *string, GntTextView *tv)
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
449 {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
450 #ifdef NO_LIBXML
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
451 return FALSE;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
452 #else
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
453 xmlParserCtxtPtr ctxt;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
454 xmlDocPtr doc;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
455 xmlNodePtr node;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
456 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
457 gboolean ret = FALSE;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
458
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
459 ctxt = xmlNewParserCtxt();
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
460 doc = xmlCtxtReadDoc(ctxt, (xmlChar*)string, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_RECOVER);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
461 if (doc) {
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
462 node = xmlDocGetRootElement(doc);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
463 util_parse_html_to_tv(node, tv, flag);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
464 xmlFreeDoc(doc);
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
465 ret = TRUE;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
466 }
28705
8981df90b64c Free up the parsers.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24503
diff changeset
467 xmlFreeParserCtxt(ctxt);
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: 18873
diff changeset
468 return ret;
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
469 #endif
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
470 }
fda2d2d99850 Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18873
diff changeset
471
18511
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
472 /* Setup trigger widget */
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
473 typedef struct {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
474 char *text;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
475 GntWidget *button;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
476 } TriggerButton;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
477
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
478 static void
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
479 free_trigger_button(TriggerButton *b)
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
480 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
481 g_free(b->text);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
482 g_free(b);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
483 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
484
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
485 static gboolean
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
486 key_pressed(GntWidget *widget, const char *text, TriggerButton *trig)
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
487 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
488 if (text && trig->text &&
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
489 strcmp(text, trig->text) == 0) {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
490 gnt_widget_activate(trig->button);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
491 return TRUE;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
492 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
493 return FALSE;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
494 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
495
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
496 void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button)
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
497 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
498 TriggerButton *tb = g_new0(TriggerButton, 1);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
499 tb->text = g_strdup(text);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
500 tb->button = button;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
501 g_signal_connect(G_OBJECT(wid), "key_pressed", G_CALLBACK(key_pressed), tb);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
502 g_signal_connect_swapped(G_OBJECT(button), "destroy", G_CALLBACK(free_trigger_button), tb);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
503 }