| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ | |
| 6 #define VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "unicode/coll.h" | |
| 13 | |
| 14 class SkBitmap; | |
| 15 | |
| 16 namespace views { | |
| 17 | |
| 18 class TableModelObserver; | |
| 19 | |
| 20 // The model driving the TableView. | |
| 21 class TableModel { | |
| 22 public: | |
| 23 // See HasGroups, get GetGroupID for details as to how this is used. | |
| 24 struct Group { | |
| 25 // The title text for the group. | |
| 26 std::wstring title; | |
| 27 | |
| 28 // Unique id for the group. | |
| 29 int id; | |
| 30 }; | |
| 31 typedef std::vector<Group> Groups; | |
| 32 | |
| 33 // Number of rows in the model. | |
| 34 virtual int RowCount() = 0; | |
| 35 | |
| 36 // Returns the value at a particular location in text. | |
| 37 virtual std::wstring GetText(int row, int column_id) = 0; | |
| 38 | |
| 39 // Returns the small icon (16x16) that should be displayed in the first | |
| 40 // column before the text. This is only used when the TableView was created | |
| 41 // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is | |
| 42 // no bitmap. | |
| 43 virtual SkBitmap GetIcon(int row); | |
| 44 | |
| 45 // Sets whether a particular row is checked. This is only invoked | |
| 46 // if the TableView was created with show_check_in_first_column true. | |
| 47 virtual void SetChecked(int row, bool is_checked) { | |
| 48 NOTREACHED(); | |
| 49 } | |
| 50 | |
| 51 // Returns whether a particular row is checked. This is only invoked | |
| 52 // if the TableView was created with show_check_in_first_column true. | |
| 53 virtual bool IsChecked(int row) { | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 // Returns true if the TableView has groups. Groups provide a way to visually | |
| 58 // delineate the rows in a table view. When groups are enabled table view | |
| 59 // shows a visual separator for each group, followed by all the rows in | |
| 60 // the group. | |
| 61 // | |
| 62 // On win2k a visual separator is not rendered for the group headers. | |
| 63 virtual bool HasGroups() { return false; } | |
| 64 | |
| 65 // Returns the groups. | |
| 66 // This is only used if HasGroups returns true. | |
| 67 virtual Groups GetGroups() { | |
| 68 // If you override HasGroups to return true, you must override this as | |
| 69 // well. | |
| 70 NOTREACHED(); | |
| 71 return std::vector<Group>(); | |
| 72 } | |
| 73 | |
| 74 // Returns the group id of the specified row. | |
| 75 // This is only used if HasGroups returns true. | |
| 76 virtual int GetGroupID(int row) { | |
| 77 // If you override HasGroups to return true, you must override this as | |
| 78 // well. | |
| 79 NOTREACHED(); | |
| 80 return 0; | |
| 81 } | |
| 82 | |
| 83 // Sets the observer for the model. The TableView should NOT take ownership | |
| 84 // of the observer. | |
| 85 virtual void SetObserver(TableModelObserver* observer) = 0; | |
| 86 | |
| 87 // Compares the values in the column with id |column_id| for the two rows. | |
| 88 // Returns a value < 0, == 0 or > 0 as to whether the first value is | |
| 89 // <, == or > the second value. | |
| 90 // | |
| 91 // This implementation does a case insensitive locale specific string | |
| 92 // comparison. | |
| 93 virtual int CompareValues(int row1, int row2, int column_id); | |
| 94 | |
| 95 protected: | |
| 96 // Returns the collator used by CompareValues. | |
| 97 Collator* GetCollator(); | |
| 98 }; | |
| 99 | |
| 100 // TableColumn specifies the title, alignment and size of a particular column. | |
| 101 struct TableColumn { | |
| 102 enum Alignment { | |
| 103 LEFT, RIGHT, CENTER | |
| 104 }; | |
| 105 | |
| 106 TableColumn(); | |
| 107 TableColumn(int id, const std::wstring& title, | |
| 108 Alignment alignment, int width); | |
| 109 TableColumn(int id, const std::wstring& title, | |
| 110 Alignment alignment, int width, float percent); | |
| 111 | |
| 112 // It's common (but not required) to use the title's IDS_* tag as the column | |
| 113 // id. In this case, the provided conveniences look up the title string on | |
| 114 // bahalf of the caller. | |
| 115 TableColumn(int id, Alignment alignment, int width); | |
| 116 TableColumn(int id, Alignment alignment, int width, float percent); | |
| 117 | |
| 118 // A unique identifier for the column. | |
| 119 int id; | |
| 120 | |
| 121 // The title for the column. | |
| 122 std::wstring title; | |
| 123 | |
| 124 // Alignment for the content. | |
| 125 Alignment alignment; | |
| 126 | |
| 127 // The size of a column may be specified in two ways: | |
| 128 // 1. A fixed width. Set the width field to a positive number and the | |
| 129 // column will be given that width, in pixels. | |
| 130 // 2. As a percentage of the available width. If width is -1, and percent is | |
| 131 // > 0, the column is given a width of | |
| 132 // available_width * percent / total_percent. | |
| 133 // 3. If the width == -1 and percent == 0, the column is autosized based on | |
| 134 // the width of the column header text. | |
| 135 // | |
| 136 // Sizing is done in four passes. Fixed width columns are given | |
| 137 // their width, percentages are applied, autosized columns are autosized, | |
| 138 // and finally percentages are applied again taking into account the widths | |
| 139 // of autosized columns. | |
| 140 int width; | |
| 141 float percent; | |
| 142 | |
| 143 // The minimum width required for all items in this column | |
| 144 // (including the header) | |
| 145 // to be visible. | |
| 146 int min_visible_width; | |
| 147 | |
| 148 // Is this column sortable? Default is false | |
| 149 bool sortable; | |
| 150 }; | |
| 151 | |
| 152 } // namespace views | |
| 153 | |
| 154 #endif // VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_ | |
| OLD | NEW |