Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: ui/views/examples/table_example.cc

Issue 11827007: Couple of tweaks for tables: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add #ifdef for SetGrouper in example Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/examples/table_example.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(sky): remove ifdef once we get rid of win32 table.
72 #if defined(USE_AURA)
73 table_->SetGrouper(this);
74 #endif
70 table_->SetObserver(this); 75 table_->SetObserver(this);
71 icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); 76 icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
72 icon1_.allocPixels(); 77 icon1_.allocPixels();
73 SkCanvas canvas1(icon1_); 78 SkCanvas canvas1(icon1_);
74 canvas1.drawColor(SK_ColorRED); 79 canvas1.drawColor(SK_ColorRED);
75 80
76 icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); 81 icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
77 icon2_.allocPixels(); 82 icon2_.allocPixels();
78 SkCanvas canvas2(icon2_); 83 SkCanvas canvas2(icon2_);
79 canvas2.drawColor(SK_ColorBLUE); 84 canvas2.drawColor(SK_ColorBLUE);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 }; 121 };
117 return ASCIIToUTF16(cells[row % 5][column_id]); 122 return ASCIIToUTF16(cells[row % 5][column_id]);
118 } 123 }
119 124
120 gfx::ImageSkia TableExample::GetIcon(int row) { 125 gfx::ImageSkia TableExample::GetIcon(int row) {
121 return row % 2 ? gfx::ImageSkia(icon1_) : gfx::ImageSkia(icon2_); 126 return row % 2 ? gfx::ImageSkia(icon1_) : gfx::ImageSkia(icon2_);
122 } 127 }
123 128
124 void TableExample::SetObserver(ui::TableModelObserver* observer) {} 129 void TableExample::SetObserver(ui::TableModelObserver* observer) {}
125 130
131 void TableExample::GetGroupRange(int model_index, GroupRange* range) {
132 if (model_index < 2) {
133 range->start = 0;
134 range->length = 2;
135 } else if (model_index > 6) {
136 range->start = 7;
137 range->length = 3;
138 } else {
139 range->start = model_index;
140 range->length = 1;
141 }
142 }
143
126 void TableExample::OnSelectionChanged() { 144 void TableExample::OnSelectionChanged() {
127 PrintStatus("Selected: %s", 145 PrintStatus("Selected: %s",
128 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); 146 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str());
129 } 147 }
130 148
131 void TableExample::OnDoubleClick() { 149 void TableExample::OnDoubleClick() {
132 PrintStatus("Double Click: %s", 150 PrintStatus("Double Click: %s",
133 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str()); 151 UTF16ToASCII(GetText(table_->FirstSelectedRow(), 0)).c_str());
134 } 152 }
135 153
(...skipping 15 matching lines...) Expand all
151 show = column3_visible_checkbox_->checked(); 169 show = column3_visible_checkbox_->checked();
152 } else if (sender == column4_visible_checkbox_) { 170 } else if (sender == column4_visible_checkbox_) {
153 index = 3; 171 index = 3;
154 show = column4_visible_checkbox_->checked(); 172 show = column4_visible_checkbox_->checked();
155 } 173 }
156 table_->SetColumnVisibility(index, show); 174 table_->SetColumnVisibility(index, show);
157 } 175 }
158 176
159 } // namespace examples 177 } // namespace examples
160 } // namespace views 178 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/table_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698