tabbed_pane.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 105e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string16.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/view.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Tab; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TabbedPaneListener; 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabStrip; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TabbedPane is a view that shows tabs. When the user clicks on a tab, the 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// associated view is displayed. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VIEWS_EXPORT TabbedPane : public View { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Internal class name. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kViewClassName[]; 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // |draw_border| indicates whether the tabbed pane should draw a border 27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // around its boundary or not. 28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch explicit TabbedPane(bool draw_border); 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~TabbedPane(); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TabbedPaneListener* listener() const { return listener_; } 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_listener(TabbedPaneListener* listener) { listener_ = listener; } 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int selected_tab_index() const { return selected_tab_index_; } 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the number of tabs. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int GetTabCount(); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the contents of the selected tab or NULL if there is none. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) View* GetSelectedTab(); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a new tab at the end of this TabbedPane with the specified |title|. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |contents| is the view displayed when the tab is selected and is owned by 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the TabbedPane. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddTab(const string16& title, View* contents); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Adds a new tab at |index| with |title|. |contents| is the view displayed 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when the tab is selected and is owned by the TabbedPane. If the tabbed pane 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is currently empty, the new tab is selected. 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void AddTabAtIndex(int index, const string16& title, View* contents); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Selects the tab at |index|, which must be valid. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectTabAt(int index); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Selects |tab| (the tabstrip view, not its content) if it is valid. 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SelectTab(Tab* tab); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from View: 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Size GetPreferredSize() OVERRIDE; 60b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual const char* GetClassName() const OVERRIDE; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch friend class TabStrip; 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the Tab (the tabstrip view, not its content) at the valid |index|. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Tab* GetTabAt(int index); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from View: 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Layout() OVERRIDE; 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void ViewHierarchyChanged( 71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const ViewHierarchyChangedDetails& details) OVERRIDE; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnFocus() OVERRIDE; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A listener notified when tab selection changes. Weak, not owned. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TabbedPaneListener* listener_; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The tab strip and contents container. The child indices of these members 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // correspond to match each Tab with its respective content View. 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabStrip* tab_strip_; 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) View* contents_; 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The selected tab index or -1 if invalid. 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int selected_tab_index_; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TabbedPane); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 93