/* Copyright (C) 2013 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 <https://www.gnu.org/licenses/>.
 */

#include <gtkmm/selectionlistmodelimpl.h>
#include <gtk/gtk.h>

namespace Gtk
{

Glib::RefPtr<SelectionModel> Stack::get_pages()
{
  // gtk_stack_get_pages() returns a pointer to a private GObject class that
  // implements GListModel and GtkSelectionModel.
  // Such an instance is wrapped in a Gtk::SelectionListModelImpl.
  // gtk_stack_get_pages() gives us a ref (transfer full).
  GtkSelectionModel* stack_pages = gtk_stack_get_pages(gobj());
  if (G_IS_LIST_MODEL(stack_pages))
  {
    // Look up current C++ wrapper instance:
    Glib::ObjectBase* pCppObject = Glib::ObjectBase::_get_current_wrapper((GObject*)stack_pages);
    if (!pCppObject)
      pCppObject = new SelectionListModelImpl((GObject*)stack_pages);
    return Glib::make_refptr_for_instance<SelectionModel>(dynamic_cast<SelectionModel*>(pCppObject));
  }
  return Glib::wrap(stack_pages);
}

} //namespace Gtk
