summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2017-02-26 14:47:07 +0100
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2017-02-26 14:47:07 +0100
commit104d5480f41e12d496dee7364ad3946dd61643b3 (patch)
treed082349978a63ad3fc50c39b48563d6219981e62
parentae9955dd4d2dee0e3abc42c98cb138a15d2cbf34 (diff)
downloadglibmm-104d5480f41e12d496dee7364ad3946dd61643b3.tar.gz
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.
-rw-r--r--gio/giomm.h1
-rw-r--r--gio/src/filelist.am1
-rw-r--r--gio/src/propertyaction.ccg31
-rw-r--r--gio/src/propertyaction.hg121
4 files changed, 154 insertions, 0 deletions
diff --git a/gio/giomm.h b/gio/giomm.h
index a7c0a916..8d5376bf 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 0095128e..ca5a3acf 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 00000000..85da4a88
--- /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 00000000..5037146c
--- /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