comparison src/gtkimhtml.c @ 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 92cbf9713795
children 2db51720fd09
comparison
equal deleted inserted replaced
8739:52969b8e9c58 8740:61a090413b93
798 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, 798 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
799 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); 799 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
800 800
801 } 801 }
802 802
803 static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused)
804 {
805 gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
806 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
807 }
803 #endif 808 #endif
804 809
805 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) 810 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml)
806 { 811 {
807 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { 812 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) {
869 874
870 if (imhtml->clipboard_text_string) { 875 if (imhtml->clipboard_text_string) {
871 g_free(imhtml->clipboard_text_string); 876 g_free(imhtml->clipboard_text_string);
872 g_free(imhtml->clipboard_html_string); 877 g_free(imhtml->clipboard_html_string);
873 } 878 }
874
875 879
876 g_list_free(imhtml->scalables); 880 g_list_free(imhtml->scalables);
877 G_OBJECT_CLASS(parent_class)->finalize (object); 881 G_OBJECT_CLASS(parent_class)->finalize (object);
878 } 882 }
879 883
962 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); 966 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM);
963 967
964 imhtml->show_smileys = TRUE; 968 imhtml->show_smileys = TRUE;
965 imhtml->show_comments = TRUE; 969 imhtml->show_comments = TRUE;
966 970
971 imhtml->zoom = 1.0;
972 imhtml->original_fsize = 0;
973
967 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, 974 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
968 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); 975 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
969 imhtml->default_smilies = gtk_smiley_tree_new(); 976 imhtml->default_smilies = gtk_smiley_tree_new();
970 977
971 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); 978 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL);
985 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); 992 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL);
986 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); 993 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL);
987 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); 994 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL);
988 //g_signal_connect_after(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); 995 //g_signal_connect_after(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml);
989 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL); 996 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL);
990 #endif 997 g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL);
998 #endif
991 999
992 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", 1000 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
993 G_CALLBACK(mark_set_so_update_selection_cb), imhtml); 1001 G_CALLBACK(mark_set_so_update_selection_cb), imhtml);
994 1002
995 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); 1003 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK);
2855 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); 2863 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL);
2856 2864
2857 return tag; 2865 return tag;
2858 } 2866 }
2859 2867
2868 static void _init_original_fsize(GtkIMHtml *imhtml)
2869 {
2870 GtkTextAttributes *attr;
2871 attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
2872 imhtml->original_fsize = pango_font_description_get_size(attr->font);
2873 gtk_text_attributes_unref(attr);
2874 }
2875
2876 static void _recalculate_font_sizes(GtkTextTag *tag, gpointer imhtml)
2877 {
2878 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) {
2879 int size;
2880
2881 size = strtol(tag->name + 10, NULL, 10);
2882 g_object_set(G_OBJECT(tag), "size",
2883 (gint) (GTK_IMHTML(imhtml)->original_fsize *
2884 ((double) _point_sizes[size-1] * GTK_IMHTML(imhtml)->zoom)), NULL);
2885 }
2886
2887
2888 }
2889
2890 void gtk_imhtml_font_zoom(GtkIMHtml *imhtml, double zoom)
2891 {
2892 GtkRcStyle *s;
2893 PangoFontDescription *font_desc = pango_font_description_new();
2894
2895 imhtml->zoom = zoom;
2896
2897 if (!imhtml->original_fsize)
2898 _init_original_fsize(imhtml);
2899
2900 gtk_text_tag_table_foreach(gtk_text_buffer_get_tag_table(imhtml->text_buffer),
2901 _recalculate_font_sizes, imhtml);
2902
2903 pango_font_description_set_size(font_desc, (gint)((double) imhtml->original_fsize * zoom));
2904
2905 s = gtk_widget_get_modifier_style(GTK_WIDGET(imhtml));
2906 s->font_desc = font_desc;
2907 gtk_widget_modify_style(GTK_WIDGET(imhtml), s);
2908 }
2909
2860 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) 2910 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size)
2861 { 2911 {
2862 gchar str[24]; 2912 gchar str[24];
2863 GtkTextTag *tag; 2913 GtkTextTag *tag;
2914
2915 if (!imhtml->original_fsize)
2916 _init_original_fsize(imhtml);
2864 2917
2865 g_snprintf(str, sizeof(str), "FONT SIZE %d", size); 2918 g_snprintf(str, sizeof(str), "FONT SIZE %d", size);
2866 str[23] = '\0'; 2919 str[23] = '\0';
2867 2920
2868 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); 2921 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
2869 if (!tag) { 2922 if (!tag) {
2870 /* For reasons I don't understand, setting "scale" here scaled based on some default 2923 /* For reasons I don't understand, setting "scale" here scaled based on some default
2871 * size other than my theme's default size. Our size 4 was actually smaller than 2924 * size other than my theme's default size. Our size 4 was actually smaller than
2872 * our size 3 for me. So this works around that oddity. 2925 * our size 3 for me. So this works around that oddity.
2873 */ 2926 */
2874 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
2875 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", 2927 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size",
2876 (gint) (pango_font_description_get_size(attr->font) * 2928 (gint) (imhtml->original_fsize *
2877 (double) _point_sizes[size-1]), NULL); 2929 ((double) _point_sizes[size-1] * imhtml->zoom)), NULL);
2878 gtk_text_attributes_unref(attr);
2879 } 2930 }
2880 2931
2881 return tag; 2932 return tag;
2882 } 2933 }
2883 2934