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