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