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 as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * gtkD is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with gtkD; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 17 */ 18 19 module TestTreeView; 20 21 private import gtk.ScrolledWindow; 22 23 private import gtk.TreeView; 24 private import gtk.TreePath; 25 private import gtk.TreeViewColumn; 26 private import gtk.TreeIter; 27 private import gtk.TreeStore; 28 private import gtk.TreeModel; 29 //private import ddi.Pixbuf; 30 private import gtk.TreeSelection; 31 private import gtk.CellRendererText; 32 33 private import gtk.Image; 34 //private import ddi.Pixbuf; 35 36 private import gtk.TreeNode; 37 38 version(Tango) private import tango.io.Stdout; 39 version(Tango) private import tango.stdc.stdio; 40 else private import std.stdio; 41 42 43 /* Don't copy this bad example; inline RGB data is always a better 44 * idea than inline XPMs. 45 */ 46 47 static string[] book_closed_xpm = [ 48 "16 16 6 1", 49 " c None s None", 50 ". c black", 51 "X c red", 52 "o c yellow", 53 "O c #808080", 54 "# c white", 55 " ", 56 " .. ", 57 " ..XX. ", 58 " ..XXXXX. ", 59 " ..XXXXXXXX. ", 60 ".ooXXXXXXXXX. ", 61 "..ooXXXXXXXXX. ", 62 ".X.ooXXXXXXXXX. ", 63 ".XX.ooXXXXXX.. ", 64 " .XX.ooXXX..#O ", 65 " .XX.oo..##OO. ", 66 " .XX..##OO.. ", 67 " .X.#OO.. ", 68 " ..O.. ", 69 " .. ", 70 " " 71 ]; 72 73 /** 74 * This tests the GtkD tree widget 75 * \todo report bug to ng: nested class with same name of other class was not used<br> 76 * test if this works:<br> 77 * class A {}<br> 78 * class B { <br> 79 * class A{} <br> 80 * method (){ new A;}<br> 81 * }<br> 82 */ 83 class TestTreeView : ScrolledWindow 84 { 85 Image image; 86 //Pixbuf pixbuf; 87 88 enum columns 89 { 90 //gtkDObject = GtkDType.PIXBUF, 91 gtkDObject = GType.STRING, 92 gtkObject = GType.STRING, 93 desc = GType.STRING, 94 percentDone = GType.STRING, 95 author = GType.STRING 96 } 97 98 this() 99 { 100 super(null,null); 101 102 TreeView treeView = setup(); 103 addWithViewport(treeView); 104 105 treeView.addOnRowActivated(&rowActivatedCallback); 106 treeView.addOnMoveCursor(&moveCursorCallBack); 107 } 108 109 void rowActivatedCallback(TreePath path, TreeViewColumn column, TreeView treeView) 110 { 111 version(Tango) 112 { 113 Stdout("rowActivateCallback for {}",treeView).newline; 114 Stdout("rowActivateCallback for path {}",path.toString()).newline; 115 } 116 else 117 { 118 writefln("rowActivateCallback for %X",treeView); 119 writefln("rowActivateCallback for path %s",path.toString()); 120 } 121 } 122 123 bool moveCursorCallBack(GtkMovementStep step, int direction, TreeView treeView) 124 { 125 version(Tango) 126 { 127 Stdout("moveCursorCallBack for {}",treeView).newline; 128 Stdout("moveCursorCallBack row = {}",direction).newline; 129 } 130 else 131 { 132 writefln("moveCursorCallBack for %X",treeView); 133 writefln("moveCursorCallBack row = %d",direction); 134 } 135 return false; 136 } 137 138 TreeIter [12] h; 139 int stack = 0; 140 void push(TreeIter ti) 141 { 142 h[stack++]=ti; 143 } 144 TreeIter peek() 145 { 146 if ( stack == 0) 147 { 148 return null; 149 } 150 return h[stack-1]; 151 } 152 153 TreeIter pop() 154 { 155 if ( stack == 0) 156 { 157 return null; 158 } 159 return h[--stack]; 160 } 161 162 class HTreeNode : TreeNode 163 { 164 165 string gtkDL; 166 string gtk; 167 string desc; 168 int percent; 169 string author; 170 //TestTreeView ttv; 171 172 this(string gtkDL,string gtk,string desc,int percent)//, TestTreeView ttv) 173 { 174 this.gtkDL = gtkDL; 175 this.gtk = gtk; 176 this.desc = desc; 177 this.percent = percent; 178 this.author = "Ant"; 179 //this.ttv = ttv; 180 181 } 182 183 //Pixbuf getNodePixbuf(int colum) 184 //{ 185 // return pixbuf; 186 //} 187 188 int columnCount() 189 { 190 return 5; 191 } 192 193 string getNodeValue(int column) 194 { 195 string value; 196 switch (column) 197 { 198 //case 0: value = pixbuf; break; 199 case 0: value = gtkDL; break; 200 case 1: value = gtk; break; 201 case 2: value = desc; break; 202 case 3: 203 switch(percent) 204 { 205 case -1: value = "uggly: won't get in"; break; 206 case 0: value = "unknown"; break; 207 case 1: value = "not yet";break; 208 case 98: value = "Almost"; break; 209 case 99: value = "AGAIG"; break; 210 case 100: value = "Complete"; break; 211 default:value = "%"; break; 212 } 213 break; 214 215 case 4: value = author; break; 216 default: value = "N/A"; break; 217 } 218 return value; 219 } 220 } 221 222 TreeView setup() 223 { 224 225 class TTreeStore : TreeStore 226 { 227 this() 228 { 229 //this.nCols = nCols; 230 static GType [5] columns = [ 231 //GtkDType.PIXBUF, 232 GType.STRING, 233 GType.STRING, 234 GType.STRING, 235 GType.STRING, 236 GType.STRING]; 237 super(columns); 238 239 } 240 } 241 242 TTreeStore testTreeStore = new TTreeStore(); 243 TreeView treeView = new TreeView(testTreeStore); 244 treeView.setRulesHint(true); 245 246 TreeSelection ts = treeView.getSelection(); 247 ts.setMode(SelectionMode.MULTIPLE); 248 249 //TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererPixbuf(),"GdkPixbuf", 0); 250 TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererText(),"text", 0); 251 treeView.appendColumn(column); 252 column.setResizable(true); 253 column.setReorderable(true); 254 column.setSortColumnId(0); 255 column.setSortIndicator(true); 256 //pixbuf = new Pixbuf(book_closed_xpm); 257 //image = new Image(pixbuf); 258 //column.setWidget(image); 259 260 column = new TreeViewColumn("GtkObject",new CellRendererText(),"text", 1); 261 treeView.appendColumn(column); 262 column.setResizable(true); 263 column.setReorderable(true); 264 column.setSortColumnId(1); 265 column.setSortIndicator(true); 266 267 column = new TreeViewColumn("Desc",new CellRendererText(),"text", 2); 268 treeView.appendColumn(column); 269 column.setResizable(true); 270 column.setReorderable(true); 271 column.setSortColumnId(2); 272 column.setSortIndicator(true); 273 274 column = new TreeViewColumn("Complete",new CellRendererText(),"text", 3); 275 treeView.appendColumn(column); 276 column.setResizable(true); 277 column.setReorderable(true); 278 column.setSortColumnId(3); 279 column.setSortIndicator(true); 280 281 column = new TreeViewColumn("Author",new CellRendererText(),"text", 4); 282 treeView.appendColumn(column); 283 column.setResizable(true); 284 column.setReorderable(true); 285 column.setSortColumnId(4); 286 column.setSortIndicator(true); 287 288 TreeIter iter; 289 TreeIter iterTop = testTreeStore.createIter(null); 290 291 TreeIter peekIter(bool pushIt) 292 { 293 TreeIter iter = testTreeStore.append(peek()); 294 if ( pushIt ) 295 { 296 push(iter); 297 } 298 return iter; 299 } 300 301 TreeIter popIter(bool pushIt) 302 { 303 TreeIter iter = testTreeStore.append(pop()); 304 if ( pushIt ) 305 { 306 push(iter); 307 } 308 return iter; 309 } 310 311 push(iterTop); 312 testTreeStore.set(iterTop, new HTreeNode("ObjectG","GObject","Parent of the main GtkD objects",90)); 313 314 testTreeStore.set(peekIter(true), new HTreeNode("ObjectGtk","GtkObject","The main gtk object",100)); 315 testTreeStore.set(peekIter(true), new HTreeNode("Misc","GtkMisc","Comon for Most widgets",100)); 316 317 testTreeStore.set(peekIter(true), new HTreeNode("Label","GtkLabel","Display only widget",100)); 318 testTreeStore.set(popIter(false), new HTreeNode("AccelLabel","GtkAccelLabel","A label with a thing",1)); 319 testTreeStore.set(peekIter(false), new HTreeNode("Arrow","GtkArrow","A standard arrow",100)); 320 testTreeStore.set(popIter(false), new HTreeNode("Image","GtkImage","A image",100)); 321 testTreeStore.set(peekIter(true), new HTreeNode("Container","GtkContainer","Comon for all widgets that can contain other widgets",90)); 322 testTreeStore.set(peekIter(false), new HTreeNode("Bin","GtkBin","Comon for many widgets",90)); 323 324 testTreeStore.set(peekIter(false), new HTreeNode("Alignment","GtkAlignment","Aligns a widget in a larger area",100)); 325 testTreeStore.set(peekIter(true), new HTreeNode("Frame","GtkFrame","",100)); 326 testTreeStore.set(popIter(false), new HTreeNode("AspectFrame","GtkAspectFrame","",100)); 327 testTreeStore.set(peekIter(true), new HTreeNode("Button","GtkButton","",90)); 328 329 testTreeStore.set(peekIter(true), new HTreeNode("ToggleButton","GtkToggleButton","",0)); 330 testTreeStore.set(peekIter(false), new HTreeNode("CheckButton","GtkCheckButton","",0)); 331 testTreeStore.set(popIter(false), new HTreeNode("RadioButton","GtkRadioButton","",0)); 332 testTreeStore.set(popIter(false), new HTreeNode("OptionMenu","GtkOptionMenu","",0)); 333 testTreeStore.set(peekIter(true), new HTreeNode("Item","GtkItem","",0)); 334 testTreeStore.set(peekIter(true), new HTreeNode("MenuItem","GtkMenuItem","",0)); 335 testTreeStore.set(peekIter(true), new HTreeNode("CheckMenuItem","GtkCheckMenuItem","",0)); 336 testTreeStore.set(popIter(false), new HTreeNode("RadioMenuItem","GtkRadioMenuItem","",0)); 337 testTreeStore.set(peekIter(false), new HTreeNode("ImageMenuItem","GtkImageMenuItem","",0)); 338 testTreeStore.set(peekIter(false), new HTreeNode("SeparatorMenuItem","GtkSeparatorMenuItem","",0)); 339 testTreeStore.set(popIter(false), new HTreeNode("TearoffMenuItem","GtkTearoffMenuItem","",0)); 340 testTreeStore.set(peekIter(true), new HTreeNode("Window","GtkWindow","",0)); 341 testTreeStore.set(peekIter(true), new HTreeNode("Dialog","GtkDialog","",0)); 342 testTreeStore.set(peekIter(false), new HTreeNode("ColorSelectionDialog","GtkColorSelectionDialog","",0)); 343 testTreeStore.set(peekIter(false), new HTreeNode("FileSelection","GtkFileSelection","",0)); 344 testTreeStore.set(peekIter(false), new HTreeNode("FontSelectionDialog","GtkFontSelectionDialog","",0)); 345 testTreeStore.set(peekIter(false), new HTreeNode("InputDialog","GtkInputDialog","",0)); 346 testTreeStore.set(popIter(false), new HTreeNode("MessageDialog","GtkMessageDialog","",0)); 347 testTreeStore.set(popIter(false), new HTreeNode("Plug","GtkPlug","",0)); 348 testTreeStore.set(peekIter(false), new HTreeNode("EventBox","GtkEventBox","",0)); 349 testTreeStore.set(peekIter(false), new HTreeNode("HandleBox","GtkHandleBox","",0)); 350 testTreeStore.set(peekIter(false), new HTreeNode("ScrolledWindow","GtkScrolledWindow","",0)); 351 testTreeStore.set(popIter(false), new HTreeNode("Viewport","GtkViewport","",0)); 352 353 354 testTreeStore.set(peekIter(true), new HTreeNode("Box","GtkBox","",0)); 355 testTreeStore.set(peekIter(true), new HTreeNode("ButtonBox","GtkButtonBox","",0)); 356 testTreeStore.set(peekIter(false), new HTreeNode("HButtonBox","GtkHButtonBox","",0)); 357 testTreeStore.set(popIter(false), new HTreeNode("VButtonBox","GtkVButtonBox","",0)); 358 testTreeStore.set(peekIter(true), new HTreeNode("VBox","GtkVBox","",100)); 359 testTreeStore.set(peekIter(false), new HTreeNode("ColorSelection","GtkColorSelection","",100)); 360 testTreeStore.set(peekIter(false), new HTreeNode("FontSelection","GtkFontSelection","",100)); 361 testTreeStore.set(popIter(false), new HTreeNode("GammaCurve","GtkGammaCurve","",0)); 362 testTreeStore.set(popIter(true), new HTreeNode("HBox","GtkHBox","",100)); 363 testTreeStore.set(peekIter(false), new HTreeNode("Combo","GtkCombo","",0)); 364 testTreeStore.set(popIter(false), new HTreeNode("Statusbar","GtkStatusbar","",0)); 365 testTreeStore.set(peekIter(false), new HTreeNode("Fixed","GtkFixed","",0)); 366 testTreeStore.set(peekIter(true), new HTreeNode("Paned","GtkPaned","",0)); 367 testTreeStore.set(peekIter(false), new HTreeNode("HPaned","GtkHPaned","",0)); 368 testTreeStore.set(popIter(false), new HTreeNode("VPaned","GtkVPaned","",0)); 369 testTreeStore.set(peekIter(false), new HTreeNode("Layout","GtkLayout","",0)); 370 testTreeStore.set(peekIter(true), new HTreeNode("MenuShell","GtkMenuShell","",0)); 371 testTreeStore.set(peekIter(false), new HTreeNode("MenuBar","GtkMenuBar","",0)); 372 testTreeStore.set(popIter(false), new HTreeNode("Menu","GtkMenu","",0)); 373 testTreeStore.set(peekIter(false), new HTreeNode("Notebook","GtkNotebook","",0)); 374 testTreeStore.set(peekIter(false), new HTreeNode("Socket","GtkSocket","",0)); 375 testTreeStore.set(peekIter(false), new HTreeNode("Table","GtkTable","",0)); 376 testTreeStore.set(peekIter(false), new HTreeNode("TextView","GtkTextView","",0)); 377 testTreeStore.set(peekIter(false), new HTreeNode("Toolbar","GtkToolbar","",0)); 378 testTreeStore.set(popIter(false), new HTreeNode("TreeView","GtkTreeView","",0)); 379 testTreeStore.set(peekIter(false), new HTreeNode("Calendar","GtkCalendar","",0)); 380 381 testTreeStore.set(peekIter(true), new HTreeNode("DrawingArea","GtkDrawingArea","",0)); 382 testTreeStore.set(popIter(false), new HTreeNode("Curve","GtkCurve","",0)); 383 testTreeStore.set(peekIter(true), new HTreeNode("Editable","GtkEditable","",0)); 384 testTreeStore.set(peekIter(true), new HTreeNode("Entry","GtkEntry","",0)); 385 testTreeStore.set(popIter(false), new HTreeNode("SpinButton","GtkSpinButton","",0)); 386 pop(); 387 testTreeStore.set(peekIter(true), new HTreeNode("Ruler","GtkRuler","",0)); 388 testTreeStore.set(peekIter(false), new HTreeNode("HRuler","GtkHRuler","",0)); 389 testTreeStore.set(popIter(false), new HTreeNode("VRuler","GtkVRuler","",0)); 390 testTreeStore.set(peekIter(true), new HTreeNode("Range","GtkRange","",0)); 391 testTreeStore.set(peekIter(true), new HTreeNode("Scale","GtkScale","",0)); 392 testTreeStore.set(peekIter(true), new HTreeNode("HScale","GtkHScale","",0)); 393 testTreeStore.set(popIter(false), new HTreeNode("VScale","GtkVScale","",0)); 394 testTreeStore.set(popIter(true), new HTreeNode("Scrollbar","GtkScrollbar","",0)); 395 testTreeStore.set(peekIter(false), new HTreeNode("HScrollbar","GtkHScrollbar","",0)); 396 testTreeStore.set(popIter(false), new HTreeNode("VScrollbar","GtkVScrollbar","",0)); 397 pop(); 398 testTreeStore.set(peekIter(true), new HTreeNode("Separator","GtkSeparator","",0)); 399 testTreeStore.set(peekIter(false), new HTreeNode("HSeparator","GtkHSeparator","",0)); 400 testTreeStore.set(popIter(false), new HTreeNode("VSeparator","GtkVSeparator","",0)); 401 testTreeStore.set(peekIter(false), new HTreeNode("Invisible","GtkInvisible","",0)); 402 testTreeStore.set(peekIter(false), new HTreeNode("Preview","GtkPreview","",0)); 403 testTreeStore.set(popIter(false), new HTreeNode("ProgressBar","GtkProgressBar","",0)); 404 testTreeStore.set(peekIter(false), new HTreeNode("Adjustment","GtkAdjustment","Values for the range widget (scroolbars, spin buttons...)",0)); 405 testTreeStore.set(peekIter(true), new HTreeNode("CellRenderer","GtkCellRenderer","",0)); 406 testTreeStore.set(peekIter(false), new HTreeNode("CellRendererPixbuf","GtkCellRendererPixbuf","",0)); 407 testTreeStore.set(peekIter(false), new HTreeNode("CellRendererText","GtkCellRendererText","",0)); 408 testTreeStore.set(popIter(false), new HTreeNode("CellRendererToggle","GtkCellRendererToggle","",0)); 409 testTreeStore.set(peekIter(false), new HTreeNode("ItemFactory","GtkItemFactory","",1)); 410 testTreeStore.set(peekIter(false), new HTreeNode("Tooltips","GtkTooltips","",0)); 411 testTreeStore.set(popIter(false), new HTreeNode("TreeViewColumn","GtkTreeViewColumn","",0)); 412 push(iterTop); 413 testTreeStore.set(peekIter(false), new HTreeNode("ListG","GList","a double linked list used to comboBox and stuf",0)); 414 415 return treeView; 416 417 } 418 419 420 }