1 // Copyright (c) 2010 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.
5 #ifndef APP_TABLE_MODEL_H_
6 #define APP_TABLE_MODEL_H_
12 #include "base/logging.h"
13 #include "unicode/coll.h"
17 class TableModelObserver
;
19 // The model driving the TableView.
22 // See HasGroups, get GetGroupID for details as to how this is used.
24 // The title text for the group.
27 // Unique id for the group.
30 typedef std::vector
<Group
> Groups
;
32 // Number of rows in the model.
33 virtual int RowCount() = 0;
35 // Returns the value at a particular location in text.
36 virtual std::wstring
GetText(int row
, int column_id
) = 0;
38 // Returns the small icon (16x16) that should be displayed in the first
39 // column before the text. This is only used when the TableView was created
40 // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is
42 virtual SkBitmap
GetIcon(int row
);
44 // Returns the tooltip, if any, to show for a particular row. If there are
45 // multiple columns in the row, this will only be shown when hovering over
47 virtual std::wstring
GetTooltip(int row
) {
48 return std::wstring();
51 // Returns true if the TableView has groups. Groups provide a way to visually
52 // delineate the rows in a table view. When groups are enabled table view
53 // shows a visual separator for each group, followed by all the rows in
56 // On win2k a visual separator is not rendered for the group headers.
57 virtual bool HasGroups() { return false; }
59 // Returns the groups.
60 // This is only used if HasGroups returns true.
61 virtual Groups
GetGroups() {
62 // If you override HasGroups to return true, you must override this as
65 return std::vector
<Group
>();
68 // Returns the group id of the specified row.
69 // This is only used if HasGroups returns true.
70 virtual int GetGroupID(int row
) {
71 // If you override HasGroups to return true, you must override this as
77 // Sets the observer for the model. The TableView should NOT take ownership
79 virtual void SetObserver(TableModelObserver
* observer
) = 0;
81 // Compares the values in the column with id |column_id| for the two rows.
82 // Returns a value < 0, == 0 or > 0 as to whether the first value is
83 // <, == or > the second value.
85 // This implementation does a case insensitive locale specific string
87 virtual int CompareValues(int row1
, int row2
, int column_id
);
89 // Reset the collator.
93 virtual ~TableModel() {}
95 // Returns the collator used by CompareValues.
96 icu::Collator
* GetCollator();
99 // TableColumn specifies the title, alignment and size of a particular column.
106 TableColumn(int id
, const std::wstring
& title
,
107 Alignment alignment
, int width
);
108 TableColumn(int id
, const std::wstring
& title
,
109 Alignment alignment
, int width
, float percent
);
111 // It's common (but not required) to use the title's IDS_* tag as the column
112 // id. In this case, the provided conveniences look up the title string on
113 // bahalf of the caller.
114 TableColumn(int id
, Alignment alignment
, int width
);
115 TableColumn(int id
, Alignment alignment
, int width
, float percent
);
117 // A unique identifier for the column.
120 // The title for the column.
123 // Alignment for the content.
126 // The size of a column may be specified in two ways:
127 // 1. A fixed width. Set the width field to a positive number and the
128 // column will be given that width, in pixels.
129 // 2. As a percentage of the available width. If width is -1, and percent is
130 // > 0, the column is given a width of
131 // available_width * percent / total_percent.
132 // 3. If the width == -1 and percent == 0, the column is autosized based on
133 // the width of the column header text.
135 // Sizing is done in four passes. Fixed width columns are given
136 // their width, percentages are applied, autosized columns are autosized,
137 // and finally percentages are applied again taking into account the widths
138 // of autosized columns.
142 // The minimum width required for all items in this column
143 // (including the header)
145 int min_visible_width
;
147 // Is this column sortable? Default is false
151 #endif // APP_TABLE_MODEL_H_