2 * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ardour/session.h"
23 #include "ardour/types.h"
25 #include "axis_provider.h"
26 #include "stripable_treemodel.h"
28 using namespace ARDOUR;
30 StripableTreeModel::Glue::Glue (boost::shared_ptr<Stripable> s)
35 StripableTreeModel::StripableTreeModel (AxisViewProvider& avp)
36 : Glib::ObjectBase( typeid(StripableTreeModel) ) //register a custom GType.
37 , Glib::Object() //The custom GType is actually registered here.
38 , axis_view_provider (avp)
40 n_columns = columns.size();
44 StripableTreeModel::set_session (Session& s)
49 StripableTreeModel::~StripableTreeModel()
53 Glib::RefPtr<StripableTreeModel>
54 StripableTreeModel::create (AxisViewProvider& avp)
56 return Glib::RefPtr<StripableTreeModel> (new StripableTreeModel (avp));
60 StripableTreeModel::get_flags_vfunc() const
62 return Gtk::TREE_MODEL_LIST_ONLY;
66 StripableTreeModel::get_n_columns_vfunc() const
72 StripableTreeModel::get_column_type_vfunc (int index) const
74 if (index <= n_columns) {
75 return columns.types()[index];
81 StripableTreeModel::get_value_vfunc (const TreeModel::iterator& iter, int column, Glib::ValueBase& value) const
87 if (column > n_columns) {
91 const Glue* glue = (const Glue*)iter.gobj()->user_data;
92 boost::shared_ptr<Stripable> iter_stripable = glue->stripable.lock();
94 if (!iter_stripable) {
100 return text_value (iter_stripable, value);
105 StripableTreeModel::text_value (boost::shared_ptr<Stripable> stripable, Glib::ValueBase& value) const
107 StringColumn::ValueType val;
108 val.set (stripable->name());
113 StripableTreeModel::iter_next_vfunc (const iterator& iter, iterator& iter_next) const
119 const Glue* glue = (const Glue*)iter.gobj()->user_data;
120 boost::shared_ptr<Stripable> iter_stripable = glue->stripable.lock();
122 if (!iter_stripable) {
126 //initialize the next iterator:
127 iter_next = iterator();
130 _session->get_stripables (sl);
134 sl.sort (Stripable::Sorter());
136 for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) {
138 if (*s == iter_stripable) {
141 Glue* new_glue = new Glue (iter_stripable);
142 iter_next.gobj()->user_data = (void*)new_glue;
143 remember_glue_item (new_glue);
144 return true; //success
150 return false; //There is no next row.
154 StripableTreeModel::iter_children_vfunc(const iterator& parent, iterator& iter) const
160 StripableTreeModel::iter_has_child_vfunc(const iterator& iter) const
166 StripableTreeModel::iter_n_children_vfunc(const iterator& iter) const
172 StripableTreeModel::iter_n_root_children_vfunc() const
176 _session->get_stripables (sl);
183 StripableTreeModel::iter_nth_child_vfunc(const iterator& parent, int /* n */, iterator& iter) const
185 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
186 return false; //There are no children.
190 StripableTreeModel::iter_nth_root_child_vfunc(int n, iterator& iter) const
192 iter = iterator(); //clear the input parameter.
198 _session->get_stripables (sl);
204 sl.sort (Stripable::Sorter());
206 StripableList::const_iterator s;
208 for (s = sl.begin(); s != sl.end() && n > 0; ++s, --n);
211 Glue* new_glue = new Glue (*s);
212 iter.gobj()->user_data = new_glue;
213 remember_glue_item (new_glue);
217 return false; //There are no children.
221 StripableTreeModel::iter_parent_vfunc(const iterator& child, iterator& iter) const
223 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
224 return false; //There are no children, so no parents.
228 StripableTreeModel::get_path_vfunc(const iterator& /* iter */) const
235 StripableTreeModel::get_iter_vfunc (const Path& path, iterator& iter) const
237 unsigned sz = path.size();
240 /* path must refer to something, but not children since we
243 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
247 return iter_nth_root_child_vfunc (path[0], iter);
251 StripableTreeModel::iter_is_valid(const iterator& iter) const
253 const Glue* glue = (const Glue*)iter.gobj()->user_data;
255 if (!glue->stripable.lock()) {
259 return Gtk::TreeModel::iter_is_valid(iter);
263 StripableTreeModel::remember_glue_item (Glue* item) const
265 glue_list.insert (item);