Don't ask translators to translate compview.cpp since it isn't compiled. Fix typo...
[synfig.git] / synfig-studio / trunk / src / gtkmm / childrentree.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file childrentree.cpp
3 **      \brief Template File
4 **
5 **      $Id$
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 "childrentree.h"
33 #include "cellrenderer_value.h"
34 #include "cellrenderer_timetrack.h"
35 #include <synfigapp/action.h>
36 #include <synfigapp/instance.h>
37 #include <gtkmm/scrolledwindow.h>
38
39 #include "general.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
51
52 #ifndef SMALL_BUTTON
53 #define SMALL_BUTTON(button,stockid,tooltip)    \
54         button = manage(new class Gtk::Button());       \
55         icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize));    \
56         button->add(*icon);     \
57         tooltips_.set_tip(*button,tooltip);     \
58         icon->set_padding(0,0);\
59         icon->show();   \
60         button->set_relief(Gtk::RELIEF_NONE); \
61         button->show()
62 #endif
63
64 #ifndef NORMAL_BUTTON
65 #define NORMAL_BUTTON(button,stockid,tooltip)   \
66         button = manage(new class Gtk::Button());       \
67         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON));       \
68         button->add(*icon);     \
69         tooltips_.set_tip(*button,tooltip);     \
70         icon->set_padding(0,0);\
71         icon->show();   \
72         /*button->set_relief(Gtk::RELIEF_NONE);*/ \
73         button->show()
74 #endif
75
76 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
77
78 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
79
80 /* === G L O B A L S ======================================================= */
81
82 /* === P R O C E D U R E S ================================================= */
83
84 /* === M E T H O D S ======================================================= */
85
86 ChildrenTree::ChildrenTree()
87 {
88         const ChildrenTreeStore::Model model;
89
90         {       // --- N A M E --------------------------------------------------------
91                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
92
93                 // Set up the icon cell-renderer
94                 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
95                 column->pack_start(*icon_cellrenderer,false);
96                 column->add_attribute(icon_cellrenderer->property_pixbuf(), model.icon);
97
98                 // Pack the label into the column
99                 column->pack_start(model.label,true);
100
101                 // Finish setting up the column
102                 column->set_reorderable();
103                 column->set_resizable();
104                 column->set_clickable();
105                 column->set_min_width(150);
106                 column->set_sort_column(model.label);
107                 tree_view.append_column(*column);
108
109         }
110         {       // --- T Y P E --------------------------------------------------------
111                 int cols_count = tree_view.append_column(_("Type"),model.type);
112                 Gtk::TreeViewColumn* column = tree_view.get_column(cols_count-1);
113                 if(column)
114                 {
115                         column->set_reorderable();
116                         column->set_resizable();
117                         column->set_clickable();
118                         column->set_sort_column(model.type);
119                 }
120         }
121         {       // --- V A L U E  -----------------------------------------------------
122                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
123
124                 // Set up the value cell-renderer
125                 cellrenderer_value=ChildrenTreeStore::add_cell_renderer_value(column);
126                 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_edited_value));
127                 cellrenderer_value->property_value()=synfig::ValueBase();
128
129                 // Finish setting up the column
130                 tree_view.append_column(*column);
131                 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
132                 column->set_min_width(150);
133                 column->set_reorderable();
134                 column->set_resizable();
135                 column->set_clickable(false);
136         }
137         {       // --- T I M E   T R A C K --------------------------------------------
138                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
139                 column_time_track=column;
140
141                 // Set up the value-node cell-renderer
142                 cellrenderer_time_track=ChildrenTreeStore::add_cell_renderer_value_node(column);
143                 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
144                 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_waypoint_clicked_childrentree) );
145                 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
146                 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
147
148                 //column->pack_start(*cellrenderer_time_track);
149
150                 // Finish setting up the column
151                 column->set_reorderable();
152                 column->set_resizable();
153                 tree_view.append_column(*column);
154         }
155
156         // This makes things easier to read.
157         tree_view.set_rules_hint();
158
159         // Make us more sensitive to several events
160         tree_view.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
161
162         tree_view.signal_event().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_tree_event));
163
164         // Create a scrolled window for that tree
165         Gtk::ScrolledWindow *scroll_children_tree = manage(new class Gtk::ScrolledWindow());
166         scroll_children_tree->set_flags(Gtk::CAN_FOCUS);
167         scroll_children_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
168         scroll_children_tree->add(tree_view);
169         scroll_children_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
170         scroll_children_tree->show();
171
172         attach(*scroll_children_tree, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
173
174         hbox=manage(new Gtk::HBox());
175
176         attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
177
178
179
180         tree_view.set_enable_search(true);
181         tree_view.set_search_column(model.label);
182
183
184 /*
185         Gtk::Image *icon;
186         //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
187         Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
188
189         SMALL_BUTTON(button_raise,"gtk-go-up",_("Raise"));
190         SMALL_BUTTON(button_lower,"gtk-go-down",_("Lower"));
191         SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate"));
192         SMALL_BUTTON(button_delete,"gtk-delete",_("Delete"));
193
194         hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
195         hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
196         hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
197         hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
198
199         button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_raise_pressed));
200         button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_lower_pressed));
201         button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_duplicate_pressed));
202         button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_delete_pressed));
203
204         button_raise->set_sensitive(false);
205         button_lower->set_sensitive(false);
206         button_duplicate->set_sensitive(false);
207         button_delete->set_sensitive(false);
208 */
209
210
211
212         get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
213
214
215         tree_view.set_reorderable(true);
216
217         hbox->show();
218         tree_view.show();
219
220         tooltips_.enable();
221
222         //get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
223 }
224
225
226 ChildrenTree::~ChildrenTree()
227 {
228 }
229
230 void
231 ChildrenTree::set_show_timetrack(bool x)
232 {
233         column_time_track->set_visible(x);
234 }
235
236 void
237 ChildrenTree::set_model(Glib::RefPtr<ChildrenTreeStore> children_tree_store)
238 {
239         children_tree_store_=children_tree_store;
240         tree_view.set_model(children_tree_store_);
241         children_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::ChildrenTree::on_dirty_preview));
242 }
243
244 void
245 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
246 {
247         cellrenderer_time_track->set_adjustment(adjustment);
248 }
249
250 void
251 ChildrenTree::on_dirty_preview()
252 {
253 }
254
255 void
256 ChildrenTree::on_selection_changed()
257 {
258         if(0)
259                 {
260                 button_raise->set_sensitive(false);
261                 button_lower->set_sensitive(false);
262                 button_duplicate->set_sensitive(false);
263                 button_delete->set_sensitive(false);
264                 return;
265         }
266 }
267
268
269 void
270 ChildrenTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
271 {
272         Gtk::TreePath path(path_string);
273
274         const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
275
276         row[model.value]=value;
277 //      signal_edited_value()(row[model.value_desc],value);
278 }
279
280 void
281 ChildrenTree::on_waypoint_clicked_childrentree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
282                                                                                            const synfig::Time& time __attribute__ ((unused)),
283                                                                                            const synfig::Time& time_offset __attribute__ ((unused)),
284                                                                                            int button __attribute__ ((unused)),
285                                                                                            synfig::Waypoint::Side side __attribute__ ((unused)))
286 {
287         //! \todo writeme
288
289         // std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
290         // signal_waypoint_clicked_childrentree()(waypoint_set,button,side);
291 }
292
293 bool
294 ChildrenTree::on_tree_event(GdkEvent *event)
295 {
296     switch(event->type)
297     {
298         case GDK_BUTTON_PRESS:
299                 {
300                         Gtk::TreeModel::Path path;
301                         Gtk::TreeViewColumn *column;
302                         int cell_x, cell_y;
303                         if(!tree_view.get_path_at_pos(
304                                 int(event->button.x),int(event->button.y),      // x, y
305                                 path, // TreeModel::Path&
306                                 column, //TreeViewColumn*&
307                                 cell_x,cell_y //int&cell_x,int&cell_y
308                                 )
309                         ) break;
310                         const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
311
312                         if(column->get_first_cell_renderer()==cellrenderer_time_track)
313                         {
314                                 return signal_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
315                         }
316                         else if(column->get_first_cell_renderer()==cellrenderer_value)
317                                 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
318                         else
319                                 return signal_user_click()(event->button.button,row,COLUMNID_ID);
320
321                 }
322                 break;
323
324         case GDK_MOTION_NOTIFY:
325                 {
326                         Gtk::TreeModel::Path path;
327                         Gtk::TreeViewColumn *column;
328                         int cell_x, cell_y;
329                         if(!tree_view.get_path_at_pos(
330                                 (int)event->button.x,(int)event->button.y,      // x, y
331                                 path, // TreeModel::Path&
332                                 column, //TreeViewColumn*&
333                                 cell_x,cell_y //int&cell_x,int&cell_y
334                                 )
335                         ) break;
336
337                         if(!tree_view.get_model()->get_iter(path))
338                                 break;
339
340                         Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
341
342                         if(cellrenderer_time_track==column->get_first_cell_renderer())
343                         {
344                                 // Movement on TimeLine
345                                 return true;
346                         }
347                         else
348                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
349                         {
350                                 tooltips_.unset_tip(*this);
351                                 Glib::ustring tooltips_string(row[model.tooltip]);
352                                 last_tooltip_path=path;
353                                 if(!tooltips_string.empty())
354                                 {
355                                         tooltips_.set_tip(*this,tooltips_string);
356                                         tooltips_.force_window();
357                                 }
358                         }
359                 }
360                 break;
361         case GDK_BUTTON_RELEASE:
362                 break;
363         default:
364                 break;
365         }
366         return false;
367 }
368
369 void
370 ChildrenTree::on_raise_pressed()
371 {
372 }
373
374 void
375 ChildrenTree::on_lower_pressed()
376 {
377 }
378
379 void
380 ChildrenTree::on_duplicate_pressed()
381 {
382 }
383
384 void
385 ChildrenTree::on_delete_pressed()
386 {
387 }