Mercurial > pidgin
changeset 8740:61a090413b93
[gaim-migrate @ 9495]
This removes a warning compile-time, and adds a function that plugins can
call to change the conversation zoom factor. Credit for this and previous
works go to Tim Ringenbach, Kevin Stange, and Daniel Atallah, who have all
done a really nice job this release and the past on the gtkimhtml code.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 21 Apr 2004 06:13:49 +0000 |
parents | 52969b8e9c58 |
children | b994b0223335 |
files | src/gtkimhtml.c src/gtkimhtml.h |
diffstat | 2 files changed, 63 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkimhtml.c Wed Apr 21 04:35:09 2004 +0000 +++ b/src/gtkimhtml.c Wed Apr 21 06:13:49 2004 +0000 @@ -800,6 +800,11 @@ } +static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused) +{ + gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, + gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); +} #endif static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) @@ -871,7 +876,6 @@ g_free(imhtml->clipboard_text_string); g_free(imhtml->clipboard_html_string); } - g_list_free(imhtml->scalables); G_OBJECT_CLASS(parent_class)->finalize (object); @@ -964,6 +968,9 @@ imhtml->show_smileys = TRUE; imhtml->show_comments = TRUE; + imhtml->zoom = 1.0; + imhtml->original_fsize = 0; + imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)gtk_smiley_tree_destroy); imhtml->default_smilies = gtk_smiley_tree_new(); @@ -987,7 +994,8 @@ g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); //g_signal_connect_after(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL); -#endif + g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL); +#endif g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_so_update_selection_cb), imhtml); @@ -2857,11 +2865,56 @@ return tag; } +static void _init_original_fsize(GtkIMHtml *imhtml) +{ + GtkTextAttributes *attr; + attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); + imhtml->original_fsize = pango_font_description_get_size(attr->font); + gtk_text_attributes_unref(attr); +} + +static void _recalculate_font_sizes(GtkTextTag *tag, gpointer imhtml) +{ + if (strncmp(tag->name, "FONT SIZE ", 10) == 0) { + int size; + + size = strtol(tag->name + 10, NULL, 10); + g_object_set(G_OBJECT(tag), "size", + (gint) (GTK_IMHTML(imhtml)->original_fsize * + ((double) _point_sizes[size-1] * GTK_IMHTML(imhtml)->zoom)), NULL); + } + + +} + +void gtk_imhtml_font_zoom(GtkIMHtml *imhtml, double zoom) +{ + GtkRcStyle *s; + PangoFontDescription *font_desc = pango_font_description_new(); + + imhtml->zoom = zoom; + + if (!imhtml->original_fsize) + _init_original_fsize(imhtml); + + gtk_text_tag_table_foreach(gtk_text_buffer_get_tag_table(imhtml->text_buffer), + _recalculate_font_sizes, imhtml); + + pango_font_description_set_size(font_desc, (gint)((double) imhtml->original_fsize * zoom)); + + s = gtk_widget_get_modifier_style(GTK_WIDGET(imhtml)); + s->font_desc = font_desc; + gtk_widget_modify_style(GTK_WIDGET(imhtml), s); +} + static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) { gchar str[24]; GtkTextTag *tag; + if (!imhtml->original_fsize) + _init_original_fsize(imhtml); + g_snprintf(str, sizeof(str), "FONT SIZE %d", size); str[23] = '\0'; @@ -2871,11 +2924,9 @@ * size other than my theme's default size. Our size 4 was actually smaller than * our size 3 for me. So this works around that oddity. */ - GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", - (gint) (pango_font_description_get_size(attr->font) * - (double) _point_sizes[size-1]), NULL); - gtk_text_attributes_unref(attr); + (gint) (imhtml->original_fsize * + ((double) _point_sizes[size-1] * imhtml->zoom)), NULL); } return tag;
--- a/src/gtkimhtml.h Wed Apr 21 04:35:09 2004 +0000 +++ b/src/gtkimhtml.h Wed Apr 21 06:13:49 2004 +0000 @@ -106,7 +106,10 @@ int fontsize; GtkTextTag *link; } edit; - + + double zoom; + int original_fsize; + char *clipboard_text_string; char *clipboard_html_string; }; @@ -214,6 +217,8 @@ void gtk_imhtml_page_up (GtkIMHtml *imhtml); void gtk_imhtml_page_down (GtkIMHtml *imhtml); +void gtk_imhtml_font_zoom(GtkIMHtml *imhtml, double zoom); + GtkIMHtmlScalable *gtk_imhtml_scalable_new(); GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename); void gtk_imhtml_image_free(GtkIMHtmlScalable *);