Rename get_param_vocab to get_children_vocab and use a wrapper for the pure virtual...
[synfig.git] / synfig-studio / src / gui / trees / 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/cellrenderer_value.h"
36 #include "cellrenderer/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                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
190
191                 // Set up the on/off cell-renderer
192                 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
193                 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
194                 column->pack_start(*cellrenderer,false);
195                 column->add_attribute(cellrenderer->property_active(), layer_model.active);
196                 get_layer_tree_view().append_column(*column);
197         }
198
199         {       // --- I C O N --------------------------------------------------------
200                 int index;
201                 // Set up the icon cell-renderer
202                 index=get_layer_tree_view().append_column(_("Icon"),layer_model.icon);
203                 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
204                 get_layer_tree_view().set_expander_column(*column);
205         }
206         {       // --- N A M E --------------------------------------------------------
207                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
208
209                 // Set up the Layer label cell-renderer
210                 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
211                 column->pack_start(*cellrenderer,false);
212                 column->add_attribute(cellrenderer->property_text(), layer_model.label);
213                 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
214                 cellrenderer->property_editable()=true;
215
216                 column->set_reorderable();
217                 column->set_resizable();
218                 column->set_clickable(true);
219                 column->set_sort_column(layer_model.label);
220
221                 get_layer_tree_view().append_column(*column);
222         }
223         {       // --- Z D E P T H ----------------------------------------------------
224                 int index;
225                 index=get_layer_tree_view().append_column(_("Z Depth"),layer_model.z_depth);
226                 // Set up the Z-Depth label cell-renderer
227
228                 column_z_depth=get_layer_tree_view().get_column(index-1);
229                 column_z_depth->set_reorderable();
230                 column_z_depth->set_resizable();
231                 column_z_depth->set_clickable();
232
233                 column_z_depth->set_sort_column(layer_model.z_depth);
234         }
235
236         get_layer_tree_view().set_enable_search(true);
237         get_layer_tree_view().set_search_column(layer_model.label);
238         get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
239
240         std::list<Gtk::TargetEntry> listTargets;
241         listTargets.push_back( Gtk::TargetEntry("LAYER") );
242         get_layer_tree_view().drag_dest_set(listTargets);
243
244         // This makes things easier to read.
245         get_layer_tree_view().set_rules_hint();
246
247         // Make us more sensitive to several events
248         //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);
249
250         get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
251         get_layer_tree_view().show();
252
253         Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
254         scroll->set_flags(Gtk::CAN_FOCUS);
255         scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
256         //scroll->add(get_layer_tree_view());
257         scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
258         scroll->show();
259
260         return scroll;
261 }
262
263 Gtk::Widget*
264 LayerTree::create_param_tree()
265 {
266         Pango::AttrList attr_list;
267         {
268                 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
269                 pango_size.set_start_index(0);
270                 pango_size.set_end_index(64);
271                 attr_list.change(pango_size);
272         }
273
274         Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
275
276         {       // --- N A M E --------------------------------------------------------
277                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
278
279                 // Set up the icon cell-renderer
280                 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
281                 column->pack_start(*icon_cellrenderer,false);
282                 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
283
284                 // Pack the label into the column
285                 //column->pack_start(layer_model.label,true);
286                 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
287                 column->pack_start(*text_cellrenderer,false);
288                 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
289                 text_cellrenderer->property_attributes()=attr_list;
290
291                 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
292                 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
293
294                 // Pack the label into the column
295                 //column->pack_start(param_model.label,true);
296
297                 // Set up the value-node icon cell-renderer to be on the far right
298                 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
299                 column->pack_end(*valuenode_icon_cellrenderer,false);
300                 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
301                 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
302
303                 // Finish setting up the column
304                 column->set_reorderable();
305                 column->set_resizable();
306                 column->set_clickable();
307
308                 get_param_tree_view().append_column(*column);
309         }
310         {       // --- V A L U E  -----------------------------------------------------
311                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
312
313                 // Set up the value cell-renderer
314                 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
315                 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
316                 cellrenderer_value->property_value()=synfig::ValueBase();
317                 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
318                 column->add_attribute(cellrenderer_value->property_child_param_desc(), param_model.child_param_desc);
319                 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
320                 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
321                 cellrenderer_value->property_attributes()=attr_list;
322
323                 // Finish setting up the column
324                 get_param_tree_view().append_column(*column);
325                 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
326                 column->set_clickable();
327                 column->set_min_width(120);
328                 column->set_reorderable();
329                 column->set_resizable();
330         }
331         {       // --- T Y P E --------------------------------------------------------
332                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
333                 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
334                 column->pack_start(*text_cellrenderer,false);
335                 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
336                 text_cellrenderer->property_attributes()=attr_list;
337                 get_param_tree_view().append_column(*column);
338                 column->set_reorderable();
339                 column->set_resizable();
340                 column->set_clickable();
341                 column->set_sort_column(param_model.type);
342         }
343 #ifdef TIMETRACK_IN_PARAMS_PANEL
344         {       // --- T I M E   T R A C K --------------------------------------------
345                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
346                 column_time_track=column;
347
348                 // Set up the value-node cell-renderer
349                 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
350                 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
351                 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked_layertree) );
352                 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
353                 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
354                 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
355                 column->add_attribute(cellrenderer_time_track->property_visible(), param_model.is_value_node);
356
357                 // Finish setting up the column
358                 column->set_reorderable();
359                 column->set_resizable();
360                 column->set_min_width(200);
361
362                 if (!getenv("SYNFIG_DISABLE_PARAMS_PANEL_TIMETRACK"))
363                         get_param_tree_view().append_column(*column);
364         }
365 #endif  // TIMETRACK_IN_PARAMS_PANEL
366
367         // This makes things easier to read.
368         get_param_tree_view().set_rules_hint();
369
370         // Make us more sensitive to several events
371         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);
372
373         get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
374         get_param_tree_view().show();
375
376         Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
377         scroll->set_flags(Gtk::CAN_FOCUS);
378         scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
379         //scroll->add(get_param_tree_view());
380         scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
381         scroll->show();
382
383         //column_time_track->set_visible(false);
384
385         return scroll;
386 }
387
388 void
389 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
390 {
391         synfigapp::Action::ParamList param_list;
392         param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
393         param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
394         param_list.add("value_node",value_node);
395         param_list.add("waypoint",waypoint);
396 //      param_list.add("time",canvas_interface()->get_time());
397
398         etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("WaypointSetSmart", param_list);
399 }
400
401 void
402 LayerTree::select_layer(synfig::Layer::Handle layer)
403 {
404         Gtk::TreeModel::Children::iterator iter;
405         if(layer_tree_store_->find_layer_row(layer,iter))
406         {
407                 if(sorted_layer_tree_store_)
408                         iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
409
410                 Gtk::TreePath path(iter);
411                 for(int i=path.get_depth();i;i--)
412                 {
413                         int j;
414                         path=Gtk::TreePath(iter);
415                         for(j=i;j;j--)
416                                 path.up();
417                         get_layer_tree_view().expand_row(path,false);
418                 }
419                 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
420                 get_layer_tree_view().get_selection()->select(iter);
421         }
422 }
423
424 void
425 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
426 {
427         get_layer_tree_view().get_selection()->select(iter);
428         if((bool)(*iter)[layer_model.children_lock])
429                 return;
430         get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
431         Gtk::TreeModel::Children children(iter->children());
432         for(iter=children.begin();iter!=children.end();++iter)
433                 select_all_children(iter);
434 }
435
436 void
437 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
438 {
439         Gtk::TreeModel::Children::iterator iter;
440         if(layer_tree_store_->find_layer_row(layer,iter))
441                 select_all_children(iter);
442 }
443
444 void
445 LayerTree::select_layers(const LayerList &layer_list)
446 {
447         LayerList::const_iterator iter;
448         for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
449                 select_layer(*iter);
450 }
451
452 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
453 {
454         const LayerTreeStore::Model layer_tree_model;
455         ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
456 }
457
458 LayerTree::LayerList
459 LayerTree::get_selected_layers()const
460 {
461         Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
462
463         if(!selection)
464                 return LayerList();
465
466         LayerList ret;
467
468         selection->selected_foreach_iter(
469                 sigc::bind(
470                         sigc::ptr_fun(
471                                 &__layer_grabber
472                         ),
473                         &ret
474                 )
475         );
476
477         return ret;
478 }
479
480 synfig::Layer::Handle
481 LayerTree::get_selected_layer()const
482 {
483         LayerList layers(get_selected_layers());
484
485         if(layers.empty())
486                 return 0;
487
488         return *layers.begin();
489 }
490
491 void
492 LayerTree::clear_selected_layers()
493 {
494         get_layer_tree_view().get_selection()->unselect_all();
495 }
496
497 void
498 LayerTree::set_show_timetrack(bool x)
499 {
500         //column_time_track->set_visible(x);
501 //      column_time_track->set_visible(false);
502         column_z_depth->set_visible(x);
503 }
504
505 void
506 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
507 {
508         layer_tree_store_=layer_tree_store;
509
510         if(false)
511         {
512                 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
513
514                 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
515
516                 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
517                 //sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
518
519                 get_layer_tree_view().set_model(sorted_layer_tree_store_);
520         }
521         else
522                 get_layer_tree_view().set_model(layer_tree_store_);
523
524         layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
525
526         //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
527
528         layer_tree_store_->canvas_interface()->signal_time_changed().connect(
529                 sigc::mem_fun(
530                         &get_param_tree_view(),
531                         &Gtk::Widget::queue_draw
532                 )
533         );
534         if(!param_tree_store_)
535         {
536                 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
537                 get_param_tree_view().set_model(param_tree_store_);
538         }
539
540 #ifdef TIMETRACK_IN_PARAMS_PANEL
541         if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
542                 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
543 #endif  // TIMETRACK_IN_PARAMS_PANEL
544 }
545
546 void
547 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
548 {
549 #ifdef TIMETRACK_IN_PARAMS_PANEL
550         cellrenderer_time_track->set_adjustment(adjustment);
551 #endif  // TIMETRACK_IN_PARAMS_PANEL
552         adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
553         adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
554 }
555
556 void
557 LayerTree::on_dirty_preview()
558 {
559 /*
560         if(quick_layer && !disable_amount_changed_signal)
561         {
562                 layer_amount_hscale->set_sensitive(true);
563                 disable_amount_changed_signal=true;
564                 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
565                 disable_amount_changed_signal=false;
566                 if(quick_layer->get_param("blend_method").is_valid())
567                 {
568                         blend_method_widget.set_sensitive(true);
569                         disable_amount_changed_signal=true;
570                         blend_method_widget.set_value(quick_layer->get_param("blend_method"));
571                         disable_amount_changed_signal=false;
572                 }
573         }
574 */
575 }
576
577 void
578 LayerTree::on_selection_changed()
579 {
580         synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
581
582         Gtk::TreeIter iter;
583         if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
584         {
585                 if(layer_list.empty())
586                 {
587                         last_top_selected_layer=0;
588                         layer_tree_view_->get_selection()->select(last_top_selected_path);
589                         return;
590                 }
591         }
592
593         {
594                 if(!layer_list.empty())
595                 {
596                         last_top_selected_layer=layer_list.front();
597                         last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
598                 }
599                 else
600                 {
601                         last_top_selected_layer=0;
602                 }
603         }
604
605         if(layer_list.empty())
606         {
607                 button_raise->set_sensitive(false);
608                 button_lower->set_sensitive(false);
609                 button_duplicate->set_sensitive(false);
610                 button_encapsulate->set_sensitive(false);
611                 button_delete->set_sensitive(false);
612                 layer_amount_hscale->set_sensitive(false);
613                 blend_method_widget.set_sensitive(false);
614                 return;
615         }
616
617         button_raise->set_sensitive(true);
618         button_lower->set_sensitive(true);
619         button_duplicate->set_sensitive(true);
620         button_encapsulate->set_sensitive(true);
621         button_delete->set_sensitive(true);
622
623         if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
624         {
625                 quick_layer=*layer_list.begin();
626         }
627         else
628                 quick_layer=0;
629
630         if(quick_layer)
631         {
632                 layer_amount_hscale->set_sensitive(true);
633                 disable_amount_changed_signal=true;
634                 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
635                 disable_amount_changed_signal=false;
636                 if(quick_layer->get_param("blend_method").is_valid())
637                 {
638                         blend_method_widget.set_sensitive(true);
639                         disable_amount_changed_signal=true;
640                         blend_method_widget.set_value(quick_layer->get_param("blend_method"));
641                         disable_amount_changed_signal=false;
642                 }
643                 else
644                         blend_method_widget.set_sensitive(false);
645         }
646         else
647         {
648                 layer_amount_hscale->set_sensitive(false);
649                 blend_method_widget.set_sensitive(false);
650         }
651 }
652
653 void
654 LayerTree::on_blend_method_changed()
655 {
656         if(disable_amount_changed_signal)
657                 return;
658         if(!quick_layer)
659                 return;
660
661         if(quick_layer->get_param("blend_method").is_valid())
662         {
663                 disable_amount_changed_signal=true;
664                 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
665                 disable_amount_changed_signal=false;
666         }
667 }
668
669 void
670 LayerTree::on_amount_value_changed()
671 {
672         if(disable_amount_changed_signal)
673                 return;
674         if(!quick_layer)
675                 return;
676
677         disable_amount_changed_signal=true;
678         signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
679         disable_amount_changed_signal=false;
680 }
681
682 void
683 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
684 {
685         Gtk::TreePath path(path_string);
686
687         const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
688         if(!row)
689                 return;
690         row[param_model.value]=value;
691         //signal_edited_value()(row[param_model.value_desc],value);
692 }
693
694 void
695 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
696 {
697         Gtk::TreePath path(path_string);
698
699         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
700         if(!row)
701                 return;
702         row[layer_model.label]=value;
703         get_layer_tree_view().columns_autosize();
704 }
705
706 void
707 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
708 {
709         Gtk::TreePath path(path_string);
710
711         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
712         bool active=static_cast<bool>(row[layer_model.active]);
713         row[layer_model.active]=!active;
714 }
715
716 #ifdef TIMETRACK_IN_PARAMS_PANEL
717 void
718 LayerTree::on_waypoint_clicked_layertree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
719                                                                                  const synfig::Time& time __attribute__ ((unused)),
720                                                                                  const synfig::Time& time_offset __attribute__ ((unused)),
721                                                                                  int button __attribute__ ((unused)))
722 {
723         std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
724         synfig::waypoint_collect(waypoint_set,time,node);
725
726         synfigapp::ValueDesc value_desc;
727
728         if (waypoint_set.size() == 1)
729         {
730                 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
731                 assert(value_node);
732
733                 Gtk::TreeRow row;
734                 if (param_tree_store_->find_first_value_node(value_node, row) && row)
735                         value_desc = static_cast<synfigapp::ValueDesc>(row[param_tree_store_->model.value_desc]);
736         }
737
738         if (!waypoint_set.empty())
739                 signal_waypoint_clicked_layertree()(value_desc,waypoint_set,button);
740 }
741 #endif  // TIMETRACK_IN_PARAMS_PANEL
742
743 bool
744 LayerTree::on_layer_tree_event(GdkEvent *event)
745 {
746     switch(event->type)
747     {
748         case GDK_BUTTON_PRESS:
749                 {
750                         Gtk::TreeModel::Path path;
751                         Gtk::TreeViewColumn *column;
752                         int cell_x, cell_y;
753                         if(!get_layer_tree_view().get_path_at_pos(
754                                 int(event->button.x),int(event->button.y),      // x, y
755                                 path, // TreeModel::Path&
756                                 column, //TreeViewColumn*&
757                                 cell_x,cell_y //int&cell_x,int&cell_y
758                                 )
759                         ) break;
760                         const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
761
762 #ifdef TIMETRACK_IN_PARAMS_PANEL
763                         if(column->get_first_cell_renderer()==cellrenderer_time_track)
764                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
765                         else
766 #endif  // TIMETRACK_IN_PARAMS_PANEL
767                         if(column->get_first_cell_renderer()==cellrenderer_value)
768                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
769                         else
770                                 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
771
772                 }
773                 break;
774
775         case GDK_MOTION_NOTIFY:
776                 {
777                         Gtk::TreeModel::Path path;
778                         Gtk::TreeViewColumn *column;
779                         int cell_x, cell_y;
780                         if(!get_layer_tree_view().get_path_at_pos(
781                                 (int)event->button.x,(int)event->button.y,      // x, y
782                                 path, // TreeModel::Path&
783                                 column, //TreeViewColumn*&
784                                 cell_x,cell_y //int&cell_x,int&cell_y
785                                 )
786                         ) break;
787
788                         if(!get_layer_tree_view().get_model()->get_iter(path))
789                                 break;
790
791                         Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
792
793 #ifdef TIMETRACK_IN_PARAMS_PANEL
794                         if(cellrenderer_time_track==column->get_first_cell_renderer())
795                                 // Movement on TimeLine
796                                 return true;
797                         else
798 #endif  // TIMETRACK_IN_PARAMS_PANEL
799                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
800                         {
801                                 tooltips_.unset_tip(*this);
802                                 Glib::ustring tooltips_string(row[layer_model.tooltip]);
803                                 last_tooltip_path=path;
804                                 if(!tooltips_string.empty())
805                                 {
806                                         tooltips_.set_tip(*this,tooltips_string);
807                                         tooltips_.force_window();
808                                 }
809                         }
810                 }
811                 break;
812         case GDK_BUTTON_RELEASE:
813                 break;
814         default:
815                 break;
816         }
817         return false;
818 }
819
820 bool
821 LayerTree::on_param_tree_event(GdkEvent *event)
822 {
823     switch(event->type)
824     {
825         case GDK_BUTTON_PRESS:
826                 {
827                         Gtk::TreeModel::Path path;
828                         Gtk::TreeViewColumn *column;
829                         int cell_x, cell_y;
830                         if(!get_param_tree_view().get_path_at_pos(
831                                 int(event->button.x),int(event->button.y),      // x, y
832                                 path, // TreeModel::Path&
833                                 column, //TreeViewColumn*&
834                                 cell_x,cell_y //int&cell_x,int&cell_y
835                                 )
836                         ) break;
837                         const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
838
839 #ifdef TIMETRACK_IN_PARAMS_PANEL
840                         if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
841                         {
842                                 Gdk::Rectangle rect;
843                                 get_param_tree_view().get_cell_area(path,*column,rect);
844                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
845                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
846                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
847                                 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
848                                 return true;
849                                 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
850                         }
851                         else
852 #endif  // TIMETRACK_IN_PARAMS_PANEL
853                         {
854                                 if(event->button.button==3)
855                                 {
856                                         LayerList layer_list(get_selected_layers());
857                                         if(layer_list.size()<=1)
858                                         {
859                                                 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
860                                                 Gtk::Menu* menu(manage(new Gtk::Menu()));
861                                                 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
862                                                 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);
863                                                 menu->popup(event->button.button,gtk_get_current_event_time());
864                                                 return true;
865                                         }
866                                         Gtk::Menu* menu(manage(new Gtk::Menu()));
867                                         menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
868                                         std::list<synfigapp::ValueDesc> value_desc_list;
869                                         ParamDesc param_desc(row[param_model.param_desc]);
870                                         for(;!layer_list.empty();layer_list.pop_back())
871                                                 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
872                                         App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
873                                         menu->popup(event->button.button,gtk_get_current_event_time());
874                                         return true;
875                                 }
876                                 else
877                                 {
878                                         if(column->get_first_cell_renderer()==cellrenderer_value)
879                                                 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
880                                         else
881                                                 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
882                                 }
883                         }
884                 }
885                 break;
886
887         case GDK_MOTION_NOTIFY:
888                 {
889                         Gtk::TreeModel::Path path;
890                         Gtk::TreeViewColumn *column;
891                         int cell_x, cell_y;
892                         if(!get_param_tree_view().get_path_at_pos(
893                                 (int)event->motion.x,(int)event->motion.y,      // x, y
894                                 path, // TreeModel::Path&
895                                 column, //TreeViewColumn*&
896                                 cell_x,cell_y //int&cell_x,int&cell_y
897                                 )
898                         ) break;
899
900                         if(!get_param_tree_view().get_model()->get_iter(path))
901                                 break;
902
903                         Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
904
905 #ifdef TIMETRACK_IN_PARAMS_PANEL
906                         if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
907                         {
908                                 Gdk::Rectangle rect;
909                                 get_param_tree_view().get_cell_area(path,*column,rect);
910                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
911                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
912                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
913                                 get_param_tree_view().queue_draw();
914                                 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
915                                 return true;
916                         }
917                         else
918 #endif  // TIMETRACK_IN_PARAMS_PANEL
919                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
920                         {
921                                 tooltips_.unset_tip(get_param_tree_view());
922                                 Glib::ustring tooltips_string(row[param_model.tooltip]);
923                                 last_tooltip_path=path;
924                                 if(!tooltips_string.empty())
925                                 {
926                                         tooltips_.set_tip(get_param_tree_view(),tooltips_string);
927                                         tooltips_.force_window();
928                                 }
929                         }
930                 }
931                 break;
932         case GDK_BUTTON_RELEASE:
933                 {
934                         Gtk::TreeModel::Path path;
935                         Gtk::TreeViewColumn *column;
936                         int cell_x, cell_y;
937                         if(!get_param_tree_view().get_path_at_pos(
938                                 (int)event->button.x,(int)event->button.y,      // x, y
939                                 path, // TreeModel::Path&
940                                 column, //TreeViewColumn*&
941                                 cell_x,cell_y //int&cell_x,int&cell_y
942                                 )
943                         ) break;
944
945                         if(!get_param_tree_view().get_model()->get_iter(path))
946                                 break;
947
948                         Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
949
950 #ifdef TIMETRACK_IN_PARAMS_PANEL
951                         if(column && cellrenderer_time_track==column->get_first_cell_renderer())
952                         {
953                                 Gdk::Rectangle rect;
954                                 get_param_tree_view().get_cell_area(path,*column,rect);
955                                 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
956                                 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
957                                 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
958                                 get_param_tree_view().queue_draw();
959                                 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
960                                 return true;
961
962                         }
963 #endif  // TIMETRACK_IN_PARAMS_PANEL
964                 }
965                 break;
966         default:
967                 break;
968         }
969         return false;
970 }
971
972 // void
973 // LayerTree::on_raise_pressed()
974 // {
975 //      synfigapp::Action::ParamList param_list;
976 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
977 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
978 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
979 //
980 //      {
981 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
982 //              synfigapp::SelectionManager::LayerList::iterator iter;
983 //
984 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
985 //                      param_list.add("layer",Layer::Handle(*iter));
986 //      }
987 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerRaise"));
988 //      action->set_param_list(param_list);
989 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
990 // }
991
992 // void
993 // LayerTree::on_lower_pressed()
994 // {
995 //      synfigapp::Action::ParamList param_list;
996 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
997 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
998 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
999 //
1000 //      {
1001 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1002 //              synfigapp::SelectionManager::LayerList::iterator iter;
1003 //
1004 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1005 //                      param_list.add("layer",Layer::Handle(*iter));
1006 //      }
1007 //
1008 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerLower"));
1009 //      action->set_param_list(param_list);
1010 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1011 // }
1012
1013 // void
1014 // LayerTree::on_duplicate_pressed()
1015 // {
1016 //      synfigapp::Action::ParamList param_list;
1017 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1018 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1019 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1020 //
1021 //      {
1022 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1023 //              synfigapp::SelectionManager::LayerList::iterator iter;
1024 //
1025 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1026 //                      param_list.add("layer",Layer::Handle(*iter));
1027 //      }
1028 //
1029 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerDuplicate"));
1030 //      action->set_param_list(param_list);
1031 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1032 // }
1033
1034 // void
1035 // LayerTree::on_encapsulate_pressed()
1036 // {
1037 //      synfigapp::Action::ParamList param_list;
1038 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1039 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1040 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1041 //
1042 //      {
1043 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1044 //              synfigapp::SelectionManager::LayerList::iterator iter;
1045 //
1046 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1047 //                      param_list.add("layer",Layer::Handle(*iter));
1048 //      }
1049 //
1050 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerEncapsulate"));
1051 //      action->set_param_list(param_list);
1052 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1053 // }
1054
1055 // void
1056 // LayerTree::on_delete_pressed()
1057 // {
1058 //      synfigapp::Action::ParamList param_list;
1059 //      param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1060 //      param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1061 //      param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1062 //
1063 //      {
1064 //              synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1065 //              synfigapp::SelectionManager::LayerList::iterator iter;
1066 //
1067 //              for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1068 //                      param_list.add("layer",Layer::Handle(*iter));
1069 //      }
1070 //
1071 //      synfigapp::Action::Handle action(synfigapp::Action::create("LayerRemove"));
1072 //      action->set_param_list(param_list);
1073 //      layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1074 // }
1075
1076 /*
1077 void
1078 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1079 {
1080         synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1081         synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1082         synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1083
1084         Gtk::TreeModel::Path path;
1085         Gtk::TreeViewColumn *column;
1086         int cell_x, cell_y;
1087         if(get_selection()
1088         Gtk::TreeRow row = *(get_selection()->get_selected());
1089
1090         if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1091         {
1092                 Layer* layer(((Layer::Handle)row[model.layer]).get());
1093                 assert(layer);
1094                 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1095                 return;
1096         }
1097 }
1098
1099 void
1100 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1101 {
1102         synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1103         synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1104         synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1105         synfig::info("Dropped x=%d, y=%d",x,y);
1106         bool success=false;
1107         bool dropped_on_specific_row=false;
1108
1109         Gtk::TreeModel::Path path;
1110         Gtk::TreeViewColumn *column;
1111         int cell_x, cell_y;
1112         if(!get_path_at_pos(
1113                 x,y,    // x, y
1114                 path, // TreeModel::Path&
1115                 column, //TreeViewColumn*&
1116                 cell_x,cell_y //int&cell_x,int&cell_y
1117                 )
1118         )
1119         {
1120                 dropped_on_specific_row=false;
1121         }
1122         else
1123                 dropped_on_specific_row=true;
1124
1125         Gtk::TreeRow row = *(get_model()->get_iter(path));
1126
1127         if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1128         {
1129                 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1130                 {
1131                         Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1132                         assert(src);
1133
1134                         Canvas::Handle dest_canvas;
1135                         Layer::Handle dest_layer;
1136
1137                         if(dropped_on_specific_row)
1138                         {
1139                                 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1140                                 dest_layer=(Layer::Handle)(row[model.layer]);
1141                                 assert(dest_canvas);
1142                         }
1143                         else
1144                                 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1145
1146                         // In this case, we are just moving.
1147                         if(dest_canvas==src->get_canvas())
1148                         {
1149                                 if(!dest_layer || dest_layer==src)
1150                                         break;
1151
1152                                 synfigapp::Action::Handle action(synfigapp::Action::create("LayerMove"));
1153                                 action->set_param("canvas",dest_canvas);
1154                                 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1155                                 action->set_param("layer",src);
1156                                 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1157                                 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1158                                         success=true;
1159                                 else
1160                                         success=false;
1161                                 break;
1162                         }
1163                 }while(0);
1164         }
1165
1166         // Finish the drag
1167         context->drag_finish(success, false, time);
1168 }
1169 */
1170
1171 /*bool
1172 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int    y, guint    time)
1173 {
1174         return get_layer_tree_view().on_drag_motion(context,x,y,time);
1175 }
1176
1177 void
1178 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1179 {
1180         get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1181 */
1182 /*
1183         if(context->gobj()->source_window==context->gobj()->dest_window)
1184         {
1185                 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1186                 return;
1187         }
1188
1189         Gtk::TreeModel::Path path;
1190         Gtk::TreeViewColumn *column;
1191         int cell_x, cell_y;
1192         if(!get_path_at_pos(
1193                 x,y,    // x, y
1194                 path, // TreeModel::Path&
1195                 column, //TreeViewColumn*&
1196                 cell_x,cell_y //int&cell_x,int&cell_y
1197                 )
1198         )
1199         {
1200                 context->drag_finish(false, false, time);
1201         }
1202
1203         if(layer_tree_store_->row_drop_possible(path,selection_data))
1204         {
1205                 if(layer_tree_store_->drag_data_received(path,selection_data))
1206                         context->drag_finish(true, false, time);
1207         }
1208         context->drag_finish(false, false, time);
1209 }
1210 */