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 printf("rowActivateCallback for %X \n",treeView); 112 printf("rowActivateCallback for path %.*s\n",path.toString()); 113 } 114 115 bool moveCursorCallBack(GtkMovementStep step, int direction, TreeView treeView) 116 { 117 printf("moveCursorCallBack for %X \n",treeView); 118 printf("moveCursorCallBack row = %d \n",direction); 119 return false; 120 } 121 122 TreeIter [12] h; 123 int stack = 0; 124 void push(TreeIter ti) 125 { 126 h[stack++]=ti; 127 } 128 TreeIter peek() 129 { 130 if ( stack == 0) 131 { 132 return null; 133 } 134 return h[stack-1]; 135 } 136 137 TreeIter pop() 138 { 139 if ( stack == 0) 140 { 141 return null; 142 } 143 return h[--stack]; 144 } 145 146 class HTreeNode : TreeNode 147 { 148 149 string gtkDL; 150 string gtk; 151 string desc; 152 int percent; 153 string author; 154 //TestTreeView ttv; 155 156 this(string gtkDL,string gtk,string desc,int percent)//, TestTreeView ttv) 157 { 158 this.gtkDL = gtkDL; 159 this.gtk = gtk; 160 this.desc = desc; 161 this.percent = percent; 162 this.author = "Ant"; 163 //this.ttv = ttv; 164 165 } 166 167 //Pixbuf getNodePixbuf(int colum) 168 //{ 169 // return pixbuf; 170 //} 171 172 int columnCount() 173 { 174 return 5; 175 } 176 177 string getNodeValue(int column) 178 { 179 string value; 180 switch (column) 181 { 182 //case 0: value = pixbuf; break; 183 case 0: value = gtkDL; break; 184 case 1: value = gtk; break; 185 case 2: value = desc; break; 186 case 3: 187 switch(percent) 188 { 189 case -1: value = "uggly: won't get in"; break; 190 case 0: value = "unknown"; break; 191 case 1: value = "not yet";break; 192 case 98: value = "Almost"; break; 193 case 99: value = "AGAIG"; break; 194 case 100: value = "Complete"; break; 195 default:value = "%"; break; 196 } 197 break; 198 199 case 4: value = author; break; 200 default: value = "N/A"; break; 201 } 202 return value; 203 } 204 } 205 206 TreeView setup() 207 { 208 209 class TTreeStore : TreeStore 210 { 211 this() 212 { 213 //this.nCols = nCols; 214 static GType [5] columns = [ 215 //GtkDType.PIXBUF, 216 GType.STRING, 217 GType.STRING, 218 GType.STRING, 219 GType.STRING, 220 GType.STRING]; 221 super(columns); 222 223 } 224 } 225 226 TTreeStore testTreeStore = new TTreeStore(); 227 TreeView treeView = new TreeView(testTreeStore); 228 treeView.setRulesHint(true); 229 230 TreeSelection ts = treeView.getSelection(); 231 ts.setMode(SelectionMode.MULTIPLE); 232 233 //TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererPixbuf(),"GdkPixbuf", 0); 234 TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererText(),"text", 0); 235 treeView.appendColumn(column); 236 column.setResizable(true); 237 column.setReorderable(true); 238 column.setSortColumnId(0); 239 column.setSortIndicator(true); 240 //pixbuf = new Pixbuf(book_closed_xpm); 241 //image = new Image(pixbuf); 242 //column.setWidget(image); 243 244 column = new TreeViewColumn("GtkObject",new CellRendererText(),"text", 1); 245 treeView.appendColumn(column); 246 column.setResizable(true); 247 column.setReorderable(true); 248 column.setSortColumnId(1); 249 column.setSortIndicator(true); 250 251 column = new TreeViewColumn("Desc",new CellRendererText(),"text", 2); 252 treeView.appendColumn(column); 253 column.setResizable(true); 254 column.setReorderable(true); 255 column.setSortColumnId(2); 256 column.setSortIndicator(true); 257 258 column = new TreeViewColumn("Complete",new CellRendererText(),"text", 3); 259 treeView.appendColumn(column); 260 column.setResizable(true); 261 column.setReorderable(true); 262 column.setSortColumnId(3); 263 column.setSortIndicator(true); 264 265 column = new TreeViewColumn("Author",new CellRendererText(),"text", 4); 266 treeView.appendColumn(column); 267 column.setResizable(true); 268 column.setReorderable(true); 269 column.setSortColumnId(4); 270 column.setSortIndicator(true); 271 272 TreeIter iter; 273 TreeIter iterTop = testTreeStore.createIter(null); 274 275 TreeIter peekIter(bool pushIt) 276 { 277 TreeIter iter = testTreeStore.append(peek()); 278 if ( pushIt ) 279 { 280 push(iter); 281 } 282 return iter; 283 } 284 285 TreeIter popIter(bool pushIt) 286 { 287 TreeIter iter = testTreeStore.append(pop()); 288 if ( pushIt ) 289 { 290 push(iter); 291 } 292 return iter; 293 } 294 295 push(iterTop); 296 testTreeStore.set(iterTop, new HTreeNode("ObjectG","GObject","Parent of the main GtkD objects",90)); 297 298 testTreeStore.set(peekIter(true), new HTreeNode("ObjectGtk","GtkObject","The main gtk object",100)); 299 testTreeStore.set(peekIter(true), new HTreeNode("Misc","GtkMisc","Comon for Most widgets",100)); 300 301 testTreeStore.set(peekIter(true), new HTreeNode("Label","GtkLabel","Display only widget",100)); 302 testTreeStore.set(popIter(false), new HTreeNode("AccelLabel","GtkAccelLabel","A label with a thing",1)); 303 testTreeStore.set(peekIter(false), new HTreeNode("Arrow","GtkArrow","A standard arrow",100)); 304 testTreeStore.set(popIter(false), new HTreeNode("Image","GtkImage","A image",100)); 305 testTreeStore.set(peekIter(true), new HTreeNode("Container","GtkContainer","Comon for all widgets that can contain other widgets",90)); 306 testTreeStore.set(peekIter(false), new HTreeNode("Bin","GtkBin","Comon for many widgets",90)); 307 308 testTreeStore.set(peekIter(false), new HTreeNode("Alignment","GtkAlignment","Aligns a widget in a larger area",100)); 309 testTreeStore.set(peekIter(true), new HTreeNode("Frame","GtkFrame","",100)); 310 testTreeStore.set(popIter(false), new HTreeNode("AspectFrame","GtkAspectFrame","",100)); 311 testTreeStore.set(peekIter(true), new HTreeNode("Button","GtkButton","",90)); 312 313 testTreeStore.set(peekIter(true), new HTreeNode("ToggleButton","GtkToggleButton","",0)); 314 testTreeStore.set(peekIter(false), new HTreeNode("CheckButton","GtkCheckButton","",0)); 315 testTreeStore.set(popIter(false), new HTreeNode("RadioButton","GtkRadioButton","",0)); 316 testTreeStore.set(popIter(false), new HTreeNode("OptionMenu","GtkOptionMenu","",0)); 317 testTreeStore.set(peekIter(true), new HTreeNode("Item","GtkItem","",0)); 318 testTreeStore.set(peekIter(true), new HTreeNode("MenuItem","GtkMenuItem","",0)); 319 testTreeStore.set(peekIter(true), new HTreeNode("CheckMenuItem","GtkCheckMenuItem","",0)); 320 testTreeStore.set(popIter(false), new HTreeNode("RadioMenuItem","GtkRadioMenuItem","",0)); 321 testTreeStore.set(peekIter(false), new HTreeNode("ImageMenuItem","GtkImageMenuItem","",0)); 322 testTreeStore.set(peekIter(false), new HTreeNode("SeparatorMenuItem","GtkSeparatorMenuItem","",0)); 323 testTreeStore.set(popIter(false), new HTreeNode("TearoffMenuItem","GtkTearoffMenuItem","",0)); 324 testTreeStore.set(peekIter(true), new HTreeNode("Window","GtkWindow","",0)); 325 testTreeStore.set(peekIter(true), new HTreeNode("Dialog","GtkDialog","",0)); 326 testTreeStore.set(peekIter(false), new HTreeNode("ColorSelectionDialog","GtkColorSelectionDialog","",0)); 327 testTreeStore.set(peekIter(false), new HTreeNode("FileSelection","GtkFileSelection","",0)); 328 testTreeStore.set(peekIter(false), new HTreeNode("FontSelectionDialog","GtkFontSelectionDialog","",0)); 329 testTreeStore.set(peekIter(false), new HTreeNode("InputDialog","GtkInputDialog","",0)); 330 testTreeStore.set(popIter(false), new HTreeNode("MessageDialog","GtkMessageDialog","",0)); 331 testTreeStore.set(popIter(false), new HTreeNode("Plug","GtkPlug","",0)); 332 testTreeStore.set(peekIter(false), new HTreeNode("EventBox","GtkEventBox","",0)); 333 testTreeStore.set(peekIter(false), new HTreeNode("HandleBox","GtkHandleBox","",0)); 334 testTreeStore.set(peekIter(false), new HTreeNode("ScrolledWindow","GtkScrolledWindow","",0)); 335 testTreeStore.set(popIter(false), new HTreeNode("Viewport","GtkViewport","",0)); 336 337 338 testTreeStore.set(peekIter(true), new HTreeNode("Box","GtkBox","",0)); 339 testTreeStore.set(peekIter(true), new HTreeNode("ButtonBox","GtkButtonBox","",0)); 340 testTreeStore.set(peekIter(false), new HTreeNode("HButtonBox","GtkHButtonBox","",0)); 341 testTreeStore.set(popIter(false), new HTreeNode("VButtonBox","GtkVButtonBox","",0)); 342 testTreeStore.set(peekIter(true), new HTreeNode("VBox","GtkVBox","",100)); 343 testTreeStore.set(peekIter(false), new HTreeNode("ColorSelection","GtkColorSelection","",100)); 344 testTreeStore.set(peekIter(false), new HTreeNode("FontSelection","GtkFontSelection","",100)); 345 testTreeStore.set(popIter(false), new HTreeNode("GammaCurve","GtkGammaCurve","",0)); 346 testTreeStore.set(popIter(true), new HTreeNode("HBox","GtkHBox","",100)); 347 testTreeStore.set(peekIter(false), new HTreeNode("Combo","GtkCombo","",0)); 348 testTreeStore.set(popIter(false), new HTreeNode("Statusbar","GtkStatusbar","",0)); 349 testTreeStore.set(peekIter(false), new HTreeNode("Fixed","GtkFixed","",0)); 350 testTreeStore.set(peekIter(true), new HTreeNode("Paned","GtkPaned","",0)); 351 testTreeStore.set(peekIter(false), new HTreeNode("HPaned","GtkHPaned","",0)); 352 testTreeStore.set(popIter(false), new HTreeNode("VPaned","GtkVPaned","",0)); 353 testTreeStore.set(peekIter(false), new HTreeNode("Layout","GtkLayout","",0)); 354 testTreeStore.set(peekIter(true), new HTreeNode("MenuShell","GtkMenuShell","",0)); 355 testTreeStore.set(peekIter(false), new HTreeNode("MenuBar","GtkMenuBar","",0)); 356 testTreeStore.set(popIter(false), new HTreeNode("Menu","GtkMenu","",0)); 357 testTreeStore.set(peekIter(false), new HTreeNode("Notebook","GtkNotebook","",0)); 358 testTreeStore.set(peekIter(false), new HTreeNode("Socket","GtkSocket","",0)); 359 testTreeStore.set(peekIter(false), new HTreeNode("Table","GtkTable","",0)); 360 testTreeStore.set(peekIter(false), new HTreeNode("TextView","GtkTextView","",0)); 361 testTreeStore.set(peekIter(false), new HTreeNode("Toolbar","GtkToolbar","",0)); 362 testTreeStore.set(popIter(false), new HTreeNode("TreeView","GtkTreeView","",0)); 363 testTreeStore.set(peekIter(false), new HTreeNode("Calendar","GtkCalendar","",0)); 364 365 testTreeStore.set(peekIter(true), new HTreeNode("DrawingArea","GtkDrawingArea","",0)); 366 testTreeStore.set(popIter(false), new HTreeNode("Curve","GtkCurve","",0)); 367 testTreeStore.set(peekIter(true), new HTreeNode("Editable","GtkEditable","",0)); 368 testTreeStore.set(peekIter(true), new HTreeNode("Entry","GtkEntry","",0)); 369 testTreeStore.set(popIter(false), new HTreeNode("SpinButton","GtkSpinButton","",0)); 370 pop(); 371 testTreeStore.set(peekIter(true), new HTreeNode("Ruler","GtkRuler","",0)); 372 testTreeStore.set(peekIter(false), new HTreeNode("HRuler","GtkHRuler","",0)); 373 testTreeStore.set(popIter(false), new HTreeNode("VRuler","GtkVRuler","",0)); 374 testTreeStore.set(peekIter(true), new HTreeNode("Range","GtkRange","",0)); 375 testTreeStore.set(peekIter(true), new HTreeNode("Scale","GtkScale","",0)); 376 testTreeStore.set(peekIter(true), new HTreeNode("HScale","GtkHScale","",0)); 377 testTreeStore.set(popIter(false), new HTreeNode("VScale","GtkVScale","",0)); 378 testTreeStore.set(popIter(true), new HTreeNode("Scrollbar","GtkScrollbar","",0)); 379 testTreeStore.set(peekIter(false), new HTreeNode("HScrollbar","GtkHScrollbar","",0)); 380 testTreeStore.set(popIter(false), new HTreeNode("VScrollbar","GtkVScrollbar","",0)); 381 pop(); 382 testTreeStore.set(peekIter(true), new HTreeNode("Separator","GtkSeparator","",0)); 383 testTreeStore.set(peekIter(false), new HTreeNode("HSeparator","GtkHSeparator","",0)); 384 testTreeStore.set(popIter(false), new HTreeNode("VSeparator","GtkVSeparator","",0)); 385 testTreeStore.set(peekIter(false), new HTreeNode("Invisible","GtkInvisible","",0)); 386 testTreeStore.set(peekIter(false), new HTreeNode("Preview","GtkPreview","",0)); 387 testTreeStore.set(popIter(false), new HTreeNode("ProgressBar","GtkProgressBar","",0)); 388 testTreeStore.set(peekIter(false), new HTreeNode("Adjustment","GtkAdjustment","Values for the range widget (scroolbars, spin buttons...)",0)); 389 testTreeStore.set(peekIter(true), new HTreeNode("CellRenderer","GtkCellRenderer","",0)); 390 testTreeStore.set(peekIter(false), new HTreeNode("CellRendererPixbuf","GtkCellRendererPixbuf","",0)); 391 testTreeStore.set(peekIter(false), new HTreeNode("CellRendererText","GtkCellRendererText","",0)); 392 testTreeStore.set(popIter(false), new HTreeNode("CellRendererToggle","GtkCellRendererToggle","",0)); 393 testTreeStore.set(peekIter(false), new HTreeNode("ItemFactory","GtkItemFactory","",1)); 394 testTreeStore.set(peekIter(false), new HTreeNode("Tooltips","GtkTooltips","",0)); 395 testTreeStore.set(popIter(false), new HTreeNode("TreeViewColumn","GtkTreeViewColumn","",0)); 396 push(iterTop); 397 testTreeStore.set(peekIter(false), new HTreeNode("ListG","GList","a double linked list used to comboBox and stuf",0)); 398 399 return treeView; 400 401 } 402 403 404 }