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.DropDown; 26 27 private import gio.ListModelIF; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gtk.Expression; 32 private import gtk.ListItemFactory; 33 private import gtk.Widget; 34 private import gtk.c.functions; 35 public import gtk.c.types; 36 37 38 /** 39 * `GtkDropDown` is a widget that allows the user to choose an item 40 * from a list of options. 41 * 42 * ![An example GtkDropDown](drop-down.png) 43 * 44 * The `GtkDropDown` displays the selected choice. 45 * 46 * The options are given to `GtkDropDown` in the form of `GListModel` 47 * and how the individual options are represented is determined by 48 * a [class@Gtk.ListItemFactory]. The default factory displays simple strings. 49 * 50 * `GtkDropDown` knows how to obtain strings from the items in a 51 * [class@Gtk.StringList]; for other models, you have to provide an expression 52 * to find the strings via [method@Gtk.DropDown.set_expression]. 53 * 54 * `GtkDropDown` can optionally allow search in the popup, which is 55 * useful if the list of options is long. To enable the search entry, 56 * use [method@Gtk.DropDown.set_enable_search]. 57 * 58 * # CSS nodes 59 * 60 * `GtkDropDown` has a single CSS node with name dropdown, 61 * with the button and popover nodes as children. 62 * 63 * # Accessibility 64 * 65 * `GtkDropDown` uses the %GTK_ACCESSIBLE_ROLE_COMBO_BOX role. 66 */ 67 public class DropDown : Widget 68 { 69 /** the main Gtk struct */ 70 protected GtkDropDown* gtkDropDown; 71 72 /** Get the main Gtk struct */ 73 public GtkDropDown* getDropDownStruct(bool transferOwnership = false) 74 { 75 if (transferOwnership) 76 ownedRef = false; 77 return gtkDropDown; 78 } 79 80 /** the main Gtk struct as a void* */ 81 protected override void* getStruct() 82 { 83 return cast(void*)gtkDropDown; 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GtkDropDown* gtkDropDown, bool ownedRef = false) 90 { 91 this.gtkDropDown = gtkDropDown; 92 super(cast(GtkWidget*)gtkDropDown, ownedRef); 93 } 94 95 96 /** */ 97 public static GType getType() 98 { 99 return gtk_drop_down_get_type(); 100 } 101 102 /** 103 * Creates a new `GtkDropDown`. 104 * 105 * You may want to call [method@Gtk.DropDown.set_factory] 106 * to set up a way to map its items to widgets. 107 * 108 * Params: 109 * model = the model to use or %NULL for none 110 * expression = the expression to use or %NULL for none 111 * 112 * Returns: a new `GtkDropDown` 113 * 114 * Throws: ConstructionException GTK+ fails to create the object. 115 */ 116 public this(ListModelIF model, Expression expression) 117 { 118 auto __p = gtk_drop_down_new((model is null) ? null : model.getListModelStruct(), (expression is null) ? null : expression.getExpressionStruct(true)); 119 120 if(__p is null) 121 { 122 throw new ConstructionException("null returned by new"); 123 } 124 125 this(cast(GtkDropDown*) __p); 126 } 127 128 /** 129 * Creates a new `GtkDropDown` that is populated with 130 * the strings. 131 * 132 * Params: 133 * strings = The strings to put in the dropdown 134 * 135 * Returns: a new `GtkDropDown` 136 * 137 * Throws: ConstructionException GTK+ fails to create the object. 138 */ 139 public this(string[] strings) 140 { 141 auto __p = gtk_drop_down_new_from_strings(Str.toStringzArray(strings)); 142 143 if(__p is null) 144 { 145 throw new ConstructionException("null returned by new_from_strings"); 146 } 147 148 this(cast(GtkDropDown*) __p); 149 } 150 151 /** 152 * Returns whether search is enabled. 153 * 154 * Returns: %TRUE if the popup includes a search entry 155 */ 156 public bool getEnableSearch() 157 { 158 return gtk_drop_down_get_enable_search(gtkDropDown) != 0; 159 } 160 161 /** 162 * Gets the expression set that is used to obtain strings from items. 163 * 164 * See [method@Gtk.DropDown.set_expression]. 165 * 166 * Returns: a `GtkExpression` or %NULL 167 */ 168 public Expression getExpression() 169 { 170 auto __p = gtk_drop_down_get_expression(gtkDropDown); 171 172 if(__p is null) 173 { 174 return null; 175 } 176 177 return ObjectG.getDObject!(Expression)(cast(GtkExpression*) __p); 178 } 179 180 /** 181 * Gets the factory that's currently used to populate list items. 182 * 183 * The factory returned by this function is always used for the 184 * item in the button. It is also used for items in the popup 185 * if [property@Gtk.DropDown:list-factory] is not set. 186 * 187 * Returns: The factory in use 188 */ 189 public ListItemFactory getFactory() 190 { 191 auto __p = gtk_drop_down_get_factory(gtkDropDown); 192 193 if(__p is null) 194 { 195 return null; 196 } 197 198 return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p); 199 } 200 201 /** 202 * Gets the factory that's currently used to populate list items in the popup. 203 * 204 * Returns: The factory in use 205 */ 206 public ListItemFactory getListFactory() 207 { 208 auto __p = gtk_drop_down_get_list_factory(gtkDropDown); 209 210 if(__p is null) 211 { 212 return null; 213 } 214 215 return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p); 216 } 217 218 /** 219 * Gets the model that provides the displayed items. 220 * 221 * Returns: The model in use 222 */ 223 public ListModelIF getModel() 224 { 225 auto __p = gtk_drop_down_get_model(gtkDropDown); 226 227 if(__p is null) 228 { 229 return null; 230 } 231 232 return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p); 233 } 234 235 /** 236 * Gets the position of the selected item. 237 * 238 * Returns: the position of the selected item, or %GTK_INVALID_LIST_POSITION 239 * if not item is selected 240 */ 241 public uint getSelected() 242 { 243 return gtk_drop_down_get_selected(gtkDropDown); 244 } 245 246 /** 247 * Gets the selected item. If no item is selected, %NULL is returned. 248 * 249 * Returns: The selected item 250 */ 251 public ObjectG getSelectedItem() 252 { 253 auto __p = gtk_drop_down_get_selected_item(gtkDropDown); 254 255 if(__p is null) 256 { 257 return null; 258 } 259 260 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p); 261 } 262 263 /** 264 * Sets whether a search entry will be shown in the popup that 265 * allows to search for items in the list. 266 * 267 * Note that [property@Gtk.DropDown:expression] must be set for 268 * search to work. 269 * 270 * Params: 271 * enableSearch = whether to enable search 272 */ 273 public void setEnableSearch(bool enableSearch) 274 { 275 gtk_drop_down_set_enable_search(gtkDropDown, enableSearch); 276 } 277 278 /** 279 * Sets the expression that gets evaluated to obtain strings from items. 280 * 281 * This is used for search in the popup. The expression must have 282 * a value type of %G_TYPE_STRING. 283 * 284 * Params: 285 * expression = a `GtkExpression`, or %NULL 286 */ 287 public void setExpression(Expression expression) 288 { 289 gtk_drop_down_set_expression(gtkDropDown, (expression is null) ? null : expression.getExpressionStruct()); 290 } 291 292 /** 293 * Sets the `GtkListItemFactory` to use for populating list items. 294 * 295 * Params: 296 * factory = the factory to use or %NULL for none 297 */ 298 public void setFactory(ListItemFactory factory) 299 { 300 gtk_drop_down_set_factory(gtkDropDown, (factory is null) ? null : factory.getListItemFactoryStruct()); 301 } 302 303 /** 304 * Sets the `GtkListItemFactory` to use for populating list items in the popup. 305 * 306 * Params: 307 * factory = the factory to use or %NULL for none 308 */ 309 public void setListFactory(ListItemFactory factory) 310 { 311 gtk_drop_down_set_list_factory(gtkDropDown, (factory is null) ? null : factory.getListItemFactoryStruct()); 312 } 313 314 /** 315 * Sets the `GListModel` to use. 316 * 317 * Params: 318 * model = the model to use or %NULL for none 319 */ 320 public void setModel(ListModelIF model) 321 { 322 gtk_drop_down_set_model(gtkDropDown, (model is null) ? null : model.getListModelStruct()); 323 } 324 325 /** 326 * Selects the item at the given position. 327 * 328 * Params: 329 * position = the position of the item to select, or %GTK_INVALID_LIST_POSITION 330 */ 331 public void setSelected(uint position) 332 { 333 gtk_drop_down_set_selected(gtkDropDown, position); 334 } 335 }