Mercurial > pidgin.yaz
comparison pidgin/gtkimhtml.c @ 16964:ab45289d2c36
Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 09 May 2007 01:21:15 +0000 |
parents | a32325c04158 |
children | 53e757c37e06 48ef40b32eb7 |
comparison
equal
deleted
inserted
replaced
16963:919515748253 | 16964:ab45289d2c36 |
---|---|
1870 | 1870 |
1871 return t->image; | 1871 return t->image; |
1872 } | 1872 } |
1873 | 1873 |
1874 static GdkPixbufAnimation * | 1874 static GdkPixbufAnimation * |
1875 gtk_smiley_tree_image (GtkIMHtml *imhtml, | 1875 gtk_smiley_get_image(GtkIMHtmlSmiley *smiley) |
1876 const gchar *sml, | 1876 { |
1877 const gchar *text) | |
1878 { | |
1879 | |
1880 GtkIMHtmlSmiley *smiley; | |
1881 | |
1882 smiley = gtk_imhtml_smiley_get(imhtml,sml,text); | |
1883 | |
1884 if (!smiley) | |
1885 return NULL; | |
1886 | |
1887 if (!smiley->icon && smiley->file) { | 1877 if (!smiley->icon && smiley->file) { |
1888 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); | 1878 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); |
1889 } else if (!smiley->icon && smiley->loader) { | 1879 } else if (!smiley->icon && smiley->loader) { |
1890 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); | 1880 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); |
1891 if (smiley->icon) | 1881 if (smiley->icon) |
1892 g_object_ref(G_OBJECT(smiley->icon)); | 1882 g_object_ref(G_OBJECT(smiley->icon)); |
1893 } | 1883 } |
1894 | 1884 |
1895 return smiley->icon; | 1885 return smiley->icon; |
1886 } | |
1887 | |
1888 static GdkPixbufAnimation * | |
1889 gtk_smiley_tree_image (GtkIMHtml *imhtml, | |
1890 const gchar *sml, | |
1891 const gchar *text) | |
1892 { | |
1893 GtkIMHtmlSmiley *smiley; | |
1894 | |
1895 smiley = gtk_imhtml_smiley_get(imhtml,sml,text); | |
1896 | |
1897 if (!smiley) | |
1898 return NULL; | |
1899 | |
1900 return gtk_smiley_get_image(smiley); | |
1896 } | 1901 } |
1897 | 1902 |
1898 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ | 1903 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
1899 *tag = g_strndup (string, strlen (x)); \ | 1904 *tag = g_strndup (string, strlen (x)); \ |
1900 *len = strlen (x) + 1; \ | 1905 *len = strlen (x) + 1; \ |
3361 be caught by the regular GtkTextView menu */ | 3366 be caught by the regular GtkTextView menu */ |
3362 else | 3367 else |
3363 return FALSE; /* Let clicks go through if we didn't catch anything */ | 3368 return FALSE; /* Let clicks go through if we didn't catch anything */ |
3364 | 3369 |
3365 } | 3370 } |
3371 | |
3372 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley) | |
3373 { | |
3374 GdkPixbufAnimation *anim = NULL; | |
3375 GdkPixbuf *pix = NULL; | |
3376 GtkIMHtmlScalable *image = NULL; | |
3377 gboolean ret; | |
3378 | |
3379 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3) | |
3380 return FALSE; | |
3381 | |
3382 anim = gtk_smiley_get_image(smiley); | |
3383 if (!anim) | |
3384 return FALSE; | |
3385 | |
3386 pix = gdk_pixbuf_animation_get_static_image(anim); | |
3387 image = gtk_imhtml_image_new(pix, NULL, 0); | |
3388 ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image); | |
3389 g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free); | |
3390 g_object_unref(G_OBJECT(pix)); | |
3391 return ret; | |
3392 } | |
3393 | |
3366 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) | 3394 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
3367 { | 3395 { |
3368 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | 3396 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
3369 | 3397 |
3370 g_object_unref(image->pixbuf); | 3398 g_object_unref(image->pixbuf); |
4376 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) | 4404 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) |
4377 { | 4405 { |
4378 GdkPixbuf *pixbuf = NULL; | 4406 GdkPixbuf *pixbuf = NULL; |
4379 GdkPixbufAnimation *annipixbuf = NULL; | 4407 GdkPixbufAnimation *annipixbuf = NULL; |
4380 GtkWidget *icon = NULL; | 4408 GtkWidget *icon = NULL; |
4381 GtkTextChildAnchor *anchor; | 4409 GtkTextChildAnchor *anchor = NULL; |
4382 char *unescaped = purple_unescape_html(smiley); | 4410 char *unescaped = purple_unescape_html(smiley); |
4383 GtkIMHtmlSmiley *imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped); | 4411 GtkIMHtmlSmiley *imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped); |
4412 GtkWidget *ebox = NULL; | |
4384 | 4413 |
4385 if (imhtml->format_functions & GTK_IMHTML_SMILEY) { | 4414 if (imhtml->format_functions & GTK_IMHTML_SMILEY) { |
4386 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); | 4415 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
4387 if (annipixbuf) { | 4416 if (annipixbuf) { |
4388 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { | 4417 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { |
4395 GtkImage *image = GTK_IMAGE(g_queue_pop_head(imhtml->animations)); | 4424 GtkImage *image = GTK_IMAGE(g_queue_pop_head(imhtml->animations)); |
4396 GdkPixbufAnimation *anim = gtk_image_get_animation(image); | 4425 GdkPixbufAnimation *anim = gtk_image_get_animation(image); |
4397 if (anim) { | 4426 if (anim) { |
4398 GdkPixbuf *pb = gdk_pixbuf_animation_get_static_image(anim); | 4427 GdkPixbuf *pb = gdk_pixbuf_animation_get_static_image(anim); |
4399 gtk_image_set_from_pixbuf(image, pb); | 4428 gtk_image_set_from_pixbuf(image, pb); |
4429 g_object_unref(G_OBJECT(pb)); | |
4400 } | 4430 } |
4401 } else { | 4431 } else { |
4402 imhtml->num_animations++; | 4432 imhtml->num_animations++; |
4403 } | 4433 } |
4404 g_signal_connect(G_OBJECT(icon), "destroy", G_CALLBACK(animated_smiley_destroy_cb), imhtml); | 4434 g_signal_connect(G_OBJECT(icon), "destroy", G_CALLBACK(animated_smiley_destroy_cb), imhtml); |
4405 g_queue_push_tail(imhtml->animations, icon); | 4435 g_queue_push_tail(imhtml->animations, icon); |
4406 } | 4436 } |
4407 } | 4437 } |
4408 } | 4438 } |
4409 | 4439 |
4440 if (imhtml_smiley->flags & GTK_IMHTML_SMILEY_CUSTOM) { | |
4441 ebox = gtk_event_box_new(); | |
4442 gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); | |
4443 gtk_widget_show(ebox); | |
4444 } | |
4445 | |
4410 if (icon) { | 4446 if (icon) { |
4411 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | 4447 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
4412 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | 4448 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); |
4413 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | 4449 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); |
4414 | 4450 |
4417 * itself, without propagating to the textview and causing | 4453 * itself, without propagating to the textview and causing |
4418 * a complete refresh */ | 4454 * a complete refresh */ |
4419 g_signal_connect(G_OBJECT(icon), "expose-event", G_CALLBACK(image_expose), NULL); | 4455 g_signal_connect(G_OBJECT(icon), "expose-event", G_CALLBACK(image_expose), NULL); |
4420 | 4456 |
4421 gtk_widget_show(icon); | 4457 gtk_widget_show(icon); |
4422 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | 4458 if (ebox) |
4459 gtk_container_add(GTK_CONTAINER(ebox), icon); | |
4460 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), ebox ? ebox : icon, anchor); | |
4423 } else if (imhtml_smiley != NULL && (imhtml->format_functions & GTK_IMHTML_SMILEY)) { | 4461 } else if (imhtml_smiley != NULL && (imhtml->format_functions & GTK_IMHTML_SMILEY)) { |
4424 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | 4462 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
4425 imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, anchor); | 4463 imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, anchor); |
4464 if (ebox) { | |
4465 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU); | |
4466 gtk_container_add(GTK_CONTAINER(ebox), img); | |
4467 gtk_widget_show(img); | |
4468 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), ebox, anchor); | |
4469 } | |
4426 } else { | 4470 } else { |
4427 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | 4471 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); |
4472 } | |
4473 | |
4474 if (ebox) { | |
4475 g_signal_connect(G_OBJECT(ebox), "event", G_CALLBACK(gtk_imhtml_smiley_clicked), imhtml_smiley); | |
4428 } | 4476 } |
4429 | 4477 |
4430 g_free(unescaped); | 4478 g_free(unescaped); |
4431 } | 4479 } |
4432 | 4480 |