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.StringList; 26 27 private import gio.ListModelIF; 28 private import gio.ListModelT; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import glib.c.functions; 32 private import gobject.ObjectG; 33 private import gtk.BuildableIF; 34 private import gtk.BuildableT; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 38 39 /** 40 * `GtkStringList` is a list model that wraps an array of strings. 41 * 42 * The objects in the model have a "string" property. 43 * 44 * `GtkStringList` is well-suited for any place where you would 45 * typically use a `char*[]`, but need a list model. 46 * 47 * # GtkStringList as GtkBuildable 48 * 49 * The `GtkStringList` implementation of the `GtkBuildable` interface 50 * supports adding items directly using the <items> element and 51 * specifying <item> elements for each item. Each <item> element 52 * supports the regular translation attributes “translatable”, 53 * “context” and “comments”. 54 * 55 * Here is a UI definition fragment specifying a `GtkStringList` 56 * 57 * ```xml 58 * <object class="GtkStringList"> 59 * <items> 60 * <item translatable="yes">Factory</item> 61 * <item translatable="yes">Home</item> 62 * <item translatable="yes">Subway</item> 63 * </items> 64 * </object> 65 * ``` 66 */ 67 public class StringList : ObjectG, ListModelIF, BuildableIF 68 { 69 /** the main Gtk struct */ 70 protected GtkStringList* gtkStringList; 71 72 /** Get the main Gtk struct */ 73 public GtkStringList* getStringListStruct(bool transferOwnership = false) 74 { 75 if (transferOwnership) 76 ownedRef = false; 77 return gtkStringList; 78 } 79 80 /** the main Gtk struct as a void* */ 81 protected override void* getStruct() 82 { 83 return cast(void*)gtkStringList; 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GtkStringList* gtkStringList, bool ownedRef = false) 90 { 91 this.gtkStringList = gtkStringList; 92 super(cast(GObject*)gtkStringList, ownedRef); 93 } 94 95 // add the ListModel capabilities 96 mixin ListModelT!(GtkStringList); 97 98 // add the Buildable capabilities 99 mixin BuildableT!(GtkStringList); 100 101 102 /** */ 103 public static GType getType() 104 { 105 return gtk_string_list_get_type(); 106 } 107 108 /** 109 * Creates a new `GtkStringList` with the given @strings. 110 * 111 * Params: 112 * strings = The strings to put in the model 113 * 114 * Returns: a new `GtkStringList` 115 * 116 * Throws: ConstructionException GTK+ fails to create the object. 117 */ 118 public this(string[] strings) 119 { 120 auto __p = gtk_string_list_new(Str.toStringzArray(strings)); 121 122 if(__p is null) 123 { 124 throw new ConstructionException("null returned by new"); 125 } 126 127 this(cast(GtkStringList*) __p, true); 128 } 129 130 /** 131 * Appends @string to @self. 132 * 133 * The @string will be copied. See 134 * [method@Gtk.StringList.take] for a way to avoid that. 135 * 136 * Params: 137 * string_ = the string to insert 138 */ 139 public void append(string string_) 140 { 141 gtk_string_list_append(gtkStringList, Str.toStringz(string_)); 142 } 143 144 /** 145 * Gets the string that is at @position in @self. 146 * 147 * If @self does not contain @position items, %NULL is returned. 148 * 149 * This function returns the const char *. To get the 150 * object wrapping it, use g_list_model_get_item(). 151 * 152 * Params: 153 * position = the position to get the string for 154 * 155 * Returns: the string at the given position 156 */ 157 public string getString(uint position) 158 { 159 return Str.toString(gtk_string_list_get_string(gtkStringList, position)); 160 } 161 162 /** 163 * Removes the string at @position from @self. 164 * 165 * @position must be smaller than the current 166 * length of the list. 167 * 168 * Params: 169 * position = the position of the string that is to be removed 170 */ 171 public void remove(uint position) 172 { 173 gtk_string_list_remove(gtkStringList, position); 174 } 175 176 /** 177 * Changes @self by removing @n_removals strings and adding @additions 178 * to it. 179 * 180 * This function is more efficient than [method@Gtk.StringList.append] 181 * and [method@Gtk.StringList.remove], because it only emits the 182 * ::items-changed signal once for the change. 183 * 184 * This function copies the strings in @additions. 185 * 186 * The parameters @position and @n_removals must be correct (ie: 187 * @position + @n_removals must be less than or equal to the length 188 * of the list at the time this function is called). 189 * 190 * Params: 191 * position = the position at which to make the change 192 * nRemovals = the number of strings to remove 193 * additions = The strings to add 194 */ 195 public void splice(uint position, uint nRemovals, string[] additions) 196 { 197 gtk_string_list_splice(gtkStringList, position, nRemovals, Str.toStringzArray(additions)); 198 } 199 200 /** 201 * Adds @string to self at the end, and takes 202 * ownership of it. 203 * 204 * This variant of [method@Gtk.StringList.append] 205 * is convenient for formatting strings: 206 * 207 * ```c 208 * gtk_string_list_take (self, g_strdup_print ("%d dollars", lots)); 209 * ``` 210 * 211 * Params: 212 * string_ = the string to insert 213 */ 214 public void take(string string_) 215 { 216 gtk_string_list_take(gtkStringList, Str.toStringz(string_)); 217 } 218 }