Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_03 / synfig-studio / src / gtkmm / layertreestore.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layertreestore.h
3 **      \brief Template Header
4 **
5 **      $Id: layertreestore.h,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_STUDIO_LAYERTREESTORE_H
26 #define __SYNFIG_STUDIO_LAYERTREESTORE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <gtkmm/treestore.h>
31 #include <synfigapp/canvasinterface.h>
32 #include <synfig/value.h>
33 #include <synfig/valuenode.h>
34 #include <gtkmm/treeview.h>
35
36 /* === M A C R O S ========================================================= */
37
38 /* === T Y P E D E F S ===================================================== */
39
40 /* === C L A S S E S & S T R U C T S ======================================= */
41
42 namespace studio {
43
44 class LayerTreeStore : virtual public Gtk::TreeStore
45 {
46         /*
47  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
48         */
49
50 public:
51
52         class Model : public Gtk::TreeModel::ColumnRecord
53         {
54         public:
55                 Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
56                 Gtk::TreeModelColumn<Glib::ustring> label;
57                 Gtk::TreeModelColumn<Glib::ustring> name;
58                 Gtk::TreeModelColumn<Glib::ustring> id;
59
60                 Gtk::TreeModelColumn<synfig::Canvas::Handle> canvas;
61
62                 Gtk::TreeModelColumn<Glib::ustring> tooltip;
63
64
65                 Gtk::TreeModelColumn<bool>                                              active;
66                 Gtk::TreeModelColumn<synfig::Layer::Handle>             layer;
67                 Gtk::TreeModelColumn<synfig::Canvas::Handle>                    contained_canvas;
68
69                 Gtk::TreeModelColumn<bool>                                              children_lock;
70
71                 Gtk::TreeModelColumn<float> z_depth;
72                 Gtk::TreeModelColumn<int> index;
73
74                 Model()
75                 {
76                         add(icon);
77                         add(label);
78                         add(name);
79                         add(id);
80                         add(canvas);
81                         add(tooltip);
82                         add(active);
83                         add(layer);
84                         add(contained_canvas);
85                         add(z_depth);
86                         add(index);
87                         add(children_lock);
88                 }
89         };
90
91         /*
92  -- ** -- P U B L I C  D A T A ------------------------------------------------
93         */
94
95 public:
96         
97         //! TreeModel for the layers
98         const Model model;
99
100         /*
101  -- ** -- P R I V A T E   D A T A ---------------------------------------------
102         */
103
104 private:
105
106         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
107
108         Glib::RefPtr<Gdk::Pixbuf> layer_icon;
109
110         /*
111  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
112         */
113
114 private:
115
116         /*
117  -- ** -- P R O T E C T E D   M E T H O D S -----------------------------------
118         */
119
120 private:
121
122         virtual void set_value_impl (const Gtk::TreeModel::iterator& row, int column, const Glib::ValueBase& value);
123         virtual void  get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const;
124
125         virtual bool  row_draggable_vfunc (const TreeModel::Path& path)const;
126         virtual bool  drag_data_get_vfunc (const TreeModel::Path& path, Gtk::SelectionData& selection_data)const;
127         virtual bool  drag_data_delete_vfunc (const TreeModel::Path& path);
128         virtual bool  drag_data_received_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data);
129         virtual bool  row_drop_possible_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)const;
130
131         /*
132  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
133         */
134
135 private:
136
137         bool on_layer_tree_event(GdkEvent *event);
138
139         void on_layer_new_description(synfig::Layer::Handle handle,synfig::String desc);
140
141         void on_layer_added(synfig::Layer::Handle handle);
142
143         void on_layer_removed(synfig::Layer::Handle handle);
144
145         void on_layer_inserted(synfig::Layer::Handle handle,int depth);
146
147         void on_layer_moved(synfig::Layer::Handle handle,int depth, synfig::Canvas::Handle canvas);
148
149         void on_layer_status_changed(synfig::Layer::Handle handle,bool);
150
151         void on_layer_lowered(synfig::Layer::Handle handle);
152
153         void on_layer_raised(synfig::Layer::Handle handle);
154
155         void on_layer_param_changed(synfig::Layer::Handle handle,synfig::String param_name);
156
157         //void on_value_node_added(synfig::ValueNode::Handle value_node);
158
159         //void on_value_node_deleted(synfig::ValueNode::Handle value_node);
160
161         //void on_value_node_changed(synfig::ValueNode::Handle value_node);
162
163         //void on_value_node_replaced(synfig::ValueNode::Handle replaced_value_node,synfig::ValueNode::Handle new_value_node);
164
165         bool find_layer_row_(const synfig::Layer::Handle &handle, synfig::Canvas::Handle canvas, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter, Gtk::TreeModel::Children::iterator &prev);
166
167         bool find_canvas_row_(synfig::Canvas::Handle canvas, synfig::Canvas::Handle parent, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter);
168
169         /*
170  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
171         */
172
173 public:
174         
175         LayerTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
176         ~LayerTreeStore();
177
178         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
179         etl::loose_handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
180         etl::loose_handle<synfigapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
181
182         bool find_canvas_row(synfig::Canvas::Handle canvas, Gtk::TreeModel::Children::iterator &iter);
183
184         bool find_layer_row(const synfig::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
185
186         bool find_prev_layer_row(const synfig::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
187
188         void rebuild();
189
190         void refresh();
191
192         void refresh_row(Gtk::TreeModel::Row &row);
193
194         void set_row_layer(Gtk::TreeRow &row,synfig::Layer::Handle &handle);
195
196         static int z_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs);
197         static int index_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs);
198
199         //void set_row_param(Gtk::TreeRow &row,synfig::Layer::Handle &handle,const std::string& name, const std::string& local_name, const synfig::ValueBase &value, etl::handle<synfig::ValueNode> value_node,synfig::ParamDesc *param_desc);
200
201         //virtual void set_row(Gtk::TreeRow row,synfigapp::ValueDesc value_desc);
202         static bool search_func(const Glib::RefPtr<TreeModel>&,int,const Glib::ustring&,const TreeModel::iterator&);
203
204         /*
205  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
206         */
207
208 public:
209         
210         static Glib::RefPtr<LayerTreeStore> create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
211
212
213 }; // END of class LayerTreeStore
214
215 }; // END of namespace studio
216
217 /* === E N D =============================================================== */
218
219 #endif