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