summaryrefslogtreecommitdiffstats
path: root/views/controls/button/native_button_gtk.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 21:59:06 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 21:59:06 +0000
commit1558020441c8b594993252707f610dc2de481bad (patch)
tree2f5e0ea5af1965f9820c2979e7b79237ba17ef53 /views/controls/button/native_button_gtk.cc
parentb6ca264f3c8d6b010e92774f1ef508dc3c39604e (diff)
downloadchromium_src-1558020441c8b594993252707f610dc2de481bad.zip
chromium_src-1558020441c8b594993252707f610dc2de481bad.tar.gz
chromium_src-1558020441c8b594993252707f610dc2de481bad.tar.bz2
Adds back some code removed during Ben's landing of views renaming.
Adds support for GTK buttons. BUG=none TEST=none Review URL: http://codereview.chromium.org/113212 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button/native_button_gtk.cc')
-rw-r--r--views/controls/button/native_button_gtk.cc95
1 files changed, 95 insertions, 0 deletions
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
new file mode 100644
index 0000000..e140b21
--- /dev/null
+++ b/views/controls/button/native_button_gtk.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include <gtk/gtk.h>
+
+#include "views/controls/button/native_button_gtk.h"
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/button/native_button.h"
+#include "views/controls/button/radio_button.h"
+#include "views/widget/widget.h"
+
+namespace views {
+
+NativeButtonGtk::NativeButtonGtk(NativeButton* native_button)
+ : NativeControlGtk(),
+ native_button_(native_button) {
+ // Associates the actual GtkWidget with the native_button so the native_button
+ // is the one considered as having the focus (not the wrapper) when the
+ // GtkWidget is focused directly (with a click for example).
+ SetAssociatedFocusView(native_button);
+}
+
+NativeButtonGtk::~NativeButtonGtk() {
+}
+
+void NativeButtonGtk::UpdateLabel() {
+ if (!native_view())
+ return;
+
+ gtk_button_set_label(GTK_BUTTON(native_view()),
+ WideToUTF8(native_button_->label()).c_str());
+}
+
+void NativeButtonGtk::UpdateFont() {
+ if (!native_view())
+ return;
+
+ NOTIMPLEMENTED();
+ // SendMessage(GetHWND(), WM_SETFONT,
+ // reinterpret_cast<WPARAM>(native_button_->font().hfont()),
+ // FALSE);
+}
+
+void NativeButtonGtk::UpdateEnabled() {
+ if (!native_view())
+ return;
+ SetEnabled(native_button_->IsEnabled());
+}
+
+void NativeButtonGtk::UpdateDefault() {
+ if (!native_view())
+ return;
+ if (!IsCheckbox())
+ NOTIMPLEMENTED();
+}
+
+View* NativeButtonGtk::GetView() {
+ return this;
+}
+
+void NativeButtonGtk::SetFocus() {
+ // Focus the associated widget.
+ Focus();
+}
+
+gfx::Size NativeButtonGtk::GetPreferredSize() {
+ GtkRequisition size_request = { 0, 0 };
+ gtk_widget_size_request(native_view(), &size_request);
+ return gfx::Size(size_request.width, size_request.height);
+}
+
+void NativeButtonGtk::CreateNativeControl() {
+ GtkWidget* widget = gtk_button_new();
+ NativeControlCreated(widget);
+}
+
+void NativeButtonGtk::NativeControlCreated(GtkWidget* widget) {
+ NativeControlGtk::NativeControlCreated(widget);
+
+ UpdateFont();
+ UpdateLabel();
+ UpdateDefault();
+}
+
+// static
+NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper(
+ NativeButton* native_button) {
+ return new NativeButtonGtk(native_button);
+}
+
+} // namespace views