Get rid of all references to the bootstrap script since it was removed
[synfig.git] / synfig-studio / trunk / src / gtkmm / dock_timetrack.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dock_timetrack.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 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "dock_timetrack.h"
34 #include "app.h"
35
36 #include <gtkmm/scrolledwindow.h>
37 #include <cassert>
38 #include "instance.h"
39 #include <sigc++/signal.h>
40 #include <sigc++/hide.h>
41 #include <sigc++/slot.h>
42 #include "canvasview.h"
43 #include "layerparamtreestore.h"
44 #include "workarea.h"
45 #include "widget_timeslider.h"
46 #include "layerparamtreestore.h"
47 #include "general.h"
48
49 #endif
50
51 /* === U S I N G =========================================================== */
52
53 using namespace std;
54 using namespace etl;
55 using namespace synfig;
56 using namespace studio;
57
58 /* === M A C R O S ========================================================= */
59
60 /* === C L A S S E S ======================================================= */
61
62 class TimeTrackView : public Gtk::TreeView
63 {
64         CellRenderer_TimeTrack *cellrenderer_time_track;
65
66         Glib::RefPtr<LayerParamTreeStore> param_tree_store_;
67
68         Gtk::TreeView *mimic_tree_view;
69 public:
70
71         sigc::signal<void,synfigapp::ValueDesc,synfig::Waypoint,int> signal_waypoint_clicked;
72
73         LayerParamTreeStore::Model model;
74
75         void set_canvas_view(handle<CanvasView> canvas_view)
76         {
77                 cellrenderer_time_track->set_adjustment(canvas_view->time_adjustment());
78         }
79
80         TimeTrackView()
81         {
82                 int label_index(append_column_editable(_("Name"),model.label));
83                 Gtk::TreeView::Column* label_column = get_column(label_index-1);
84
85                 {       // --- T I M E   T R A C K --------------------------------------------
86                         Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
87
88                         // Set up the value-node cell-renderer
89                         cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
90                         cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
91                         cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_clicked) );
92                         cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_changed) );
93                         column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
94                         column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
95                         //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
96
97                         //column->pack_start(*cellrenderer_time_track);
98
99                         // Finish setting up the column
100                         column->set_reorderable();
101                         column->set_resizable();
102                         column->set_min_width(200);
103
104
105                         append_column(*column);
106                 }
107                 set_rules_hint();
108
109                 set_expander_column(*label_column);
110                 label_column->set_visible(false);
111                 set_headers_visible(false);
112                 set_size_request(-1,64);
113         }
114
115         bool
116         on_event(GdkEvent *event)
117         {
118                 switch(event->type)
119                 {
120                 case GDK_SCROLL:
121                         if(mimic_tree_view)
122                         {
123                                 if(event->scroll.direction==GDK_SCROLL_DOWN)
124                                 {
125                                         mimic_tree_view->get_vadjustment()->set_value(
126                                                 std::min(
127                                                         mimic_tree_view->get_vadjustment()->get_value()+
128                                                         mimic_tree_view->get_vadjustment()->get_step_increment(),
129                                                         mimic_tree_view->get_vadjustment()->get_upper()-
130                                                         mimic_tree_view->get_vadjustment()->get_page_size()
131                                                 )
132                                         );
133                                         mimic_tree_view->get_vadjustment()->value_changed();
134                                 }
135                                 else if(event->scroll.direction==GDK_SCROLL_UP)
136                                 {
137                                         mimic_tree_view->get_vadjustment()->set_value(
138                                                 std::max(
139                                                         mimic_tree_view->get_vadjustment()->get_value()-
140                                                         mimic_tree_view->get_vadjustment()->get_step_increment(),
141                                                         mimic_tree_view->get_vadjustment()->get_lower()
142                                                 )
143                                         );
144                                         mimic_tree_view->get_vadjustment()->value_changed();
145                                 }
146                         }
147                         break;
148                 case GDK_BUTTON_PRESS:
149                         {
150                                 Gtk::TreeModel::Path path;
151                                 Gtk::TreeViewColumn *column;
152                                 int cell_x, cell_y;
153                                 if(!get_path_at_pos(
154                                         int(event->button.x),int(event->button.y),      // x, y
155                                         path, // TreeModel::Path&
156                                         column, //TreeViewColumn*&
157                                         cell_x,cell_y //int&cell_x,int&cell_y
158                                         )
159                                 ) break;
160                                 const Gtk::TreeRow row = *(get_model()->get_iter(path));
161
162                                 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
163                                 {
164                                         Gdk::Rectangle rect;
165                                         get_cell_area(path,*column,rect);
166                                         cellrenderer_time_track->property_value_desc()=row[model.value_desc];
167                                         cellrenderer_time_track->property_canvas()=row[model.canvas];
168                                         cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
169                                         queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
170                                         return true;
171                                         //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
172                                 }
173 /*                              else
174                                 {
175                                         if(event->button.button==3)
176                                         {
177                                                 LayerList layer_list(get_selected_layers());
178                                                 if(layer_list.size()<=1)
179                                                 {
180                                                         synfigapp::ValueDesc value_desc(row[model.value_desc]);
181                                                         Gtk::Menu* menu(manage(new Gtk::Menu()));
182                                                         menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
183                                                         App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc,0.5f);
184                                                         menu->popup(event->button.button,gtk_get_current_event_time());
185                                                         return true;
186                                                 }
187                                                 Gtk::Menu* menu(manage(new Gtk::Menu()));
188                                                 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
189                                                 std::list<synfigapp::ValueDesc> value_desc_list;
190                                                 ParamDesc param_desc(row[model.param_desc]);
191                                                 for(;!layer_list.empty();layer_list.pop_back())
192                                                         value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
193                                                 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
194                                                 menu->popup(event->button.button,gtk_get_current_event_time());
195                                                 return true;
196                                         }
197                                         else
198                                         {
199                                                 if(column->get_first_cell_renderer()==cellrenderer_value)
200                                                         return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
201                                                 else
202                                                         return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
203                                         }
204                                 }
205                                 */
206                         }
207                         break;
208
209                 case GDK_MOTION_NOTIFY:
210                         {
211                                 Gtk::TreeModel::Path path;
212                                 Gtk::TreeViewColumn *column;
213                                 int cell_x, cell_y;
214                                 if(!get_path_at_pos(
215                                         (int)event->motion.x,(int)event->motion.y,      // x, y
216                                         path, // TreeModel::Path&
217                                         column, //TreeViewColumn*&
218                                         cell_x,cell_y //int&cell_x,int&cell_y
219                                         )
220                                 ) break;
221
222                                 if(!get_model()->get_iter(path))
223                                         break;
224
225                                 Gtk::TreeRow row = *(get_model()->get_iter(path));
226
227                                 if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
228                                 {
229                                         Gdk::Rectangle rect;
230                                         get_cell_area(path,*column,rect);
231                                         cellrenderer_time_track->property_value_desc()=row[model.value_desc];
232                                         cellrenderer_time_track->property_canvas()=row[model.canvas];
233                                         cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
234                                         queue_draw();
235                                         //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
236                                         return true;
237                                 }
238 /*                              else
239                                 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
240                                 {
241                                         tooltips_.unset_tip(*this);
242                                         Glib::ustring tooltips_string(row[layer_model.tooltip]);
243                                         last_tooltip_path=path;
244                                         if(!tooltips_string.empty())
245                                         {
246                                                 tooltips_.set_tip(*this,tooltips_string);
247                                                 tooltips_.force_window();
248                                         }
249                                 }
250 */
251                                 return true;
252                         }
253                         break;
254                 case GDK_BUTTON_RELEASE:
255                         {
256                                 Gtk::TreeModel::Path path;
257                                 Gtk::TreeViewColumn *column;
258                                 int cell_x, cell_y;
259                                 if(!get_path_at_pos(
260                                         (int)event->button.x,(int)event->button.y,      // x, y
261                                         path, // TreeModel::Path&
262                                         column, //TreeViewColumn*&
263                                         cell_x,cell_y //int&cell_x,int&cell_y
264                                         )
265                                 ) break;
266
267                                 if(!get_model()->get_iter(path))
268                                         break;
269
270                                 Gtk::TreeRow row = *(get_model()->get_iter(path));
271
272                                 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
273                                 {
274                                         Gdk::Rectangle rect;
275                                         get_cell_area(path,*column,rect);
276                                         cellrenderer_time_track->property_value_desc()=row[model.value_desc];
277                                         cellrenderer_time_track->property_canvas()=row[model.canvas];
278                                         cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
279                                         queue_draw();
280                                         queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
281                                         return true;
282                                 }
283                         }
284                         break;
285                 default:
286                         break;
287                 }
288                 mimic_resync();
289                 return Gtk::TreeView::on_event(event);
290         }
291
292         void
293         queue_draw_msg()
294         {
295                 synfig::info("*************QUEUE_DRAW***************** (time track view)");
296                 Widget::queue_draw();
297         }
298         void set_model(Glib::RefPtr<LayerParamTreeStore> store)
299         {
300                 Gtk::TreeView::set_model(store);
301                 param_tree_store_=store;
302                 cellrenderer_time_track->set_canvas_interface(param_tree_store_->canvas_interface());
303                 store->signal_changed().connect(sigc::mem_fun(*this, &TimeTrackView::queue_draw));
304         }
305
306         void
307         on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
308         {
309                 synfigapp::Action::ParamList param_list;
310                 param_list.add("canvas",param_tree_store_->canvas_interface()->get_canvas());
311                 param_list.add("canvas_interface",param_tree_store_->canvas_interface());
312                 param_list.add("value_node",value_node);
313                 param_list.add("waypoint",waypoint);
314         //      param_list.add("time",canvas_interface()->get_time());
315
316                 etl::handle<studio::Instance>::cast_static(param_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
317         }
318
319         void mimic(Gtk::TreeView *param_tree_view)
320         {
321                 mimic_tree_view=param_tree_view;
322                 param_tree_view->signal_row_expanded().connect(
323                         sigc::hide<0>(
324                         sigc::hide_return(
325                                 sigc::bind<-1>(
326                                         sigc::mem_fun(
327                                                 *this,
328                                                 &Gtk::TreeView::expand_row
329                                         ),
330                                         false
331                                 )
332                         ))
333                 );
334                 param_tree_view->signal_row_collapsed().connect(
335                         sigc::hide<0>(
336                         sigc::hide_return(
337                                         sigc::mem_fun(
338                                                 *this,
339                                                 &Gtk::TreeView::collapse_row
340                                         )
341                         ))
342                 );
343                 mimic_resync();
344         }
345
346         void mimic_resync()
347         {
348
349                 if(mimic_tree_view)
350                 {
351                         Gtk::Adjustment &adjustment(*mimic_tree_view->get_vadjustment());
352                         set_vadjustment(adjustment);
353
354                         if(adjustment.get_page_size()>get_height())
355                                 adjustment.set_page_size(get_height());
356
357                         int row_height = 0;
358                         if(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"))
359                                 row_height = atoi(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"));
360                         if (row_height < 3)
361                                 row_height = 18;
362                                                                           
363                         cellrenderer_time_track->set_fixed_size(-1,row_height);
364                 }
365         }
366
367         void
368         on_waypoint_clicked(const Glib::ustring &/*path_string*/, synfig::Waypoint waypoint,int button)
369         {
370 /*
371                 Gtk::TreePath path(path_string);
372
373                 const Gtk::TreeRow row = *(get_model()->get_iter(path));
374                 if(!row)
375                         return;
376 */
377
378                 ValueNode::Handle value_node(waypoint.get_parent_value_node());
379                 assert(value_node);
380
381                 Gtk::TreeRow row;
382                 if(!param_tree_store_->find_first_value_node(value_node, row))
383                 {
384                         synfig::error(__FILE__":%d: Unable to find the valuenode",__LINE__);
385                         return;
386                 }
387
388                 if(!row)
389                         return;
390
391                 synfigapp::ValueDesc value_desc(static_cast<synfigapp::ValueDesc>(row[model.value_desc]));
392
393                 signal_waypoint_clicked(value_desc,waypoint,button);
394         }
395 };
396
397 /* === G L O B A L S ======================================================= */
398
399 /* === P R O C E D U R E S ================================================= */
400
401 /* === M E T H O D S ======================================================= */
402
403 Dock_Timetrack::Dock_Timetrack():
404         Dock_CanvasSpecific("timetrack",_("Timetrack"),Gtk::StockID("synfig-timetrack"))
405 {
406         table_=0;
407         widget_timeslider_= new Widget_Timeslider();
408
409         int header_height = 0;
410         if(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"))
411                 header_height = atoi(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"));
412         if (header_height < 3)
413                 header_height = 22;
414
415         widget_timeslider_->set_size_request(-1,header_height);
416         hscrollbar_=new Gtk::HScrollbar();
417         vscrollbar_=new Gtk::VScrollbar();
418 }
419
420 Dock_Timetrack::~Dock_Timetrack()
421 {
422         if(table_)delete table_;
423         delete hscrollbar_;
424         delete vscrollbar_;
425         delete widget_timeslider_;
426 }
427
428 void
429 Dock_Timetrack::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
430 {
431         LayerParamTreeStore::Model model;
432
433         Glib::RefPtr<LayerParamTreeStore> tree_store(
434                 Glib::RefPtr<LayerParamTreeStore>::cast_dynamic(
435                         canvas_view->get_tree_model("params")
436                 )
437         );
438
439         TimeTrackView* tree_view(new TimeTrackView());
440         tree_view->set_canvas_view(canvas_view);
441         tree_view->set_model(tree_store);
442         Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
443         tree_view->mimic(param_tree_view);
444
445         tree_view->signal_waypoint_clicked.connect(sigc::mem_fun(*canvas_view, &studio::CanvasView::on_waypoint_clicked));
446
447
448         canvas_view->time_adjustment().signal_value_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
449         canvas_view->time_adjustment().signal_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
450
451         canvas_view->set_ext_widget(get_name(),tree_view);
452 }
453
454 void
455 Dock_Timetrack::refresh_selected_param()
456 {
457 /*      Gtk::TreeView* tree_view(
458                 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
459         );
460         Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
461
462         if(iter)
463         {
464                 LayerParamTreeStore::Model model;
465                 get_canvas_view()->work_area->set_selected_value_node(
466                         (synfig::ValueNode::Handle)(*iter)[model.value_node]
467                 );
468         }
469         else
470         {
471                 get_canvas_view()->work_area->set_selected_value_node(0);
472         }
473 */
474 }
475
476 void
477 Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
478 {
479         if(table_)
480         {
481                 table_->hide();
482                 delete table_;
483                 hscrollbar_->unset_adjustment();
484                 vscrollbar_->unset_adjustment();
485                 //widget_timeslider_->unset_adjustment();
486                 table_=0;
487         }
488
489
490         if(canvas_view)
491         {
492                 TimeTrackView* tree_view(dynamic_cast<TimeTrackView*>(canvas_view->get_ext_widget(get_name())));
493         Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
494         tree_view->set_vadjustment(*param_tree_view->get_vadjustment());
495
496                 assert(tree_view);
497
498                 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
499                 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
500                 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
501
502                 vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
503                 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
504                 table_=new Gtk::Table(2,2);
505                 table_->attach(*widget_timeslider_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
506                 table_->attach(*tree_view, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
507                 table_->attach(*hscrollbar_, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
508                 table_->attach(*vscrollbar_, 1, 2, 0, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
509                 add(*table_);
510
511                 //add(*last_widget_curves_);
512                 table_->show_all();
513                 show_all();
514         }
515         else
516         {
517                 //clear_previous();
518         }
519 }