1 // Copyright (c) 2012 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 UI_BASE_MODELS_TABLE_MODEL_H_
6 #define UI_BASE_MODELS_TABLE_MODEL_H_
10 #include "base/strings/string16.h"
11 #include "third_party/icu/source/i18n/unicode/coll.h"
12 #include "ui/base/ui_base_export.h"
20 class TableModelObserver
;
22 // The model driving the TableView.
23 class UI_BASE_EXPORT TableModel
{
25 // See HasGroups, get GetGroupID for details as to how this is used.
27 // The title text for the group.
30 // Unique id for the group.
33 typedef std::vector
<Group
> Groups
;
35 // Number of rows in the model.
36 virtual int RowCount() = 0;
38 // Returns the value at a particular location in text.
39 virtual base::string16
GetText(int row
, int column_id
) = 0;
41 // Returns the small icon (16x16) that should be displayed in the first
42 // column before the text. This is only used when the TableView was created
43 // with the ICON_AND_TEXT table type. Returns an isNull() image if there is
45 virtual gfx::ImageSkia
GetIcon(int row
);
47 // Returns the tooltip, if any, to show for a particular row. If there are
48 // multiple columns in the row, this will only be shown when hovering over
50 virtual base::string16
GetTooltip(int row
);
52 // If true, this row should be indented.
53 virtual bool ShouldIndent(int row
);
55 // Returns true if the TableView has groups. Groups provide a way to visually
56 // delineate the rows in a table view. When groups are enabled table view
57 // shows a visual separator for each group, followed by all the rows in
60 // On win2k a visual separator is not rendered for the group headers.
61 virtual bool HasGroups();
63 // Returns the groups.
64 // This is only used if HasGroups returns true.
65 virtual Groups
GetGroups();
67 // Returns the group id of the specified row.
68 // This is only used if HasGroups returns true.
69 virtual int GetGroupID(int row
);
71 // Sets the observer for the model. The TableView should NOT take ownership
73 virtual void SetObserver(TableModelObserver
* observer
) = 0;
75 // Compares the values in the column with id |column_id| for the two rows.
76 // Returns a value < 0, == 0 or > 0 as to whether the first value is
77 // <, == or > the second value.
79 // This implementation does a case insensitive locale specific string
81 virtual int CompareValues(int row1
, int row2
, int column_id
);
83 // Reset the collator.
87 virtual ~TableModel() {}
89 // Returns the collator used by CompareValues.
90 icu::Collator
* GetCollator();
93 // TableColumn specifies the title, alignment and size of a particular column.
94 struct UI_BASE_EXPORT TableColumn
{
100 TableColumn(int id
, Alignment alignment
, int width
, float percent
);
102 // A unique identifier for the column.
105 // The title for the column.
106 base::string16 title
;
108 // Alignment for the content.
111 // The size of a column may be specified in two ways:
112 // 1. A fixed width. Set the width field to a positive number and the
113 // column will be given that width, in pixels.
114 // 2. As a percentage of the available width. If width is -1, and percent is
115 // > 0, the column is given a width of
116 // available_width * percent / total_percent.
117 // 3. If the width == -1 and percent == 0, the column is autosized based on
118 // the width of the column header text.
120 // Sizing is done in four passes. Fixed width columns are given
121 // their width, percentages are applied, autosized columns are autosized,
122 // and finally percentages are applied again taking into account the widths
123 // of autosized columns.
127 // The minimum width required for all items in this column
128 // (including the header)
130 int min_visible_width
;
132 // Is this column sortable? Default is false
138 #endif // UI_BASE_MODELS_TABLE_MODEL_H_