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.ScaleButton; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Adjustment; 32 private import gtk.Button; 33 private import gtk.OrientableIF; 34 private import gtk.OrientableT; 35 private import gtk.Widget; 36 private import gtkc.gtk; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * #GtkScaleButton provides a button which pops up a scale widget. 43 * This kind of widget is commonly used for volume controls in multimedia 44 * applications, and GTK+ provides a #GtkVolumeButton subclass that 45 * is tailored for this use case. 46 * 47 * # CSS nodes 48 * 49 * GtkScaleButton has a single CSS node with name button. To differentiate 50 * it from a plain #GtkButton, it gets the .scale style class. 51 */ 52 public class ScaleButton : Button, OrientableIF 53 { 54 /** the main Gtk struct */ 55 protected GtkScaleButton* gtkScaleButton; 56 57 /** Get the main Gtk struct */ 58 public GtkScaleButton* getScaleButtonStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gtkScaleButton; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gtkScaleButton; 69 } 70 71 protected override void setStruct(GObject* obj) 72 { 73 gtkScaleButton = cast(GtkScaleButton*)obj; 74 super.setStruct(obj); 75 } 76 77 /** 78 * Sets our main struct and passes it to the parent class. 79 */ 80 public this (GtkScaleButton* gtkScaleButton, bool ownedRef = false) 81 { 82 this.gtkScaleButton = gtkScaleButton; 83 super(cast(GtkButton*)gtkScaleButton, ownedRef); 84 } 85 86 // add the Orientable capabilities 87 mixin OrientableT!(GtkScaleButton); 88 89 90 /** */ 91 public static GType getType() 92 { 93 return gtk_scale_button_get_type(); 94 } 95 96 /** 97 * Creates a #GtkScaleButton, with a range between @min and @max, with 98 * a stepping of @step. 99 * 100 * Params: 101 * size = a stock icon size (#GtkIconSize) 102 * min = the minimum value of the scale (usually 0) 103 * max = the maximum value of the scale (usually 100) 104 * step = the stepping of value when a scroll-wheel event, 105 * or up/down arrow event occurs (usually 2) 106 * icons = a %NULL-terminated 107 * array of icon names, or %NULL if you want to set the list 108 * later with gtk_scale_button_set_icons() 109 * 110 * Returns: a new #GtkScaleButton 111 * 112 * Since: 2.12 113 * 114 * Throws: ConstructionException GTK+ fails to create the object. 115 */ 116 public this(GtkIconSize size, double min, double max, double step, string[] icons) 117 { 118 auto p = gtk_scale_button_new(size, min, max, step, Str.toStringzArray(icons)); 119 120 if(p is null) 121 { 122 throw new ConstructionException("null returned by new"); 123 } 124 125 this(cast(GtkScaleButton*) p); 126 } 127 128 /** 129 * Gets the #GtkAdjustment associated with the #GtkScaleButton’s scale. 130 * See gtk_range_get_adjustment() for details. 131 * 132 * Returns: the adjustment associated with the scale 133 * 134 * Since: 2.12 135 */ 136 public Adjustment getAdjustment() 137 { 138 auto p = gtk_scale_button_get_adjustment(gtkScaleButton); 139 140 if(p is null) 141 { 142 return null; 143 } 144 145 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p); 146 } 147 148 /** 149 * Retrieves the minus button of the #GtkScaleButton. 150 * 151 * Returns: the minus button of the #GtkScaleButton as a #GtkButton 152 * 153 * Since: 2.14 154 */ 155 public Button getMinusButton() 156 { 157 auto p = gtk_scale_button_get_minus_button(gtkScaleButton); 158 159 if(p is null) 160 { 161 return null; 162 } 163 164 return ObjectG.getDObject!(Button)(cast(GtkButton*) p); 165 } 166 167 /** 168 * Retrieves the plus button of the #GtkScaleButton. 169 * 170 * Returns: the plus button of the #GtkScaleButton as a #GtkButton 171 * 172 * Since: 2.14 173 */ 174 public Button getPlusButton() 175 { 176 auto p = gtk_scale_button_get_plus_button(gtkScaleButton); 177 178 if(p is null) 179 { 180 return null; 181 } 182 183 return ObjectG.getDObject!(Button)(cast(GtkButton*) p); 184 } 185 186 /** 187 * Retrieves the popup of the #GtkScaleButton. 188 * 189 * Returns: the popup of the #GtkScaleButton 190 * 191 * Since: 2.14 192 */ 193 public Widget getPopup() 194 { 195 auto p = gtk_scale_button_get_popup(gtkScaleButton); 196 197 if(p is null) 198 { 199 return null; 200 } 201 202 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 203 } 204 205 /** 206 * Gets the current value of the scale button. 207 * 208 * Returns: current value of the scale button 209 * 210 * Since: 2.12 211 */ 212 public double getValue() 213 { 214 return gtk_scale_button_get_value(gtkScaleButton); 215 } 216 217 /** 218 * Sets the #GtkAdjustment to be used as a model 219 * for the #GtkScaleButton’s scale. 220 * See gtk_range_set_adjustment() for details. 221 * 222 * Params: 223 * adjustment = a #GtkAdjustment 224 * 225 * Since: 2.12 226 */ 227 public void setAdjustment(Adjustment adjustment) 228 { 229 gtk_scale_button_set_adjustment(gtkScaleButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 230 } 231 232 /** 233 * Sets the icons to be used by the scale button. 234 * For details, see the #GtkScaleButton:icons property. 235 * 236 * Params: 237 * icons = a %NULL-terminated array of icon names 238 * 239 * Since: 2.12 240 */ 241 public void setIcons(string[] icons) 242 { 243 gtk_scale_button_set_icons(gtkScaleButton, Str.toStringzArray(icons)); 244 } 245 246 /** 247 * Sets the current value of the scale; if the value is outside 248 * the minimum or maximum range values, it will be clamped to fit 249 * inside them. The scale button emits the #GtkScaleButton::value-changed 250 * signal if the value changes. 251 * 252 * Params: 253 * value = new value of the scale button 254 * 255 * Since: 2.12 256 */ 257 public void setValue(double value) 258 { 259 gtk_scale_button_set_value(gtkScaleButton, value); 260 } 261 262 protected class OnPopdownDelegateWrapper 263 { 264 void delegate(ScaleButton) dlg; 265 gulong handlerId; 266 267 this(void delegate(ScaleButton) dlg) 268 { 269 this.dlg = dlg; 270 onPopdownListeners ~= this; 271 } 272 273 void remove(OnPopdownDelegateWrapper source) 274 { 275 foreach(index, wrapper; onPopdownListeners) 276 { 277 if (wrapper.handlerId == source.handlerId) 278 { 279 onPopdownListeners[index] = null; 280 onPopdownListeners = std.algorithm.remove(onPopdownListeners, index); 281 break; 282 } 283 } 284 } 285 } 286 OnPopdownDelegateWrapper[] onPopdownListeners; 287 288 /** 289 * The ::popdown signal is a 290 * [keybinding signal][GtkBindingSignal] 291 * which gets emitted to popdown the scale widget. 292 * 293 * The default binding for this signal is Escape. 294 * 295 * Since: 2.12 296 */ 297 gulong addOnPopdown(void delegate(ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 298 { 299 auto wrapper = new OnPopdownDelegateWrapper(dlg); 300 wrapper.handlerId = Signals.connectData( 301 this, 302 "popdown", 303 cast(GCallback)&callBackPopdown, 304 cast(void*)wrapper, 305 cast(GClosureNotify)&callBackPopdownDestroy, 306 connectFlags); 307 return wrapper.handlerId; 308 } 309 310 extern(C) static void callBackPopdown(GtkScaleButton* scalebuttonStruct, OnPopdownDelegateWrapper wrapper) 311 { 312 wrapper.dlg(wrapper.outer); 313 } 314 315 extern(C) static void callBackPopdownDestroy(OnPopdownDelegateWrapper wrapper, GClosure* closure) 316 { 317 wrapper.remove(wrapper); 318 } 319 320 protected class OnPopupDelegateWrapper 321 { 322 void delegate(ScaleButton) dlg; 323 gulong handlerId; 324 325 this(void delegate(ScaleButton) dlg) 326 { 327 this.dlg = dlg; 328 onPopupListeners ~= this; 329 } 330 331 void remove(OnPopupDelegateWrapper source) 332 { 333 foreach(index, wrapper; onPopupListeners) 334 { 335 if (wrapper.handlerId == source.handlerId) 336 { 337 onPopupListeners[index] = null; 338 onPopupListeners = std.algorithm.remove(onPopupListeners, index); 339 break; 340 } 341 } 342 } 343 } 344 OnPopupDelegateWrapper[] onPopupListeners; 345 346 /** 347 * The ::popup signal is a 348 * [keybinding signal][GtkBindingSignal] 349 * which gets emitted to popup the scale widget. 350 * 351 * The default bindings for this signal are Space, Enter and Return. 352 * 353 * Since: 2.12 354 */ 355 gulong addOnPopup(void delegate(ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 356 { 357 auto wrapper = new OnPopupDelegateWrapper(dlg); 358 wrapper.handlerId = Signals.connectData( 359 this, 360 "popup", 361 cast(GCallback)&callBackPopup, 362 cast(void*)wrapper, 363 cast(GClosureNotify)&callBackPopupDestroy, 364 connectFlags); 365 return wrapper.handlerId; 366 } 367 368 extern(C) static void callBackPopup(GtkScaleButton* scalebuttonStruct, OnPopupDelegateWrapper wrapper) 369 { 370 wrapper.dlg(wrapper.outer); 371 } 372 373 extern(C) static void callBackPopupDestroy(OnPopupDelegateWrapper wrapper, GClosure* closure) 374 { 375 wrapper.remove(wrapper); 376 } 377 378 protected class OnValueChangedDelegateWrapper 379 { 380 void delegate(double, ScaleButton) dlg; 381 gulong handlerId; 382 383 this(void delegate(double, ScaleButton) dlg) 384 { 385 this.dlg = dlg; 386 onValueChangedListeners ~= this; 387 } 388 389 void remove(OnValueChangedDelegateWrapper source) 390 { 391 foreach(index, wrapper; onValueChangedListeners) 392 { 393 if (wrapper.handlerId == source.handlerId) 394 { 395 onValueChangedListeners[index] = null; 396 onValueChangedListeners = std.algorithm.remove(onValueChangedListeners, index); 397 break; 398 } 399 } 400 } 401 } 402 OnValueChangedDelegateWrapper[] onValueChangedListeners; 403 404 /** 405 * The ::value-changed signal is emitted when the value field has 406 * changed. 407 * 408 * Params: 409 * value = the new value 410 * 411 * Since: 2.12 412 */ 413 gulong addOnValueChanged(void delegate(double, ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 414 { 415 auto wrapper = new OnValueChangedDelegateWrapper(dlg); 416 wrapper.handlerId = Signals.connectData( 417 this, 418 "value-changed", 419 cast(GCallback)&callBackValueChanged, 420 cast(void*)wrapper, 421 cast(GClosureNotify)&callBackValueChangedDestroy, 422 connectFlags); 423 return wrapper.handlerId; 424 } 425 426 extern(C) static void callBackValueChanged(GtkScaleButton* scalebuttonStruct, double value, OnValueChangedDelegateWrapper wrapper) 427 { 428 wrapper.dlg(value, wrapper.outer); 429 } 430 431 extern(C) static void callBackValueChangedDestroy(OnValueChangedDelegateWrapper wrapper, GClosure* closure) 432 { 433 wrapper.remove(wrapper); 434 } 435 }