| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/tabbed_pane/native_tabbed_pane_gtk.h" | 5 #include "views/controls/tabbed_pane/native_tabbed_pane_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 WidgetGtk* widget = WidgetGtk::GetViewForNative(page); | 68 WidgetGtk* widget = WidgetGtk::GetViewForNative(page); |
| 69 | 69 |
| 70 // detach the content view from widget so that we can delete widget | 70 // detach the content view from widget so that we can delete widget |
| 71 // without destroying the content view. | 71 // without destroying the content view. |
| 72 View* removed_tab = GetTabViewAt(index); | 72 View* removed_tab = GetTabViewAt(index); |
| 73 widget->GetRootView()->RemoveChildView(removed_tab); | 73 widget->GetRootView()->RemoveChildView(removed_tab); |
| 74 | 74 |
| 75 // widget delete itself when native_view is deleted. | 75 // widget delete itself when native_view is deleted. |
| 76 gtk_notebook_remove_page(GTK_NOTEBOOK(native_view()), index); | 76 gtk_notebook_remove_page(GTK_NOTEBOOK(native_view()), index); |
| 77 | 77 |
| 78 // Removing a tab might change the size of the tabbed pane. |
| 79 RootView* root_view = GetRootView(); |
| 80 if (root_view) |
| 81 GetRootView()->Layout(); |
| 82 |
| 78 return removed_tab; | 83 return removed_tab; |
| 79 } | 84 } |
| 80 | 85 |
| 81 void NativeTabbedPaneGtk::SelectTabAt(int index) { | 86 void NativeTabbedPaneGtk::SelectTabAt(int index) { |
| 82 DCHECK((index >= 0) && (index < GetTabCount())); | 87 DCHECK((index >= 0) && (index < GetTabCount())); |
| 83 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), index); | 88 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), index); |
| 84 } | 89 } |
| 85 | 90 |
| 86 int NativeTabbedPaneGtk::GetTabCount() { | 91 int NativeTabbedPaneGtk::GetTabCount() { |
| 87 return gtk_notebook_get_n_pages(GTK_NOTEBOOK(native_view())); | 92 return gtk_notebook_get_n_pages(GTK_NOTEBOOK(native_view())); |
| 88 } | 93 } |
| 89 | 94 |
| 90 int NativeTabbedPaneGtk::GetSelectedTabIndex() { | 95 int NativeTabbedPaneGtk::GetSelectedTabIndex() { |
| 91 return gtk_notebook_get_current_page(GTK_NOTEBOOK(native_view())); | 96 return gtk_notebook_get_current_page(GTK_NOTEBOOK(native_view())); |
| 92 } | 97 } |
| 93 | 98 |
| 94 View* NativeTabbedPaneGtk::GetSelectedTab() { | 99 View* NativeTabbedPaneGtk::GetSelectedTab() { |
| 95 return GetTabViewAt(GetSelectedTabIndex()); | 100 return GetTabViewAt(GetSelectedTabIndex()); |
| 96 } | 101 } |
| 97 | 102 |
| 98 View* NativeTabbedPaneGtk::GetView() { | 103 View* NativeTabbedPaneGtk::GetView() { |
| 99 return this; | 104 return this; |
| 100 } | 105 } |
| 101 | 106 |
| 102 void NativeTabbedPaneGtk::SetFocus() { | 107 void NativeTabbedPaneGtk::SetFocus() { |
| 103 Focus(); | 108 Focus(); |
| 104 } | 109 } |
| 105 | 110 |
| 111 gfx::Size NativeTabbedPaneGtk::GetPreferredSize() { |
| 112 if (!native_view()) |
| 113 return gfx::Size(); |
| 114 |
| 115 // For some strange reason (or maybe it's a bug), the requisition is not |
| 116 // returned in the passed requisition parameter, but instead written to the |
| 117 // widget's requisition field. |
| 118 GtkRequisition requisition = { 0, 0 }; |
| 119 gtk_widget_size_request(GTK_WIDGET(native_view()), &requisition); |
| 120 GtkRequisition& size(GTK_WIDGET(native_view())->requisition); |
| 121 return gfx::Size(size.width, size.height); |
| 122 } |
| 123 |
| 106 gfx::NativeView NativeTabbedPaneGtk::GetTestingHandle() const { | 124 gfx::NativeView NativeTabbedPaneGtk::GetTestingHandle() const { |
| 107 return native_view(); | 125 return native_view(); |
| 108 } | 126 } |
| 109 | 127 |
| 110 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 111 // NativeTabbedPaneGtk, NativeControlGtk override: | 129 // NativeTabbedPaneGtk, NativeControlGtk override: |
| 112 | 130 |
| 113 void NativeTabbedPaneGtk::CreateNativeControl() { | 131 void NativeTabbedPaneGtk::CreateNativeControl() { |
| 114 GtkWidget* widget = gtk_notebook_new(); | 132 GtkWidget* widget = gtk_notebook_new(); |
| 115 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), GTK_POS_TOP); | 133 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), GTK_POS_TOP); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 GtkWidget* label = gtk_label_new(WideToUTF8(title).c_str()); | 177 GtkWidget* label = gtk_label_new(WideToUTF8(title).c_str()); |
| 160 gtk_widget_show(label); | 178 gtk_widget_show(label); |
| 161 gtk_notebook_insert_page(GTK_NOTEBOOK(native_view()), | 179 gtk_notebook_insert_page(GTK_NOTEBOOK(native_view()), |
| 162 page, | 180 page, |
| 163 label, | 181 label, |
| 164 index); | 182 index); |
| 165 g_object_unref(page); | 183 g_object_unref(page); |
| 166 | 184 |
| 167 if (tab_count == 0 && select_if_first_tab) | 185 if (tab_count == 0 && select_if_first_tab) |
| 168 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), 0); | 186 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), 0); |
| 187 |
| 188 // Relayout the hierarchy, since the added tab might require more space. |
| 189 RootView* root_view = GetRootView(); |
| 190 if (root_view) |
| 191 GetRootView()->Layout(); |
| 169 } | 192 } |
| 170 | 193 |
| 171 WidgetGtk* NativeTabbedPaneGtk::GetWidgetAt(int index) { | 194 WidgetGtk* NativeTabbedPaneGtk::GetWidgetAt(int index) { |
| 172 DCHECK(index <= GetTabCount()); | 195 DCHECK(index <= GetTabCount()); |
| 173 GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), | 196 GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), |
| 174 index); | 197 index); |
| 175 WidgetGtk* widget = WidgetGtk::GetViewForNative(page); | 198 WidgetGtk* widget = WidgetGtk::GetViewForNative(page); |
| 176 DCHECK(widget); | 199 DCHECK(widget); |
| 177 return widget; | 200 return widget; |
| 178 } | 201 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 200 //////////////////////////////////////////////////////////////////////////////// | 223 //////////////////////////////////////////////////////////////////////////////// |
| 201 // NativeTabbedPaneWrapper, public: | 224 // NativeTabbedPaneWrapper, public: |
| 202 | 225 |
| 203 // static | 226 // static |
| 204 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper( | 227 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper( |
| 205 TabbedPane* tabbed_pane) { | 228 TabbedPane* tabbed_pane) { |
| 206 return new NativeTabbedPaneGtk(tabbed_pane); | 229 return new NativeTabbedPaneGtk(tabbed_pane); |
| 207 } | 230 } |
| 208 | 231 |
| 209 } // namespace views | 232 } // namespace views |
| OLD | NEW |