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 gtk.Adjustment;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtkc.gtk;
31 public  import gtkc.gtktypes;
32 private import std.algorithm;
33 
34 
35 /**
36  * The #GtkAdjustment object represents a value which has an associated lower
37  * and upper bound, together with step and page increments, and a page size.
38  * It is used within several GTK+ widgets, including #GtkSpinButton, #GtkViewport,
39  * and #GtkRange (which is a base class for #GtkScrollbar and #GtkScale).
40  * 
41  * The #GtkAdjustment object does not update the value itself. Instead
42  * it is left up to the owner of the #GtkAdjustment to control the value.
43  */
44 public class Adjustment : ObjectG
45 {
46 	/** the main Gtk struct */
47 	protected GtkAdjustment* gtkAdjustment;
48 
49 	/** Get the main Gtk struct */
50 	public GtkAdjustment* getAdjustmentStruct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return gtkAdjustment;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected override void* getStruct()
59 	{
60 		return cast(void*)gtkAdjustment;
61 	}
62 
63 	protected override void setStruct(GObject* obj)
64 	{
65 		gtkAdjustment = cast(GtkAdjustment*)obj;
66 		super.setStruct(obj);
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GtkAdjustment* gtkAdjustment, bool ownedRef = false)
73 	{
74 		this.gtkAdjustment = gtkAdjustment;
75 		super(cast(GObject*)gtkAdjustment, ownedRef);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return gtk_adjustment_get_type();
83 	}
84 
85 	/**
86 	 * Creates a new #GtkAdjustment.
87 	 *
88 	 * Params:
89 	 *     value = the initial value
90 	 *     lower = the minimum value
91 	 *     upper = the maximum value
92 	 *     stepIncrement = the step increment
93 	 *     pageIncrement = the page increment
94 	 *     pageSize = the page size
95 	 *
96 	 * Returns: a new #GtkAdjustment
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this(double value, double lower, double upper, double stepIncrement, double pageIncrement, double pageSize)
101 	{
102 		auto p = gtk_adjustment_new(value, lower, upper, stepIncrement, pageIncrement, pageSize);
103 		
104 		if(p is null)
105 		{
106 			throw new ConstructionException("null returned by new");
107 		}
108 		
109 		this(cast(GtkAdjustment*) p);
110 	}
111 
112 	/**
113 	 * Emits a #GtkAdjustment::changed signal from the #GtkAdjustment.
114 	 * This is typically called by the owner of the #GtkAdjustment after it has
115 	 * changed any of the #GtkAdjustment properties other than the value.
116 	 *
117 	 * Deprecated: GTK+ emits #GtkAdjustment::changed itself whenever any
118 	 * of the properties (other than value) change
119 	 */
120 	public void changed()
121 	{
122 		gtk_adjustment_changed(gtkAdjustment);
123 	}
124 
125 	/**
126 	 * Updates the #GtkAdjustment:value property to ensure that the range
127 	 * between @lower and @upper is in the current page (i.e. between
128 	 * #GtkAdjustment:value and #GtkAdjustment:value + #GtkAdjustment:page-size).
129 	 * If the range is larger than the page size, then only the start of it will
130 	 * be in the current page.
131 	 *
132 	 * A #GtkAdjustment::value-changed signal will be emitted if the value is changed.
133 	 *
134 	 * Params:
135 	 *     lower = the lower value
136 	 *     upper = the upper value
137 	 */
138 	public void clampPage(double lower, double upper)
139 	{
140 		gtk_adjustment_clamp_page(gtkAdjustment, lower, upper);
141 	}
142 
143 	/**
144 	 * Sets all properties of the adjustment at once.
145 	 *
146 	 * Use this function to avoid multiple emissions of the
147 	 * #GtkAdjustment::changed signal. See gtk_adjustment_set_lower()
148 	 * for an alternative way of compressing multiple emissions of
149 	 * #GtkAdjustment::changed into one.
150 	 *
151 	 * Params:
152 	 *     value = the new value
153 	 *     lower = the new minimum value
154 	 *     upper = the new maximum value
155 	 *     stepIncrement = the new step increment
156 	 *     pageIncrement = the new page increment
157 	 *     pageSize = the new page size
158 	 *
159 	 * Since: 2.14
160 	 */
161 	public void configure(double value, double lower, double upper, double stepIncrement, double pageIncrement, double pageSize)
162 	{
163 		gtk_adjustment_configure(gtkAdjustment, value, lower, upper, stepIncrement, pageIncrement, pageSize);
164 	}
165 
166 	/**
167 	 * Retrieves the minimum value of the adjustment.
168 	 *
169 	 * Returns: The current minimum value of the adjustment
170 	 *
171 	 * Since: 2.14
172 	 */
173 	public double getLower()
174 	{
175 		return gtk_adjustment_get_lower(gtkAdjustment);
176 	}
177 
178 	/**
179 	 * Gets the smaller of step increment and page increment.
180 	 *
181 	 * Returns: the minimum increment of @adjustment
182 	 *
183 	 * Since: 3.2
184 	 */
185 	public double getMinimumIncrement()
186 	{
187 		return gtk_adjustment_get_minimum_increment(gtkAdjustment);
188 	}
189 
190 	/**
191 	 * Retrieves the page increment of the adjustment.
192 	 *
193 	 * Returns: The current page increment of the adjustment
194 	 *
195 	 * Since: 2.14
196 	 */
197 	public double getPageIncrement()
198 	{
199 		return gtk_adjustment_get_page_increment(gtkAdjustment);
200 	}
201 
202 	/**
203 	 * Retrieves the page size of the adjustment.
204 	 *
205 	 * Returns: The current page size of the adjustment
206 	 *
207 	 * Since: 2.14
208 	 */
209 	public double getPageSize()
210 	{
211 		return gtk_adjustment_get_page_size(gtkAdjustment);
212 	}
213 
214 	/**
215 	 * Retrieves the step increment of the adjustment.
216 	 *
217 	 * Returns: The current step increment of the adjustment.
218 	 *
219 	 * Since: 2.14
220 	 */
221 	public double getStepIncrement()
222 	{
223 		return gtk_adjustment_get_step_increment(gtkAdjustment);
224 	}
225 
226 	/**
227 	 * Retrieves the maximum value of the adjustment.
228 	 *
229 	 * Returns: The current maximum value of the adjustment
230 	 *
231 	 * Since: 2.14
232 	 */
233 	public double getUpper()
234 	{
235 		return gtk_adjustment_get_upper(gtkAdjustment);
236 	}
237 
238 	/**
239 	 * Gets the current value of the adjustment.
240 	 * See gtk_adjustment_set_value().
241 	 *
242 	 * Returns: The current value of the adjustment
243 	 */
244 	public double getValue()
245 	{
246 		return gtk_adjustment_get_value(gtkAdjustment);
247 	}
248 
249 	/**
250 	 * Sets the minimum value of the adjustment.
251 	 *
252 	 * When setting multiple adjustment properties via their individual
253 	 * setters, multiple #GtkAdjustment::changed signals will be emitted.
254 	 * However, since the emission of the #GtkAdjustment::changed signal
255 	 * is tied to the emission of the #GObject::notify signals of the changed
256 	 * properties, it’s possible to compress the #GtkAdjustment::changed
257 	 * signals into one by calling g_object_freeze_notify() and
258 	 * g_object_thaw_notify() around the calls to the individual setters.
259 	 *
260 	 * Alternatively, using a single g_object_set() for all the properties
261 	 * to change, or using gtk_adjustment_configure() has the same effect
262 	 * of compressing #GtkAdjustment::changed emissions.
263 	 *
264 	 * Params:
265 	 *     lower = the new minimum value
266 	 *
267 	 * Since: 2.14
268 	 */
269 	public void setLower(double lower)
270 	{
271 		gtk_adjustment_set_lower(gtkAdjustment, lower);
272 	}
273 
274 	/**
275 	 * Sets the page increment of the adjustment.
276 	 *
277 	 * See gtk_adjustment_set_lower() about how to compress multiple
278 	 * emissions of the #GtkAdjustment::changed signal when setting
279 	 * multiple adjustment properties.
280 	 *
281 	 * Params:
282 	 *     pageIncrement = the new page increment
283 	 *
284 	 * Since: 2.14
285 	 */
286 	public void setPageIncrement(double pageIncrement)
287 	{
288 		gtk_adjustment_set_page_increment(gtkAdjustment, pageIncrement);
289 	}
290 
291 	/**
292 	 * Sets the page size of the adjustment.
293 	 *
294 	 * See gtk_adjustment_set_lower() about how to compress multiple
295 	 * emissions of the GtkAdjustment::changed signal when setting
296 	 * multiple adjustment properties.
297 	 *
298 	 * Params:
299 	 *     pageSize = the new page size
300 	 *
301 	 * Since: 2.14
302 	 */
303 	public void setPageSize(double pageSize)
304 	{
305 		gtk_adjustment_set_page_size(gtkAdjustment, pageSize);
306 	}
307 
308 	/**
309 	 * Sets the step increment of the adjustment.
310 	 *
311 	 * See gtk_adjustment_set_lower() about how to compress multiple
312 	 * emissions of the #GtkAdjustment::changed signal when setting
313 	 * multiple adjustment properties.
314 	 *
315 	 * Params:
316 	 *     stepIncrement = the new step increment
317 	 *
318 	 * Since: 2.14
319 	 */
320 	public void setStepIncrement(double stepIncrement)
321 	{
322 		gtk_adjustment_set_step_increment(gtkAdjustment, stepIncrement);
323 	}
324 
325 	/**
326 	 * Sets the maximum value of the adjustment.
327 	 *
328 	 * Note that values will be restricted by `upper - page-size`
329 	 * if the page-size property is nonzero.
330 	 *
331 	 * See gtk_adjustment_set_lower() about how to compress multiple
332 	 * emissions of the #GtkAdjustment::changed signal when setting
333 	 * multiple adjustment properties.
334 	 *
335 	 * Params:
336 	 *     upper = the new maximum value
337 	 *
338 	 * Since: 2.14
339 	 */
340 	public void setUpper(double upper)
341 	{
342 		gtk_adjustment_set_upper(gtkAdjustment, upper);
343 	}
344 
345 	/**
346 	 * Sets the #GtkAdjustment value. The value is clamped to lie between
347 	 * #GtkAdjustment:lower and #GtkAdjustment:upper.
348 	 *
349 	 * Note that for adjustments which are used in a #GtkScrollbar, the
350 	 * effective range of allowed values goes from #GtkAdjustment:lower to
351 	 * #GtkAdjustment:upper - #GtkAdjustment:page-size.
352 	 *
353 	 * Params:
354 	 *     value = the new value
355 	 */
356 	public void setValue(double value)
357 	{
358 		gtk_adjustment_set_value(gtkAdjustment, value);
359 	}
360 
361 	/**
362 	 * Emits a #GtkAdjustment::value-changed signal from the #GtkAdjustment.
363 	 * This is typically called by the owner of the #GtkAdjustment after it has
364 	 * changed the #GtkAdjustment:value property.
365 	 *
366 	 * Deprecated: GTK+ emits #GtkAdjustment::value-changed itself whenever
367 	 * the value changes
368 	 */
369 	public void valueChanged()
370 	{
371 		gtk_adjustment_value_changed(gtkAdjustment);
372 	}
373 
374 	protected class OnChangedDelegateWrapper
375 	{
376 		void delegate(Adjustment) dlg;
377 		gulong handlerId;
378 		
379 		this(void delegate(Adjustment) dlg)
380 		{
381 			this.dlg = dlg;
382 			onChangedListeners ~= this;
383 		}
384 		
385 		void remove(OnChangedDelegateWrapper source)
386 		{
387 			foreach(index, wrapper; onChangedListeners)
388 			{
389 				if (wrapper.handlerId == source.handlerId)
390 				{
391 					onChangedListeners[index] = null;
392 					onChangedListeners = std.algorithm.remove(onChangedListeners, index);
393 					break;
394 				}
395 			}
396 		}
397 	}
398 	OnChangedDelegateWrapper[] onChangedListeners;
399 
400 	/**
401 	 * Emitted when one or more of the #GtkAdjustment properties have been
402 	 * changed, other than the #GtkAdjustment:value property.
403 	 */
404 	gulong addOnChanged(void delegate(Adjustment) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
405 	{
406 		auto wrapper = new OnChangedDelegateWrapper(dlg);
407 		wrapper.handlerId = Signals.connectData(
408 			this,
409 			"changed",
410 			cast(GCallback)&callBackChanged,
411 			cast(void*)wrapper,
412 			cast(GClosureNotify)&callBackChangedDestroy,
413 			connectFlags);
414 		return wrapper.handlerId;
415 	}
416 	
417 	extern(C) static void callBackChanged(GtkAdjustment* adjustmentStruct, OnChangedDelegateWrapper wrapper)
418 	{
419 		wrapper.dlg(wrapper.outer);
420 	}
421 	
422 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
423 	{
424 		wrapper.remove(wrapper);
425 	}
426 
427 	protected class OnValueChangedDelegateWrapper
428 	{
429 		void delegate(Adjustment) dlg;
430 		gulong handlerId;
431 		
432 		this(void delegate(Adjustment) dlg)
433 		{
434 			this.dlg = dlg;
435 			onValueChangedListeners ~= this;
436 		}
437 		
438 		void remove(OnValueChangedDelegateWrapper source)
439 		{
440 			foreach(index, wrapper; onValueChangedListeners)
441 			{
442 				if (wrapper.handlerId == source.handlerId)
443 				{
444 					onValueChangedListeners[index] = null;
445 					onValueChangedListeners = std.algorithm.remove(onValueChangedListeners, index);
446 					break;
447 				}
448 			}
449 		}
450 	}
451 	OnValueChangedDelegateWrapper[] onValueChangedListeners;
452 
453 	/**
454 	 * Emitted when the #GtkAdjustment:value property has been changed.
455 	 */
456 	gulong addOnValueChanged(void delegate(Adjustment) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
457 	{
458 		auto wrapper = new OnValueChangedDelegateWrapper(dlg);
459 		wrapper.handlerId = Signals.connectData(
460 			this,
461 			"value-changed",
462 			cast(GCallback)&callBackValueChanged,
463 			cast(void*)wrapper,
464 			cast(GClosureNotify)&callBackValueChangedDestroy,
465 			connectFlags);
466 		return wrapper.handlerId;
467 	}
468 	
469 	extern(C) static void callBackValueChanged(GtkAdjustment* adjustmentStruct, OnValueChangedDelegateWrapper wrapper)
470 	{
471 		wrapper.dlg(wrapper.outer);
472 	}
473 	
474 	extern(C) static void callBackValueChangedDestroy(OnValueChangedDelegateWrapper wrapper, GClosure* closure)
475 	{
476 		wrapper.remove(wrapper);
477 	}
478 }