OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef VIEWS_CONTROLS_TABBED_PANE_H_ | 5 #ifndef VIEWS_CONTROLS_TABBED_PANE_H_ |
6 #define VIEWS_CONTROLS_TABBED_PANE_H_ | 6 #define VIEWS_CONTROLS_TABBED_PANE_H_ |
7 | 7 |
8 #include "views/controls/native_control.h" | 8 #include "views/view.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
11 | 11 |
| 12 class NativeTabbedPaneWrapper; |
| 13 |
12 // The TabbedPane class is a view that shows tabs. When the user clicks on a | 14 // The TabbedPane class is a view that shows tabs. When the user clicks on a |
13 // tab, the associated view is displayed. | 15 // tab, the associated view is displayed. |
14 // TODO (jcampan): implement GetPreferredSize(). | 16 // TODO (jcampan): implement GetPreferredSize(). |
15 class WidgetWin; | |
16 | 17 |
17 class TabbedPane : public NativeControl { | 18 class TabbedPane : public View { |
18 public: | 19 public: |
19 TabbedPane(); | 20 TabbedPane(); |
20 virtual ~TabbedPane(); | 21 virtual ~TabbedPane(); |
21 | 22 |
22 // An interface an object can implement to be notified about events within | 23 // An interface an object can implement to be notified about events within |
23 // the TabbedPane. | 24 // the TabbedPane. |
24 class Listener { | 25 class Listener { |
25 public: | 26 public: |
26 // Called when the tab at the specified |index| is selected by the user. | 27 // Called when the tab at the specified |index| is selected by the user. |
27 virtual void TabSelectedAt(int index) = 0; | 28 virtual void TabSelectedAt(int index) = 0; |
28 }; | 29 }; |
29 void SetListener(Listener* listener); | 30 void SetListener(Listener* listener); |
30 | 31 |
| 32 // Returns the number of tabs. |
| 33 int GetTabCount(); |
| 34 |
| 35 // Returns the index of the selected tab. |
| 36 int GetSelectedTabIndex(); |
| 37 |
| 38 // Returns the contents of the selected tab. |
| 39 View* GetSelectedTab(); |
| 40 |
31 // Adds a new tab at the end of this TabbedPane with the specified |title|. | 41 // Adds a new tab at the end of this TabbedPane with the specified |title|. |
32 // |contents| is the view displayed when the tab is selected and is owned by | 42 // |contents| is the view displayed when the tab is selected and is owned by |
33 // the TabbedPane. | 43 // the TabbedPane. |
34 void AddTab(const std::wstring& title, View* contents); | 44 void AddTab(const std::wstring& title, View* contents); |
35 | 45 |
36 // Adds a new tab at the specified |index| with the specified |title|. | 46 // Adds a new tab at the specified |index| with the specified |title|. |
37 // |contents| is the view displayed when the tab is selected and is owned by | 47 // |contents| is the view displayed when the tab is selected and is owned by |
38 // the TabbedPane. If |select_if_first_tab| is true and the tabbed pane is | 48 // the TabbedPane. If |select_if_first_tab| is true and the tabbed pane is |
39 // currently empty, the new tab is selected. If you pass in false for | 49 // currently empty, the new tab is selected. If you pass in false for |
40 // |select_if_first_tab| you need to explicitly invoke SelectTabAt, otherwise | 50 // |select_if_first_tab| you need to explicitly invoke SelectTabAt, otherwise |
41 // the tabbed pane will not have a valid selection. | 51 // the tabbed pane will not have a valid selection. |
42 void AddTabAtIndex(int index, | 52 void AddTabAtIndex(int index, |
43 const std::wstring& title, | 53 const std::wstring& title, |
44 View* contents, | 54 View* contents, |
45 bool select_if_first_tab); | 55 bool select_if_first_tab); |
46 | 56 |
47 // Removes the tab at the specified |index| and returns the associated content | 57 // Removes the tab at the specified |index| and returns the associated content |
48 // view. The caller becomes the owner of the returned view. | 58 // view. The caller becomes the owner of the returned view. |
49 View* RemoveTabAtIndex(int index); | 59 View* RemoveTabAtIndex(int index); |
50 | 60 |
51 // Selects the tab at the specified |index|, which must be valid. | 61 // Selects the tab at the specified |index|, which must be valid. |
52 void SelectTabAt(int index); | 62 void SelectTabAt(int index); |
53 | 63 |
54 // Selects the tab containing the specified |contents|, which must be valid. | 64 Listener* listener() const { return listener_; } |
55 void SelectTabForContents(const View* contents); | |
56 | 65 |
57 // Returns the number of tabs. | 66 // View overrides: |
58 int GetTabCount(); | 67 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
| 68 virtual std::string GetClassName() const; |
| 69 virtual void Layout(); |
| 70 virtual void Focus(); |
59 | 71 |
60 virtual HWND CreateNativeControl(HWND parent_container); | 72 protected: |
61 virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); | 73 // The object that actually implements the tabbed-pane. |
62 | 74 // Protected for tests access. |
63 virtual void Layout(); | 75 NativeTabbedPaneWrapper* native_tabbed_pane_; |
64 | |
65 virtual RootView* GetContentsRootView(); | |
66 virtual FocusTraversable* GetFocusTraversable(); | |
67 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); | |
68 | 76 |
69 private: | 77 private: |
70 // Changes the contents view to the view associated with the tab at |index|. | 78 // The tabbed-pane's class name. |
71 void DoSelectTabAt(int index); | 79 static const char kViewClassName[]; |
72 | 80 |
73 // Returns the index of the tab containing the specified |contents|. | 81 // Creates the native wrapper. |
74 int GetIndexForContents(const View* contents) const; | 82 void CreateWrapper(); |
75 | |
76 void ResizeContents(HWND tab_control); | |
77 | |
78 HWND tab_control_; | |
79 | |
80 // The views associated with the different tabs. | |
81 std::vector<View*> tab_views_; | |
82 | |
83 // The window displayed in the tab. | |
84 WidgetWin* content_window_; | |
85 | 83 |
86 // The listener we notify about tab selection changes. | 84 // The listener we notify about tab selection changes. |
87 Listener* listener_; | 85 Listener* listener_; |
88 | 86 |
89 DISALLOW_EVIL_CONSTRUCTORS(TabbedPane); | 87 DISALLOW_COPY_AND_ASSIGN(TabbedPane); |
90 }; | 88 }; |
91 | 89 |
92 } // namespace views | 90 } // namespace views |
93 | 91 |
94 #endif // #define VIEWS_CONTROLS_TABBED_PANE_H_ | 92 #endif // VIEWS_CONTROLS_TABBED_PANE_H_ |
OLD | NEW |