Allow PasteCanvas layers with unset canvas parameters to be exported.
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasview.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
27 #define __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include <gtkmm/window.h>
32 #include <gtkmm/image.h>
33 #include <gtkmm/tooltips.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/statusbar.h>
36 #include <gtkmm/progressbar.h>
37 #include <gtkmm/button.h>
38 #include <gtkmm/menu.h>
39 #include <gtkmm/treeview.h>
40 #include <gtkmm/treestore.h>
41 #include <gtkmm/scrolledwindow.h>
42 #include <gtkmm/notebook.h>
43 #include <gdkmm/device.h>
44
45 #include <synfigapp/canvasinterface.h>
46 #include <synfigapp/selectionmanager.h>
47
48 #include <synfig/canvas.h>
49 #include <synfig/string.h>
50 #include <synfig/time.h>
51
52 #include "instance.h"
53 #include "canvasproperties.h"
54 #include "canvasoptions.h"
55 #include "render.h"
56 #include "cellrenderer_timetrack.h"
57 #include "app.h"
58
59 #include "layertreestore.h"
60 #include "layertree.h"
61 #include "childrentreestore.h"
62 #include "childrentree.h"
63 #include "keyframetreestore.h"
64 #include "keyframetree.h"
65
66 #include "dialog_waypoint.h"
67 #include "dialog_keyframe.h"
68
69 #include "duckmatic.h"
70 #include <gtkmm/scale.h>
71
72 #include <gtkmm/uimanager.h>
73
74 #include "smach.h"
75
76 #include <memory>
77 #include <set>
78 #include <map>
79 #include <gtkmm/toggleaction.h>
80 #include <gtkmm/radioaction.h>
81 #include <synfig/rect.h>
82
83 #include "adjust_window.h"
84
85 #include <synfig/transform.h>
86
87 /* === M A C R O S ========================================================= */
88
89 #ifndef DEBUGPOINT_CLASS
90 #if     _DEBUG
91 #define DEBUGPOINT_CLASS(x)             struct debugpointclass_ ## x { debugpointclass_ ## x () { DEBUGPOINT(); } ~debugpointclass_ ## x () { DEBUGPOINT(); } } badfthguae_ ## x ;
92 #else
93 #define DEBUGPOINT_CLASS(x)
94 #endif
95 #endif
96
97 /* === T Y P E D E F S ===================================================== */
98
99 /* === C L A S S E S & S T R U C T S ======================================= */
100
101 namespace synfig {
102         class TransformStack;
103 }
104
105 namespace studio {
106
107 class CanvasViewUIInterface;
108 class CanvasViewSelectionManager;
109
110 class CellRenderer_TimeTrack;
111 class CellRenderer_ValueBase;
112 class UniversalScrubber;
113 class WorkArea;
114
115 class Duckmatic;
116
117 class Preview;
118 struct PreviewInfo;
119 class AudioContainer;
120
121 class Widget_Sound;
122 class Widget_Timeslider;
123 class Widget_Time;
124
125 class Dialog_SoundSelect;
126 class Dialog_Preview;
127
128 class Dock_Layers;
129 class Dock_Children;
130 class Dock_Keyframes;
131
132 class CanvasView : public Gtk::Window, public etl::shared_object
133 {
134         friend class UniversalScrubber;
135         friend class Dock_Layers;
136         friend class Dock_Children;
137         friend class Dock_Keyframes;
138
139         friend class CanvasViewUIInterface;
140         friend class CanvasViewSelectionManager;
141
142         friend class Duckmatic;
143
144         /*
145  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
146         */
147
148 public:
149
150         typedef etl::handle<CanvasView> Handle;
151
152         typedef etl::handle<const CanvasView> ConstHandle;
153
154         typedef etl::loose_handle<CanvasView> LooseHandle;
155
156         typedef LayerTreeStore::Model LayerTreeModel;
157
158         typedef ChildrenTreeStore::Model ChildrenTreeModel;
159
160         //! Create an instance of this class whenever doing a longer task.
161         /*! Make sure that you check the bool value of this class occasionally
162         **      to make sure the action has not been canceled. */
163         class IsWorking
164         {
165                 CanvasView &canvas_view_;
166
167         public:
168                 IsWorking(CanvasView &canvas_view_);
169                 ~IsWorking();
170                 operator bool()const;
171         };
172         friend class IsWorking;
173
174         typedef synfigapp::CanvasInterface::Mode Mode;
175
176         void set_grid_snap_toggle(bool flag) { grid_snap_toggle->set_active(flag); }
177         void set_grid_show_toggle(bool flag) { grid_show_toggle->set_active(flag); }
178
179         /*
180  -- ** -- P R I V A T E   D A T A ---------------------------------------------
181         */
182
183 public:
184         std::auto_ptr<WorkArea> work_area;
185
186         WorkArea* get_work_area() { return work_area.get(); }
187 private:
188
189         synfig::TransformStack curr_transform_stack;
190         bool curr_transform_stack_set;
191
192         synfig::Rect bbox;
193
194         // DEBUGPOINT_CLASS(1);
195
196         //! State Machine
197         Smach smach_;
198
199         // DEBUGPOINT_CLASS(2);
200
201         etl::loose_handle<Instance> instance_;
202         etl::handle<synfigapp::CanvasInterface> canvas_interface_;
203
204         // DEBUGPOINT_CLASS(3);
205
206         //! Sound and information to play it
207         etl::handle<AudioContainer>             audio;
208         studio::Widget_Sound                    *disp_audio; //should this be put into thing too?
209
210         sigc::connection                                playcon;
211         sigc::connection                                stopcon;
212
213         std::auto_ptr<UniversalScrubber> universal_scrubber;
214
215         //! Tooltip controller
216         Gtk::Tooltips tooltips;
217
218         // DEBUGPOINT_CLASS(4);
219
220         //! TreeModel for the layers
221         LayerTreeModel layer_tree_model;
222
223         //! TreeModel for the the children
224         ChildrenTreeModel children_tree_model;
225
226         //Glib::RefPtr<LayerTreeStore> layer_tree_store_;
227
228         //Glib::RefPtr<ChildrenTreeStore> children_tree_store_;
229
230         //Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store_;
231
232         // DEBUGPOINT_CLASS(5);
233
234         //std::map<synfig::String,Glib::RefPtr<Gtk::TreeModel> > tree_model_book_;
235         std::map<synfig::String,Glib::RefPtr<Glib::ObjectBase> > ref_obj_book_;
236         std::map<synfig::String,Gtk::Widget*> ext_widget_book_;
237
238         //! The time adjustment's scope is defined by the time_window adjustment
239         Gtk::Adjustment time_adjustment_;
240
241         //! The time_window adjustment governs the position of the time window on the whole time line
242         //Gtk::Adjustment time_window_adjustment_;
243         studio::Adjust_Window time_window_adjustment_;
244
245         LayerTree *layer_tree;
246
247         ChildrenTree *children_tree;
248
249         KeyframeTree *keyframe_tree;
250
251         Gtk::Widget *keyframe_tab_child;
252
253         Gtk::ProgressBar *progressbar;
254         Gtk::Statusbar *statusbar;
255
256         Gtk::TreeRow children_canvas_row;
257         Gtk::TreeRow children_valuenode_row;
258
259         Gtk::Button *stopbutton;
260         Gtk::Button *refreshbutton;
261         Gtk::Button *treetogglebutton;
262         Gtk::Notebook *notebook;
263         Gtk::Widget *timebar;
264
265         Widget_Time *current_time_widget;
266         void on_current_time_widget_changed();
267
268         std::auto_ptr<Widget_Timeslider>                timeslider;
269
270         std::list<sigc::connection> duck_changed_connections;
271
272         Gtk::Button *animatebutton;
273         Gtk::Button *keyframebutton;
274
275 /*      DEBUGPOINT_CLASS(8);
276
277         Gtk::Menu duckmaskmenu;
278         DEBUGPOINT_CLASS(77);
279         Gtk::Menu qualitymenu;
280         DEBUGPOINT_CLASS(6);
281
282         Gtk::Menu filemenu;
283         DEBUGPOINT_CLASS(777);
284         Gtk::Menu editmenu;
285         DEBUGPOINT_CLASS(71);
286         Gtk::Menu canvasmenu;
287         DEBUGPOINT_CLASS(73);
288 public:
289         Gtk::Menu layermenu;
290 private:
291         DEBUGPOINT_CLASS(74);
292         Gtk::Menu newlayermenu;
293         DEBUGPOINT_CLASS(76);
294         Gtk::Menu viewmenu;
295
296         DEBUGPOINT_CLASS(99);
297         Gtk::Menu keyframemenu;
298
299         Gtk::Menu parammenu;
300         DEBUGPOINT_CLASS(9);
301         Gtk::Menu trackmenu;
302         DEBUGPOINT_CLASS(7);
303
304         Gtk::CheckMenuItem* duck_mask_position;
305         Gtk::CheckMenuItem* duck_mask_vertex;
306         Gtk::CheckMenuItem* duck_mask_tangent;
307         Gtk::CheckMenuItem* duck_mask_radius;
308         Gtk::CheckMenuItem* duck_mask_width;
309         Gtk::CheckMenuItem* duck_mask_angle;
310 */
311         Gtk::Menu parammenu;
312
313         Glib::RefPtr<Gtk::ToggleAction> grid_snap_toggle;
314         Glib::RefPtr<Gtk::ToggleAction> grid_show_toggle;
315
316         Gtk::RadioButtonGroup quality_group;
317         Gtk::RadioButtonGroup low_res_pixel_size_group;
318
319         Glib::RefPtr<Gtk::ActionGroup> action_group;
320
321         etl::handle<synfigapp::UIInterface> ui_interface_;
322         etl::handle<synfigapp::SelectionManager> selection_manager_;
323
324         bool is_playing_;
325
326         sigc::signal<void> signal_deleted_;
327
328         bool rebuild_ducks_queued;
329         sigc::connection queue_rebuild_ducks_connection;
330
331         /*
332  -- ** -- P U B L I C   D A T A -----------------------------------------------
333         */
334
335 public:
336         void queue_rebuild_ducks();
337         sigc::signal<void>& signal_deleted() { return signal_deleted_; }
338
339         Gtk::Menu mainmenu;
340
341         bool duck_refresh_flag;
342         bool duck_refresh_needed;
343
344         //! This is for the IsWorking class.
345         int working_depth;
346
347         bool cancel;
348
349         /*
350  -- ** -- D I A L O G S -------------------------------------------------------
351         */
352
353 public:
354
355         CanvasProperties canvas_properties;
356         CanvasOptions canvas_options;
357         RenderSettings render_settings;
358         Dialog_Waypoint waypoint_dialog;
359         Dialog_Keyframe keyframe_dialog;
360
361         std::auto_ptr<Dialog_Preview>                   preview_dialog;
362         //std::auto_ptr<Dialog_PreviewOptions>  previewoption_dialog;
363         std::auto_ptr<Dialog_SoundSelect>               sound_dialog;
364
365         /*
366  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
367         */
368
369 private:
370
371         // Constructor is private to force the use of the "create()" constructor
372         CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface);
373
374         //! Constructor Helper
375         // Gtk::Widget* create_layer_tree();
376
377         //! Constructor Helper
378         // Gtk::Widget* create_children_tree();
379
380         //! Constructor Helper
381         // Gtk::Widget* create_keyframe_tree();
382
383         //! Constructor Helper
384         Gtk::Widget* create_status_bar();
385
386         //! Constructor Helper - Initializes all of the menus
387         void init_menus();
388
389         bool duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name);
390
391         void refresh_time_window();
392
393         void time_was_changed();
394
395         void refresh_rend_desc();
396
397         void toggle_duck_mask(Duckmatic::Type type);
398
399         Gtk::Widget *create_work_area();
400
401         Gtk::Widget *create_time_bar();
402
403         void popup_param_menu_bezier(float location, synfigapp::ValueDesc value_desc)
404         { popup_param_menu(value_desc,location,true); }
405
406         void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0, bool bezier=false);
407
408         void workarea_layer_selected(synfig::Layer::Handle layer);
409
410         void selected_layer_color_set(synfig::Color color);
411
412         void register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>*);
413
414         //! Rebuilds the "new layer" menu
415         void build_new_layer_menu(Gtk::Menu &menu);
416
417         void rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list);
418
419         void decrease_low_res_pixel_size();
420         void increase_low_res_pixel_size();
421
422         /*
423  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
424         */
425
426 public:
427         const synfig::TransformStack& get_curr_transform_stack()const { return curr_transform_stack; }
428
429         const synfig::Rect& get_bbox()const { return bbox; }
430
431         Glib::RefPtr<Glib::ObjectBase> get_ref_obj(const synfig::String& x);
432         Glib::RefPtr<const Glib::ObjectBase> get_ref_obj(const synfig::String& x)const;
433         void set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y);
434
435         Glib::RefPtr<Gtk::TreeModel> get_tree_model(const synfig::String& x);
436         Glib::RefPtr<const Gtk::TreeModel> get_tree_model(const synfig::String& x)const;
437         void set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y);
438
439         Gtk::Widget* get_ext_widget(const synfig::String& x);
440         void set_ext_widget(const synfig::String& x, Gtk::Widget* y);
441
442         //std::map<synfig::String,Gtk::Widget*>& tree_view_book() { return tree_view_book_; }
443         //std::map<synfig::String,Gtk::Widget*>& ext_widget_book() { return tree_view_book_; }
444
445         void popup_main_menu();
446
447         Smach& get_smach() { return smach_; }
448
449         const Smach& get_smach()const { return smach_; }
450
451         Smach::event_result process_event_key(EventKey x);
452
453         void popup_layer_menu(synfig::Layer::Handle layer);
454
455         virtual ~CanvasView();
456
457         void set_mode(Mode x) { canvas_interface()->set_mode(x); }
458
459         Mode get_mode()const { return canvas_interface()->get_mode(); }
460
461         Gtk::Adjustment &time_adjustment() { return time_adjustment_; }
462
463         const Gtk::Adjustment &time_adjustment()const { return time_adjustment_; }
464
465         studio::Adjust_Window &time_window_adjustment() { return time_window_adjustment_; }
466
467         const studio::Adjust_Window &time_window_adjustment()const { return time_window_adjustment_; }
468
469         etl::handle<synfigapp::UIInterface> get_ui_interface() { return ui_interface_;}
470
471         etl::handle<synfigapp::SelectionManager> get_selection_manager() { return selection_manager_; }
472
473         Glib::RefPtr<Gtk::TreeModel> layer_tree_store() { return get_tree_model("layers"); }
474
475         Glib::RefPtr<const Gtk::TreeModel> layer_tree_store()const { return get_tree_model("layers"); }
476
477         Glib::RefPtr<Gtk::TreeModel> children_tree_store() { return get_tree_model("children"); }
478
479         Glib::RefPtr<const Gtk::TreeModel> children_tree_store()const { return get_tree_model("children"); }
480
481         Glib::RefPtr<Gtk::TreeModel> keyframe_tree_store() { return get_tree_model("keyframes"); }
482
483         Glib::RefPtr<const Gtk::TreeModel> keyframe_tree_store()const { return get_tree_model("keyframes"); }
484
485         void set_time(synfig::Time t) { canvas_interface_->set_time(t); }
486
487         synfig::Time get_time() { return canvas_interface_->get_time(); }
488
489         etl::handle<synfig::Canvas> get_canvas()const { return canvas_interface_->get_canvas(); }
490
491         etl::handle<Instance> get_instance()const { return instance_; }
492
493         etl::handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
494
495         etl::handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
496
497         void add_actions_to_menu(Gtk::Menu *menu,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
498
499         //! Updates the title of the window
500         void update_title();
501
502         //! Closes this document
503         bool close_instance();
504
505         //! Closes this canvas view
506         bool close_view();
507
508         //!     Stops the currently executing action
509         /*! \see get_cancel_status(), reset_cancel_status(), IsWorking */
510         void stop() { cancel=true; }
511
512         //! Returns the cancel status
513         /*! \see stop(), reset_cancel_status(), IsWorking */
514         bool get_cancel_status()const { return cancel; }
515
516         //! Resets the cancel status
517         /*! \see stop(), get_cancel_status(), IsWorking */
518         void reset_cancel_status() { cancel=false; }
519
520         void new_child_canvas();
521
522         //! Rebuilds layer_tree_store_ from the Canvas. Maintains selected items.
523         void rebuild_tables();
524
525         //! Builds layer_tree_store_ from the Canvas. Does not maintain selected items.
526         void build_tables();
527
528         //! Refreshes the data for the tables
529         void refresh_tables();
530
531         //void rebuild_layer_table();
532         //void build_layer_table();
533         //void refresh_layer_table();
534
535 //      void rebuild_canvas_table();
536 //      void build_canvas_table();
537 //      void refresh_canvas_table();
538
539 //      void rebuild_valuenode_table();
540 //      void build_valuenode_table();
541 //      void refresh_valuenode_table();
542
543         //! \writeme
544         void rebuild_ducks();
545
546         //bool add_to_ducks(synfigapp::ValueDesc value_desc, synfig::ParamDesc *param_desc=NULL);
547
548         //! Starts "playing" the animation in real-time
549         void play();
550
551         //! Shows the tables (Layer/Children)
552         void show_tables();
553
554         //! Hides the tables (Layer/Children)
555         void hide_tables();
556
557         //! Toggles the tables
558         void toggle_tables();
559
560         //! Gets the table status
561         bool tables_are_visible();
562
563         //! Shows the time bar
564         void show_timebar();
565
566         //! Hides the time bar
567         void hide_timebar();
568
569         //t Enables or disables interaction with the timebar
570         void set_sensitive_timebar(bool sensitive);
571
572         void time_zoom_in();
573         void time_zoom_out();
574
575         void add_layer(synfig::String x);
576
577         void show_keyframe_dialog();
578
579         void play_audio(float t);
580         void stop_audio();
581
582         void image_import();
583
584         void on_waypoint_clicked_canvasview(synfigapp::ValueDesc,std::set<synfig::Waypoint,std::less<synfig::UniqueID> >, int button);
585
586         void preview_option() {on_preview_option();}
587
588         void present();
589
590         bool is_playing() { return is_playing_; }
591
592         /*
593  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
594         */
595
596 private:
597
598         void on_select_layers();
599         void on_unselect_layers();
600
601         void on_input_device_changed(GdkDevice*);
602
603         virtual void on_hide();
604
605         virtual bool on_focus_in_event(GdkEventFocus*);
606         virtual bool on_focus_out_event(GdkEventFocus*);
607
608         //bool on_children_tree_event(GdkEvent *event);
609
610         bool on_keyframe_tree_event(GdkEvent *event);
611
612         //void on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value);
613
614         void on_dirty_preview();
615
616         bool on_children_user_click(int, Gtk::TreeRow, ChildrenTree::ColumnID);
617
618         bool on_layer_user_click(int, Gtk::TreeRow, LayerTree::ColumnID);
619
620 //      void on_layer_toggle(const Glib::ustring& path_string, Gtk::TreeModelColumn<bool> column);
621
622         void on_mode_changed(synfigapp::CanvasInterface::Mode mode);
623
624 //      void on_layer_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
625
626         //void on_children_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
627
628         void on_waypoint_changed();
629
630         void on_waypoint_delete();
631
632         void on_refresh_pressed();
633
634         void on_id_changed();
635
636         void on_time_changed();
637
638         /*
639         void on_layer_raise_pressed();
640         void on_layer_lower_pressed();
641         void on_layer_duplicate_pressed();
642         void on_layer_delete_pressed();
643         */
644
645         void on_keyframe_add_pressed();
646
647         void on_keyframe_duplicate_pressed();
648
649         void on_keyframe_remove_pressed();
650
651         void on_animate_button_pressed();
652
653         void on_keyframe_button_pressed();
654
655         void on_preview_option();
656         void on_preview_create(const PreviewInfo &);
657
658         void on_audio_option();
659         void on_audio_file_change(const std::string &f);
660         void on_audio_offset_change(const synfig::Time &t);
661
662         void on_audio_file_notify();
663         void on_audio_offset_notify();
664
665         bool on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc);
666         bool on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc);
667
668         void on_layer_toggle(synfig::Layer::Handle);
669
670         void on_edited_value(synfigapp::ValueDesc,synfig::ValueBase);
671
672         void on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time);
673
674         //void on_audio_play();
675         bool on_audio_scrub();
676
677 protected:
678         bool close_instance_when_safe();
679         bool on_delete_event(GdkEventAny* event);
680
681         /*
682  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
683         */
684
685 public:
686
687         static etl::handle<studio::CanvasView> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
688         static std::list<int>& get_pixel_sizes();
689
690 }; // END of class CanvasView
691
692 }; // END of namespace studio
693
694 /* === E N D =============================================================== */
695
696 #endif