Mercurial > pidgin
comparison src/gtkimhtml.c @ 10692:533060d9a2c6
[gaim-migrate @ 12243]
Just because CVS wasn't broken enough...
This is good-style background coloring. http://gaim.sf.net/sean/backcolor.png
It doesn't work very well. I'd call it a "proof-of-concept". In fact, if you
try to send a message, the whole thing infi-loops. I expect Tim to fix it.
Also, we'll need to distinguish between <body background> and <font bgcolor>.
That shouldn't be very difficult. I expect Tim to do that as well.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 14 Mar 2005 01:55:50 +0000 |
parents | b39d5850883a |
children | 4b9d6f77ca61 |
comparison
equal
deleted
inserted
replaced
10691:fb30c4b67856 | 10692:533060d9a2c6 |
---|---|
519 #endif /* !(Gtk+ >= 2.2.0) */ | 519 #endif /* !(Gtk+ >= 2.2.0) */ |
520 } | 520 } |
521 | 521 |
522 return FALSE; | 522 return FALSE; |
523 } | 523 } |
524 | |
525 struct backcolor_tag { | |
526 GtkTextMark *start; | |
527 GtkTextMark *end; | |
528 char *color; | |
529 }; | |
530 | |
531 static gint | |
532 gtk_imhtml_expose_event (GtkWidget *widget, | |
533 GdkEventExpose *event) | |
534 { | |
535 GSList *l = GTK_IMHTML(widget)->backcolor_tags; | |
536 while (l) { | |
537 struct backcolor_tag *tag = (struct backcolor_tag*)l->data; | |
538 GdkRectangle visible_rect; | |
539 GdkRectangle redraw_rect; | |
540 int top, bottom, height, win_top, win_bottom; | |
541 GtkTextIter start, end; | |
542 | |
543 GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window)); | |
544 GdkColor color; | |
545 | |
546 gtk_text_buffer_get_iter_at_mark (GTK_IMHTML(widget)->text_buffer, &start, tag->start); | |
547 | |
548 if (tag->end) | |
549 gtk_text_buffer_get_iter_at_mark (GTK_IMHTML(widget)->text_buffer, &end, tag->end); | |
550 else | |
551 gtk_text_buffer_get_end_iter (GTK_IMHTML(widget)->text_buffer, &end); | |
552 | |
553 gtk_text_view_get_line_yrange (GTK_TEXT_VIEW(widget), &start, &top, NULL); | |
554 gtk_text_view_get_line_yrange (GTK_TEXT_VIEW(widget), &end, &bottom, &height); | |
555 | |
556 gtk_text_view_get_visible_rect (GTK_TEXT_VIEW(widget), &visible_rect); | |
557 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW(widget), | |
558 GTK_TEXT_WINDOW_TEXT, | |
559 visible_rect.x, | |
560 visible_rect.y, | |
561 &redraw_rect.x, | |
562 &redraw_rect.y); | |
563 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW(widget), | |
564 GTK_TEXT_WINDOW_TEXT, | |
565 0, | |
566 top, | |
567 NULL, | |
568 &win_top); | |
569 gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW(widget), | |
570 GTK_TEXT_WINDOW_TEXT, | |
571 0, | |
572 bottom + height, | |
573 NULL, | |
574 &win_bottom); | |
575 redraw_rect.width = visible_rect.width; | |
576 redraw_rect.height = visible_rect.height; | |
577 | |
578 | |
579 | |
580 gdk_color_parse(tag->color, &color); | |
581 gdk_gc_set_rgb_fg_color(gc, &color); | |
582 | |
583 gdk_draw_rectangle(event->window, | |
584 gc, | |
585 TRUE, | |
586 redraw_rect.x, win_top, redraw_rect.width, win_bottom - win_top); | |
587 gdk_gc_unref(gc); | |
588 l = l->next; | |
589 } | |
590 if (GTK_WIDGET_CLASS (parent_class)->expose_event) | |
591 return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
592 (widget, event); | |
593 return FALSE; | |
594 } | |
595 | |
596 | |
524 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) | 597 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
525 { | 598 { |
526 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | 599 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
527 | 600 |
528 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); | 601 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); |
529 | 602 |
530 } | 603 } |
604 | |
605 | |
531 | 606 |
532 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) | 607 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) |
533 { | 608 { |
534 GtkWidget *menuitem; | 609 GtkWidget *menuitem; |
535 | 610 |
1017 klass->toggle_format = imhtml_toggle_format; | 1092 klass->toggle_format = imhtml_toggle_format; |
1018 klass->message_send = imhtml_message_send; | 1093 klass->message_send = imhtml_message_send; |
1019 | 1094 |
1020 gobject_class->finalize = gtk_imhtml_finalize; | 1095 gobject_class->finalize = gtk_imhtml_finalize; |
1021 widget_class->drag_motion = gtk_text_view_drag_motion; | 1096 widget_class->drag_motion = gtk_text_view_drag_motion; |
1097 widget_class->expose_event = gtk_imhtml_expose_event; | |
1022 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", | 1098 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", |
1023 _("Hyperlink color"), | 1099 _("Hyperlink color"), |
1024 _("Color to draw hyperlinks."), | 1100 _("Color to draw hyperlinks."), |
1025 GDK_TYPE_COLOR, G_PARAM_READABLE)); | 1101 GDK_TYPE_COLOR, G_PARAM_READABLE)); |
1026 | 1102 |
1124 | 1200 |
1125 #ifdef _WIN32 | 1201 #ifdef _WIN32 |
1126 /* Register HTML Format as desired clipboard format */ | 1202 /* Register HTML Format as desired clipboard format */ |
1127 win_html_fmt = RegisterClipboardFormat("HTML Format"); | 1203 win_html_fmt = RegisterClipboardFormat("HTML Format"); |
1128 #endif | 1204 #endif |
1205 imhtml->backcolor_tags = NULL; | |
1129 } | 1206 } |
1130 | 1207 |
1131 GtkWidget *gtk_imhtml_new(void *a, void *b) | 1208 GtkWidget *gtk_imhtml_new(void *a, void *b) |
1132 { | 1209 { |
1133 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); | 1210 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
2695 | 2772 |
2696 void | 2773 void |
2697 gtk_imhtml_clear (GtkIMHtml *imhtml) | 2774 gtk_imhtml_clear (GtkIMHtml *imhtml) |
2698 { | 2775 { |
2699 GList *del; | 2776 GList *del; |
2777 GSList *dels | |
2700 GtkTextIter start, end; | 2778 GtkTextIter start, end; |
2701 GObject *object = g_object_ref(G_OBJECT(imhtml)); | 2779 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
2702 | 2780 |
2781 for (dels = imhtml->backcolor_tags; dels; dels = dels->next) { | |
2782 struct backcolor_tag *tag = dels->data; | |
2783 g_free(tag->color); | |
2784 g_free(tag); | |
2785 } | |
2786 g_slist_free(imhtml->backcolor_tags); | |
2787 imhtml->backcolor_tags = NULL; | |
2788 | |
2703 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | 2789 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
2704 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | 2790 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); |
2705 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | 2791 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); |
2706 | 2792 |
2707 for(del = imhtml->scalables; del; del = del->next) { | 2793 for(del = imhtml->scalables; del; del = del->next) { |
2708 GtkIMHtmlScalable *scale = del->data; | 2794 GtkIMHtmlScalable *scale = del->data; |
2709 scale->free(scale); | 2795 scale->free(scale); |
2710 } | 2796 } |
2797 | |
2711 g_list_free(imhtml->scalables); | 2798 g_list_free(imhtml->scalables); |
2712 imhtml->scalables = NULL; | 2799 imhtml->scalables = NULL; |
2713 | 2800 |
2714 g_object_unref(object); | 2801 g_object_unref(object); |
2715 } | 2802 } |
3719 | 3806 |
3720 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | 3807 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) |
3721 { | 3808 { |
3722 GObject *object; | 3809 GObject *object; |
3723 GtkTextIter start, end; | 3810 GtkTextIter start, end; |
3724 | 3811 struct backcolor_tag *bct = NULL; |
3725 if (imhtml->edit.backcolor != NULL) | 3812 if (imhtml->edit.backcolor != NULL) |
3726 g_free(imhtml->edit.backcolor); | 3813 g_free(imhtml->edit.backcolor); |
3727 | 3814 |
3728 if (color && strcmp(color, "") != 0) { | 3815 if (color && strcmp(color, "") != 0) { |
3729 imhtml->edit.backcolor = g_strdup(color); | 3816 imhtml->edit.backcolor = g_strdup(color); |
3731 if (imhtml->wbfo) { | 3818 if (imhtml->wbfo) { |
3732 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 3819 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
3733 remove_font_backcolor(imhtml, &start, &end, TRUE); | 3820 remove_font_backcolor(imhtml, &start, &end, TRUE); |
3734 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 3821 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3735 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), &start, &end); | 3822 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), &start, &end); |
3736 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 3823 bct = g_malloc(sizeof(struct backcolor_tag)); |
3737 remove_font_backcolor(imhtml, &start, &end, FALSE); | 3824 bct->color = strdup(imhtml->edit.backcolor); |
3738 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 3825 bct->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &start, TRUE); |
3739 find_font_backcolor_tag(imhtml, | 3826 bct->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &end, TRUE); |
3740 imhtml->edit.backcolor), &start, &end); | 3827 imhtml->backcolor_tags = g_slist_prepend(imhtml->backcolor_tags, bct); |
3828 } else { | |
3829 bct = g_malloc(sizeof(struct backcolor_tag)); | |
3830 bct->color = strdup(imhtml->edit.backcolor); | |
3831 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &start, | |
3832 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); | |
3833 bct->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &start, TRUE); | |
3834 bct->end = NULL; | |
3835 imhtml->backcolor_tags = g_slist_prepend(imhtml->backcolor_tags, bct); | |
3836 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3837 remove_font_backcolor(imhtml, &start, &end, FALSE); | |
3838 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3839 find_font_backcolor_tag(imhtml, | |
3840 imhtml->edit.backcolor), &start, &end); | |
3841 } | |
3741 } | 3842 } |
3742 } else { | 3843 } else { |
3743 imhtml->edit.backcolor = NULL; | 3844 if (imhtml->backcolor_tags) { |
3845 bct = ((struct backcolor_tag*)(imhtml->backcolor_tags->data)); | |
3846 if (bct->end == NULL) { | |
3847 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &end, | |
3848 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); | |
3849 bct->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &end, TRUE); | |
3850 } | |
3851 } | |
3744 if (imhtml->wbfo) { | 3852 if (imhtml->wbfo) { |
3745 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 3853 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
3746 remove_font_backcolor(imhtml, &start, &end, TRUE); | 3854 remove_font_backcolor(imhtml, &start, &end, TRUE); |
3747 } | 3855 } |
3748 } | 3856 } |