Debian Codegraph @

gtk/src/treeviewcolumn.ccg

raw
1 /* Copyright (C) 2002 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 <gtk/gtk.h>
18 #include <gtkmm/treeview_private.h>
19
20 namespace Gtk
21 {
22
23 // Only necessary because of the templated ctor, see .hg file.
24 const Glib::Class& TreeViewColumn::class_init_()
25 {
26 return treeviewcolumn_class_.init();
27 }
28
29 TreeViewColumn::TreeViewColumn(const Glib::ustring& title)
30 :
31 _CONSTRUCT("title", title.c_str())
32 {}
33
34 TreeViewColumn::TreeViewColumn(const Glib::ustring& title, Gtk::CellRenderer& cell)
35 :
36 _CONSTRUCT("title", title.c_str())
37 {
38 //This is equivalent to _gtk_tree_view_column_new_with_attributes().
39 //You will also need to call add_atrribute(), or set_renderer() a few times.
40
41 pack_start(cell, true);
42 }
43
44 void TreeViewColumn::add_attribute(Gtk::CellRenderer& cell, const Glib::ustring& property_name,
45 const TreeModelColumnBase& column)
46 {
47 gtk_tree_view_column_add_attribute(gobj(),
48 (GtkCellRenderer*) cell.gobj(), property_name.c_str(), column.index());
49 }
50
51 void TreeViewColumn::add_attribute(const Glib::PropertyProxy_Base& property,
52 const TreeModelColumnBase& column)
53 {
54 gtk_tree_view_column_add_attribute(gobj(),
55 (GtkCellRenderer*) property.get_object()->gobj(), property.get_name(), column.index());
56 }
57
58 void TreeViewColumn::set_renderer(Gtk::CellRenderer& renderer, const TreeModelColumnBase& column)
59 {
60 add_attribute(renderer._property_renderable(), column);
61 }
62
63
64 void TreeViewColumn::set_cell_data_func(CellRenderer& cell_renderer, const SlotTreeCellData& slot)
65 {
66 //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
67 //It will be deleted when TreeView_Private::SignalProxy_CellData_gtk_callback_destroy() is called.
68 auto slot_copy = new SlotTreeCellData(slot);
69
70 gtk_tree_view_column_set_cell_data_func(
71 gobj(), cell_renderer.gobj(),
72 &TreeView_Private::SignalProxy_CellData_gtk_callback, slot_copy,
73 &TreeView_Private::SignalProxy_CellData_gtk_callback_destroy);
74 }
75
76 void TreeViewColumn::unset_cell_data_func(CellRenderer& cell_renderer)
77 {
78 gtk_tree_view_column_set_cell_data_func(gobj(), cell_renderer.gobj(), nullptr, nullptr, nullptr);
79 }
80
81 } // namespace Gtk