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