1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.PropertyAction;
26 
27 private import gio.ActionIF;
28 private import gio.ActionT;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gtkc.gio;
33 public  import gtkc.giotypes;
34 
35 
36 /**
37  * A #GPropertyAction is a way to get a #GAction with a state value
38  * reflecting and controlling the value of a #GObject property.
39  * 
40  * The state of the action will correspond to the value of the property.
41  * Changing it will change the property (assuming the requested value
42  * matches the requirements as specified in the #GParamSpec).
43  * 
44  * Only the most common types are presently supported.  Booleans are
45  * mapped to booleans, strings to strings, signed/unsigned integers to
46  * int32/uint32 and floats and doubles to doubles.
47  * 
48  * If the property is an enum then the state will be string-typed and
49  * conversion will automatically be performed between the enum value and
50  * "nick" string as per the #GEnumValue table.
51  * 
52  * Flags types are not currently supported.
53  * 
54  * Properties of object types, boxed types and pointer types are not
55  * supported and probably never will be.
56  * 
57  * Properties of #GVariant types are not currently supported.
58  * 
59  * If the property is boolean-valued then the action will have a NULL
60  * parameter type, and activating the action (with no parameter) will
61  * toggle the value of the property.
62  * 
63  * In all other cases, the parameter type will correspond to the type of
64  * the property.
65  * 
66  * The general idea here is to reduce the number of locations where a
67  * particular piece of state is kept (and therefore has to be synchronised
68  * between). #GPropertyAction does not have a separate state that is kept
69  * in sync with the property value -- its state is the property value.
70  * 
71  * For example, it might be useful to create a #GAction corresponding to
72  * the "visible-child-name" property of a #GtkStack so that the current
73  * page can be switched from a menu.  The active radio indication in the
74  * menu is then directly determined from the active page of the
75  * #GtkStack.
76  * 
77  * An anti-example would be binding the "active-id" property on a
78  * #GtkComboBox.  This is because the state of the combobox itself is
79  * probably uninteresting and is actually being used to control
80  * something else.
81  * 
82  * Another anti-example would be to bind to the "visible-child-name"
83  * property of a #GtkStack if this value is actually stored in
84  * #GSettings.  In that case, the real source of the value is
85  * #GSettings.  If you want a #GAction to control a setting stored in
86  * #GSettings, see g_settings_create_action() instead, and possibly
87  * combine its use with g_settings_bind().
88  *
89  * Since: 2.38
90  */
91 public class PropertyAction : ObjectG, ActionIF
92 {
93 	/** the main Gtk struct */
94 	protected GPropertyAction* gPropertyAction;
95 
96 	/** Get the main Gtk struct */
97 	public GPropertyAction* getPropertyActionStruct(bool transferOwnership = false)
98 	{
99 		if (transferOwnership)
100 			ownedRef = false;
101 		return gPropertyAction;
102 	}
103 
104 	/** the main Gtk struct as a void* */
105 	protected override void* getStruct()
106 	{
107 		return cast(void*)gPropertyAction;
108 	}
109 
110 	protected override void setStruct(GObject* obj)
111 	{
112 		gPropertyAction = cast(GPropertyAction*)obj;
113 		super.setStruct(obj);
114 	}
115 
116 	/**
117 	 * Sets our main struct and passes it to the parent class.
118 	 */
119 	public this (GPropertyAction* gPropertyAction, bool ownedRef = false)
120 	{
121 		this.gPropertyAction = gPropertyAction;
122 		super(cast(GObject*)gPropertyAction, ownedRef);
123 	}
124 
125 	// add the Action capabilities
126 	mixin ActionT!(GPropertyAction);
127 
128 
129 	/** */
130 	public static GType getType()
131 	{
132 		return g_property_action_get_type();
133 	}
134 
135 	/**
136 	 * Creates a #GAction corresponding to the value of property
137 	 * @property_name on @object.
138 	 *
139 	 * The property must be existent and readable and writable (and not
140 	 * construct-only).
141 	 *
142 	 * This function takes a reference on @object and doesn't release it
143 	 * until the action is destroyed.
144 	 *
145 	 * Params:
146 	 *     name = the name of the action to create
147 	 *     object = the object that has the property
148 	 *         to wrap
149 	 *     propertyName = the name of the property
150 	 *
151 	 * Returns: a new #GPropertyAction
152 	 *
153 	 * Since: 2.38
154 	 *
155 	 * Throws: ConstructionException GTK+ fails to create the object.
156 	 */
157 	public this(string name, ObjectG object, string propertyName)
158 	{
159 		auto p = g_property_action_new(Str.toStringz(name), (object is null) ? null : object.getObjectGStruct(), Str.toStringz(propertyName));
160 		
161 		if(p is null)
162 		{
163 			throw new ConstructionException("null returned by new");
164 		}
165 		
166 		this(cast(GPropertyAction*) p, true);
167 	}
168 }