| 1 |
/* Copyright (C) 2014 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <gtk/gtk.h> |
| 18 |
#include <gtkmm/adjustment.h> |
| 19 |
|
| 20 |
namespace |
| 21 |
{ |
| 22 |
|
| 23 |
static void FuncProxy_Foreach_gtk_callback(GtkFlowBox* box, GtkFlowBoxChild* child, void* data) |
| 24 |
{ |
| 25 |
auto the_slot = static_cast<Gtk::FlowBox::SlotSelectedForeach*>(data); |
| 26 |
|
| 27 |
try |
| 28 |
{ |
| 29 |
(*the_slot)(Glib::wrap(box), Glib::wrap(child)); |
| 30 |
} |
| 31 |
catch(...) |
| 32 |
{ |
| 33 |
Glib::exception_handlers_invoke(); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
static gboolean SignalProxy_Filter_gtk_callback(GtkFlowBoxChild* child, void* data) |
| 38 |
{ |
| 39 |
auto the_slot = static_cast<Gtk::FlowBox::SlotFilter*>(data); |
| 40 |
|
| 41 |
try |
| 42 |
{ |
| 43 |
return (*the_slot)(Glib::wrap(child)); |
| 44 |
} |
| 45 |
catch(...) |
| 46 |
{ |
| 47 |
Glib::exception_handlers_invoke(); |
| 48 |
return FALSE; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
static void SignalProxy_Filter_gtk_callback_destroy(void* data) |
| 53 |
{ |
| 54 |
delete static_cast<Gtk::FlowBox::SlotFilter*>(data); |
| 55 |
} |
| 56 |
|
| 57 |
static gint SignalProxy_Sort_gtk_callback(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, void* data) |
| 58 |
{ |
| 59 |
auto the_slot = static_cast<Gtk::FlowBox::SlotSort*>(data); |
| 60 |
|
| 61 |
try |
| 62 |
{ |
| 63 |
return (*the_slot)(Glib::wrap(child1), Glib::wrap(child2)); |
| 64 |
} |
| 65 |
catch(...) |
| 66 |
{ |
| 67 |
Glib::exception_handlers_invoke(); |
| 68 |
return 0; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static void SignalProxy_Sort_gtk_callback_destroy(void* data) |
| 73 |
{ |
| 74 |
delete static_cast<Gtk::FlowBox::SlotSort*>(data); |
| 75 |
} |
| 76 |
|
| 77 |
static GtkWidget* proxy_bind_model_create_widget_callback(void* item, void* data) |
| 78 |
{ |
| 79 |
auto& slot = *static_cast<Gtk::FlowBox::SlotCreateWidget<Glib::Object>*>(data); |
| 80 |
auto cobject = static_cast<GObject*>(item); |
| 81 |
|
| 82 |
try |
| 83 |
{ |
| 84 |
// take_copy is true here, because wrap() returns a Glib::RefPtr<Glib::Object>. |
| 85 |
// cobject will be unreferenced when the RefPtr is deleted. |
| 86 |
Gtk::Widget* widget = slot(Glib::wrap(cobject, true)); |
| 87 |
if (widget) |
| 88 |
return widget->gobj(); |
| 89 |
} |
| 90 |
catch(...) |
| 91 |
{ |
| 92 |
Glib::exception_handlers_invoke(); |
| 93 |
} |
| 94 |
return nullptr; |
| 95 |
} |
| 96 |
|
| 97 |
} // anonymous namespace |
| 98 |
|
| 99 |
namespace Gtk |
| 100 |
{ |
| 101 |
|
| 102 |
void FlowBox::selected_foreach(const SlotSelectedForeach& slot) |
| 103 |
{ |
| 104 |
SlotSelectedForeach slot_local_copy(slot); |
| 105 |
|
| 106 |
gtk_flow_box_selected_foreach(gobj(), |
| 107 |
&FuncProxy_Foreach_gtk_callback, &slot_local_copy); |
| 108 |
} |
| 109 |
|
| 110 |
void FlowBox::set_filter_func(const SlotFilter& slot) |
| 111 |
{ |
| 112 |
// Create a copy of the slot object. A pointer to this will be passed |
| 113 |
// through the callback's data parameter. It will be deleted |
| 114 |
// when SignalProxy_Filter_gtk_callback_destroy() is called. |
| 115 |
auto slot_copy = new SlotFilter(slot); |
| 116 |
|
| 117 |
gtk_flow_box_set_filter_func(gobj(), |
| 118 |
&SignalProxy_Filter_gtk_callback, slot_copy, |
| 119 |
&SignalProxy_Filter_gtk_callback_destroy); |
| 120 |
} |
| 121 |
|
| 122 |
void FlowBox::unset_filter_func() |
| 123 |
{ |
| 124 |
gtk_flow_box_set_filter_func(gobj(), nullptr, nullptr, nullptr); |
| 125 |
} |
| 126 |
|
| 127 |
void FlowBox::set_sort_func(const SlotSort& slot) |
| 128 |
{ |
| 129 |
// Create a copy of the slot object. A pointer to this will be passed |
| 130 |
// through the callback's data parameter. It will be deleted |
| 131 |
// when SignalProxy_Sort_gtk_callback_destroy() is called. |
| 132 |
auto slot_copy = new SlotSort(slot); |
| 133 |
|
| 134 |
gtk_flow_box_set_sort_func(gobj(), |
| 135 |
&SignalProxy_Sort_gtk_callback, slot_copy, |
| 136 |
&SignalProxy_Sort_gtk_callback_destroy); |
| 137 |
} |
| 138 |
|
| 139 |
void FlowBox::unset_sort_func() |
| 140 |
{ |
| 141 |
gtk_flow_box_set_sort_func(gobj(), nullptr, nullptr, nullptr); |
| 142 |
} |
| 143 |
|
| 144 |
void FlowBox::bind_model(const Glib::RefPtr<Gio::ListModel>& model, |
| 145 |
const SlotCreateWidget<Glib::Object>& slot_create_widget) |
| 146 |
{ |
| 147 |
// Create a copy of the slot. |
| 148 |
// It will be deleted by Glib::destroy_notify_delete<SlotCreateWidget>. |
| 149 |
auto slot_copy = new SlotCreateWidget<Glib::Object>(slot_create_widget); |
| 150 |
|
| 151 |
gtk_flow_box_bind_model(gobj(), Glib::unwrap(model), &proxy_bind_model_create_widget_callback, |
| 152 |
slot_copy, &Glib::destroy_notify_delete<SlotCreateWidget<Glib::Object>>); |
| 153 |
} |
| 154 |
|
| 155 |
} //namespace Gtk |
| 156 |
|