Allow PasteCanvas layers with unset canvas parameters to be exported.
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasview.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 <sigc++/adaptors/hide.h>
34
35 #include <ETL/clock>
36 #include <sstream>
37
38 #include <gtkmm/paned.h>
39 #include <gtkmm/scale.h>
40 #include <gtkmm/dialog.h>
41 #include <gtkmm/messagedialog.h>
42 #include <gtkmm/treemodelsort.h>
43 #include <gtkmm/buttonbox.h>
44
45 #include <gtk/gtktreestore.h>
46 #include <gtk/gtkversion.h>
47
48 #include <synfig/valuenode_reference.h>
49 #include <synfig/valuenode_subtract.h>
50 #include <synfig/valuenode_linear.h>
51 #include <synfig/valuenode_timedswap.h>
52 #include <synfig/valuenode_scale.h>
53 #include <synfig/valuenode_dynamiclist.h>
54 #include <synfig/valuenode_twotone.h>
55 #include <synfig/valuenode_stripes.h>
56 #include <synfig/valuenode_blinecalctangent.h>
57 #include <synfig/valuenode_blinecalcvertex.h>
58 #include <synfig/valuenode_blinecalcwidth.h>
59 #include <synfig/valuenode_bline.h>
60 #include <synfig/layer.h>
61
62 #include <synfigapp/uimanager.h>
63 #include <synfigapp/canvasinterface.h>
64 #include <synfigapp/selectionmanager.h>
65 //#include <synfigapp/action_setwaypoint.h>
66 //#include <synfigapp/action_deletewaypoint.h>
67
68 #include <sigc++/retype_return.h>
69 #include <sigc++/retype.h>
70 //#include <sigc++/hide.h>
71
72 #include "canvasview.h"
73 #include "instance.h"
74 #include "app.h"
75 #include "cellrenderer_value.h"
76 #include "cellrenderer_timetrack.h"
77 #include "workarea.h"
78 #include "dialog_color.h"
79 #include "eventkey.h"
80
81 #include "state_polygon.h"
82 #include "state_bline.h"
83 #include "state_normal.h"
84 #include "state_eyedrop.h"
85 #include "state_draw.h"
86
87 #include "ducktransform_scale.h"
88 #include "ducktransform_translate.h"
89 #include "ducktransform_rotate.h"
90
91 #include "event_mouse.h"
92 #include "event_layerclick.h"
93
94 #include "toolbox.h"
95
96 #include "dialog_preview.h"
97 #include "dialog_soundselect.h"
98
99 #include "preview.h"
100 #include "audiocontainer.h"
101 #include "widget_timeslider.h"
102
103 #include <synfigapp/main.h>
104 #include <synfigapp/inputdevice.h>
105
106 #include "general.h"
107
108 #endif
109
110 /* === U S I N G =========================================================== */
111
112 using namespace std;
113 using namespace etl;
114 using namespace synfig;
115 using namespace studio;
116 using namespace sigc;
117
118 /* === M A C R O S ========================================================= */
119
120 #define GRAB_HINT_DATA(y)       { \
121                 String x; \
122                 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
123                 { \
124                         set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str()));    \
125                 } \
126         }
127
128 #define DEFAULT_TIME_WINDOW_SIZE                (10.0)
129
130 #ifndef SMALL_BUTTON
131 #define SMALL_BUTTON(button,stockid,tooltip)    \
132         button = manage(new class Gtk::Button());       \
133         icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize));    \
134         button->add(*icon);     \
135         tooltips.set_tip(*button,tooltip);      \
136         icon->set_padding(0,0);\
137         icon->show();   \
138         button->set_relief(Gtk::RELIEF_NONE); \
139         button->show()
140 #endif
141
142 #ifndef NORMAL_BUTTON
143 #define NORMAL_BUTTON(button,stockid,tooltip)   \
144         button = manage(new class Gtk::Button());       \
145         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON));       \
146         button->add(*icon);     \
147         tooltips.set_tip(*button,tooltip);      \
148         icon->set_padding(0,0);\
149         icon->show();   \
150         /*button->set_relief(Gtk::RELIEF_NONE);*/ \
151         button->show()
152 #endif
153
154 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
155
156 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
157
158 #define SLOT_EVENT(x)   sigc::hide_return(sigc::bind(sigc::mem_fun(*this,&studio::CanvasView::process_event_key),x))
159
160 /* === C L A S S E S ======================================================= */
161
162 class studio::UniversalScrubber
163 {
164         CanvasView *canvas_view;
165
166         bool            scrubbing;
167         etl::clock      scrub_timer;
168
169         sigc::connection end_scrub_connection;
170 public:
171         UniversalScrubber(CanvasView *canvas_view):
172                 canvas_view(canvas_view),
173                 scrubbing(false)
174         {
175                 canvas_view->canvas_interface()->signal_time_changed().connect(
176                         sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
177                 );
178         }
179
180         ~UniversalScrubber()
181         {
182                 end_scrub_connection.disconnect();
183         }
184
185         void on_time_changed()
186         {
187                 // Make sure we are changing the time quickly
188                 // before we enable scrubbing
189                 if(!scrubbing && scrub_timer()>1)
190                 {
191                         scrub_timer.reset();
192                         return;
193                 }
194
195                 // If we aren't scrubbing already, enable it
196                 if(!scrubbing)
197                 {
198                         scrubbing=true;
199                         audio_container()->start_scrubbing(canvas_view->get_time());
200                 }
201
202                 // Reset the scrubber ender
203                 end_scrub_connection.disconnect();
204                 end_scrub_connection=Glib::signal_timeout().connect(
205                         sigc::bind_return(
206                                 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
207                                 false
208                         ),
209                         1000
210                 );
211
212                 // Scrub!
213                 audio_container()->scrub(canvas_view->get_time());
214
215                 scrub_timer.reset();
216         }
217
218         void end_of_scrubbing()
219         {
220                 scrubbing=false;
221                 audio_container()->stop_scrubbing();
222                 scrub_timer.reset();
223         }
224
225         handle<AudioContainer> audio_container()
226         {
227                 assert(canvas_view->audio);
228                 return canvas_view->audio;
229         }
230 };
231
232 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
233 {
234         CanvasView *view;
235
236 public:
237
238         CanvasViewUIInterface(CanvasView *view):
239                 view(view)
240         {
241                 view->statusbar->push(_("Idle"));
242         }
243
244         ~CanvasViewUIInterface()
245         {
246                 //view->statusbar->pop();
247                 //view->progressbar->set_fraction(0);
248         }
249
250         virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
251         {
252                 view->present();
253                 //while(studio::App::events_pending())studio::App::iteration(false);
254                 Gtk::Dialog dialog(
255                         title,          // Title
256                         *view,          // Parent
257                         true,           // Modal
258                         true            // use_separator
259                 );
260                 Gtk::Label label(message);
261                 label.show();
262
263                 dialog.get_vbox()->pack_start(label);
264                 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
265                 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
266
267                 dialog.set_default_response(dflt);
268                 dialog.show();
269                 return (Response)dialog.run();
270         }
271         virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
272         {
273                 view->present();
274                 //while(studio::App::events_pending())studio::App::iteration(false);
275                 Gtk::Dialog dialog(
276                         title,          // Title
277                         *view,          // Parent
278                         true,           // Modal
279                         true            // use_separator
280                 );
281                 Gtk::Label label(message);
282                 label.show();
283
284                 dialog.get_vbox()->pack_start(label);
285                 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
286                 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
287                 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
288
289                 dialog.set_default_response(dflt);
290                 dialog.show();
291                 return (Response)dialog.run();
292         }
293         virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
294         {
295                 view->present();
296                 //while(studio::App::events_pending())studio::App::iteration(false);
297                 Gtk::Dialog dialog(
298                         title,          // Title
299                         *view,          // Parent
300                         true,           // Modal
301                         true            // use_separator
302                 );
303                 Gtk::Label label(message);
304                 label.show();
305
306                 dialog.get_vbox()->pack_start(label);
307                 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
308                 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
309
310                 dialog.set_default_response(dflt);
311                 dialog.show();
312                 return (Response)dialog.run();
313         }
314
315         virtual bool
316         task(const std::string &task)
317         {
318                 if(!view->is_playing_)
319                 {
320                         view->statusbar->pop();
321                         view->statusbar->push(task);
322                 }
323                 //while(studio::App::events_pending())studio::App::iteration(false);
324                 if(view->cancel){return false;}
325                 return true;
326         }
327
328         virtual bool
329         error(const std::string &err)
330         {
331                 view->statusbar->push(_("ERROR"));
332
333                 // If we are in the process of canceling,
334                 // then just go ahead and return false --
335                 // don't bother displaying a dialog
336                 if(view->cancel)return false;
337                 Gtk::MessageDialog dialog(*view, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
338                 dialog.show();
339                 dialog.run();
340                 view->statusbar->pop();
341                 return true;
342         }
343
344         virtual bool
345         warning(const std::string &err)
346         {
347                 view->statusbar->pop();
348                 view->statusbar->push(err);
349
350                 //while(studio::App::events_pending())studio::App::iteration(false);
351                 if(view->cancel)return false;
352                 return true;
353         }
354
355         virtual bool
356         amount_complete(int current, int total)
357         {
358                 if(!view->is_playing_)
359                 {
360                         if(!view->working_depth)
361                         {
362                                 if(current)
363                                         view->stopbutton->set_sensitive(true);
364                                 else
365                                         view->stopbutton->set_sensitive(false);
366                         }
367                         float x((float)current/(float)total);
368                         if(x<0)x=0;
369                         else if(x>1)x=1;
370                         view->progressbar->set_fraction(x);
371                 }
372                 //while(studio::App::events_pending())studio::App::iteration(false);
373                 if(view->cancel){/*view->cancel=false;*/return false;}
374                 return true;
375         }
376
377         void
378         not_implemented()
379         {
380                 error(_("Feature not yet implemented"));
381         }
382 };
383
384 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
385 {
386         CanvasView *view;
387         CanvasView::LayerTreeModel layer_tree_model;
388         CanvasView::ChildrenTreeModel children_tree_model;
389
390 public:
391         CanvasViewSelectionManager(CanvasView *view): view(view) { }
392
393 private:
394         void _set_selected_layer(const synfig::Layer::Handle &layer)
395         {
396                 view->layer_tree->select_layer(layer);
397 /*
398                 // Don't change the selection while we are busy
399                 // I cannot remember exactly why I put this here...
400                 // It musta been for some reason, but I cannot recall.
401                 //if(App::Busy::count)
402                 //      return;
403
404                 if(view->layer_tree->get_selection()->get_selected())
405                 {
406                         const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
407
408                         // Don't do anything if that layer is already selected
409                         if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
410                                 return;
411                 }
412                 Gtk::TreeModel::Children::iterator iter;
413                 if(view->layer_tree_store()->find_layer_row(layer,iter))
414                 {
415                         Gtk::TreePath path(iter);
416                         for(int i=path.get_depth();i;i--)
417                         {
418                                 int j;
419                                 path=Gtk::TreePath(iter);
420                                 for(j=i;j;j--)
421                                         path.up();
422                                 view->layer_tree->get_tree_view().expand_row(path,false);
423                         }
424                         view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
425                         view->layer_tree->get_selection()->select(iter);
426                 }
427 */
428         }
429 public:
430
431         //! Returns the number of layers selected.
432         virtual int get_selected_layer_count()const
433         {
434                 return get_selected_layers().size();
435         }
436
437         //! Returns a list of the currently selected layers.
438         virtual LayerList get_selected_layers()const
439         {
440 //              assert(view->layer_tree);
441
442                 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
443                 return view->layer_tree->get_selected_layers();
444         }
445
446         //! Returns the first layer selected or an empty handle if none are selected.
447         virtual synfig::Layer::Handle get_selected_layer()const
448         {
449 //              assert(view->layer_tree);
450
451                 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return 0; }
452                 return view->layer_tree->get_selected_layer();
453         }
454
455         //! Sets which layers should be selected
456         virtual void set_selected_layers(const LayerList &layer_list)
457         {
458 //              assert(view->layer_tree);
459
460                 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
461                 view->layer_tree->select_layers(layer_list);
462                 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
463
464                 //view->queue_rebuild_ducks();
465         }
466
467         //! Sets which layer should be selected.
468         virtual void set_selected_layer(const synfig::Layer::Handle &layer)
469         {
470 //              assert(view->layer_tree);
471
472                 if(!view->layer_tree) { synfig::error("canvas_view.layer_tree not defined!?"); return; }
473                 view->layer_tree->select_layer(layer);
474                 //view->queue_rebuild_ducks();
475         }
476
477         //! Clears the layer selection list
478         virtual void clear_selected_layers()
479         {
480                 if(!view->layer_tree) return;
481                 view->layer_tree->clear_selected_layers();
482         }
483
484         //! Returns the number of value_nodes selected.
485         virtual int get_selected_children_count()const
486         {
487                 return get_selected_children().size();
488         }
489
490         static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
491         {
492                 const CanvasView::ChildrenTreeModel children_tree_model;
493                 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
494                 if(value_desc)
495                         ret->push_back(value_desc);
496         }
497
498         //! Returns a list of the currently selected value_nodes.
499         virtual ChildrenList get_selected_children()const
500         {
501                 if(!view->children_tree) return ChildrenList();
502
503                 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
504
505                 if(!selection)
506                         return ChildrenList();
507
508                 ChildrenList ret;
509
510                 selection->selected_foreach_iter(
511                         sigc::bind(
512                                 sigc::ptr_fun(
513                                         &studio::CanvasViewSelectionManager::__child_grabber
514                                 ),
515                                 &ret
516                         )
517                 );
518
519                 /*
520                 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
521                 iter++;
522                 Gtk::TreeModel::Children children = iter->children();
523                 for(iter = children.begin(); iter != children.end(); ++iter)
524                 {
525                         Gtk::TreeModel::Row row = *iter;
526                         if(selection->is_selected(row))
527                                 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
528                 }
529                 */
530                 return ret;
531         }
532
533         //! Returns the first value_node selected or an empty handle if none are selected.
534         virtual ChildrenList::value_type get_selected_child()const
535         {
536                 if(!view->children_tree) return ChildrenList::value_type();
537
538                 ChildrenList children(get_selected_children());
539
540                 if(children.empty())
541                         return ChildrenList::value_type();
542
543                 return children.front();
544         }
545
546         //! Sets which value_nodes should be selected
547         virtual void set_selected_children(const ChildrenList &/*children_list*/)
548         {
549                 return;
550         }
551
552         //! Sets which value_node should be selected. Empty handle if none.
553         virtual void set_selected_child(const ChildrenList::value_type &/*child*/)
554         {
555                 return;
556         }
557
558         //! Clears the value_node selection list
559         virtual void clear_selected_children()
560         {
561                 return;
562         }
563
564         int get_selected_layer_parameter_count()const
565         {
566                 return get_selected_layer_parameters().size();
567         }
568
569         LayerParamList get_selected_layer_parameters()const
570         {
571                 if(!view->layer_tree) return LayerParamList();
572
573                 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
574
575                 if(!selection)
576                         return LayerParamList();
577
578                 LayerParamList ret;
579
580                 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
581                 Gtk::TreeModel::Children::iterator iter;
582                 for(iter = children.begin(); iter != children.end(); ++iter)
583                 {
584                         Gtk::TreeModel::Row row = *iter;
585                         Gtk::TreeModel::Children::iterator iter;
586                         for(iter=row.children().begin();iter!=row.children().end();iter++)
587                         {
588                                 Gtk::TreeModel::Row row = *iter;
589                                 if(selection->is_selected(row))
590                                         ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
591                         }
592                 }
593                 return ret;
594         }
595
596         LayerParam get_selected_layer_parameter() const
597         {
598                 if(!view->layer_tree) return LayerParam();
599                 return get_selected_layer_parameters().front();
600         }
601
602         void set_selected_layer_parameters(const LayerParamList &/*layer_param_list*/)
603         {
604                 return;
605         }
606
607         void set_selected_layer_param(const LayerParam &/*layer_param*/)
608         {
609                 return;
610         }
611
612         void clear_selected_layer_parameters()
613         {
614                 return;
615         }
616
617 }; // END of class SelectionManager
618
619 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
620         canvas_view_(canvas_view_)
621 {
622         if(!canvas_view_.working_depth)
623                 canvas_view_.stopbutton->set_sensitive(true);
624         canvas_view_.working_depth++;
625         canvas_view_.cancel=false;
626 }
627
628 CanvasView::IsWorking::~IsWorking()
629 {
630         canvas_view_.working_depth--;
631         if(!canvas_view_.working_depth)
632                 canvas_view_.stopbutton->set_sensitive(false);
633 }
634
635 CanvasView::IsWorking::operator bool()const
636 {
637         if(canvas_view_.cancel)
638                 return false;
639         return true;
640 }
641
642 /* === M E T H O D S ======================================================= */
643
644 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
645         smach_                                  (this),
646         instance_                               (instance),
647         canvas_interface_               (canvas_interface_),
648         //layer_tree_store_             (LayerTreeStore::create(canvas_interface_)),
649         //children_tree_store_  (ChildrenTreeStore::create(canvas_interface_)),
650         //keyframe_tree_store_  (KeyframeTreeStore::create(canvas_interface_)),
651         time_adjustment_                (0,0,25,0,0,0),
652         time_window_adjustment_ (0,0,25,0,0,0),
653         statusbar                               (manage(new class Gtk::Statusbar())),
654
655         timeslider                              (new Widget_Timeslider),
656
657         ui_interface_                   (new CanvasViewUIInterface(this)),
658         selection_manager_              (new CanvasViewSelectionManager(this)),
659         is_playing_                             (false),
660
661         working_depth                   (0),
662         cancel                                  (false),
663
664         canvas_properties               (*this,canvas_interface_),
665         canvas_options                  (this),
666         render_settings                 (*this,canvas_interface_),
667         waypoint_dialog                 (*this,canvas_interface_->get_canvas()),
668         keyframe_dialog                 (*this,canvas_interface_),
669         preview_dialog                  (new Dialog_Preview),
670         sound_dialog                    (new Dialog_SoundSelect(*this,canvas_interface_))
671 {
672         layer_tree=0;
673         children_tree=0;
674         duck_refresh_flag=true;
675
676         smach_.set_default_state(&state_normal);
677
678         disp_audio = new Widget_Sound();
679
680         //synfig::info("Canvasview: Entered constructor");
681         // Minor hack
682         get_canvas()->set_time(0);
683         //layer_tree_store_->rebuild();
684
685         // Set up the UI and Selection managers
686         canvas_interface()->set_ui_interface(get_ui_interface());
687         canvas_interface()->set_selection_manager(get_selection_manager());
688         rebuild_ducks_queued=false;
689
690         //notebook=manage(new class Gtk::Notebook());
691         //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
692         //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
693         //vpaned->pack2(*notebook, Gtk::SHRINK);
694         //vpaned->show_all();
695
696         //notebook->show();
697
698         //notebook->append_page(*create_layer_tree(),_("Layers"));
699         //notebook->append_page(*create_children_tree(),_("Children"));
700         //notebook->append_page(*create_keyframe_tree(),_("Keyframes"));
701
702         //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
703         //create all allocated stuff for this canvas
704         audio = new AudioContainer();
705
706         Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
707         //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
708         layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
709         init_menus();
710         //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
711
712         layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
713         layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
714
715         update_title();
716
717         layout_table->show();
718         add(*layout_table);
719
720         //set_transient_for(*App::toolbox);
721
722         //synfig::info("Canvasview: Before Signals");
723         /*
724  --     ** -- Signals -------------------------------------------------------------
725         */
726
727         canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
728         canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
729
730         canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
731
732         //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
733         canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
734         canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
735         waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
736         waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
737
738         //MODIFIED TIME ADJUSTMENT STUFF....
739         time_window_adjustment().set_child_adjustment(&time_adjustment());
740         time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
741         time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
742
743         work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
744         work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
745
746         canvas_interface()->signal_canvas_added().connect(
747                 sigc::hide(
748                         sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
749                 )
750         );
751         canvas_interface()->signal_canvas_removed().connect(
752                 sigc::hide(
753                         sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
754                 )
755         );
756
757         canvas_interface()->signal_layer_param_changed().connect(
758                 sigc::hide(
759                         sigc::hide(
760                                 SLOT_EVENT(EVENT_REFRESH_DUCKS)
761                         )
762                 )
763         );
764
765         //MUCH TIME STUFF TAKES PLACE IN HERE
766         refresh_rend_desc();
767         refresh_time_window();
768
769         /*! \todo We shouldn't need to do this at construction --
770         **      This should be performed at the first time the window
771         **      becomes visible.
772         */
773         work_area->queue_render_preview();
774
775         // If the canvas is really big, zoom out so that we can fit it all in the window
776         /*! \todo In other words, this is a zoom-to-fit, and should be
777         ** in its own function.
778         */
779         int w=get_canvas()->rend_desc().get_w()+70;
780         int h=get_canvas()->rend_desc().get_h()+70;
781         while(w>700 || h>600)
782         {
783                 // Minor hack:
784                 //   zoom_out() =>
785                 //         WorkArea::async_update_preview() =>
786                 //           WorkArea::set_zoom(float) =>
787                 //                 WorkArea::async_update_preview() =>
788                 //                       desc.set_time(cur_time), where cur_time isn't initialized
789                 work_area->set_time(0);
790                 work_area->zoom_out();
791                 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
792                 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
793         }
794         if(w>700)w=700;
795         if(h>600)h=600;
796         set_default_size(w,h);
797         property_window_position().set_value(Gtk::WIN_POS_NONE);
798
799         std::list<Gtk::TargetEntry> listTargets;
800         listTargets.push_back( Gtk::TargetEntry("STRING") );
801         listTargets.push_back( Gtk::TargetEntry("text/plain") );
802         listTargets.push_back( Gtk::TargetEntry("image") );
803
804         drag_dest_set(listTargets);
805         signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
806
807         /*
808         Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
809         if(length<10.0)
810         {
811                 time_window_adjustment().set_page_increment(length);
812                 time_window_adjustment().set_page_size(length);
813         }
814         else
815         {
816                 time_window_adjustment().set_page_increment(10.0);
817                 time_window_adjustment().set_page_size(10.0);
818         }
819         */
820
821         //synfig::info("Canvasview: Before Sound Hookup");
822         //load sound info from meta data
823         {
824                 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
825
826                 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
827                 on_audio_offset_notify();
828
829                 //signal connection - since they are all associated with the canvas view
830
831                 //hook in signals for sound options box
832                 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
833                 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
834
835                 //attach to the preview when it's visible
836                 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
837                 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
838
839                 //hook to metadata signals
840                 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
841                 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
842
843                 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
844         }
845
846         //synfig::info("Canvasview: Before Final time set up");
847         //MORE TIME STUFF
848         time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
849         time_window_adjustment().value_changed();
850
851         GRAB_HINT_DATA("canvas_view");
852         /*
853         {
854         set_skip_taskbar_hint(true);
855         set_skip_pager_hint(true);
856         set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
857         }
858         */
859
860         refresh_rend_desc();
861         hide_tables();
862
863         on_time_changed();
864         //synfig::info("Canvasview: Constructor Done");
865 }
866
867 CanvasView::~CanvasView()
868 {
869         signal_deleted()();
870
871         App::ui_manager()->remove_action_group(action_group);
872
873         // Shut down the smach
874         smach_.egress();
875         smach_.set_default_state(0);
876
877         // We want to ensure that the UI_Manager and
878         // the selection manager get destructed right now.
879         ui_interface_.reset();
880         selection_manager_.reset();
881
882         // Delete any external widgets
883         for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
884         {
885                 if(ext_widget_book_.begin()->second)
886                         delete ext_widget_book_.begin()->second;
887         }
888
889         //delete preview
890         audio.reset();
891
892         hide();
893
894         // don't be calling on_dirty_preview once this object has been deleted;
895         // this was causing a crash before
896         canvas_interface()->signal_dirty_preview().clear();
897
898         if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
899                 synfig::info("CanvasView::~CanvasView(): Deleted");
900 }
901
902 std::list<int>&
903 CanvasView::get_pixel_sizes()
904 {
905         // prime factors of 120 are 2, 2, 2, 3, 5 - see TILE_SIZE in synfig-core/trunk/src/synfig/target_tile.h
906         static int pixel_size_array[] = {2,3,4,5,6,8,10,12,15,20,24,30,40,60,120};
907         static list<int> pixel_sizes = list<int>(pixel_size_array, pixel_size_array + sizeof(pixel_size_array) / sizeof(int));
908
909         return pixel_sizes;
910 }
911
912 Gtk::Widget *
913 CanvasView::create_time_bar()
914 {
915         Gtk::Image *icon;
916
917         Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
918         //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
919         //TIME BAR TEMPORARY POSITION
920         //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
921         timeslider->show();
922         timeslider->set_time_adjustment(&time_adjustment());
923         timeslider->set_bounds_adjustment(&time_window_adjustment());
924         //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
925
926         tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
927         tooltips.set_tip(*timeslider,_("Changes the current time"));
928         time_window_scroll->show();
929         timeslider->show();
930         time_window_scroll->set_flags(Gtk::CAN_FOCUS);
931         timeslider->set_flags(Gtk::CAN_FOCUS);
932
933         //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
934         //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
935
936         NORMAL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
937         animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
938         animatebutton->show();
939
940         NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all",_("All Keyframes Locked"));
941         keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
942         keyframebutton->show();
943
944         Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
945
946         //setup the audio display
947         disp_audio->set_size_request(-1,32); //disp_audio->show();
948         disp_audio->set_time_adjustment(&time_adjustment());
949         disp_audio->signal_start_scrubbing().connect(
950                 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
951         );
952         disp_audio->signal_scrub().connect(
953                 sigc::mem_fun(*audio,&AudioContainer::scrub)
954         );
955         disp_audio->signal_stop_scrubbing().connect(
956                 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
957         );
958
959         table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
960         table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
961         table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
962
963         table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
964         table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
965         timebar=table;
966         table->show();
967         return table;
968 }
969
970 Gtk::Widget *
971 CanvasView::create_work_area()
972 {
973         work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
974         work_area->set_instance(get_instance());
975         work_area->set_canvas(get_canvas());
976         work_area->set_canvas_view(this);
977         work_area->set_progress_callback(get_ui_interface().get());
978         work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
979         work_area->show();
980         return work_area.get();
981 }
982
983 Gtk::Widget*
984 CanvasView::create_status_bar()
985 {
986         Gtk::Image *icon;
987         Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
988         cancel=false;
989
990         // Create the status bar at the bottom of the window
991         Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
992 //      statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
993         progressbar =manage(new class Gtk::ProgressBar());
994         SMALL_BUTTON(stopbutton,"gtk-stop",_("Stop"));
995         SMALL_BUTTON(refreshbutton,"gtk-refresh",_("Refresh"));
996         //SMALL_BUTTON(treetogglebutton,"gtk-go-down",_("Toggle Layer Tree"));
997 //      NEW_SMALL_BUTTON(raisebutton,"gtk-go-up",_("Raise Layer"));
998 //      NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down",_("Lower Layer"));
999         //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1000 //      statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1001 //      statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1002
1003         current_time_widget=manage(new Widget_Time);
1004         current_time_widget->set_value(get_time());
1005         current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1006         current_time_widget->signal_value_changed().connect(
1007                 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1008         );
1009
1010         statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1011         statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1012         statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1013         statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1014         statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1015         statusbar->set_has_resize_grip(false);
1016         statusbar->show();
1017         stopbutton->show();
1018         refreshbutton->show();
1019         progressbar->show();
1020         stopbutton->set_sensitive(false);
1021
1022         //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1023         //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1024         //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1025
1026         refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1027         stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1028
1029         statusbartable->show_all();
1030         return statusbartable;
1031 }
1032
1033 void
1034 CanvasView::on_current_time_widget_changed()
1035 {
1036         set_time(current_time_widget->get_value());
1037
1038         // show the value being used - it will have been rounded to nearest frame
1039         // this was already being done elsewhere, but only if the time was really changed;
1040         // if the current time was 6f and the user edited it to 6.1f, then the 6.1f would
1041         // be left in the display without the following line to fix it
1042         current_time_widget->set_value(get_time());
1043         current_time_widget->set_position(-1); // leave the cursor at the end
1044 }
1045
1046 //      Gtk::Widget*
1047 //      CanvasView::create_children_tree()
1048 //      {
1049 //              // Create the layer tree
1050 //              children_tree=manage(new class ChildrenTree());
1051 //
1052 //              // Set up the layer tree
1053 //              //children_tree->set_model(children_tree_store());
1054 //              if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1055 //              if(children_tree)children_tree->show();
1056 //
1057 //              // Connect Signals
1058 //              if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1059 //              if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1060 //              if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1061 //              if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1062 //
1063 //              return children_tree;
1064 //      }
1065
1066 //      Gtk::Widget*
1067 //      CanvasView::create_keyframe_tree()
1068 //      {
1069 //              keyframe_tree=manage(new KeyframeTree());
1070 //
1071 //              //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1072 //              //keyframe_tree->show();
1073 //              //keyframe_tree->set_model(keyframe_tree_store());
1074 //              keyframe_tree->set_editable(true);
1075 //              //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1076 //
1077 //              keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1078 //
1079 //              Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1080 //              scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1081 //              scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1082 //              scroll_layer_tree->add(*keyframe_tree);
1083 //              scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1084 //              //scroll_layer_tree->show();
1085 //
1086 //
1087 //              Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1088 //              layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1089 //
1090 //              Gtk::Image *icon;
1091 //              Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1092 //
1093 //              NEW_SMALL_BUTTON(button_add,"gtk-add",_("New Keyframe"));
1094 //              NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate Keyframe"));
1095 //              NEW_SMALL_BUTTON(button_delete,"gtk-delete",_("Delete Keyframe"));
1096 //
1097 //              Gtk::HBox *hbox(manage(new Gtk::HBox()));
1098 //              layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1099 //
1100 //              hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1101 //              hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1102 //              hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1103 //
1104 //              /*
1105 //              button_raise->set_relief(Gtk::RELIEF_HALF);
1106 //              button_lower->set_relief(Gtk::RELIEF_HALF);
1107 //              button_duplicate->set_relief(Gtk::RELIEF_HALF);
1108 //              button_delete->set_relief(Gtk::RELIEF_HALF);
1109 //              */
1110 //
1111 //              button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1112 //              button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1113 //              button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1114 //
1115 //              //layout_table->show_all();
1116 //
1117 //              keyframe_tab_child=layout_table;
1118 //
1119 //
1120 //              layout_table->hide();
1121 //
1122 //              return layout_table;
1123 //      }
1124
1125 //      Gtk::Widget*
1126 //      CanvasView::create_layer_tree()
1127 //      {
1128 //              // Create the layer tree
1129 //              printf("CanvasView::create_layer_tree()\n");
1130 //              layer_tree=manage(new class LayerTree());
1131 //
1132 //              // Set up the layer tree
1133 //              //layer_tree->set_model(layer_tree_store());
1134 //              layer_tree->set_time_adjustment(time_adjustment());
1135 //              layer_tree->show();
1136 //
1137 //              // Connect Signals
1138 //              layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1139 //              layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1140 //              layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1141 //              layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1142 //              layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1143 //              layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1144 //
1145 //              layer_tree->hide();
1146 //              return layer_tree;
1147 //      }
1148
1149 void
1150 CanvasView::init_menus()
1151 {
1152 /*
1153         mainmenu.set_accel_group(get_accel_group());
1154         mainmenu.set_accel_path("<Canvas-view>");
1155
1156         filemenu.set_accel_group(get_accel_group());
1157         filemenu.set_accel_path("<Canvas-view>/File");
1158
1159         editmenu.set_accel_group(get_accel_group());
1160         editmenu.set_accel_path("<Canvas-view>/Edit");
1161
1162         layermenu.set_accel_group(get_accel_group());
1163         layermenu.set_accel_path("<Canvas-view>/Layer");
1164 */
1165         //cache the position of desired widgets
1166
1167         /*Menus to worry about:
1168         - filemenu
1169         - editmenu
1170         - layermenu
1171         - duckmaskmenu
1172         - mainmenu
1173         - canvasmenu
1174         - viewmenu
1175         */
1176         action_group = Gtk::ActionGroup::create();
1177
1178         //action_group->add( Gtk::Action::create("MenuFile", _("_File")) );
1179         action_group->add( Gtk::Action::create("new", Gtk::Stock::NEW),
1180                 sigc::hide_return(sigc::ptr_fun(&studio::App::new_instance))
1181         );
1182         action_group->add( Gtk::Action::create("open", Gtk::Stock::OPEN),
1183                 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::open))
1184         );
1185         action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1186                 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1187         );
1188         action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1189                 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1190         );
1191         action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1192                 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1193         );
1194         action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1195                 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1196         );
1197         action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1198                 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1199         );
1200         action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1201                 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1202         );
1203         action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1204                 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1205         );
1206         action_group->add( Gtk::Action::create("import", _("Import")),
1207                 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1208         );
1209         action_group->add( Gtk::Action::create("render", _("Render")),
1210                 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1211         );
1212         action_group->add( Gtk::Action::create("preview", _("Preview")),
1213                 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1214         );
1215         action_group->add( Gtk::Action::create("sound", _("Sound File")),
1216                 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1217         );
1218         action_group->add( Gtk::Action::create("options", _("Options")),
1219                 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1220         );
1221         action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close"), _("Close Window")),
1222                 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1223         );
1224         action_group->add( Gtk::Action::create("close-document", Gtk::StockID("gtk-close"), _("Close Document")),
1225                 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_instance))
1226         );
1227         action_group->add( Gtk::Action::create("quit", Gtk::StockID("gtk-quit"), _("Quit")),
1228                 sigc::hide_return(sigc::ptr_fun(&studio::App::quit))
1229         );
1230
1231         //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1232         //      SLOT_EVENT(EVENT_UNDO)
1233         //);
1234
1235         //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1236         //      SLOT_EVENT(EVENT_REDO)
1237         //);
1238
1239         action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1240                 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1241         );
1242
1243         action_group->add( Gtk::Action::create("unselect-all-ducks", _("Unselect All Ducks")),
1244                 sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)
1245         );
1246
1247         action_group->add( Gtk::Action::create("select-all-layers", _("Select All Layers")),
1248                 sigc::mem_fun(*this,&CanvasView::on_select_layers)
1249         );
1250
1251         action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1252                 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1253         );
1254
1255         action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1256                 SLOT_EVENT(EVENT_STOP)
1257         );
1258
1259         action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1260                 SLOT_EVENT(EVENT_REFRESH)
1261         );
1262
1263         action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1264                 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1265         );
1266
1267         // Preview Quality Menu
1268         {
1269                 int i;
1270                 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1271                         sigc::bind(
1272                                 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1273                                 0
1274                         )
1275                 );
1276                 for(i=1;i<=10;i++)
1277                 {
1278                         String note;
1279                         if (i == 1) note = _(" (best)");
1280                         if (i == 10) note = _(" (fastest)");
1281                         Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i),
1282                                                                                                                                                    strprintf(_("Set Quality to %d"),i) + note));
1283                         if (i==8)                       // default quality
1284                         {
1285                                 action->set_active();
1286                                 work_area->set_quality(i);
1287                         }
1288                         action_group->add( action,
1289                                 sigc::bind(
1290                                         sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1291                                         i
1292                                 )
1293                         );
1294                 }
1295         }
1296
1297         // Low-Res Quality Menu
1298         {
1299                 int i;
1300                 for(list<int>::iterator iter = CanvasView::get_pixel_sizes().begin(); iter != CanvasView::get_pixel_sizes().end(); iter++)
1301                 {
1302                         i = *iter;
1303                         Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(low_res_pixel_size_group,strprintf("lowres-pixel-%d",i),
1304                                                                                                                                                    strprintf(_("Set Low-Res pixel size to %d"),i)));
1305                         if(i==2)                        // default pixel size
1306                         {
1307                                 action->set_active();
1308                                 work_area->set_low_res_pixel_size(i);
1309                         }
1310                         action_group->add( action,
1311                                 sigc::bind(
1312                                         sigc::mem_fun(*work_area, &studio::WorkArea::set_low_res_pixel_size),
1313                                         i
1314                                 )
1315                         );
1316                 }
1317
1318                 Glib::RefPtr<Gtk::Action> action;
1319
1320                 action=Gtk::Action::create("decrease-low-res-pixel-size", _("Decrease Low-Res Pixel Size"));
1321                 action_group->add( action,sigc::mem_fun(this, &studio::CanvasView::decrease_low_res_pixel_size));
1322
1323                 action=Gtk::Action::create("increase-low-res-pixel-size",  _("Increase Low-Res Pixel Size"));
1324                 action_group->add( action, sigc::mem_fun(this, &studio::CanvasView::increase_low_res_pixel_size));
1325
1326         }
1327
1328         action_group->add( Gtk::Action::create("play", Gtk::Stock::MEDIA_PLAY),
1329                 sigc::mem_fun(*this, &studio::CanvasView::play)
1330         );
1331
1332         action_group->add( Gtk::Action::create("dialog-flipbook", _("Flipbook Dialog")),
1333                 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1334         );
1335
1336         {
1337                 Glib::RefPtr<Gtk::ToggleAction> action;
1338
1339                 grid_show_toggle = Gtk::ToggleAction::create("toggle-grid-show", _("Show Grid"));
1340                 grid_show_toggle->set_active(work_area->grid_status());
1341                 action_group->add(grid_show_toggle, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid));
1342
1343                 grid_snap_toggle = Gtk::ToggleAction::create("toggle-grid-snap", _("Snap to Grid"));
1344                 grid_snap_toggle->set_active(work_area->get_grid_snap());
1345                 action_group->add(grid_snap_toggle, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap));
1346
1347                 action = Gtk::ToggleAction::create("toggle-guide-show", _("Show Guides"));
1348                 action->set_active(work_area->get_show_guides());
1349                 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap));
1350
1351                 action = Gtk::ToggleAction::create("toggle-low-res", _("Use Low-Res"));
1352                 action->set_active(work_area->get_low_resolution_flag());
1353                 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag));
1354
1355                 action = Gtk::ToggleAction::create("toggle-onion-skin", _("Show Onion Skin"));
1356                 action->set_active(work_area->get_onion_skin());
1357                 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_onion_skin));
1358         }
1359
1360         action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1361                 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1362         );
1363         action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1364                 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1365         );
1366
1367         {
1368                 Glib::RefPtr<Gtk::Action> action;
1369
1370                 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1371                 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1372                 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1373                 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1374
1375                 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Forward"),_("Seek Forward"));
1376                 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1377                 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1378                 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1379
1380                 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1381                 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1382
1383                 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1384                 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1385
1386                 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1387                 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1388
1389                 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1390                 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1391
1392                 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1393                 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1394
1395                 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1396                 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1397
1398                 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1399                 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1400
1401                 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1402                 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1403
1404         }
1405
1406         {
1407                 Glib::RefPtr<Gtk::ToggleAction> action;
1408
1409 #define DUCK_MASK(lower,upper,string)                                                                                           \
1410                 action=Gtk::ToggleAction::create("mask-" #lower "-ducks", string);                      \
1411                 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper));      \
1412                 action_group->add(action,                                                                                                       \
1413                         sigc::bind(                                                                                                                             \
1414                                 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),            \
1415                                 Duck::TYPE_##upper))
1416
1417                 DUCK_MASK(position,POSITION,_("Show Position Ducks"));
1418                 DUCK_MASK(tangent,TANGENT,_("Show Tangent Ducks"));
1419                 DUCK_MASK(vertex,VERTEX,_("Show Vertex Ducks"));
1420                 DUCK_MASK(radius,RADIUS,_("Show Radius Ducks"));
1421                 DUCK_MASK(width,WIDTH,_("Show Width Ducks"));
1422                 DUCK_MASK(angle,ANGLE,_("Show Angle Ducks"));
1423
1424 #undef DUCK_MASK
1425         }
1426
1427         add_accel_group(App::ui_manager()->get_accel_group());
1428
1429 /*      // Here is where we add the actions that may have conflicting
1430         // keyboard accelerators.
1431         {
1432                 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1433                 Glib::RefPtr<Gtk::Action> action;
1434
1435                 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1436                 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1437
1438                 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1439                 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1440
1441                 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1442                 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1443
1444                 action=Gtk::Action::create("jump-prev-keyframe", Gtk::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1445                 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1446
1447                 action=Gtk::Action::create("canvas-zoom-in", Gtk::StockID("gtk-zoom-in"));
1448                 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1449
1450                 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1451                 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1452
1453                 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1454                 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1455
1456                 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1457                 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1458
1459                 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1460
1461                 Glib::ustring ui_info =
1462                 "
1463                 <ui>
1464                         <accelerator action='seek-next-frame' />
1465                         <accelerator action='seek-prev-frame' />
1466                         <accelerator action='jump-next-keyframe' />
1467                         <accelerator action='jump-prev-keyframe' />
1468                         <accelerator action='canvas-zoom-in' />
1469                         <accelerator action='canvas-zoom-out' />
1470                         <accelerator action='time-zoom-in' />
1471                         <accelerator action='time-zoom-out' />
1472                 </ui>
1473                 ";
1474
1475                 accel_ui_manager->add_ui_from_string(ui_info);
1476                 add_accel_group(accel_ui_manager->get_accel_group());
1477
1478                 accel_ui_manager->insert_action_group(accel_action_group);
1479                 set_ref_obj("accel_ui_manager",accel_ui_manager);
1480                 set_ref_obj("accel_action_group",accel_action_group);
1481         }
1482 */
1483
1484 #if 0
1485 //
1486 //      //Test some key stuff
1487 //
1488 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1489 //              hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1490 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save-as"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_save_as))));
1491 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-revert-to-saved"),hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))));
1492 //      filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1493 //
1494 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_add"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))));
1495 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_update"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))));
1496 //      filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_commit"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))));
1497 //
1498 //      filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1499 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Import..."),Gtk::AccelKey('I',Gdk::CONTROL_MASK),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))));
1500 //      filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1501 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1502 //              sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1503 //      ));
1504 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1505 //              sigc::mem_fun(*this,&CanvasView::on_preview_option)
1506 //      ));
1507 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1508 //              sigc::mem_fun(*this,&CanvasView::on_audio_option)
1509 //      ));
1510 //
1511 //      filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1512 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1513 //              sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1514 //      ));
1515 //      filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1516 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close View"),
1517 //              sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1518 //      ));
1519 //      filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close Document"),
1520 //              sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_document))
1521 //      ));
1522 //
1523 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1524 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1525 //      editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1526 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1527 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1528 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1529 //      editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1530 //      editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Ducks"),Gtk::AccelKey('E',Gdk::CONTROL_MASK),sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)));
1531 //      editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Unselect All Ducks"),Gtk::AccelKey('E',Gdk::CONTROL_MASK),sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)));
1532 //      editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Layers"),Gtk::AccelKey('A',Gdk::CONTROL_MASK),sigc::mem_fun(*this,&CanvasView::on_select_layers)));
1533 //      editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Unselect All Layers"),Gtk::AccelKey('D',Gdk::CONTROL_MASK),sigc::mem_fun(*this,&CanvasView::on_unselect_layers)));
1534 //      editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1535 //
1536 //      //editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-stop"),Gtk::AccelKey(GDK_Escape,static_cast<Gdk::ModifierType>(0)),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::stop))));
1537 //      //editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed))));
1538 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-stop"),Gtk::AccelKey(GDK_Escape,static_cast<Gdk::ModifierType>(0)),SLOT_EVENT(EVENT_STOP)));
1539 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1540 //      editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1541 //      editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1542 //              sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1543 //      ));
1544 //
1545 //      build_new_layer_menu(newlayermenu);
1546 //      layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New"),newlayermenu));
1547 //
1548 //
1549 //      {
1550 //              synfigapp::Action::ParamList param_list;
1551 //              param_list.add("canvas",Canvas::Handle(get_canvas()));
1552 //              param_list.add("canvas_interface",canvas_interface());
1553 //              add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1554 //      }
1555 //
1556 //
1557 //      //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Keyframe Dialog"),sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1558 //
1559 //      // Duck Mask Menu
1560 //      if(1)
1561 //              {
1562 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1563 //
1564 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1565 //              duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1566 //              duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1567 //              duck_mask_position->signal_toggled().connect(
1568 //                      sigc::bind(
1569 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1570 //                              Duck::TYPE_POSITION
1571 //                      )
1572 //              );
1573 //
1574 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1575 //              duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1576 //              duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1577 //              duck_mask_vertex->signal_toggled().connect(
1578 //                      sigc::bind(
1579 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1580 //                              Duck::TYPE_VERTEX
1581 //                      )
1582 //              );
1583 //
1584 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1585 //              duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1586 //              duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1587 //              duck_mask_tangent->signal_toggled().connect(
1588 //                      sigc::bind(
1589 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1590 //                              Duck::TYPE_TANGENT
1591 //                      )
1592 //              );
1593 //
1594 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1595 //              duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1596 //              duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1597 //              duck_mask_radius->signal_toggled().connect(
1598 //                      sigc::bind(
1599 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1600 //                              Duck::TYPE_RADIUS
1601 //                      )
1602 //              );
1603 //
1604 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1605 //              duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1606 //              duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1607 //              duck_mask_width->signal_toggled().connect(
1608 //                      sigc::bind(
1609 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1610 //                              Duck::TYPE_WIDTH
1611 //                      )
1612 //              );
1613 //
1614 //              duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1615 //              duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1616 //              duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1617 //              duck_mask_angle->signal_toggled().connect(
1618 //                      sigc::bind(
1619 //                              sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1620 //                              Duck::TYPE_ANGLE
1621 //                      )
1622 //              );
1623 //
1624 //              viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1625 //      }
1626 //
1627 //      // Preview Quality Menu
1628 //      if(1)
1629 //      {
1630 //              qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1631 //              int i;
1632 //              qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1633 //                      sigc::bind(
1634 //                              sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1635 //                              0
1636 //                      )
1637 //              ));
1638 //              for(i=1;i<=10;i++)
1639 //              {
1640 //                      qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1641 //                              sigc::bind(
1642 //                                      sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1643 //                                      i
1644 //                              )
1645 //                      ));
1646 //              }
1647 //              viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1648 //      }
1649 //
1650 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::MEDIA_PLAY,
1651 //              sigc::mem_fun(*this, &studio::CanvasView::play)));
1652 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1653 //              sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1654 //
1655 //      viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1656 //
1657 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1658 //              sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1659 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1660 //              sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1661 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1662 //              sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1663 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1664 //              sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1665 //
1666 //      viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1667 //
1668 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1669 //              sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1670 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1671 //              sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1672 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1673 //              sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1674 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1675 //              sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
1676 //      viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1677 //
1678 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('+',static_cast<Gdk::ModifierType>(0)),
1679 //              sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in)));
1680 //      viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('_',static_cast<Gdk::ModifierType>(0)),
1681 //              sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out)));
1682 //
1683 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1684 //              sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1685 //      viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1686 //              sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1687 //
1688 //      mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1689 //      mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_File"),filemenu));
1690 //      mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),editmenu));
1691 //      mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_View"),viewmenu));
1692 //      mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Canvas"),canvasmenu));
1693 //      mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Layer"),layermenu));
1694 //
1695 //      mainmenu.accelerate(*this);
1696 //
1697 ///*
1698 //      {
1699 //
1700 //              trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Waypoint"),NOT_IMPLEMENTED_SLOT));
1701 //              trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Delete Waypoint"),NOT_IMPLEMENTED_SLOT));
1702 //              trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Export"),NOT_IMPLEMENTED_SLOT));
1703 //              trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1704 //              trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Properties"),NOT_IMPLEMENTED_SLOT));
1705 //      }
1706 //*/
1707 //      mainmenu.show();
1708 //      filemenu.show();
1709 //      editmenu.show();
1710 //      canvasmenu.show();
1711 //      layermenu.show();
1712 //
1713 //      keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1714 //              sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1715 //      ));
1716 //
1717 //
1718 //      get_accel_group()->unlock();
1719 //
1720 //      //Set the accelerator paths for all the menus
1721 //      filemenu.set_accel_path("<synfig>/File");
1722 //      editmenu.set_accel_path("<synfig>/Edit");
1723 //      layermenu.set_accel_path("<synfig>/Layer");
1724 //      //mainmenu.set_accel_path("<synfig-main>");
1725 //      canvasmenu.set_accel_path("<synfig>/Canvas");
1726 //      viewmenu.set_accel_path("<synfig>/View");
1727 //      duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1728 #endif
1729 }
1730
1731 void
1732 CanvasView::on_select_layers()
1733 {
1734         Canvas::Handle canvas(get_canvas());
1735         for (CanvasBase::iterator iter = canvas->begin(); iter != canvas->end(); iter++)
1736                 layer_tree->select_all_children_layers(*iter);
1737 }
1738
1739 void
1740 CanvasView::on_unselect_layers()
1741 {
1742         layer_tree->clear_selected_layers();
1743 }
1744
1745 void
1746 CanvasView::show_keyframe_dialog()
1747 {
1748         Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
1749         if(selection->get_selected())
1750         {
1751                 Gtk::TreeRow row(*selection->get_selected());
1752
1753                 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
1754
1755                 keyframe_dialog.set_keyframe(keyframe);
1756                 keyframe_dialog.present();
1757         }
1758 }
1759
1760 void
1761 CanvasView::add_layer(synfig::String x)
1762 {
1763         Canvas::Handle canvas;
1764
1765         synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1766
1767         int target_depth(0);
1768
1769         if(layer_list.empty())
1770         {
1771                 canvas=get_canvas();
1772         }
1773         else
1774         {
1775                 canvas=(*layer_list.begin())->get_canvas();
1776                 target_depth=canvas->get_depth(*layer_list.begin());
1777         }
1778
1779         Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
1780         if(layer)
1781         {
1782                 get_selection_manager()->clear_selected_layers();
1783                 get_selection_manager()->set_selected_layer(layer);
1784         }
1785 }
1786
1787 void
1788 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
1789 {
1790         //Gtk::Menu* menu(manage(new Gtk::Menu));
1791         Gtk::Menu* menu(&parammenu);
1792         menu->items().clear();
1793
1794         synfigapp::Action::ParamList param_list;
1795         param_list.add("time",canvas_interface()->get_time());
1796         param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
1797         param_list.add("canvas_interface",canvas_interface());
1798         param_list.add("layer",layer);
1799
1800         //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
1801         //build_new_layer_menu(*newlayers);
1802
1803         //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
1804
1805         if(layer->get_name()=="PasteCanvas")
1806         {
1807                 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
1808                         sigc::bind(
1809                                 sigc::mem_fun(
1810                                         *layer_tree,
1811                                         &studio::LayerTree::select_all_children_layers
1812                                 ),
1813                                 layer
1814                         )
1815                 ));
1816         }
1817
1818         add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
1819
1820         menu->popup(3,gtk_get_current_event_time());
1821 }
1822
1823 void
1824 CanvasView::register_layer_type(synfig::Layer::Book::value_type &/*lyr*/,std::map<synfig::String,Gtk::Menu*>* /*category_map*/)
1825 {
1826 /*      if(lyr.second.category==CATEGORY_DO_NOT_USE)
1827                 return;
1828
1829         if(category_map->count(lyr.second.category)==0)
1830                 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
1831
1832         (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
1833                 sigc::hide_return(
1834                         sigc::bind(
1835                                 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
1836                                 lyr.first
1837                         )
1838                 )
1839         ));
1840 */
1841 }
1842
1843 void
1844 CanvasView::build_new_layer_menu(Gtk::Menu &/*menu*/)
1845 {
1846 /*
1847         std::map<synfig::String,Gtk::Menu*> category_map;
1848
1849         std::for_each(
1850                 synfig::Layer::book().begin(),
1851                 synfig::Layer::book().end(),
1852                 sigc::bind(
1853                         sigc::mem_fun(
1854                                 *this,
1855                                 &studio::CanvasView::register_layer_type
1856                         ),
1857                         &category_map
1858                 )
1859         );
1860
1861         menu.items().clear();
1862         menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1863
1864         std::map<synfig::String,Gtk::Menu*>::iterator iter;
1865         for(iter=category_map.begin();iter!=category_map.end();++iter)
1866                 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
1867
1868         menu.show();
1869 */
1870 }
1871
1872 void
1873 CanvasView::popup_main_menu()
1874 {
1875         //mainmenu.popup(0,gtk_get_current_event_time());
1876         Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
1877         if(menu)
1878         {
1879                 //menu->set_accel_group(App::ui_manager()->get_accel_group());
1880                 //menu->accelerate(*this);
1881                 menu->popup(0,gtk_get_current_event_time());
1882         }
1883 }
1884
1885 void
1886 CanvasView::on_refresh_pressed()
1887 {
1888         rebuild_tables();
1889         rebuild_ducks();
1890         work_area->queue_render_preview();
1891 }
1892
1893 void
1894 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
1895 {
1896         get_selection_manager()->clear_selected_layers();
1897         if(layer)
1898                 get_selection_manager()->set_selected_layer(layer);
1899 }
1900
1901 void
1902 CanvasView::refresh_rend_desc()
1903 {
1904         current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1905
1906         //????
1907         //synfig::info("Canvasview: Refreshing render desc info");
1908         if(!get_time().is_equal(time_adjustment().get_value()))
1909         {
1910                 time_adjustment().set_value(get_time());
1911                 time_adjustment().value_changed();
1912         }
1913
1914         Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1915         if(length<DEFAULT_TIME_WINDOW_SIZE)
1916         {
1917                 time_window_adjustment().set_page_increment(length);
1918                 time_window_adjustment().set_page_size(length);
1919         }
1920         else
1921         {
1922                 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
1923                 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
1924         }
1925
1926         //set the FPS of the timeslider
1927         timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
1928
1929         //set the beginning and ending time of the time slider
1930         Time begin_time=get_canvas()->rend_desc().get_time_start();
1931         Time end_time=get_canvas()->rend_desc().get_time_end();
1932
1933         // Setup the time_window adjustment
1934         time_window_adjustment().set_lower(begin_time);
1935         time_window_adjustment().set_upper(end_time);
1936         time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1937
1938         //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1939         if(length < time_window_adjustment().get_page_size())
1940         {
1941                 time_window_adjustment().set_page_increment(length);
1942                 time_window_adjustment().set_page_size(length);
1943         }
1944
1945         /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1946                                 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1947                                 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1948                                 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1949         );*/
1950
1951         time_window_adjustment().changed(); //only non-value stuff was changed
1952
1953         // Setup the time adjustment
1954
1955         //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
1956         //time_adjustment().set_lower(time_window_adjustment().get_value());
1957         //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
1958
1959 //      time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
1960 //      time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
1961         time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1962         time_adjustment().set_page_increment(synfig::Time(1.0));
1963         time_adjustment().set_page_size(0);
1964
1965         time_adjustment().changed();
1966
1967         /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1968                                 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1969                                 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1970                                 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1971         );      */
1972
1973         if(begin_time==end_time)
1974         {
1975                 hide_timebar();
1976         }
1977         else
1978         {
1979                 show_timebar();
1980         }
1981
1982         //clamp time to big bounds...
1983         if(time_window_adjustment().get_value() < begin_time)
1984         {
1985                 time_window_adjustment().set_value(begin_time);
1986                 time_window_adjustment().value_changed();
1987         }
1988
1989         if(time_window_adjustment().get_value() + time_window_adjustment().get_page_size() > end_time)
1990         {
1991                 time_window_adjustment().set_value(end_time - time_window_adjustment().get_page_size());
1992                 time_window_adjustment().value_changed();
1993         }
1994
1995         if(time_adjustment().get_value() < begin_time)
1996         {
1997                 time_adjustment().set_value(begin_time);
1998                 time_adjustment().value_changed();
1999         }
2000
2001         if(time_adjustment().get_value() > end_time)
2002         {
2003                 time_adjustment().set_value(end_time);
2004                 time_adjustment().value_changed();
2005         }
2006
2007         /*synfig::info("Time stats: \n"
2008                                 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
2009                                 "t: %p - [%.3f,%.3f] %.3f",
2010                                 &time_window_adjustment_, time_window_adjustment_.get_lower(),
2011                                 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2012                                 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
2013                                 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
2014                                 time_adjustment_.get_value()
2015         );*/
2016
2017         work_area->queue_render_preview();
2018 }
2019
2020 bool
2021 CanvasView::close_view()
2022 {
2023         if(get_instance()->get_visible_canvases()==1)
2024                 close_instance();
2025         else
2026                 hide();
2027         return false;
2028 }
2029
2030 static bool _close_instance(etl::handle<Instance> instance)
2031 {
2032         etl::handle<Instance> argh(instance);
2033         instance->safe_close();
2034         synfig::info("closed");
2035         return false;
2036 }
2037
2038 bool
2039 CanvasView::close_instance()
2040 {
2041 #ifdef SINGLE_THREADED
2042         if (get_work_area()->get_updating())
2043         {
2044                 get_work_area()->stop_updating(true); // stop and mark as cancelled
2045
2046                 // give the workarea chances to stop updating
2047                 Glib::signal_timeout().connect(
2048                         sigc::mem_fun(*this, &CanvasView::close_instance),
2049                         250);
2050         }
2051         else
2052 #endif
2053                 Glib::signal_timeout().connect(
2054                         sigc::bind(sigc::ptr_fun(_close_instance),
2055                                            (etl::handle<Instance>)get_instance()),
2056                         250);
2057         return false;
2058 }
2059
2060 handle<CanvasView>
2061 CanvasView::create(etl::loose_handle<Instance> instance, etl::handle<synfig::Canvas> canvas)
2062 {
2063         etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
2064         instance->canvas_view_list().push_front(view);
2065         instance->signal_canvas_view_created()(view.get());
2066         return view;
2067 }
2068
2069 void
2070 CanvasView::update_title()
2071 {
2072         string title;
2073
2074         title = strprintf("%s%s\"%s\"",
2075                                           (
2076                                                   get_instance()->get_action_count()
2077                                                   ? "*"
2078                                                   : ""
2079                                           ), (
2080                                                   get_instance()->has_real_filename()
2081                                                   ? (etl::basename(get_instance()->get_file_name()) + " : ").c_str()
2082                                                   : ""
2083                                           ), (
2084                                                   get_canvas()->get_name().empty()
2085                                                   ? get_canvas()->get_id().c_str()
2086                                                   : get_canvas()->get_name().c_str()
2087                                           ));
2088
2089         if(get_instance()->synfigapp::Instance::in_repository())
2090         {
2091                 title+=" (CVS";
2092                 if(get_instance()->synfigapp::Instance::is_modified())
2093                         title+=_("-MODIFIED");
2094                 if(get_instance()->synfigapp::Instance::is_updated())
2095                         title+=_("-UPDATED");
2096                 title+=')';
2097         }
2098
2099         if(get_canvas()->is_root())
2100                 title+=_(" (Root)");
2101
2102         set_title(title);
2103 }
2104
2105 void
2106 CanvasView::on_hide()
2107 {
2108         smach_.egress();
2109         Gtk::Window::on_hide();
2110 }
2111
2112 void
2113 CanvasView::present()
2114 {
2115         grab_focus();//on_focus_in_event(0);
2116         Gtk::Window::present();
2117 }
2118
2119 bool
2120 CanvasView::on_focus_in_event(GdkEventFocus*x)
2121 {
2122         if(studio::App::get_selected_canvas_view()!=this)
2123         {
2124                 if(studio::App::get_selected_canvas_view())
2125                 {
2126                         studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2127                         App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2128                 }
2129
2130                 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2131
2132                 studio::App::set_selected_canvas_view(this);
2133
2134                 App::ui_manager()->insert_action_group(action_group);
2135         }
2136
2137         // HACK ... Questionable...?
2138         if(x)
2139                 return Gtk::Window::on_focus_in_event(x);
2140
2141         return true;
2142 }
2143
2144 bool
2145 CanvasView::on_focus_out_event(GdkEventFocus*x)
2146 {
2147         //App::ui_manager()->remove_action_group(action_group);
2148         //App::ui_manager()->ensure_update();
2149         return Gtk::Window::on_focus_out_event(x);
2150 }
2151
2152 void
2153 CanvasView::refresh_tables()
2154 {
2155 //      if(layer_tree_store_)layer_tree_store_->refresh();
2156 //      if(children_tree_store_)children_tree_store_->refresh();
2157 }
2158
2159 void
2160 CanvasView::rebuild_tables()
2161 {
2162 //      layer_tree_store_->rebuild();
2163 //      children_tree_store_->rebuild();
2164 }
2165
2166 void
2167 CanvasView::build_tables()
2168 {
2169 //      layer_tree_store_->rebuild();
2170 //      children_tree_store_->rebuild();
2171 }
2172
2173 void
2174 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2175 {
2176         synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2177         assert(action);
2178
2179         if(!action)
2180                 return;
2181
2182         action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2183         if(!action->set_param("canvas_interface",canvas_interface()))
2184 //      if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2185                 synfig::error("LayerActivate didn't like CanvasInterface...?");
2186         action->set_param("time",get_time());
2187         action->set_param("layer",layer);
2188         action->set_param("new_status",!layer->active());
2189
2190         assert(action->is_ready());
2191
2192         canvas_interface()->get_instance()->perform_action(action);
2193 }
2194
2195 void
2196 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location, bool bezier)
2197 {
2198         parammenu.items().clear();
2199         get_instance()->make_param_menu(&parammenu,get_canvas(),value_desc,location,bezier);
2200
2201         parammenu.popup(3,gtk_get_current_event_time());
2202 }
2203
2204 void
2205 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList &param_list,synfigapp::Action::Category category)const
2206 {
2207         get_instance()->add_actions_to_menu(menu, param_list, category);
2208 }
2209
2210 bool
2211 CanvasView::on_layer_user_click(int button, Gtk::TreeRow /*row*/, LayerTree::ColumnID /*column_id*/)
2212 {
2213         switch(button)
2214         {
2215         case 3:
2216                 {
2217                         Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2218                         if(menu && menu->get_submenu())
2219                         {
2220                                 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2221                                 //menu->accelerate(*this);
2222                                 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2223                         }
2224
2225                         #if 0
2226                         bool multiple_selected=true;
2227
2228                         if(layer_tree->get_selection()->count_selected_rows()<=1)
2229                                 multiple_selected=false;
2230
2231                         // If the clicked row is not selected, then unselect
2232                         // everything that isn't selected and select this row
2233                         if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2234                         {
2235                                 layer_tree->get_selection()->unselect_all();
2236                                 layer_tree->get_selection()->select(row);
2237                                 multiple_selected=false;
2238                         }
2239
2240                         if(column_id==COLUMNID_TIME_TRACK)
2241                                 return false;
2242
2243                         //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2244                         //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2245                         //ValueNode::Handle parent_value_node;
2246                         //ValueBase value=row[layer_param_tree_model.value];
2247
2248                         //if(row.parent())
2249                         //{
2250                         //      parent_value_node=(*row.parent())[layer_tree_model.value_node];
2251                         //}
2252
2253                         {
2254                                 Layer::Handle layer(row[layer_tree_model.layer]);
2255                                 synfigapp::Action::ParamList param_list;
2256                                 param_list.add("time",canvas_interface()->get_time());
2257                                 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2258                                 param_list.add("canvas_interface",canvas_interface());
2259                                 if(!multiple_selected)
2260                                         param_list.add("layer",layer);
2261                                 else
2262                                 {
2263                                         synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2264                                         synfigapp::SelectionManager::LayerList::iterator iter;
2265
2266                                         for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2267                                                 param_list.add("layer",Layer::Handle(*iter));
2268                                 }
2269
2270                                 parammenu.items().clear();
2271
2272                                 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2273                                 // do we need this?  the code is all #ifdef'ed out anyway
2274                                 // newlayers->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), newlayers));
2275                                 build_new_layer_menu(*newlayers);
2276
2277                                 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
2278                                 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2279                                 {
2280                                         parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2281                                                 sigc::bind(
2282                                                         sigc::mem_fun(
2283                                                                 *layer_tree,
2284                                                                 &studio::LayerTree::select_all_children_layers
2285                                                         ),
2286                                                         layer
2287                                                 )
2288                                         ));
2289                                 }
2290
2291                                 add_actions_to_menu(&parammenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2292                                 parammenu.popup(button,gtk_get_current_event_time());
2293                                 return true;
2294                         }
2295 /*
2296                         else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2297                         {
2298                                 // Right-click on time track with animated
2299 //                              trackmenu.popup(0,0);
2300                                 return true;
2301                         }
2302                         else
2303                         {
2304                                 if(!multiple_selected)
2305                                 {
2306                                         popup_param_menu(value_desc);
2307                                         return true;
2308                                 }
2309                                 else
2310                                 {
2311 #warning update me!
2312 #if 0
2313                                         parammenu.items().clear();
2314                                         parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Connect"),
2315                                                 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2316                                         ));
2317                                         parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Disconnect"),
2318                                                 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2319                                         ));
2320                                         parammenu.popup(0,0);
2321 #endif
2322                                 }
2323                                 return true;
2324                         }
2325                 */
2326 #endif
2327 }
2328                 return true;
2329                 break;
2330
2331         default:
2332                 return false;
2333                 break;
2334         }
2335 }
2336
2337 bool
2338 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2339 {
2340         switch(button)
2341         {
2342         case 3:
2343                 {
2344                         if(column_id==COLUMNID_TIME_TRACK)
2345                                 return false;
2346                         if(!(bool)row[children_tree_model.is_canvas])
2347                         {
2348                                 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2349                                 if (!value_desc)
2350                                 {
2351                                         //! \todo fix properly -- what is the child dialog for?
2352                                         synfig::info("preventing child dialog right-click crash");
2353                                         return true;
2354                                 }
2355                                 assert(value_desc);
2356                                 popup_param_menu(value_desc);
2357                                 return true;
2358                         }
2359                 }
2360                 return true;
2361                 break;
2362
2363         default:
2364                 return false;
2365                 break;
2366         }
2367 }
2368
2369 bool
2370 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2371 {
2372     switch(event->type)
2373     {
2374         case GDK_BUTTON_PRESS:
2375                 switch(event->button.button)
2376                 {
2377                         case 3:
2378                         {
2379                                 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2380                                 return true;
2381                         }
2382                         break;
2383                 }
2384                 break;
2385         case GDK_MOTION_NOTIFY:
2386                 break;
2387         case GDK_BUTTON_RELEASE:
2388                 break;
2389         default:
2390                 break;
2391         }
2392         return false;
2393 }
2394
2395 void
2396 CanvasView::refresh_time_window()
2397 {
2398         //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2399         //time_adjustment().set_lower(time_window_adjustment().get_value());
2400         //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2401
2402         time_adjustment().set_page_increment(1.0); // One second
2403         time_adjustment().set_page_size(0);
2404
2405         if(get_canvas())
2406                 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2407         time_adjustment().changed();
2408
2409         //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2410         if(children_tree)
2411                 children_tree->queue_draw();
2412 }
2413
2414 void
2415 CanvasView::on_time_changed()
2416 {
2417         Time time(get_time());
2418
2419         current_time_widget->set_value(time);
2420         try {
2421                 get_canvas()->keyframe_list().find(time);
2422                 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2423         }catch(...){
2424                 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2425         }
2426
2427         if(get_time() != time_adjustment().get_value())
2428         {
2429                 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2430                 if(time < time_window_adjustment().get_value() ||
2431                         time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2432                 {
2433                         time_window_adjustment().set_value(
2434                                 time-time_window_adjustment().get_page_size()/2
2435                         );
2436                 }
2437                 time_adjustment().set_value(time);
2438                 time_adjustment().value_changed();
2439
2440                 // Shouldn't these trees just hook into
2441                 // the time changed signal...?
2442                 //YES THEY SHOULD...
2443                 if(layer_tree)layer_tree->queue_draw();
2444                 if(children_tree)children_tree->queue_draw();
2445         }
2446 }
2447
2448 void
2449 CanvasView::time_zoom_in()
2450 {
2451         float frame_rate = get_canvas()->rend_desc().get_frame_rate();
2452         Time min_page_size = 2/frame_rate;
2453
2454         time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2455         if (time_window_adjustment().get_page_size() < min_page_size)
2456                 time_window_adjustment().set_page_size(min_page_size);
2457         time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2458         time_window_adjustment().changed();
2459
2460         refresh_time_window();
2461 }
2462
2463 void
2464 CanvasView::time_zoom_out()
2465 {
2466         Time length = (get_canvas()->rend_desc().get_time_end() -
2467                                    get_canvas()->rend_desc().get_time_start());
2468
2469         time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2470         if (time_window_adjustment().get_page_size() > length)
2471                 time_window_adjustment().set_page_size(length);
2472         time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2473         time_window_adjustment().changed();
2474
2475         refresh_time_window();
2476 }
2477
2478 void
2479 CanvasView::time_was_changed()
2480 {
2481         synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2482         set_time(time);
2483 }
2484
2485 void
2486 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2487 {
2488         canvas_interface()->change_value(value_desc,new_value);
2489 }
2490
2491 /*
2492 void
2493 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2494 {
2495         Gtk::TreePath path(path_string);
2496
2497         const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2498
2499         assert((bool)row[children_tree_model.is_value_node]);
2500
2501         synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2502         assert(value_desc);
2503
2504         on_edited_value(value_desc,value);
2505 }
2506 */
2507
2508 void
2509 CanvasView::on_id_changed()
2510 {
2511         update_title();
2512 }
2513
2514 void
2515 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2516 {
2517         // If the animate flag was set in mode...
2518         if(mode&synfigapp::MODE_ANIMATE)
2519         {
2520                 Gtk::Image *icon;
2521                 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2522                 animatebutton->remove();
2523                 animatebutton->add(*icon);
2524                 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2525                 icon->set_padding(0,0);
2526                 icon->show();
2527         }
2528         else
2529         {
2530                 Gtk::Image *icon;
2531                 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2532                 animatebutton->remove();
2533                 animatebutton->add(*icon);
2534                 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2535                 icon->set_padding(0,0);
2536                 icon->show();
2537         }
2538
2539         if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2540         {
2541                 Gtk::Image *icon;
2542                 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2543                 keyframebutton->remove();
2544                 keyframebutton->add(*icon);
2545                 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2546                 icon->set_padding(0,0);
2547                 icon->show();
2548         }
2549         else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2550         {
2551                 Gtk::Image *icon;
2552                 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2553                 keyframebutton->remove();
2554                 keyframebutton->add(*icon);
2555                 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2556                 icon->set_padding(0,0);
2557                 icon->show();
2558         }
2559         else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2560         {
2561                 Gtk::Image *icon;
2562                 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2563                 keyframebutton->remove();
2564                 keyframebutton->add(*icon);
2565                 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2566                 icon->set_padding(0,0);
2567                 icon->show();
2568         }
2569         else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2570         {
2571                 Gtk::Image *icon;
2572                 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2573                 keyframebutton->remove();
2574                 keyframebutton->add(*icon);
2575                 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2576                 icon->set_padding(0,0);
2577                 icon->show();
2578         }
2579
2580         work_area->queue_draw();
2581 }
2582
2583 void
2584 CanvasView::on_animate_button_pressed()
2585 {
2586         if(get_mode()&synfigapp::MODE_ANIMATE)
2587                 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2588         else
2589                 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2590 }
2591
2592 void
2593 CanvasView::on_keyframe_button_pressed()
2594 {
2595         synfigapp::CanvasInterface::Mode mode(get_mode());
2596
2597         //   future && past   -->             past
2598         if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2599                 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2600         //             past   -->   future
2601         else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2602                 set_mode((get_mode()-synfigapp::MODE_ANIMATE_PAST)|synfigapp::MODE_ANIMATE_FUTURE);
2603         //   future           -->       (nothing)
2604         else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2605                 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2606         //      (nothing)     -->   future && past
2607         else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2608                 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2609 }
2610
2611 bool
2612 CanvasView::duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2613 {
2614         return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2615 }
2616
2617 bool
2618 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2619 {
2620         if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
2621         {
2622                 Real old_width((*bline_width)(get_time()).get(Real()));
2623                 Real new_width(value.mag());
2624                 int scale_index(bline_width->get_link_index_from_name("scale"));
2625                 Real scale((*(bline_width->get_link(scale_index)))(get_time()).get(Real()));
2626                 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_width,scale_index), new_width * scale / old_width);
2627         }
2628
2629         if (ValueNode_BLineCalcVertex::Handle bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
2630         {
2631                 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")));
2632                 Real radius = 0.0;
2633                 Real amount = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
2634                 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount);
2635         }
2636
2637         if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2638         {
2639                 switch(value_desc.get_value_type())
2640                 {
2641                 case ValueBase::TYPE_REAL:
2642                 {
2643                         Real old_length = (*bline_tangent)(get_time()).get(Real());
2644                         Real new_length = value.mag();
2645                         int scale_index(bline_tangent->get_link_index_from_name("scale"));
2646                         int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2647                         Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2648                         bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2649                         if (fixed_length)
2650                                 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length);
2651                         if (old_length == 0)
2652                                 return true;
2653                         return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length);
2654                 }
2655
2656                 case ValueBase::TYPE_ANGLE:
2657                         assert(0);                      // doesn't happen?
2658                         break;
2659
2660                 case ValueBase::TYPE_VECTOR:
2661                 {
2662                         Vector old_tangent = (*bline_tangent)(get_time()).get(Vector());
2663                         Angle old_angle = old_tangent.angle();
2664                         Real old_length = old_tangent.mag();
2665                         Angle new_angle = value.angle();
2666                         Real new_length = value.mag();
2667                         int offset_index(bline_tangent->get_link_index_from_name("offset"));
2668                         int scale_index(bline_tangent->get_link_index_from_name("scale"));
2669                         int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2670                         Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2671                         Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2672                         bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2673                         if (fixed_length)
2674                         {
2675                                 if (!(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length)))
2676                                         return false;
2677                         }
2678                         else if (old_length != 0 && !(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length)))
2679                                 return false;
2680                         return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + new_angle - old_angle);
2681                 }
2682                 default:
2683                         break;
2684                 }
2685         }
2686
2687         switch(value_desc.get_value_type())
2688         {
2689         case ValueBase::TYPE_REAL:
2690                 return canvas_interface()->change_value(value_desc,value.mag());
2691         case ValueBase::TYPE_ANGLE:
2692                 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2693         default:
2694                 return canvas_interface()->change_value(value_desc,value);
2695         }
2696 }
2697
2698 bool
2699 CanvasView::on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc)
2700 {
2701         if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2702         {
2703                 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2704                 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2705                 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + rotation);
2706         }
2707
2708         // \todo will this really always be the case?
2709         assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
2710         return canvas_interface()->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
2711 }
2712
2713 void
2714 CanvasView::selected_layer_color_set(synfig::Color color)
2715 {
2716         synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2717         synfigapp::SelectionManager::LayerList::iterator iter;
2718
2719         // Create the action group
2720         //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2721
2722         Layer::Handle layer;
2723         for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2724         {
2725                 if(*iter==layer)
2726                         continue;
2727                 layer=*iter;
2728                 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2729         }
2730 }
2731
2732 void
2733 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2734 {
2735         int transforms(0);
2736         String layer_name;
2737
2738 #define QUEUE_REBUILD_DUCKS             sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2739
2740         if(!canvas)
2741         {
2742                 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2743                 return;
2744         }
2745         for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2746         {
2747                 Layer::Handle layer(*iter);
2748
2749                 if(selected_list.count(layer))
2750                 {
2751                         if(!curr_transform_stack_set)
2752                         {
2753                                 curr_transform_stack_set=true;
2754                                 curr_transform_stack=transform_stack;
2755                         }
2756
2757                         // This layer is currently selected.
2758                         duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2759
2760                         // do the bounding box thing
2761                         bbox|=transform_stack.perform(layer->get_bounding_rect());
2762
2763                         // Grab the layer's list of parameters
2764                         Layer::ParamList paramlist(layer->get_param_list());
2765
2766                         // Grab the layer vocabulary
2767                         Layer::Vocab vocab=layer->get_param_vocab();
2768                         Layer::Vocab::iterator iter;
2769
2770                         for(iter=vocab.begin();iter!=vocab.end();iter++)
2771                         {
2772                                 if(!iter->get_hidden() && !iter->get_invisible_duck())
2773                                 {
2774                                         synfigapp::ValueDesc value_desc(layer,iter->get_name());
2775                                         work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2776                                         if(value_desc.is_value_node())
2777                                                 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2778                                 }
2779                                 if(iter->get_name()=="color")
2780                                 {
2781                                         /*
2782                                         if(!App::dialog_color->busy())
2783                                         {
2784                                                 App::dialog_color->reset();
2785                                                 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2786                                                 App::dialog_color->signal_edited().connect(
2787                                                         sigc::mem_fun(
2788                                                                 *this,
2789                                                                 &studio::CanvasView::selected_layer_color_set
2790                                                         )
2791                                                 );
2792                                         }
2793                                         */
2794                                 }
2795                         }
2796                 }
2797
2798                 layer_name=layer->get_name();
2799
2800                 if(layer->active())
2801                 {
2802                         Transform::Handle trans(layer->get_transform());
2803                         if(trans)
2804                         {
2805                                 transform_stack.push(trans);
2806                                 transforms++;
2807                         }
2808
2809 /*                      // Add transforms onto the stack
2810                         if(layer_name=="Translate")
2811                         {
2812                                 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2813                                 transforms++;
2814                         }else
2815                         if(layer_name=="Zoom")
2816                         {
2817                                 Vector scale;
2818                                 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2819                                 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2820                                 transforms++;
2821                         }else
2822                         if(layer_name=="stretch")
2823                         {
2824                                 Vector scale(layer->get_param("amount").get(Vector()));
2825                                 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2826                                 transforms++;
2827                         }else
2828                         if(layer_name=="Rotate")
2829                         {
2830                                 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2831                                 transforms++;
2832                         }
2833 */
2834                 }
2835
2836                 // If this is a paste canvas layer, then we need to
2837                 // descend into it
2838                 if(layer_name=="PasteCanvas")
2839                 {
2840                         Vector scale;
2841                         scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2842                         Vector origin(layer->get_param("origin").get(Vector()));
2843
2844                         Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2845
2846                         if(!scale.is_equal_to(Vector(1,1)))
2847                                 transform_stack.push(new Transform_Scale(scale,origin));
2848                         if(!scale.is_equal_to(Vector(0,0)))
2849                                 transform_stack.push(new Transform_Translate(origin));
2850
2851                         rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2852
2853                         if(!scale.is_equal_to(Vector(0,0)))
2854                                 transform_stack.pop();
2855                         if(!scale.is_equal_to(Vector(1,1)))
2856                                 transform_stack.pop();
2857                 }
2858         }
2859         // Remove all of the transforms we have added
2860         while(transforms--) { transform_stack.pop(); }
2861
2862 #undef QUEUE_REBUILD_DUCKS
2863 }
2864
2865 void
2866 CanvasView::queue_rebuild_ducks()
2867 {
2868 #if 0
2869         if(rebuild_ducks_queued)
2870                 return;
2871 #else
2872         if(rebuild_ducks_queued)
2873                 queue_rebuild_ducks_connection.disconnect();
2874 #endif
2875
2876         queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2877                 sigc::bind_return(
2878                         sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2879                         false
2880                 ),
2881                 50
2882         );
2883
2884         rebuild_ducks_queued=true;
2885 }
2886
2887 void
2888 CanvasView::rebuild_ducks()
2889 {
2890         /*static int i=0;
2891         i++;
2892         if(i>30)
2893                 synfig::info("%d",i/(i-i));
2894         */
2895
2896         rebuild_ducks_queued=false;
2897         //queue_rebuild_ducks_connection.disconnect();
2898
2899         if(work_area->is_dragging())
2900         {
2901                 queue_rebuild_ducks();
2902                 return;
2903         }
2904
2905         if(!duck_refresh_flag)
2906         {
2907                 duck_refresh_needed=true;
2908                 return;
2909         }
2910
2911         bbox=Rect::zero();
2912
2913         work_area->clear_ducks();
2914         work_area->set_time(get_time());
2915         get_canvas()->set_time(get_time());
2916         curr_transform_stack.clear();
2917         //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2918         curr_transform_stack_set=false;
2919
2920         for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2921
2922         //get_canvas()->set_time(get_time());
2923         bool not_empty(false);
2924
2925         // First do the layers...
2926         do{
2927                 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2928                 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2929
2930                 if(!layer_set.empty())
2931                         not_empty=true;
2932
2933                 synfig::TransformStack transform_stack;
2934
2935                 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2936
2937         }while(0);
2938
2939         // Now do the children
2940         do{
2941                 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2942                 synfigapp::SelectionManager::ChildrenList::iterator iter;
2943                 synfig::TransformStack transform_stack;
2944
2945                 if(selected_list.empty())
2946                 {
2947                         break;
2948                 }
2949                 else
2950                 {
2951                         not_empty=true;
2952                         for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2953                         {
2954                                 work_area->add_to_ducks(*iter,this,transform_stack);
2955                         }
2956                 }
2957         }while(0);
2958         work_area->refresh_selected_ducks();
2959         work_area->queue_draw_preview();
2960 }
2961
2962 void
2963 CanvasView::decrease_low_res_pixel_size()
2964 {
2965         list<int> sizes = CanvasView::get_pixel_sizes();
2966         int pixel_size = work_area->get_low_res_pixel_size();
2967
2968         for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2969                 if (*iter == pixel_size)
2970                 {
2971                         if (iter == sizes.begin())
2972                                 // we already have the smallest low-res pixels possible - turn off low-res instead
2973                                 work_area->set_low_resolution_flag(false);
2974                         else
2975                         {
2976                                 iter--;
2977                                 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
2978                                 action->activate(); // to make sure the radiobutton in the menu is updated too
2979                                 work_area->set_low_resolution_flag(true);
2980                         }
2981                         break;
2982                 }
2983 }
2984
2985 void
2986 CanvasView::increase_low_res_pixel_size()
2987 {
2988         list<int> sizes = CanvasView::get_pixel_sizes();
2989         int pixel_size = work_area->get_low_res_pixel_size();
2990
2991         if (!work_area->get_low_resolution_flag())
2992         {
2993                 work_area->set_low_resolution_flag(true);
2994                 return;
2995         }
2996
2997         for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2998                 if (*iter == pixel_size)
2999                 {
3000                         iter++;
3001                         if (iter != sizes.end())
3002                         {
3003                                 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
3004                                 action->activate(); // to make sure the radiobutton in the menu is updated too
3005                                 work_area->set_low_resolution_flag(true);
3006                         }
3007                         break;
3008                 }
3009 }
3010
3011 void
3012 CanvasView::on_dirty_preview()
3013 {
3014         if(!is_playing_)
3015         {
3016                 IsWorking is_working(*this);
3017
3018                 work_area->queue_render_preview();
3019         }
3020 }
3021
3022 void
3023 CanvasView::play()
3024 {
3025         assert(get_canvas());
3026
3027         // If we are already busy, don't play!
3028         if(working_depth)return;
3029
3030         // Set us up as working
3031         IsWorking is_working(*this);
3032
3033         etl::clock timer;
3034         Time
3035                 time=work_area->get_time(),
3036                 endtime=get_canvas()->rend_desc().get_time_end();
3037
3038         // If we are already at the end of time, start over
3039         if(time==endtime)
3040                 time=get_canvas()->rend_desc().get_time_start();
3041
3042         is_playing_=true;
3043
3044         work_area->clear_ducks();
3045
3046         for(timer.reset(); time + timer() < endtime;)
3047         {
3048                 //Clamp the time window so we can see the time value as it races across the horizon
3049                 bool timewindreset = false;
3050
3051                 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
3052                 {
3053                         time_window_adjustment().set_value(
3054                                         min(
3055                                                 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
3056                                                 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
3057                                 );
3058                         timewindreset = true;
3059                 }
3060
3061                 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
3062                 {
3063                         time_window_adjustment().set_value(
3064                                 max(
3065                                         time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
3066                                         time_window_adjustment().get_lower())
3067                         );
3068
3069                         timewindreset = true;
3070                 }
3071
3072                 //we need to tell people that the value changed
3073                 if(timewindreset) time_window_adjustment().value_changed();
3074
3075                 //update actual time to next step
3076                 time_adjustment().set_value(time+timer());
3077                 time_adjustment().value_changed();
3078
3079                 if(!work_area->sync_render_preview())
3080                         break;
3081
3082                 // wait for the workarea to refresh itself
3083                 while (studio::App::events_pending())
3084                         studio::App::iteration(false);
3085
3086                 if(get_cancel_status())
3087                 {
3088                         is_playing_=false;
3089                         return;
3090                 }
3091         }
3092         is_playing_=false;
3093
3094         time_adjustment().set_value(endtime);
3095         time_adjustment().value_changed();
3096 }
3097
3098 void
3099 CanvasView::show_tables()
3100 {
3101 /*
3102         Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
3103         if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3104         {
3105                 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3106                 treetogglebutton->remove();
3107                 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
3108                 treetogglebutton->show_all();
3109                 notebook->show();
3110         }
3111 */
3112 }
3113
3114 void
3115 CanvasView::hide_tables()
3116 {
3117 /*
3118         Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
3119         if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3120         {
3121                 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3122                 treetogglebutton->remove();
3123                 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
3124                 treetogglebutton->show_all();
3125                 notebook->hide();
3126         }
3127 */
3128 }
3129
3130 bool
3131 CanvasView::tables_are_visible()
3132 {
3133 //      return notebook->is_visible();
3134         return false;
3135 }
3136
3137 void
3138 CanvasView::toggle_tables()
3139 {
3140 //      if(tables_are_visible())
3141 //              hide_tables();
3142 //      else
3143 //              show_tables();
3144 }
3145
3146 void
3147 CanvasView::show_timebar()
3148 {
3149         timebar->show();
3150         current_time_widget->show();
3151
3152         //keyframe_tab_child->show();
3153         if(layer_tree)
3154                 layer_tree->set_show_timetrack(true);
3155         if(children_tree)
3156                 children_tree->set_show_timetrack(true);
3157 }
3158
3159 void
3160 CanvasView::hide_timebar()
3161 {
3162         timebar->hide();
3163         current_time_widget->hide();
3164         //keyframe_tab_child->hide();
3165         if(layer_tree)
3166                 layer_tree->set_show_timetrack(false);
3167         if(children_tree)
3168                 children_tree->set_show_timetrack(false);
3169 }
3170
3171 void
3172 CanvasView::set_sensitive_timebar(bool sensitive)
3173 {
3174         timebar->set_sensitive(sensitive);
3175         current_time_widget->set_sensitive(sensitive);
3176         //keyframe_tab_child->set_sensitive(sensitive);
3177         if(layer_tree)
3178                 layer_tree->set_sensitive(sensitive);
3179         if(children_tree)
3180                 children_tree->set_sensitive(sensitive);
3181 }
3182
3183 static void
3184 set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3185                                    Waypoint::Model model,
3186                                    etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3187 {
3188         // Create the action group
3189         synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Change Waypoint Group"));
3190
3191         std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3192         for(iter=waypoints.begin();iter!=waypoints.end();++iter)
3193         {
3194                 Waypoint waypoint(*iter);
3195                 waypoint.apply_model(model);
3196
3197                 synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set"));
3198
3199                 assert(action);
3200
3201                 action->set_param("canvas",canvas_interface->get_canvas());
3202                 action->set_param("canvas_interface",canvas_interface);
3203
3204                 action->set_param("waypoint",waypoint);
3205                 action->set_param("value_node",waypoint.get_parent_value_node());
3206
3207                 if(!canvas_interface->get_instance()->perform_action(action))
3208                 {
3209                         group.cancel();
3210                         return;
3211                 }
3212         }
3213 }
3214
3215 static void
3216 duplicate_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3217                                         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3218 {
3219         // Create the action group
3220         synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Duplicate Waypoints"));
3221
3222         std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3223         for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3224         {
3225                 Waypoint waypoint(*iter);
3226                 ValueNode::Handle value_node(iter->get_parent_value_node());
3227                 canvas_interface->waypoint_duplicate(value_node, waypoint);
3228         }
3229 }
3230
3231 static void
3232 remove_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3233                                  etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3234 {
3235         // Create the action group
3236         synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Remove Waypoints"));
3237
3238         std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3239         for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3240         {
3241                 Waypoint waypoint(*iter);
3242                 ValueNode::Handle value_node(iter->get_parent_value_node());
3243                 canvas_interface->waypoint_remove(value_node, waypoint);
3244         }
3245 }
3246
3247 void
3248 CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc,
3249                                                                                    std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set,
3250                                                                                    int button)
3251 {
3252         int size = waypoint_set.size();
3253         Waypoint waypoint(*(waypoint_set.begin()));
3254         Time time(waypoint.get_time());
3255
3256         if (size == 1)
3257         {
3258                 waypoint_dialog.set_value_desc(value_desc);
3259                 waypoint_dialog.set_waypoint(waypoint);
3260         }
3261
3262         switch(button)
3263         {
3264         case -1:
3265                 if (size == 1)
3266                         waypoint_dialog.show();
3267                 break;
3268         case 2:
3269         {
3270                 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
3271                 waypoint_menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), waypoint_menu));
3272
3273                 Gtk::Menu* interp_menu_in(manage(new Gtk::Menu()));
3274                 Gtk::Menu* interp_menu_out(manage(new Gtk::Menu()));
3275                 Gtk::Menu* interp_menu_both(manage(new Gtk::Menu()));
3276
3277                 {
3278                         Waypoint::Model model;
3279
3280                         model.reset(); model.set_before(INTERPOLATION_TCB);
3281                         interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3282                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3283                         model.reset(); model.set_after(INTERPOLATION_TCB);
3284                         interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3285                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3286                         model.set_before(INTERPOLATION_TCB);
3287                         interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3288                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3289
3290                         model.reset(); model.set_before(INTERPOLATION_LINEAR);
3291                         interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3292                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3293                         model.reset(); model.set_after(INTERPOLATION_LINEAR);
3294                         interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3295                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3296                         model.set_before(INTERPOLATION_LINEAR);
3297                         interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3298                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3299
3300                         model.reset(); model.set_before(INTERPOLATION_HALT);
3301                         interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In"),
3302                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3303                         model.reset(); model.set_after(INTERPOLATION_HALT);
3304                         interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease Out"),
3305                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3306                         model.set_before(INTERPOLATION_HALT);
3307                         interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In/Out"),
3308                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3309
3310                         model.reset(); model.set_before(INTERPOLATION_CONSTANT);
3311                         interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3312                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3313                         model.reset(); model.set_after(INTERPOLATION_CONSTANT);
3314                         interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3315                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3316                         model.set_before(INTERPOLATION_CONSTANT);
3317                         interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3318                                 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3319                 }
3320
3321                 // ------------------------------------------------------------------------
3322                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"),
3323                         sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time)));
3324
3325                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Duplicate"),
3326                          sigc::bind(sigc::ptr_fun(duplicate_waypoints), waypoint_set, canvas_interface())));
3327
3328                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem((size == 1) ? _("_Remove") : strprintf(_("_Remove %d Waypoints"), size),
3329                          sigc::bind(sigc::ptr_fun(remove_waypoints), waypoint_set, canvas_interface())));
3330
3331                 if (size == 1 && value_desc.is_valid())
3332                         waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),
3333                                 sigc::mem_fun(waypoint_dialog,&Gtk::Widget::show)));
3334
3335                 // ------------------------------------------------------------------------
3336                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
3337
3338                 // ------------------------------------------------------------------------
3339                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Both"), *interp_menu_both));
3340                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_In"),   *interp_menu_in));
3341                 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Out"),  *interp_menu_out));
3342
3343                 // ------------------------------------------------------------------------
3344                 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3345         }
3346         break;
3347
3348         default:
3349                 break;
3350         }
3351 }
3352
3353 void
3354 CanvasView::on_waypoint_changed()
3355 {
3356         synfigapp::Action::ParamList param_list;
3357         param_list.add("canvas",get_canvas());
3358         param_list.add("canvas_interface",canvas_interface());
3359         param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3360         param_list.add("waypoint",waypoint_dialog.get_waypoint());
3361 //      param_list.add("time",canvas_interface()->get_time());
3362
3363         get_instance()->process_action("waypoint_set_smart", param_list);
3364 }
3365
3366 void
3367 CanvasView::on_waypoint_delete()
3368 {
3369         synfigapp::Action::ParamList param_list;
3370         param_list.add("canvas",get_canvas());
3371         param_list.add("canvas_interface",canvas_interface());
3372         param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3373         param_list.add("waypoint",waypoint_dialog.get_waypoint());
3374 //      param_list.add("time",canvas_interface()->get_time());
3375
3376         get_instance()->process_action("waypoint_remove", param_list);
3377 }
3378
3379 void
3380 CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int /*x*/, int /*y*/, const Gtk::SelectionData& selection_data_, guint /*info*/, guint time)
3381 {
3382         // We will make this true once we have a solid drop
3383         bool success(false);
3384         //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
3385         //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
3386         //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3387
3388         if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3389         {
3390                 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3391                 {
3392                         synfig::String selection_data((gchar *)(selection_data_.get_data()));
3393
3394                         Layer::Handle layer(synfig::Layer::create("Text"));
3395                         if(!layer)
3396                                 break;
3397                         if(!layer->set_param("text",ValueBase(selection_data)))
3398                                 break;
3399
3400                         synfigapp::Action::Handle       action(synfigapp::Action::create("layer_add"));
3401
3402                         assert(action);
3403                         if(!action)
3404                                 break;
3405
3406                         action->set_param("canvas",get_canvas());
3407                         action->set_param("canvas_interface",canvas_interface());
3408                         action->set_param("new",layer);
3409
3410                         if(!get_instance()->perform_action(action))
3411                                 break;
3412
3413                         // Ok, we have successfully imported at least one item.
3414                         success=true;
3415                 } while(0); // END of "STRING"
3416
3417                 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3418                 {
3419                         synfig::String selection_data((gchar *)(selection_data_.get_data()));
3420
3421                         // For some reason, GTK hands us a list of URLs separated
3422                         // by not only Carriage-Returns, but also Line-Feeds.
3423                         // Line-Feeds will mess us up. Remove all the line-feeds.
3424                         while(selection_data.find_first_of('\r')!=synfig::String::npos)
3425                                 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3426
3427                         std::stringstream stream(selection_data);
3428
3429                         //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3430                         while(stream)
3431                         {
3432                                 synfig::String filename,URI;
3433                                 getline(stream,filename);
3434
3435                                 // If we don't have a filename, move on.
3436                                 if(filename.empty())
3437                                         continue;
3438
3439                                 // Make sure this URL is of the "file://" type.
3440                                 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3441                                 if(URI!="file://")
3442                                 {
3443                                         synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3444                                         continue;
3445                                 }
3446
3447                                 // Strip the "file://" part from the filename
3448                                 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3449
3450                                 String ext(filename_extension(filename));
3451                                 if (ext.size()) ext = ext.substr(1); // skip initial '.'
3452
3453                                 // If this is a SIF file, then we need to do things slightly differently
3454                                 if(ext=="sketch")
3455                                 {
3456                                         if(work_area->load_sketch(filename))
3457                                         {
3458                                                 success=true;
3459                                                 work_area->queue_draw();
3460                                         }
3461                                 }
3462                                 else
3463                                 {
3464                                         String errors, warnings;
3465                                         if(canvas_interface()->import(filename, errors, warnings, App::resize_imported_images))
3466                                                 success=true;
3467                                         if (warnings != "")
3468                                                 App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
3469                                 }
3470
3471                                 continue;
3472                         }
3473                 } // END of "text/plain"
3474         }
3475         else
3476                 ui_interface_->error("Drop failed: bad selection data");
3477
3478         // Finish the drag
3479         context->drag_finish(success, false, time);
3480 }
3481
3482 void
3483 CanvasView::on_keyframe_add_pressed()
3484 {
3485         synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3486
3487         if(!action)
3488         {
3489                 ui_interface_->error("I am unable to find the appropriate action");
3490                 return;
3491         }
3492
3493         action->set_param("canvas",get_canvas());
3494         action->set_param("canvas_interface",canvas_interface());
3495         action->set_param("keyframe",Keyframe(get_time()));
3496
3497         canvas_interface()->get_instance()->perform_action(action);
3498 }
3499
3500 void
3501 CanvasView::on_keyframe_duplicate_pressed()
3502 {
3503         const KeyframeTreeStore::Model model;
3504         const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3505         Keyframe keyframe;
3506         if(!row)
3507         {
3508                 ui_interface_->error("I am unable to duplicate the keyframe");
3509                 return;
3510         }
3511         keyframe=row[model.keyframe];
3512
3513         synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3514
3515         if(!action)
3516         {
3517                 ui_interface_->error("I am unable to find the appropriate action");
3518                 return;
3519         }
3520
3521         action->set_param("canvas",get_canvas());
3522         action->set_param("canvas_interface",canvas_interface());
3523         action->set_param("keyframe",keyframe);
3524         action->set_param("time",get_time());
3525
3526         canvas_interface()->get_instance()->perform_action(action);
3527 }
3528
3529 void
3530 CanvasView::on_keyframe_remove_pressed()
3531 {
3532         const KeyframeTreeStore::Model model;
3533         const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3534         Keyframe keyframe;
3535         if(!row)
3536         {
3537                 ui_interface_->error("I am unable to remove the keyframe");
3538                 return;
3539         }
3540         keyframe=row[model.keyframe];
3541
3542         synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3543
3544         if(!action)
3545         {
3546                 ui_interface_->error("I am unable to find the appropriate action");
3547                 return;
3548         }
3549
3550         action->set_param("canvas",get_canvas());
3551         action->set_param("canvas_interface",canvas_interface());
3552         action->set_param("keyframe",keyframe);
3553
3554         canvas_interface()->get_instance()->perform_action(action);
3555 }
3556
3557 void
3558 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3559 {
3560         bool is_currently_on(work_area->get_type_mask()&type);
3561
3562         if(is_currently_on)
3563                 work_area->set_type_mask(work_area->get_type_mask()-type);
3564         else
3565                 work_area->set_type_mask(work_area->get_type_mask()|type);
3566
3567         work_area->queue_draw();
3568 }
3569
3570 void
3571 CanvasView::image_import()
3572 {
3573         // String filename(dirname(get_canvas()->get_file_name()));
3574         String filename("*.*");
3575         String errors, warnings;
3576         if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
3577         {
3578                 canvas_interface()->import(filename, errors, warnings, App::resize_imported_images);
3579                 if (warnings != "")
3580                         App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
3581         }
3582 }
3583
3584 Smach::event_result
3585 CanvasView::process_event_key(EventKey x)
3586 {
3587         return smach_.process_event(x);
3588 }
3589
3590 void
3591 CanvasView::on_input_device_changed(GdkDevice* device)
3592 {
3593         if(!device)
3594         {
3595                 get_smach().egress();
3596         }
3597         assert(device);
3598
3599         synfigapp::InputDevice::Handle input_device;
3600         input_device=synfigapp::Main::select_input_device(device->name);
3601         App::toolbox->change_state(input_device->get_state());
3602         process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3603 }
3604
3605 void
3606 CanvasView::on_preview_option()
3607 {
3608         Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3609
3610         Canvas::Handle  canv = get_canvas();
3611
3612         if(canv)
3613         {
3614                 RendDesc &r = canv->rend_desc();
3615                 if(r.get_frame_rate())
3616                 {
3617                         float rate = 1/r.get_frame_rate();
3618                         float beg = r.get_time_start() + r.get_frame_start()*rate;
3619                         float end = r.get_time_start() + r.get_frame_end()*rate;
3620
3621                         if(!po)
3622                         {
3623                                 po = new Dialog_PreviewOptions;
3624                                 po->set_zoom(work_area->get_zoom()/2);
3625                                 po->set_fps(r.get_frame_rate()/2);
3626                                 po->set_begintime(beg);
3627                                 po->set_begin_override(false);
3628                                 po->set_endtime(end);
3629                                 po->set_end_override(false);
3630
3631                                 set_ext_widget("prevoptions",po);
3632                         }
3633                         /*po->set_zoom(work_area->get_zoom()/2);
3634                         po->set_fps(r.get_frame_rate()/2);
3635                         po->set_begintime(beg);
3636                         po->set_begin_override(false);
3637                         po->set_endtime(end);
3638                         po->set_end_override(false);*/
3639
3640                         po->set_global_fps(r.get_frame_rate());
3641                         po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3642                         po->present();
3643                 }
3644         }
3645 }
3646
3647 void
3648 CanvasView::on_preview_create(const PreviewInfo &info)
3649 {
3650         //set all the options
3651         etl::handle<Preview>    prev = new Preview;
3652
3653         prev->set_canvasview(this);
3654         prev->set_zoom(info.zoom);
3655         prev->set_fps(info.fps);
3656         prev->set_overbegin(info.overbegin);
3657         prev->set_begintime(info.begintime);
3658         prev->set_overend(info.overend);
3659         prev->set_endtime(info.endtime);
3660         prev->set_quality(work_area->get_quality());
3661
3662         //render it out...
3663         prev->render();
3664
3665         Dialog_Preview *pd = preview_dialog.get();
3666         assert(pd);
3667
3668         pd->set_default_size(700,510);
3669         pd->set_preview(prev.get());
3670         pd->present();
3671 }
3672
3673 void
3674 CanvasView::on_audio_option()
3675 {
3676         synfig::warning("Launching Audio Options");
3677         sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3678         sound_dialog->present();
3679 }
3680
3681 void
3682 CanvasView::on_audio_file_change(const std::string &f)
3683 {
3684         //save in meta data - always even when not valid...
3685         canvas_interface()->set_meta_data("audiofile",f);
3686 }
3687
3688 void
3689 CanvasView::on_audio_offset_change(const synfig::Time &t)
3690 {
3691         canvas_interface()->set_meta_data("audiooffset",t.get_string());
3692 }
3693
3694 void
3695 CanvasView::on_audio_file_notify()
3696 {
3697         std::string file(get_canvas()->get_meta_data("audiofile"));
3698         if(!file.c_str()) return;
3699
3700         if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3701         {
3702                 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3703                 get_canvas()->erase_meta_data("audiofile");
3704                 disp_audio->hide();
3705                 disp_audio->set_profile(etl::handle<AudioProfile>());
3706         }else
3707         {
3708                 //save in canvasview
3709                 synfig::warning("Getting the profile of the music stuff");
3710
3711                 //profile specific stuff for the preview widget
3712                 //similar for other attachments
3713                 Dialog_Preview *pd = preview_dialog.get();
3714                 pd->get_widget().set_audio(audio);
3715
3716                 handle<AudioProfile>    prof = audio->get_profile();
3717
3718                 if(!prof)
3719                 {
3720                         synfig::warning("Agh, I couldn't build the profile captain!");
3721                 }
3722                 pd->get_widget().set_audioprofile(prof);
3723
3724                 disp_audio->set_profile(audio->get_profile());
3725                 disp_audio->show();
3726
3727                 synfig::warning("successfully set the profiles and stuff");
3728         }
3729         disp_audio->queue_draw();
3730 }
3731
3732 void
3733 CanvasView::on_audio_offset_notify()
3734 {
3735         Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3736         audio->set_offset(t);
3737         sound_dialog->set_offset(t);
3738         disp_audio->queue_draw();
3739
3740         // synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3741 }
3742
3743 void
3744 CanvasView::play_audio(float t)
3745 {
3746         if(audio.get())
3747         {
3748                 synfig::info("Playing audio at %f s",t);
3749                 audio->play(t);
3750         }
3751 }
3752
3753 void
3754 CanvasView::stop_audio()
3755 {
3756         if(audio.get())
3757         {
3758                 audio->stop();
3759         }
3760 }
3761
3762 bool
3763 CanvasView::on_audio_scrub()
3764 {
3765         disp_audio->draw();
3766         return true;
3767 }
3768
3769 Glib::RefPtr<Glib::ObjectBase>
3770 CanvasView::get_ref_obj(const synfig::String& x)
3771 {
3772         return ref_obj_book_[x];
3773 }
3774
3775 Glib::RefPtr<const Glib::ObjectBase>
3776 CanvasView::get_ref_obj(const synfig::String& x)const
3777 {
3778         return ref_obj_book_.find(x)->second;
3779 }
3780
3781 void
3782 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3783 {
3784         ref_obj_book_[x]=y;
3785 }
3786
3787 Glib::RefPtr<Gtk::TreeModel>
3788 CanvasView::get_tree_model(const synfig::String& x)
3789 {
3790         return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3791 }
3792
3793 Glib::RefPtr<const Gtk::TreeModel>
3794 CanvasView::get_tree_model(const synfig::String& x)const
3795 {
3796         return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3797 }
3798
3799 void
3800 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3801 {
3802         ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3803 }
3804
3805 Gtk::Widget*
3806 CanvasView::get_ext_widget(const synfig::String& x)
3807 {
3808         return ext_widget_book_[x];
3809 }
3810
3811 void
3812 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3813 {
3814         ext_widget_book_[x]=y;
3815         if(x=="layers_cmp")
3816         {
3817                 layer_tree=dynamic_cast<LayerTree*>(y);
3818
3819                 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3820                 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3821                 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3822                 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3823                 layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3824         }
3825         if(x=="children")
3826         {
3827                 children_tree=dynamic_cast<ChildrenTree*>(y);
3828                 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3829                 if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3830                 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3831         }
3832         if(x=="keyframes")
3833                 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3834 }
3835
3836 bool
3837 CanvasView::on_delete_event(GdkEventAny* event __attribute__ ((unused)))
3838 {
3839         close_view();
3840
3841         //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
3842         //                Is there ever any need to pass on the delete event to the window here?
3843         // if(event) return Gtk::Window::on_delete_event(event);
3844
3845         return true;
3846 }