diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:42:29 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:42:29 +0000 |
commit | a5166af69628552e4bcf746a38f3710cc895eac3 (patch) | |
tree | 0d6e0ab20143724111855ac501aad3fd469e6b8d /chrome/browser/gtk/custom_button.cc | |
parent | 08f91cc8431cc6dea19e3c3ff3a229c71a7fc71f (diff) | |
download | chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.zip chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.tar.gz chromium_src-a5166af69628552e4bcf746a38f3710cc895eac3.tar.bz2 |
GTK: Initial implementation of using GTK themes, partially based on evan's CL 118358.
A lot of stuff works:
- Colors are picked out of the GTK theme.
- Buttons use the current GTK button theme.
- We use the user's icon theme.
A lot of stuff doesn't:
- We could do a better job of picking colors for the skylines.
- The omnibox hasn't been touched.
- UI that's not part of the toolbar hasn't been touched.
- We currently fail on themes like HighContrastInverse.
TEST=Under Options>Personal Stuff, click GTK Theme. Colors and widgets should be rendered with the current GTK theme stuff.
TEST=With chrome open and in GTK Theme mode, change your GTK theme or icon theme. chrome should pick up on the change immediately and reimport the colors and images.
http://crbug.com/13967
Review URL: http://codereview.chromium.org/150176
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/custom_button.cc')
-rw-r--r-- | chrome/browser/gtk/custom_button.cc | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc index e828243..6729ee6 100644 --- a/chrome/browser/gtk/custom_button.cc +++ b/chrome/browser/gtk/custom_button.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/gfx/gtk_util.h" #include "grit/theme_resources.h" @@ -64,26 +65,46 @@ CustomDrawButton::CustomDrawButton( int normal_id, int active_id, int highlight_id, - int depressed_id) - : button_base_(normal_id, active_id, highlight_id, depressed_id) { + int depressed_id, + const char* stock_id) + : button_base_(normal_id, active_id, highlight_id, depressed_id), + gtk_stock_name_(stock_id), + has_expose_signal_handler_(false) { widget_.Own(gtk_button_new()); GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); - - gtk_widget_set_size_request(widget_.get(), - gdk_pixbuf_get_width(button_base_.pixbufs(0)), - gdk_pixbuf_get_height(button_base_.pixbufs(0))); - - gtk_widget_set_app_paintable(widget_.get(), TRUE); - // We effectively double-buffer by virtue of having only one image... - gtk_widget_set_double_buffered(widget_.get(), FALSE); - g_signal_connect(G_OBJECT(widget_.get()), "expose-event", - G_CALLBACK(OnExpose), this); + SetUseSystemTheme(false); } CustomDrawButton::~CustomDrawButton() { widget_.Destroy(); } +void CustomDrawButton::SetUseSystemTheme(bool use_gtk) { + if (use_gtk && gtk_stock_name_) { + gtk_button_set_image( + GTK_BUTTON(widget_.get()), + gtk_image_new_from_stock(gtk_stock_name_, GTK_ICON_SIZE_BUTTON)); + gtk_widget_set_size_request(widget_.get(), -1, -1); + gtk_widget_set_app_paintable(widget_.get(), FALSE); + gtk_widget_set_double_buffered(widget_.get(), TRUE); + + if (has_expose_signal_handler_) + gtk_signal_disconnect_by_data(GTK_OBJECT(widget_.get()), this); + has_expose_signal_handler_ = false; + } else { + gtk_widget_set_size_request(widget_.get(), + gdk_pixbuf_get_width(button_base_.pixbufs(0)), + gdk_pixbuf_get_height(button_base_.pixbufs(0))); + + gtk_widget_set_app_paintable(widget_.get(), TRUE); + // We effectively double-buffer by virtue of having only one image... + gtk_widget_set_double_buffered(widget_.get(), FALSE); + g_signal_connect(G_OBJECT(widget_.get()), "expose-event", + G_CALLBACK(OnCustomExpose), this); + has_expose_signal_handler_ = true; + } +} + void CustomDrawButton::SetPaintOverride(GtkStateType state) { button_base_.set_paint_override(state); gtk_widget_queue_draw(widget_.get()); @@ -95,14 +116,16 @@ void CustomDrawButton::UnsetPaintOverride() { } // static -gboolean CustomDrawButton::OnExpose(GtkWidget* widget, - GdkEventExpose* e, - CustomDrawButton* button) { +gboolean CustomDrawButton::OnCustomExpose(GtkWidget* widget, + GdkEventExpose* e, + CustomDrawButton* button) { return button->button_base_.OnExpose(widget, e); } // static CustomDrawButton* CustomDrawButton::CloseButton() { - return new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, - IDR_CLOSE_BAR_H, 0); + CustomDrawButton* button = + new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, + IDR_CLOSE_BAR_H, 0, NULL); + return button; } |