1 //<script type="text/javascript">
5 * Yet another attempt to create a usable object construction library for seed..
7 * Extend this.. to use it's wonderful features..
12 function XObject (cfg) {
13 // first apply cfg if set.
15 o.pack = o.pack || 'add';
17 XObject.extend(o, cfg); // copy everything into o.
18 XObject.extend(this, o);
25 // remove objects/functions from o, so they can be sent to the contructor.
27 if ((typeof(o[i]) == 'object') ||
28 (typeof(o[i]) == 'function') ||
35 this.listeners = this.listeners || {};
41 //if ((this.xtype == 'Include')) {
42 // o = this.pre_registry[cls];
44 var isSeed = typeof(Seed) != 'undefined';
46 // xtype= Gtk.Menu ?? what about c_new stuff?
47 if (typeof(this.xtype) == 'function') {
48 this.el = this.el || new this.xtype(o);
51 if (!this.el && o.xns)
52 var NS = imports.gi[o.xns];
54 Seed.print('Invalid xns: ' + o.xns);
56 constructor = NS[o.xtype];
58 Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
60 this.el = this.el || (isSeed ? new constructor(o) : new constructor());
65 if (o.xnsid && o.xid) {
66 XObject.registry = XObject.registry || { };
67 XObject.registry[o.xnsid] = XObject.registry[o.xnsid] || {};
68 XObject.registry[o.xnsid][o.xid] = this;
71 cfg.items.forEach(this.addItem, this);
77 * @property el {GObject} the Gtk / etc. element.
81 * @property items {Array} list of sub elements
84 * @property parent {XObject} parent Element
87 addItem : function(o) {
88 var item = new XObject(o);
90 this.items.push(item);
93 if (typeof(item.pack) == 'function') {
95 item.pack.apply(o, [ o , o.items[i] ]);
101 var pack_m = typeof(item.pack) == 'string' ? item.pack : item.pack.shift();
104 if (pack_m && typeof(o.el[pack_m]) == 'undefined') {
105 Seed.print('pack method not available : ' + o.xtype + '.' + pack_m);
110 //Seed.print('Pack ' + o.xtype + '.'+ pack_m + '(' + o.items[i].xtype + ')');
112 var args = Array.prototype.slice.call(typeof(item.pack) == 'string' ? [] : item.pack);
113 item.pack.unshift(item.el);
114 //Seed.print('args: ' + args.length);
116 this.el[pack_m].apply(item.el, args);
124 xnew: function (o, in_xnsid)
130 var isSeed = typeof(Seed) != 'undefined';
132 var constructor = false
136 Seed.print('xnew : ' + o.xns + '.' + o.xtype);
137 // support for xns='Gtk', xtyle='Window'..
138 var NS = imports.gi[o.xns];
140 Seed.print('Invalid xns: ' + o.xns);
142 constructor = NS[o.xtype];
144 Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
147 // how to hanlde gjs constructor???? - can it even be done..
149 o.el = o.el || (isSeed ? new constructor(o) : new constructor());
154 if (o.listeners._new) { // rendered!?!?
155 Seed.print('Call : ' + o.xtype+'.listeners._new');
156 o.listeners._new.call(o);
160 //Seed.print(o.pack.length);
161 // packing - if 'add method exists on created node use that..
164 for( var i =0; i < o.items.length;i++) {
169 o.items[i] = xnew.xnew(o.items[i], xnsid);
171 if (typeof(o.items[i].packing) == 'function') {
173 o.items[i].packing.apply(o, [ o , o.items[i] ]);
174 o.items[i].xparent = o;
177 var pack_m = o.items[i].packing[0];
179 if (pack_m && typeof(o.el[pack_m]) == 'undefined') {
180 Seed.print('pack method not available : ' + o.xtype + '.' + pack_m);
183 Seed.print('Pack ' + o.xtype + '.'+ pack_m + '(' + o.items[i].xtype + ')');
185 args = this.copyArray(o.items[i].packing);
186 args[0] = o.items[i].el;
187 Seed.print('args: ' + args.length);
189 o.el[pack_m].apply(o.el, args);
192 o.items[i].xparent = o;
197 for (var i in o.set) {
198 Seed.print('Set ' + i);
199 if (typeof(o.el[i].apply) !='undefined') {
200 o.el[i].apply(o.el, o.set[i]);
205 for (var i in o.listeners) {
206 if (i.substring(0,1) == '_') {
209 Seed.print('Add Listener ' + i);
211 var _li = this.createDelegate(o.listeners[i],o);
212 // private listeners that are not copied to GTk.
216 // Seed.print(typeof(_li));
217 o.el.signal[i].connect(_li);
219 o.el.connect( i, _li);
225 if (o.listeners._rendered) { // rendered!?!?
226 Seed.print('Call : ' + o.xtype+'.listeners._rendered');
227 o.listeners._rendered.call(o);