1 /* === S Y N F I G ========================================================= */
2 /*! \file childrentree.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "trees/childrentree.h"
34 #include "cellrenderer/cellrenderer_value.h"
35 #include "cellrenderer/cellrenderer_timetrack.h"
36 #include <synfigapp/action.h>
37 #include <synfigapp/instance.h>
38 #include <gtkmm/scrolledwindow.h>
39 #include <synfig/timepointcollect.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
55 #define SMALL_BUTTON(button,stockid,tooltip) \
56 button = manage(new class Gtk::Button()); \
57 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
59 tooltips_.set_tip(*button,tooltip); \
60 icon->set_padding(0,0);\
62 button->set_relief(Gtk::RELIEF_NONE); \
67 #define NORMAL_BUTTON(button,stockid,tooltip) \
68 button = manage(new class Gtk::Button()); \
69 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
71 tooltips_.set_tip(*button,tooltip); \
72 icon->set_padding(0,0);\
74 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
78 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
80 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
82 /* === G L O B A L S ======================================================= */
84 /* === P R O C E D U R E S ================================================= */
86 /* === M E T H O D S ======================================================= */
88 ChildrenTree::ChildrenTree()
90 const ChildrenTreeStore::Model model;
92 { // --- N A M E --------------------------------------------------------
93 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
95 // Set up the icon cell-renderer
96 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
97 column->pack_start(*icon_cellrenderer,false);
98 column->add_attribute(icon_cellrenderer->property_pixbuf(), model.icon);
100 // Pack the label into the column
101 column->pack_start(model.label,true);
103 // Finish setting up the column
104 column->set_reorderable();
105 column->set_resizable();
106 column->set_clickable();
107 column->set_min_width(150);
108 column->set_sort_column(model.label);
109 tree_view.append_column(*column);
112 { // --- T Y P E --------------------------------------------------------
113 int cols_count = tree_view.append_column(_("Type"),model.type);
114 Gtk::TreeViewColumn* column = tree_view.get_column(cols_count-1);
117 column->set_reorderable();
118 column->set_resizable();
119 column->set_clickable();
120 column->set_sort_column(model.type);
123 { // --- V A L U E -----------------------------------------------------
124 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
126 // Set up the value cell-renderer
127 cellrenderer_value=ChildrenTreeStore::add_cell_renderer_value(column);
128 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_edited_value));
129 cellrenderer_value->property_value()=synfig::ValueBase();
131 // Finish setting up the column
132 tree_view.append_column(*column);
133 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
134 column->set_min_width(150);
135 column->set_reorderable();
136 column->set_resizable();
137 column->set_clickable(false);
139 { // --- T I M E T R A C K --------------------------------------------
140 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
141 column_time_track=column;
143 // Set up the value-node cell-renderer
144 cellrenderer_time_track=ChildrenTreeStore::add_cell_renderer_value_node(column);
145 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
146 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_waypoint_clicked_childrentree) );
147 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
148 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
150 //column->pack_start(*cellrenderer_time_track);
152 // Finish setting up the column
153 column->set_reorderable();
154 column->set_resizable();
155 tree_view.append_column(*column);
158 // This makes things easier to read.
159 tree_view.set_rules_hint();
161 // Make us more sensitive to several events
162 tree_view.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
164 tree_view.signal_event().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_tree_event));
166 // Create a scrolled window for that tree
167 Gtk::ScrolledWindow *scroll_children_tree = manage(new class Gtk::ScrolledWindow());
168 scroll_children_tree->set_flags(Gtk::CAN_FOCUS);
169 scroll_children_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
170 scroll_children_tree->add(tree_view);
171 scroll_children_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
172 scroll_children_tree->show();
174 attach(*scroll_children_tree, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
176 hbox=manage(new Gtk::HBox());
178 attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
180 tree_view.set_enable_search(true);
181 tree_view.set_search_column(model.label);
183 /* // Buttons to raise/lower/duplicate/delete children valuenodes
184 // Commented out because these functions are not implemented
185 // and children sort themselves alphabetically
188 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
189 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
191 SMALL_BUTTON(button_raise,"gtk-go-up",_("Raise"));
192 SMALL_BUTTON(button_lower,"gtk-go-down",_("Lower"));
193 SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate"));
194 SMALL_BUTTON(button_delete,"gtk-delete",_("Delete"));
196 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
197 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
198 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
199 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
201 button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_raise_pressed));
202 button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_lower_pressed));
203 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_duplicate_pressed));
204 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_delete_pressed));
206 button_raise->set_sensitive(false);
207 button_lower->set_sensitive(false);
208 button_duplicate->set_sensitive(false);
209 button_delete->set_sensitive(false);
212 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
214 tree_view.set_reorderable(true);
221 //get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
224 ChildrenTree::~ChildrenTree()
229 ChildrenTree::set_show_timetrack(bool x)
231 column_time_track->set_visible(x);
235 ChildrenTree::set_model(Glib::RefPtr<ChildrenTreeStore> children_tree_store)
237 children_tree_store_=children_tree_store;
238 tree_view.set_model(children_tree_store_);
239 cellrenderer_time_track->set_canvas_interface(children_tree_store_->canvas_interface()); // am I smart people? (cellrenderer/cellrenderer_timetrack.h:176)
240 children_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::ChildrenTree::on_dirty_preview));
244 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
246 cellrenderer_time_track->set_adjustment(adjustment);
250 ChildrenTree::on_dirty_preview()
255 ChildrenTree::on_selection_changed()
259 button_raise->set_sensitive(false);
260 button_lower->set_sensitive(false);
261 button_duplicate->set_sensitive(false);
262 button_delete->set_sensitive(false);
268 ChildrenTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
270 Gtk::TreePath path(path_string);
272 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
274 row[model.value]=value;
275 // signal_edited_value()(row[model.value_desc],value);
279 ChildrenTree::on_waypoint_clicked_childrentree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
280 const synfig::Time& time __attribute__ ((unused)),
281 const synfig::Time& time_offset __attribute__ ((unused)),
282 int button __attribute__ ((unused)))
284 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
285 synfig::waypoint_collect(waypoint_set,time,node);
287 synfigapp::ValueDesc value_desc;
289 if (waypoint_set.size() == 1)
291 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
295 if (children_tree_store_->find_first_value_node(value_node, row) && row)
296 value_desc = static_cast<synfigapp::ValueDesc>(row[model.value_desc]);
299 if (!waypoint_set.empty())
300 signal_waypoint_clicked_childrentree()(value_desc,waypoint_set,button);
304 ChildrenTree::on_tree_event(GdkEvent *event)
308 case GDK_BUTTON_PRESS:
310 Gtk::TreeModel::Path path;
311 Gtk::TreeViewColumn *column;
313 if(!tree_view.get_path_at_pos(
314 int(event->button.x),int(event->button.y), // x, y
315 path, // TreeModel::Path&
316 column, //TreeViewColumn*&
317 cell_x,cell_y //int&cell_x,int&cell_y
320 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
322 if(column->get_first_cell_renderer()==cellrenderer_time_track)
325 tree_view.get_cell_area(path,*column,rect);
326 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
327 cellrenderer_time_track->property_canvas()=row[model.canvas];
328 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
329 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
332 else if(column->get_first_cell_renderer()==cellrenderer_value)
333 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
335 return signal_user_click()(event->button.button,row,COLUMNID_ID);
340 case GDK_MOTION_NOTIFY:
342 Gtk::TreeModel::Path path;
343 Gtk::TreeViewColumn *column;
345 if(!tree_view.get_path_at_pos(
346 (int)event->button.x,(int)event->button.y, // x, y
347 path, // TreeModel::Path&
348 column, //TreeViewColumn*&
349 cell_x,cell_y //int&cell_x,int&cell_y
353 if(!tree_view.get_model()->get_iter(path))
356 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
358 if(cellrenderer_time_track==column->get_first_cell_renderer())
360 // Movement on TimeLine
362 tree_view.get_cell_area(path,*column,rect);
363 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
364 cellrenderer_time_track->property_canvas()=row[model.canvas];
365 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
367 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
371 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
373 tooltips_.unset_tip(*this);
374 Glib::ustring tooltips_string(row[model.tooltip]);
375 last_tooltip_path=path;
376 if(!tooltips_string.empty())
378 tooltips_.set_tip(*this,tooltips_string);
379 tooltips_.force_window();
384 case GDK_BUTTON_RELEASE:
386 Gtk::TreeModel::Path path;
387 Gtk::TreeViewColumn *column;
389 if(!tree_view.get_path_at_pos(
390 (int)event->button.x,(int)event->button.y, // x, y
391 path, // TreeModel::Path&
392 column, //TreeViewColumn*&
393 cell_x,cell_y //int&cell_x,int&cell_y
397 if(!tree_view.get_model()->get_iter(path))
400 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
402 if(column && cellrenderer_time_track == column->get_first_cell_renderer())
405 tree_view.get_cell_area(path,*column,rect);
406 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
407 cellrenderer_time_track->property_canvas()=row[model.canvas];
408 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
410 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
422 ChildrenTree::on_raise_pressed()
427 ChildrenTree::on_lower_pressed()
432 ChildrenTree::on_duplicate_pressed()
437 ChildrenTree::on_delete_pressed()