[glibmm] Add Gio::PropertyAction
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Add Gio::PropertyAction
- Date: Sun, 26 Feb 2017 13:49:25 +0000 (UTC)
commit 104d5480f41e12d496dee7364ad3946dd61643b3
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Sun Feb 26 14:47:07 2017 +0100
Add Gio::PropertyAction
* gio/giomm.h: Add propertyaction.h
* gio/src/filelist.am: Add propertyaction.hg
* gio/src/propertyaction.[ccg|hg]: New files.
Required in the "Building Applications" chapter in the gtkmm tutorial.
gio/giomm.h | 1 +
gio/src/filelist.am | 1 +
gio/src/propertyaction.ccg | 31 +++++++++++
gio/src/propertyaction.hg | 121 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 154 insertions(+), 0 deletions(-)
---
diff --git a/gio/giomm.h b/gio/giomm.h
index a7c0a91..8d5376b 100644
--- a/gio/giomm.h
+++ b/gio/giomm.h
@@ -108,6 +108,7 @@
#include <giomm/permission.h>
#include <giomm/pollableinputstream.h>
#include <giomm/pollableoutputstream.h>
+#include <giomm/propertyaction.h>
#include <giomm/proxy.h>
#include <giomm/proxyaddress.h>
#include <giomm/proxyresolver.h>
diff --git a/gio/src/filelist.am b/gio/src/filelist.am
index 0095128..ca5a3ac 100644
--- a/gio/src/filelist.am
+++ b/gio/src/filelist.am
@@ -94,6 +94,7 @@ giomm_files_any_hg = \
permission.hg \
pollableinputstream.hg \
pollableoutputstream.hg \
+ propertyaction.hg \
proxy.hg \
proxyaddress.hg \
proxyresolver.hg \
diff --git a/gio/src/propertyaction.ccg b/gio/src/propertyaction.ccg
new file mode 100644
index 0000000..85da4a8
--- /dev/null
+++ b/gio/src/propertyaction.ccg
@@ -0,0 +1,31 @@
+/* Copyright (C) 2017 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+
+PropertyAction::PropertyAction(const Glib::ustring& name,
+ const Glib::PropertyProxy_Base& property_proxy, bool invert_boolean)
+:
+_CONSTRUCT("name", name.c_str(), "object", property_proxy.get_object()->gobj(),
+ "property-name", property_proxy.get_name(),
+ "invert-boolean", invert_boolean)
+{
+}
+
+} // namespace Gio
diff --git a/gio/src/propertyaction.hg b/gio/src/propertyaction.hg
new file mode 100644
index 0000000..5037146
--- /dev/null
+++ b/gio/src/propertyaction.hg
@@ -0,0 +1,121 @@
+/* Copyright (C) 2017 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glibmm/object.h>
+#include <glibmm/refptr.h>
+#include <giomm/action.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gio
+{
+/** An Action reflecting a Glib::Object property.
+ *
+ * A %PropertyAction is a way to get an Action with a state value
+ * reflecting and controlling the value of a Glib::Object property.
+ *
+ * The state of the action will correspond to the value of the property.
+ * Changing it will change the property (assuming the requested value
+ * matches the requirements as specified in the GParamSpec, used when the
+ * property was installed).
+ *
+ * Only the most common types are presently supported. Booleans are
+ * mapped to booleans, strings to strings, signed/unsigned integers to
+ * int32/uint32 and floats and doubles to doubles.
+ *
+ * If the property is an enum then the state will be string-typed and
+ * conversion will automatically be performed between the enum value and
+ * "nick" string as per the GEnumValue table.
+ *
+ * Flags types are not currently supported.
+ *
+ * Properties of object types, boxed types and pointer types are not
+ * supported and probably never will be.
+ *
+ * Properties of Glib::Variant types are not currently supported.
+ *
+ * If the property is boolean-valued then the action will have a nullptr
+ * parameter type, and activating the action (with no parameter) will
+ * toggle the value of the property.
+ *
+ * In all other cases, the parameter type will correspond to the type of
+ * the property.
+ *
+ * The general idea here is to reduce the number of locations where a
+ * particular piece of state is kept (and therefore has to be synchronised
+ * between). %PropertyAction does not have a separate state that is kept
+ * in sync with the property value -- its state is the property value.
+ *
+ * For example, it might be useful to create an Action corresponding to
+ * property_visible_child_name() of a Gtk::Stack so that the current
+ * page can be switched from a menu. The active radio indication in the
+ * menu is then directly determined from the active page of the Gtk::Stack.
+ *
+ * An anti-example would be binding property_active_id() on a Gtk::ComboBox.
+ * This is because the state of the combobox itself is probably uninteresting
+ * and is actually being used to control something else.
+ *
+ * Another anti-example would be to bind to property_visible_child_name()
+ * of a Gtk::Stack if this value is actually stored in Gio::Settings.
+ * In that case, the real source of the value is
+ * Gio::Settings. If you want an Action to control a setting stored in
+ * Gio::Settings, see Gio::Settings::create_action() instead, and possibly
+ * combine its use with Gio::Settings::bind().
+ *
+ * @newin{2,52}
+ */
+class PropertyAction : public Glib::Object, public Action
+{
+ _CLASS_GOBJECT(PropertyAction, GPropertyAction, G_PROPERTY_ACTION, Glib::Object, GObject)
+ _IMPLEMENTS_INTERFACE(Action)
+
+protected:
+ PropertyAction(const Glib::ustring& name, const Glib::PropertyProxy_Base& property_proxy,
+ bool invert_boolean = false);
+
+public:
+ /** Creates an Action corresponding to the value of property @a property_proxy.
+ *
+ * The property must be existent and readable and writable (and not construct-only).
+ *
+ * This function takes a reference on the property's object and doesn't
+ * release it until the action is destroyed.
+ *
+ * @param name The name of the action to create.
+ * @param property_proxy The property to bind.
+ * @param invert_boolean If <tt>true</tt>, the state of the action will be
+ * the negation of the property value, provided the property is boolean.
+ * @return A new %PropertyAction.
+ *
+ * @newin{2,52}
+ */
+ _WRAP_CREATE(const Glib::ustring& name, const Glib::PropertyProxy_Base& property_proxy,
+ bool invert_boolean = false)
+
+ _WRAP_PROPERTY("name", Glib::ustring, newin "2,52")
+ _WRAP_PROPERTY("parameter-type", Glib::VariantType, newin "2,52")
+ _WRAP_PROPERTY("enabled", bool, newin "2,52")
+ _WRAP_PROPERTY("state-type", Glib::VariantType, newin "2,52")
+ _WRAP_PROPERTY("state", Glib::VariantBase, newin "2,52")
+ //_WRAP_PROPERTY("object", Glib::ObjectBase) // write-only, construct-only
+ //_WRAP_PROPERTY("property-name", Glib::ustring) // write-only, construct-only
+ _WRAP_PROPERTY("invert-boolean", bool, newin "2,52")
+
+ // There are no methods (apart from ctor and create), signals or vfuncs.
+};
+
+} // namespace Gio
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]