summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-23 15:19:06 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-23 15:19:06 +0000
commit7a028d30364d6712b0f13bf897714e0ce4f3787b (patch)
treeb7626fe9e6cf4549361034a6a71f16c6b74bd674 /views
parent5e9aca2ab199d6a93fd1f060c2dd84e769f26482 (diff)
downloadchromium_src-7a028d30364d6712b0f13bf897714e0ce4f3787b.zip
chromium_src-7a028d30364d6712b0f13bf897714e0ce4f3787b.tar.gz
chromium_src-7a028d30364d6712b0f13bf897714e0ce4f3787b.tar.bz2
views: Add table2_example to views_examples target.
Also move the implementation from header to the source file. BUG=None TEST=run out/Debug/views_examples, everything should works as before. Review URL: http://codereview.chromium.org/6264010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/examples/table2_example.cc154
-rw-r--r--views/examples/table2_example.h190
-rw-r--r--views/views.gyp2
3 files changed, 196 insertions, 150 deletions
diff --git a/views/examples/table2_example.cc b/views/examples/table2_example.cc
new file mode 100644
index 0000000..1d25430
--- /dev/null
+++ b/views/examples/table2_example.cc
@@ -0,0 +1,154 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/examples/table2_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/table/table_view2.h"
+#include "views/grid_layout.h"
+
+namespace examples {
+
+Table2Example::Table2Example(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+Table2Example::~Table2Example() {
+}
+
+std::wstring Table2Example::GetExampleTitle() {
+ return L"Table2";
+}
+
+void Table2Example::CreateExampleView(views::View* container) {
+ column1_visible_checkbox_ = new views::Checkbox(L"Fruit column visible");
+ column1_visible_checkbox_->SetChecked(true);
+ column1_visible_checkbox_->set_listener(this);
+ column2_visible_checkbox_ = new views::Checkbox(L"Color column visible");
+ column2_visible_checkbox_->SetChecked(true);
+ column2_visible_checkbox_->set_listener(this);
+ column3_visible_checkbox_ = new views::Checkbox(L"Origin column visible");
+ column3_visible_checkbox_->SetChecked(true);
+ column3_visible_checkbox_->set_listener(this);
+ column4_visible_checkbox_ = new views::Checkbox(L"Price column visible");
+ column4_visible_checkbox_->SetChecked(true);
+ column4_visible_checkbox_->set_listener(this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ std::vector<TableColumn> columns;
+ columns.push_back(
+ TableColumn(0, ASCIIToUTF16("Fruit"), TableColumn::LEFT, 100));
+ columns.push_back(
+ TableColumn(1, ASCIIToUTF16("Color"), TableColumn::LEFT, 100));
+ columns.push_back(
+ TableColumn(2, ASCIIToUTF16("Origin"), TableColumn::LEFT, 100));
+ columns.push_back(
+ TableColumn(3, ASCIIToUTF16("Price"), TableColumn::LEFT, 100));
+ const int options = (views::TableView2::SINGLE_SELECTION |
+ views::TableView2::RESIZABLE_COLUMNS |
+ views::TableView2::AUTOSIZE_COLUMNS |
+ views::TableView2::HORIZONTAL_LINES |
+ views::TableView2::VERTICAL_LINES);
+ table_ = new views::TableView2(this, columns, views::ICON_AND_TEXT, options);
+ table_->SetObserver(this);
+ icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon1_.allocPixels();
+ SkCanvas canvas1(icon1_);
+ canvas1.drawColor(SK_ColorRED);
+
+ icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon2_.allocPixels();
+ SkCanvas canvas2(icon2_);
+ canvas2.drawColor(SK_ColorBLUE);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, 0);
+ layout->AddView(table_);
+
+ column_set = layout->AddColumnSet(1);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0 /* no expand */, 1);
+
+ layout->AddView(column1_visible_checkbox_);
+ layout->AddView(column2_visible_checkbox_);
+ layout->AddView(column3_visible_checkbox_);
+ layout->AddView(column4_visible_checkbox_);
+}
+
+int Table2Example::RowCount() {
+ return 10;
+}
+
+string16 Table2Example::GetText(int row, int column_id) {
+ const char* const cells[5][4] = {
+ { "Orange", "Orange", "South america", "$5" },
+ { "Apple", "Green", "Canada", "$3" },
+ { "Blue berries", "Blue", "Mexico", "$10.3" },
+ { "Strawberries", "Red", "California", "$7" },
+ { "Cantaloupe", "Orange", "South america", "$5" }
+ };
+ return ASCIIToUTF16(cells[row % 5][column_id]);
+}
+
+SkBitmap Table2Example::GetIcon(int row) {
+ return row % 2 ? icon1_ : icon2_;
+}
+
+void Table2Example::SetObserver(TableModelObserver* observer) {
+}
+
+void Table2Example::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ int index = 0;
+ bool show = true;
+ if (sender == column1_visible_checkbox_) {
+ index = 0;
+ show = column1_visible_checkbox_->checked();
+ } else if (sender == column2_visible_checkbox_) {
+ index = 1;
+ show = column2_visible_checkbox_->checked();
+ } else if (sender == column3_visible_checkbox_) {
+ index = 2;
+ show = column3_visible_checkbox_->checked();
+ } else if (sender == column4_visible_checkbox_) {
+ index = 3;
+ show = column4_visible_checkbox_->checked();
+ }
+ table_->SetColumnVisibility(index, show);
+}
+
+void Table2Example::OnSelectionChanged() {
+ PrintStatus(L"Selection changed: %d", table_->GetFirstSelectedRow());
+}
+
+void Table2Example::OnDoubleClick() {
+}
+
+void Table2Example::OnMiddleClick() {
+}
+
+void Table2Example::OnKeyDown(ui::KeyboardCode virtual_keycode) {
+}
+
+void Table2Example::OnTableViewDelete(views::TableView* table_view) {
+}
+
+void Table2Example::OnTableView2Delete(views::TableView2* table_view) {
+}
+
+} // namespace examples
diff --git a/views/examples/table2_example.h b/views/examples/table2_example.h
index c4c33b2..ebd3f74 100644
--- a/views/examples/table2_example.h
+++ b/views/examples/table2_example.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,162 +7,52 @@
#pragma once
#include <string>
-#include <vector>
-#include "base/utf_string_conversions.h"
-#include "third_party/skia/include/core/SkCanvas.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/models/table_model.h"
-#include "views/controls/button/checkbox.h"
+#include "views/controls/button/button.h"
#include "views/controls/table/table_view_observer.h"
-#include "views/controls/table/table_view2.h"
#include "views/examples/example_base.h"
-using ui::TableModel;
-using ui::TableModelObserver; // TODO(beng): remove these.
+namespace views {
+class Checkbox;
+class Event;
+class TableView2;
+}
namespace examples {
-class Table2Example
- : public ExampleBase,
- public TableModel,
- public views::ButtonListener,
- public views::TableViewObserver {
+class Table2Example : public ExampleBase,
+ public ui::TableModel,
+ public views::ButtonListener,
+ public views::TableViewObserver {
public:
- explicit Table2Example(ExamplesMain* main) : ExampleBase(main) {
- }
-
- virtual ~Table2Example() {}
-
- virtual std::wstring GetExampleTitle() {
- return L"Table2";
- }
-
- virtual void CreateExampleView(views::View* container) {
- column1_visible_checkbox_ = new views::Checkbox(L"Fruit column visible");
- column1_visible_checkbox_->SetChecked(true);
- column1_visible_checkbox_->set_listener(this);
- column2_visible_checkbox_ = new views::Checkbox(L"Color column visible");
- column2_visible_checkbox_->SetChecked(true);
- column2_visible_checkbox_->set_listener(this);
- column3_visible_checkbox_ = new views::Checkbox(L"Origin column visible");
- column3_visible_checkbox_->SetChecked(true);
- column3_visible_checkbox_->set_listener(this);
- column4_visible_checkbox_ = new views::Checkbox(L"Price column visible");
- column4_visible_checkbox_->SetChecked(true);
- column4_visible_checkbox_->set_listener(this);
-
- views::GridLayout* layout = new views::GridLayout(container);
- container->SetLayoutManager(layout);
-
- std::vector<TableColumn> columns;
- columns.push_back(TableColumn(0, ASCIIToUTF16("Fruit"), TableColumn::LEFT,
- 100));
- columns.push_back(TableColumn(1, ASCIIToUTF16("Color"), TableColumn::LEFT,
- 100));
- columns.push_back(TableColumn(2, ASCIIToUTF16("Origin"), TableColumn::LEFT,
- 100));
- columns.push_back(TableColumn(3, ASCIIToUTF16("Price"), TableColumn::LEFT,
- 100));
- const int options = (views::TableView2::SINGLE_SELECTION |
- views::TableView2::RESIZABLE_COLUMNS |
- views::TableView2::AUTOSIZE_COLUMNS |
- views::TableView2::HORIZONTAL_LINES |
- views::TableView2::VERTICAL_LINES);
- table_ = new views::TableView2(this, columns, views::ICON_AND_TEXT,
- options);
- table_->SetObserver(this);
- icon1.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
- icon1.allocPixels();
- SkCanvas canvas1(icon1);
- canvas1.drawColor(SK_ColorRED);
-
- icon2.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
- icon2.allocPixels();
- SkCanvas canvas2(icon2);
- canvas2.drawColor(SK_ColorBLUE);
-
- views::ColumnSet* column_set = layout->AddColumnSet(0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
- views::GridLayout::USE_PREF, 0, 0);
- layout->StartRow(1 /* expand */, 0);
- layout->AddView(table_);
-
- column_set = layout->AddColumnSet(1);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 0.5f, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 0.5f, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 0.5f, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 0.5f, views::GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0 /* no expand */, 1);
-
- layout->AddView(column1_visible_checkbox_);
- layout->AddView(column2_visible_checkbox_);
- layout->AddView(column3_visible_checkbox_);
- layout->AddView(column4_visible_checkbox_);
- }
-
- // TableModel implementation:
- virtual int RowCount() {
- return 10;
- }
-
- virtual string16 GetText(int row, int column_id) {
- const char* const cells[5][4] = {
- { "Orange", "Orange", "South america", "$5" },
- { "Apple", "Green", "Canada", "$3" },
- { "Blue berries", "Blue", "Mexico", "$10.3" },
- { "Strawberries", "Red", "California", "$7" },
- { "Cantaloupe", "Orange", "South america", "$5" }
- };
- return ASCIIToUTF16(cells[row % 5][column_id]);
- }
-
- virtual SkBitmap GetIcon(int row) {
- return row % 2 ? icon1 : icon2;
- }
-
- virtual void SetObserver(TableModelObserver* observer) {
- }
-
- // TableViewObserver implementation:
- virtual void OnSelectionChanged() {
- PrintStatus(L"Selection changed: %d",
- table_->GetFirstSelectedRow());
- }
-
- virtual void OnDoubleClick() {}
-
- virtual void OnMiddleClick() {}
-
- virtual void OnKeyDown(ui::KeyboardCode virtual_keycode) {}
-
- virtual void OnTableViewDelete(views::TableView* table_view) {}
-
- virtual void OnTableView2Delete(views::TableView2* table_view) {}
-
- // ButtonListener implementation:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- int index = 0;
- bool show = true;
- if (sender == column1_visible_checkbox_) {
- index = 0;
- show = column1_visible_checkbox_->checked();
- } else if (sender == column2_visible_checkbox_) {
- index = 1;
- show = column2_visible_checkbox_->checked();
- } else if (sender == column3_visible_checkbox_) {
- index = 2;
- show = column3_visible_checkbox_->checked();
- } else if (sender == column4_visible_checkbox_) {
- index = 3;
- show = column4_visible_checkbox_->checked();
- }
- table_->SetColumnVisibility(index, show);
- }
+ explicit Table2Example(ExamplesMain* main);
+ virtual ~Table2Example();
+
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ // Overridden from TableModel:
+ virtual int RowCount() OVERRIDE;
+ virtual string16 GetText(int row, int column_id) OVERRIDE;
+ virtual SkBitmap GetIcon(int row) OVERRIDE;
+ virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // Overridden from views::TableViewObserver:
+ virtual void OnSelectionChanged() OVERRIDE;
+ virtual void OnDoubleClick() OVERRIDE;
+ virtual void OnMiddleClick() OVERRIDE;
+ virtual void OnKeyDown(ui::KeyboardCode virtual_keycode) OVERRIDE;
+ virtual void OnTableViewDelete(views::TableView* table_view) OVERRIDE;
+ virtual void OnTableView2Delete(views::TableView2* table_view) OVERRIDE;
private:
// The table to be tested.
@@ -173,8 +63,8 @@ class Table2Example
views::Checkbox* column3_visible_checkbox_;
views::Checkbox* column4_visible_checkbox_;
- SkBitmap icon1;
- SkBitmap icon2;
+ SkBitmap icon1_;
+ SkBitmap icon2_;
DISALLOW_COPY_AND_ASSIGN(Table2Example);
};
diff --git a/views/views.gyp b/views/views.gyp
index 2c9cb29..26c5a34 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -534,6 +534,8 @@
'examples/slider_example.h',
'examples/tabbed_pane_example.cc',
'examples/tabbed_pane_example.h',
+ 'examples/table2_example.cc',
+ 'examples/table2_example.h',
'examples/textfield_example.h',
'examples/throbber_example.cc',
'examples/throbber_example.h',