/* buffer.cc
 *
 * Copyright (C) 2004-2005 Jae Jang
 * Copyright (C) 2005-2006 Rob Page
 * Copyright (C) 2006 Dodji Seketeli
 * Copyright (C) 2009, 2010, 2011 Krzesimir Nowak
 *
 * 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.
 */

#include <gtksourceview/gtksource.h>

#include <glibmm/vectorutils.h>

namespace Gsv
{

Buffer::Buffer () :
  _CONSTRUCT("tag-table", 0)
{}

Buffer::Buffer (const Glib::RefPtr<Gtk::TextTagTable>& tag_table) :
  _CONSTRUCT("tag-table", Glib::unwrap(tag_table))
{}

Buffer::Buffer (const Glib::RefPtr<Language> &language) :
    _CONSTRUCT("tag-table", 0, "language", Glib::unwrap(language))
{
}

bool Buffer::backward_iter_to_source_mark(Gtk::TextIter& iter)
{
    return gtk_source_buffer_backward_iter_to_source_mark(gobj(), iter.gobj(), 0);
}

bool Buffer::forward_iter_to_source_mark(Gtk::TextIter& iter)
{
    return gtk_source_buffer_forward_iter_to_source_mark(gobj(), iter.gobj(), 0);
}

Glib::RefPtr<Gsv::Mark>
Buffer::create_source_mark(const Glib::ustring& category, const Gtk::TextIter& where)
{
  return Glib::wrap(gtk_source_buffer_create_source_mark(gobj(), 0, category.c_str(), where.gobj()));
}

std::vector<Glib::RefPtr<Gsv::Mark> > Buffer::get_source_marks_at_line(int line) const
{
    return Glib::SListHandler<Glib::RefPtr<Gsv::Mark> >::slist_to_vector(gtk_source_buffer_get_source_marks_at_line(const_cast<GtkSourceBuffer*>(gobj()), line, 0), Glib::OWNERSHIP_SHALLOW);
}

std::vector<Glib::RefPtr<Gsv::Mark> > Buffer::get_source_marks_at_iter(Gtk::TextIter& iter) const
{
    return Glib::SListHandler<Glib::RefPtr<Gsv::Mark> >::slist_to_vector(gtk_source_buffer_get_source_marks_at_iter(const_cast<GtkSourceBuffer*>(gobj()), iter.gobj(), 0), Glib::OWNERSHIP_SHALLOW);
}

void
Buffer::remove_source_marks(const Gtk::TextIter& start, const Gtk::TextIter& end)
{
  gtk_source_buffer_remove_source_marks(gobj(), start.gobj(), end.gobj(), 0);
}

void
Buffer::unset_style_scheme()
{
  gtk_source_buffer_set_style_scheme(gobj(), 0);
}

void
Buffer::set_default_undo_manager()
{
  gtk_source_buffer_set_undo_manager(gobj(), 0);
}

}//end namespace Gsv


