1 /* Copyright (C) 2017 Paul Davis
2 * based on gtkmm example Copyright (C) 2002 gtkmm development team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * This program 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
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ardour/session.h"
21 #include "ardour/types.h"
23 #include "axis_provider.h"
24 #include "stripable_treemodel.h"
26 using namespace ARDOUR;
28 StripableTreeModel::Glue::Glue (boost::shared_ptr<Stripable> s)
33 StripableTreeModel::StripableTreeModel (AxisViewProvider& avp)
34 : Glib::ObjectBase( typeid(StripableTreeModel) ) //register a custom GType.
35 , Glib::Object() //The custom GType is actually registered here.
36 , axis_view_provider (avp)
38 n_columns = columns.size();
42 StripableTreeModel::set_session (Session& s)
47 StripableTreeModel::~StripableTreeModel()
51 Glib::RefPtr<StripableTreeModel>
52 StripableTreeModel::create (AxisViewProvider& avp)
54 return Glib::RefPtr<StripableTreeModel> (new StripableTreeModel (avp));
58 StripableTreeModel::get_flags_vfunc() const
60 return Gtk::TREE_MODEL_LIST_ONLY;
64 StripableTreeModel::get_n_columns_vfunc() const
70 StripableTreeModel::get_column_type_vfunc (int index) const
72 if (index <= n_columns) {
73 return columns.types()[index];
79 StripableTreeModel::get_value_vfunc (const TreeModel::iterator& iter, int column, Glib::ValueBase& value) const
85 if (column > n_columns) {
89 const Glue* glue = (const Glue*)iter.gobj()->user_data;
90 boost::shared_ptr<Stripable> iter_stripable = glue->stripable.lock();
92 if (!iter_stripable) {
98 return text_value (iter_stripable, value);
103 StripableTreeModel::text_value (boost::shared_ptr<Stripable> stripable, Glib::ValueBase& value) const
105 StringColumn::ValueType val;
106 val.set (stripable->name());
111 StripableTreeModel::iter_next_vfunc (const iterator& iter, iterator& iter_next) const
117 const Glue* glue = (const Glue*)iter.gobj()->user_data;
118 boost::shared_ptr<Stripable> iter_stripable = glue->stripable.lock();
120 if (!iter_stripable) {
124 //initialize the next iterator:
125 iter_next = iterator();
128 _session->get_stripables (sl);
132 sl.sort (Stripable::Sorter());
134 for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) {
136 if (*s == iter_stripable) {
139 Glue* new_glue = new Glue (iter_stripable);
140 iter_next.gobj()->user_data = (void*)new_glue;
141 remember_glue_item (new_glue);
142 return true; //success
148 return false; //There is no next row.
152 StripableTreeModel::iter_children_vfunc(const iterator& parent, iterator& iter) const
158 StripableTreeModel::iter_has_child_vfunc(const iterator& iter) const
164 StripableTreeModel::iter_n_children_vfunc(const iterator& iter) const
170 StripableTreeModel::iter_n_root_children_vfunc() const
174 _session->get_stripables (sl);
181 StripableTreeModel::iter_nth_child_vfunc(const iterator& parent, int /* n */, iterator& iter) const
183 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
184 return false; //There are no children.
188 StripableTreeModel::iter_nth_root_child_vfunc(int n, iterator& iter) const
190 iter = iterator(); //clear the input parameter.
196 _session->get_stripables (sl);
202 sl.sort (Stripable::Sorter());
204 StripableList::const_iterator s;
206 for (s = sl.begin(); s != sl.end() && n > 0; ++s, --n);
209 Glue* new_glue = new Glue (*s);
210 iter.gobj()->user_data = new_glue;
211 remember_glue_item (new_glue);
215 return false; //There are no children.
219 StripableTreeModel::iter_parent_vfunc(const iterator& child, iterator& iter) const
221 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
222 return false; //There are no children, so no parents.
226 StripableTreeModel::get_path_vfunc(const iterator& /* iter */) const
233 StripableTreeModel::get_iter_vfunc (const Path& path, iterator& iter) const
235 unsigned sz = path.size();
238 /* path must refer to something, but not children since we
241 iter = iterator(); //Set is as invalid, as the TreeModel documentation says that it should be.
245 return iter_nth_root_child_vfunc (path[0], iter);
249 StripableTreeModel::iter_is_valid(const iterator& iter) const
251 const Glue* glue = (const Glue*)iter.gobj()->user_data;
253 if (!glue->stripable.lock()) {
257 return Gtk::TreeModel::iter_is_valid(iter);
261 StripableTreeModel::remember_glue_item (Glue* item) const
263 glue_list.insert (item);