summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/gtk/gtkmm/listviewtext.h
blob: b8236abcdccfae9e5590eb7e1672f37673933b2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Copyright(C) 2006 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or(at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _GTKMM_LISTVIEW_TEXT_H
#define _GTKMM_LISTVIEW_TEXT_H

#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>

#include <vector>

namespace Gtk
{

/** A simple listbox which presents some lines of information in columns and lets the user select some of them.
 *
 * This is a convenience class, based on Gtk::TreeView, which allows only text values and does not allow child items.
 * In most cases you will actually need the functionality offered by a real Gtk::TreeView with your own type-safe 
 * Gtk::TreeModel::ColumnRecord.
 *
 * @ingroup Widgets
 * @ingroup Containers
 * @ingroup TreeView
 *
 * @newin2p10
 */
class ListViewText : public Gtk::TreeView
{
public:

  ListViewText(guint columns_count, bool editable = false, Gtk::SelectionMode mode = Gtk::SELECTION_SINGLE);
  virtual ~ListViewText();

  /** Adds a title to column @a column.
   * @param column the column number.
   * @param title the title for column @a column.
   */
  void set_column_title(guint column, const Glib::ustring& title);

  /** Gets the title of column @a column.
   * @param column the column number.
   * @return the title of column @a column.
   */
  Glib::ustring get_column_title(guint column) const;

  /** Add a new row at the end of the list
   * @param column_one_value the new text for the new row, column 0
   * @return the number of the row added
   */
  guint append_text(const Glib::ustring& column_one_value = Glib::ustring());

  /** Insert a new row at the beginning of the list
   * @param column_one_value the new text for the new row, column 0
   */
  void prepend_text(const Glib::ustring& column_one_value = Glib::ustring());

  /** Insert a new row at an arbitrary position in the list
   * @param row The row number
   * @param column_one_value the new text for the new row, column 0
   */
  void insert_text(guint row, const Glib::ustring& column_one_value = Glib::ustring());

  /// Discard all row:
  void clear_items();

  /** Obtain the value of an existing cell from the list.
   * @param row the number of the row in the listbox.
   * @param column the number of the column in the row.
   * @return the value of that cell, if it exists.
   */
  Glib::ustring get_text(guint row, guint column = 0) const;

  /** Change an existing value of cell of the list.
   * @param row the number of the row in the list.
   * @param column the number of the column in the row.	 
   * @param value the new contents of that row and column.
   */
  void set_text(guint row, guint column, const Glib::ustring& value);

  /** Change an existing value of a column 0 of a row of the list
   * @param row the number of the row in the list.
   * @param value the new contents of column 0 of the row.
   */
  void set_text(guint row, const Glib::ustring& value);

  /// @return the number of rows in the listbox
  guint size() const;

  /// @return the number of columns in the listbox
  guint get_num_columns() const;

  typedef std::vector<int> SelectionList;

  /** Returns a vector of the indexes of the selected rows
    * @return a SelectionList with the selection results
    */
  SelectionList get_selected();

protected:

 class TextModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:
    TextModelColumns(guint columns_count);
    ~TextModelColumns();

    guint get_num_columns() const;

    Gtk::TreeModelColumn<Glib::ustring>* m_columns;

  protected:
    guint m_columns_count;
  };

  Glib::RefPtr<Gtk::ListStore> m_model;
  TextModelColumns m_model_columns;
};

} //namespace Gtk

#endif //_GTKMM_LISTVIEW_TEXT_H