summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:02:06 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:02:06 +0000
commited157a21f003e2dd212d84fa81663c8fc95c8965 (patch)
tree316ae89593d61287ad823de3f6f607ef9c3befa7 /views
parent4c5368e69adf1ae4f234785ec20fd8c2384e7b67 (diff)
downloadchromium_src-ed157a21f003e2dd212d84fa81663c8fc95c8965.zip
chromium_src-ed157a21f003e2dd212d84fa81663c8fc95c8965.tar.gz
chromium_src-ed157a21f003e2dd212d84fa81663c8fc95c8965.tar.bz2
Lands http://codereview.chromium.org/185003 for Oshima:
* gtk implemenation of tabbed pane * focus is not handled as Jay is working on it. BUG=none TEST=none Review URL: http://codereview.chromium.org/171120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_gtk.cc175
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_gtk.h60
-rw-r--r--views/views.gyp2
3 files changed, 237 insertions, 0 deletions
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
new file mode 100644
index 0000000..855ce805
--- /dev/null
+++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
@@ -0,0 +1,175 @@
+// 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 "views/controls/tabbed_pane/native_tabbed_pane_gtk.h"
+
+#include <gtk/gtk.h>
+
+#include "app/gfx/canvas.h"
+#include "app/gfx/font.h"
+#include "app/resource_bundle.h"
+#include "base/logging.h"
+#include "base/stl_util-inl.h"
+#include "base/string_util.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/fill_layout.h"
+#include "views/widget/root_view.h"
+#include "views/widget/widget_gtk.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeTabbedPaneGtk, public:
+
+NativeTabbedPaneGtk::NativeTabbedPaneGtk(TabbedPane* tabbed_pane)
+ : NativeControlGtk(),
+ tabbed_pane_(tabbed_pane) {
+ set_focus_view(tabbed_pane);
+}
+
+NativeTabbedPaneGtk::~NativeTabbedPaneGtk() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeTabbedPaneGtk, NativeTabbedPaneWrapper implementation:
+
+void NativeTabbedPaneGtk::AddTab(const std::wstring& title, View* contents) {
+ AddTabAtIndex(GetTabCount(), title, contents, true);
+}
+
+void NativeTabbedPaneGtk::AddTabAtIndex(int index, const std::wstring& title,
+ View* contents,
+ bool select_if_first_tab) {
+ DCHECK(native_view());
+ DoAddTabAtIndex(index, title, contents, select_if_first_tab);
+}
+
+View* NativeTabbedPaneGtk::RemoveTabAtIndex(int index) {
+ int tab_count = GetTabCount();
+ DCHECK(index >= 0 && index < tab_count);
+
+ if (index < (tab_count - 1)) {
+ // Select the next tab.
+ SelectTabAt(index + 1);
+ } else {
+ // We are the last tab, select the previous one.
+ if (index > 0) {
+ SelectTabAt(index - 1);
+ } else {
+ // last tab. nothing to select.
+ }
+ }
+ View* removed_tab = GetTabViewAt(index);
+
+ gtk_notebook_remove_page(GTK_NOTEBOOK(native_view()), index);
+
+ return removed_tab;
+}
+
+void NativeTabbedPaneGtk::SelectTabAt(int index) {
+ DCHECK((index >= 0) && (index < GetTabCount()));
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), index);
+}
+
+int NativeTabbedPaneGtk::GetTabCount() {
+ return gtk_notebook_get_n_pages(GTK_NOTEBOOK(native_view()));
+}
+
+int NativeTabbedPaneGtk::GetSelectedTabIndex() {
+ return gtk_notebook_get_current_page(GTK_NOTEBOOK(native_view()));
+}
+
+View* NativeTabbedPaneGtk::GetSelectedTab() {
+ return GetTabViewAt(GetSelectedTabIndex());
+}
+
+View* NativeTabbedPaneGtk::GetView() {
+ return this;
+}
+
+void NativeTabbedPaneGtk::SetFocus() {
+ Focus();
+}
+
+gfx::NativeView NativeTabbedPaneGtk::GetTestingHandle() const {
+ return native_view();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeTabbedPaneGtk, NativeControlGtk override:
+
+void NativeTabbedPaneGtk::CreateNativeControl() {
+ GtkWidget* widget = gtk_notebook_new();
+ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), GTK_POS_TOP);
+ g_signal_connect(G_OBJECT(widget), "switch-page",
+ G_CALLBACK(CallSwitchPage), this);
+ NativeControlCreated(widget);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeTabbedPaneGtk, private:
+void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, const std::wstring& title,
+ View* contents,
+ bool select_if_first_tab) {
+ int tab_count = GetTabCount();
+ DCHECK(index <= tab_count);
+
+ WidgetGtk* page_container = new WidgetGtk(WidgetGtk::TYPE_CHILD);
+ page_container->Init(NULL, gfx::Rect());
+ page_container->SetContentsView(contents);
+ page_container->Show();
+
+ GtkWidget* page = page_container->GetNativeView();
+
+ // increment ref count not to delete on remove below
+ g_object_ref(page);
+ // detach parent from the page so that we can add it to notebook
+ GtkWidget* parent = gtk_widget_get_parent(page);
+ gtk_container_remove(GTK_CONTAINER(parent), page);
+
+ GtkWidget* label = gtk_label_new(WideToUTF8(title).c_str());
+ gtk_widget_show(label);
+ gtk_notebook_insert_page(GTK_NOTEBOOK(native_view()),
+ page,
+ label,
+ index);
+ g_object_unref(page);
+
+ if (tab_count == 0 && select_if_first_tab)
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), 0);
+}
+
+View* NativeTabbedPaneGtk::GetTabViewAt(int index) {
+ DCHECK(index <= GetTabCount());
+ GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()),
+ index);
+ WidgetGtk* widget = WidgetGtk::GetViewForNative(page);
+ DCHECK(widget && widget->GetRootView()->GetChildViewCount() == 1);
+ return widget->GetRootView()->GetChildViewAt(0);
+}
+
+void NativeTabbedPaneGtk::OnSwitchPage(int selected_tab_index) {
+ TabbedPane::Listener* listener = tabbed_pane_->listener();
+ if (listener != NULL)
+ listener->TabSelectedAt(selected_tab_index);
+}
+
+// static
+void NativeTabbedPaneGtk::CallSwitchPage(GtkNotebook* widget,
+ GtkNotebookPage* page,
+ guint selected_tab_index,
+ NativeTabbedPaneGtk* tabbed_pane) {
+ tabbed_pane->OnSwitchPage(selected_tab_index);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeTabbedPaneWrapper, public:
+
+// static
+NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper(
+ TabbedPane* tabbed_pane) {
+ return new NativeTabbedPaneGtk(tabbed_pane);
+}
+
+} // namespace views
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.h b/views/controls/tabbed_pane/native_tabbed_pane_gtk.h
new file mode 100644
index 0000000..63a70f7
--- /dev/null
+++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_GTK_H_
+#define VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_GTK_H_
+
+#include "views/controls/native_control_gtk.h"
+#include "views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
+
+namespace views {
+
+class WidgetGtk;
+
+class NativeTabbedPaneGtk : public NativeControlGtk,
+ public NativeTabbedPaneWrapper {
+ public:
+ explicit NativeTabbedPaneGtk(TabbedPane* tabbed_pane);
+ virtual ~NativeTabbedPaneGtk();
+
+ // NativeTabbedPaneWrapper implementation:
+ virtual void AddTab(const std::wstring& title, View* contents);
+ virtual void AddTabAtIndex(int index,
+ const std::wstring& title,
+ View* contents,
+ bool select_if_first_tab);
+ virtual View* RemoveTabAtIndex(int index);
+ virtual void SelectTabAt(int index);
+ virtual int GetTabCount();
+ virtual int GetSelectedTabIndex();
+ virtual View* GetSelectedTab();
+ virtual View* GetView();
+ virtual void SetFocus();
+ virtual gfx::NativeView GetTestingHandle() const;
+
+ // NativeControlGtk overrides.
+ virtual void CreateNativeControl();
+
+ private:
+ void DoAddTabAtIndex(int index,
+ const std::wstring& title,
+ View* contents,
+ bool select_if_first_tab);
+ View* GetTabViewAt(int index);
+ void OnSwitchPage(int selected_tab_index);
+
+ static void CallSwitchPage(GtkNotebook* widget,
+ GtkNotebookPage* page,
+ guint selected_tab_index,
+ NativeTabbedPaneGtk* tabbed_pane);
+
+ // The tabbed-pane we are bound to.
+ TabbedPane* tabbed_pane_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeTabbedPaneGtk);
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_GTK_H_
diff --git a/views/views.gyp b/views/views.gyp
index 946c9bd..573986f 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -172,6 +172,8 @@
'controls/single_split_view.h',
'controls/tabbed_pane/tabbed_pane.cc',
'controls/tabbed_pane/tabbed_pane.h',
+ 'controls/tabbed_pane/native_tabbed_pane_gtk.cc',
+ 'controls/tabbed_pane/native_tabbed_pane_gtk.h',
'controls/tabbed_pane/native_tabbed_pane_win.cc',
'controls/tabbed_pane/native_tabbed_pane_win.h',
'controls/tabbed_pane/native_tabbed_pane_wrapper.h',