sync
[app.Builder.js] / XObjectBase / GtkListStore.js
1
2 //<Script type="Text/javascript">
3
4 XObject = imports.XObject.XObject
5  
6 GObject = imports.gi.GObject;
7 //GtkClutter.Embed..
8 Gtk= imports.gi.Gtk;
9
10 // children are not added at init / but at show stage..
11 // listener is added on show..
12 // we should really add a hock to destroy it..
13 GtkListStore = XObject.define(
14     function(cfg) {
15         XObject.call(this, cfg);
16         // this is an example...
17        
18     }, 
19     XObject,
20     {
21         pack : 'set_model',
22         init : function() 
23         {
24             XObject.prototype.init.call(this);
25             this.el.set_column_types ( 6, [
26                 GObject.TYPE_STRING, 
27                 GObject.TYPE_STRING, 
28                 GObject.TYPE_STRING, 
29                 GObject.TYPE_STRING, 
30                 GObject.TYPE_STRING, 
31                 GObject.TYPE_STRING 
32             ] );
33             
34         },
35         append : function( values ) {
36             var iter = new Gtk.TreeIter();
37             this.el.append(iter);
38             for (var i = 0; i < values.length; i++) {
39                 this.el.set_value(iter,i,values[i]);
40             }
41             
42         },
43         nextPath : function(path)
44         {
45             if (path === false) {
46                 var iter = new Gtk.TreeIter();
47                 this.el.get_iter_first(iter);
48                 return this.el.get_path(iter);    
49             }
50             var tpath = path;
51             if (typeof(path) == 'string' ) {
52                 tpath = new Gtk.TreePath.from_string(path);     
53             }
54             var iter = new Gtk.TreeIter();
55             
56             this.el.get_iter (iter, tpath) ;
57             
58             if (!this.el.iter_next(iter)) {
59                 return false;
60             };
61             return this.el.get_path(iter);
62         },
63         
64         getValue  : function ( path, col)
65         {
66             // not very type safe...
67             var tpath = path;
68             if (typeof(path) == 'string' ) {
69                 tpath = new Gtk.TreePath.from_string(path);
70                  
71             }
72             
73             var iter = new Gtk.TreeIter();
74             
75             this.el.get_iter (iter, tpath) ;
76              
77             var gval = new GObject.Value(  [this.el.get_column_type(col), null ]);
78             this.el.get_value( iter, col, gval);
79             print("GET VALUE RETURNED: " + gval.value);
80             return gval.value;
81         },
82         setValue  : function ( path, col, val)
83         {
84             var tpath = path;
85             if (typeof(path) == 'string' ) {
86                 tpath = new Gtk.TreePath.from_string(path);
87             }
88             var iter = new Gtk.TreeIter();
89             this.el.get_iter (iter, tpath) ;
90             this.el.set_value(iter,col,val);
91         }
92                 
93         
94     }
95 );