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(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 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
114 synfig::info("LayerGroupTree::~LayerGroupTree(): Deleted");
118 LayerGroupTree::set_model(Glib::RefPtr<LayerGroupTreeStore> layer_group_tree_store)
120 layer_group_tree_store_=layer_group_tree_store;
121 LayerGroupTreeStore::Model model;
125 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(layer_group_tree_store_));
126 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
127 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
128 sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
129 Gtk::TreeView::set_model(sorted_store);
132 Gtk::TreeView::set_model(layer_group_tree_store);
137 LayerGroupTree::set_editable(bool x)
143 cell_renderer_time->property_editable()=true;
144 cell_renderer_time_delta->property_editable()=true;
145 cell_renderer_description->property_editable()=true;
149 cell_renderer_time->property_editable()=false;
150 cell_renderer_time_delta->property_editable()=false;
151 cell_renderer_description->property_editable()=false;
157 LayerGroupTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
159 Gtk::TreePath path(path_string);
161 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
163 synfig::Keyframe keyframe(row[model.keyframe]);
164 if(time!=keyframe.get_time())
166 row[model.time]=time;
167 //keyframe.set_time(time);
168 //signal_edited_time()(keyframe,time);
169 //signal_edited()(keyframe);
174 LayerGroupTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
176 Gtk::TreePath path(path_string);
178 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
180 if(row)row[model.time_delta]=time;
184 LayerGroupTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
186 Gtk::TreePath path(path_string);
188 const Gtk::TreeRow row = *(get_model()->get_iter(path));
190 const synfig::String description(desc);
191 synfig::Keyframe keyframe(row[model.keyframe]);
192 if(description!=keyframe.get_description())
194 row[model.description]=desc;
195 keyframe.set_description(description);
196 signal_edited_description()(keyframe,description);
197 signal_edited()(keyframe);
203 LayerGroupTree::on_event(GdkEvent *event)
207 case GDK_BUTTON_PRESS:
209 Gtk::TreeModel::Path path;
210 Gtk::TreeViewColumn *column;
212 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
213 //tree_to_widget_coords (,, wx, wy);
216 path, // TreeModel::Path&
217 column, //TreeViewColumn*&
218 cell_x,cell_y //int&cell_x,int&cell_y
221 const Gtk::TreeRow row = *(get_model()->get_iter(path));
223 if(row[model.is_layer] && event->button.button==3)
225 signal_popup_layer_menu()((Layer::Handle)row[model.layer]);
229 /*signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
230 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
232 layer_group_tree_store_->canvas_interface()->set_time(row[model.time]);
236 case GDK_2BUTTON_PRESS:
238 Gtk::TreeModel::Path path;
239 Gtk::TreeViewColumn *column;
242 int(event->button.x),int(event->button.y), // x, y
243 path, // TreeModel::Path&
244 column, //TreeViewColumn*&
245 cell_x,cell_y //int&cell_x,int&cell_y
248 const Gtk::TreeRow row = *(get_model()->get_iter(path));
250 LayerList layer_list(row[model.all_layers]);
251 if(!layer_list.empty())
253 if(!(event->button.state&GDK_CONTROL_MASK))
255 layer_group_tree_store_->canvas_interface()->get_selection_manager()->clear_selected_layers();
257 layer_group_tree_store_->canvas_interface()->get_selection_manager()->set_selected_layers(layer_list);
262 case GDK_BUTTON_RELEASE:
267 return Gtk::TreeView::on_event(event);
271 static inline void __group_grabber(const Gtk::TreeModel::iterator& iter, std::list<synfig::String>* ret)
273 const LayerGroupTreeStore::Model model;
274 if((bool)(*iter)[model.is_group])
275 ret->push_back((Glib::ustring)(*iter)[model.group_name]);
278 std::list<synfig::String>
279 LayerGroupTree::get_selected_groups()const
281 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
284 return std::list<synfig::String>();
286 std::list<synfig::String> ret;
288 selection->selected_foreach_iter(
300 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerGroupTree::LayerList* ret)
302 const LayerGroupTreeStore::Model model;
303 if((bool)(*iter)[model.is_layer])
304 ret->push_back((Layer::Handle)(*iter)[model.layer]);
307 LayerGroupTree::LayerList
308 LayerGroupTree::get_selected_layers()const
310 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
317 selection->selected_foreach_iter(
330 LayerGroupTree::set_cursor(const Gtk::TreeModel::Path& path, bool start_editing)
332 Gtk::TreeView::set_cursor(path, *label_column, start_editing);