Home | History | Annotate | Download | only in tabbed_pane
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
      6 #define UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/strings/string16.h"
     11 #include "ui/views/view.h"
     12 
     13 namespace views {
     14 
     15 class Tab;
     16 class TabbedPaneListener;
     17 class TabStrip;
     18 
     19 // TabbedPane is a view that shows tabs. When the user clicks on a tab, the
     20 // associated view is displayed.
     21 class VIEWS_EXPORT TabbedPane : public View {
     22  public:
     23   // Internal class name.
     24   static const char kViewClassName[];
     25 
     26   // |draw_border| indicates whether the tabbed pane should draw a border
     27   // around its boundary or not.
     28   explicit TabbedPane(bool draw_border);
     29   virtual ~TabbedPane();
     30 
     31   TabbedPaneListener* listener() const { return listener_; }
     32   void set_listener(TabbedPaneListener* listener) { listener_ = listener; }
     33 
     34   int selected_tab_index() const { return selected_tab_index_; }
     35 
     36   // Returns the number of tabs.
     37   int GetTabCount();
     38 
     39   // Returns the contents of the selected tab or NULL if there is none.
     40   View* GetSelectedTab();
     41 
     42   // Adds a new tab at the end of this TabbedPane with the specified |title|.
     43   // |contents| is the view displayed when the tab is selected and is owned by
     44   // the TabbedPane.
     45   void AddTab(const string16& title, View* contents);
     46 
     47   // Adds a new tab at |index| with |title|. |contents| is the view displayed
     48   // when the tab is selected and is owned by the TabbedPane. If the tabbed pane
     49   // is currently empty, the new tab is selected.
     50   void AddTabAtIndex(int index, const string16& title, View* contents);
     51 
     52   // Selects the tab at |index|, which must be valid.
     53   void SelectTabAt(int index);
     54 
     55   // Selects |tab| (the tabstrip view, not its content) if it is valid.
     56   void SelectTab(Tab* tab);
     57 
     58   // Overridden from View:
     59   virtual gfx::Size GetPreferredSize() OVERRIDE;
     60   virtual const char* GetClassName() const OVERRIDE;
     61 
     62  private:
     63    friend class TabStrip;
     64 
     65    // Get the Tab (the tabstrip view, not its content) at the valid |index|.
     66    Tab* GetTabAt(int index);
     67 
     68   // Overridden from View:
     69   virtual void Layout() OVERRIDE;
     70   virtual void ViewHierarchyChanged(
     71       const ViewHierarchyChangedDetails& details) OVERRIDE;
     72   virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
     73   virtual void OnFocus() OVERRIDE;
     74   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     75 
     76   // A listener notified when tab selection changes. Weak, not owned.
     77   TabbedPaneListener* listener_;
     78 
     79   // The tab strip and contents container. The child indices of these members
     80   // correspond to match each Tab with its respective content View.
     81   TabStrip* tab_strip_;
     82   View* contents_;
     83 
     84   // The selected tab index or -1 if invalid.
     85   int selected_tab_index_;
     86 
     87   DISALLOW_COPY_AND_ASSIGN(TabbedPane);
     88 };
     89 
     90 }  // namespace views
     91 
     92 #endif  // UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
     93