/* Copyright (C) 2014 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
namespace
{
static void FuncProxy_Foreach_gtk_callback(GtkFlowBox* box, GtkFlowBoxChild* child, void* data)
{
auto the_slot = static_cast(data);
try
{
(*the_slot)(Glib::wrap(box), Glib::wrap(child));
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
static gboolean SignalProxy_Filter_gtk_callback(GtkFlowBoxChild* child, void* data)
{
auto the_slot = static_cast(data);
try
{
return (*the_slot)(Glib::wrap(child));
}
catch(...)
{
Glib::exception_handlers_invoke();
return FALSE;
}
}
static void SignalProxy_Filter_gtk_callback_destroy(void* data)
{
delete static_cast(data);
}
static gint SignalProxy_Sort_gtk_callback(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, void* data)
{
auto the_slot = static_cast(data);
try
{
return (*the_slot)(Glib::wrap(child1), Glib::wrap(child2));
}
catch(...)
{
Glib::exception_handlers_invoke();
return 0;
}
}
static void SignalProxy_Sort_gtk_callback_destroy(void* data)
{
delete static_cast(data);
}
static GtkWidget* proxy_bind_model_create_widget_callback(void* item, void* data)
{
auto& slot = *static_cast*>(data);
auto cobject = static_cast(item);
try
{
// take_copy is true here, because wrap() returns a Glib::RefPtr.
// cobject will be unreferenced when the RefPtr is deleted.
Gtk::Widget* widget = slot(Glib::wrap(cobject, true));
if (widget)
return widget->gobj();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return nullptr;
}
} // anonymous namespace
namespace Gtk
{
void FlowBox::selected_foreach(const SlotSelectedForeach& slot)
{
SlotSelectedForeach slot_local_copy(slot);
gtk_flow_box_selected_foreach(gobj(),
&FuncProxy_Foreach_gtk_callback, &slot_local_copy);
}
void FlowBox::set_filter_func(const SlotFilter& slot)
{
// Create a copy of the slot object. A pointer to this will be passed
// through the callback's data parameter. It will be deleted
// when SignalProxy_Filter_gtk_callback_destroy() is called.
auto slot_copy = new SlotFilter(slot);
gtk_flow_box_set_filter_func(gobj(),
&SignalProxy_Filter_gtk_callback, slot_copy,
&SignalProxy_Filter_gtk_callback_destroy);
}
void FlowBox::unset_filter_func()
{
gtk_flow_box_set_filter_func(gobj(), nullptr, nullptr, nullptr);
}
void FlowBox::set_sort_func(const SlotSort& slot)
{
// Create a copy of the slot object. A pointer to this will be passed
// through the callback's data parameter. It will be deleted
// when SignalProxy_Sort_gtk_callback_destroy() is called.
auto slot_copy = new SlotSort(slot);
gtk_flow_box_set_sort_func(gobj(),
&SignalProxy_Sort_gtk_callback, slot_copy,
&SignalProxy_Sort_gtk_callback_destroy);
}
void FlowBox::unset_sort_func()
{
gtk_flow_box_set_sort_func(gobj(), nullptr, nullptr, nullptr);
}
void FlowBox::bind_model(const Glib::RefPtr& model,
const SlotCreateWidget& slot_create_widget)
{
// Create a copy of the slot.
// It will be deleted by Glib::destroy_notify_delete.
auto slot_copy = new SlotCreateWidget(slot_create_widget);
gtk_flow_box_bind_model(gobj(), Glib::unwrap(model), &proxy_bind_model_create_widget_callback,
slot_copy, &Glib::destroy_notify_delete>);
}
} //namespace Gtk