1 /* === S Y N F I G ========================================================= */
2 /*! \file layergrouptree.cpp
3 ** \brief Template File
5 ** $Id: layergrouptree.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 LayerGroupTree::LayerGroupTree()
56 const LayerGroupTreeStore::Model model;
59 { // --- O N / O F F ----------------------------------------------------
61 index=append_column_editable(_(" "),model.active);
62 //Gtk::TreeView::Column* column = get_column(index-1);
64 { // --- I C O N --------------------------------------------------------
66 index=append_column(_(" "),model.icon);
67 Gtk::TreeView::Column* column = get_column(index-1);
68 set_expander_column(*column);
70 { // --- N A M E --------------------------------------------------------
72 index=append_column_editable(_("Name"),model.label);
73 label_column = get_column(index-1);
75 //column->set_sort_column_id(layer_model.index);
77 //set_expander_column(*column);
78 //column->set_reorderable();
79 //column->set_resizable();
80 //column->set_clickable(false);
82 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
83 //column->pack_start(*icon_cellrenderer,false);
84 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
87 set_enable_search(true);
88 set_search_column(model.label);
89 set_search_equal_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::search_func));
91 // This makes things easier to read.
94 // Make us more sensitive to several events
95 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
97 set_reorderable(true);
99 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
101 //set_flags(get_flags()|Gtk::RECEIVES_DEFAULT|Gtk::HAS_GRAB);
103 //std::list<Gtk::TargetEntry> listTargets;
104 //listTargets.push_back( Gtk::TargetEntry("LAYER") );
105 //listTargets.push_back( Gtk::TargetEntry("GROUP") );
106 //drag_dest_set(listTargets);
109 LayerGroupTree::~LayerGroupTree()
111 synfig::info("LayerGroupTree::~LayerGroupTree(): deleted");
115 LayerGroupTree::set_model(Glib::RefPtr<LayerGroupTreeStore> layer_group_tree_store)
117 layer_group_tree_store_=layer_group_tree_store;
118 LayerGroupTreeStore::Model model;
122 Glib::RefPtr<Gtk::TreeModelSort> sorted_store(Gtk::TreeModelSort::create(layer_group_tree_store_));
123 sorted_store->set_default_sort_func(sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
124 sorted_store->set_sort_func(model.time.index(),sigc::ptr_fun(&studio::LayerGroupTreeStore::time_sorter));
125 sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
126 Gtk::TreeView::set_model(sorted_store);
129 Gtk::TreeView::set_model(layer_group_tree_store);
134 LayerGroupTree::set_editable(bool x)
140 cell_renderer_time->property_editable()=true;
141 cell_renderer_time_delta->property_editable()=true;
142 cell_renderer_description->property_editable()=true;
146 cell_renderer_time->property_editable()=false;
147 cell_renderer_time_delta->property_editable()=false;
148 cell_renderer_description->property_editable()=false;
154 LayerGroupTree::on_edited_time(const Glib::ustring&path_string,synfig::Time time)
156 Gtk::TreePath path(path_string);
158 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
160 synfig::Keyframe keyframe(row[model.keyframe]);
161 if(time!=keyframe.get_time())
163 row[model.time]=time;
164 //keyframe.set_time(time);
165 //signal_edited_time()(keyframe,time);
166 //signal_edited()(keyframe);
171 LayerGroupTree::on_edited_time_delta(const Glib::ustring&path_string,synfig::Time time)
173 Gtk::TreePath path(path_string);
175 const Gtk::TreeRow row(*(get_model()->get_iter(path)));
177 if(row)row[model.time_delta]=time;
181 LayerGroupTree::on_edited_description(const Glib::ustring&path_string,const Glib::ustring &desc)
183 Gtk::TreePath path(path_string);
185 const Gtk::TreeRow row = *(get_model()->get_iter(path));
187 const synfig::String description(desc);
188 synfig::Keyframe keyframe(row[model.keyframe]);
189 if(description!=keyframe.get_description())
191 row[model.description]=desc;
192 keyframe.set_description(description);
193 signal_edited_description()(keyframe,description);
194 signal_edited()(keyframe);
200 LayerGroupTree::on_event(GdkEvent *event)
204 case GDK_BUTTON_PRESS:
206 Gtk::TreeModel::Path path;
207 Gtk::TreeViewColumn *column;
209 int wx(round_to_int(event->button.x)),wy(round_to_int(event->button.y));
210 //tree_to_widget_coords (,, wx, wy);
213 path, // TreeModel::Path&
214 column, //TreeViewColumn*&
215 cell_x,cell_y //int&cell_x,int&cell_y
218 const Gtk::TreeRow row = *(get_model()->get_iter(path));
220 if(row[model.is_layer] && event->button.button==3)
222 signal_popup_layer_menu()((Layer::Handle)row[model.layer]);
226 /*signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
227 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
229 layer_group_tree_store_->canvas_interface()->set_time(row[model.time]);
233 case GDK_2BUTTON_PRESS:
235 Gtk::TreeModel::Path path;
236 Gtk::TreeViewColumn *column;
239 int(event->button.x),int(event->button.y), // x, y
240 path, // TreeModel::Path&
241 column, //TreeViewColumn*&
242 cell_x,cell_y //int&cell_x,int&cell_y
245 const Gtk::TreeRow row = *(get_model()->get_iter(path));
247 LayerList layer_list(row[model.all_layers]);
248 if(!layer_list.empty())
250 if(!(event->button.state&GDK_CONTROL_MASK))
252 layer_group_tree_store_->canvas_interface()->get_selection_manager()->clear_selected_layers();
254 layer_group_tree_store_->canvas_interface()->get_selection_manager()->set_selected_layers(layer_list);
259 case GDK_BUTTON_RELEASE:
264 return Gtk::TreeView::on_event(event);
268 static inline void __group_grabber(const Gtk::TreeModel::iterator& iter, std::list<synfig::String>* ret)
270 const LayerGroupTreeStore::Model model;
271 if((bool)(*iter)[model.is_group])
272 ret->push_back((Glib::ustring)(*iter)[model.group_name]);
275 std::list<synfig::String>
276 LayerGroupTree::get_selected_groups()const
278 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
281 return std::list<synfig::String>();
283 std::list<synfig::String> ret;
285 selection->selected_foreach_iter(
297 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerGroupTree::LayerList* ret)
299 const LayerGroupTreeStore::Model model;
300 if((bool)(*iter)[model.is_layer])
301 ret->push_back((Layer::Handle)(*iter)[model.layer]);
304 LayerGroupTree::LayerList
305 LayerGroupTree::get_selected_layers()const
307 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<LayerGroupTree&>(*this).get_selection();
314 selection->selected_foreach_iter(
327 LayerGroupTree::set_cursor(const Gtk::TreeModel::Path& path, bool start_editing)
329 Gtk::TreeView::set_cursor(path, *label_column, start_editing);