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