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