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);
73 return new Gtk.Image.from_stock (Gtk.STOCK_HOME, 100)
79 XObject.prototype.init.call(this);
84 this.el, /* widget that will accept a drop */
85 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
86 null, /* lists of target to support */
88 Gdk.DragAction.COPY /* what to do with data after dropped */
91 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
92 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
93 //Gtk.drag_dest_add_text_targets(this.el);
99 "drag-leave" : function () {
100 Seed.print("TARGET: drag-leave");
101 // stop monitoring of mouse montion in rendering..
104 'drag-motion' : function (w, ctx, x, y, time, ud)
108 // console.log('DRAG MOTION');
110 // if lastCurrentNode == this.currentNode.. -- don't change anything..
113 // A) find out from drag all the places that node could be dropped.
114 var src = Gtk.drag_get_source_widget(ctx);
116 Gdk.drag_status(ctx, 0, time);
119 // b) get what we are over.. (from activeNode)
120 // tree is empty.. - list should be correct..
121 if (!LeftTree.get('model').currentTree) {
122 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
126 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
127 var activeNode = this.getActiveNode(x, y);
130 var tg = LeftTree.get('model').findDropNode(activeNode, src.dropList);
133 Gdk.drag_status(ctx, 0,time);
134 LeftTree.get('view').highlight(false);
138 // if we have a target..
139 // -> highlight it! (in browser)
140 // -> highlight it! (in tree)
142 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
143 LeftTree.get('view').highlight(tg);
144 this.targetData = tg;
145 // for tree we should handle this...
149 "drag-drop" : function (w, ctx,x,y,time, ud)
152 Seed.print("TARGET: drag-drop");
153 is_valid_drop_site = true;
158 w, /* will receive 'drag-data-received' signal */
159 ctx, /* represents the current state of the DnD */
160 LeftTree.atoms["STRING"], /* the target type we want */
161 time /* time stamp */
165 /* No target offered by source => error */
168 return is_valid_drop_site;
172 "drag-data-received" : function (w, ctx, x, y, sel_data, target_type, time, ud)
174 Seed.print("GtkView: drag-data-received");
175 delete_selection_data = false;
177 /* Deal with what we are given from source */
178 if( sel_data && sel_data.length ) {
180 if (ctx.action == Gdk.DragAction.ASK) {
181 /* Ask the user to move or copy, then set the ctx action. */
184 if (ctx.action == Gdk.DragAction.MOVE) {
185 delete_selection_data = true;
187 var source = Gtk.drag_get_source_widget(ctx);
189 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
190 if (this.targetData) {
191 Seed.print(this.targetData);
192 LeftTree.get('model').dropNode(this.targetData, source.dragData);
201 if (dnd_success == false)
203 Seed.print ("DnD data transfer failed!\n");
206 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
210 //'line-mark-activated' : line_mark_activated,
215 getActiveNode : function(x,y)
217 // workout what node is here..
226 showInWindow: function ()
228 var src= this.lastSrc;
229 if (!this.lastSrc.length) {
232 var x = new imports.sandbox.Context();
241 x.get_global_object()._top.el.show_all();
245 buildJS: function(data) {
246 var i = [ 'Gtk', 'Gdk', 'Pango' ];
248 i.forEach(function(e) {
249 src += e+" = imports.gi." + e +";\n";
251 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
253 src += '_top=new XObject('+ this.mungeToString(data) + ')\n;';
254 src += '_top.init();\n';
260 renderJS : function(data)
262 // can we mess with data?!?!?
266 * sandbox it? - nope then will have dificulting passing. stuff aruond..
272 var src = this.buildJS(data);
273 var x = new imports.sandbox.Context();
275 //x.get_global_object().a = "hello world";
284 var r = new Gdk.Rectangle();
285 var _top = x.get_global_object()._top;
287 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
291 _top.el.popup(null, null, null, null, 3, null);
294 var pb = _top.el.get_snapshot(r);
301 var Window = imports.Builder.Window.Window;
302 var gc = new Gdk.GC.c_new(Window.el.window);
304 // 10 points all round..
305 var full = new Gdk.Pixmap.c_new (Window.el.window, r.width+20, r.height+20, pb.get_depth());
306 // draw a white background..
307 // gc.set_rgb_fg_color({ red: 0, white: 0, black : 0 });
308 Gdk.draw_rectangle(full, gc, true, 0, 0, r.width+20, r.height+20);
310 Gdk.draw_drawable (full, gc, pb, 0, 0, 10, 10, r.width, r.height);
312 //gc.set_rgb_fg_color({ red: 255, white: 255, black : 255 });
313 Gdk.draw_rectangle(full, gc, true, 0, 0, 10, 10);
314 this.get('view').el.set_from_pixmap(full, null);
315 //var img = new Gtk.Image.from_file("/home/alan/solarpanels.jpeg");
320 mungeToString: function(obj, isListener)
324 isListener = isListener || false;
326 if (obj.constructor.toString() === Array.toString()) {
327 for (var i= 0; i < obj.length; i++) {
339 typeof(obj['|xns']) != 'undefined' &&
340 typeof(obj['xtype']) != 'undefined'
342 els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
343 skip.push('|xns','xtype');
348 keys.forEach(function(i) {
350 if (!isArray && skip.indexOf(i) > -1) {
354 els.push(JSON.stringify(i) + ":" + obj[i]);
357 if (typeof(i) == 'string' && i[0] == '|') {
358 // does not hapepnd with arrays..
359 els.push(JSON.stringify(i.substring(1)) + ":" + obj[i]);
362 var left = isArray ? '' : (JSON.stringify(i) + " : " )
363 if (typeof(el) == 'object') {
364 els.push(left + _this.mungeToString(el, i == 'listeners'));
367 els.push(JSON.stringify(i) + ":" + JSON.stringify(obj[i]));
369 return (isArray ? '[' : '{') +
371 (isArray ? ']' : '}');