1 //<script type="text/javascript">
5 GObject = imports.gi.GObject;
9 * we use a hidden window to render the created dialog...
10 * then use snapshot to render it to an image...
15 XObject = imports.XObject.XObject;
16 File = imports.File.File;
17 console = imports.console;
19 LeftTree = imports.Builder.LeftTree.LeftTree ;
20 LeftPanel = imports.Builder.LeftPanel.LeftPanel;
21 //console.dump(imports.Builder.LeftTree);
24 RightGtkView = new XObject({
27 pack : [ 'append_page', new Gtk.Label({ label : "Gtk View" }) ],
32 pack : [ 'pack_start', false, true, 0 ],
38 label : 'Show in New Window',
39 pack : [ 'pack_start', false, false, 0 ],
42 'button-press-event' : function(w, ev ){
44 RightGtkView.showInWindow();
46 // show the MidPropTree..
57 xtype: Gtk.ScrolledWindow,
60 shadow_type : Gtk.ShadowType.IN ,
62 XObject.prototype.init.call(this);
64 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
72 packing : ['add_with_viewport' ],
77 return new Gtk.Image.from_stock (Gtk.STOCK_HOME, 100)
80 packing : ['add_with_viewport' ],
83 XObject.prototype.init.call(this);
88 this.el, /* widget that will accept a drop */
89 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
90 null, /* lists of target to support */
92 Gdk.DragAction.COPY /* what to do with data after dropped */
95 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
96 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
97 //Gtk.drag_dest_add_text_targets(this.el);
103 "drag-leave" : function () {
104 Seed.print("TARGET: drag-leave");
105 // stop monitoring of mouse montion in rendering..
108 'drag-motion' : function (w, ctx, x, y, time, ud)
112 // console.log('DRAG MOTION');
114 // if lastCurrentNode == this.currentNode.. -- don't change anything..
117 // A) find out from drag all the places that node could be dropped.
118 var src = Gtk.drag_get_source_widget(ctx);
120 Gdk.drag_status(ctx, 0, time);
123 // b) get what we are over.. (from activeNode)
124 // tree is empty.. - list should be correct..
125 if (!LeftTree.get('model').currentTree) {
126 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
130 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
131 var activeNode = this.getActiveNode(x, y);
134 var tg = LeftTree.get('model').findDropNode(activeNode, src.dropList);
137 Gdk.drag_status(ctx, 0,time);
138 LeftTree.get('view').highlight(false);
142 // if we have a target..
143 // -> highlight it! (in browser)
144 // -> highlight it! (in tree)
146 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
147 LeftTree.get('view').highlight(tg);
148 this.targetData = tg;
149 // for tree we should handle this...
153 "drag-drop" : function (w, ctx,x,y,time, ud)
156 Seed.print("TARGET: drag-drop");
157 is_valid_drop_site = true;
162 w, /* will receive 'drag-data-received' signal */
163 ctx, /* represents the current state of the DnD */
164 LeftTree.atoms["STRING"], /* the target type we want */
165 time /* time stamp */
169 /* No target offered by source => error */
172 return is_valid_drop_site;
176 "drag-data-received" : function (w, ctx, x, y, sel_data, target_type, time, ud)
178 Seed.print("GtkView: drag-data-received");
179 delete_selection_data = false;
181 /* Deal with what we are given from source */
182 if( sel_data && sel_data.length ) {
184 if (ctx.action == Gdk.DragAction.ASK) {
185 /* Ask the user to move or copy, then set the ctx action. */
188 if (ctx.action == Gdk.DragAction.MOVE) {
189 delete_selection_data = true;
191 var source = Gtk.drag_get_source_widget(ctx);
193 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
194 if (this.targetData) {
195 Seed.print(this.targetData);
196 LeftTree.get('model').dropNode(this.targetData, source.dragData);
205 if (dnd_success == false)
207 Seed.print ("DnD data transfer failed!\n");
210 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
214 //'line-mark-activated' : line_mark_activated,
219 getActiveNode : function(x,y)
221 // workout what node is here..
232 showInWindow: function ()
234 var src= this.lastSrc;
235 if (!this.lastSrc.length) {
238 var x = new imports.sandbox.Context();
248 var _top = x.get_global_object()._top;
250 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
253 _top.el.popup(null, null, null, null, 3, null);
257 buildJS: function(data) {
258 var i = [ 'Gtk', 'Gdk', 'Pango' ];
260 i.forEach(function(e) {
261 src += e+" = imports.gi." + e +";\n";
263 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
265 src += '_top=new XObject('+ this.mungeToString(data) + ')\n;';
266 src += '_top.init();\n';
272 renderJS : function(data)
274 // can we mess with data?!?!?
278 * sandbox it? - nope then will have dificulting passing. stuff aruond..
284 var src = this.buildJS(data);
285 var x = new imports.sandbox.Context();
287 //x.get_global_object().a = "hello world";
296 var r = new Gdk.Rectangle();
297 var _top = x.get_global_object()._top;
299 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
302 _top.el.popup(null, null, null, null, 3, null);
307 var pb = _top.el.get_snapshot(r);
314 var Window = imports.Builder.Window.Window;
315 var gc = new Gdk.GC.c_new(Window.el.window);
317 // 10 points all round..
318 var full = new Gdk.Pixmap.c_new (Window.el.window, r.width+20, r.height+20, pb.get_depth());
319 // draw a white background..
320 // gc.set_rgb_fg_color({ red: 0, white: 0, black : 0 });
321 Gdk.draw_rectangle(full, gc, true, 0, 0, r.width+20, r.height+20);
323 Gdk.draw_drawable (full, gc, pb, 0, 0, 10, 10, r.width, r.height);
325 //gc.set_rgb_fg_color({ red: 255, white: 255, black : 255 });
326 Gdk.draw_rectangle(full, gc, true, 0, 0, 10, 10);
327 this.get('view').el.set_from_pixmap(full, null);
328 this.get('view').el.set_size_request( r.width+20, r.height+20);
329 //var img = new Gtk.Image.from_file("/home/alan/solarpanels.jpeg");
334 mungeToString: function(obj, isListener)
338 isListener = isListener || false;
340 if (obj.constructor.toString() === Array.toString()) {
341 for (var i= 0; i < obj.length; i++) {
353 typeof(obj['|xns']) != 'undefined' &&
354 typeof(obj['xtype']) != 'undefined'
356 els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
357 skip.push('|xns','xtype');
362 keys.forEach(function(i) {
364 if (!isArray && skip.indexOf(i) > -1) {
368 if (obj[i].match(/Gtk.main_quit/)) { // we can not handle this very well..
371 els.push(JSON.stringify(i) + ":" + obj[i]);
374 if (typeof(i) == 'string' && i[0] == '|') {
375 // does not hapepnd with arrays..
376 if (!obj[i].length) { //skip empty.
379 if (obj[i].match(/Gtk.main_quit/)) { // we can not handle this very well..
382 els.push(JSON.stringify(i.substring(1)) + ":" + obj[i]);
385 var left = isArray ? '' : (JSON.stringify(i) + " : " )
386 if (typeof(el) == 'object') {
387 els.push(left + _this.mungeToString(el, i == 'listeners'));
390 els.push(JSON.stringify(i) + ":" + JSON.stringify(obj[i]));
392 return (isArray ? '[' : '{') +
394 (isArray ? ']' : '}');