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 * Conversion parameters: 26 * inFile = GtkScale.html 27 * outPack = gtk 28 * outFile = Scale 29 * strct = GtkScale 30 * realStrct= 31 * ctorStrct= 32 * clss = Scale 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_scale_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - gtk.Adjustment 48 * - pango.PgLayout 49 * structWrap: 50 * - GtkAdjustment* -> Adjustment 51 * - PangoLayout* -> PgLayout 52 * module aliases: 53 * local aliases: 54 * overrides: 55 */ 56 57 module gtk.Scale; 58 59 public import gtkc.gtktypes; 60 61 private import gtkc.gtk; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 private import gobject.Signals; 66 public import gtkc.gdktypes; 67 private import glib.Str; 68 private import gtk.Adjustment; 69 private import pango.PgLayout; 70 71 72 private import gtk.Range; 73 74 /** 75 * A GtkScale is a slider control used to select a numeric value. 76 * To use it, you'll probably want to investigate the methods on 77 * its base class, GtkRange, in addition to the methods for GtkScale itself. 78 * To set the value of a scale, you would normally use gtk_range_set_value(). 79 * To detect changes to the value, you would normally use the 80 * "value-changed" signal. 81 * 82 * Note that using the same upper and lower bounds for the GtkScale (through 83 * the GtkRange methods) will hide the slider itself. This is useful for 84 * applications that want to show an undeterminate value on the scale, without 85 * changing the layout of the application (such as movie or music players). 86 * 87 * GtkScale as GtkBuildable 88 * 89 * GtkScale supports a custom <marks> element, which 90 * can contain multiple <mark> elements. The "value" and "position" 91 * attributes have the same meaning as gtk_scale_add_mark() parameters of the 92 * same name. If the element is not empty, its content is taken as the markup 93 * to show at the mark. It can be translated with the usual "translatable and 94 * "context" attributes. 95 */ 96 public class Scale : Range 97 { 98 99 /** the main Gtk struct */ 100 protected GtkScale* gtkScale; 101 102 103 /** Get the main Gtk struct */ 104 public GtkScale* getScaleStruct() 105 { 106 return gtkScale; 107 } 108 109 110 /** the main Gtk struct as a void* */ 111 protected override void* getStruct() 112 { 113 return cast(void*)gtkScale; 114 } 115 116 /** 117 * Sets our main struct and passes it to the parent class 118 */ 119 public this (GtkScale* gtkScale) 120 { 121 super(cast(GtkRange*)gtkScale); 122 this.gtkScale = gtkScale; 123 } 124 125 protected override void setStruct(GObject* obj) 126 { 127 super.setStruct(obj); 128 gtkScale = cast(GtkScale*)obj; 129 } 130 131 /** 132 */ 133 int[string] connectedSignals; 134 135 string delegate(gdouble, Scale)[] onFormatValueListeners; 136 /** 137 * Signal which allows you to change how the scale value is displayed. 138 * Connect a signal handler which returns an allocated string representing 139 * value. That string will then be used to display the scale's value. 140 * Here's an example signal handler which displays a value 1.0 as 141 * with "-->1.0<--". 142 * $(DDOC_COMMENT example) 143 */ 144 void addOnFormatValue(string delegate(gdouble, Scale) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 145 { 146 if ( !("format-value" in connectedSignals) ) 147 { 148 Signals.connectData( 149 getStruct(), 150 "format-value", 151 cast(GCallback)&callBackFormatValue, 152 cast(void*)this, 153 null, 154 connectFlags); 155 connectedSignals["format-value"] = 1; 156 } 157 onFormatValueListeners ~= dlg; 158 } 159 extern(C) static void callBackFormatValue(GtkScale* scaleStruct, gdouble value, Scale _scale) 160 { 161 foreach ( string delegate(gdouble, Scale) dlg ; _scale.onFormatValueListeners ) 162 { 163 dlg(value, _scale); 164 } 165 } 166 167 168 /** 169 * Creates a new GtkScale. 170 * Params: 171 * orientation = the scale's orientation. 172 * adjustment = the GtkAdjustment which sets the range 173 * of the scale, or NULL to create a new adjustment. [allow-none] 174 * Throws: ConstructionException GTK+ fails to create the object. 175 */ 176 public this (GtkOrientation orientation, Adjustment adjustment) 177 { 178 // GtkWidget * gtk_scale_new (GtkOrientation orientation, GtkAdjustment *adjustment); 179 auto p = gtk_scale_new(orientation, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 180 if(p is null) 181 { 182 throw new ConstructionException("null returned by gtk_scale_new(orientation, (adjustment is null) ? null : adjustment.getAdjustmentStruct())"); 183 } 184 this(cast(GtkScale*) p); 185 } 186 187 /** 188 * Creates a new scale widget with the given orientation that lets the 189 * user input a number between min and max (including min and max) 190 * with the increment step. step must be nonzero; it's the distance 191 * the slider moves when using the arrow keys to adjust the scale 192 * value. 193 * Note that the way in which the precision is derived works best if step 194 * is a power of ten. If the resulting precision is not suitable for your 195 * needs, use gtk_scale_set_digits() to correct it. 196 * Params: 197 * orientation = the scale's orientation. 198 * min = minimum value 199 * max = maximum value 200 * step = step increment (tick size) used with keyboard shortcuts 201 * Throws: ConstructionException GTK+ fails to create the object. 202 */ 203 public this (GtkOrientation orientation, double min, double max, double step) 204 { 205 // GtkWidget * gtk_scale_new_with_range (GtkOrientation orientation, gdouble min, gdouble max, gdouble step); 206 auto p = gtk_scale_new_with_range(orientation, min, max, step); 207 if(p is null) 208 { 209 throw new ConstructionException("null returned by gtk_scale_new_with_range(orientation, min, max, step)"); 210 } 211 this(cast(GtkScale*) p); 212 } 213 214 /** 215 * Sets the number of decimal places that are displayed in the value. 216 * Also causes the value of the adjustment to be rounded off to this 217 * number of digits, so the retrieved value matches the value the user saw. 218 * Params: 219 * digits = the number of decimal places to display, 220 * e.g. use 1 to display 1.0, 2 to display 1.00, etc 221 */ 222 public void setDigits(int digits) 223 { 224 // void gtk_scale_set_digits (GtkScale *scale, gint digits); 225 gtk_scale_set_digits(gtkScale, digits); 226 } 227 228 /** 229 * Specifies whether the current value is displayed as a string next 230 * to the slider. 231 * Params: 232 * drawValue = TRUE to draw the value 233 */ 234 public void setDrawValue(int drawValue) 235 { 236 // void gtk_scale_set_draw_value (GtkScale *scale, gboolean draw_value); 237 gtk_scale_set_draw_value(gtkScale, drawValue); 238 } 239 240 /** 241 * If has_origin is set to TRUE (the default), 242 * the scale will highlight the part of the scale 243 * between the origin (bottom or left side) of the scale 244 * and the current value. 245 * Params: 246 * hasOrigin = TRUE if the scale has an origin 247 * Since 3.4 248 */ 249 public void setHasOrigin(int hasOrigin) 250 { 251 // void gtk_scale_set_has_origin (GtkScale *scale, gboolean has_origin); 252 gtk_scale_set_has_origin(gtkScale, hasOrigin); 253 } 254 255 /** 256 * Sets the position in which the current value is displayed. 257 * Params: 258 * pos = the position in which the current value is displayed 259 */ 260 public void setValuePos(GtkPositionType pos) 261 { 262 // void gtk_scale_set_value_pos (GtkScale *scale, GtkPositionType pos); 263 gtk_scale_set_value_pos(gtkScale, pos); 264 } 265 266 /** 267 * Gets the number of decimal places that are displayed in the value. 268 * Returns: the number of decimal places that are displayed 269 */ 270 public int getDigits() 271 { 272 // gint gtk_scale_get_digits (GtkScale *scale); 273 return gtk_scale_get_digits(gtkScale); 274 } 275 276 /** 277 * Returns whether the current value is displayed as a string 278 * next to the slider. 279 * Returns: whether the current value is displayed as a string 280 */ 281 public int getDrawValue() 282 { 283 // gboolean gtk_scale_get_draw_value (GtkScale *scale); 284 return gtk_scale_get_draw_value(gtkScale); 285 } 286 287 /** 288 * Returns whether the scale has an origin. 289 * Returns: TRUE if the scale has an origin. Since 3.4 290 */ 291 public int getHasOrigin() 292 { 293 // gboolean gtk_scale_get_has_origin (GtkScale *scale); 294 return gtk_scale_get_has_origin(gtkScale); 295 } 296 297 /** 298 * Gets the position in which the current value is displayed. 299 * Returns: the position in which the current value is displayed 300 */ 301 public GtkPositionType getValuePos() 302 { 303 // GtkPositionType gtk_scale_get_value_pos (GtkScale *scale); 304 return gtk_scale_get_value_pos(gtkScale); 305 } 306 307 /** 308 * Gets the PangoLayout used to display the scale. The returned 309 * object is owned by the scale so does not need to be freed by 310 * the caller. 311 * Since 2.4 312 * Returns: the PangoLayout for this scale, or NULL if the "draw-value" property is FALSE. [transfer none] 313 */ 314 public PgLayout getLayout() 315 { 316 // PangoLayout * gtk_scale_get_layout (GtkScale *scale); 317 auto p = gtk_scale_get_layout(gtkScale); 318 319 if(p is null) 320 { 321 return null; 322 } 323 324 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p); 325 } 326 327 /** 328 * Obtains the coordinates where the scale will draw the 329 * PangoLayout representing the text in the scale. Remember 330 * when using the PangoLayout function you need to convert to 331 * and from pixels using PANGO_PIXELS() or PANGO_SCALE. 332 * If the "draw-value" property is FALSE, the return 333 * values are undefined. 334 * Since 2.4 335 * Params: 336 * x = location to store X offset of layout, or NULL. [out][allow-none] 337 * y = location to store Y offset of layout, or NULL. [out][allow-none] 338 */ 339 public void getLayoutOffsets(out int x, out int y) 340 { 341 // void gtk_scale_get_layout_offsets (GtkScale *scale, gint *x, gint *y); 342 gtk_scale_get_layout_offsets(gtkScale, &x, &y); 343 } 344 345 /** 346 * Adds a mark at value. 347 * A mark is indicated visually by drawing a tick mark next to the scale, 348 * and GTK+ makes it easy for the user to position the scale exactly at the 349 * marks value. 350 * If markup is not NULL, text is shown next to the tick mark. 351 * To remove marks from a scale, use gtk_scale_clear_marks(). 352 * Since 2.16 353 * Params: 354 * value = the value at which the mark is placed, must be between 355 * the lower and upper limits of the scales' adjustment 356 * position = where to draw the mark. For a horizontal scale, GTK_POS_TOP 357 * and GTK_POS_LEFT are drawn above the scale, anything else below. 358 * For a vertical scale, GTK_POS_LEFT and GTK_POS_TOP are drawn to 359 * the left of the scale, anything else to the right. 360 * markup = Text to be shown at the mark, using Pango markup, or NULL. [allow-none] 361 */ 362 public void addMark(double value, GtkPositionType position, string markup) 363 { 364 // void gtk_scale_add_mark (GtkScale *scale, gdouble value, GtkPositionType position, const gchar *markup); 365 gtk_scale_add_mark(gtkScale, value, position, Str.toStringz(markup)); 366 } 367 368 /** 369 * Removes any marks that have been added with gtk_scale_add_mark(). 370 * Since 2.16 371 */ 372 public void clearMarks() 373 { 374 // void gtk_scale_clear_marks (GtkScale *scale); 375 gtk_scale_clear_marks(gtkScale); 376 } 377 }