/* Copyright 2006 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, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>

// This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.

static int SignalProxy_Compare_gtk_callback(GtkRecentInfo* a, GtkRecentInfo* b, gpointer data)
{
  const Gtk::RecentChooser::SlotCompare* the_slot = static_cast<Gtk::RecentChooser::SlotCompare*>(data);

  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  try
  {
  #endif //GLIBMM_EXCEPTIONS_ENABLED
    return (*the_slot)(Glib::wrap(a, true /* take reference */), Glib::wrap(b, true /* take reference */));
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  }
  catch(...)
  {
    Glib::exception_handlers_invoke();
  }

  return 0;
  #endif //GLIBMM_EXCEPTIONS_ENABLED
}

static void SignalProxy_Compare_gtk_callback_destroy(gpointer data)
{
  delete static_cast<Gtk::RecentChooser::SlotCompare*>(data);
}


namespace Gtk
{

//Allow the generated code to work without the prefix:
typedef RecentChooser::ListHandle_RecentInfos ListHandle_RecentInfos;

void RecentChooser::set_sort_func(const SlotCompare& slot)
{
  SlotCompare* slot_copy = new SlotCompare(slot);

  gtk_recent_chooser_set_sort_func(
      gobj(),
      &SignalProxy_Compare_gtk_callback, slot_copy,
      &SignalProxy_Compare_gtk_callback_destroy);
}

Glib::StringArrayHandle RecentChooser::get_uris() const
{
  return Glib::StringArrayHandle(gtk_recent_chooser_get_uris(const_cast<GtkRecentChooser*>(gobj()), NULL));
}

void RecentChooser::unset_limit()
{
  gtk_recent_chooser_set_limit(gobj(), -1 /* See C docs */);
}

} // namespace Gtk

