| OLD | NEW |
| 1 // Copyright (c) 2009 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_EXAMPLES_TABLE2_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_ |
| 6 #define VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "app/table_model.h" | 12 #include "app/table_model.h" |
| 12 #include "base/string_util.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "views/controls/button/checkbox.h" | 15 #include "views/controls/button/checkbox.h" |
| 15 #include "views/controls/table/table_view_observer.h" | 16 #include "views/controls/table/table_view_observer.h" |
| 16 #include "views/controls/table/table_view2.h" | 17 #include "views/controls/table/table_view2.h" |
| 17 #include "views/examples/example_base.h" | 18 #include "views/examples/example_base.h" |
| 18 | 19 |
| 19 namespace examples { | 20 namespace examples { |
| 20 | 21 |
| 21 class Table2Example | 22 class Table2Example |
| 22 : public ExampleBase, | 23 : public ExampleBase, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 column3_visible_checkbox_->SetChecked(true); | 45 column3_visible_checkbox_->SetChecked(true); |
| 45 column3_visible_checkbox_->set_listener(this); | 46 column3_visible_checkbox_->set_listener(this); |
| 46 column4_visible_checkbox_ = new views::Checkbox(L"Price column visible"); | 47 column4_visible_checkbox_ = new views::Checkbox(L"Price column visible"); |
| 47 column4_visible_checkbox_->SetChecked(true); | 48 column4_visible_checkbox_->SetChecked(true); |
| 48 column4_visible_checkbox_->set_listener(this); | 49 column4_visible_checkbox_->set_listener(this); |
| 49 | 50 |
| 50 views::GridLayout* layout = new views::GridLayout(container); | 51 views::GridLayout* layout = new views::GridLayout(container); |
| 51 container->SetLayoutManager(layout); | 52 container->SetLayoutManager(layout); |
| 52 | 53 |
| 53 std::vector<TableColumn> columns; | 54 std::vector<TableColumn> columns; |
| 54 columns.push_back(TableColumn(0, L"Fruit", TableColumn::LEFT, 100)); | 55 columns.push_back(TableColumn(0, ASCIIToUTF16("Fruit"), TableColumn::LEFT, |
| 55 columns.push_back(TableColumn(1, L"Color", TableColumn::LEFT, 100)); | 56 100)); |
| 56 columns.push_back(TableColumn(2, L"Origin", TableColumn::LEFT, 100)); | 57 columns.push_back(TableColumn(1, ASCIIToUTF16("Color"), TableColumn::LEFT, |
| 57 columns.push_back(TableColumn(3, L"Price", TableColumn::LEFT, 100)); | 58 100)); |
| 59 columns.push_back(TableColumn(2, ASCIIToUTF16("Origin"), TableColumn::LEFT, |
| 60 100)); |
| 61 columns.push_back(TableColumn(3, ASCIIToUTF16("Price"), TableColumn::LEFT, |
| 62 100)); |
| 58 const int options = (views::TableView2::SINGLE_SELECTION | | 63 const int options = (views::TableView2::SINGLE_SELECTION | |
| 59 views::TableView2::RESIZABLE_COLUMNS | | 64 views::TableView2::RESIZABLE_COLUMNS | |
| 60 views::TableView2::AUTOSIZE_COLUMNS | | 65 views::TableView2::AUTOSIZE_COLUMNS | |
| 61 views::TableView2::HORIZONTAL_LINES | | 66 views::TableView2::HORIZONTAL_LINES | |
| 62 views::TableView2::VERTICAL_LINES); | 67 views::TableView2::VERTICAL_LINES); |
| 63 table_ = new views::TableView2(this, columns, views::ICON_AND_TEXT, | 68 table_ = new views::TableView2(this, columns, views::ICON_AND_TEXT, |
| 64 options); | 69 options); |
| 65 table_->SetObserver(this); | 70 table_->SetObserver(this); |
| 66 icon1.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 71 icon1.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
| 67 icon1.allocPixels(); | 72 icon1.allocPixels(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 layout->AddView(column2_visible_checkbox_); | 100 layout->AddView(column2_visible_checkbox_); |
| 96 layout->AddView(column3_visible_checkbox_); | 101 layout->AddView(column3_visible_checkbox_); |
| 97 layout->AddView(column4_visible_checkbox_); | 102 layout->AddView(column4_visible_checkbox_); |
| 98 } | 103 } |
| 99 | 104 |
| 100 // TableModel implementation: | 105 // TableModel implementation: |
| 101 virtual int RowCount() { | 106 virtual int RowCount() { |
| 102 return 10; | 107 return 10; |
| 103 } | 108 } |
| 104 | 109 |
| 105 virtual std::wstring GetText(int row, int column_id) { | 110 virtual string16 GetText(int row, int column_id) { |
| 106 std::wstring cells[5][5] = { | 111 const char* const cells[5][4] = { |
| 107 { L"Orange", L"Orange", L"South america", L"$5" }, | 112 { "Orange", "Orange", "South america", "$5" }, |
| 108 { L"Apple", L"Green", L"Canada", L"$3" }, | 113 { "Apple", "Green", "Canada", "$3" }, |
| 109 { L"Blue berries", L"Blue", L"Mexico", L"$10.3" }, | 114 { "Blue berries", "Blue", "Mexico", "$10.3" }, |
| 110 { L"Strawberries", L"Red", L"California", L"$7" }, | 115 { "Strawberries", "Red", "California", "$7" }, |
| 111 { L"Cantaloupe", L"Orange", L"South america", L"$5" }, | 116 { "Cantaloupe", "Orange", "South america", "$5" } |
| 112 }; | 117 }; |
| 113 return cells[row % 5][column_id]; | 118 return ASCIIToUTF16(cells[row % 5][column_id]); |
| 114 } | 119 } |
| 115 | 120 |
| 116 virtual SkBitmap GetIcon(int row) { | 121 virtual SkBitmap GetIcon(int row) { |
| 117 return row % 2 ? icon1 : icon2; | 122 return row % 2 ? icon1 : icon2; |
| 118 } | 123 } |
| 119 | 124 |
| 120 virtual void SetObserver(TableModelObserver* observer) { | 125 virtual void SetObserver(TableModelObserver* observer) { |
| 121 } | 126 } |
| 122 | 127 |
| 123 // TableViewObserver implementation: | 128 // TableViewObserver implementation: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 172 |
| 168 SkBitmap icon1; | 173 SkBitmap icon1; |
| 169 SkBitmap icon2; | 174 SkBitmap icon2; |
| 170 | 175 |
| 171 DISALLOW_COPY_AND_ASSIGN(Table2Example); | 176 DISALLOW_COPY_AND_ASSIGN(Table2Example); |
| 172 }; | 177 }; |
| 173 | 178 |
| 174 } // namespace examples | 179 } // namespace examples |
| 175 | 180 |
| 176 #endif // VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_ | 181 #endif // VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_ |
| OLD | NEW |