1 /* === S Y N F I G ========================================================= */
2 /*! \file layergrouptree.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 <synfig/layer.h>
34 #include "trees/layergrouptree.h"
35 #include <gtkmm/treemodelsort.h>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace studio;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 LayerGroupTree::LayerGroupTree()
59 const LayerGroupTreeStore::Model model;
62 { // --- O N / O F F ----------------------------------------------------
64 index=append_column_editable(_(" "),model.active);
65 //Gtk::TreeView::Column* column = get_column(index-1);
67 { // --- I C O N --------------------------------------------------------
69 index=append_column(_(" "),model.icon);
70 Gtk::TreeView::Column* column = get_column(index-1);
71 set_expander_column(*column);
73 { // --- N A M E --------------------------------------------------------
75 index=append_column_editable(_("Name"),model.label);
76 label_column = get_column(index-1);
78 //column->set_sort_column(layer_model.index);
80 //set_expander_column(*column);
81 //column->set_reorderable();
82 //column->set_resizable();
83 //column->set_clickable(false);
85 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
86 //column->pack_start(*icon_cellrenderer,false);
87 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
90 set_enable_search(true);
91 set_search_column(model.label);
92 set_search_equal_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::search_func));
94 // This makes things easier to read.
97 // Make us more sensitive to several events
98 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
100 set_reorderable(true);
102 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
104 //set_flags(get_flags()|Gtk::RECEIVES_DEFAULT|Gtk::HAS_GRAB);
106 //std::list<Gtk::TargetEntry> listTargets;
107 //listTargets.push_back( Gtk::TargetEntry("LAYER") );
108 //listTargets.push_back( Gtk::TargetEntry("GROUP") );
109 //drag_dest_set(listTargets);
112 LayerGroupTree::~LayerGroupTree()
114 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
115 synfig::info("LayerGroupTree::~LayerGroupTree(): Deleted");
119 LayerGroupTree::set_model(Glib::RefPtr<LayerGroupTreeStore> layer_group_tree_store)
121 layer_group_tree_store_=layer_group_tree_store;
122 LayerGroupTreeStore::Model model;
126 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(layer_group_tree_store_));
127 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
128 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
129 sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
130 Gtk::TreeView::set_model(sorted_store);
133 Gtk::TreeView::set_model(layer_group_tree_store);
138 LayerGroupTree::set_editable(bool x)
144 cell_renderer_time->property_editable()=true;
145 cell_renderer_time_delta->property_editable()=true;
146 cell_renderer_description->property_editable()=true;
150 cell_renderer_time->property_editable()=false;
151 cell_renderer_time_delta->property_editable()=false;
152 cell_renderer_description->property_editable()=false;
158 LayerGroupTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
160 Gtk::TreePath path(path_string);
162 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
164 synfig::Keyframe keyframe(row[model.keyframe]);
165 if(time!=keyframe.get_time())
167 row[model.time]=time;
168 //keyframe.set_time(time);
169 //signal_edited_time()(keyframe,time);
170 //signal_edited()(keyframe);
175 LayerGroupTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
177 Gtk::TreePath path(path_string);
179 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
181 if(row)row[model.time_delta]=time;
185 LayerGroupTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
187 Gtk::TreePath path(path_string);
189 const Gtk::TreeRow row = *(get_model()->get_iter(path));
191 const synfig::String description(desc);
192 synfig::Keyframe keyframe(row[model.keyframe]);
193 if(description!=keyframe.get_description())
195 row[model.description]=desc;
196 keyframe.set_description(description);
197 signal_edited_description()(keyframe,description);
198 signal_edited()(keyframe);
204 LayerGroupTree::on_event(GdkEvent *event)
208 case GDK_BUTTON_PRESS:
210 Gtk::TreeModel::Path path;
211 Gtk::TreeViewColumn *column;
213 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
214 //tree_to_widget_coords (,, wx, wy);
217 path, // TreeModel::Path&
218 column, //TreeViewColumn*&
219 cell_x,cell_y //int&cell_x,int&cell_y
222 const Gtk::TreeRow row = *(get_model()->get_iter(path));
224 if(row[model.is_layer] && event->button.button==3)
226 signal_popup_layer_menu()((Layer::Handle)row[model.layer]);
230 /*signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
231 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
233 layer_group_tree_store_->canvas_interface()->set_time(row[model.time]);
237 case GDK_2BUTTON_PRESS:
239 Gtk::TreeModel::Path path;
240 Gtk::TreeViewColumn *column;
243 int(event->button.x),int(event->button.y), // x, y
244 path, // TreeModel::Path&
245 column, //TreeViewColumn*&
246 cell_x,cell_y //int&cell_x,int&cell_y
249 const Gtk::TreeRow row = *(get_model()->get_iter(path));
251 LayerList layer_list(row[model.all_layers]);
252 if(!layer_list.empty())
254 if(!(event->button.state&GDK_CONTROL_MASK))
256 layer_group_tree_store_->canvas_interface()->get_selection_manager()->clear_selected_layers();
258 layer_group_tree_store_->canvas_interface()->get_selection_manager()->set_selected_layers(layer_list);
263 case GDK_BUTTON_RELEASE:
268 return Gtk::TreeView::on_event(event);
272 static inline void __group_grabber(const Gtk::TreeModel::iterator& iter, std::list<synfig::String>* ret)
274 const LayerGroupTreeStore::Model model;
275 if((bool)(*iter)[model.is_group])
276 ret->push_back((Glib::ustring)(*iter)[model.group_name]);
279 std::list<synfig::String>
280 LayerGroupTree::get_selected_groups()const
282 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
285 return std::list<synfig::String>();
287 std::list<synfig::String> ret;
289 selection->selected_foreach_iter(
301 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerGroupTree::LayerList* ret)
303 const LayerGroupTreeStore::Model model;
304 if((bool)(*iter)[model.is_layer])
305 ret->push_back((Layer::Handle)(*iter)[model.layer]);
308 LayerGroupTree::LayerList
309 LayerGroupTree::get_selected_layers()const
311 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
318 selection->selected_foreach_iter(
331 LayerGroupTree::set_cursor(const Gtk::TreeModel::Path& path, bool start_editing)
333 Gtk::TreeView::set_cursor(path, *label_column, start_editing);