Added "--with-userdir" to configure script to change the default user settings directory
[synfig.git] / synfig-studio / trunk / src / gtkmm / dock_curves.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dock_params.cpp
3 **      \brief Template File
4 **
5 **      $Id: dock_curves.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "dock_curves.h"
33 #include "app.h"
34
35 #include <gtkmm/scrolledwindow.h>
36 #include <cassert>
37 #include "instance.h"
38 #include <sigc++/signal.h>
39 #include <sigc++/hide.h>
40 #include <sigc++/slot.h>
41 #include "canvasview.h"
42 #include "layerparamtreestore.h"
43 #include "workarea.h"
44 #include "widget_curves.h"
45 #include "layerparamtreestore.h"
46 #include <gtkmm/table.h>
47 #include <gtkmm/scrollbar.h>
48 #include "widget_timeslider.h"
49
50 #endif
51
52 /* === U S I N G =========================================================== */
53
54 using namespace std;
55 using namespace etl;
56 using namespace synfig;
57 using namespace studio;
58
59 /* === M A C R O S ========================================================= */
60
61 /* === G L O B A L S ======================================================= */
62
63 /* === P R O C E D U R E S ================================================= */
64
65 /* === M E T H O D S ======================================================= */
66
67 Dock_Curves::Dock_Curves():
68         Dock_CanvasSpecific("curves",_("Curves"),Gtk::StockID("synfig-curves"))
69 {
70         last_widget_curves_=0;
71         table_=0;
72         
73         hscrollbar_=new Gtk::HScrollbar();
74         vscrollbar_=new Gtk::VScrollbar();
75         widget_timeslider_= new Widget_Timeslider();
76 }
77
78 Dock_Curves::~Dock_Curves()
79 {
80         if(table_)delete table_;
81         delete hscrollbar_;
82         delete vscrollbar_;
83         delete widget_timeslider_;
84 }
85
86 static void
87 _curve_selection_changed(Gtk::TreeView* param_tree_view,Widget_Curves* curves)
88 {
89         LayerParamTreeStore::Model model;
90         Gtk::TreeIter iter;
91         if(!param_tree_view->get_selection()->count_selected_rows())
92         {
93                 curves->clear();
94                 return;
95         }
96         
97         std::list<synfigapp::ValueDesc> value_descs;
98
99         //std::list<Gtk::TreePath> path_list(
100         //param_tree_view->get_selection()->selected_foreach_iter(tmp);
101         iter=param_tree_view->get_selection()->get_selected();
102         
103         value_descs.push_back((*iter)[model.value_desc]);
104         curves->set_value_descs(value_descs);
105         
106         //curves->set_value_descs(tmp.value_descs);     
107 }
108
109 void
110 Dock_Curves::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
111 {
112         Widget_Curves* curves(new Widget_Curves());
113         curves->set_time_adjustment(canvas_view->time_adjustment());
114         
115         Gtk::TreeView* param_tree_view(
116                 static_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params"))
117         );
118         
119         param_tree_view->get_selection()->signal_changed().connect(
120                 sigc::bind(
121                         sigc::bind(
122                                 sigc::ptr_fun(
123                                         _curve_selection_changed
124                                 ),curves
125                         ),param_tree_view
126                 )
127         );
128         
129         canvas_view->set_ext_widget(get_name(),curves);
130 }
131
132 void
133 Dock_Curves::refresh_selected_param()
134 {
135 /*      Gtk::TreeView* tree_view(
136                 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
137         );
138         Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
139         
140         if(iter)
141         {
142                 LayerParamTreeStore::Model model;
143                 get_canvas_view()->work_area->set_selected_value_node(
144                         (synfig::ValueNode::Handle)(*iter)[model.value_node]
145                 );
146         }
147         else
148         {
149                 get_canvas_view()->work_area->set_selected_value_node(0);
150         }
151 */
152 }
153
154 void
155 Dock_Curves::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
156 {
157         if(table_)
158         {
159                 table_->hide();
160                 delete table_;
161                 hscrollbar_->unset_adjustment();
162                 vscrollbar_->unset_adjustment();
163                 //widget_timeslider_->unset_adjustment();
164                 table_=0;
165         }
166
167         
168         if(canvas_view)
169         {
170                 last_widget_curves_=dynamic_cast<Widget_Curves*>(
171                         canvas_view->get_ext_widget(get_name())
172                 );
173
174                 vscrollbar_->set_adjustment(last_widget_curves_->get_range_adjustment());
175                 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
176                 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
177                 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
178                 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
179
180                 table_=new Gtk::Table(2,2);
181                 table_->attach(*widget_timeslider_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
182                 table_->attach(*last_widget_curves_, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
183                 table_->attach(*hscrollbar_, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
184                 table_->attach(*vscrollbar_, 1, 2, 0, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
185                 add(*table_);
186                 
187                 //add(*last_widget_curves_);
188                 last_widget_curves_->show();
189                 table_->show_all();
190                 show_all();
191         }
192         else
193         {
194                 //clear_previous();
195         }
196 }