| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TABLE_TABLE_VIEW2_H_ | 5 #ifndef VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_ |
| 6 #define VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_ | 6 #define VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "build/build_config.h" | |
| 10 | |
| 11 #include <map> | 9 #include <map> |
| 12 #include <vector> | 10 #include <vector> |
| 13 | 11 |
| 14 #include "base/memory/scoped_ptr.h" | 12 #include "base/basictypes.h" |
| 15 #include "ui/gfx/rect.h" | |
| 16 #include "views/controls/table/table_view.h" | |
| 17 #include "views/controls/table/native_table_wrapper.h" | |
| 18 #include "views/view.h" | |
| 19 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/base/models/table_model_observer.h" | 14 #include "ui/base/models/table_model_observer.h" |
| 15 #include "ui/gfx/canvas.h" |
| 16 #include "views/controls/table/native_table_wrapper.h" |
| 17 #include "views/controls/table/table_view.h" |
| 18 #include "views/view.h" |
| 21 | 19 |
| 22 class SkBitmap; | 20 class SkBitmap; |
| 23 | 21 |
| 24 namespace ui { | 22 namespace ui { |
| 25 struct TableColumn; | 23 struct TableColumn; |
| 26 class TableModel; | 24 class TableModel; |
| 27 } | 25 } |
| 28 using ui::TableColumn; | |
| 29 using ui::TableModel; | |
| 30 using ui::TableModelObserver; // TODO(beng): remove these. | |
| 31 | 26 |
| 32 // A TableView2 is a view that displays multiple rows with any number of | 27 // A TableView2 is a view that displays multiple rows with any number of |
| 33 // columns. | 28 // columns. |
| 34 // TableView is driven by a TableModel. The model returns the contents | 29 // TableView is driven by a TableModel. The model returns the contents |
| 35 // to display. TableModel also has an Observer which is used to notify | 30 // to display. TableModel also has an Observer which is used to notify |
| 36 // TableView of changes to the model so that the display may be updated | 31 // TableView of changes to the model so that the display may be updated |
| 37 // appropriately. | 32 // appropriately. |
| 38 // | 33 // |
| 39 // TableView2 itself has an observer that is notified when the selection | 34 // TableView2 itself has an observer that is notified when the selection |
| 40 // changes. | 35 // changes. |
| 41 // | 36 // |
| 42 // TableView2 is the current port of TableView to use a NativeControl for | 37 // TableView2 is the current port of TableView to use a NativeControl for |
| 43 // portability. | 38 // portability. |
| 44 // | 39 // |
| 45 // TODO(jcampan): add sorting. | 40 // TODO(jcampan): add sorting. |
| 46 // TODO(jcampan): add group support. | 41 // TODO(jcampan): add group support. |
| 47 | 42 |
| 48 namespace views { | 43 namespace views { |
| 49 | 44 |
| 50 class ListView; | 45 class ListView; |
| 51 class ListViewParent; | 46 class ListViewParent; |
| 52 class TableView; | 47 class TableView; |
| 53 class TableViewObserver; | 48 class TableViewObserver; |
| 54 class View; | 49 class View; |
| 55 | 50 |
| 56 class VIEWS_EXPORT TableView2 : public View, public TableModelObserver { | 51 class VIEWS_EXPORT TableView2 : public View, public ui::TableModelObserver { |
| 57 public: | 52 public: |
| 58 typedef TableSelectionIterator iterator; | 53 typedef TableSelectionIterator iterator; |
| 59 | 54 |
| 60 // A helper struct for GetCellColors. Set |color_is_set| to true if color is | 55 // A helper struct for GetCellColors. Set |color_is_set| to true if color is |
| 61 // set. See OnCustomDraw for more details on why we need this. | 56 // set. See OnCustomDraw for more details on why we need this. |
| 62 struct ItemColor { | 57 struct ItemColor { |
| 63 bool color_is_set; | 58 bool color_is_set; |
| 64 SkColor color; | 59 SkColor color; |
| 65 }; | 60 }; |
| 66 | 61 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 // column at the right fills the remaining space. | 79 // column at the right fills the remaining space. |
| 85 // When resizable_columns is true, users can resize columns by dragging the | 80 // When resizable_columns is true, users can resize columns by dragging the |
| 86 // separator on the column header. NOTE: Right now this is always true. The | 81 // separator on the column header. NOTE: Right now this is always true. The |
| 87 // code to set it false is still in place to be a base for future, better | 82 // code to set it false is still in place to be a base for future, better |
| 88 // resizing behavior (see http://b/issue?id=874646 ), but no one uses or | 83 // resizing behavior (see http://b/issue?id=874646 ), but no one uses or |
| 89 // tests the case where this flag is false. | 84 // tests the case where this flag is false. |
| 90 // Note that setting both resizable_columns and autosize_columns to false is | 85 // Note that setting both resizable_columns and autosize_columns to false is |
| 91 // probably not a good idea, as there is no way for the user to increase a | 86 // probably not a good idea, as there is no way for the user to increase a |
| 92 // column's size in that case. | 87 // column's size in that case. |
| 93 // |options| is a bitmask of options. See comments at Options. | 88 // |options| is a bitmask of options. See comments at Options. |
| 94 TableView2(TableModel* model, const std::vector<TableColumn>& columns, | 89 TableView2(ui::TableModel* model, const std::vector<ui::TableColumn>& columns, |
| 95 TableTypes table_type, int options); | 90 TableTypes table_type, int options); |
| 96 virtual ~TableView2(); | 91 virtual ~TableView2(); |
| 97 | 92 |
| 98 // Assigns a new model to the table view, detaching the old one if present. | 93 // Assigns a new model to the table view, detaching the old one if present. |
| 99 // If |model| is NULL, the table view cannot be used after this call. This | 94 // If |model| is NULL, the table view cannot be used after this call. This |
| 100 // should be called in the containing view's destructor to avoid destruction | 95 // should be called in the containing view's destructor to avoid destruction |
| 101 // issues when the model needs to be deleted before the table. | 96 // issues when the model needs to be deleted before the table. |
| 102 void SetModel(TableModel* model); | 97 void SetModel(ui::TableModel* model); |
| 103 TableModel* model() const { return model_; } | 98 ui::TableModel* model() const { return model_; } |
| 104 | 99 |
| 105 // Returns the number of rows in the table. | 100 // Returns the number of rows in the table. |
| 106 int GetRowCount(); | 101 int GetRowCount(); |
| 107 | 102 |
| 108 // Returns the number of selected rows. | 103 // Returns the number of selected rows. |
| 109 int SelectedRowCount(); | 104 int SelectedRowCount(); |
| 110 | 105 |
| 111 // Makes all row not selected. | 106 // Makes all row not selected. |
| 112 void ClearSelection(); | 107 void ClearSelection(); |
| 113 | 108 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 bool IsRowFocused(int model_row); | 128 bool IsRowFocused(int model_row); |
| 134 | 129 |
| 135 // Returns an iterator over the selection. The iterator proceeds from the | 130 // Returns an iterator over the selection. The iterator proceeds from the |
| 136 // last index to the first. | 131 // last index to the first. |
| 137 // | 132 // |
| 138 // NOTE: the iterator iterates over the visual order (but returns coordinates | 133 // NOTE: the iterator iterates over the visual order (but returns coordinates |
| 139 // in terms of the model). | 134 // in terms of the model). |
| 140 iterator SelectionBegin(); | 135 iterator SelectionBegin(); |
| 141 iterator SelectionEnd(); | 136 iterator SelectionEnd(); |
| 142 | 137 |
| 143 // TableModelObserver methods. | 138 // ui::TableModelObserver methods. |
| 144 virtual void OnModelChanged(); | 139 virtual void OnModelChanged(); |
| 145 virtual void OnItemsChanged(int start, int length); | 140 virtual void OnItemsChanged(int start, int length); |
| 146 virtual void OnItemsAdded(int start, int length); | 141 virtual void OnItemsAdded(int start, int length); |
| 147 virtual void OnItemsRemoved(int start, int length); | 142 virtual void OnItemsRemoved(int start, int length); |
| 148 | 143 |
| 149 void SetObserver(TableViewObserver* observer) { | 144 void SetObserver(TableViewObserver* observer) { |
| 150 table_view_observer_ = observer; | 145 table_view_observer_ = observer; |
| 151 } | 146 } |
| 152 TableViewObserver* observer() const { return table_view_observer_; } | 147 TableViewObserver* observer() const { return table_view_observer_; } |
| 153 | 148 |
| 154 // Replaces the set of known columns without changing the current visible | 149 // Replaces the set of known columns without changing the current visible |
| 155 // columns. | 150 // columns. |
| 156 void SetColumns(const std::vector<TableColumn>& columns); | 151 void SetColumns(const std::vector<ui::TableColumn>& columns); |
| 157 void AddColumn(const TableColumn& col); | 152 void AddColumn(const ui::TableColumn& col); |
| 158 bool HasColumn(int id); | 153 bool HasColumn(int id); |
| 159 | 154 |
| 160 // Sets which columns (by id) are displayed. All transient size and position | 155 // Sets which columns (by id) are displayed. All transient size and position |
| 161 // information is lost. | 156 // information is lost. |
| 162 void SetVisibleColumns(const std::vector<int>& columns); | 157 void SetVisibleColumns(const std::vector<int>& columns); |
| 163 void SetColumnVisibility(int id, bool is_visible); | 158 void SetColumnVisibility(int id, bool is_visible); |
| 164 bool IsColumnVisible(int id) const; | 159 bool IsColumnVisible(int id) const; |
| 165 | 160 |
| 166 TableColumn GetVisibleColumnAt(int index); | 161 ui::TableColumn GetVisibleColumnAt(int index); |
| 167 size_t GetVisibleColumnCount(); | 162 size_t GetVisibleColumnCount(); |
| 168 | 163 |
| 169 // Resets the size of the columns based on the sizes passed to the | 164 // Resets the size of the columns based on the sizes passed to the |
| 170 // constructor. Your normally needn't invoked this, it's done for you the | 165 // constructor. Your normally needn't invoked this, it's done for you the |
| 171 // first time the TableView is given a valid size. | 166 // first time the TableView is given a valid size. |
| 172 void ResetColumnSizes(); | 167 void ResetColumnSizes(); |
| 173 | 168 |
| 174 bool single_selection() const { | 169 bool single_selection() const { |
| 175 return single_selection_; | 170 return single_selection_; |
| 176 } | 171 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 virtual void OnPaintFocusBorder(gfx::Canvas* canvas); | 195 virtual void OnPaintFocusBorder(gfx::Canvas* canvas); |
| 201 | 196 |
| 202 // Used by tests. | 197 // Used by tests. |
| 203 virtual gfx::NativeView GetTestingHandle(); | 198 virtual gfx::NativeView GetTestingHandle(); |
| 204 | 199 |
| 205 protected: | 200 protected: |
| 206 virtual NativeTableWrapper* CreateWrapper(); | 201 virtual NativeTableWrapper* CreateWrapper(); |
| 207 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); | 202 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
| 208 | 203 |
| 209 private: | 204 private: |
| 205 friend class ListViewParent; |
| 206 friend class TableSelectionIterator; |
| 207 |
| 210 // Used in the constructors. | 208 // Used in the constructors. |
| 211 void Init(const std::vector<TableColumn>& columns); | 209 void Init(const std::vector<ui::TableColumn>& columns); |
| 212 | 210 |
| 213 // We need this wrapper to pass the table view to the windows proc handler | 211 // We need this wrapper to pass the table view to the windows proc handler |
| 214 // when subclassing the list view and list view header, as the reinterpret | 212 // when subclassing the list view and list view header, as the reinterpret |
| 215 // cast from GetWindowLongPtr would break the pointer if it is pointing to a | 213 // cast from GetWindowLongPtr would break the pointer if it is pointing to a |
| 216 // subclass (in the OO sense of TableView). | 214 // subclass (in the OO sense of TableView). |
| 217 struct TableViewWrapper { | 215 struct TableViewWrapper { |
| 218 explicit TableViewWrapper(TableView2* view) : table_view(view) { } | 216 explicit TableViewWrapper(TableView2* view) : table_view(view) { } |
| 219 TableView2* table_view; | 217 TableView2* table_view; |
| 220 }; | 218 }; |
| 221 | 219 |
| 222 friend class ListViewParent; | |
| 223 friend class TableSelectionIterator; | |
| 224 | |
| 225 // Adds a new column. | 220 // Adds a new column. |
| 226 void InsertColumn(const TableColumn& tc, int index); | 221 void InsertColumn(const ui::TableColumn& tc, int index); |
| 227 | 222 |
| 228 // Update headers and internal state after columns have changed | 223 // Update headers and internal state after columns have changed |
| 229 void OnColumnsChanged(); | 224 void OnColumnsChanged(); |
| 230 | 225 |
| 231 TableModel* model_; | 226 ui::TableModel* model_; |
| 232 TableTypes table_type_; | 227 TableTypes table_type_; |
| 233 TableViewObserver* table_view_observer_; | 228 TableViewObserver* table_view_observer_; |
| 234 | 229 |
| 235 // An ordered list of id's into all_columns_ representing current visible | 230 // An ordered list of id's into all_columns_ representing current visible |
| 236 // columns. | 231 // columns. |
| 237 std::vector<int> visible_columns_; | 232 std::vector<int> visible_columns_; |
| 238 | 233 |
| 239 // Mapping of an int id to a TableColumn representing all possible columns. | 234 // Mapping of an int id to a TableColumn representing all possible columns. |
| 240 std::map<int, TableColumn> all_columns_; | 235 std::map<int, ui::TableColumn> all_columns_; |
| 241 | 236 |
| 242 // Cached value of columns_.size() | 237 // Cached value of columns_.size() |
| 243 int column_count_; | 238 int column_count_; |
| 244 | 239 |
| 245 // Selection mode. | 240 // Selection mode. |
| 246 bool single_selection_; | 241 bool single_selection_; |
| 247 | 242 |
| 248 // Whether or not the user can resize columns. | 243 // Whether or not the user can resize columns. |
| 249 bool resizable_columns_; | 244 bool resizable_columns_; |
| 250 | 245 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 264 | 259 |
| 265 // The object that actually implements the table. | 260 // The object that actually implements the table. |
| 266 NativeTableWrapper* native_wrapper_; | 261 NativeTableWrapper* native_wrapper_; |
| 267 | 262 |
| 268 DISALLOW_COPY_AND_ASSIGN(TableView2); | 263 DISALLOW_COPY_AND_ASSIGN(TableView2); |
| 269 }; | 264 }; |
| 270 | 265 |
| 271 } // namespace views | 266 } // namespace views |
| 272 | 267 |
| 273 #endif // VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_ | 268 #endif // VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_ |
| OLD | NEW |