Add stuff missing from yesterday's library commit.
[ardour.git] / libs / gtkmm2 / gtk / gtkmm / listviewtext.h
1 /* Copyright(C) 2006 The gtkmm Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or(at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the Free
15  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  */
17
18 #ifndef _GTKMM_LISTVIEW_TEXT_H
19 #define _GTKMM_LISTVIEW_TEXT_H
20
21 #include <gtkmm/treeview.h>
22 #include <gtkmm/liststore.h>
23
24 #include <vector>
25
26 namespace Gtk
27 {
28
29 /** A simple listbox which presents some lines of information in columns and lets the user select some of them.
30  *
31  * This is a convenience class, based on Gtk::TreeView, which allows only text values and does not allow child items.
32  * In most cases you will actually need the functionality offered by a real Gtk::TreeView with your own type-safe 
33  * Gtk::TreeModel::ColumnRecord.
34  *
35  * @ingroup Widgets
36  * @ingroup Containers
37  * @ingroup TreeView
38  *
39  * @newin2p10
40  */
41 class ListViewText : public Gtk::TreeView
42 {
43 public:
44
45   ListViewText(guint columns_count, bool editable = false, Gtk::SelectionMode mode = Gtk::SELECTION_SINGLE);
46   virtual ~ListViewText();
47
48   /** Adds a title to column @a column.
49    * @param column the column number.
50    * @param title the title for column @a column.
51    */
52   void set_column_title(guint column, const Glib::ustring& title);
53
54   /** Gets the title of column @a column.
55    * @param column the column number.
56    * @return the title of column @a column.
57    */
58   Glib::ustring get_column_title(guint column) const;
59
60   /** Add a new row at the end of the list
61    * @param column_one_value the new text for the new row, column 0
62    * @return the number of the row added
63    */
64   guint append_text(const Glib::ustring& column_one_value = Glib::ustring());
65
66   /** Insert a new row at the beginning of the list
67    * @param column_one_value the new text for the new row, column 0
68    */
69   void prepend_text(const Glib::ustring& column_one_value = Glib::ustring());
70
71   /** Insert a new row at an arbitrary position in the list
72    * @param row The row number
73    * @param column_one_value the new text for the new row, column 0
74    */
75   void insert_text(guint row, const Glib::ustring& column_one_value = Glib::ustring());
76
77   /// Discard all row:
78   void clear_items();
79
80   /** Obtain the value of an existing cell from the list.
81    * @param row the number of the row in the listbox.
82    * @param column the number of the column in the row.
83    * @return the value of that cell, if it exists.
84    */
85   Glib::ustring get_text(guint row, guint column = 0) const;
86
87   /** Change an existing value of cell of the list.
88    * @param row the number of the row in the list.
89    * @param column the number of the column in the row.  
90    * @param value the new contents of that row and column.
91    */
92   void set_text(guint row, guint column, const Glib::ustring& value);
93
94   /** Change an existing value of a column 0 of a row of the list
95    * @param row the number of the row in the list.
96    * @param value the new contents of column 0 of the row.
97    */
98   void set_text(guint row, const Glib::ustring& value);
99
100   /// @return the number of rows in the listbox
101   guint size() const;
102
103   /// @return the number of columns in the listbox
104   guint get_num_columns() const;
105
106   typedef std::vector<int> SelectionList;
107
108   /** Returns a vector of the indexes of the selected rows
109     * @return a SelectionList with the selection results
110     */
111   SelectionList get_selected();
112
113 protected:
114
115  class TextModelColumns : public Gtk::TreeModel::ColumnRecord
116   {
117   public:
118     TextModelColumns(guint columns_count);
119     ~TextModelColumns();
120
121     guint get_num_columns() const;
122
123     Gtk::TreeModelColumn<Glib::ustring>* m_columns;
124
125   protected:
126     guint m_columns_count;
127   };
128
129   Glib::RefPtr<Gtk::ListStore> m_model;
130   TextModelColumns m_model_columns;
131 };
132
133 } //namespace Gtk
134
135 #endif //_GTKMM_LISTVIEW_TEXT_H
136