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