1 /* Copyright(C) 2006 The gtkmm Development Team
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.
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.
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.
18 #ifndef _GTKMM_LISTVIEW_TEXT_H
19 #define _GTKMM_LISTVIEW_TEXT_H
21 #include <gtkmm/treeview.h>
22 #include <gtkmm/liststore.h>
29 /** A simple listbox which presents some lines of information in columns and lets the user select some of them.
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.
41 class ListViewText : public Gtk::TreeView
45 ListViewText(guint columns_count, bool editable = false, Gtk::SelectionMode mode = Gtk::SELECTION_SINGLE);
46 virtual ~ListViewText();
48 /** Adds a title to column @a column.
49 * @param column the column number.
50 * @param title the title for column @a column.
52 void set_column_title(guint column, const Glib::ustring& title);
54 /** Gets the title of column @a column.
55 * @param column the column number.
56 * @return the title of column @a column.
58 Glib::ustring get_column_title(guint column) const;
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
64 guint append_text(const Glib::ustring& column_one_value = Glib::ustring());
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
69 void prepend_text(const Glib::ustring& column_one_value = Glib::ustring());
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
75 void insert_text(guint row, const Glib::ustring& column_one_value = Glib::ustring());
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.
85 Glib::ustring get_text(guint row, guint column = 0) const;
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.
92 void set_text(guint row, guint column, const Glib::ustring& value);
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.
98 void set_text(guint row, const Glib::ustring& value);
100 /// @return the number of rows in the listbox
103 /// @return the number of columns in the listbox
104 guint get_num_columns() const;
106 typedef std::vector<int> SelectionList;
108 /** Returns a vector of the indexes of the selected rows
109 * @return a SelectionList with the selection results
111 SelectionList get_selected();
115 class TextModelColumns : public Gtk::TreeModel::ColumnRecord
118 TextModelColumns(guint columns_count);
121 guint get_num_columns() const;
123 Gtk::TreeModelColumn<Glib::ustring>* m_columns;
126 guint m_columns_count;
129 Glib::RefPtr<Gtk::ListStore> m_model;
130 TextModelColumns m_model_columns;
135 #endif //_GTKMM_LISTVIEW_TEXT_H