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.TreePath; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gtk.c.functions; 32 public import gtk.c.types; 33 private import gtkd.Loader; 34 35 36 /** 37 * An opaque structure representing a path to a row in a model. 38 */ 39 public class TreePath 40 { 41 /** the main Gtk struct */ 42 protected GtkTreePath* gtkTreePath; 43 protected bool ownedRef; 44 45 /** Get the main Gtk struct */ 46 public GtkTreePath* getTreePathStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return gtkTreePath; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected void* getStruct() 55 { 56 return cast(void*)gtkTreePath; 57 } 58 59 /** 60 * Sets our main struct and passes it to the parent class. 61 */ 62 public this (GtkTreePath* gtkTreePath, bool ownedRef = false) 63 { 64 this.gtkTreePath = gtkTreePath; 65 this.ownedRef = ownedRef; 66 } 67 68 ~this () 69 { 70 if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef ) 71 gtk_tree_path_free(gtkTreePath); 72 } 73 74 /** 75 * Creates a new GtkTreePath. This structure refers to a row. 76 * Params: 77 * firstRow = if true this is the string representation of this path is "0" 78 * Throws: ConstructionException GTK+ fails to create the object. 79 */ 80 public this (bool firstRow=false) 81 { 82 GtkTreePath* __p; 83 84 if ( firstRow ) 85 { 86 // GtkTreePath* gtk_tree_path_new_first (void); 87 __p = cast(GtkTreePath*)gtk_tree_path_new_first(); 88 } 89 else 90 { 91 // GtkTreePath* gtk_tree_path_new (void); 92 __p = cast(GtkTreePath*)gtk_tree_path_new(); 93 } 94 95 if(__p is null) 96 { 97 throw new ConstructionException("null returned by gtk_tree_path_new()"); 98 } 99 100 this(__p); 101 } 102 103 /** 104 */ 105 106 /** */ 107 public static GType getType() 108 { 109 return gtk_tree_path_get_type(); 110 } 111 112 /** 113 * Creates a new path with the given @indices array of @length. 114 * 115 * Params: 116 * indices = array of indices 117 * 118 * Returns: A newly created #GtkTreePath-struct 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this(int[] indices) 123 { 124 auto __p = gtk_tree_path_new_from_indicesv(indices.ptr, cast(size_t)indices.length); 125 126 if(__p is null) 127 { 128 throw new ConstructionException("null returned by new_from_indicesv"); 129 } 130 131 this(cast(GtkTreePath*) __p); 132 } 133 134 /** 135 * Creates a new #GtkTreePath-struct initialized to @path. 136 * 137 * @path is expected to be a colon separated list of numbers. 138 * For example, the string “10:4:0” would create a path of depth 139 * 3 pointing to the 11th child of the root node, the 5th 140 * child of that 11th child, and the 1st child of that 5th child. 141 * If an invalid path string is passed in, %NULL is returned. 142 * 143 * Params: 144 * path = The string representation of a path 145 * 146 * Returns: A newly-created #GtkTreePath-struct, or %NULL 147 * 148 * Throws: ConstructionException GTK+ fails to create the object. 149 */ 150 public this(string path) 151 { 152 auto __p = gtk_tree_path_new_from_string(Str.toStringz(path)); 153 154 if(__p is null) 155 { 156 throw new ConstructionException("null returned by new_from_string"); 157 } 158 159 this(cast(GtkTreePath*) __p); 160 } 161 162 /** 163 * Appends a new index to a path. 164 * 165 * As a result, the depth of the path is increased. 166 * 167 * Params: 168 * index = the index 169 */ 170 public void appendIndex(int index) 171 { 172 gtk_tree_path_append_index(gtkTreePath, index); 173 } 174 175 /** 176 * Compares two paths. 177 * 178 * If @a appears before @b in a tree, then -1 is returned. 179 * If @b appears before @a, then 1 is returned. 180 * If the two nodes are equal, then 0 is returned. 181 * 182 * Params: 183 * b = a #GtkTreePath-struct to compare with 184 * 185 * Returns: the relative positions of @a and @b 186 */ 187 public int compare(TreePath b) 188 { 189 return gtk_tree_path_compare(gtkTreePath, (b is null) ? null : b.getTreePathStruct()); 190 } 191 192 /** 193 * Creates a new #GtkTreePath-struct as a copy of @path. 194 * 195 * Returns: a new #GtkTreePath-struct 196 */ 197 public TreePath copy() 198 { 199 auto __p = gtk_tree_path_copy(gtkTreePath); 200 201 if(__p is null) 202 { 203 return null; 204 } 205 206 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) __p, true); 207 } 208 209 /** 210 * Moves @path to point to the first child of the current path. 211 */ 212 public void down() 213 { 214 gtk_tree_path_down(gtkTreePath); 215 } 216 217 /** 218 * Frees @path. If @path is %NULL, it simply returns. 219 */ 220 public void free() 221 { 222 gtk_tree_path_free(gtkTreePath); 223 ownedRef = false; 224 } 225 226 /** 227 * Returns the current depth of @path. 228 * 229 * Returns: The depth of @path 230 */ 231 public int getDepth() 232 { 233 return gtk_tree_path_get_depth(gtkTreePath); 234 } 235 236 /** 237 * Returns the current indices of @path. 238 * 239 * This is an array of integers, each representing a node in a tree. 240 * This value should not be freed. 241 * 242 * The length of the array can be obtained with gtk_tree_path_get_depth(). 243 * 244 * Returns: The current indices, or %NULL 245 */ 246 public int* getIndices() 247 { 248 return gtk_tree_path_get_indices(gtkTreePath); 249 } 250 251 /** 252 * Returns the current indices of @path. 253 * 254 * This is an array of integers, each representing a node in a tree. 255 * It also returns the number of elements in the array. 256 * The array should not be freed. 257 * 258 * Returns: The current 259 * indices, or %NULL 260 */ 261 public int[] getIndicesWithDepth() 262 { 263 int depth; 264 265 auto __p = gtk_tree_path_get_indices_with_depth(gtkTreePath, &depth); 266 267 return __p[0 .. depth]; 268 } 269 270 /** 271 * Returns %TRUE if @descendant is a descendant of @path. 272 * 273 * Params: 274 * descendant = another #GtkTreePath-struct 275 * 276 * Returns: %TRUE if @descendant is contained inside @path 277 */ 278 public bool isAncestor(TreePath descendant) 279 { 280 return gtk_tree_path_is_ancestor(gtkTreePath, (descendant is null) ? null : descendant.getTreePathStruct()) != 0; 281 } 282 283 /** 284 * Returns %TRUE if @path is a descendant of @ancestor. 285 * 286 * Params: 287 * ancestor = another #GtkTreePath-struct 288 * 289 * Returns: %TRUE if @ancestor contains @path somewhere below it 290 */ 291 public bool isDescendant(TreePath ancestor) 292 { 293 return gtk_tree_path_is_descendant(gtkTreePath, (ancestor is null) ? null : ancestor.getTreePathStruct()) != 0; 294 } 295 296 /** 297 * Moves the @path to point to the next node at the current depth. 298 */ 299 public void next() 300 { 301 gtk_tree_path_next(gtkTreePath); 302 } 303 304 /** 305 * Prepends a new index to a path. 306 * 307 * As a result, the depth of the path is increased. 308 * 309 * Params: 310 * index = the index 311 */ 312 public void prependIndex(int index) 313 { 314 gtk_tree_path_prepend_index(gtkTreePath, index); 315 } 316 317 /** 318 * Moves the @path to point to the previous node at the 319 * current depth, if it exists. 320 * 321 * Returns: %TRUE if @path has a previous node, and 322 * the move was made 323 */ 324 public bool prev() 325 { 326 return gtk_tree_path_prev(gtkTreePath) != 0; 327 } 328 329 /** 330 * Generates a string representation of the path. 331 * 332 * This string is a “:” separated list of numbers. 333 * For example, “4:10:0:3” would be an acceptable 334 * return value for this string. If the path has 335 * depth 0, %NULL is returned. 336 * 337 * Returns: A newly-allocated string. 338 * Must be freed with g_free(). 339 */ 340 public override string toString() 341 { 342 auto retStr = gtk_tree_path_to_string(gtkTreePath); 343 344 scope(exit) Str.freeString(retStr); 345 return Str.toString(retStr); 346 } 347 348 /** 349 * Moves the @path to point to its parent node, if it has a parent. 350 * 351 * Returns: %TRUE if @path has a parent, and the move was made 352 */ 353 public bool up() 354 { 355 return gtk_tree_path_up(gtkTreePath) != 0; 356 } 357 }