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