/* Copyright (C) 1998-2002 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, see .
*/
#include
#include
#include
namespace Gtk
{
TreePath::TreePath(GtkTreePath* gobject, bool make_a_copy)
:
// For BoxedType wrappers, make_a_copy is true by default. The static
// BoxedType wrappers must always take a copy, thus make_a_copy = true
// ensures identical behaviour if the default argument is used.
gobject_ (gobject ? (make_a_copy ? gtk_tree_path_copy(gobject) : gobject) : gtk_tree_path_new())
{}
TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
:
gobject_(gtk_tree_path_new())
{
for(; n > 0; --n)
gtk_tree_path_append_index(gobject_, value);
}
TreePath::TreePath(const Glib::ustring& path)
:
gobject_ (gtk_tree_path_new_from_string(path.c_str()))
{
if (!gobject_)
gobject_ = gtk_tree_path_new();
}
TreePath::TreePath(const TreeModel::iterator& iter)
:
// The GtkTreePath* is always newly created.
gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast(iter.gobj())))
{
if (!gobject_)
gobject_ = gtk_tree_path_new();
}
TreePath& TreePath::operator=(const TreeModel::iterator& iter)
{
TreePath temp(iter);
swap(temp);
return *this;
}
void TreePath::clear()
{
TreePath empty_path;
swap(empty_path);
}
TreePath::size_type TreePath::size() const
{
return gtk_tree_path_get_depth(gobject_);
}
_DEPRECATE_IFDEF_START
TreePath::operator const void*() const
{
return !empty() ? GINT_TO_POINTER(1) : nullptr;
}
_DEPRECATE_IFDEF_END
TreePath::operator bool() const
{
return !empty();
}
bool TreePath::empty() const
{
return (gtk_tree_path_get_depth(gobject_) == 0);
}
TreePath::reference TreePath::operator[](TreePath::size_type i)
{
int *const indices = gtk_tree_path_get_indices(gobject_);
return indices[i];
}
TreePath::const_reference TreePath::operator[](TreePath::size_type i) const
{
const int *const indices = gtk_tree_path_get_indices(gobject_);
return indices[i];
}
TreePath::iterator TreePath::begin()
{
return gtk_tree_path_get_indices(gobject_);
}
TreePath::iterator TreePath::end()
{
return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
}
TreePath::const_iterator TreePath::begin() const
{
return gtk_tree_path_get_indices(gobject_);
}
TreePath::const_iterator TreePath::end() const
{
return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
}
bool TreePath::get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr& model, TreePath& path) //static
{
GtkTreeModel* src_model = nullptr;
GtkTreePath* src_path = nullptr;
gboolean result = gtk_tree_get_row_drag_data(const_cast(selection_data.gobj()), &src_model, &src_path);
model = Glib::wrap(src_model, true /* take_copy=true */);
//gtk_tree_get_row_drag_data gives us ownership of src_path.
path = Glib::wrap(src_path, false /* take_copy=false */);
return result;
}
bool TreePath::get_from_selection_data(const SelectionData& selection_data, TreePath& path) //static
{
GtkTreePath* src_path = nullptr;
gboolean result = gtk_tree_get_row_drag_data(const_cast(selection_data.gobj()), nullptr, &src_path);
//gtk_tree_get_row_drag_data gives us ownership of src_path.
path = Glib::wrap(src_path, false /* take_copy=false */);
return result;
}
bool TreePath::set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr& model) const
{
return gtk_tree_set_row_drag_data(selection_data.gobj(), const_cast(model->gobj()), const_cast(gobj()));
}
} // namespace Gtk