• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_BASE_MODELS_TABLE_MODEL_H_
6 #define UI_BASE_MODELS_TABLE_MODEL_H_
7 
8 #include <vector>
9 
10 #include "base/strings/string16.h"
11 #include "third_party/icu/source/i18n/unicode/coll.h"
12 #include "ui/base/ui_export.h"
13 
14 namespace gfx {
15 class ImageSkia;
16 }
17 
18 namespace ui {
19 
20 class TableModelObserver;
21 
22 // The model driving the TableView.
23 class UI_EXPORT TableModel {
24  public:
25   // See HasGroups, get GetGroupID for details as to how this is used.
26   struct Group {
27     // The title text for the group.
28     base::string16 title;
29 
30     // Unique id for the group.
31     int id;
32   };
33   typedef std::vector<Group> Groups;
34 
35   // Number of rows in the model.
36   virtual int RowCount() = 0;
37 
38   // Returns the value at a particular location in text.
39   virtual base::string16 GetText(int row, int column_id) = 0;
40 
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
44   // no image.
45   virtual gfx::ImageSkia GetIcon(int row);
46 
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
49   // column zero.
50   virtual base::string16 GetTooltip(int row);
51 
52   // If true, this row should be indented.
53   virtual bool ShouldIndent(int row);
54 
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
58   // the group.
59   //
60   // On win2k a visual separator is not rendered for the group headers.
61   virtual bool HasGroups();
62 
63   // Returns the groups.
64   // This is only used if HasGroups returns true.
65   virtual Groups GetGroups();
66 
67   // Returns the group id of the specified row.
68   // This is only used if HasGroups returns true.
69   virtual int GetGroupID(int row);
70 
71   // Sets the observer for the model. The TableView should NOT take ownership
72   // of the observer.
73   virtual void SetObserver(TableModelObserver* observer) = 0;
74 
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.
78   //
79   // This implementation does a case insensitive locale specific string
80   // comparison.
81   virtual int CompareValues(int row1, int row2, int column_id);
82 
83   // Reset the collator.
84   void ClearCollator();
85 
86  protected:
~TableModel()87   virtual ~TableModel() {}
88 
89   // Returns the collator used by CompareValues.
90   icu::Collator* GetCollator();
91 };
92 
93 // TableColumn specifies the title, alignment and size of a particular column.
94 struct UI_EXPORT TableColumn {
95   enum Alignment {
96     LEFT, RIGHT, CENTER
97   };
98 
99   TableColumn();
100   TableColumn(int id, Alignment alignment, int width, float percent);
101 
102   // A unique identifier for the column.
103   int id;
104 
105   // The title for the column.
106   base::string16 title;
107 
108   // Alignment for the content.
109   Alignment alignment;
110 
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.
119   //
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.
124   int width;
125   float percent;
126 
127   // The minimum width required for all items in this column
128   // (including the header)
129   // to be visible.
130   int min_visible_width;
131 
132   // Is this column sortable? Default is false
133   bool sortable;
134 };
135 
136 }  // namespace ui
137 
138 #endif  // UI_BASE_MODELS_TABLE_MODEL_H_
139