OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ | |
6 #define VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "ui/base/models/table_model.h" | |
11 #include "views/controls/table/table_view.h" | |
12 | |
13 namespace views { | |
14 | |
15 struct GroupRange { | |
16 int start; | |
17 int length; | |
18 }; | |
19 | |
20 // The model driving the GroupTableView. | |
21 class GroupTableModel : public ui::TableModel { | |
22 public: | |
23 // Populates the passed range with the first row/last row (included) | |
24 // that this item belongs to. | |
25 virtual void GetGroupRangeForItem(int item, GroupRange* range) = 0; | |
26 }; | |
27 | |
28 // GroupTableView adds grouping to the TableView class. | |
29 // It allows to have groups of rows that act as a single row from the selection | |
30 // perspective. Groups are visually separated by a horizontal line. | |
31 class VIEWS_EXPORT GroupTableView : public TableView { | |
32 public: | |
33 // The view class name. | |
34 static const char kViewClassName[]; | |
35 | |
36 GroupTableView(GroupTableModel* model, | |
37 const std::vector<ui::TableColumn>& columns, | |
38 TableTypes table_type, bool single_selection, | |
39 bool resizable_columns, bool autosize_columns, | |
40 bool draw_group_separators); | |
41 virtual ~GroupTableView(); | |
42 | |
43 virtual std::string GetClassName() const; | |
44 | |
45 protected: | |
46 // Notification from the ListView that the selected state of an item has | |
47 // changed. | |
48 void OnSelectedStateChanged(); | |
49 | |
50 // Extra-painting required to draw the separator line between groups. | |
51 virtual bool ImplementPostPaint() { return true; } | |
52 virtual void PostPaint(int model_row, int column, bool selected, | |
53 const gfx::Rect& bounds, HDC device_context); | |
54 | |
55 // In order to make keyboard navigation possible (using the Up and Down | |
56 // keys), we must take action when an arrow key is pressed. The reason we | |
57 // need to process this message has to do with the manner in which the focus | |
58 // needs to be set on a group item when a group is selected. | |
59 virtual bool OnKeyDown(ui::KeyboardCode virtual_keycode); | |
60 | |
61 // Overriden to make sure rows in the same group stay grouped together. | |
62 virtual int CompareRows(int model_row1, int model_row2); | |
63 | |
64 // Updates model_index_to_range_start_map_ from the model. | |
65 virtual void PrepareForSort(); | |
66 | |
67 private: | |
68 // Make the selection of group consistent. | |
69 void SyncSelection(); | |
70 | |
71 GroupTableModel* model_; | |
72 | |
73 // If true, draw separators between groups. | |
74 bool draw_group_separators_; | |
75 | |
76 // A factory to make the selection consistent among groups. | |
77 base::WeakPtrFactory<GroupTableView> sync_selection_factory_; | |
78 | |
79 // Maps from model row to start of group. | |
80 std::map<int,int> model_index_to_range_start_map_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(GroupTableView); | |
83 }; | |
84 | |
85 } // namespace views | |
86 | |
87 #endif // VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ | |
OLD | NEW |