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.ComboBoxText; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gtk.ComboBox; 31 private import gtk.c.functions; 32 public import gtk.c.types; 33 34 35 /** 36 * A `GtkComboBoxText` is a simple variant of `GtkComboBox` for text-only 37 * use cases. 38 * 39 * ![An example GtkComboBoxText](combo-box-text.png) 40 * 41 * `GtkComboBoxText` hides the model-view complexity of `GtkComboBox`. 42 * 43 * To create a `GtkComboBoxText`, use [ctor@Gtk.ComboBoxText.new] or 44 * [ctor@Gtk.ComboBoxText.new_with_entry]. 45 * 46 * You can add items to a `GtkComboBoxText` with 47 * [method@Gtk.ComboBoxText.append_text], 48 * [method@Gtk.ComboBoxText.insert_text] or 49 * [method@Gtk.ComboBoxText.prepend_text] and remove options with 50 * [method@Gtk.ComboBoxText.remove]. 51 * 52 * If the `GtkComboBoxText` contains an entry (via the 53 * [property@Gtk.ComboBox:has-entry] property), its contents can be retrieved 54 * using [method@Gtk.ComboBoxText.get_active_text]. 55 * 56 * You should not call [method@Gtk.ComboBox.set_model] or attempt to pack more 57 * cells into this combo box via its [interface@Gtk.CellLayout] interface. 58 * 59 * # GtkComboBoxText as GtkBuildable 60 * 61 * The `GtkComboBoxText` implementation of the `GtkBuildable` interface supports 62 * adding items directly using the <items> element and specifying <item> 63 * elements for each item. Each <item> element can specify the “id” 64 * corresponding to the appended text and also supports the regular 65 * translation attributes “translatable”, “context” and “comments”. 66 * 67 * Here is a UI definition fragment specifying `GtkComboBoxText` items: 68 * ```xml 69 * <object class="GtkComboBoxText"> 70 * <items> 71 * <item translatable="yes" id="factory">Factory</item> 72 * <item translatable="yes" id="home">Home</item> 73 * <item translatable="yes" id="subway">Subway</item> 74 * </items> 75 * </object> 76 * ``` 77 * 78 * # CSS nodes 79 * 80 * ``` 81 * combobox 82 * ╰── box.linked 83 * ├── entry.combo 84 * ├── button.combo 85 * ╰── window.popup 86 * ``` 87 * 88 * `GtkComboBoxText` has a single CSS node with name combobox. It adds 89 * the style class .combo to the main CSS nodes of its entry and button 90 * children, and the .linked class to the node of its internal box. 91 */ 92 public class ComboBoxText : ComboBox 93 { 94 /** the main Gtk struct */ 95 protected GtkComboBoxText* gtkComboBoxText; 96 97 /** Get the main Gtk struct */ 98 public GtkComboBoxText* getComboBoxTextStruct(bool transferOwnership = false) 99 { 100 if (transferOwnership) 101 ownedRef = false; 102 return gtkComboBoxText; 103 } 104 105 /** the main Gtk struct as a void* */ 106 protected override void* getStruct() 107 { 108 return cast(void*)gtkComboBoxText; 109 } 110 111 /** 112 * Sets our main struct and passes it to the parent class. 113 */ 114 public this (GtkComboBoxText* gtkComboBoxText, bool ownedRef = false) 115 { 116 this.gtkComboBoxText = gtkComboBoxText; 117 super(cast(GtkComboBox*)gtkComboBoxText, ownedRef); 118 } 119 120 /** 121 * Creates a new ComboBoxText, which is a ComboBox just displaying strings. 122 * Params: 123 * entry = If true, create an ComboBox with an entry. 124 * Throws: ConstructionException GTK+ fails to create the object. 125 */ 126 public this (bool entry=true) 127 { 128 GtkComboBoxText* __p; 129 if ( entry ) 130 { 131 // GtkWidget* gtk_combo_box_text_new_with_entry (void); 132 __p = cast(GtkComboBoxText*)gtk_combo_box_text_new_with_entry(); 133 } 134 else 135 { 136 // GtkWidget* gtk_combo_box_text_new (void); 137 __p = cast(GtkComboBoxText*)gtk_combo_box_text_new(); 138 } 139 140 if(__p is null) 141 { 142 throw new ConstructionException("null returned by gtk_combo_box_new"); 143 } 144 145 this(__p); 146 } 147 148 /** 149 */ 150 151 /** */ 152 public static GType getType() 153 { 154 return gtk_combo_box_text_get_type(); 155 } 156 157 /** 158 * Appends @text to the list of strings stored in @combo_box. 159 * 160 * If @id is non-%NULL then it is used as the ID of the row. 161 * 162 * This is the same as calling [method@Gtk.ComboBoxText.insert] 163 * with a position of -1. 164 * 165 * Params: 166 * id = a string ID for this value, or %NULL 167 * text = A string 168 */ 169 public void append(string id, string text) 170 { 171 gtk_combo_box_text_append(gtkComboBoxText, Str.toStringz(id), Str.toStringz(text)); 172 } 173 174 /** 175 * Appends @text to the list of strings stored in @combo_box. 176 * 177 * This is the same as calling [method@Gtk.ComboBoxText.insert_text] 178 * with a position of -1. 179 * 180 * Params: 181 * text = A string 182 */ 183 public void appendText(string text) 184 { 185 gtk_combo_box_text_append_text(gtkComboBoxText, Str.toStringz(text)); 186 } 187 188 /** 189 * Returns the currently active string in @combo_box. 190 * 191 * If no row is currently selected, %NULL is returned. 192 * If @combo_box contains an entry, this function will 193 * return its contents (which will not necessarily 194 * be an item from the list). 195 * 196 * Returns: a newly allocated 197 * string containing the currently active text. 198 * Must be freed with g_free(). 199 */ 200 public string getActiveText() 201 { 202 auto retStr = gtk_combo_box_text_get_active_text(gtkComboBoxText); 203 204 scope(exit) Str.freeString(retStr); 205 return Str.toString(retStr); 206 } 207 208 /** 209 * Inserts @text at @position in the list of strings stored in @combo_box. 210 * 211 * If @id is non-%NULL then it is used as the ID of the row. 212 * See [property@Gtk.ComboBox:id-column]. 213 * 214 * If @position is negative then @text is appended. 215 * 216 * Params: 217 * position = An index to insert @text 218 * id = a string ID for this value, or %NULL 219 * text = A string to display 220 */ 221 public void insert(int position, string id, string text) 222 { 223 gtk_combo_box_text_insert(gtkComboBoxText, position, Str.toStringz(id), Str.toStringz(text)); 224 } 225 226 /** 227 * Inserts @text at @position in the list of strings stored in @combo_box. 228 * 229 * If @position is negative then @text is appended. 230 * 231 * This is the same as calling [method@Gtk.ComboBoxText.insert] 232 * with a %NULL ID string. 233 * 234 * Params: 235 * position = An index to insert @text 236 * text = A string 237 */ 238 public void insertText(int position, string text) 239 { 240 gtk_combo_box_text_insert_text(gtkComboBoxText, position, Str.toStringz(text)); 241 } 242 243 /** 244 * Prepends @text to the list of strings stored in @combo_box. 245 * 246 * If @id is non-%NULL then it is used as the ID of the row. 247 * 248 * This is the same as calling [method@Gtk.ComboBoxText.insert] 249 * with a position of 0. 250 * 251 * Params: 252 * id = a string ID for this value, or %NULL 253 * text = a string 254 */ 255 public void prepend(string id, string text) 256 { 257 gtk_combo_box_text_prepend(gtkComboBoxText, Str.toStringz(id), Str.toStringz(text)); 258 } 259 260 /** 261 * Prepends @text to the list of strings stored in @combo_box. 262 * 263 * This is the same as calling [method@Gtk.ComboBoxText.insert_text] 264 * with a position of 0. 265 * 266 * Params: 267 * text = A string 268 */ 269 public void prependText(string text) 270 { 271 gtk_combo_box_text_prepend_text(gtkComboBoxText, Str.toStringz(text)); 272 } 273 274 /** 275 * Removes the string at @position from @combo_box. 276 * 277 * Params: 278 * position = Index of the item to remove 279 */ 280 public void remove(int position) 281 { 282 gtk_combo_box_text_remove(gtkComboBoxText, position); 283 } 284 285 /** 286 * Removes all the text entries from the combo box. 287 */ 288 public void removeAll() 289 { 290 gtk_combo_box_text_remove_all(gtkComboBoxText); 291 } 292 }