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 "childrentree.h"
34 #include "cellrenderer_value.h"
35 #include "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);
185 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
186 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
188 SMALL_BUTTON(button_raise,"gtk-go-up",_("Raise"));
189 SMALL_BUTTON(button_lower,"gtk-go-down",_("Lower"));
190 SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate"));
191 SMALL_BUTTON(button_delete,"gtk-delete",_("Delete"));
193 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
194 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
195 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
196 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
198 button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_raise_pressed));
199 button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_lower_pressed));
200 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_duplicate_pressed));
201 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_delete_pressed));
203 button_raise->set_sensitive(false);
204 button_lower->set_sensitive(false);
205 button_duplicate->set_sensitive(false);
206 button_delete->set_sensitive(false);
209 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
211 tree_view.set_reorderable(true);
218 //get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
221 ChildrenTree::~ChildrenTree()
226 ChildrenTree::set_show_timetrack(bool x)
228 column_time_track->set_visible(x);
232 ChildrenTree::set_model(Glib::RefPtr<ChildrenTreeStore> children_tree_store)
234 children_tree_store_=children_tree_store;
235 tree_view.set_model(children_tree_store_);
236 cellrenderer_time_track->set_canvas_interface(children_tree_store_->canvas_interface()); // am I smart people? (cellrenderer_timetrack.h:176)
237 children_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::ChildrenTree::on_dirty_preview));
241 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
243 cellrenderer_time_track->set_adjustment(adjustment);
247 ChildrenTree::on_dirty_preview()
252 ChildrenTree::on_selection_changed()
256 button_raise->set_sensitive(false);
257 button_lower->set_sensitive(false);
258 button_duplicate->set_sensitive(false);
259 button_delete->set_sensitive(false);
265 ChildrenTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
267 Gtk::TreePath path(path_string);
269 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
271 row[model.value]=value;
272 // signal_edited_value()(row[model.value_desc],value);
276 ChildrenTree::on_waypoint_clicked_childrentree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
277 const synfig::Time& time __attribute__ ((unused)),
278 const synfig::Time& time_offset __attribute__ ((unused)),
279 int button __attribute__ ((unused)))
281 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
282 synfig::waypoint_collect(waypoint_set,time,node);
284 synfigapp::ValueDesc value_desc;
286 if (waypoint_set.size() == 1)
288 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
292 if (children_tree_store_->find_first_value_node(value_node, row) && row)
293 value_desc = static_cast<synfigapp::ValueDesc>(row[model.value_desc]);
296 if (!waypoint_set.empty())
297 signal_waypoint_clicked_childrentree()(value_desc,waypoint_set,button);
301 ChildrenTree::on_tree_event(GdkEvent *event)
305 case GDK_BUTTON_PRESS:
307 Gtk::TreeModel::Path path;
308 Gtk::TreeViewColumn *column;
310 if(!tree_view.get_path_at_pos(
311 int(event->button.x),int(event->button.y), // x, y
312 path, // TreeModel::Path&
313 column, //TreeViewColumn*&
314 cell_x,cell_y //int&cell_x,int&cell_y
317 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
319 if(column->get_first_cell_renderer()==cellrenderer_time_track)
322 tree_view.get_cell_area(path,*column,rect);
323 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
324 cellrenderer_time_track->property_canvas()=row[model.canvas];
325 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
326 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
329 else if(column->get_first_cell_renderer()==cellrenderer_value)
330 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
332 return signal_user_click()(event->button.button,row,COLUMNID_ID);
337 case GDK_MOTION_NOTIFY:
339 Gtk::TreeModel::Path path;
340 Gtk::TreeViewColumn *column;
342 if(!tree_view.get_path_at_pos(
343 (int)event->button.x,(int)event->button.y, // x, y
344 path, // TreeModel::Path&
345 column, //TreeViewColumn*&
346 cell_x,cell_y //int&cell_x,int&cell_y
350 if(!tree_view.get_model()->get_iter(path))
353 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
355 if(cellrenderer_time_track==column->get_first_cell_renderer())
357 // Movement on TimeLine
359 tree_view.get_cell_area(path,*column,rect);
360 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
361 cellrenderer_time_track->property_canvas()=row[model.canvas];
362 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
364 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
368 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
370 tooltips_.unset_tip(*this);
371 Glib::ustring tooltips_string(row[model.tooltip]);
372 last_tooltip_path=path;
373 if(!tooltips_string.empty())
375 tooltips_.set_tip(*this,tooltips_string);
376 tooltips_.force_window();
381 case GDK_BUTTON_RELEASE:
383 Gtk::TreeModel::Path path;
384 Gtk::TreeViewColumn *column;
386 if(!tree_view.get_path_at_pos(
387 (int)event->button.x,(int)event->button.y, // x, y
388 path, // TreeModel::Path&
389 column, //TreeViewColumn*&
390 cell_x,cell_y //int&cell_x,int&cell_y
394 if(!tree_view.get_model()->get_iter(path))
397 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
399 if(column && cellrenderer_time_track == column->get_first_cell_renderer())
402 tree_view.get_cell_area(path,*column,rect);
403 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
404 cellrenderer_time_track->property_canvas()=row[model.canvas];
405 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
407 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
419 ChildrenTree::on_raise_pressed()
424 ChildrenTree::on_lower_pressed()
429 ChildrenTree::on_duplicate_pressed()
434 ChildrenTree::on_delete_pressed()