OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/custom_button.h" | 5 #include "chrome/browser/gtk/custom_button.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/gfx/gtk_util.h" |
10 | 11 |
11 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
12 | 13 |
13 CustomDrawButtonBase::CustomDrawButtonBase( | 14 CustomDrawButtonBase::CustomDrawButtonBase( |
14 int normal_id, | 15 int normal_id, |
15 int active_id, | 16 int active_id, |
16 int highlight_id, | 17 int highlight_id, |
17 int depressed_id) | 18 int depressed_id) |
18 : paint_override_(-1) { | 19 : paint_override_(-1) { |
19 // Load the button images from the resource bundle. | 20 // Load the button images from the resource bundle. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 cairo_paint(cairo_context); | 58 cairo_paint(cairo_context); |
58 cairo_destroy(cairo_context); | 59 cairo_destroy(cairo_context); |
59 | 60 |
60 return TRUE; | 61 return TRUE; |
61 } | 62 } |
62 | 63 |
63 CustomDrawButton::CustomDrawButton( | 64 CustomDrawButton::CustomDrawButton( |
64 int normal_id, | 65 int normal_id, |
65 int active_id, | 66 int active_id, |
66 int highlight_id, | 67 int highlight_id, |
67 int depressed_id) | 68 int depressed_id, |
68 : button_base_(normal_id, active_id, highlight_id, depressed_id) { | 69 const char* stock_id) |
| 70 : button_base_(normal_id, active_id, highlight_id, depressed_id), |
| 71 gtk_stock_name_(stock_id), |
| 72 has_expose_signal_handler_(false) { |
69 widget_.Own(gtk_button_new()); | 73 widget_.Own(gtk_button_new()); |
70 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); | 74 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); |
71 | 75 SetUseSystemTheme(false); |
72 gtk_widget_set_size_request(widget_.get(), | |
73 gdk_pixbuf_get_width(button_base_.pixbufs(0)), | |
74 gdk_pixbuf_get_height(button_base_.pixbufs(0))); | |
75 | |
76 gtk_widget_set_app_paintable(widget_.get(), TRUE); | |
77 // We effectively double-buffer by virtue of having only one image... | |
78 gtk_widget_set_double_buffered(widget_.get(), FALSE); | |
79 g_signal_connect(G_OBJECT(widget_.get()), "expose-event", | |
80 G_CALLBACK(OnExpose), this); | |
81 } | 76 } |
82 | 77 |
83 CustomDrawButton::~CustomDrawButton() { | 78 CustomDrawButton::~CustomDrawButton() { |
84 widget_.Destroy(); | 79 widget_.Destroy(); |
85 } | 80 } |
86 | 81 |
| 82 void CustomDrawButton::SetUseSystemTheme(bool use_gtk) { |
| 83 if (use_gtk && gtk_stock_name_) { |
| 84 gtk_button_set_image( |
| 85 GTK_BUTTON(widget_.get()), |
| 86 gtk_image_new_from_stock(gtk_stock_name_, GTK_ICON_SIZE_BUTTON)); |
| 87 gtk_widget_set_size_request(widget_.get(), -1, -1); |
| 88 gtk_widget_set_app_paintable(widget_.get(), FALSE); |
| 89 gtk_widget_set_double_buffered(widget_.get(), TRUE); |
| 90 |
| 91 if (has_expose_signal_handler_) |
| 92 gtk_signal_disconnect_by_data(GTK_OBJECT(widget_.get()), this); |
| 93 has_expose_signal_handler_ = false; |
| 94 } else { |
| 95 gtk_widget_set_size_request(widget_.get(), |
| 96 gdk_pixbuf_get_width(button_base_.pixbufs(0)), |
| 97 gdk_pixbuf_get_height(button_base_.pixbufs(0))); |
| 98 |
| 99 gtk_widget_set_app_paintable(widget_.get(), TRUE); |
| 100 // We effectively double-buffer by virtue of having only one image... |
| 101 gtk_widget_set_double_buffered(widget_.get(), FALSE); |
| 102 g_signal_connect(G_OBJECT(widget_.get()), "expose-event", |
| 103 G_CALLBACK(OnCustomExpose), this); |
| 104 has_expose_signal_handler_ = true; |
| 105 } |
| 106 } |
| 107 |
87 void CustomDrawButton::SetPaintOverride(GtkStateType state) { | 108 void CustomDrawButton::SetPaintOverride(GtkStateType state) { |
88 button_base_.set_paint_override(state); | 109 button_base_.set_paint_override(state); |
89 gtk_widget_queue_draw(widget_.get()); | 110 gtk_widget_queue_draw(widget_.get()); |
90 } | 111 } |
91 | 112 |
92 void CustomDrawButton::UnsetPaintOverride() { | 113 void CustomDrawButton::UnsetPaintOverride() { |
93 button_base_.set_paint_override(-1); | 114 button_base_.set_paint_override(-1); |
94 gtk_widget_queue_draw(widget_.get()); | 115 gtk_widget_queue_draw(widget_.get()); |
95 } | 116 } |
96 | 117 |
97 // static | 118 // static |
98 gboolean CustomDrawButton::OnExpose(GtkWidget* widget, | 119 gboolean CustomDrawButton::OnCustomExpose(GtkWidget* widget, |
99 GdkEventExpose* e, | 120 GdkEventExpose* e, |
100 CustomDrawButton* button) { | 121 CustomDrawButton* button) { |
101 return button->button_base_.OnExpose(widget, e); | 122 return button->button_base_.OnExpose(widget, e); |
102 } | 123 } |
103 | 124 |
104 // static | 125 // static |
105 CustomDrawButton* CustomDrawButton::CloseButton() { | 126 CustomDrawButton* CustomDrawButton::CloseButton() { |
106 return new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, | 127 CustomDrawButton* button = |
107 IDR_CLOSE_BAR_H, 0); | 128 new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P, |
| 129 IDR_CLOSE_BAR_H, 0, NULL); |
| 130 return button; |
108 } | 131 } |
OLD | NEW |