Debian Codegraph @

gtk/gtkmm/childpropertyproxy_base.cc

raw symbols SCIP
1 /* childpropertyproxy_base.cc
2 *
3 * Copyright (C) 2014 The gtkmm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include <gtkmm/childpropertyproxy_base.h>
20 #include <gtkmm/container.h>
21
22 #include <gtk/gtk.h>
23
24 namespace Gtk
25 {
26
27 sigc::connection SignalProxyChildProperty::connect(const SlotType& sl)
28 {
29 // Create a proxy to hold our connection info
30 // This will be deleted by destroy_notify_handler.
31 Glib::PropertyProxyConnectionNode* pConnectionNode = new Glib::PropertyProxyConnectionNode(sl, obj_->gobj());
32
33 // connect it to gtk+
34 // pConnectionNode will be passed as the data argument to the callback.
35 // The callback will then call the virtual Object::property_change_notify() method,
36 // which will contain a switch/case statement which will examine the property name.
37 const Glib::ustring notify_signal_name = "child-notify::" + Glib::ustring(property_name_);
38 pConnectionNode->connection_id_ = g_signal_connect_data(obj_->gobj(),
39 notify_signal_name.c_str(), (GCallback)(&Glib::PropertyProxyConnectionNode::callback), pConnectionNode,
40 &Glib::PropertyProxyConnectionNode::destroy_notify_handler,
41 G_CONNECT_AFTER);
42
43 return sigc::connection(pConnectionNode->slot_);
44 }
45
46 ChildPropertyProxy_Base::ChildPropertyProxy_Base(Gtk::Container* parent, Gtk::Widget& child, const char* property_name)
47 : parent_(parent),
48 child_(child),
49 property_name_(property_name) {}
50
51 ChildPropertyProxy_Base::ChildPropertyProxy_Base(const ChildPropertyProxy_Base& other)
52 : parent_(other.parent_),
53 child_(other.child_),
54 property_name_(other.property_name_) {}
55
56 SignalProxyChildProperty ChildPropertyProxy_Base::signal_changed()
57 {
58 return SignalProxyChildProperty(&child_, property_name_);
59 }
60
61 void ChildPropertyProxy_Base::set_property_(const Glib::ValueBase& value)
62 {
63 gtk_container_child_set_property(parent_->gobj(), child_.gobj(), property_name_, value.gobj());
64 }
65
66 void ChildPropertyProxy_Base::get_property_(Glib::ValueBase& value) const
67 {
68 gtk_container_child_get_property(parent_->gobj(), child_.gobj(), property_name_, value.gobj());
69 }
70
71 void ChildPropertyProxy_Base::reset_property_()
72 {
73 // Get information about the parameter:
74 const GParamSpec *const pParamSpec =
75 gtk_container_class_find_child_property(G_OBJECT_GET_CLASS(parent_->gobj()), property_name_);
76
77 g_return_if_fail(pParamSpec != nullptr);
78
79 Glib::ValueBase value;
80 value.init(G_PARAM_SPEC_VALUE_TYPE(pParamSpec));
81
82 // An explicit reset is not needed, because ValueBase:init()
83 // has already initialized it to the default value for this type.
84 // value.reset();
85
86 set_property_(value);
87 }
88
89 } // namespace Gtk