Mercurial > pidgin
changeset 7740:ddc450689c05
[gaim-migrate @ 8385]
Font sizes wysiwyg. Which is cool.
Now we just need to make POINT_SIZE center around the GTK+ theme font size.
Also, it would be cool if we could handle the ol' point size/font size problem
here.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 04 Dec 2003 07:53:42 +0000 |
parents | 2850079ad35f |
children | cbf4725c60aa |
files | src/gtkconv.c src/gtkimhtml.c src/gtkimhtml.h |
diffstat | 3 files changed, 86 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkconv.c Thu Dec 04 06:33:10 2003 +0000 +++ b/src/gtkconv.c Thu Dec 04 07:53:42 2003 +0000 @@ -125,7 +125,6 @@ static void do_italic(GtkWidget *italic, GaimGtkConversation *gtkconv); static void do_underline(GtkWidget *underline, GaimGtkConversation *gtkconv); static void do_small(GtkWidget *smalltb, GaimGtkConversation *gtkconv); -static void do_normal(GtkWidget *normal, GaimGtkConversation *gtkconv); static void do_big(GtkWidget *large, GaimGtkConversation *gtkconv); static void toggle_font(GtkWidget *font, GaimConversation *conv); static void toggle_fg_color(GtkWidget *color, GaimConversation *conv); @@ -1424,12 +1423,12 @@ break; case '0': - set_toggle(gtkconv->toolbar.normal_size, + /*set_toggle(gtkconv->toolbar.normal_size, !gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(gtkconv->toolbar.normal_size))); g_signal_stop_emission_by_name(G_OBJECT(entry), - "key_press_event"); + "key_press_event"); */ break; case 'f': @@ -2205,33 +2204,14 @@ static void do_small(GtkWidget *smalltb, GaimGtkConversation *gtkconv) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smalltb))) - gaim_gtk_surround(gtkconv, "<FONT SIZE=\"1\">", "</FONT>"); - else - gaim_gtk_advance_past(gtkconv, "<FONT SIZE=\"1\">", "</FONT>"); - - gtk_widget_grab_focus(gtkconv->entry); -} - -static void -do_normal(GtkWidget *normal, GaimGtkConversation *gtkconv) -{ - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(normal))) - gaim_gtk_surround(gtkconv, "<FONT SIZE=\"3\">", "</FONT>"); - else - gaim_gtk_advance_past(gtkconv, "<FONT SIZE=\"3\">", "</FONT>"); - + gtk_imhtml_font_shrink(GTK_IMHTML(gtkconv->entry)); gtk_widget_grab_focus(gtkconv->entry); } static void do_big(GtkWidget *large, GaimGtkConversation *gtkconv) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(large))) - gaim_gtk_surround(gtkconv, "<FONT SIZE=\"5\">", "</FONT>"); - else - gaim_gtk_advance_past(gtkconv, "<FONT SIZE=\"5\">", "</FONT>"); - + gtk_imhtml_font_grow(GTK_IMHTML(gtkconv->entry)); gtk_widget_grab_focus(gtkconv->entry); } @@ -3268,7 +3248,7 @@ gtkconv->toolbar.larger_size = button; - /* Normal font size */ + /* Normal font size button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_NORMAL); gtk_size_group_add_widget(sg, button); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); @@ -3279,6 +3259,7 @@ G_CALLBACK(do_normal), gtkconv); gtkconv->toolbar.normal_size = button; + */ /* Decrease font size */ button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER);
--- a/src/gtkimhtml.c Thu Dec 04 06:33:10 2003 +0000 +++ b/src/gtkimhtml.c Thu Dec 04 07:53:42 2003 +0000 @@ -523,6 +523,8 @@ imhtml->edit.forecolor = NULL; imhtml->edit.backcolor = NULL; imhtml->edit.fontface = NULL; + imhtml->edit.sizespan = NULL; + imhtml->edit.fontsize = 3; imhtml->format_spans = NULL; @@ -1640,6 +1642,8 @@ imhtml->edit.fontface = NULL; imhtml->edit.forecolor = NULL; imhtml->edit.backcolor = NULL; + imhtml->edit.sizespan = NULL; + imhtml->edit.fontsize = 3; } void gtk_imhtml_page_up (GtkIMHtml *imhtml) @@ -2013,6 +2017,20 @@ gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &face, span->start); gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &face, iter); } + + if ((span = imhtml->edit.sizespan)) { + GtkTextIter size; + /* We create the tags here so that one can grow font or shrink font several times + * in a row without creating unnecessary tags */ + if (span->tag == NULL) { + span->tag = gtk_text_buffer_create_tag + (imhtml->text_buffer, NULL, "size-points", (double)_point_sizes [imhtml->edit.fontsize-1], NULL); + span->start_tag = g_strdup_printf("<font size='%d'>", imhtml->edit.fontsize); + span->end_tag = g_strdup("</font>"); + } + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start); + gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter); + } } void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) @@ -2099,6 +2117,64 @@ return imhtml->edit.underline != NULL; } +void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) +{ + GtkIMHtmlFormatSpan *span; + GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); + GtkTextIter iter; + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); + if (imhtml->edit.fontsize == 1) + return; + + imhtml->edit.fontsize--; + + if (imhtml->edit.sizespan) { + GtkTextIter iter2; + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); + if (gtk_text_iter_equal(&iter2, &iter)) + return; + span = imhtml->edit.sizespan; + span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + } + + span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + span->end = NULL; + span->buffer = imhtml->text_buffer; + span->tag = NULL; + imhtml->edit.sizespan = span; + imhtml->format_spans = g_list_append(imhtml->format_spans, span); +} + +void gtk_imhtml_font_grow(GtkIMHtml *imhtml) +{ + GtkIMHtmlFormatSpan *span; + GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); + GtkTextIter iter; + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); + if (imhtml->edit.fontsize == MAX_FONT_SIZE) + return; + + imhtml->edit.fontsize++; + + if (imhtml->edit.sizespan) { + GtkTextIter iter2; + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); + if (gtk_text_iter_equal(&iter2, &iter)) + return; + span = imhtml->edit.sizespan; + span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + } + + span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); + span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); + span->end = NULL; + span->tag = NULL; + span->buffer = imhtml->text_buffer; + imhtml->edit.sizespan = span; + imhtml->format_spans = g_list_append(imhtml->format_spans, span); +} + gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) { GtkIMHtmlFormatSpan *span;
--- a/src/gtkimhtml.h Thu Dec 04 06:33:10 2003 +0000 +++ b/src/gtkimhtml.h Thu Dec 04 07:53:42 2003 +0000 @@ -92,6 +92,8 @@ GtkIMHtmlFormatSpan *forecolor; GtkIMHtmlFormatSpan *backcolor; GtkIMHtmlFormatSpan *fontface; + GtkIMHtmlFormatSpan *sizespan; + int fontsize; } edit; GList *format_spans; }; @@ -215,6 +217,8 @@ gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face); void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text); void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley); +void gtk_imhtml_font_shrink(GtkIMHtml *imhtml); +void gtk_imhtml_font_grow(GtkIMHtml *imhtml); char *gtk_imhtml_get_markup(GtkIMHtml *imhtml); char *gtk_imhtml_get_text(GtkIMHtml *imhtml);