Debian Codegraph @

gtk/gtkmm/styleproperty.cc

raw symbols SCIP
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 <gtkmm/styleproperty.h>
18
19 #include <gtk/gtk.h>
20
21 namespace Gtk
22 {
23
24 /**** Gtk::StylePropertyBase ***************************************/
25
26 StylePropertyBase::StylePropertyBase(Gtk::Widget& widget, GType value_type)
27 :
28 widget_ (&widget),
29 value_type_ (value_type),
30 param_spec_ (nullptr)
31 {
32 }
33
34 StylePropertyBase::~StylePropertyBase() noexcept
35 {
36 if (param_spec_)
37 g_param_spec_unref(param_spec_);
38 }
39
40 bool StylePropertyBase::lookup_style_property(const Glib::ustring& name)
41 {
42 g_assert(param_spec_ == nullptr);
43
44 param_spec_ = gtk_widget_class_find_style_property(GTK_WIDGET_GET_CLASS(widget_->gobj()), name.c_str());
45
46 if (param_spec_)
47 {
48 g_assert(G_PARAM_SPEC_VALUE_TYPE(param_spec_) == value_type_);
49 g_param_spec_ref(param_spec_);
50 }
51
52 return param_spec_ != nullptr;
53 }
54
55 void StylePropertyBase::install_style_property(GParamSpec* param_spec)
56 {
57 g_return_if_fail(param_spec != nullptr);
58
59 gtk_widget_class_install_style_property(GTK_WIDGET_GET_CLASS(widget_->gobj()), param_spec);
60
61 param_spec_ = param_spec;
62 g_param_spec_ref(param_spec_);
63 }
64
65 const char* StylePropertyBase::get_name_internal() const
66 {
67 const char* const name = g_param_spec_get_name(param_spec_);
68 g_return_val_if_fail(name != nullptr, "");
69 return name;
70 }
71
72 Glib::ustring StylePropertyBase::get_name() const
73 {
74 return Glib::ustring(get_name_internal());
75 }
76
77 } // namespace Gtk