comparison src/gtkimhtml.c @ 4263:74f65a3d2a1f

[gaim-migrate @ 4514] I wanted to get this into cvs before I went to bed. Now proto-specific themes will work. The code's a bit crude at parts and it's not as fast as I'd like, but I can work some more on it tomorrow. Just figured you'd want to get a look at this. 8 penguin points to whoever finds out why gtk_smiley_tree_destroy (commented out right now, causing leakage) segfaults on me now. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 09 Jan 2003 09:41:49 +0000
parents 6c8ea04270e1
children f1876640e568
comparison
equal deleted inserted replaced
4262:7103653dd34e 4263:74f65a3d2a1f
52 }; 52 };
53 53
54 struct _GtkSmileyTree { 54 struct _GtkSmileyTree {
55 GString *values; 55 GString *values;
56 GtkSmileyTree **children; 56 GtkSmileyTree **children;
57 gchar *image; 57 GtkIMHtmlSmiley *image;
58 }; 58 };
59 59
60 static GtkSmileyTree* 60 static GtkSmileyTree*
61 gtk_smiley_tree_new () 61 gtk_smiley_tree_new ()
62 { 62 {
63 return g_new0 (GtkSmileyTree, 1); 63 return g_new0 (GtkSmileyTree, 1);
64 } 64 }
65 65
66 static void 66 static void
67 gtk_smiley_tree_insert (GtkSmileyTree *tree, 67 gtk_smiley_tree_insert (GtkSmileyTree *tree,
68 const gchar *text, 68 GtkIMHtmlSmiley *smiley)
69 const gchar *path)
70 { 69 {
71 GtkSmileyTree *t = tree; 70 GtkSmileyTree *t = tree;
72 const gchar *x = text; 71 const gchar *x = smiley->smile;
73 72
74 if (!strlen (x)) 73 if (!strlen (x))
75 return; 74 return;
76 75
77 while (*x) { 76 while (*x) {
93 t = t->children [index]; 92 t = t->children [index];
94 93
95 x++; 94 x++;
96 } 95 }
97 96
98 t->image = g_strdup(path); 97 t->image = smiley;
99 } 98 }
99
100 100
101 gboolean gtk_smiley_tree_destroy (GtkSmileyTree *tree) 101 gboolean gtk_smiley_tree_destroy (GtkSmileyTree *tree)
102 { 102 {
103 /*
103 GSList *list = g_slist_append (NULL, tree); 104 GSList *list = g_slist_append (NULL, tree);
104 105
105 while (list) { 106 while (list) {
106 GtkSmileyTree *t = list->data; 107 GtkSmileyTree *t = list->data;
107 gint i; 108 gint i;
110 for (i = 0; i < t->values->len; i++) 111 for (i = 0; i < t->values->len; i++)
111 list = g_slist_append (list, t->children [i]); 112 list = g_slist_append (list, t->children [i]);
112 g_string_free (t->values, TRUE); 113 g_string_free (t->values, TRUE);
113 g_free (t->children); 114 g_free (t->children);
114 } 115 }
115 g_free (t->image);
116 g_free (t); 116 g_free (t);
117 } 117 }
118 return TRUE; 118 return TRUE;
119 } 119 */
120 }
121
120 122
121 static GtkTextViewClass *parent_class = NULL; 123 static GtkTextViewClass *parent_class = NULL;
122 124
123 125
124 /* GtkIMHtml has one signal--URL_CLICKED */ 126 /* GtkIMHtml has one signal--URL_CLICKED */
231 /* clear timeout and make an arrow cursor again --if GTK worked as it should */ 233 /* clear timeout and make an arrow cursor again --if GTK worked as it should */
232 } 234 }
233 } 235 }
234 236
235 static void 237 static void
236 gtk_smiley_tree_remove (GtkSmileyTree *tree, 238 gtk_smiley_tree_remove (GtkSmileyTree *tree,
237 const gchar *text) 239 GtkIMHtmlSmiley *smiley)
238 { 240 {
239 GtkSmileyTree *t = tree; 241 GtkSmileyTree *t = tree;
240 const gchar *x = text; 242 const gchar *x = smiley->smile;
241 gint len = 0; 243 gint len = 0;
242 244
243 while (*x) { 245 while (*x) {
244 gchar *pos; 246 gchar *pos;
245 247
254 256
255 x++; len++; 257 x++; len++;
256 } 258 }
257 259
258 if (t->image) { 260 if (t->image) {
259 g_free(t->image);
260 t->image = NULL; 261 t->image = NULL;
261 } 262 }
262 } 263 }
263 264
264 static gint 265 static gint
289 290
290 return 0; 291 return 0;
291 } 292 }
292 293
293 void 294 void
294 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, 295 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
295 gchar *text, 296 gchar *sml,
296 gchar *sml, 297 GtkIMHtmlSmiley *smiley)
297 gchar *path)
298 { 298 {
299 GtkSmileyTree *tree; 299 GtkSmileyTree *tree;
300 g_return_if_fail (imhtml != NULL); 300 g_return_if_fail (imhtml != NULL);
301 g_return_if_fail (GTK_IS_IMHTML (imhtml)); 301 g_return_if_fail (GTK_IS_IMHTML (imhtml));
302 g_return_if_fail (text != NULL); 302
303
304 if (sml == NULL) 303 if (sml == NULL)
305 tree = imhtml->default_smilies; 304 tree = imhtml->default_smilies;
306 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { 305 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
307 } else { 306 } else {
308 tree = gtk_smiley_tree_new(); 307 tree = gtk_smiley_tree_new();
309 g_hash_table_insert(imhtml->smiley_data, sml, tree); 308 g_hash_table_insert(imhtml->smiley_data, sml, tree);
310 } 309 }
311 310
312 if (path == NULL) 311 gtk_smiley_tree_insert (tree, smiley);
313 gtk_smiley_tree_remove (tree, text);
314 else
315 gtk_smiley_tree_insert (tree, text, path);
316 } 312 }
317 313
318 static gboolean 314 static gboolean
319 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, 315 gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
320 GSList *fonts, 316 GSList *fonts,
340 336
341 *len = gtk_smiley_tree_lookup (tree, text); 337 *len = gtk_smiley_tree_lookup (tree, text);
342 return (*len > 0); 338 return (*len > 0);
343 } 339 }
344 340
345 static gchar* 341 GdkPixbuf*
346 gtk_smiley_tree_image (GtkIMHtml *imhtml, 342 gtk_smiley_tree_image (GtkIMHtml *imhtml,
347 const gchar *sml, 343 const gchar *sml,
348 const gchar *text) 344 const gchar *text)
349 { 345 {
350 GtkSmileyTree *t; 346 GtkSmileyTree *t;
351 const gchar *x = text; 347 const gchar *x = text;
352
353 if (sml == NULL) 348 if (sml == NULL)
354 t = imhtml->default_smilies; 349 t = imhtml->default_smilies;
355 else 350 else
356 t = g_hash_table_lookup(imhtml->smiley_data, sml); 351 t = g_hash_table_lookup(imhtml->smiley_data, sml);
357 352
373 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; 368 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
374 } 369 }
375 x++; 370 x++;
376 } 371 }
377 372
378 return t->image; 373 if (!t->image->icon)
374 t->image->icon = gdk_pixbuf_new_from_file(t->image->file, NULL);
375
376 return t->image->icon;
379 } 377 }
380 #define VALID_TAG(x) if (!g_strncasecmp (string, x ">", strlen (x ">"))) { \ 378 #define VALID_TAG(x) if (!g_strncasecmp (string, x ">", strlen (x ">"))) { \
381 *tag = g_strndup (string, strlen (x)); \ 379 *tag = g_strndup (string, strlen (x)); \
382 *len = strlen (x) + 1; \ 380 *len = strlen (x) + 1; \
383 return TRUE; \ 381 return TRUE; \
930 fd = fonts->data; 928 fd = fonts->data;
931 sml = fd->sml; 929 sml = fd->sml;
932 } 930 }
933 NEW_BIT (NEW_TEXT_BIT); 931 NEW_BIT (NEW_TEXT_BIT);
934 wpos = g_snprintf (ws, smilelen + 1, "%s", c); 932 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
935 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gdk_pixbuf_new_from_file(gtk_smiley_tree_image (imhtml, sml, ws), NULL)); 933 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gtk_smiley_tree_image (imhtml, sml, ws));
936 c += smilelen; 934 c += smilelen;
937 pos += smilelen; 935 pos += smilelen;
938 wpos = 0; 936 wpos = 0;
939 ws[0] = 0; 937 ws[0] = 0;
940 } else if (*c) { 938 } else if (*c) {