Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 7807:317f43c8287c
[gaim-migrate @ 8454]
It's getting better all the ti-ee-ime.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 08 Dec 2003 06:00:53 +0000 |
parents | 9db4ec5e6bca |
children | 4707d8436806 |
comparison
equal
deleted
inserted
replaced
7806:c86f075b269a | 7807:317f43c8287c |
---|---|
417 { | 417 { |
418 char *text; | 418 char *text; |
419 guint16 c; | 419 guint16 c; |
420 if (selection_data->length < 0) { | 420 if (selection_data->length < 0) { |
421 text = gtk_clipboard_wait_for_text(clipboard); | 421 text = gtk_clipboard_wait_for_text(clipboard); |
422 printf("%s\n", text); | |
423 } else { | 422 } else { |
424 text = g_malloc((selection_data->format / 8) * selection_data->length); | 423 text = g_malloc((selection_data->format / 8) * selection_data->length); |
425 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); | 424 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); |
426 printf("%s\n", text); | |
427 } | 425 } |
428 | 426 |
429 memcpy (&c, text, 2); | 427 memcpy (&c, text, 2); |
430 if (c == 0xfeff) { | 428 if (c == 0xfeff) { |
431 /* This is UCS2 */ | 429 /* This is UCS2 */ |
432 char *utf8 = g_convert(text+2, selection_data->length * (selection_data->format / 8), "UTF-8", "UCS-2", NULL, NULL, NULL); | 430 char *utf8 = g_convert(text+2, (selection_data->length * (selection_data->format / 8)) - 2, "UTF-8", "UCS-2", NULL, NULL, NULL); |
433 g_free(text); | 431 g_free(text); |
434 text = utf8; | 432 text = utf8; |
435 } | 433 } |
436 gtk_imhtml_close_tags(imhtml); | 434 gtk_imhtml_close_tags(imhtml); |
437 gtk_imhtml_append_text_with_images(imhtml, text, 0, NULL); | 435 gtk_imhtml_append_text_with_images(imhtml, text, GTK_IMHTML_NO_NEWLINE, NULL); |
438 } | 436 } |
439 | 437 |
440 | 438 |
441 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | 439 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) |
442 { | 440 { |
526 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | 524 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); |
527 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | 525 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); |
528 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | 526 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); |
529 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); | 527 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
530 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); | 528 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
529 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ | |
531 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | 530 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
532 | 531 |
533 /* These tags will be used often and can be reused--we create them on init and then apply them by name | 532 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
534 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | 533 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ |
535 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | 534 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
620 gchar *url; | 619 gchar *url; |
621 }; | 620 }; |
622 | 621 |
623 static void url_open(GtkWidget *w, struct url_data *data) { | 622 static void url_open(GtkWidget *w, struct url_data *data) { |
624 if(!data) return; | 623 if(!data) return; |
625 | |
626 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | 624 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
627 | 625 |
628 g_object_unref(data->object); | 626 g_object_unref(data->object); |
629 g_free(data->url); | 627 g_free(data->url); |
630 g_free(data); | 628 g_free(data); |
1219 | 1217 |
1220 | 1218 |
1221 g_return_val_if_fail (imhtml != NULL, NULL); | 1219 g_return_val_if_fail (imhtml != NULL, NULL); |
1222 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | 1220 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); |
1223 g_return_val_if_fail (text != NULL, NULL); | 1221 g_return_val_if_fail (text != NULL, NULL); |
1224 | 1222 printf("Appending: %s\n", text); |
1225 c = text; | 1223 c = text; |
1226 len = strlen(text); | 1224 len = strlen(text); |
1227 ws = g_malloc(len + 1); | 1225 ws = g_malloc(len + 1); |
1228 ws[0] = 0; | 1226 ws[0] = 0; |
1229 | 1227 |
1614 fd = fonts->data; | 1612 fd = fonts->data; |
1615 sml = fd->sml; | 1613 sml = fd->sml; |
1616 } | 1614 } |
1617 if (url) | 1615 if (url) |
1618 gtk_imhtml_insert_link(imhtml, url, ws); | 1616 gtk_imhtml_insert_link(imhtml, url, ws); |
1619 else | 1617 else { |
1618 printf("Inserting %s\n", ws); | |
1620 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | 1619 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
1621 ws[0] = '\0'; | 1620 } |
1622 //NEW_BIT (NEW_TEXT_BIT); | |
1623 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | 1621 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
1624 gtk_imhtml_insert_smiley(imhtml, sml, ws); | 1622 gtk_imhtml_insert_smiley(imhtml, sml, ws); |
1625 | |
1626 /*anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); | |
1627 annipixbuf = gtk_smiley_tree_image(imhtml, sml, ws); | |
1628 if(annipixbuf) { | |
1629 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
1630 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
1631 if(pixbuf) | |
1632 icon = gtk_image_new_from_pixbuf(pixbuf); | |
1633 } else { | |
1634 icon = gtk_image_new_from_animation(annipixbuf); | |
1635 } | |
1636 } | |
1637 | |
1638 if (icon) { | |
1639 gtk_widget_show(icon); | |
1640 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
1641 } | |
1642 | 1623 |
1643 copy = iter; | 1624 ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
1644 gtk_text_iter_backward_char(©); | 1625 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
1645 if (bg) { | 1626 |
1646 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); | |
1647 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
1648 } | |
1649 if (fonts) { | |
1650 GtkIMHtmlFontDetail *fd = fonts->data; | |
1651 if (fd->back) { | |
1652 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); | |
1653 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
1654 } | |
1655 } | |
1656 */ | |
1657 c += smilelen; | 1627 c += smilelen; |
1658 pos += smilelen; | 1628 pos += smilelen; |
1659 wpos = 0; | 1629 wpos = 0; |
1660 ws[0] = 0; | 1630 ws[0] = 0; |
1661 } else if (*c) { | 1631 } else if (*c) { |
1662 ws [wpos++] = *c++; | 1632 ws [wpos++] = *c++; |
1663 pos++; | 1633 pos++; |
1664 } else { | 1634 } else { |
1665 break; | 1635 break; |
1666 } | 1636 } |
2455 GdkPixbufAnimation *annipixbuf = NULL; | 2425 GdkPixbufAnimation *annipixbuf = NULL; |
2456 GtkWidget *icon = NULL; | 2426 GtkWidget *icon = NULL; |
2457 printf("%s %s\n", sml, smiley); | 2427 printf("%s %s\n", sml, smiley); |
2458 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | 2428 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
2459 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); | 2429 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); |
2460 g_object_set_data(G_OBJECT(anchor), "text_tag", smiley); | 2430 g_object_set_data(G_OBJECT(anchor), "text_tag", g_strdup(smiley)); |
2461 | 2431 |
2462 annipixbuf = gtk_smiley_tree_image(imhtml, sml, smiley); | 2432 annipixbuf = gtk_smiley_tree_image(imhtml, sml, smiley); |
2463 if(annipixbuf) { | 2433 if(annipixbuf) { |
2464 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | 2434 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { |
2465 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | 2435 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
2487 int span_compare_end(GtkIMHtmlFormatSpan *a, GtkIMHtmlFormatSpan *b) | 2457 int span_compare_end(GtkIMHtmlFormatSpan *a, GtkIMHtmlFormatSpan *b) |
2488 { | 2458 { |
2489 GtkTextIter ia, ib; | 2459 GtkTextIter ia, ib; |
2490 gtk_text_buffer_get_iter_at_mark(a->buffer, &ia, a->start); | 2460 gtk_text_buffer_get_iter_at_mark(a->buffer, &ia, a->start); |
2491 gtk_text_buffer_get_iter_at_mark(b->buffer, &ib, b->start); | 2461 gtk_text_buffer_get_iter_at_mark(b->buffer, &ib, b->start); |
2492 return gtk_text_iter_compare(&ia, &ib); | 2462 /* The -1 here makes it so that if I have two spans that close at the same point, the |
2463 * span added second will be closed first, as in <b><i>Hello</i></b>. Without this, | |
2464 * it would be <b><i>Hello</b></i> */ | |
2465 return gtk_text_iter_compare(&ia, &ib) - 1; | |
2493 } | 2466 } |
2494 | 2467 |
2495 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | 2468 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such |
2496 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | 2469 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else |
2497 * check the list of formatted strings, sorted by the position of the starting tags and apply them as | 2470 * check the list of formatted strings, sorted by the position of the starting tags and apply them as |
2592 else | 2565 else |
2593 str = g_string_append_unichar(str, c); | 2566 str = g_string_append_unichar(str, c); |
2594 } | 2567 } |
2595 gtk_text_iter_forward_char(&iter); | 2568 gtk_text_iter_forward_char(&iter); |
2596 } | 2569 } |
2570 closers = g_list_reverse(closers); | |
2597 while (closers) { | 2571 while (closers) { |
2598 GtkIMHtmlFormatSpan *span = (GtkIMHtmlFormatSpan*)closers->data; | 2572 GtkIMHtmlFormatSpan *span = (GtkIMHtmlFormatSpan*)closers->data; |
2599 str = g_string_append(str, span->end_tag); | 2573 str = g_string_append(str, span->end_tag); |
2600 closers = g_list_remove(closers, span); | 2574 closers = g_list_remove(closers, span); |
2601 } | 2575 |
2576 } | |
2577 printf("Gotten: %s\n", str->str); | |
2602 return g_string_free(str, FALSE); | 2578 return g_string_free(str, FALSE); |
2603 } | 2579 } |
2604 | 2580 |
2605 void gtk_imhtml_close_tags(GtkIMHtml *imhtml) | 2581 void gtk_imhtml_close_tags(GtkIMHtml *imhtml) |
2606 { | 2582 { |