| 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 #include "app/table_model.h" | 5 #include "app/table_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/l10n_util_collator.h" | 8 #include "app/l10n_util_collator.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 | 11 |
| 12 // TableColumn ----------------------------------------------------------------- | 12 // TableColumn ----------------------------------------------------------------- |
| 13 | 13 |
| 14 TableColumn::TableColumn() | 14 TableColumn::TableColumn() |
| 15 : id(0), | 15 : id(0), |
| 16 title(), | 16 title(), |
| 17 alignment(LEFT), | 17 alignment(LEFT), |
| 18 width(-1), | 18 width(-1), |
| 19 percent(), | 19 percent(), |
| 20 min_visible_width(0), | 20 min_visible_width(0), |
| 21 sortable(false) { | 21 sortable(false) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 TableColumn::TableColumn(int id, const std::wstring& title, | 24 TableColumn::TableColumn(int id, const string16& title, |
| 25 Alignment alignment, | 25 Alignment alignment, |
| 26 int width) | 26 int width) |
| 27 : id(id), | 27 : id(id), |
| 28 title(title), | 28 title(title), |
| 29 alignment(alignment), | 29 alignment(alignment), |
| 30 width(width), | 30 width(width), |
| 31 percent(0), | 31 percent(0), |
| 32 min_visible_width(0), | 32 min_visible_width(0), |
| 33 sortable(false) { | 33 sortable(false) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 TableColumn::TableColumn(int id, const std::wstring& title, | 36 TableColumn::TableColumn(int id, const string16& title, |
| 37 Alignment alignment, int width, float percent) | 37 Alignment alignment, int width, float percent) |
| 38 : id(id), | 38 : id(id), |
| 39 title(title), | 39 title(title), |
| 40 alignment(alignment), | 40 alignment(alignment), |
| 41 width(width), | 41 width(width), |
| 42 percent(percent), | 42 percent(percent), |
| 43 min_visible_width(0), | 43 min_visible_width(0), |
| 44 sortable(false) { | 44 sortable(false) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 // It's common (but not required) to use the title's IDS_* tag as the column | 47 // It's common (but not required) to use the title's IDS_* tag as the column |
| 48 // id. In this case, the provided conveniences look up the title string on | 48 // id. In this case, the provided conveniences look up the title string on |
| 49 // bahalf of the caller. | 49 // bahalf of the caller. |
| 50 TableColumn::TableColumn(int id, Alignment alignment, int width) | 50 TableColumn::TableColumn(int id, Alignment alignment, int width) |
| 51 : id(id), | 51 : id(id), |
| 52 alignment(alignment), | 52 alignment(alignment), |
| 53 width(width), | 53 width(width), |
| 54 percent(0), | 54 percent(0), |
| 55 min_visible_width(0), | 55 min_visible_width(0), |
| 56 sortable(false) { | 56 sortable(false) { |
| 57 title = UTF16ToWide(l10n_util::GetStringUTF16(id)); | 57 title = l10n_util::GetStringUTF16(id); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) | 60 TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) |
| 61 : id(id), | 61 : id(id), |
| 62 alignment(alignment), | 62 alignment(alignment), |
| 63 width(width), | 63 width(width), |
| 64 percent(percent), | 64 percent(percent), |
| 65 min_visible_width(0), | 65 min_visible_width(0), |
| 66 sortable(false) { | 66 sortable(false) { |
| 67 title = UTF16ToWide(l10n_util::GetStringUTF16(id)); | 67 title = l10n_util::GetStringUTF16(id); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // TableModel ----------------------------------------------------------------- | 70 // TableModel ----------------------------------------------------------------- |
| 71 | 71 |
| 72 // Used for sorting. | 72 // Used for sorting. |
| 73 static icu::Collator* collator = NULL; | 73 static icu::Collator* collator = NULL; |
| 74 | 74 |
| 75 SkBitmap TableModel::GetIcon(int row) { | 75 SkBitmap TableModel::GetIcon(int row) { |
| 76 return SkBitmap(); | 76 return SkBitmap(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 std::wstring TableModel::GetTooltip(int row) { | 79 string16 TableModel::GetTooltip(int row) { |
| 80 return std::wstring(); | 80 return string16(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool TableModel::ShouldIndent(int row) { | 83 bool TableModel::ShouldIndent(int row) { |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool TableModel::HasGroups() { | 87 bool TableModel::HasGroups() { |
| 88 return false; | 88 return false; |
| 89 } | 89 } |
| 90 | 90 |
| 91 TableModel::Groups TableModel::GetGroups() { | 91 TableModel::Groups TableModel::GetGroups() { |
| 92 // If you override HasGroups to return true, you must override this as | 92 // If you override HasGroups to return true, you must override this as |
| 93 // well. | 93 // well. |
| 94 NOTREACHED(); | 94 NOTREACHED(); |
| 95 return std::vector<Group>(); | 95 return std::vector<Group>(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 int TableModel::GetGroupID(int row) { | 98 int TableModel::GetGroupID(int row) { |
| 99 // If you override HasGroups to return true, you must override this as | 99 // If you override HasGroups to return true, you must override this as |
| 100 // well. | 100 // well. |
| 101 NOTREACHED(); | 101 NOTREACHED(); |
| 102 return 0; | 102 return 0; |
| 103 } | 103 } |
| 104 | 104 |
| 105 int TableModel::CompareValues(int row1, int row2, int column_id) { | 105 int TableModel::CompareValues(int row1, int row2, int column_id) { |
| 106 DCHECK(row1 >= 0 && row1 < RowCount() && | 106 DCHECK(row1 >= 0 && row1 < RowCount() && |
| 107 row2 >= 0 && row2 < RowCount()); | 107 row2 >= 0 && row2 < RowCount()); |
| 108 std::wstring value1 = GetText(row1, column_id); | 108 string16 value1 = GetText(row1, column_id); |
| 109 std::wstring value2 = GetText(row2, column_id); | 109 string16 value2 = GetText(row2, column_id); |
| 110 icu::Collator* collator = GetCollator(); | 110 icu::Collator* collator = GetCollator(); |
| 111 | 111 |
| 112 if (collator) | 112 if (collator) |
| 113 return l10n_util::CompareStringWithCollator(collator, value1, value2); | 113 return l10n_util::CompareString16WithCollator(collator, value1, value2); |
| 114 | 114 |
| 115 NOTREACHED(); | 115 NOTREACHED(); |
| 116 return 0; | 116 return 0; |
| 117 } | 117 } |
| 118 | 118 |
| 119 icu::Collator* TableModel::GetCollator() { | 119 icu::Collator* TableModel::GetCollator() { |
| 120 if (!collator) { | 120 if (!collator) { |
| 121 UErrorCode create_status = U_ZERO_ERROR; | 121 UErrorCode create_status = U_ZERO_ERROR; |
| 122 collator = icu::Collator::createInstance(create_status); | 122 collator = icu::Collator::createInstance(create_status); |
| 123 if (!U_SUCCESS(create_status)) { | 123 if (!U_SUCCESS(create_status)) { |
| 124 collator = NULL; | 124 collator = NULL; |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 return collator; | 128 return collator; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void TableModel::ClearCollator() { | 131 void TableModel::ClearCollator() { |
| 132 delete collator; | 132 delete collator; |
| 133 collator = NULL; | 133 collator = NULL; |
| 134 } | 134 } |
| OLD | NEW |