a69f23427df8d4c417d8289a319ccf5fb7dd5d6d
[synfig.git] / layertree.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layertree.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "layertree.h"
34 #include "layerparamtreestore.h"
35 #include "cellrenderer_value.h"
36 #include "cellrenderer_timetrack.h"
37 #include <synfigapp/action.h>
38 #include <synfigapp/instance.h>
39 #include <gtkmm/scrolledwindow.h>
40 #include <gtkmm/paned.h>
41 #include "app.h"
42 #include "instance.h"
43 #include <gtkmm/treemodelsort.h>
44
45 #ifdef TIMETRACK_IN_PARAMS_PANEL
46 #  include <synfig/timepointcollect.h>
47 #endif  // TIMETRACK_IN_PARAMS_PANEL
48
49 #include "general.h"
50
51 #endif
52
53 /* === U S I N G =========================================================== */
54
55 using namespace std;
56 using namespace etl;
57 using namespace synfig;
58 using namespace studio;
59
60 /* === M A C R O S ========================================================= */
61
62 #ifndef SMALL_BUTTON
63 #define SMALL_BUTTON(button,stockid,tooltip)    \
64         button = manage(new class Gtk::Button());       \
65         icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize));    \
66         button->add(*icon);     \
67         tooltips_.set_tip(*button,tooltip);     \
68         icon->set_padding(0,0);\
69         icon->show();   \
70         button->set_relief(Gtk::RELIEF_NONE); \
71         button->show()
72 #endif
73
74 #ifndef NORMAL_BUTTON
75 #define NORMAL_BUTTON(button,stockid,tooltip)   \
76         button = manage(new class Gtk::Button());       \
77         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON));       \
78         button->add(*icon);     \
79         tooltips_.set_tip(*button,tooltip);     \
80         icon->set_padding(0,0);\
81         icon->show();   \
82         /*button->set_relief(Gtk::RELIEF_NONE);*/ \
83         button->show()
84 #endif
85
86 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
87
88 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
89
90 /* === G L O B A L S ======================================================= */
91
92 /* === P R O C E D U R E S ================================================= */
93
94 /* === M E T H O D S ======================================================= */
95
96 LayerTree::LayerTree():
97         layer_amount_adjustment_(1,0,1,0.01,0.01,0)
98 {
99         param_tree_view_=new Gtk::TreeView;
100         layer_tree_view_=new Gtk::TreeView;
101
102         //Gtk::HPaned* hpaned(manage(new Gtk::HPaned()));
103         //hpaned->show();
104         //attach(*hpaned, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
105         //attach(*create_layer_tree(), 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
106
107         create_layer_tree();
108         create_param_tree();
109
110         //hpaned->pack1(*create_layer_tree(),false,false);
111         //hpaned->pack2(*create_param_tree(),true,false);
112         //hpaned->set_position(200);
113         hbox=manage(new Gtk::HBox());
114
115         attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
116         attach(blend_method_widget, 2, 3, 1, 2,Gtk::SHRINK, Gtk::SHRINK, 0, 0);
117
118         layer_amount_hscale=manage(new Gtk::HScale(layer_amount_adjustment_));
119         layer_amount_hscale->set_digits(2);
120         layer_amount_hscale->set_value_pos(Gtk::POS_LEFT);
121         layer_amount_hscale->set_sensitive(false);
122         layer_amount_hscale->set_update_policy( Gtk::UPDATE_DISCONTINUOUS);
123         attach(*layer_amount_hscale, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 1, 1);
124         layer_amount_adjustment_.signal_value_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_amount_value_changed));
125
126         Gtk::Image *icon;
127         //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
128         Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
129
130         SMALL_BUTTON(button_raise,"gtk-go-up","Raise");
131         SMALL_BUTTON(button_lower,"gtk-go-down","Lower");
132         SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate");
133         SMALL_BUTTON(button_encapsulate,"synfig-encapsulate","Encapsulate");
134         SMALL_BUTTON(button_delete,"gtk-delete","Delete");
135
136         hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
137         hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
138         hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
139         hbox->pack_start(*button_encapsulate,Gtk::PACK_SHRINK);
140         hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
141
142         // button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_raise_pressed));
143         // button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_lower_pressed));
144         // button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_duplicate_pressed));
145         // button_encapsulate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_encapsulate_pressed));
146         // button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_delete_pressed));
147
148         button_raise->set_sensitive(false);
149         button_lower->set_sensitive(false);
150         button_duplicate->set_sensitive(false);
151         button_encapsulate->set_sensitive(false);
152         button_delete->set_sensitive(false);
153
154         get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_selection_changed));
155
156         get_layer_tree_view().set_reorderable(true);
157         get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
158         //get_param_tree_view().get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
159         get_layer_tree_view().show();
160         get_param_tree_view().show();
161
162         hbox->show();
163         layer_amount_hscale->show();
164         blend_method_widget.show();
165
166         tooltips_.enable();
167         disable_amount_changed_signal=false;
168
169         blend_method_widget.set_param_desc(ParamDesc(Color::BlendMethod(),"blend_method"));
170
171         blend_method_widget.set_value((int)Color::BLEND_COMPOSITE);
172         blend_method_widget.set_size_request(150,-1);
173         blend_method_widget.set_sensitive(false);
174         blend_method_widget.signal_activate().connect(sigc::mem_fun(*this, &studio::LayerTree::on_blend_method_changed));
175 }
176
177 LayerTree::~LayerTree()
178 {
179         if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
180                 synfig::info("LayerTree::~LayerTree(): Deleted");
181 }
182
183 Gtk::Widget*
184 LayerTree::create_layer_tree()
185 {
186         const LayerTreeStore::Model model;
187
188         {       // --- O N / O F F ----------------------------------------------------
189                 //int index;
190                 //index=get_layer_tree_view().append_column_editable(_(" "),layer_model.active);
191                 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
192
193                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
194
195                 // Set up the icon cell-renderer
196                 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
197                 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
198
199                 column->pack_start(*cellrenderer,false);
200                 column->add_attribute(cellrenderer->property_active(), layer_model.active);
201                 get_layer_tree_view().append_column(*column);
202         }
203
204         {       // --- I C O N --------------------------------------------------------
205                 int index;
206                 index=get_layer_tree_view().append_column(_("Z"),layer_model.icon);
207                 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
208                 get_layer_tree_view().set_expander_column(*column);
209
210                 column->set_sort_column(layer_model.z_depth);
211                 //column->set_reorderable();
212                 //column->set_resizable();
213                 //column->set_clickable();
214
215                 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
216                 //column->pack_start(*icon_cellrenderer,false);
217                 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
218         }
219         //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
220         {       // --- N A M E --------------------------------------------------------
221                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
222
223                 // Set up the icon cell-renderer
224                 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
225                 column->pack_start(*cellrenderer,false);
226                 column->add_attribute(cellrenderer->property_text(), layer_model.label);
227                 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
228                 cellrenderer->property_editable()=true;
229
230                 column->set_reorderable();
231                 // column->set_resizable();
232                 column->set_clickable(true);
233                 column->set_sort_column(layer_model.label);
234
235                 get_layer_tree_view().append_column(*column);
236
237                 //              int index;
238 //              index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
239                 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
240
241                 //get_layer_tree_view().set_expander_column(*column);
242
243                 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
244                 //column->pack_start(*icon_cellrenderer,false);
245                 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
246         }
247         {       // --- Z D E P T H ----------------------------------------------------
248                 int index;
249                 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
250                 column_z_depth=get_layer_tree_view().get_column(index-1);
251
252                 column_z_depth->set_reorderable();
253                 column_z_depth->set_resizable();
254                 column_z_depth->set_clickable();
255
256                 column_z_depth->set_sort_column(layer_model.z_depth);
257         }
258
259         get_layer_tree_view().set_enable_search(true);
260         get_layer_tree_view().set_search_column(layer_model.label);
261         get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
262
263         std::list<Gtk::TargetEntry> listTargets;
264         listTargets.push_back( Gtk::TargetEntry("LAYER") );
265         get_layer_tree_view().drag_dest_set(listTargets);
266
267         // This makes things easier to read.
268         get_layer_tree_view().set_rules_hint();
269
270         // Make us more sensitive to several events
271         //get_layer_tree_view().add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
272
273         get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
274         get_layer_tree_view().show();
275
276         Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
277         scroll->set_flags(Gtk::CAN_FOCUS);
278         scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
279         //scroll->add(get_layer_tree_view());
280         scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
281         scroll->show();
282
283         return scroll;
284 }
285
286 Gtk::Widget*
287 LayerTree::create_param_tree()
288 {
289         Pango::AttrList attr_list;
290         {
291                 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
292                 pango_size.set_start_index(0);
293                 pango_size.set_end_index(64);
294                 attr_list.change(pango_size);
295         }
296
297         Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
298
299         {       // --- N A M E --------------------------------------------------------
300                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
301
302                 // Set up the icon cell-renderer
303                 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
304                 column->pack_start(*icon_cellrenderer,false);
305                 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
306
307                 // Pack the label into the column
308                 //column->pack_start(layer_model.label,true);
309                 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
310                 column->pack_start(*text_cellrenderer,false);
311                 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
312                 text_cellrenderer->property_attributes()=attr_list;
313
314                 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
315                 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
316
317                 // Pack the label into the column
318                 //column->pack_start(param_model.label,true);
319
320                 // Set up the value-node icon cell-renderer to be on the far right
321                 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
322                 column->pack_end(*valuenode_icon_cellrenderer,false);
323                 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
324                 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
325
326                 // Finish setting up the column
327                 column->set_reorderable();
328                 column->set_resizable();
329                 column->set_clickable();
330
331                 get_param_tree_view().append_column(*column);
332         }
333         {       // --- V A L U E  -----------------------------------------------------
334                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
335
336                 // Set up the value cell-renderer
337                 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
338                 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
339                 cellrenderer_value->property_value()=synfig::ValueBase();
340                 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
341                 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
342                 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
343                 cellrenderer_value->property_attributes()=attr_list;
344
345                 // Finish setting up the column
346                 get_param_tree_view().append_column(*column);
347                 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
348                 column->set_clickable();
349                 column->set_min_width(120);
350                 column->set_reorderable();
351                 column->set_resizable();
352         }
353         {       // --- T Y P E --------------------------------------------------------
354                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
355                 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
356                 column->pack_start(*text_cellrenderer,false);
357                 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
358                 text_cellrenderer->property_attributes()=attr_list;
359                 get_param_tree_view().append_column(*column);
360                 column->set_reorderable();
361                 column->set_resizable();
362                 column->set_clickable();
363                 column->set_sort_column(param_model.type);
364         }
365 #ifdef TIMETRACK_IN_PARAMS_PANEL
366         {       // --- T I M E   T R A C K --------------------------------------------
367                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
368                 column_time_track=column;
369
370                 // Set up the value-node cell-renderer
371                 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
372                 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
373                 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked_layertree) );
374                 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
375                 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
376                 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
377                 column->add_attribute(cellrenderer_time_track->property_visible(), param_model.is_value_node);
378
379                 // Finish setting up the column
380                 column->set_reorderable();
381                 column->set_resizable();
382                 column->set_min_width(200);
383
384                 if (!getenv("SYNFIG_DISABLE_PARAMS_PANEL_TIMETRACK"))
385                         get_param_tree_view().append_column(*column);
386         }
387 #endif  // TIMETRACK_IN_PARAMS_PANEL
388
389         // This makes things easier to read.
390         get_param_tree_view().set_rules_hint();
391
392         // Make us more sensitive to several events
393         get_param_tree_view().add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
394
395         get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
396         get_param_tree_view().show();
397
398         Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
399         scroll->set_flags(Gtk::CAN_FOCUS);
400         scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
401         //scroll->add(get_param_tree_view());
402         scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
403         scroll->show();
404
405         //column_time_track->set_visible(false);
406
407         return scroll;
408 }
409
410 void
411 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
412 {
413         synfigapp::Action::ParamList param_list;
414         param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
415         param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
416         param_list.add("value_node",value_node);
417         param_list.add("waypoint",waypoint);
418 //      param_list.add("time",canvas_interface()->get_time());
419
420         etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("WaypointSetSmart", param_list);
421 }
422
423 void
424 LayerTree::select_layer(synfig::Layer::Handle layer)
425 {
426         Gtk::TreeModel::Children::iterator iter;
427         if(layer_tree_store_->find_layer_row(layer,iter))
428         {
429                 if(sorted_layer_tree_store_)
430                         iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
431
432                 Gtk::TreePath path(iter);
433                 for(int i=path.get_depth();i;i--)
434                 {
435                         int j;
436                         path=Gtk::TreePath(iter);
437                         for(j=i;j;j--)
438                                 path.up();
439                         get_layer_tree_view().expand_row(path,false);
440                 }
441                 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
442                 get_layer_tree_view().get_selection()->select(iter);
443         }
444 }
445
446 void
447 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
448 {
449         get_layer_tree_view().get_selection()->select(iter);
450         if((bool)(*iter)[layer_model.children_lock])
451                 return;
452         get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
453         Gtk::TreeModel::Children children(iter->children());
454         for(iter=children.begin();iter!=children.end();++iter)
455                 select_all_children(iter);
456 }
457
458 void
459 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
460 {
461         Gtk::TreeModel::Children::iterator iter;
462         if(layer_tree_store_->find_layer_row(layer,iter))
463                 select_all_children(iter);
464 }
465
466 void
467 LayerTree::select_layers(const LayerList &layer_list)
468 {
469         LayerList::const_iterator iter;
470         for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
471                 select_layer(*iter);
472 }
473
474 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
475 {
476         const LayerTreeStore::Model layer_tree_model;
477         ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
478 }
479
480 LayerTree::LayerList
481 LayerTree::get_selected_layers()const
482 {
483         Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
484
485         if(!selection)
486                 return LayerList();
487
488         LayerList ret;
489
490         selection->selected_foreach_iter(
491                 sigc::bind(
492                         sigc::ptr_fun(
493                                 &__layer_grabber
494                         ),
495                         &ret
496                 )
497         );
498
499         return ret;
500 }
501
502 synfig::Layer::Handle
503 LayerTree::get_selected_layer()const
504 {
505         LayerList layers(get_selected_layers());
506
507         if(layers.empty())
508                 return 0;
509
510         return *layers.begin();
511 }
512
513 void
514 LayerTree::clear_selected_layers()
515 {
516         get_layer_tree_view().get_selection()->unselect_all();
517 }
518
519 void
520 LayerTree::set_show_timetrack(bool x)
521 {
522         //column_time_track->set_visible(x);
523 //      column_time_track->set_visible(false);
524         column_z_depth->set_visible(x);
525 }
526
527 void
528 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
529 {
530         layer_tree_store_=layer_tree_store;
531
532         if(false)
533         {
534                 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
535
536                 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
537
538                 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
539                 //sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
540
541                 get_layer_tree_view().set_model(sorted_layer_tree_store_);
542         }
543         else
544                 get_layer_tree_view().set_model(layer_tree_store_);
545
546         layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
547
548         //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
549
550         layer_tree_store_->canvas_interface()->signal_time_changed().connect(
551                 sigc::mem_fun(
552                         &get_param_tree_view(),
553                         &Gtk::Widget::queue_draw
554                 )
555         );
556         if(!param_tree_store_)
557         {
558                 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
559                 get_param_tree_view().set_model(param_tree_store_);
560         }
561
562 #ifdef TIMETRACK_IN_PARAMS_PANEL
563         if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
564                 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
565 #endif  // TIMETRACK_IN_PARAMS_PANEL
566 }
567
568 void
569 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
570 {
571 #ifdef TIMETRACK_IN_PARAMS_PANEL
572         cellrenderer_time_track->set_adjustment(adjustment);
573 #endif  // TIMETRACK_IN_PARAMS_PANEL
574         adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
575         adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
576 }
577
578 void
579 LayerTree::on_dirty_preview()
580 {
581 /*
582         if(quick_layer && !disable_amount_changed_signal)
583         {
584                 layer_amount_hscale->set_sensitive(true);
585                 disable_amount_changed_signal=true;
586                 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
587                 disable_amount_changed_signal=false;
588                 if(quick_layer->get_param("blend_method").is_valid())
589                 {
590                         blend_method_widget.set_sensitive(true);
591                         disable_amount_changed_signal=true;
592                         blend_method_widget.set_value(quick_layer->get_param("blend_method"));
593                         disable_amount_changed_signal=false;
594                 }
595         }
596 */
597 }
598
599 void
600 LayerTree::on_selection_changed()
601 {
602         synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
603
604         Gtk::TreeIter iter;
605         if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
606         {
607                 if(layer_list.empty())
608                 {
609                         last_top_selected_layer=0;
610                         layer_tree_view_->get_selection()->select(last_top_selected_path);
611                         return;
612                 }
613         }
614
615         {
616                 if(!layer_list.empty())
617                 {
618                         last_top_selected_layer=layer_list.front();
619                         last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
620                 }
621                 else
622                 {
623                         last_top_selected_layer=0;
624                 }
625         }
626
627         if(layer_list.empty())
628         {
629                 button_raise->set_sensitive(false);
630                 button_lower->set_sensitive(false);
631                 button_duplicate->set_sensitive(false);
632                 button_encapsulate->set_sensitive(false);
633                 button_delete->set_sensitive(false);
634                 layer_amount_hscale->set_sensitive(false);
635                 blend_method_widget.set_sensitive(false);
636                 return;
637         }
638
639         button_raise->set_sensitive(true);
640         button_lower->set_sensitive(true);
641         button_duplicate->set_sensitive(true);
642         button_encapsulate->set_sensitive(true);
643         button_delete->set_sensitive(true);
644
645         if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
646         {
647                 quick_layer=*layer_list.begin();
648         }
649         else
650                 quick_layer=0;
651
652         if(quick_layer)
653         {
654                 layer_amount_hscale->set_sensitive(true);
655                 disable_amount_changed_signal=true;
656                 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
657                 disable_amount_changed_signal=false;
658                 if(quick_layer->get_param("blend_method").is_valid())
659                 {
660                         blend_method_widget.set_sensitive(true);
661                         disable_amount_changed_signal=true;
662                         blend_method_widget.set_value(quick_layer->get_param("blend_method"));
663                         disable_amount_changed_signal=false;
664                 }
665                 else
666                         blend_method_widget.set_sensitive(false);
667         }
668         else
669         {
670                 layer_amount_hscale->set_sensitive(false);
671                 blend_method_widget.set_sensitive(false);
672         }
673 }
674
675 void
676 LayerTree::on_blend_method_changed()
677 {
678         if(disable_amount_changed_signal)
679                 return;
680         if(!quick_layer)
681                 return;
682
683         if(quick_layer->get_param("blend_method").is_valid())
684         {
685                 disable_amount_changed_signal=true;
686                 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
687                 disable_amount_changed_signal=false;
688         }
689 }
690
691 void
692 LayerTree::on_amount_value_changed()
693 {
694         if(disable_amount_changed_signal)
695                 return;
696         if(!quick_layer)
697                 return;
698
699         disable_amount_changed_signal=true;
700         signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
701         disable_amount_changed_signal=false;
702 }
703
704 void
705 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
706 {
707         Gtk::TreePath path(path_string);
708
709         const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
710         if(!row)
711                 return;
712         row[param_model.value]=value;
713         //signal_edited_value()(row[param_model.value_desc],value);
714 }
715
716 void
717 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
718 {
719         Gtk::TreePath path(path_string);
720
721         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
722         if(!row)
723                 return;
724         row[layer_model.label]=value;
725         get_layer_tree_view().columns_autosize();
726 }
727
728 void
729 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
730 {
731         Gtk::TreePath path(path_string);
732
733         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
734         bool active=static_cast<bool>(row[layer_model.active]);
735         row[layer_model.active]=!active;
736 }
737
738 #ifdef TIMETRACK_IN_PARAMS_PANEL
739 void
740 LayerTree::on_waypoint_clicked_layertree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
741                                                                                  const synfig::Time& time __attribute__ ((unused)),
742                                                                                  const synfig::Time& time_offset __attribute__ ((unused)),
743                                                                                  int button __attribute__ ((unused)))
744 {
745         std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
746         synfig::waypoint_collect(waypoint_set,time,node);
747
748         synfigapp::ValueDesc value_desc;
749
750         if (waypoint_set.size() == 1)
751         {
752                 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
753                 assert(value_node);
754
755                 Gtk::TreeRow row;
756                 if (param_tree_store_->find_first_value_node(value_node, row) && row)
757                         value_desc = static_cast<synfigapp::ValueDesc>(row[param_tree_store_->model.value_desc]);
758         }
759
760         if (!waypoint_set.empty())
761                 signal_waypoint_clicked_layertree()(value_desc,waypoint_set,button);
762 }
763 #endif  // TIMETRACK_IN_PARAMS_PANEL
764
765 bool
766 LayerTree::on_layer_tree_event(GdkEvent *event)
767 {
768     switch(event->type)
769     {
770         case GDK_BUTTON_PRESS:
771                 {
772                         Gtk::TreeModel::Path path;
773                         Gtk::TreeViewColumn *column;
774                         int cell_x, cell_y;
775                         if(!get_layer_tree_view().get_path_at_pos(
776                                 int(event->button.x),int(event->button.y),      // x, y
777                                 path, // TreeModel::Path&
778                                 column, //TreeViewColumn*&
779                                 cell_x,cell_y //int&cell_x,int&cell_y
780                                 )
781                         ) break;
782                         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
783
784 #ifdef TIMETRACK_IN_PARAMS_PANEL
785                         if(column->get_first_cell_renderer()==cellrenderer_time_track)
786                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
787                         else
788 #endif  // TIMETRACK_IN_PARAMS_PANEL
789                         if(column->get_first_cell_renderer()==cellrenderer_value)
790                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
791                         else
792                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
793
794                 }
795                 break;
796
797         case GDK_MOTION_NOTIFY:
798                 {
799                         Gtk::TreeModel::Path path;
800                         Gtk::TreeViewColumn *column;
801                         int cell_x, cell_y;
802                         if(!get_layer_tree_view().get_path_at_pos(
803                                 (int)event->button.x,(int)event->button.y,      // x, y
804                                 path, // TreeModel::Path&
805                                 column, //TreeViewColumn*&
806                                 cell_x,cell_y //int&cell_x,int&cell_y
807                                 )
808                         ) break;
809
810                         if(!get_layer_tree_view().get_model()->get_iter(path))
811                                 break;
812
813                         Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
814
815 #ifdef TIMETRACK_IN_PARAMS_PANEL
816                         if(cellrenderer_time_track==column->get_first_cell_renderer())
817                                 // Movement on TimeLine
818                                 return true;
819                         else
820 #endif  // TIMETRACK_IN_PARAMS_PANEL
821                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
822                         {
823                                 tooltips_.unset_tip(*this);
824                                 Glib::ustring tooltips_string(row[layer_model.tooltip]);
825                                 last_tooltip_path=path;
826                                 if(!tooltips_string.empty())
827                                 {
828                                         tooltips_.set_tip(*this,tooltips_string);
829                                         tooltips_.force_window();
830                                 }
831                         }
832                 }
833                 break;
834         case GDK_BUTTON_RELEASE:
835                 break;
836         default:
837                 break;
838         }
839         return false;
840 }
841
842 bool
843 LayerTree::on_param_tree_event(GdkEvent *event)
844 {
845     switch(event->type)
846     {
847         case GDK_BUTTON_PRESS:
848                 {
849                         Gtk::TreeModel::Path path;
850                         Gtk::TreeViewColumn *column;
851                         int cell_x, cell_y;
852                         if(!get_param_tree_view().get_path_at_pos(
853                                 int(event->button.x),int(event->button.y),      // x, y
854                                 path, // TreeModel::Path&
855                                 column, //TreeViewColumn*&
856                                 cell_x,cell_y //int&cell_x,int&cell_y
857                                 )
858                         ) break;
859                         const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
860
861 #ifdef TIMETRACK_IN_PARAMS_PANEL
862                         if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
863                         {
864                                 Gdk::Rectangle rect;
865                                 get_param_tree_view().get_cell_area(path,*column,rect);
866                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
867                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
868                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
869                                 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
870                                 return true;
871                                 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
872                         }
873                         else
874 #endif  // TIMETRACK_IN_PARAMS_PANEL
875                         {
876                                 if(event->button.button==3)
877                                 {
878                                         LayerList layer_list(get_selected_layers());
879                                         if(layer_list.size()<=1)
880                                         {
881                                                 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
882                                                 Gtk::Menu* menu(manage(new Gtk::Menu()));
883                                                 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
884                                                 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc,0.5f);
885                                                 menu->popup(event->button.button,gtk_get_current_event_time());
886                                                 return true;
887                                         }
888                                         Gtk::Menu* menu(manage(new Gtk::Menu()));
889                                         menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
890                                         std::list<synfigapp::ValueDesc> value_desc_list;
891                                         ParamDesc param_desc(row[param_model.param_desc]);
892                                         for(;!layer_list.empty();layer_list.pop_back())
893                                                 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
894                                         App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
895                                         menu->popup(event->button.button,gtk_get_current_event_time());
896                                         return true;
897                                 }
898                                 else
899                                 {
900                                         if(column->get_first_cell_renderer()==cellrenderer_value)
901                                                 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
902                                         else
903                                                 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
904                                 }
905                         }
906                 }
907                 break;
908
909         case GDK_MOTION_NOTIFY:
910                 {
911                         Gtk::TreeModel::Path path;
912                         Gtk::TreeViewColumn *column;
913                         int cell_x, cell_y;
914                         if(!get_param_tree_view().get_path_at_pos(
915                                 (int)event->motion.x,(int)event->motion.y,      // x, y
916                                 path, // TreeModel::Path&
917                                 column, //TreeViewColumn*&
918                                 cell_x,cell_y //int&cell_x,int&cell_y
919                                 )
920                         ) break;
921
922                         if(!get_param_tree_view().get_model()->get_iter(path))
923                                 break;
924
925                         Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
926
927 #ifdef TIMETRACK_IN_PARAMS_PANEL
928                         if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
929                         {
930                                 Gdk::Rectangle rect;
931                                 get_param_tree_view().get_cell_area(path,*column,rect);
932                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
933                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
934                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
935                                 get_param_tree_view().queue_draw();
936                                 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
937                                 return true;
938                         }
939                         else
940 #endif  // TIMETRACK_IN_PARAMS_PANEL
941                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
942                         {
943                                 tooltips_.unset_tip(*this);
944                                 Glib::ustring tooltips_string(row[layer_model.tooltip]);
945                                 last_tooltip_path=path;
946                                 if(!tooltips_string.empty())
947                                 {
948                                         tooltips_.set_tip(*this,tooltips_string);
949                                         tooltips_.force_window();
950                                 }
951                         }
952                 }
953                 break;
954         case GDK_BUTTON_RELEASE:
955                 {
956                         Gtk::TreeModel::Path path;
957                         Gtk::TreeViewColumn *column;
958                         int cell_x, cell_y;
959                         if(!get_param_tree_view().get_path_at_pos(
960                                 (int)event->button.x,(int)event->button.y,      // x, y
961                                 path, // TreeModel::Path&
962                                 column, //TreeViewColumn*&
963                                 cell_x,cell_y //int&cell_x,int&cell_y
964                                 )
965                         ) break;
966
967                         if(!get_param_tree_view().get_model()->get_iter(path))
968                                 break;
969
970                         Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
971
972 #ifdef TIMETRACK_IN_PARAMS_PANEL
973                         if(column && cellrenderer_time_track==column->get_first_cell_renderer())
974                         {
975                                 Gdk::Rectangle rect;
976                                 get_param_tree_view().get_cell_area(path,*column,rect);
977                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
978                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
979                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
980                                 get_param_tree_view().queue_draw();
981                                 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
982                                 return true;
983
984                         }
985 #endif  // TIMETRACK_IN_PARAMS_PANEL
986                 }
987                 break;
988         default:
989                 break;
990         }
991         return false;
992 }
993
994 // void
995 // LayerTree::on_raise_pressed()
996 // {
997 //      synfigapp::Action::ParamList param_list;
998 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
999 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1000 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1001 //
1002 //      {
1003 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1004 //              synfigapp::SelectionManager::LayerList::iterator iter;
1005 //
1006 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1007 //                      param_list.add("layer",Layer::Handle(*iter));
1008 //      }
1009 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerRaise"));
1010 //      action->set_param_list(param_list);
1011 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1012 // }
1013
1014 // void
1015 // LayerTree::on_lower_pressed()
1016 // {
1017 //      synfigapp::Action::ParamList param_list;
1018 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1019 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1020 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1021 //
1022 //      {
1023 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1024 //              synfigapp::SelectionManager::LayerList::iterator iter;
1025 //
1026 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1027 //                      param_list.add("layer",Layer::Handle(*iter));
1028 //      }
1029 //
1030 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerLower"));
1031 //      action->set_param_list(param_list);
1032 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1033 // }
1034
1035 // void
1036 // LayerTree::on_duplicate_pressed()
1037 // {
1038 //      synfigapp::Action::ParamList param_list;
1039 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1040 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1041 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1042 //
1043 //      {
1044 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1045 //              synfigapp::SelectionManager::LayerList::iterator iter;
1046 //
1047 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1048 //                      param_list.add("layer",Layer::Handle(*iter));
1049 //      }
1050 //
1051 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerDuplicate"));
1052 //      action->set_param_list(param_list);
1053 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1054 // }
1055
1056 // void
1057 // LayerTree::on_encapsulate_pressed()
1058 // {
1059 //      synfigapp::Action::ParamList param_list;
1060 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1061 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1062 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1063 //
1064 //      {
1065 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1066 //              synfigapp::SelectionManager::LayerList::iterator iter;
1067 //
1068 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1069 //                      param_list.add("layer",Layer::Handle(*iter));
1070 //      }
1071 //
1072 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerEncapsulate"));
1073 //      action->set_param_list(param_list);
1074 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1075 // }
1076
1077 // void
1078 // LayerTree::on_delete_pressed()
1079 // {
1080 //      synfigapp::Action::ParamList param_list;
1081 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1082 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1083 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1084 //
1085 //      {
1086 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1087 //              synfigapp::SelectionManager::LayerList::iterator iter;
1088 //
1089 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1090 //                      param_list.add("layer",Layer::Handle(*iter));
1091 //      }
1092 //
1093 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerRemove"));
1094 //      action->set_param_list(param_list);
1095 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1096 // }
1097
1098 /*
1099 void
1100 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1101 {
1102         synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1103         synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1104         synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1105
1106         Gtk::TreeModel::Path path;
1107         Gtk::TreeViewColumn *column;
1108         int cell_x, cell_y;
1109         if(get_selection()
1110         Gtk::TreeRow row = *(get_selection()->get_selected());
1111
1112         if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1113         {
1114                 Layer* layer(((Layer::Handle)row[model.layer]).get());
1115                 assert(layer);
1116                 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1117                 return;
1118         }
1119 }
1120
1121 void
1122 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1123 {
1124         synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1125         synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1126         synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1127         synfig::info("Dropped x=%d, y=%d",x,y);
1128         bool success=false;
1129         bool dropped_on_specific_row=false;
1130
1131         Gtk::TreeModel::Path path;
1132         Gtk::TreeViewColumn *column;
1133         int cell_x, cell_y;
1134         if(!get_path_at_pos(
1135                 x,y,    // x, y
1136                 path, // TreeModel::Path&
1137                 column, //TreeViewColumn*&
1138                 cell_x,cell_y //int&cell_x,int&cell_y
1139                 )
1140         )
1141         {
1142                 dropped_on_specific_row=false;
1143         }
1144         else
1145                 dropped_on_specific_row=true;
1146
1147         Gtk::TreeRow row = *(get_model()->get_iter(path));
1148
1149         if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1150         {
1151                 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1152                 {
1153                         Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1154                         assert(src);
1155
1156                         Canvas::Handle dest_canvas;
1157                         Layer::Handle dest_layer;
1158
1159                         if(dropped_on_specific_row)
1160                         {
1161                                 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1162                                 dest_layer=(Layer::Handle)(row[model.layer]);
1163                                 assert(dest_canvas);
1164                         }
1165                         else
1166                                 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1167
1168                         // In this case, we are just moving.
1169                         if(dest_canvas==src->get_canvas())
1170                         {
1171                                 if(!dest_layer || dest_layer==src)
1172                                         break;
1173
1174                                 synfigapp::Action::Handle action(synfigapp::Action::create("LayerMove"));
1175                                 action->set_param("canvas",dest_canvas);
1176                                 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1177                                 action->set_param("layer",src);
1178                                 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1179                                 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1180                                         success=true;
1181                                 else
1182                                         success=false;
1183                                 break;
1184                         }
1185                 }while(0);
1186         }
1187
1188         // Finish the drag
1189         context->drag_finish(success, false, time);
1190 }
1191 */
1192
1193 /*bool
1194 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int    y, guint    time)
1195 {
1196         return get_layer_tree_view().on_drag_motion(context,x,y,time);
1197 }
1198
1199 void
1200 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1201 {
1202         get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1203 */
1204 /*
1205         if(context->gobj()->source_window==context->gobj()->dest_window)
1206         {
1207                 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1208                 return;
1209         }
1210
1211         Gtk::TreeModel::Path path;
1212         Gtk::TreeViewColumn *column;
1213         int cell_x, cell_y;
1214         if(!get_path_at_pos(
1215                 x,y,    // x, y
1216                 path, // TreeModel::Path&
1217                 column, //TreeViewColumn*&
1218                 cell_x,cell_y //int&cell_x,int&cell_y
1219                 )
1220         )
1221         {
1222                 context->drag_finish(false, false, time);
1223         }
1224
1225         if(layer_tree_store_->row_drop_possible(path,selection_data))
1226         {
1227                 if(layer_tree_store_->drag_data_received(path,selection_data))
1228                         context->drag_finish(true, false, time);
1229         }
1230         context->drag_finish(false, false, time);
1231 }
1232 */