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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gtkmm/listviewtext.h>
namespace Gtk
{
ListViewText::TextModelColumns::TextModelColumns(guint columns_count)
: m_columns_count(columns_count)
{
m_columns = new Gtk::TreeModelColumn<Glib::ustring>[m_columns_count];
if(m_columns)
{
for(guint i = 0; i < m_columns_count; ++i)
{
add(m_columns[i]);
}
}
}
ListViewText::TextModelColumns::~TextModelColumns()
{
if(m_columns)
delete[] m_columns;
}
guint ListViewText::TextModelColumns::get_num_columns() const
{
return m_columns_count;
}
ListViewText::ListViewText(guint columns_count, bool editable, Gtk::SelectionMode mode)
: m_model_columns(columns_count)
{
char column_title[20];
// Create model
m_model = Gtk::ListStore::create(m_model_columns);
set_model(m_model);
// Append columns
for(guint i = 0; i < columns_count; ++i)
{
//Get text for the number:
sprintf(column_title, "%d", i);
if(editable)
append_column_editable(column_title, m_model_columns.m_columns[i]);
else
append_column(column_title, m_model_columns.m_columns[i]);
}
// Set multiple or simple selection
get_selection()->set_mode(mode);
}
ListViewText::~ListViewText()
{
}
void ListViewText::set_column_title(guint column, const Glib::ustring& title)
{
g_return_if_fail( column < get_columns().size() );
get_column(column)->set_title(title);
}
Glib::ustring ListViewText::get_column_title(guint column) const
{
g_return_val_if_fail( column < get_columns().size(), "" ); //Using Glib::ustring() fails sometimes: Bug #352226
return get_column(column)->get_title();
}
guint ListViewText::append(const Glib::ustring& column_one_value)
{
Gtk::TreeModel::Row newRow = *(m_model->append());
newRow[m_model_columns.m_columns[0]] = column_one_value;
return size() - 1;
}
void ListViewText::prepend(const Glib::ustring& column_one_value)
{
Gtk::TreeModel::Row newRow = *(m_model->prepend());
newRow[m_model_columns.m_columns[0]] = column_one_value;
}
void ListViewText::insert(guint row, const Glib::ustring& column_one_value)
{
g_return_if_fail( row < size() );
Gtk::ListStore::const_iterator iter = m_model->children()[row];
Gtk::TreeModel::Row newRow = *(m_model->insert(iter));
if(!column_one_value.empty())
{
newRow[m_model_columns.m_columns[0]] = column_one_value;
}
}
void ListViewText::clear_items()
{
m_model->clear();
}
Glib::ustring ListViewText::get_text(guint row, guint column) const
{
Glib::ustring result;
g_return_val_if_fail( row < size(), result );
Gtk::TreeModel::iterator iter = m_model->children()[row];
iter->get_value(column, result);
return result;
}
void ListViewText::set_text(guint row, guint column, const Glib::ustring& value)
{
g_return_if_fail( row < size() );
Gtk::TreeModel::iterator iter = m_model->children()[row];
(*iter)->set_value(column, value);
}
void ListViewText::set_text(guint row, const Glib::ustring& value)
{
g_return_if_fail( row < size() );
Gtk::TreeModel::iterator iter = m_model->children()[ row ];
(*iter)->set_value(0, value);
}
guint ListViewText::size() const
{
return (guint)m_model->children().size();
}
guint ListViewText::get_num_columns() const
{
return m_model_columns.get_num_columns();
}
ListViewText::SelectionList ListViewText::get_selected()
{
Glib::RefPtr<Gtk::TreeSelection> selected = get_selection();
std::vector<TreeModel::Path> selectedRows = selected->get_selected_rows();
// Reserve space
SelectionList selectionList;
selectionList.reserve( selected->count_selected_rows() );
// Save selected rows
for (std::vector<TreeModel::Path>::const_iterator iter = selectedRows.begin(); iter != selectedRows.end(); ++iter)
{
selectionList.push_back( *((*iter).begin()) );
}
return selectionList;
}
} //namespace Gtk
|