# HG changeset patch # User Sean Egan # Date 1078899000 0 # Node ID c25c697525b759b73a957606ebb7487e253f19c3 # Parent 5c6124e9a3a79520c847c352c9c41fed842e7a13 [gaim-migrate @ 9150] Phase II. If anyone finds anything problematic here that can't be attributed to GtkIMHtml itself, please let me know (I'll probably tell you it can be attributed to GtkIMHtml itself ;)). Love, Sean. committer: Tailor Script diff -r 5c6124e9a3a7 -r c25c697525b7 src/gtkconv.c --- a/src/gtkconv.c Tue Mar 09 19:52:17 2004 +0000 +++ b/src/gtkconv.c Wed Mar 10 06:10:00 2004 +0000 @@ -2215,7 +2215,8 @@ gtkwin = GAIM_GTK_WINDOW(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gc = gaim_conversation_get_gc(conv); - + GtkIMHtmlButtons buttons; + if (gc != NULL) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); @@ -2329,13 +2330,19 @@ } /* Deal with the toolbar */ + + if (gc->flags & GAIM_CONNECTION_HTML) { + buttons = -1; /* Everything on */ + if (!(prpl_info->options & OPT_PROTO_IM_IMAGE)) + buttons ^= GTK_IMHTML_IMAGE; + if (gc->flags & GAIM_CONNECTION_NO_BGCOLOR) + buttons ^= GTK_IMHTML_BACKCOLOR; + } else { + buttons = 0; + } + gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->entry), buttons); + #if 0 - gtk_widget_set_sensitive(gtkconv->toolbar.link, TRUE); - gtk_widget_set_sensitive(gtkconv->toolbar.image, - (prpl_info->options & OPT_PROTO_IM_IMAGE)); - gtk_widget_set_sensitive(gtkconv->toolbar.bgcolor, - !(gc->flags & GAIM_CONNECTION_NO_BGCOLOR)); - /* Deal with menu items */ gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE); gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE); @@ -2381,7 +2388,7 @@ } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE); } - + /* Then deal with menu items */ gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE); gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE); diff -r 5c6124e9a3a7 -r c25c697525b7 src/gtkimhtml.c --- a/src/gtkimhtml.c Tue Mar 09 19:52:17 2004 +0000 +++ b/src/gtkimhtml.c Wed Mar 10 06:10:00 2004 +0000 @@ -84,6 +84,14 @@ DRAG_URL }; +enum { + URL_CLICKED, + BUTTONS_UPDATE, + TOGGLE_FORMAT, + LAST_SIGNAL +}; +static guint signals [LAST_SIGNAL] = { 0 }; + GtkTargetEntry selection_targets[] = { { "text/html", 0, TARGET_HTML }, { "UTF8_STRING", 0, TARGET_UTF8_STRING }, @@ -360,6 +368,7 @@ { char buf[7]; buf[0] = '\0'; + GObject *object; if (event->state & GDK_CONTROL_MASK) switch (event->keyval) { @@ -377,7 +386,12 @@ case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ case 'B': - gtk_imhtml_toggle_bold(imhtml); + if (imhtml->format_functions & GTK_IMHTML_BOLD) { + gtk_imhtml_toggle_bold(imhtml); + object = g_object_ref(G_OBJECT(imhtml)); + g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD); + g_object_unref(object); + } return TRUE; break; @@ -392,36 +406,28 @@ case 'i': case 'I': - /*set_toggle(gtkconv->toolbar.italic, - !gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(gtkconv->toolbar.italic)));*/ - gtk_imhtml_toggle_italic(imhtml); + if (imhtml->format_functions & GTK_IMHTML_ITALIC) + gtk_imhtml_toggle_italic(imhtml); return TRUE; break; case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ case 'U': - /*set_toggle(gtkconv->toolbar.underline, - !gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(gtkconv->toolbar.underline)));*/ - gtk_imhtml_toggle_underline(imhtml); + if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) + gtk_imhtml_toggle_underline(imhtml); return TRUE; break; case '-': - /*set_toggle(gtkconv->toolbar.smaller_size, - !gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(gtkconv->toolbar.smaller_size)));*/ - gtk_imhtml_font_shrink(imhtml); + if (imhtml->format_functions & GTK_IMHTML_SHRINK) + gtk_imhtml_font_shrink(imhtml); return TRUE; break; case '=': case '+': - /*set_toggle(gtkconv->toolbar.larger_size, - !gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(gtkconv->toolbar.larger_size)));*/ - gtk_imhtml_font_grow(imhtml); + if (imhtml->format_functions & GTK_IMHTML_GROW) + gtk_imhtml_font_grow(imhtml); return TRUE; break; @@ -566,13 +572,6 @@ static GtkTextViewClass *parent_class = NULL; -/* GtkIMHtml has one signal--URL_CLICKED */ -enum { - URL_CLICKED, - LAST_SIGNAL -}; -static guint signals [LAST_SIGNAL] = { 0 }; - static void gtk_imhtml_finalize (GObject *object) { @@ -616,6 +615,24 @@ g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); + signals[BUTTONS_UPDATE] = g_signal_new("format_functions_update", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), + NULL, + 0, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_INT); + signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), + NULL, + 0, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_INT); gobject_class->finalize = gtk_imhtml_finalize; } @@ -690,7 +707,6 @@ imhtml->scalables = NULL; gtk_imhtml_set_editable(imhtml, FALSE); - } GtkWidget *gtk_imhtml_new(void *a, void *b) @@ -1373,6 +1389,7 @@ GtkIMHtmlScalable *scalable = NULL; int y, height; + printf("Appending: %s\n", text); g_return_val_if_fail (imhtml != NULL, NULL); g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); @@ -2462,6 +2479,15 @@ */ /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ imhtml->editable = editable; + imhtml->format_functions = !editable ? 0 : -1; +} + +void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) +{ + GObject *object = g_object_ref(G_OBJECT(imhtml)); + g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); + imhtml->format_functions = buttons; + g_object_unref(object); } gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) diff -r 5c6124e9a3a7 -r c25c697525b7 src/gtkimhtml.h --- a/src/gtkimhtml.h Tue Mar 09 19:52:17 2004 +0000 +++ b/src/gtkimhtml.h Wed Mar 10 06:10:00 2004 +0000 @@ -49,6 +49,19 @@ typedef struct _GtkIMHtmlImage GtkIMHtmlImage; typedef struct _GtkIMHtmlHr GtkIMHtmlHr; +typedef enum { + GTK_IMHTML_BOLD = 1 << 0, + GTK_IMHTML_ITALIC = 1 << 1, + GTK_IMHTML_UNDERLINE = 1 << 2, + GTK_IMHTML_GROW = 1 << 3, + GTK_IMHTML_SHRINK = 1 << 4, + GTK_IMHTML_FACE = 1 << 5, + GTK_IMHTML_FORECOLOR = 1 << 6, + GTK_IMHTML_BACKCOLOR = 1 << 7, + GTK_IMHTML_LINK = 1 << 8, + GTK_IMHTML_IMAGE = 1 << 9, + GTK_IMHTML_SMILEY = 1 << 10 +} GtkIMHtmlButtons; typedef struct { GtkTextMark *start; @@ -83,6 +96,8 @@ gchar *search_string; gboolean editable; + GtkIMHtmlButtons format_functions; + struct { GtkIMHtmlFormatSpan *bold; GtkIMHtmlFormatSpan *italic; @@ -101,6 +116,8 @@ GtkTextViewClass parent_class; void (*url_clicked)(GtkIMHtml *, const gchar *); + void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons); + void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons); }; struct _GtkIMHtmlFontDetail { @@ -202,6 +219,7 @@ /* Editable stuff */ void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable); +void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons); gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml); diff -r 5c6124e9a3a7 -r c25c697525b7 src/gtkimhtmltoolbar.c --- a/src/gtkimhtmltoolbar.c Tue Mar 09 19:52:17 2004 +0000 +++ b/src/gtkimhtmltoolbar.c Wed Mar 10 06:10:00 2004 +0000 @@ -603,6 +603,47 @@ gtk_widget_grab_focus(toolbar->imhtml); } +static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) +{ + + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE); + + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->larger_size), buttons & GTK_IMHTML_GROW); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smaller_size), buttons & GTK_IMHTML_SHRINK); + + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->font), buttons & GTK_IMHTML_FACE); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->fgcolor), buttons & GTK_IMHTML_FORECOLOR); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bgcolor), buttons & GTK_IMHTML_BACKCOLOR); + + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK); + gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY); + +} + +static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) +{ + /* This is hacky. I have to tolerate the fact that set_active causes the signal to be emited, so I wind up + * toggling in gtkimhtml twice here */ + + if (buttons & GTK_IMHTML_BOLD) { + gtk_imhtml_toggle_bold(imhtml); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->bold), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))); + } + + if (buttons & GTK_IMHTML_ITALIC) { + gtk_imhtml_toggle_italic(imhtml); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->italic), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))); + } + + if (buttons & GTK_IMHTML_UNDERLINE) { + gtk_imhtml_toggle_underline(imhtml); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->underline), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))); + } +} + enum { LAST_SIGNAL }; @@ -852,4 +893,6 @@ g_return_if_fail(GTK_IS_IMHTML(imhtml)); toolbar->imhtml = imhtml; + g_signal_connect(G_OBJECT(imhtml), "format_functions_update", G_CALLBACK(update_buttons_cb), toolbar); + g_signal_connect(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); }