1 #ifndef _GLIBMM_PROPERTYPROXY_BASE_H
2 #define _GLIBMM_PROPERTYPROXY_BASE_H
3 
4 /* propertyproxy_base.h
5  *
6  * Copyright 2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <glibmmconfig.h>
23 #include <glibmm/value.h>
24 #include <glibmm/signalproxy.h>
25 
26 namespace Glib
27 {
28 
29 class GLIBMM_API ObjectBase;
30 
31 /// Use the connect() method, with sigc::ptr_fun() or sigc::mem_fun() to connect signals to signal
32 /// handlers.
33 class GLIBMM_API SignalProxyProperty : public SignalProxyBase
34 {
35 public:
36   friend class PropertyProxy_Base;
37 
38   SignalProxyProperty(Glib::ObjectBase* obj, const gchar* property_name);
39   ~SignalProxyProperty() noexcept;
40 
41   using SlotType = sigc::slot<void>;
42   sigc::connection connect(const SlotType& slot);
43   /** @newin{2,48}
44    */
45   sigc::connection connect(SlotType&& slot);
46 
47 protected:
48   const char* property_name_; // Should be a static string literal.
49 
50 private:
51   SignalProxyProperty& operator=(const SignalProxyProperty&); // not implemented
52 };
53 
54 class GLIBMM_API PropertyProxy_Base
55 {
56 public:
57   PropertyProxy_Base(ObjectBase* obj, const char* property_name);
58   PropertyProxy_Base(const PropertyProxy_Base& other);
59 
60   /// This signal will be emitted when the property changes.
61   SignalProxyProperty signal_changed();
62 
get_object()63   ObjectBase* get_object() const { return obj_; }
get_name()64   const char* get_name() const { return property_name_; }
65 
66 protected:
67   void set_property_(const Glib::ValueBase& value);
68   void get_property_(Glib::ValueBase& value) const;
69   void reset_property_();
70 
71   ObjectBase* obj_; // The C++ wrapper instance of which this PropertyProxy is a member.
72 
73   const char* property_name_; // Should be a static string literal.
74 
75 private:
76   // Declared as private, but not implemented to prevent any automatically generated implementation.
77   PropertyProxy_Base& operator=(const PropertyProxy_Base&);
78 };
79 
80 #ifndef DOXYGEN_SHOULD_SKIP_THIS
81 
82 class GLIBMM_API SignalProxyProperty;
83 
84 /** PropertyProxyConnectionNode is a connection node for use with SignalProxyProperty.
85   * It's like SignalProxyConnectionNode, but it contains the property name too.
86   * This is not public API.
87   */
88 class GLIBMM_API PropertyProxyConnectionNode : public SignalProxyConnectionNode
89 {
90 public:
91   friend class SignalProxyProperty;
92 
93   PropertyProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject);
94   /** @newin{2,48}
95    */
96   PropertyProxyConnectionNode(sigc::slot_base&& slot, GObject* gobject);
97 
98   /** Connect callback() to the notify::property_name signal.
99    * It invokes the slot, supplied in the constructor.
100    *
101    * @newin{2,48}
102    */
103   sigc::connection connect_changed(const Glib::ustring& property_name);
104 
105   static void callback(GObject* object, GParamSpec* pspec, gpointer data);
106 };
107 
108 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
109 
110 } // namespace Glib
111 
112 #endif /* _GLIBMM_PROPERTYPROXY_BASE_H */
113