summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 21:36:05 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 21:36:05 +0000
commitb3d7a18cfceb5305aa563a321408665e4d7d3d12 (patch)
tree59b170abd48bb0b5d99d3027c6fec5566d62158a /chrome
parent696e1dd3dec8f2b92d2f5ee00def6a01fa9d4e00 (diff)
downloadchromium_src-b3d7a18cfceb5305aa563a321408665e4d7d3d12.zip
chromium_src-b3d7a18cfceb5305aa563a321408665e4d7d3d12.tar.gz
chromium_src-b3d7a18cfceb5305aa563a321408665e4d7d3d12.tar.bz2
Use two CustomDrawButtonBases to draw ToolbarStarToggleGtk.
Review URL: http://codereview.chromium.org/67012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/toolbar_star_toggle_gtk.cc80
-rw-r--r--chrome/browser/gtk/toolbar_star_toggle_gtk.h15
2 files changed, 30 insertions, 65 deletions
diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
index 26a8561..e6edf24 100644
--- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
+++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
@@ -3,75 +3,41 @@
// found in the LICENSE file.
#include "chrome/browser/gtk/toolbar_star_toggle_gtk.h"
+
#include "chrome/common/resource_bundle.h"
#include "grit/theme_resources.h"
-ToolbarStarToggleGtk::ToolbarStarToggleGtk() {
- widget_ = gtk_button_new();
-
- // Load the button images from the resource bundle.
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- unstarred_pixbuf_[GTK_STATE_NORMAL] = rb.LoadPixbuf(IDR_STAR);
- unstarred_pixbuf_[GTK_STATE_ACTIVE] = rb.LoadPixbuf(IDR_STAR_P);
- unstarred_pixbuf_[GTK_STATE_PRELIGHT] = rb.LoadPixbuf(IDR_STAR_H);
- unstarred_pixbuf_[GTK_STATE_SELECTED] = NULL;
- unstarred_pixbuf_[GTK_STATE_INSENSITIVE] = rb.LoadPixbuf(IDR_STAR_D);
-
- starred_pixbuf_[GTK_STATE_NORMAL] = rb.LoadPixbuf(IDR_STARRED);
- starred_pixbuf_[GTK_STATE_ACTIVE] = rb.LoadPixbuf(IDR_STARRED_P);
- starred_pixbuf_[GTK_STATE_PRELIGHT] = rb.LoadPixbuf(IDR_STARRED_H);
- starred_pixbuf_[GTK_STATE_SELECTED] = NULL;
- starred_pixbuf_[GTK_STATE_INSENSITIVE] = NULL;
-
- gtk_widget_set_size_request(widget_,
- gdk_pixbuf_get_width(unstarred_pixbuf_[0]),
- gdk_pixbuf_get_height(unstarred_pixbuf_[0]));
-
- gtk_widget_set_app_paintable(widget_, TRUE);
- // We effectively double-buffer by virtue of having only one image...
- gtk_widget_set_double_buffered(widget_, FALSE);
- g_signal_connect(G_OBJECT(widget_), "expose-event",
- G_CALLBACK(OnExpose), this);
+ToolbarStarToggleGtk::ToolbarStarToggleGtk()
+ : widget_(gtk_button_new()),
+ is_starred_(false),
+ unstarred_(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D),
+ starred_(IDR_STARRED, IDR_STARRED_P, IDR_STARRED_H, 0) {
+ gtk_widget_set_size_request(widget_.get(),
+ gdk_pixbuf_get_width(unstarred_.pixbufs(0)),
+ gdk_pixbuf_get_height(unstarred_.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);
}
ToolbarStarToggleGtk::~ToolbarStarToggleGtk() {
- for (size_t i = 0; i < arraysize(unstarred_pixbuf_); ++i) {
- if (unstarred_pixbuf_[i])
- gdk_pixbuf_unref(unstarred_pixbuf_[i]);
- if (starred_pixbuf_[i])
- gdk_pixbuf_unref(starred_pixbuf_[i]);
- }
+ widget_.Destroy();
}
void ToolbarStarToggleGtk::SetStarred(bool starred) {
- starred_ = starred;
- gtk_widget_queue_draw(widget_);
+ is_starred_ = starred;
+ gtk_widget_queue_draw(widget_.get());
}
// static
gboolean ToolbarStarToggleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e,
ToolbarStarToggleGtk* button) {
- GdkPixbuf** pixbuf_bank = NULL;
- if (button->starred_)
- pixbuf_bank = button->starred_pixbuf_;
- else
- pixbuf_bank = button->unstarred_pixbuf_;
-
- GdkPixbuf* pixbuf = pixbuf_bank[GTK_WIDGET_STATE(widget)];
-
- // Fall back to the default image if we don't have one for this state.
- if (!pixbuf)
- pixbuf = pixbuf_bank[GTK_STATE_NORMAL];
-
- if (!pixbuf)
- return FALSE;
-
- gdk_draw_pixbuf(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- pixbuf,
- 0, 0,
- widget->allocation.x, widget->allocation.y, -1, -1,
- GDK_RGB_DITHER_NONE, 0, 0);
-
- return TRUE;
+ if (button->is_starred_) {
+ return button->starred_.OnExpose(widget, e);
+ } else {
+ return button->unstarred_.OnExpose(widget, e);
+ }
}
diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.h b/chrome/browser/gtk/toolbar_star_toggle_gtk.h
index 584d2b6..dec5cd9 100644
--- a/chrome/browser/gtk/toolbar_star_toggle_gtk.h
+++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.h
@@ -8,6 +8,8 @@
#include <gtk/gtk.h>
#include "base/basictypes.h"
+#include "chrome/browser/gtk/custom_button.h"
+#include "chrome/common/owned_widget_gtk.h"
class GURL;
@@ -22,7 +24,7 @@ class ToolbarStarToggleGtk {
void SetStarred(bool starred);
- GtkWidget* widget() const { return widget_; }
+ GtkWidget* widget() const { return widget_.get(); }
private:
// Callback for expose, used to draw the custom graphics.
@@ -30,16 +32,13 @@ class ToolbarStarToggleGtk {
ToolbarStarToggleGtk* obj);
// The actual button widget.
- GtkWidget* widget_;
+ OwnedWidgetGtk widget_;
// Whether we show the yellow star.
- bool starred_;
+ bool is_starred_;
- // Unstarred images
- GdkPixbuf* unstarred_pixbuf_[GTK_STATE_INSENSITIVE + 1];
-
- // Starred images
- GdkPixbuf* starred_pixbuf_[GTK_STATE_INSENSITIVE + 1];
+ CustomDrawButtonBase unstarred_;
+ CustomDrawButtonBase starred_;
DISALLOW_EVIL_CONSTRUCTORS(ToolbarStarToggleGtk);
};