diff options
Diffstat (limited to 'chrome/browser/gtk/gtk_chrome_link_button.cc')
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_link_button.cc | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc index 0534a76..764c9c7 100644 --- a/chrome/browser/gtk/gtk_chrome_link_button.cc +++ b/chrome/browser/gtk/gtk_chrome_link_button.cc @@ -42,23 +42,26 @@ G_DEFINE_TYPE(GtkChromeLinkButton, gtk_chrome_link_button, GTK_TYPE_BUTTON) // can be read. static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) { // We only set the markup once. - if (button->blue_markup) + if (button->normal_markup) return; gchar* text = button->text; gboolean uses_markup = button->uses_markup; if (!uses_markup) { - button->blue_markup = g_markup_printf_escaped(kLinkMarkup, "blue", text); - button->red_markup = g_markup_printf_escaped(kLinkMarkup, "red", text); + button->normal_markup = g_markup_printf_escaped(kLinkMarkup, + button->normal_color, + text); + button->pressed_markup = g_markup_printf_escaped(kLinkMarkup, "red", text); } else { - button->blue_markup = static_cast<gchar*>( - g_malloc(strlen(kLinkMarkup) + strlen("blue") + strlen(text) + 1)); - sprintf(button->blue_markup, kLinkMarkup, "blue", text); - - button->red_markup = static_cast<gchar*>( - g_malloc(strlen(kLinkMarkup) + strlen("red") + strlen(text) + 1)); - sprintf(button->red_markup, kLinkMarkup, "red", text); + int length = strlen(kLinkMarkup) + 9 + strlen(text) + 1; + button->normal_markup = static_cast<gchar*>(g_malloc(length)); + snprintf(button->normal_markup, length, kLinkMarkup, button->normal_color, + text); + + length = strlen(kLinkMarkup) + strlen("red") + strlen(text) + 1; + button->pressed_markup = static_cast<gchar*>(g_malloc(length)); + snprintf(button->pressed_markup, length, kLinkMarkup, "red", text); } // Get the current GTK theme's link button text color. @@ -67,7 +70,7 @@ static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) { if (native_color) { gchar color_spec[9]; - sprintf(color_spec, "#%02X%02X%02X", native_color->red / 257, + sprintf(color_spec, 9, "#%02X%02X%02X", native_color->red / 257, native_color->green / 257, native_color->blue / 257); gdk_color_free(native_color); @@ -83,11 +86,12 @@ static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button) { } else { // If the theme doesn't have a link color, just use blue. This matches the // default for GtkLinkButton. - button->native_markup = button->blue_markup; + button->native_markup = button->normal_markup; } gtk_label_set_markup(GTK_LABEL(button->label), - button->using_native_theme ? button->native_markup : button->blue_markup); + button->using_native_theme ? button->native_markup : + button->normal_markup); } static gboolean gtk_chrome_link_button_expose(GtkWidget* widget, @@ -97,14 +101,15 @@ static gboolean gtk_chrome_link_button_expose(GtkWidget* widget, gtk_chrome_link_button_set_text(button); - if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && button->is_blue) { - gtk_label_set_markup(GTK_LABEL(label), button->red_markup); - button->is_blue = FALSE; - } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE && !button->is_blue) { + if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && button->is_normal) { + gtk_label_set_markup(GTK_LABEL(label), button->pressed_markup); + button->is_normal = FALSE; + } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE && + !button->is_normal) { gtk_label_set_markup(GTK_LABEL(label), button->using_native_theme ? button->native_markup : - button->blue_markup); - button->is_blue = TRUE; + button->normal_markup); + button->is_normal = TRUE; } // Draw the link inside the button. @@ -135,16 +140,16 @@ static void gtk_chrome_link_button_leave(GtkButton* button) { static void gtk_chrome_link_button_destroy(GtkObject* object) { GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(object); - if (button->native_markup && (button->native_markup != button->blue_markup)) + if (button->native_markup && (button->native_markup != button->normal_markup)) g_free(button->native_markup); button->native_markup = NULL; - if (button->blue_markup) { - g_free(button->blue_markup); - button->blue_markup = NULL; + if (button->normal_markup) { + g_free(button->normal_markup); + button->normal_markup = NULL; } - if (button->red_markup) { - g_free(button->red_markup); - button->red_markup = NULL; + if (button->pressed_markup) { + g_free(button->pressed_markup); + button->pressed_markup = NULL; } if (button->hand_cursor) { gdk_cursor_unref(button->hand_cursor); @@ -178,9 +183,10 @@ static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) { // let the button draw itself; catch all expose events to the button and pass // them through to the label. button->label = gtk_label_new(NULL); - button->blue_markup = NULL; - button->red_markup = NULL; - button->is_blue = TRUE; + button->normal_markup = NULL; + button->pressed_markup = NULL; + button->is_normal = TRUE; + strncpy(button->normal_color, "blue", 9); button->native_markup = NULL; button->using_native_theme = TRUE; button->hand_cursor = gtk_util::GetCursor(GDK_HAND2); @@ -221,16 +227,34 @@ void gtk_chrome_link_button_set_label(GtkChromeLinkButton* button, button->text = strdup(text); // Clear the markup so we can redraw. - if (button->native_markup && (button->native_markup != button->blue_markup)) + if (button->native_markup && (button->native_markup != button->normal_markup)) g_free(button->native_markup); button->native_markup = NULL; - if (button->blue_markup) { - g_free(button->blue_markup); - button->blue_markup = NULL; + if (button->normal_markup) { + g_free(button->normal_markup); + button->normal_markup = NULL; + } + if (button->pressed_markup) { + g_free(button->pressed_markup); + button->pressed_markup = NULL; + } + + if (GTK_WIDGET_VISIBLE(button)) + gtk_widget_queue_draw(GTK_WIDGET(button)); +} + +void gtk_chrome_link_button_set_normal_color(GtkChromeLinkButton* button, + const GdkColor* color) { + if (button->normal_markup) { + g_free(button->normal_markup); + button->normal_markup = NULL; } - if (button->red_markup) { - g_free(button->red_markup); - button->red_markup = NULL; + + if (color) { + snprintf(button->normal_color, 9, "#%02X%02X%02X", color->red / 257, + color->green / 257, color->blue / 257); + } else { + strncpy(button->normal_color, "blue", 9); } if (GTK_WIDGET_VISIBLE(button)) |