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
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
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>
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
51 #define SMALL_BUTTON(button,stockid,tooltip) \
52 button = manage(new class Gtk::Button()); \
53 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
55 tooltips_.set_tip(*button,tooltip); \
56 icon->set_padding(0,0);\
58 button->set_relief(Gtk::RELIEF_NONE); \
63 #define NORMAL_BUTTON(button,stockid,tooltip) \
64 button = manage(new class Gtk::Button()); \
65 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
67 tooltips_.set_tip(*button,tooltip); \
68 icon->set_padding(0,0);\
70 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
74 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
76 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
78 /* === G L O B A L S ======================================================= */
80 /* === P R O C E D U R E S ================================================= */
82 /* === M E T H O D S ======================================================= */
84 ChildrenTree::ChildrenTree()
86 const ChildrenTreeStore::Model model;
88 { // --- N A M E --------------------------------------------------------
89 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
91 // Set up the icon cell-renderer
92 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
93 column->pack_start(*icon_cellrenderer,false);
94 column->add_attribute(icon_cellrenderer->property_pixbuf(), model.icon);
96 // Pack the label into the column
97 column->pack_start(model.label,true);
99 // Finish setting up the column
100 column->set_reorderable();
101 column->set_resizable();
102 column->set_clickable();
103 column->set_min_width(150);
104 column->set_sort_column_id(model.label);
105 tree_view.append_column(*column);
108 { // --- T Y P E --------------------------------------------------------
109 int cols_count = tree_view.append_column(_("Type"),model.type);
110 Gtk::TreeViewColumn* column = tree_view.get_column(cols_count-1);
113 column->set_reorderable();
114 column->set_resizable();
115 column->set_clickable();
116 column->set_sort_column_id(model.type);
119 { // --- V A L U E -----------------------------------------------------
120 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
122 // Set up the value cell-renderer
123 cellrenderer_value=ChildrenTreeStore::add_cell_renderer_value(column);
124 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_edited_value));
125 cellrenderer_value->property_value()=synfig::ValueBase();
127 // Finish setting up the column
128 tree_view.append_column(*column);
129 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
130 column->set_min_width(150);
131 column->set_reorderable();
132 column->set_resizable();
133 column->set_clickable(false);
135 { // --- T I M E T R A C K --------------------------------------------
136 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
137 column_time_track=column;
139 // Set up the value-node cell-renderer
140 cellrenderer_time_track=ChildrenTreeStore::add_cell_renderer_value_node(column);
141 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
142 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_waypoint_clicked) );
143 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
144 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
146 //column->pack_start(*cellrenderer_time_track);
148 // Finish setting up the column
149 column->set_reorderable();
150 column->set_resizable();
151 tree_view.append_column(*column);
154 // This makes things easier to read.
155 tree_view.set_rules_hint();
157 // Make us more sensitive to several events
158 tree_view.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
160 tree_view.signal_event().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_tree_event));
162 // Create a scrolled window for that tree
163 Gtk::ScrolledWindow *scroll_children_tree = manage(new class Gtk::ScrolledWindow());
164 scroll_children_tree->set_flags(Gtk::CAN_FOCUS);
165 scroll_children_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
166 scroll_children_tree->add(tree_view);
167 scroll_children_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
168 scroll_children_tree->show();
170 attach(*scroll_children_tree, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
172 hbox=manage(new Gtk::HBox());
174 attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
178 tree_view.set_enable_search(true);
179 tree_view.set_search_column(model.label);
184 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
185 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
187 SMALL_BUTTON(button_raise,"gtk-go-up","Raise");
188 SMALL_BUTTON(button_lower,"gtk-go-down","Lower");
189 SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate");
190 SMALL_BUTTON(button_delete,"gtk-delete","Delete");
192 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
193 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
194 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
195 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
197 button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_raise_pressed));
198 button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_lower_pressed));
199 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_duplicate_pressed));
200 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_delete_pressed));
202 button_raise->set_sensitive(false);
203 button_lower->set_sensitive(false);
204 button_duplicate->set_sensitive(false);
205 button_delete->set_sensitive(false);
210 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
213 tree_view.set_reorderable(true);
220 //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 children_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::ChildrenTree::on_dirty_preview));
243 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
245 cellrenderer_time_track->set_adjustment(adjustment);
249 ChildrenTree::on_dirty_preview()
254 ChildrenTree::on_selection_changed()
258 button_raise->set_sensitive(false);
259 button_lower->set_sensitive(false);
260 button_duplicate->set_sensitive(false);
261 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(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
281 Gtk::TreePath path(path_string);
283 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
285 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[model.value_desc]),waypoint,button);
289 ChildrenTree::on_tree_event(GdkEvent *event)
293 case GDK_BUTTON_PRESS:
295 Gtk::TreeModel::Path path;
296 Gtk::TreeViewColumn *column;
298 if(!tree_view.get_path_at_pos(
299 int(event->button.x),int(event->button.y), // x, y
300 path, // TreeModel::Path&
301 column, //TreeViewColumn*&
302 cell_x,cell_y //int&cell_x,int&cell_y
305 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
307 if(column->get_first_cell_renderer()==cellrenderer_time_track)
309 return signal_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
311 else if(column->get_first_cell_renderer()==cellrenderer_value)
312 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
314 return signal_user_click()(event->button.button,row,COLUMNID_ID);
319 case GDK_MOTION_NOTIFY:
321 Gtk::TreeModel::Path path;
322 Gtk::TreeViewColumn *column;
324 if(!tree_view.get_path_at_pos(
325 (int)event->button.x,(int)event->button.y, // x, y
326 path, // TreeModel::Path&
327 column, //TreeViewColumn*&
328 cell_x,cell_y //int&cell_x,int&cell_y
332 if(!tree_view.get_model()->get_iter(path))
335 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
337 if(cellrenderer_time_track==column->get_first_cell_renderer())
339 // Movement on TimeLine
343 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
345 tooltips_.unset_tip(*this);
346 Glib::ustring tooltips_string(row[model.tooltip]);
347 last_tooltip_path=path;
348 if(!tooltips_string.empty())
350 tooltips_.set_tip(*this,tooltips_string);
351 tooltips_.force_window();
356 case GDK_BUTTON_RELEASE:
365 ChildrenTree::on_raise_pressed()
370 ChildrenTree::on_lower_pressed()
375 ChildrenTree::on_duplicate_pressed()
380 ChildrenTree::on_delete_pressed()