| 1 |
/* Copyright (C) 2003 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 <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <glibmm/vectorutils.h> |
| 18 |
|
| 19 |
#include <gtkmm/cellarea.h> |
| 20 |
#include <gtk/gtk.h> |
| 21 |
|
| 22 |
|
| 23 |
static void SignalProxy_CellData_gtk_callback(GtkCellLayout* /* cell_layout */, GtkCellRenderer* /* cell */, GtkTreeModel* tree_model, GtkTreeIter* iter, gpointer data) |
| 24 |
{ |
| 25 |
auto the_slot = static_cast<Gtk::CellLayout::SlotCellData*>(data); |
| 26 |
|
| 27 |
try |
| 28 |
{ |
| 29 |
//We ignore the cell, because that was given as an argument to the connecting method, so the caller should know which one it is already. |
| 30 |
//And we ignore the tree_model because that can be obtained from the iter or from the CellLayout itself. |
| 31 |
(*the_slot)(Gtk::TreeModel::const_iterator(tree_model, iter)); |
| 32 |
} |
| 33 |
catch(...) |
| 34 |
{ |
| 35 |
Glib::exception_handlers_invoke(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
static void SignalProxy_CellData_gtk_callback_destroy(void* data) |
| 40 |
{ |
| 41 |
delete static_cast<Gtk::CellLayout::SlotCellData*>(data); |
| 42 |
} |
| 43 |
|
| 44 |
namespace Gtk |
| 45 |
{ |
| 46 |
|
| 47 |
void CellLayout::add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column) |
| 48 |
{ |
| 49 |
gtk_cell_layout_add_attribute(gobj(), |
| 50 |
(GtkCellRenderer*) property.get_object()->gobj(), property.get_name(), column.index()); |
| 51 |
} |
| 52 |
|
| 53 |
void CellLayout::add_attribute(CellRenderer& cell, const Glib::ustring& attribute, const TreeModelColumnBase& column) |
| 54 |
{ |
| 55 |
gtk_cell_layout_add_attribute(gobj(), |
| 56 |
(GtkCellRenderer*) cell.gobj(), attribute.c_str(), column.index()); |
| 57 |
} |
| 58 |
|
| 59 |
void CellLayout::set_cell_data_func(CellRenderer& cell, const SlotCellData& slot) |
| 60 |
{ |
| 61 |
// Create a copy of the slot object. A pointer to this will be passed |
| 62 |
// through the callback's data parameter. It will be deleted |
| 63 |
// when SignalProxy_CellData_gtk_callback_destroy() is called. |
| 64 |
auto slot_copy = new SlotCellData(slot); |
| 65 |
|
| 66 |
gtk_cell_layout_set_cell_data_func(gobj(), cell.gobj(), |
| 67 |
&SignalProxy_CellData_gtk_callback, slot_copy, |
| 68 |
&SignalProxy_CellData_gtk_callback_destroy); |
| 69 |
} |
| 70 |
|
| 71 |
CellRenderer* CellLayout::get_first_cell() |
| 72 |
{ |
| 73 |
auto vecCellRenderers = get_cells(); |
| 74 |
if(!vecCellRenderers.empty()) |
| 75 |
return vecCellRenderers[0]; |
| 76 |
else |
| 77 |
return nullptr; |
| 78 |
} |
| 79 |
|
| 80 |
const CellRenderer* CellLayout::get_first_cell() const |
| 81 |
{ |
| 82 |
//Do some const_cast-ing to avoid repetition of code: |
| 83 |
return const_cast<CellLayout*>(this)->get_first_cell(); |
| 84 |
} |
| 85 |
|
| 86 |
} //namespace Gtk |