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 public  import gtkc.gdktypes;
31 private import gtkc.gtk;
32 public  import gtkc.gtktypes;
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
39  * #GtkSpinButton, #GtkViewport, and #GtkRange (which is a base class for
40  * #GtkHScrollbar, #GtkVScrollbar, #GtkHScale, and #GtkVScale).
41  * 
42  * The #GtkAdjustment object does not update the value itself. Instead
43  * it is left up to the owner of the #GtkAdjustment to control the value.
44  * 
45  * The owner of the #GtkAdjustment typically calls the
46  * gtk_adjustment_value_changed() and gtk_adjustment_changed() functions
47  * after changing the value and its bounds. This results in the emission of the
48  * #GtkAdjustment::value_changed or #GtkAdjustment::changed signal respectively.
49  */
50 public class Adjustment : ObjectG
51 {
52 	/** the main Gtk struct */
53 	protected GtkAdjustment* gtkAdjustment;
54 
55 	/** Get the main Gtk struct */
56 	public GtkAdjustment* getAdjustmentStruct()
57 	{
58 		return gtkAdjustment;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gtkAdjustment;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		gtkAdjustment = cast(GtkAdjustment*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GtkAdjustment* gtkAdjustment, bool ownedRef = false)
77 	{
78 		this.gtkAdjustment = gtkAdjustment;
79 		super(cast(GObject*)gtkAdjustment, ownedRef);
80 	}
81 
82 	/**
83 	 */
84 
85 	public static GType getType()
86 	{
87 		return gtk_adjustment_get_type();
88 	}
89 
90 	/**
91 	 * Creates a new #GtkAdjustment.
92 	 *
93 	 * Params:
94 	 *     value = the initial value.
95 	 *     lower = the minimum value.
96 	 *     upper = the maximum value.
97 	 *     stepIncrement = the step increment.
98 	 *     pageIncrement = the page increment.
99 	 *     pageSize = the page size.
100 	 *
101 	 * Return: a new #GtkAdjustment.
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this(double value, double lower, double upper, double stepIncrement, double pageIncrement, double pageSize)
106 	{
107 		auto p = gtk_adjustment_new(value, lower, upper, stepIncrement, pageIncrement, pageSize);
108 		
109 		if(p is null)
110 		{
111 			throw new ConstructionException("null returned by new");
112 		}
113 		
114 		this(cast(GtkAdjustment*) p);
115 	}
116 
117 	/**
118 	 * Emits a #GtkAdjustment::changed signal from the #GtkAdjustment.
119 	 * This is typically called by the owner of the #GtkAdjustment after it has
120 	 * changed any of the #GtkAdjustment properties other than the value.
121 	 */
122 	public void changed()
123 	{
124 		gtk_adjustment_changed(gtkAdjustment);
125 	}
126 
127 	/**
128 	 * Updates the #GtkAdjustment:value property to ensure that the range
129 	 * between @lower and @upper is in the current page (i.e. between
130 	 * #GtkAdjustment:value and #GtkAdjustment:value + #GtkAdjustment:page_size).
131 	 * If the range is larger than the page size, then only the start of it will
132 	 * be in the current page.
133 	 * A #GtkAdjustment::changed signal will be emitted if the value is changed.
134 	 *
135 	 * Params:
136 	 *     lower = the lower value.
137 	 *     upper = the upper value.
138 	 */
139 	public void clampPage(double lower, double upper)
140 	{
141 		gtk_adjustment_clamp_page(gtkAdjustment, lower, upper);
142 	}
143 
144 	/**
145 	 * Sets all properties of the adjustment at once.
146 	 *
147 	 * Use this function to avoid multiple emissions of the #GtkAdjustment::changed
148 	 * signal. See gtk_adjustment_set_lower() for an alternative way
149 	 * of compressing multiple emissions of #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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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 	 * Return: 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. See
240 	 * gtk_adjustment_set_value ().
241 	 *
242 	 * Return: 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. However, since
254 	 * the emission of the #GtkAdjustment::changed signal is tied to the emission of the
255 	 * #GObject::notify signals of the changed properties, it’s possible
256 	 * to compress the #GtkAdjustment::changed signals into one by calling
257 	 * g_object_freeze_notify() and g_object_thaw_notify() around the
258 	 * 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 multiple adjustment
279 	 * 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 multiple adjustment
296 	 * 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 multiple adjustment
313 	 * 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
329 	 * `upper - page-size` if the page-size
330 	 * property is nonzero.
331 	 *
332 	 * See gtk_adjustment_set_lower() about how to compress multiple
333 	 * emissions of the #GtkAdjustment::changed signal when setting multiple adjustment
334 	 * properties.
335 	 *
336 	 * Params:
337 	 *     upper = the new maximum value
338 	 *
339 	 * Since: 2.14
340 	 */
341 	public void setUpper(double upper)
342 	{
343 		gtk_adjustment_set_upper(gtkAdjustment, upper);
344 	}
345 
346 	/**
347 	 * Sets the #GtkAdjustment value. The value is clamped to lie between
348 	 * #GtkAdjustment:lower and #GtkAdjustment:upper.
349 	 *
350 	 * Note that for adjustments which are used in a #GtkScrollbar, the effective
351 	 * range of allowed values goes from #GtkAdjustment:lower to
352 	 * #GtkAdjustment:upper - #GtkAdjustment:page_size.
353 	 *
354 	 * Params:
355 	 *     value = the new value.
356 	 */
357 	public void setValue(double value)
358 	{
359 		gtk_adjustment_set_value(gtkAdjustment, value);
360 	}
361 
362 	/**
363 	 * Emits a #GtkAdjustment::value_changed signal from the #GtkAdjustment.
364 	 * This is typically called by the owner of the #GtkAdjustment after it has
365 	 * changed the #GtkAdjustment:value property.
366 	 */
367 	public void valueChanged()
368 	{
369 		gtk_adjustment_value_changed(gtkAdjustment);
370 	}
371 
372 	int[string] connectedSignals;
373 
374 	void delegate(Adjustment)[] onChangedListeners;
375 	/**
376 	 * Emitted when one or more of the #GtkAdjustment properties have been
377 	 * changed, other than the #GtkAdjustment:value property.
378 	 */
379 	void addOnChanged(void delegate(Adjustment) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
380 	{
381 		if ( "changed" !in connectedSignals )
382 		{
383 			Signals.connectData(
384 				this,
385 				"changed",
386 				cast(GCallback)&callBackChanged,
387 				cast(void*)this,
388 				null,
389 				connectFlags);
390 			connectedSignals["changed"] = 1;
391 		}
392 		onChangedListeners ~= dlg;
393 	}
394 	extern(C) static void callBackChanged(GtkAdjustment* adjustmentStruct, Adjustment _adjustment)
395 	{
396 		foreach ( void delegate(Adjustment) dlg; _adjustment.onChangedListeners )
397 		{
398 			dlg(_adjustment);
399 		}
400 	}
401 
402 	void delegate(Adjustment)[] onValueChangedListeners;
403 	/**
404 	 * Emitted when the #GtkAdjustment:value property has been changed.
405 	 */
406 	void addOnValueChanged(void delegate(Adjustment) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
407 	{
408 		if ( "value-changed" !in connectedSignals )
409 		{
410 			Signals.connectData(
411 				this,
412 				"value-changed",
413 				cast(GCallback)&callBackValueChanged,
414 				cast(void*)this,
415 				null,
416 				connectFlags);
417 			connectedSignals["value-changed"] = 1;
418 		}
419 		onValueChangedListeners ~= dlg;
420 	}
421 	extern(C) static void callBackValueChanged(GtkAdjustment* adjustmentStruct, Adjustment _adjustment)
422 	{
423 		foreach ( void delegate(Adjustment) dlg; _adjustment.onValueChangedListeners )
424 		{
425 			dlg(_adjustment);
426 		}
427 	}
428 }