comparison src/gtkimhtml.c @ 8505:112f5762a41a

[gaim-migrate @ 9241] (22:47:05) kstange: lschiere2: http://kevin.simguy.net/temp/patches/gaim-imhtml-smileys-with-entities-fix-take2.diff .... no more n^2 (22:49:30) kstange: lschiere2: this patch basically reverses all the code I wrote to fix it the other way, and does it a MUCH more efficient way :-) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 26 Mar 2004 05:05:08 +0000
parents 0a9b591278bc
children 887c0259b47b
comparison
equal deleted inserted replaced
8504:534b479692d0 8505:112f5762a41a
61 #endif 61 #endif
62 62
63 #define TOOLTIP_TIMEOUT 500 63 #define TOOLTIP_TIMEOUT 500
64 64
65 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); 65 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
66 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length);
66 void gtk_imhtml_close_tags(GtkIMHtml *imhtml); 67 void gtk_imhtml_close_tags(GtkIMHtml *imhtml);
67 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); 68 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml);
68 69
69 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a 70 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a
70 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ 71 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */
938 const gchar *text) 939 const gchar *text)
939 { 940 {
940 GtkSmileyTree *t = tree; 941 GtkSmileyTree *t = tree;
941 const gchar *x = text; 942 const gchar *x = text;
942 gint len = 0; 943 gint len = 0;
944 gchar *amp;
945 gint alen;
943 946
944 while (*x) { 947 while (*x) {
945 gchar *pos; 948 gchar *pos;
946 949
947 if (!t->values) 950 if (!t->values)
948 break; 951 break;
949 952
950 pos = strchr (t->values->str, *x); 953 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &amp, &alen)) {
954 len += alen - strlen(amp);
955 x += alen - strlen(amp);
956 pos = strchr (t->values->str, *amp);
957 }
958 else
959 pos = strchr (t->values->str, *x);
960
951 if (pos) 961 if (pos)
952 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; 962 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
953 else 963 else
954 break; 964 break;
955 965
989 gint *len) 999 gint *len)
990 { 1000 {
991 GtkSmileyTree *tree; 1001 GtkSmileyTree *tree;
992 GtkIMHtmlFontDetail *font; 1002 GtkIMHtmlFontDetail *font;
993 char *sml = NULL; 1003 char *sml = NULL;
994 char *unescaped = NULL;
995 1004
996 if (fonts) { 1005 if (fonts) {
997 font = fonts->data; 1006 font = fonts->data;
998 sml = font->sml; 1007 sml = font->sml;
999 } 1008 }
1004 tree = g_hash_table_lookup(imhtml->smiley_data, sml); 1013 tree = g_hash_table_lookup(imhtml->smiley_data, sml);
1005 } 1014 }
1006 if (tree == NULL) 1015 if (tree == NULL)
1007 return FALSE; 1016 return FALSE;
1008 1017
1009 unescaped = gaim_unescape_html(text); 1018 *len = gtk_smiley_tree_lookup (tree, text);
1010 *len = gtk_smiley_tree_lookup (tree, unescaped);
1011 g_free(unescaped);
1012 return (*len > 0); 1019 return (*len > 0);
1013 } 1020 }
1014 1021
1015 GdkPixbufAnimation * 1022 GdkPixbufAnimation *
1016 gtk_smiley_tree_image (GtkIMHtml *imhtml, 1023 gtk_smiley_tree_image (GtkIMHtml *imhtml,
1912 g_free(tag); /* This was allocated back in VALID_TAG() */ 1919 g_free(tag); /* This was allocated back in VALID_TAG() */
1913 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { 1920 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
1914 GtkIMHtmlFontDetail *fd; 1921 GtkIMHtmlFontDetail *fd;
1915 1922
1916 gchar *sml = NULL; 1923 gchar *sml = NULL;
1917 gchar *unescaped = NULL;
1918 gint length = 0;
1919 if (fonts) { 1924 if (fonts) {
1920 fd = fonts->data; 1925 fd = fonts->data;
1921 sml = fd->sml; 1926 sml = fd->sml;
1922 } 1927 }
1923 if (url) 1928 if (url)
1924 gtk_imhtml_insert_link(imhtml, url, ws); 1929 gtk_imhtml_insert_link(imhtml, url, ws);
1925 else { 1930 else {
1926 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); 1931 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
1927 } 1932 }
1928 unescaped = gaim_unescape_html(c); 1933 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
1929 wpos = g_snprintf (ws, smilelen + 1, "%s", unescaped);
1930 g_free(unescaped);
1931 1934
1932 gtk_imhtml_insert_smiley(imhtml, sml, ws); 1935 gtk_imhtml_insert_smiley(imhtml, sml, ws);
1933 1936
1934 ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 1937 ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
1935 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 1938 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
1936 1939
1937 while(length < smilelen) 1940 c += smilelen;
1938 { 1941 pos += smilelen;
1939 if(*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
1940 c += tlen;
1941 pos += tlen;
1942 } else {
1943 c++;
1944 pos++;
1945 }
1946 length++;
1947 }
1948
1949 wpos = 0; 1942 wpos = 0;
1950 ws[0] = 0; 1943 ws[0] = 0;
1951 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) { 1944 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
1952 while(*amp) { 1945 while(*amp) {
1953 ws [wpos++] = *amp++; 1946 ws [wpos++] = *amp++;
2914 GtkTextIter iter; 2907 GtkTextIter iter;
2915 GdkPixbuf *pixbuf = NULL; 2908 GdkPixbuf *pixbuf = NULL;
2916 GdkPixbufAnimation *annipixbuf = NULL; 2909 GdkPixbufAnimation *annipixbuf = NULL;
2917 GtkWidget *icon = NULL; 2910 GtkWidget *icon = NULL;
2918 GtkTextChildAnchor *anchor; 2911 GtkTextChildAnchor *anchor;
2912 char *unescaped = gaim_unescape_html(smiley);
2919 2913
2920 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2914 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2921 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); 2915 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter);
2922 g_object_set_data(G_OBJECT(anchor), "text_tag", g_strdup(smiley)); 2916 g_object_set_data(G_OBJECT(anchor), "text_tag", unescaped);
2923 2917
2924 annipixbuf = gtk_smiley_tree_image(imhtml, sml, smiley); 2918 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped);
2925 if(annipixbuf) { 2919 if(annipixbuf) {
2926 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { 2920 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) {
2927 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); 2921 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf);
2928 if(pixbuf) 2922 if(pixbuf)
2929 icon = gtk_image_new_from_pixbuf(pixbuf); 2923 icon = gtk_image_new_from_pixbuf(pixbuf);