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