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 atk.ValueT;
26 
27 public  import atk.Range;
28 public  import glib.ListSG;
29 public  import glib.Str;
30 public  import gobject.ObjectG;
31 public  import gobject.Signals;
32 public  import gobject.Value;
33 public  import gtkc.atk;
34 public  import gtkc.atktypes;
35 public  import gtkc.gdktypes;
36 public  import std.algorithm;
37 
38 
39 /**
40  * #AtkValue should be implemented for components which either display
41  * a value from a bounded range, or which allow the user to specify a
42  * value from a bounded range, or both. For instance, most sliders and
43  * range controls, as well as dials, should have #AtkObject
44  * representations which implement #AtkValue on the component's
45  * behalf. #AtKValues may be read-only, in which case attempts to
46  * alter the value return would fail.
47  * 
48  * <refsect1 id="current-value-text">
49  * <title>On the subject of current value text</title>
50  * <para>
51  * In addition to providing the current value, implementors can
52  * optionally provide an end-user-consumable textual description
53  * associated with this value. This description should be included
54  * when the numeric value fails to convey the full, on-screen
55  * representation seen by users.
56  * </para>
57  * 
58  * <example>
59  * <title>Password strength</title>
60  * A password strength meter whose value changes as the user types
61  * their new password. Red is used for values less than 4.0, yellow
62  * for values between 4.0 and 7.0, and green for values greater than
63  * 7.0. In this instance, value text should be provided by the
64  * implementor. Appropriate value text would be "weak", "acceptable,"
65  * and "strong" respectively.
66  * </example>
67  * 
68  * A level bar whose value changes to reflect the battery charge. The
69  * color remains the same regardless of the charge and there is no
70  * on-screen text reflecting the fullness of the battery. In this
71  * case, because the position within the bar is the only indication
72  * the user has of the current charge, value text should not be
73  * provided by the implementor.
74  * 
75  * <refsect2 id="implementor-notes">
76  * <title>Implementor Notes</title>
77  * <para>
78  * Implementors should bear in mind that assistive technologies will
79  * likely prefer the value text provided over the numeric value when
80  * presenting a widget's value. As a result, strings not intended for
81  * end users should not be exposed in the value text, and strings
82  * which are exposed should be localized. In the case of widgets which
83  * display value text on screen, for instance through a separate label
84  * in close proximity to the value-displaying widget, it is still
85  * expected that implementors will expose the value text using the
86  * above API.
87  * </para>
88  * 
89  * <para>
90  * #AtkValue should NOT be implemented for widgets whose displayed
91  * value is not reflective of a meaningful amount. For instance, a
92  * progress pulse indicator whose value alternates between 0.0 and 1.0
93  * to indicate that some process is still taking place should not
94  * implement #AtkValue because the current value does not reflect
95  * progress towards completion.
96  * </para>
97  * </refsect2>
98  * </refsect1>
99  * 
100  * <refsect1 id="ranges">
101  * <title>On the subject of ranges</title>
102  * <para>
103  * In addition to providing the minimum and maximum values,
104  * implementors can optionally provide details about subranges
105  * associated with the widget. These details should be provided by the
106  * implementor when both of the following are communicated visually to
107  * the end user:
108  * </para>
109  * <itemizedlist>
110  * <listitem>The existence of distinct ranges such as "weak",
111  * "acceptable", and "strong" indicated by color, bar tick marks,
112  * and/or on-screen text.</listitem>
113  * <listitem>Where the current value stands within a given subrange,
114  * for instance illustrating progression from very "weak" towards
115  * nearly "acceptable" through changes in shade and/or position on
116  * the bar within the "weak" subrange.</listitem>
117  * </itemizedlist>
118  * <para>
119  * If both of the above do not apply to the widget, it should be
120  * sufficient to expose the numeric value, along with the value text
121  * if appropriate, to make the widget accessible.
122  * </para>
123  * 
124  * <refsect2 id="ranges-implementor-notes">
125  * <title>Implementor Notes</title>
126  * <para>
127  * If providing subrange details is deemed necessary, all possible
128  * values of the widget are expected to fall within one of the
129  * subranges defined by the implementor.
130  * </para>
131  * </refsect2>
132  * </refsect1>
133  * 
134  * <refsect1 id="localization">
135  * <title>On the subject of localization of end-user-consumable text
136  * values</title>
137  * <para>
138  * Because value text and subrange descriptors are human-consumable,
139  * implementors are expected to provide localized strings which can be
140  * directly presented to end users via their assistive technology. In
141  * order to simplify this for implementors, implementors can use
142  * atk_value_type_get_localized_name() with the following
143  * already-localized constants for commonly-needed values can be used:
144  * </para>
145  * 
146  * <itemizedlist>
147  * <listitem>ATK_VALUE_VERY_WEAK</listitem>
148  * <listitem>ATK_VALUE_WEAK</listitem>
149  * <listitem>ATK_VALUE_ACCEPTABLE</listitem>
150  * <listitem>ATK_VALUE_STRONG</listitem>
151  * <listitem>ATK_VALUE_VERY_STRONG</listitem>
152  * <listitem>ATK_VALUE_VERY_LOW</listitem>
153  * <listitem>ATK_VALUE_LOW</listitem>
154  * <listitem>ATK_VALUE_MEDIUM</listitem>
155  * <listitem>ATK_VALUE_HIGH</listitem>
156  * <listitem>ATK_VALUE_VERY_HIGH</listitem>
157  * <listitem>ATK_VALUE_VERY_BAD</listitem>
158  * <listitem>ATK_VALUE_BAD</listitem>
159  * <listitem>ATK_VALUE_GOOD</listitem>
160  * <listitem>ATK_VALUE_VERY_GOOD</listitem>
161  * <listitem>ATK_VALUE_BEST</listitem>
162  * <listitem>ATK_VALUE_SUBSUBOPTIMAL</listitem>
163  * <listitem>ATK_VALUE_SUBOPTIMAL</listitem>
164  * <listitem>ATK_VALUE_OPTIMAL</listitem>
165  * </itemizedlist>
166  * <para>
167  * Proposals for additional constants, along with their use cases,
168  * should be submitted to the GNOME Accessibility Team.
169  * </para>
170  * </refsect1>
171  * 
172  * <refsect1 id="changes">
173  * <title>On the subject of changes</title>
174  * <para>
175  * Note that if there is a textual description associated with the new
176  * numeric value, that description should be included regardless of
177  * whether or not it has also changed.
178  * </para>
179  * </refsect1>
180  */
181 public template ValueT(TStruct)
182 {
183 	/** Get the main Gtk struct */
184 	public AtkValue* getValueStruct()
185 	{
186 		return cast(AtkValue*)getStruct();
187 	}
188 
189 
190 	/**
191 	 * Gets the value of this object.
192 	 *
193 	 * Deprecated: Since 2.12. Use atk_value_get_value_and_text()
194 	 * instead.
195 	 *
196 	 * Params:
197 	 *     value = a #GValue representing the current accessible value
198 	 */
199 	public void getCurrentValue(out Value value)
200 	{
201 		GValue* outvalue = gMalloc!GValue();
202 		
203 		atk_value_get_current_value(getValueStruct(), outvalue);
204 		
205 		value = ObjectG.getDObject!(Value)(outvalue, true);
206 	}
207 
208 	/**
209 	 * Gets the minimum increment by which the value of this object may be
210 	 * changed.  If zero, the minimum increment is undefined, which may
211 	 * mean that it is limited only by the floating point precision of the
212 	 * platform.
213 	 *
214 	 * Return: the minimum increment by which the value of this
215 	 *     object may be changed. zero if undefined.
216 	 *
217 	 * Since: 2.12
218 	 */
219 	public double getIncrement()
220 	{
221 		return atk_value_get_increment(getValueStruct());
222 	}
223 
224 	/**
225 	 * Gets the maximum value of this object.
226 	 *
227 	 * Deprecated: Since 2.12. Use atk_value_get_range() instead.
228 	 *
229 	 * Params:
230 	 *     value = a #GValue representing the maximum accessible value
231 	 */
232 	public void getMaximumValue(out Value value)
233 	{
234 		GValue* outvalue = gMalloc!GValue();
235 		
236 		atk_value_get_maximum_value(getValueStruct(), outvalue);
237 		
238 		value = ObjectG.getDObject!(Value)(outvalue, true);
239 	}
240 
241 	/**
242 	 * Gets the minimum increment by which the value of this object may be changed.  If zero,
243 	 * the minimum increment is undefined, which may mean that it is limited only by the
244 	 * floating point precision of the platform.
245 	 *
246 	 * Deprecated: Since 2.12. Use atk_value_get_increment() instead.
247 	 *
248 	 * Params:
249 	 *     value = a #GValue representing the minimum increment by which the accessible value may be changed
250 	 *
251 	 * Since: 1.12
252 	 */
253 	public void getMinimumIncrement(out Value value)
254 	{
255 		GValue* outvalue = gMalloc!GValue();
256 		
257 		atk_value_get_minimum_increment(getValueStruct(), outvalue);
258 		
259 		value = ObjectG.getDObject!(Value)(outvalue, true);
260 	}
261 
262 	/**
263 	 * Gets the minimum value of this object.
264 	 *
265 	 * Deprecated: Since 2.12. Use atk_value_get_range() instead.
266 	 *
267 	 * Params:
268 	 *     value = a #GValue representing the minimum accessible value
269 	 */
270 	public void getMinimumValue(out Value value)
271 	{
272 		GValue* outvalue = gMalloc!GValue();
273 		
274 		atk_value_get_minimum_value(getValueStruct(), outvalue);
275 		
276 		value = ObjectG.getDObject!(Value)(outvalue, true);
277 	}
278 
279 	/**
280 	 * Gets the range of this object.
281 	 *
282 	 * Return: a newly allocated #AtkRange
283 	 *     that represents the minimum, maximum and descriptor (if available)
284 	 *     of @obj. NULL if that range is not defined.
285 	 *
286 	 * Since: 2.12
287 	 */
288 	public Range getRange()
289 	{
290 		auto p = atk_value_get_range(getValueStruct());
291 		
292 		if(p is null)
293 		{
294 			return null;
295 		}
296 		
297 		return ObjectG.getDObject!(Range)(cast(AtkRange*) p, true);
298 	}
299 
300 	/**
301 	 * Gets the list of subranges defined for this object. See #AtkValue
302 	 * introduction for examples of subranges and when to expose them.
303 	 *
304 	 * Return: an #GSList of
305 	 *     #AtkRange which each of the subranges defined for this object. Free
306 	 *     the returns list with g_slist_free().
307 	 *
308 	 * Since: 2.12
309 	 */
310 	public ListSG getSubRanges()
311 	{
312 		auto p = atk_value_get_sub_ranges(getValueStruct());
313 		
314 		if(p is null)
315 		{
316 			return null;
317 		}
318 		
319 		return new ListSG(cast(GSList*) p, true);
320 	}
321 
322 	/**
323 	 * Gets the current value and the human readable text alternative of
324 	 * @obj. @text is a newly created string, that must be freed by the
325 	 * caller. Can be NULL if no descriptor is available.
326 	 *
327 	 * Params:
328 	 *     value = address of #gdouble to put the current value of @obj
329 	 *     text = address of #gchar to put the human
330 	 *         readable text alternative for @value
331 	 *
332 	 * Since: 2.12
333 	 */
334 	public void getValueAndText(out double value, out string text)
335 	{
336 		char* outtext = null;
337 		
338 		atk_value_get_value_and_text(getValueStruct(), &value, &outtext);
339 		
340 		text = Str.toString(outtext);
341 	}
342 
343 	/**
344 	 * Sets the value of this object.
345 	 *
346 	 * Deprecated: Since 2.12. Use atk_value_set_value() instead.
347 	 *
348 	 * Params:
349 	 *     value = a #GValue which is the desired new accessible value.
350 	 *
351 	 * Return: %TRUE if new value is successfully set, %FALSE otherwise.
352 	 */
353 	public bool setCurrentValue(Value value)
354 	{
355 		return atk_value_set_current_value(getValueStruct(), (value is null) ? null : value.getValueStruct()) != 0;
356 	}
357 
358 	/**
359 	 * Sets the value of this object.
360 	 *
361 	 * This method is intended to provide a way to change the value of the
362 	 * object. In any case, it is possible that the value can't be
363 	 * modified (ie: a read-only component). If the value changes due this
364 	 * call, it is possible that the text could change, and will trigger
365 	 * an #AtkValue::value-changed signal emission.
366 	 *
367 	 * Note for implementors: the deprecated atk_value_set_current_value()
368 	 * method returned TRUE or FALSE depending if the value was assigned
369 	 * or not. In the practice several implementors were not able to
370 	 * decide it, and returned TRUE in any case. For that reason it is not
371 	 * required anymore to return if the value was properly assigned or
372 	 * not.
373 	 *
374 	 * Params:
375 	 *     newValue = a double which is the desired new accessible value.
376 	 *
377 	 * Since: 2.12
378 	 */
379 	public void setValue(double newValue)
380 	{
381 		atk_value_set_value(getValueStruct(), newValue);
382 	}
383 
384 	protected class OnValueChangedDelegateWrapper
385 	{
386 		void delegate(double, string, ValueIF) dlg;
387 		gulong handlerId;
388 		ConnectFlags flags;
389 		this(void delegate(double, string, ValueIF) dlg, gulong handlerId, ConnectFlags flags)
390 		{
391 			this.dlg = dlg;
392 			this.handlerId = handlerId;
393 			this.flags = flags;
394 		}
395 	}
396 	protected OnValueChangedDelegateWrapper[] onValueChangedListeners;
397 
398 	/**
399 	 * The 'value-changed' signal is emitted when the current value
400 	 * that represent the object changes. @value is the numerical
401 	 * representation of this new value.  @text is the human
402 	 * readable text alternative of @value, and can be NULL if it is
403 	 * not available. Note that if there is a textual description
404 	 * associated with the new numeric value, that description
405 	 * should be included regardless of whether or not it has also
406 	 * changed.
407 	 *
408 	 * Example: a password meter whose value changes as the user
409 	 * types their new password. Appropiate value text would be
410 	 * "weak", "acceptable" and "strong".
411 	 *
412 	 * Params:
413 	 *     value = the new value in a numerical form.
414 	 *     text = human readable text alternative (also called
415 	 *         description) of this object. NULL if not available.
416 	 *
417 	 * Since: 2.12
418 	 */
419 	gulong addOnValueChanged(void delegate(double, string, ValueIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
420 	{
421 		onValueChangedListeners ~= new OnValueChangedDelegateWrapper(dlg, 0, connectFlags);
422 		onValueChangedListeners[onValueChangedListeners.length - 1].handlerId = Signals.connectData(
423 			this,
424 			"value-changed",
425 			cast(GCallback)&callBackValueChanged,
426 			cast(void*)onValueChangedListeners[onValueChangedListeners.length - 1],
427 			cast(GClosureNotify)&callBackValueChangedDestroy,
428 			connectFlags);
429 		return onValueChangedListeners[onValueChangedListeners.length - 1].handlerId;
430 	}
431 	
432 	extern(C) static void callBackValueChanged(AtkValue* valueStruct, double value, char* text,OnValueChangedDelegateWrapper wrapper)
433 	{
434 		wrapper.dlg(value, Str.toString(text), wrapper.outer);
435 	}
436 	
437 	extern(C) static void callBackValueChangedDestroy(OnValueChangedDelegateWrapper wrapper, GClosure* closure)
438 	{
439 		wrapper.outer.internalRemoveOnValueChanged(wrapper);
440 	}
441 
442 	protected void internalRemoveOnValueChanged(OnValueChangedDelegateWrapper source)
443 	{
444 		foreach(index, wrapper; onValueChangedListeners)
445 		{
446 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
447 			{
448 				onValueChangedListeners[index] = null;
449 				onValueChangedListeners = std.algorithm.remove(onValueChangedListeners, index);
450 				break;
451 			}
452 		}
453 	}
454 	
455 }