| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "views/controls/table/table_view.h" | 5 #include "views/controls/table/table_view.h" |
| 6 | 6 |
| 7 #include <windowsx.h> | 7 #include <windowsx.h> |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlapp.h> | 9 #include <atlapp.h> |
| 10 #include <atlmisc.h> | 10 #include <atlmisc.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 #include "app/gfx/canvas.h" | 14 #include "app/gfx/canvas.h" |
| 15 #include "app/gfx/favicon_size.h" | 15 #include "app/gfx/favicon_size.h" |
| 16 #include "app/gfx/icon_util.h" | 16 #include "app/gfx/icon_util.h" |
| 17 #include "app/l10n_util_win.h" | 17 #include "app/l10n_util_win.h" |
| 18 #include "app/resource_bundle.h" | 18 #include "app/resource_bundle.h" |
| 19 #include "app/table_model.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "base/win_util.h" | 21 #include "base/win_util.h" |
| 21 #include "skia/ext/skia_utils_win.h" | 22 #include "skia/ext/skia_utils_win.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "third_party/skia/include/core/SkColorFilter.h" | 24 #include "third_party/skia/include/core/SkColorFilter.h" |
| 24 #include "views/controls/native/native_view_host.h" | 25 #include "views/controls/native/native_view_host.h" |
| 25 #include "views/controls/table/table_model.h" | |
| 26 #include "views/controls/table/table_view_observer.h" | 26 #include "views/controls/table/table_view_observer.h" |
| 27 | 27 |
| 28 namespace views { | 28 namespace views { |
| 29 | 29 |
| 30 // Added to column width to prevent truncation. | 30 // Added to column width to prevent truncation. |
| 31 const int kListViewTextPadding = 15; | 31 const int kListViewTextPadding = 15; |
| 32 // Additional column width necessary if column has icons. | 32 // Additional column width necessary if column has icons. |
| 33 const int kListViewIconWidthAndPadding = 18; | 33 const int kListViewIconWidthAndPadding = 18; |
| 34 | 34 |
| 35 // TableModel ----------------------------------------------------------------- | 35 // TableView ------------------------------------------------------------------ |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 const int TableView::kImageSize = 18; | 38 const int TableView::kImageSize = 18; |
| 39 | 39 |
| 40 // Used for sorting. | |
| 41 static Collator* collator = NULL; | |
| 42 | |
| 43 SkBitmap TableModel::GetIcon(int row) { | |
| 44 return SkBitmap(); | |
| 45 } | |
| 46 | |
| 47 int TableModel::CompareValues(int row1, int row2, int column_id) { | |
| 48 DCHECK(row1 >= 0 && row1 < RowCount() && | |
| 49 row2 >= 0 && row2 < RowCount()); | |
| 50 std::wstring value1 = GetText(row1, column_id); | |
| 51 std::wstring value2 = GetText(row2, column_id); | |
| 52 Collator* collator = GetCollator(); | |
| 53 | |
| 54 if (collator) { | |
| 55 UErrorCode compare_status = U_ZERO_ERROR; | |
| 56 UCollationResult compare_result = collator->compare( | |
| 57 static_cast<const UChar*>(value1.c_str()), | |
| 58 static_cast<int>(value1.length()), | |
| 59 static_cast<const UChar*>(value2.c_str()), | |
| 60 static_cast<int>(value2.length()), | |
| 61 compare_status); | |
| 62 DCHECK(U_SUCCESS(compare_status)); | |
| 63 return compare_result; | |
| 64 } | |
| 65 NOTREACHED(); | |
| 66 return 0; | |
| 67 } | |
| 68 | |
| 69 Collator* TableModel::GetCollator() { | |
| 70 if (!collator) { | |
| 71 UErrorCode create_status = U_ZERO_ERROR; | |
| 72 collator = Collator::createInstance(create_status); | |
| 73 if (!U_SUCCESS(create_status)) { | |
| 74 collator = NULL; | |
| 75 NOTREACHED(); | |
| 76 } | |
| 77 } | |
| 78 return collator; | |
| 79 } | |
| 80 | |
| 81 // TableView ------------------------------------------------------------------ | |
| 82 | |
| 83 TableView::TableView(TableModel* model, | 40 TableView::TableView(TableModel* model, |
| 84 const std::vector<TableColumn>& columns, | 41 const std::vector<TableColumn>& columns, |
| 85 TableTypes table_type, | 42 TableTypes table_type, |
| 86 bool single_selection, | 43 bool single_selection, |
| 87 bool resizable_columns, | 44 bool resizable_columns, |
| 88 bool autosize_columns) | 45 bool autosize_columns) |
| 89 : model_(model), | 46 : model_(model), |
| 90 table_view_observer_(NULL), | 47 table_view_observer_(NULL), |
| 91 visible_columns_(), | 48 visible_columns_(), |
| 92 all_columns_(), | 49 all_columns_(), |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 view_to_model_.reset(NULL); | 911 view_to_model_.reset(NULL); |
| 955 model_to_view_.reset(NULL); | 912 model_to_view_.reset(NULL); |
| 956 return; | 913 return; |
| 957 } | 914 } |
| 958 | 915 |
| 959 PrepareForSort(); | 916 PrepareForSort(); |
| 960 | 917 |
| 961 // Sort the items. | 918 // Sort the items. |
| 962 ListView_SortItems(list_view_, &TableView::SortFunc, this); | 919 ListView_SortItems(list_view_, &TableView::SortFunc, this); |
| 963 | 920 |
| 964 // Cleanup the collator. | 921 model_->ClearCollator(); |
| 965 if (collator) { | |
| 966 delete collator; | |
| 967 collator = NULL; | |
| 968 } | |
| 969 | 922 |
| 970 // Update internal mapping to match how items were actually sorted. | 923 // Update internal mapping to match how items were actually sorted. |
| 971 int row_count = RowCount(); | 924 int row_count = RowCount(); |
| 972 model_to_view_.reset(new int[row_count]); | 925 model_to_view_.reset(new int[row_count]); |
| 973 view_to_model_.reset(new int[row_count]); | 926 view_to_model_.reset(new int[row_count]); |
| 974 LVITEM item; | 927 LVITEM item; |
| 975 memset(&item, 0, sizeof(LVITEM)); | 928 memset(&item, 0, sizeof(LVITEM)); |
| 976 item.mask = LVIF_PARAM; | 929 item.mask = LVIF_PARAM; |
| 977 for (int i = 0; i < row_count; ++i) { | 930 for (int i = 0; i < row_count; ++i) { |
| 978 item.iItem = i; | 931 item.iItem = i; |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 } | 1544 } |
| 1592 | 1545 |
| 1593 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { | 1546 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { |
| 1594 if (view_index_ == -1) | 1547 if (view_index_ == -1) |
| 1595 model_index_ = -1; | 1548 model_index_ = -1; |
| 1596 else | 1549 else |
| 1597 model_index_ = table_view_->view_to_model(view_index_); | 1550 model_index_ = table_view_->view_to_model(view_index_); |
| 1598 } | 1551 } |
| 1599 | 1552 |
| 1600 } // namespace views | 1553 } // namespace views |
| OLD | NEW |