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.TreeIter; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.Value; 30 private import gtk.TreeIterError; 31 private import gtk.TreeModelIF; 32 private import gtk.TreePath; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 public import gtkc.gtktypes; 36 private import std.variant; 37 38 39 /** 40 * The #GtkTreeIter is the primary structure 41 * for accessing a #GtkTreeModel. Models are expected to put a unique 42 * integer in the @stamp member, and put 43 * model-specific data in the three @user_data 44 * members. 45 */ 46 public class TreeIter 47 { 48 /** the main Gtk struct */ 49 protected GtkTreeIter* gtkTreeIter; 50 protected bool ownedRef; 51 52 /** Get the main Gtk struct */ 53 public GtkTreeIter* getTreeIterStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gtkTreeIter; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected void* getStruct() 62 { 63 return cast(void*)gtkTreeIter; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkTreeIter* gtkTreeIter, bool ownedRef = false) 70 { 71 this.gtkTreeIter = gtkTreeIter; 72 this.ownedRef = ownedRef; 73 } 74 75 /** 76 * this will be set only when the iter 77 * is created from the model. 78 */ 79 GtkTreeModel* gtkTreeModel; 80 81 /** */ 82 public void setModel(GtkTreeModel* gtkTreeModel) 83 { 84 this.gtkTreeModel = gtkTreeModel; 85 } 86 87 /** */ 88 public void setModel(TreeModelIF treeModel) 89 { 90 this.gtkTreeModel = treeModel.getTreeModelStruct(); 91 } 92 93 /** 94 * Throws: ConstructionException GTK+ fails to create the object. 95 */ 96 public this(TreeModelIF treeModel, string treePath) 97 { 98 this(treeModel, new TreePath(treePath)); 99 } 100 101 /** 102 * Throws: ConstructionException GTK+ fails to create the object. 103 */ 104 public this(TreeModelIF treeModel, TreePath treePath) 105 { 106 this(); 107 setModel(treeModel); 108 if ( !gtk_tree_model_get_iter_from_string( 109 treeModel.getTreeModelStruct(), 110 getTreeIterStruct(), Str.toStringz(treePath.toString())) ) 111 { 112 throw new ConstructionException("null returned by gtk_tree_model_get_iter_from_string"); 113 } 114 } 115 116 /** 117 * creates a new tree iteractor. 118 * used TreeView.createIter and TreeView.append() to create iteractor for a tree or list 119 */ 120 this() 121 { 122 this(new GtkTreeIter); 123 } 124 125 /** 126 * Creates a dynamically allocated tree iterator as a copy of iter. 127 */ 128 TreeIter copy(TreeIter iter) 129 { 130 TreeIter cp = new TreeIter(); 131 *(cp.gtkTreeIter) = *(iter.gtkTreeIter); 132 133 return cp; 134 } 135 136 /** 137 * Get Value 138 * Params: 139 * column = 140 * value = 141 */ 142 void getValue(int column, Value value) 143 { 144 if ( gtkTreeModel is null ) 145 { 146 throw new TreeIterError("getValue","Tree model not set"); 147 } 148 gtk_tree_model_get_value(gtkTreeModel, gtkTreeIter, column, value.getValueStruct()); 149 } 150 151 /** 152 * Get the value of a column as a string 153 * Params: 154 * column = the column number 155 * Returns: a string representing the value of the column 156 */ 157 string getValueString(int column) 158 { 159 if ( gtkTreeModel is null ) 160 { 161 throw new TreeIterError("getValueString","Tree model not set"); 162 } 163 Value value = new Value(); 164 gtk_tree_model_get_value(gtkTreeModel, gtkTreeIter, column, value.getValueStruct()); 165 //printf("TreeIter.getValuaString = %.*s\n", value.getString().toString()); 166 return value.getString(); 167 } 168 169 /** 170 * Get the value of a column as an int 171 * Params: 172 * column = the column number 173 * Returns: a string representing the value of the column 174 */ 175 int getValueInt(int column) 176 { 177 if ( gtkTreeModel is null ) 178 { 179 throw new TreeIterError("getValueInt", "Tree model not set"); 180 } 181 Value value = new Value(); 182 gtk_tree_model_get_value(gtkTreeModel, gtkTreeIter, column, value.getValueStruct()); 183 return value.getInt(); 184 } 185 186 /** */ 187 TreePath getTreePath() 188 { 189 if ( gtkTreeModel is null ) 190 { 191 throw new TreeIterError("getTreePath","Tree model not set"); 192 } 193 return new TreePath(gtk_tree_model_get_path(gtkTreeModel, gtkTreeIter)); 194 } 195 196 /** 197 * This return the path visible to the user. 198 */ 199 string getVisiblePath(string separator) 200 { 201 string vPath; 202 if ( gtkTreeModel is null ) 203 { 204 throw new TreeIterError("getVisiblePath", "Tree model not set"); 205 } 206 207 vPath = getValueString(0); 208 TreeIter parent = getParent(); 209 while ( parent !is null ) 210 { 211 //printf("TreeIter.getVisiblePath parent = %.*s\n",parent.getValueString(0).toString()); 212 vPath = parent.getValueString(0) ~ separator ~ vPath; 213 parent = parent.getParent(); 214 } 215 216 //printf("TreeIter.getVisiblePath = %.*s\n", vPath.toString()); 217 218 return vPath; 219 } 220 221 /** 222 * Gets the parent of this iter 223 * Returns: the parent iter or null if can't get parent or an error occured 224 */ 225 TreeIter getParent() 226 { 227 if ( gtkTreeModel is null ) 228 { 229 throw new TreeIterError("getParent", "Tree model not set"); 230 } 231 TreeIter parent = new TreeIter(); 232 bool gotParent = gtk_tree_model_iter_parent(gtkTreeModel, parent.getTreeIterStruct(), gtkTreeIter) == 0 ? false : true; 233 if ( !gotParent ) 234 { 235 return null; 236 } 237 parent.setModel(gtkTreeModel); 238 return parent; 239 } 240 241 /** */ 242 TreeIter getGrandParent() 243 { 244 if ( gtkTreeModel is null ) 245 { 246 throw new TreeIterError("getGrandParent", "Tree model not set"); 247 } 248 TreeIter grandParent = this; 249 TreeIter parent = grandParent.getParent(); 250 while ( parent !is null ) 251 { 252 grandParent = parent; 253 parent = grandParent.getParent(); 254 } 255 256 return grandParent; 257 } 258 259 /** A unique stamp to catch invalid iterators */ 260 public int stamp() 261 { 262 return gtkTreeIter.stamp; 263 } 264 265 /** Ditto */ 266 public void stamp(int stamp) 267 { 268 gtkTreeIter.stamp = stamp; 269 } 270 271 /** Model specific data */ 272 public void* userData() 273 { 274 return gtkTreeIter.userData; 275 } 276 277 /** Ditto */ 278 public void userData(void* data) 279 { 280 gtkTreeIter.userData = data; 281 } 282 283 /** Ditto */ 284 public void* userData2() 285 { 286 return gtkTreeIter.userData2; 287 } 288 289 /** Ditto */ 290 public void userData2(void* data) 291 { 292 gtkTreeIter.userData2 = data; 293 } 294 295 /** Ditto */ 296 public void* userData3() 297 { 298 return gtkTreeIter.userData3; 299 } 300 301 /** Ditto */ 302 public void userData3(void* data) 303 { 304 gtkTreeIter.userData3 = data; 305 } 306 307 /** 308 * setUserData and getUserData provide simple boxing 309 * around the userData field in the TreeIter struct. 310 * Throws: TreeIterError for unsupported types or a type mismatch. 311 * Example: 312 * --- 313 * Treeiter iter = new TreeIter(); 314 * 315 * iter.setUserData(20); 316 * int i = iter.getUserData!(int)(); 317 * --- 318 */ 319 public void setUserData(T)(T data) 320 { 321 Variant* var = new Variant(); 322 *var = data; 323 gtkTreeIter.userData = var; 324 } 325 326 /** Ditto */ 327 public void setUserData2(T)(T data) 328 { 329 Variant* var = new Variant(); 330 *var = data; 331 gtkTreeIter.userData2 = var; 332 } 333 334 /** Ditto */ 335 public void setUserData3(T)(T data) 336 { 337 Variant* var = new Variant(); 338 *var = data; 339 gtkTreeIter.userData3 = var; 340 } 341 342 /** Ditto */ 343 public T getUserData(T)() 344 { 345 Variant* var = cast(Variant*)gtkTreeIter.userData; 346 return var.get!T(); 347 } 348 349 /** Ditto */ 350 public T getUserData2(T)() 351 { 352 Variant* var = cast(Variant*)gtkTreeIter.userData2; 353 return var.get!T(); 354 } 355 356 /** Ditto */ 357 public T getUserData3(T)() 358 { 359 Variant* var = cast(Variant*)gtkTreeIter.userData3; 360 return var.get!T(); 361 } 362 363 /** 364 */ 365 366 /** */ 367 public static GType getType() 368 { 369 return gtk_tree_iter_get_type(); 370 } 371 }