diff options
Diffstat (limited to 'views/controls/table')
-rw-r--r-- | views/controls/table/group_table_view.h | 2 | ||||
-rw-r--r-- | views/controls/table/table_model.cc | 68 | ||||
-rw-r--r-- | views/controls/table/table_model.h | 154 | ||||
-rw-r--r-- | views/controls/table/table_model_observer.h | 29 | ||||
-rw-r--r-- | views/controls/table/table_view.cc | 53 | ||||
-rw-r--r-- | views/controls/table/table_view.h | 6 | ||||
-rw-r--r-- | views/controls/table/table_view_unittest.cc | 13 |
7 files changed, 14 insertions, 311 deletions
diff --git a/views/controls/table/group_table_view.h b/views/controls/table/group_table_view.h index c92587f..640776e 100644 --- a/views/controls/table/group_table_view.h +++ b/views/controls/table/group_table_view.h @@ -5,8 +5,8 @@ #ifndef VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ #define VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_ +#include "app/table_model.h" #include "base/task.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view.h" // The GroupTableView adds grouping to the TableView class. diff --git a/views/controls/table/table_model.cc b/views/controls/table/table_model.cc deleted file mode 100644 index 7e1dd0e..0000000 --- a/views/controls/table/table_model.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2009 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/controls/table/table_model.h" - -#include "app/l10n_util.h" - -namespace views { - -TableColumn::TableColumn() - : id(0), - title(), - alignment(LEFT), - width(-1), - percent(), - min_visible_width(0), - sortable(false) { -} - -TableColumn::TableColumn(int id, const std::wstring& title, - Alignment alignment, - int width) - : id(id), - title(title), - alignment(alignment), - width(width), - percent(0), - min_visible_width(0), - sortable(false) { -} - -TableColumn::TableColumn(int id, const std::wstring& title, - Alignment alignment, int width, float percent) - : id(id), - title(title), - alignment(alignment), - width(width), - percent(percent), - min_visible_width(0), - sortable(false) { -} - -// It's common (but not required) to use the title's IDS_* tag as the column -// id. In this case, the provided conveniences look up the title string on -// bahalf of the caller. -TableColumn::TableColumn(int id, Alignment alignment, int width) - : id(id), - alignment(alignment), - width(width), - percent(0), - min_visible_width(0), - sortable(false) { - title = l10n_util::GetString(id); -} - -TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) - : id(id), - alignment(alignment), - width(width), - percent(percent), - min_visible_width(0), - sortable(false) { - title = l10n_util::GetString(id); -} - -} // namespace views - diff --git a/views/controls/table/table_model.h b/views/controls/table/table_model.h deleted file mode 100644 index 5c377c7..0000000 --- a/views/controls/table/table_model.h +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2009 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. - -#ifndef VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ -#define VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ - -#include <string> -#include <vector> - -#include "base/logging.h" -#include "unicode/coll.h" - -class SkBitmap; - -namespace views { - -class TableModelObserver; - -// The model driving the TableView. -class TableModel { - public: - // See HasGroups, get GetGroupID for details as to how this is used. - struct Group { - // The title text for the group. - std::wstring title; - - // Unique id for the group. - int id; - }; - typedef std::vector<Group> Groups; - - // Number of rows in the model. - virtual int RowCount() = 0; - - // Returns the value at a particular location in text. - virtual std::wstring GetText(int row, int column_id) = 0; - - // Returns the small icon (16x16) that should be displayed in the first - // column before the text. This is only used when the TableView was created - // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is - // no bitmap. - virtual SkBitmap GetIcon(int row); - - // Sets whether a particular row is checked. This is only invoked - // if the TableView was created with show_check_in_first_column true. - virtual void SetChecked(int row, bool is_checked) { - NOTREACHED(); - } - - // Returns whether a particular row is checked. This is only invoked - // if the TableView was created with show_check_in_first_column true. - virtual bool IsChecked(int row) { - return false; - } - - // Returns true if the TableView has groups. Groups provide a way to visually - // delineate the rows in a table view. When groups are enabled table view - // shows a visual separator for each group, followed by all the rows in - // the group. - // - // On win2k a visual separator is not rendered for the group headers. - virtual bool HasGroups() { return false; } - - // Returns the groups. - // This is only used if HasGroups returns true. - virtual Groups GetGroups() { - // If you override HasGroups to return true, you must override this as - // well. - NOTREACHED(); - return std::vector<Group>(); - } - - // Returns the group id of the specified row. - // This is only used if HasGroups returns true. - virtual int GetGroupID(int row) { - // If you override HasGroups to return true, you must override this as - // well. - NOTREACHED(); - return 0; - } - - // Sets the observer for the model. The TableView should NOT take ownership - // of the observer. - virtual void SetObserver(TableModelObserver* observer) = 0; - - // Compares the values in the column with id |column_id| for the two rows. - // Returns a value < 0, == 0 or > 0 as to whether the first value is - // <, == or > the second value. - // - // This implementation does a case insensitive locale specific string - // comparison. - virtual int CompareValues(int row1, int row2, int column_id); - - protected: - // Returns the collator used by CompareValues. - Collator* GetCollator(); -}; - -// TableColumn specifies the title, alignment and size of a particular column. -struct TableColumn { - enum Alignment { - LEFT, RIGHT, CENTER - }; - - TableColumn(); - TableColumn(int id, const std::wstring& title, - Alignment alignment, int width); - TableColumn(int id, const std::wstring& title, - Alignment alignment, int width, float percent); - - // It's common (but not required) to use the title's IDS_* tag as the column - // id. In this case, the provided conveniences look up the title string on - // bahalf of the caller. - TableColumn(int id, Alignment alignment, int width); - TableColumn(int id, Alignment alignment, int width, float percent); - - // A unique identifier for the column. - int id; - - // The title for the column. - std::wstring title; - - // Alignment for the content. - Alignment alignment; - - // The size of a column may be specified in two ways: - // 1. A fixed width. Set the width field to a positive number and the - // column will be given that width, in pixels. - // 2. As a percentage of the available width. If width is -1, and percent is - // > 0, the column is given a width of - // available_width * percent / total_percent. - // 3. If the width == -1 and percent == 0, the column is autosized based on - // the width of the column header text. - // - // Sizing is done in four passes. Fixed width columns are given - // their width, percentages are applied, autosized columns are autosized, - // and finally percentages are applied again taking into account the widths - // of autosized columns. - int width; - float percent; - - // The minimum width required for all items in this column - // (including the header) - // to be visible. - int min_visible_width; - - // Is this column sortable? Default is false - bool sortable; -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ diff --git a/views/controls/table/table_model_observer.h b/views/controls/table/table_model_observer.h deleted file mode 100644 index b968a9f..0000000 --- a/views/controls/table/table_model_observer.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2009 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. - -#ifndef VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ -#define VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ - -namespace views { - -// Observer for a TableModel. Anytime the model changes, it must notify its -// observer. -class TableModelObserver { - public: - // Invoked when the model has been completely changed. - virtual void OnModelChanged() = 0; - - // Invoked when a range of items has changed. - virtual void OnItemsChanged(int start, int length) = 0; - - // Invoked when new items are added. - virtual void OnItemsAdded(int start, int length) = 0; - - // Invoked when a range of items has been removed. - virtual void OnItemsRemoved(int start, int length) = 0; -}; - -} // namespace views - -#endif // VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_ diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 4e095cf..e0d0b55 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -16,13 +16,13 @@ #include "app/gfx/icon_util.h" #include "app/l10n_util_win.h" #include "app/resource_bundle.h" +#include "app/table_model.h" #include "base/string_util.h" #include "base/win_util.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColorFilter.h" #include "views/controls/native/native_view_host.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view_observer.h" namespace views { @@ -32,54 +32,11 @@ const int kListViewTextPadding = 15; // Additional column width necessary if column has icons. const int kListViewIconWidthAndPadding = 18; -// TableModel ----------------------------------------------------------------- +// TableView ------------------------------------------------------------------ // static const int TableView::kImageSize = 18; -// Used for sorting. -static Collator* collator = NULL; - -SkBitmap TableModel::GetIcon(int row) { - return SkBitmap(); -} - -int TableModel::CompareValues(int row1, int row2, int column_id) { - DCHECK(row1 >= 0 && row1 < RowCount() && - row2 >= 0 && row2 < RowCount()); - std::wstring value1 = GetText(row1, column_id); - std::wstring value2 = GetText(row2, column_id); - Collator* collator = GetCollator(); - - if (collator) { - UErrorCode compare_status = U_ZERO_ERROR; - UCollationResult compare_result = collator->compare( - static_cast<const UChar*>(value1.c_str()), - static_cast<int>(value1.length()), - static_cast<const UChar*>(value2.c_str()), - static_cast<int>(value2.length()), - compare_status); - DCHECK(U_SUCCESS(compare_status)); - return compare_result; - } - NOTREACHED(); - return 0; -} - -Collator* TableModel::GetCollator() { - if (!collator) { - UErrorCode create_status = U_ZERO_ERROR; - collator = Collator::createInstance(create_status); - if (!U_SUCCESS(create_status)) { - collator = NULL; - NOTREACHED(); - } - } - return collator; -} - -// TableView ------------------------------------------------------------------ - TableView::TableView(TableModel* model, const std::vector<TableColumn>& columns, TableTypes table_type, @@ -961,11 +918,7 @@ void TableView::SortItemsAndUpdateMapping() { // Sort the items. ListView_SortItems(list_view_, &TableView::SortFunc, this); - // Cleanup the collator. - if (collator) { - delete collator; - collator = NULL; - } + model_->ClearCollator(); // Update internal mapping to match how items were actually sorted. int row_count = RowCount(); diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h index 94198f8..b8bda67 100644 --- a/views/controls/table/table_view.h +++ b/views/controls/table/table_view.h @@ -15,13 +15,15 @@ typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW; #include <map> #include <vector> +#include "app/table_model_observer.h" #include "third_party/skia/include/core/SkColor.h" #if defined(OS_WIN) // TODO(port): remove the ifdef when native_control.h is ported. #include "views/controls/native_control.h" #endif // defined(OS_WIN) -#include "views/controls/table/table_model_observer.h" +struct TableColumn; +class TableModel; class SkBitmap; // A TableView is a view that displays multiple rows with any number of columns. @@ -51,8 +53,6 @@ namespace views { class ListView; class ListViewParent; class TableView; -struct TableColumn; -class TableModel; class TableViewObserver; // The cells in the first column of a table can contain: diff --git a/views/controls/table/table_view_unittest.cc b/views/controls/table/table_view_unittest.cc index c3d0a75..d79a5bc 100644 --- a/views/controls/table/table_view_unittest.cc +++ b/views/controls/table/table_view_unittest.cc @@ -4,10 +4,11 @@ #include <vector> +#include "app/table_model.h" +#include "app/table_model_observer.h" #include "base/message_loop.h" #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "views/controls/table/table_model.h" #include "views/controls/table/table_view.h" #include "views/window/window_delegate.h" #include "views/window/window_win.h" @@ -24,7 +25,7 @@ using views::TableView; // 0, 1 // 1, 1 // 2, 2 -class TestTableModel : public views::TableModel { +class TestTableModel : public TableModel { public: TestTableModel(); @@ -40,11 +41,11 @@ class TestTableModel : public views::TableModel { // TableModel virtual int RowCount(); virtual std::wstring GetText(int row, int column_id); - virtual void SetObserver(views::TableModelObserver* observer); + virtual void SetObserver(TableModelObserver* observer); virtual int CompareValues(int row1, int row2, int column_id); private: - views::TableModelObserver* observer_; + TableModelObserver* observer_; // The data. std::vector<std::vector<int>> rows_; @@ -90,7 +91,7 @@ std::wstring TestTableModel::GetText(int row, int column_id) { return IntToWString(rows_[row][column_id]); } -void TestTableModel::SetObserver(views::TableModelObserver* observer) { +void TestTableModel::SetObserver(TableModelObserver* observer) { observer_ = observer; } @@ -141,7 +142,7 @@ class TableViewTest : public testing::Test, views::WindowDelegate { void TableViewTest::SetUp() { OleInitialize(NULL); model_.reset(CreateModel()); - std::vector<views::TableColumn> columns; + std::vector<TableColumn> columns; columns.resize(2); columns[0].id = 0; columns[1].id = 1; |