OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 | 6 |
7 #include "views/controls/button/native_button_gtk.h" | 7 #include "views/controls/button/native_button_gtk.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 void NativeButtonGtk::UpdateEnabled() { | 51 void NativeButtonGtk::UpdateEnabled() { |
52 if (!native_view()) | 52 if (!native_view()) |
53 return; | 53 return; |
54 SetEnabled(native_button_->IsEnabled()); | 54 SetEnabled(native_button_->IsEnabled()); |
55 } | 55 } |
56 | 56 |
57 void NativeButtonGtk::UpdateDefault() { | 57 void NativeButtonGtk::UpdateDefault() { |
58 if (!native_view()) | 58 if (!native_view()) |
59 return; | 59 return; |
60 if (!IsCheckbox()) | 60 if (IsCheckbox()) |
| 61 UpdateChecked(); |
| 62 else |
61 NOTIMPLEMENTED(); | 63 NOTIMPLEMENTED(); |
62 } | 64 } |
63 | 65 |
64 View* NativeButtonGtk::GetView() { | 66 View* NativeButtonGtk::GetView() { |
65 return this; | 67 return this; |
66 } | 68 } |
67 | 69 |
68 void NativeButtonGtk::SetFocus() { | 70 void NativeButtonGtk::SetFocus() { |
69 // Focus the associated widget. | 71 // Focus the associated widget. |
70 Focus(); | 72 Focus(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 110 |
109 // static | 111 // static |
110 void NativeButtonGtk::CallClicked(GtkButton* widget, NativeButtonGtk* button) { | 112 void NativeButtonGtk::CallClicked(GtkButton* widget, NativeButtonGtk* button) { |
111 button->OnClicked(); | 113 button->OnClicked(); |
112 } | 114 } |
113 | 115 |
114 void NativeButtonGtk::OnClicked() { | 116 void NativeButtonGtk::OnClicked() { |
115 native_button_->ButtonPressed(); | 117 native_button_->ButtonPressed(); |
116 } | 118 } |
117 | 119 |
| 120 //////////////////////////////////////////////////////////////////////////////// |
| 121 // NativeCheckboxGtk |
118 NativeCheckboxGtk::NativeCheckboxGtk(Checkbox* checkbox) | 122 NativeCheckboxGtk::NativeCheckboxGtk(Checkbox* checkbox) |
119 : NativeButtonGtk(checkbox) { | 123 : NativeButtonGtk(checkbox), |
| 124 checkbox_(checkbox), |
| 125 deliver_click_event_(true) { |
120 } | 126 } |
121 | 127 |
122 void NativeCheckboxGtk::CreateNativeControl() { | 128 void NativeCheckboxGtk::CreateNativeControl() { |
123 GtkWidget* widget = gtk_check_button_new(); | 129 GtkWidget* widget = gtk_check_button_new(); |
| 130 g_signal_connect(G_OBJECT(widget), "clicked", |
| 131 G_CALLBACK(CallClicked), this); |
124 NativeControlCreated(widget); | 132 NativeControlCreated(widget); |
125 } | 133 } |
126 | 134 |
| 135 void NativeCheckboxGtk::OnClicked() { |
| 136 // ignore event if the event is generated by |
| 137 // gtk_toggle_button_set_active below. |
| 138 if (deliver_click_event_) { |
| 139 checkbox_->SetChecked(!checkbox_->checked()); |
| 140 NativeButtonGtk::OnClicked(); |
| 141 } |
| 142 } |
| 143 |
| 144 void NativeCheckboxGtk::UpdateChecked() { |
| 145 if (!native_view()) |
| 146 return; |
| 147 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(native_view())) |
| 148 != checkbox_->checked()) { |
| 149 // gtk_toggle_button_set_active emites "clicked" signal, which |
| 150 // invokes OnClicked method above. deliver_click_event_ flag is used |
| 151 // to prevent such signal to invoke OnClicked callback. |
| 152 deliver_click_event_ = false; |
| 153 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(native_view()), |
| 154 checkbox_->checked()); |
| 155 deliver_click_event_ = true; |
| 156 } |
| 157 } |
| 158 |
| 159 // static |
| 160 void NativeCheckboxGtk::CallClicked(GtkButton* widget, |
| 161 NativeCheckboxGtk* button) { |
| 162 button->OnClicked(); |
| 163 } |
| 164 |
| 165 //////////////////////////////////////////////////////////////////////////////// |
| 166 // NativeButtonWrapper |
| 167 |
127 // static | 168 // static |
128 int NativeButtonWrapper::GetFixedWidth() { | 169 int NativeButtonWrapper::GetFixedWidth() { |
129 // TODO(brettw) implement this properly. | 170 // TODO(brettw) implement this properly. |
130 return 10; | 171 return 10; |
131 } | 172 } |
132 | 173 |
133 // static | 174 // static |
134 NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper( | 175 NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper( |
135 NativeButton* native_button) { | 176 NativeButton* native_button) { |
136 return new NativeButtonGtk(native_button); | 177 return new NativeButtonGtk(native_button); |
137 } | 178 } |
138 | 179 |
139 // static | 180 // static |
140 NativeButtonWrapper* NativeButtonWrapper::CreateCheckboxWrapper( | 181 NativeButtonWrapper* NativeButtonWrapper::CreateCheckboxWrapper( |
141 Checkbox* checkbox) { | 182 Checkbox* checkbox) { |
142 return new NativeCheckboxGtk(checkbox); | 183 return new NativeCheckboxGtk(checkbox); |
143 } | 184 } |
144 | 185 |
145 // static | 186 // static |
146 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( | 187 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( |
147 RadioButton* radio_button) { | 188 RadioButton* radio_button) { |
148 NOTIMPLEMENTED(); | 189 NOTIMPLEMENTED(); |
149 return NULL; | 190 return NULL; |
150 } | 191 } |
151 | 192 |
152 } // namespace views | 193 } // namespace views |
OLD | NEW |