OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ui/views/examples/table_example.h" | 5 #include "ui/views/examples/table_example.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/views/controls/button/checkbox.h" | 14 #include "ui/views/controls/button/checkbox.h" |
| 15 #include "ui/views/controls/table/group_table_model.h" |
15 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
16 | 17 |
17 namespace views { | 18 namespace views { |
18 namespace examples { | 19 namespace examples { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 ui::TableColumn TestTableColumn(int id, const std::string& title) { | 23 ui::TableColumn TestTableColumn(int id, const std::string& title) { |
23 ui::TableColumn column; | 24 ui::TableColumn column; |
24 column.id = id; | 25 column.id = id; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 GridLayout* layout = new GridLayout(container); | 61 GridLayout* layout = new GridLayout(container); |
61 container->SetLayoutManager(layout); | 62 container->SetLayoutManager(layout); |
62 | 63 |
63 std::vector<ui::TableColumn> columns; | 64 std::vector<ui::TableColumn> columns; |
64 columns.push_back(TestTableColumn(0, "Fruit")); | 65 columns.push_back(TestTableColumn(0, "Fruit")); |
65 columns.push_back(TestTableColumn(1, "Color")); | 66 columns.push_back(TestTableColumn(1, "Color")); |
66 columns.push_back(TestTableColumn(2, "Origin")); | 67 columns.push_back(TestTableColumn(2, "Origin")); |
67 columns.push_back(TestTableColumn(3, "Price")); | 68 columns.push_back(TestTableColumn(3, "Price")); |
68 columns.back().alignment = ui::TableColumn::RIGHT; | 69 columns.back().alignment = ui::TableColumn::RIGHT; |
69 table_ = new TableView(this, columns, ICON_AND_TEXT, true, true, true); | 70 table_ = new TableView(this, columns, ICON_AND_TEXT, true, true, true); |
| 71 table_->SetGrouper(this); |
70 table_->SetObserver(this); | 72 table_->SetObserver(this); |
71 icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 73 icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
72 icon1_.allocPixels(); | 74 icon1_.allocPixels(); |
73 SkCanvas canvas1(icon1_); | 75 SkCanvas canvas1(icon1_); |
74 canvas1.drawColor(SK_ColorRED); | 76 canvas1.drawColor(SK_ColorRED); |
75 | 77 |
76 icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 78 icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
77 icon2_.allocPixels(); | 79 icon2_.allocPixels(); |
78 SkCanvas canvas2(icon2_); | 80 SkCanvas canvas2(icon2_); |
79 canvas2.drawColor(SK_ColorBLUE); | 81 canvas2.drawColor(SK_ColorBLUE); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 }; | 118 }; |
117 return ASCIIToUTF16(cells[row % 5][column_id]); | 119 return ASCIIToUTF16(cells[row % 5][column_id]); |
118 } | 120 } |
119 | 121 |
120 gfx::ImageSkia TableExample::GetIcon(int row) { | 122 gfx::ImageSkia TableExample::GetIcon(int row) { |
121 return row % 2 ? gfx::ImageSkia(icon1_) : gfx::ImageSkia(icon2_); | 123 return row % 2 ? gfx::ImageSkia(icon1_) : gfx::ImageSkia(icon2_); |
122 } | 124 } |
123 | 125 |
124 void TableExample::SetObserver(ui::TableModelObserver* observer) {} | 126 void TableExample::SetObserver(ui::TableModelObserver* observer) {} |
125 | 127 |
| 128 void TableExample::GetGroupRange(int model_index, GroupRange* range) { |
| 129 if (model_index < 2) { |
| 130 range->start = 0; |
| 131 range->length = 2; |
| 132 } else if (model_index > 6) { |
| 133 range->start = 7; |
| 134 range->length = 3; |
| 135 } else { |
| 136 range->start = model_index; |
| 137 range->length = 1; |
| 138 } |
| 139 } |
| 140 |
126 void TableExample::OnSelectionChanged() { | 141 void TableExample::OnSelectionChanged() { |
127 PrintStatus("Selected: %s", | 142 PrintStatus("Selected: %s", |
128 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); | 143 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); |
129 } | 144 } |
130 | 145 |
131 void TableExample::OnDoubleClick() { | 146 void TableExample::OnDoubleClick() { |
132 PrintStatus("Double Click: %s", | 147 PrintStatus("Double Click: %s", |
133 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); | 148 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); |
134 } | 149 } |
135 | 150 |
(...skipping 15 matching lines...) Expand all Loading... |
151 show = column3_visible_checkbox_->checked(); | 166 show = column3_visible_checkbox_->checked(); |
152 } else if (sender == column4_visible_checkbox_) { | 167 } else if (sender == column4_visible_checkbox_) { |
153 index = 3; | 168 index = 3; |
154 show = column4_visible_checkbox_->checked(); | 169 show = column4_visible_checkbox_->checked(); |
155 } | 170 } |
156 table_->SetColumnVisibility(index, show); | 171 table_->SetColumnVisibility(index, show); |
157 } | 172 } |
158 | 173 |
159 } // namespace examples | 174 } // namespace examples |
160 } // namespace views | 175 } // namespace views |
OLD | NEW |