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 TestTreeView1; 20 21 //debug = trace; 22 23 private import gtk.VBox; 24 25 private import gobject.Value; 26 27 private import gtk.Image; 28 private import gtk.TreeView; 29 private import gtk.TreeStore; 30 private import gtk.TreePath; 31 private import gtk.TreeViewColumn; 32 private import gtk.TreeIter; 33 private import gtk.TreeSelection; 34 private import gtk.CellRendererPixbuf; 35 private import gtk.CellRendererText; 36 private import gtk.ScrolledWindow; 37 private import gdk.Pixbuf; 38 private import glib.Str; 39 private import std.stdio; 40 41 /** 42 * This tests the gtkD tree widget 43 */ 44 public class TestTreeView1 : VBox 45 { 46 // enum columns 47 // { 48 // gtkDObject = pixbufGetType(), 49 // desc = gtkDType.STRING, 50 // } 51 52 Image image; 53 Pixbuf pixbuf; 54 Pixbuf pixbufTest; 55 56 TreeStore testTreeStore1; 57 TreeStore testTreeStore2; 58 59 this() 60 { 61 62 debug(trace) writeln("TestTreeView1.this 1"); 63 super(false, 0); 64 debug(trace) writeln("TestTreeView1.this 2"); 65 66 pixbuf = new Pixbuf(greenClass_xpm); 67 debug(trace) writeln("TestTreeView1.this 2.1"); 68 pixbufTest = new Pixbuf(book_closed_xpm); 69 debug(trace) writeln("TestTreeView1.this 2.2"); 70 image = new Image(pixbufTest); 71 72 debug(trace) writeln("TestTreeView1.this 3"); 73 TreeView treeView1 = setup1(); 74 populate(testTreeStore1); 75 76 debug(trace) writeln("TestTreeView1.this 4"); 77 TreeView treeView2 = setup2(); 78 populate(testTreeStore2); 79 80 debug(trace) writeln("TestTreeView1.this 5"); 81 treeView2.addOnMoveCursor(&moveCursorCallback); 82 packStart(image, false, false, 1); 83 ScrolledWindow sw = new ScrolledWindow(null, null); 84 sw.add(treeView1); 85 packStart(sw, true, true, 1); 86 sw = new ScrolledWindow(null, null); 87 sw.add(treeView2); 88 packStart(sw, true, true, 1); 89 90 debug(trace) writeln("TestTreeView1.this 6"); 91 //addWithViewport(treeView); 92 93 94 95 } 96 97 bool moveCursorCallback(GtkMovementStep step, int i, TreeView tree) 98 { 99 TreeIter iter = tree.getSelectedIter(); 100 iter.setModel(tree.getModel()); 101 Value v = new Value(); 102 iter.getValue(1, v); 103 debug(trace) writefln("cursor on %s", v); 104 return false; 105 } 106 107 108 109 void populate(TreeStore treeStore) 110 { 111 TreeIter iterChild; 112 TreeIter iterTop = treeStore.createIter(); 113 treeStore.setValue(iterTop, 0, new Pixbuf(package_xpm) ); 114 treeStore.setValue(iterTop, 1, "Icon for packages" ); 115 116 iterChild = treeStore.append(iterTop); 117 treeStore.setValue(iterChild, 0,new Pixbuf(greenTemplate_xpm) ); 118 treeStore.setValue(iterChild, 1, "Icon for templates" ); 119 120 iterChild = treeStore.append(iterTop); 121 treeStore.setValue(iterChild, 0, new Pixbuf(greenInterface_xpm) ); 122 treeStore.setValue(iterChild, 1, "Icon for interfaces" ); 123 124 iterChild = treeStore.append(iterTop); 125 treeStore.setValue(iterChild, 0, new Pixbuf(greenClass_xpm) ); 126 treeStore.setValue(iterChild, 1, "Icon for classes" ); 127 128 } 129 130 /** 131 * Creates the treeView and treeStore 132 * @return 133 */ 134 TreeView setup1() 135 { 136 class TTreeStore : TreeStore 137 { 138 this() 139 { 140 //int* i = cast(int*)pixbufGetType(); 141 142 GType[] columns; 143 columns ~= Pixbuf.getType(); 144 columns ~= GType.STRING; 145 super(columns); 146 147 } 148 } 149 150 testTreeStore1 = new TTreeStore(); 151 TreeView treeView = new TreeView(testTreeStore1); 152 treeView.setRulesHint(true); 153 154 TreeSelection ts = treeView.getSelection(); 155 ts.setMode(SelectionMode.MULTIPLE); 156 TreeViewColumn column; 157 int col = 0; 158 column = new TreeViewColumn("Icon",new CellRendererPixbuf(),"pixbuf", col); 159 treeView.appendColumn(column); 160 ++col; 161 162 column = new TreeViewColumn("Description",new CellRendererText(),"text", col); 163 treeView.appendColumn(column); 164 column.setResizable(true); 165 column.setReorderable(true); 166 column.setSortColumnId(col); 167 column.setSortIndicator(true); 168 ++col; 169 170 return treeView; 171 172 } 173 174 /** 175 * Creates the treeView and treeStore 176 * @return 177 */ 178 TreeView setup2() 179 { 180 class TTreeStore : TreeStore 181 { 182 this() 183 { 184 //int* i = cast(int*)pixbufGetType(); 185 186 GType[] columns; 187 columns ~= Pixbuf.getType(); 188 columns ~= GType.STRING; 189 super(columns); 190 191 } 192 } 193 194 testTreeStore2 = new TTreeStore(); 195 TreeView treeView = new TreeView(testTreeStore2); 196 treeView.setRulesHint(true); 197 198 TreeSelection ts = treeView.getSelection(); 199 ts.setMode(SelectionMode.MULTIPLE); 200 TreeViewColumn column; 201 int col = 0; 202 203 column = new TreeViewColumn(); 204 205 CellRendererPixbuf cellPixbuf = new CellRendererPixbuf(); 206 CellRendererText cellText = new CellRendererText(); 207 208 column.packStart(cellPixbuf, false); 209 column.addAttribute(cellPixbuf, "pixbuf", col); 210 ++col; 211 212 column.packEnd(cellText, true); 213 column.addAttribute(cellText, "text", col); 214 215 column.setTitle("Types"); 216 217 treeView.appendColumn(column); 218 219 column.setResizable(true); 220 column.setReorderable(true); 221 column.setSortColumnId(col); 222 column.setSortIndicator(true); 223 ++col; 224 225 return treeView; 226 227 } 228 229 230 void rowActivatedCallback(TreeView treeView, TreePath path, TreeViewColumn column) 231 { 232 writefln("rowActivateCallback for %X",treeView); 233 writefln("rowActivateCallback for path %s",path.toString()); 234 } 235 236 237 /* XPM */ 238 static string[] greenClass_xpm = [ 239 "16 16 67 1", 240 " c None", 241 ". c #00CF2E", 242 "+ c #005D14", 243 "@ c #005A16", 244 "# c #005217", 245 "$ c #004B15", 246 "% c #004413", 247 "& c #00BC23", 248 "* c #00BB23", 249 "= c #006A14", 250 "- c #000000", 251 "; c #00B721", 252 "> c #00BF25", 253 ", c #006F17", 254 "' c #00821C", 255 ") c #00801A", 256 "! c #007B17", 257 "~ c #00C126", 258 "{ c #FFFFFF", 259 "] c #00761A", 260 "^ c #008B21", 261 "/ c #00821B", 262 "( c #007316", 263 "_ c #00BA22", 264 ": c #A9EBB6", 265 "< c #007B1D", 266 "[ c #009426", 267 "} c #A9F5BC", 268 "| c #A9F2BA", 269 "1 c #00BA23", 270 "2 c #00D935", 271 "3 c #00BE25", 272 "4 c #A9EDB7", 273 "5 c #007F1F", 274 "6 c #009C2A", 275 "7 c #00ED3E", 276 "8 c #00E339", 277 "9 c #A9F1B9", 278 "0 c #00CB2C", 279 "a c #00BE24", 280 "b c #00C729", 281 "c c #00BF26", 282 "d c #008120", 283 "e c #00A52E", 284 "f c #00F241", 285 "g c #00E53A", 286 "h c #00D933", 287 "i c #00841D", 288 "j c #007B18", 289 "k c #007F20", 290 "l c #009928", 291 "m c #009224", 292 "n c #008B20", 293 "o c #A9EFB8", 294 "p c #00801F", 295 "q c #00BC24", 296 "r c #00C82A", 297 "s c #007A1C", 298 "t c #00791C", 299 "u c #007117", 300 "v c #006B14", 301 "w c #00B822", 302 "x c #00C629", 303 "y c #A9E9B5", 304 "z c #A9E7B4", 305 "A c #00C127", 306 "B c #00CF2C", 307 " ", 308 " .+@#$% ", 309 " &*=----- ", 310 " ;>,--')!-- ", 311 " ~>{]-^{{/!( ", 312 " _:{<-[}|{{1 ", 313 " 234{5-67890a2 ", 314 " bc4{d-efghij. ", 315 " 234{k--lmn--2 ", 316 " 1:o{p-----_ ", 317 " q>ro{st]uv& ", 318 " w>x4{{{{; ", 319 " ~13yyzA ", 320 " Bbh ", 321 " ", 322 " "]; 323 324 325 /* XPM */ 326 static string[] greenInterface_xpm = [ 327 "16 16 62 1", 328 " c None", 329 ". c #00CF2E", 330 "+ c #008A1E", 331 "@ c #009023", 332 "# c #00BC23", 333 "$ c #00BB23", 334 "% c #FFFFFF", 335 "& c #007F18", 336 "* c #000000", 337 "= c #00B721", 338 "- c #00BF25", 339 "; c #AAECB7", 340 "> c #00881D", 341 ", c #00861D", 342 "' c #007A16", 343 ") c #00C126", 344 "! c #00C82A", 345 "~ c #AAEFB9", 346 "{ c #008F21", 347 "] c #00861C", 348 "^ c #00BA22", 349 "/ c #00C629", 350 "( c #00D12F", 351 "_ c #AAF3BB", 352 ": c #AAF5BC", 353 "< c #009726", 354 "[ c #008B1F", 355 "} c #00C529", 356 "| c #00BA23", 357 "1 c #00D935", 358 "2 c #00BE25", 359 "3 c #00CA2C", 360 "4 c #00D732", 361 "5 c #00E238", 362 "6 c #AAF8BF", 363 "7 c #009E29", 364 "8 c #00CB2C", 365 "9 c #00BE24", 366 "0 c #00C729", 367 "a c #00BF26", 368 "b c #00CC2C", 369 "c c #00D933", 370 "d c #00E53A", 371 "e c #AAFABF", 372 "f c #00A12B", 373 "g c #009022", 374 "h c #00CC2D", 375 "i c #00CA2B", 376 "j c #00D632", 377 "k c #00E239", 378 "l c #AAF9BE", 379 "m c #009E2A", 380 "n c #00BD25", 381 "o c #009927", 382 "p c #009626", 383 "q c #008A1F", 384 "r c #00841A", 385 "s c #00BC24", 386 "t c #00B822", 387 "u c #00841B", 388 "v c #AAE8B5", 389 "w c #00CF2C", 390 " ", 391 " .+@ ", 392 " #$%&*** ", 393 " =-;%>,*&' ", 394 " )-!~%%{*]-) ", 395 " ^/(_:%<*[}| ", 396 " 123456%7*{891 ", 397 " 0abcde%f*gha. ", 398 " 12ijkl%m*{in1 ", 399 " |/(_%op*qr^ ", 400 " s-!~%g***&# ", 401 " t-;%>,u&' ", 402 " )v%%%%% ", 403 " w0c ", 404 " ", 405 " "]; 406 407 408 /* XPM */ 409 static string[] greenTemplate_xpm = [ 410 "16 16 63 1", 411 " c None", 412 ". c #008A1E", 413 "+ c #009023", 414 "@ c #007D17", 415 "# c #000000", 416 "$ c #FFFFFF", 417 "% c #007F18", 418 "& c #003B0C", 419 "* c #003C0C", 420 "= c #00380A", 421 "- c #003609", 422 "; c #A9EAB5", 423 "> c #00851C", 424 ", c #008F21", 425 "' c #00861C", 426 ") c #A9E7B4", 427 "! c #A9F5BB", 428 "~ c #009726", 429 "{ c #008B1F", 430 "] c #A9EBB6", 431 "^ c #00D935", 432 "/ c #A9E9B5", 433 "( c #A9EDB7", 434 "_ c #A9F1B9", 435 ": c #00EC3F", 436 "< c #009E29", 437 "[ c #00CB2C", 438 "} c #00BE24", 439 "| c #00C729", 440 "1 c #00BF26", 441 "2 c #00CC2C", 442 "3 c #00D933", 443 "4 c #00E53A", 444 "5 c #A9FABE", 445 "6 c #00A12B", 446 "7 c #009022", 447 "8 c #00CC2D", 448 "9 c #00CF2E", 449 "0 c #00BE25", 450 "a c #00CA2B", 451 "b c #00D632", 452 "c c #00E239", 453 "d c #A9F8BD", 454 "e c #009E2A", 455 "f c #00BD25", 456 "g c #00BA23", 457 "h c #00C629", 458 "i c #00D12F", 459 "j c #00DB34", 460 "k c #009626", 461 "l c #008A1F", 462 "m c #00C628", 463 "n c #00BA22", 464 "o c #00BC24", 465 "p c #00BF25", 466 "q c #00C82A", 467 "r c #00BC23", 468 "s c #00B822", 469 "t c #00841B", 470 "u c #00B721", 471 "v c #00C126", 472 "w c #00C127", 473 "x c #00CF2C", 474 " ", 475 " ..+ ", 476 " @######### ", 477 " $%#&*&#=-## ", 478 " ;$>#$$,#'$$# ", 479 " )$$$!$~#{]) ", 480 " ^/(_!:$<#,[}^ ", 481 " |12345$6#7819 ", 482 " ^0abcd$e#,af^ ", 483 " ghij!$k#lmn ", 484 " opqi_$,#'pr ", 485 " sph(($tpu ", 486 " vg0//gw ", 487 " x|3 ", 488 " ", 489 " "]; 490 491 /* XPM */ 492 static string[] package_xpm = [ 493 "16 16 25 1", 494 " c None", 495 ". c #713C17", 496 "+ c #BF8231", 497 "@ c #C17A2D", 498 "# c #93551F", 499 "$ c #C1772B", 500 "% c #DBBF9E", 501 "& c #E5C9A1", 502 "* c #CEAB8B", 503 "= c #9E7058", 504 "- c #BF752A", 505 "; c #F9F1BB", 506 "> c #EDD1A6", 507 ", c #D7B897", 508 "' c #BB712A", 509 ") c #D7B998", 510 "! c #B76D28", 511 "~ c #C7A082", 512 "{ c #794F40", 513 "] c #AE6325", 514 "^ c #A96023", 515 "/ c #A55C22", 516 "( c #A25922", 517 "_ c #C58332", 518 ": c #A05921", 519 " ", 520 " . ", 521 " +@@@@#@@@@+ ", 522 " $%&&*=%&&*$ ", 523 " -&;>,=&;>,- ", 524 " '&>>)=&>>)' ", 525 " !*,)~{*,)~! ", 526 " .#==={{{===#. ", 527 " ]%&&*{%&&*] ", 528 " ^&;>,=&;>,^ ", 529 " /&>>)=&>>)/ ", 530 " (*,)~=*,)~( ", 531 " _::::#::::_ ", 532 " . ", 533 " ", 534 " "]; 535 536 /* Don't copy this bad example; inline RGB data is always a better 537 * idea than inline XPMs. 538 */ 539 static string[] book_closed_xpm = [ 540 "16 16 7 1", 541 " c None s None", 542 ". c black", 543 "X c red", 544 "B c blue", 545 "o c yellow", 546 "O c #808080", 547 "# c white", 548 " ", 549 " .. ", 550 " ..XB. ", 551 " ..XXXXB. ", 552 " ..XXXXXXXB. ", 553 ".ooXXBBBBBXB. ", 554 "..ooXBBBBBBXB. ", 555 ".X.ooXBBBBBBXB. ", 556 ".XX.ooXBBBXX.. ", 557 " .XX.ooXBX..#O ", 558 " .XX.oo..##OO. ", 559 " .XX..##OO.. ", 560 " .X.#OO.. ", 561 " ..O.. ", 562 " .. ", 563 " " 564 ]; 565 566 567 } 568 569 570