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
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 <synfig/layer.h>
33 #include "layergrouptree.h"
34 #include <gtkmm/treemodelsort.h>
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 LayerGroupTree::LayerGroupTree()
58 const LayerGroupTreeStore::Model model;
61 { // --- O N / O F F ----------------------------------------------------
63 index=append_column_editable(_(" "),model.active);
64 //Gtk::TreeView::Column* column = get_column(index-1);
66 { // --- I C O N --------------------------------------------------------
68 index=append_column(_(" "),model.icon);
69 Gtk::TreeView::Column* column = get_column(index-1);
70 set_expander_column(*column);
72 { // --- N A M E --------------------------------------------------------
74 index=append_column_editable(_("Name"),model.label);
75 label_column = get_column(index-1);
77 //column->set_sort_column_id(layer_model.index);
79 //set_expander_column(*column);
80 //column->set_reorderable();
81 //column->set_resizable();
82 //column->set_clickable(false);
84 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
85 //column->pack_start(*icon_cellrenderer,false);
86 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
89 set_enable_search(true);
90 set_search_column(model.label);
91 set_search_equal_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::search_func));
93 // This makes things easier to read.
96 // Make us more sensitive to several events
97 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
99 set_reorderable(true);
101 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
103 //set_flags(get_flags()|Gtk::RECEIVES_DEFAULT|Gtk::HAS_GRAB);
105 //std::list<Gtk::TargetEntry> listTargets;
106 //listTargets.push_back( Gtk::TargetEntry("LAYER") );
107 //listTargets.push_back( Gtk::TargetEntry("GROUP") );
108 //drag_dest_set(listTargets);
111 LayerGroupTree::~LayerGroupTree()
113 synfig::info("LayerGroupTree::~LayerGroupTree(): deleted");
117 LayerGroupTree::set_model(Glib::RefPtr<LayerGroupTreeStore> layer_group_tree_store)
119 layer_group_tree_store_=layer_group_tree_store;
120 LayerGroupTreeStore::Model model;
124 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(layer_group_tree_store_));
125 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
126 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
127 sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
128 Gtk::TreeView::set_model(sorted_store);
131 Gtk::TreeView::set_model(layer_group_tree_store);
136 LayerGroupTree::set_editable(bool x)
142 cell_renderer_time->property_editable()=true;
143 cell_renderer_time_delta->property_editable()=true;
144 cell_renderer_description->property_editable()=true;
148 cell_renderer_time->property_editable()=false;
149 cell_renderer_time_delta->property_editable()=false;
150 cell_renderer_description->property_editable()=false;
156 LayerGroupTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
158 Gtk::TreePath path(path_string);
160 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
162 synfig::Keyframe keyframe(row[model.keyframe]);
163 if(time!=keyframe.get_time())
165 row[model.time]=time;
166 //keyframe.set_time(time);
167 //signal_edited_time()(keyframe,time);
168 //signal_edited()(keyframe);
173 LayerGroupTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
175 Gtk::TreePath path(path_string);
177 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
179 if(row)row[model.time_delta]=time;
183 LayerGroupTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
185 Gtk::TreePath path(path_string);
187 const Gtk::TreeRow row = *(get_model()->get_iter(path));
189 const synfig::String description(desc);
190 synfig::Keyframe keyframe(row[model.keyframe]);
191 if(description!=keyframe.get_description())
193 row[model.description]=desc;
194 keyframe.set_description(description);
195 signal_edited_description()(keyframe,description);
196 signal_edited()(keyframe);
202 LayerGroupTree::on_event(GdkEvent *event)
206 case GDK_BUTTON_PRESS:
208 Gtk::TreeModel::Path path;
209 Gtk::TreeViewColumn *column;
211 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
212 //tree_to_widget_coords (,, wx, wy);
215 path, // TreeModel::Path&
216 column, //TreeViewColumn*&
217 cell_x,cell_y //int&cell_x,int&cell_y
220 const Gtk::TreeRow row = *(get_model()->get_iter(path));
222 if(row[model.is_layer] && event->button.button==3)
224 signal_popup_layer_menu()((Layer::Handle)row[model.layer]);
228 /*signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
229 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
231 layer_group_tree_store_->canvas_interface()->set_time(row[model.time]);
235 case GDK_2BUTTON_PRESS:
237 Gtk::TreeModel::Path path;
238 Gtk::TreeViewColumn *column;
241 int(event->button.x),int(event->button.y), // x, y
242 path, // TreeModel::Path&
243 column, //TreeViewColumn*&
244 cell_x,cell_y //int&cell_x,int&cell_y
247 const Gtk::TreeRow row = *(get_model()->get_iter(path));
249 LayerList layer_list(row[model.all_layers]);
250 if(!layer_list.empty())
252 if(!(event->button.state&GDK_CONTROL_MASK))
254 layer_group_tree_store_->canvas_interface()->get_selection_manager()->clear_selected_layers();
256 layer_group_tree_store_->canvas_interface()->get_selection_manager()->set_selected_layers(layer_list);
261 case GDK_BUTTON_RELEASE:
266 return Gtk::TreeView::on_event(event);
270 static inline void __group_grabber(const Gtk::TreeModel::iterator& iter, std::list<synfig::String>* ret)
272 const LayerGroupTreeStore::Model model;
273 if((bool)(*iter)[model.is_group])
274 ret->push_back((Glib::ustring)(*iter)[model.group_name]);
277 std::list<synfig::String>
278 LayerGroupTree::get_selected_groups()const
280 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
283 return std::list<synfig::String>();
285 std::list<synfig::String> ret;
287 selection->selected_foreach_iter(
299 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerGroupTree::LayerList* ret)
301 const LayerGroupTreeStore::Model model;
302 if((bool)(*iter)[model.is_layer])
303 ret->push_back((Layer::Handle)(*iter)[model.layer]);
306 LayerGroupTree::LayerList
307 LayerGroupTree::get_selected_layers()const
309 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
316 selection->selected_foreach_iter(
329 LayerGroupTree::set_cursor(const Gtk::TreeModel::Path& path, bool start_editing)
331 Gtk::TreeView::set_cursor(path, *label_column, start_editing);