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>
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
48 using namespace studio;
50 /* === M A C R O S ========================================================= */
53 #define SMALL_BUTTON(button,stockid,tooltip) \
54 button = manage(new class Gtk::Button()); \
55 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
57 tooltips_.set_tip(*button,tooltip); \
58 icon->set_padding(0,0);\
60 button->set_relief(Gtk::RELIEF_NONE); \
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)); \
69 tooltips_.set_tip(*button,tooltip); \
70 icon->set_padding(0,0);\
72 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
76 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
78 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
80 /* === G L O B A L S ======================================================= */
82 /* === P R O C E D U R E S ================================================= */
84 /* === M E T H O D S ======================================================= */
86 ChildrenTree::ChildrenTree()
88 const ChildrenTreeStore::Model model;
90 { // --- N A M E --------------------------------------------------------
91 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
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);
98 // Pack the label into the column
99 column->pack_start(model.label,true);
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);
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);
115 column->set_reorderable();
116 column->set_resizable();
117 column->set_clickable();
118 column->set_sort_column(model.type);
121 { // --- V A L U E -----------------------------------------------------
122 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
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();
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);
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;
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().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_waypoint_clicked) );
145 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
146 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
148 //column->pack_start(*cellrenderer_time_track);
150 // Finish setting up the column
151 column->set_reorderable();
152 column->set_resizable();
153 tree_view.append_column(*column);
156 // This makes things easier to read.
157 tree_view.set_rules_hint();
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);
162 tree_view.signal_event().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_tree_event));
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();
172 attach(*scroll_children_tree, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
174 hbox=manage(new Gtk::HBox());
176 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);
186 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
187 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
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"));
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);
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));
204 button_raise->set_sensitive(false);
205 button_lower->set_sensitive(false);
206 button_duplicate->set_sensitive(false);
207 button_delete->set_sensitive(false);
212 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
215 tree_view.set_reorderable(true);
222 //get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
226 ChildrenTree::~ChildrenTree()
231 ChildrenTree::set_show_timetrack(bool x)
233 column_time_track->set_visible(x);
237 ChildrenTree::set_model(Glib::RefPtr<ChildrenTreeStore> children_tree_store)
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));
245 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
247 cellrenderer_time_track->set_adjustment(adjustment);
251 ChildrenTree::on_dirty_preview()
256 ChildrenTree::on_selection_changed()
260 button_raise->set_sensitive(false);
261 button_lower->set_sensitive(false);
262 button_duplicate->set_sensitive(false);
263 button_delete->set_sensitive(false);
270 ChildrenTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
272 Gtk::TreePath path(path_string);
274 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
276 row[model.value]=value;
277 // signal_edited_value()(row[model.value_desc],value);
281 ChildrenTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
283 Gtk::TreePath path(path_string);
285 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
287 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[model.value_desc]),waypoint,button);
291 ChildrenTree::on_tree_event(GdkEvent *event)
295 case GDK_BUTTON_PRESS:
297 Gtk::TreeModel::Path path;
298 Gtk::TreeViewColumn *column;
300 if(!tree_view.get_path_at_pos(
301 int(event->button.x),int(event->button.y), // x, y
302 path, // TreeModel::Path&
303 column, //TreeViewColumn*&
304 cell_x,cell_y //int&cell_x,int&cell_y
307 const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
309 if(column->get_first_cell_renderer()==cellrenderer_time_track)
311 return signal_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
313 else if(column->get_first_cell_renderer()==cellrenderer_value)
314 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
316 return signal_user_click()(event->button.button,row,COLUMNID_ID);
321 case GDK_MOTION_NOTIFY:
323 Gtk::TreeModel::Path path;
324 Gtk::TreeViewColumn *column;
326 if(!tree_view.get_path_at_pos(
327 (int)event->button.x,(int)event->button.y, // x, y
328 path, // TreeModel::Path&
329 column, //TreeViewColumn*&
330 cell_x,cell_y //int&cell_x,int&cell_y
334 if(!tree_view.get_model()->get_iter(path))
337 Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
339 if(cellrenderer_time_track==column->get_first_cell_renderer())
341 // Movement on TimeLine
345 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
347 tooltips_.unset_tip(*this);
348 Glib::ustring tooltips_string(row[model.tooltip]);
349 last_tooltip_path=path;
350 if(!tooltips_string.empty())
352 tooltips_.set_tip(*this,tooltips_string);
353 tooltips_.force_window();
358 case GDK_BUTTON_RELEASE:
367 ChildrenTree::on_raise_pressed()
372 ChildrenTree::on_lower_pressed()
377 ChildrenTree::on_duplicate_pressed()
382 ChildrenTree::on_delete_pressed()