// -*- c++ -*-
/* $Id: linkbutton.ccg,v 1.1 2006/01/29 12:21:43 murrayc Exp $ */

/*
 *
 * 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>

_DEPRECATE_IFDEF_START
static void SignalProxy_UriHook_gtk_callback(GtkLinkButton *button, const gchar *link, gpointer user_data)
{
  Gtk::LinkButton::SlotUri* the_slot = static_cast<Gtk::LinkButton::SlotUri*>(user_data);

  try
  {
    // use Slot::operator()
    (*the_slot)(Glib::wrap(button), Glib::convert_const_gchar_ptr_to_ustring(link));
  }
  catch(...)
  {
    Glib::exception_handlers_invoke();
  }
}

static void SignalProxy_UriHook_gtk_callback_destroy(void* data)
{
  delete static_cast<Gtk::LinkButton::SlotUri*>(data);
}
_DEPRECATE_IFDEF_END


namespace Gtk
{

_DEPRECATE_IFDEF_START
LinkButton::LinkButton(const Glib::ustring& uri)
:
  _CONSTRUCT("uri", uri.c_str(), "label", uri.c_str()) //Note that the uri is used for the label too, as in the C _new() function.
{}

void LinkButton::set_uri_hook(const SlotUri& slot)
{
  //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
  //It will be deleted when TreeView_Private::SignalProxy_CellData_gtk_callback_destroy() is called.
   SlotUri* slot_copy = new SlotUri(slot);

  gtk_link_button_set_uri_hook (&SignalProxy_UriHook_gtk_callback, slot_copy, &SignalProxy_UriHook_gtk_callback_destroy);
}

void LinkButton::unset_uri_hook()
{
  gtk_link_button_set_uri_hook (0, 0, 0);
}
_DEPRECATE_IFDEF_END

} // namespace Gtk

