1 module DemoCostumList; 2 3 import CustomList; 4 5 import glib.RandG; 6 import gtk.Main; 7 import gtk.ScrolledWindow; 8 import gtk.MainWindow; 9 import gtk.TreeView; 10 import gtk.TreeViewColumn; 11 import gtk.CellRendererText; 12 import gtk.ListStore; 13 14 class CustomListWindow : MainWindow 15 { 16 this() 17 { 18 super("GtkD - Custom TreeModel"); 19 setDefaultSize(200, 400); 20 21 ScrolledWindow scrollwin = new ScrolledWindow(); 22 TreeView view = createViewAndModel(); 23 24 scrollwin.add(view); 25 add(scrollwin); 26 27 showAll(); 28 } 29 30 TreeView createViewAndModel() 31 { 32 TreeViewColumn col; 33 CellRendererText renderer; 34 CustomList customlist; 35 TreeView view; 36 37 customlist = new CustomList(); 38 fillModel(customlist); 39 40 view = new TreeView(customlist); 41 42 col = new TreeViewColumn(); 43 renderer = new CellRendererText(); 44 col.packStart(renderer, true); 45 col.addAttribute(renderer, "text", CustomListColumn.Name); 46 col.setTitle("Name"); 47 view.appendColumn(col); 48 49 col = new TreeViewColumn(); 50 renderer = new CellRendererText(); 51 col.packStart(renderer, true); 52 col.addAttribute(renderer, "text", CustomListColumn.YearBorn); 53 col.setTitle("Year Born"); 54 view.appendColumn(col); 55 56 return view; 57 } 58 59 void fillModel (CustomList customlist) 60 { 61 string[] firstnames = [ "Joe", "Jane", "William", "Hannibal", "Timothy", "Gargamel" ]; 62 string[] surnames = [ "Grokowich", "Twitch", "Borheimer", "Bork" ]; 63 64 foreach (sname; surnames) 65 { 66 foreach (fname; firstnames) 67 { 68 customlist.appendRecord(fname ~" "~ sname, 1900 + (RandG.randomInt() % 100)); 69 } 70 } 71 } 72 } 73 74 void main (string[] arg) 75 { 76 Main.init(arg); 77 78 new CustomListWindow(); 79 80 Main.run(); 81 }