initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / layergrouptreestore.h
1 /* === S I N F G =========================================================== */
2 /*!     \file layertreestore.h
3 **      \brief Template Header
4 **
5 **      $Id: layergrouptreestore.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_LAYERGROUPTREESTORE_H
25 #define __SINFG_STUDIO_LAYERGROUPTREESTORE_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 LayerGroupTreeStore :  public Gtk::TreeStore
44 {
45         /*
46  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
47         */
48
49 public:
50         typedef std::list<sinfg::Layer::Handle> LayerList;
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> tooltip;
58                 
59                 Gtk::TreeModelColumn<Glib::ustring> group_name;
60                 Gtk::TreeModelColumn<Glib::ustring> parent_group_name;
61
62                 Gtk::TreeModelColumn<sinfg::Canvas::Handle> canvas;
63
64                 Gtk::TreeModelColumn<bool>                                              active;
65                 Gtk::TreeModelColumn<bool>                                              is_layer;
66                 Gtk::TreeModelColumn<bool>                                              is_group;
67                 Gtk::TreeModelColumn<sinfg::Layer::Handle>              layer;
68                 
69                 Gtk::TreeModelColumn<LayerList>         all_layers;
70                 Gtk::TreeModelColumn<LayerList>         child_layers;
71                 
72                 Model()
73                 {
74                         add(icon);
75                         add(label);
76                         add(group_name);
77                         add(parent_group_name);
78                         add(canvas);
79                         add(tooltip);
80                         add(active);
81                         add(layer);
82                         add(is_layer);
83                         add(is_group);
84                         add(all_layers);
85                         add(child_layers);
86                 }
87         };
88
89         /*
90  -- ** -- P U B L I C  D A T A ------------------------------------------------
91         */
92
93 public:
94         
95         //! TreeModel for the layers
96         const Model model;
97         
98         bool rebuilding;
99
100         /*
101  -- ** -- P R I V A T E   D A T A ---------------------------------------------
102         */
103
104 private:
105
106         etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface_;
107
108         Glib::RefPtr<Gdk::Pixbuf> layer_icon;
109         Glib::RefPtr<Gdk::Pixbuf> group_icon;
110
111         /*
112  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
113         */
114
115 private:
116
117         /*
118  -- ** -- P R O T E C T E D   M E T H O D S -----------------------------------
119         */
120
121 private:
122
123         virtual void set_value_impl (const Gtk::TreeModel::iterator& row, int column, const Glib::ValueBase& value);
124         virtual void  get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const;
125
126         virtual bool  row_draggable_vfunc (const TreeModel::Path& path)const;
127         virtual bool  drag_data_get_vfunc (const TreeModel::Path& path, Gtk::SelectionData& selection_data)const;
128         virtual bool  drag_data_delete_vfunc (const TreeModel::Path& path);
129         virtual bool  drag_data_received_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data);
130         virtual bool  row_drop_possible_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)const;
131
132
133         void on_group_pair_added(sinfg::String group, etl::handle<sinfg::Layer> layer);
134         void on_group_pair_removed(sinfg::String group, etl::handle<sinfg::Layer> layer);
135
136         void on_activity();
137
138         /*
139  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
140         */
141
142 private:
143
144         bool on_layer_tree_event(GdkEvent *event);
145
146         void on_layer_new_description(sinfg::Layer::Handle handle,sinfg::String desc);
147
148         void on_layer_status_changed(sinfg::Layer::Handle handle,bool);
149
150         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);
151
152         bool find_group_row_(const sinfg::String &group, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter, Gtk::TreeModel::Children::iterator &prev);
153
154         bool on_group_removed(sinfg::String group);
155         bool on_group_changed(sinfg::String group);
156
157         /*
158  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
159         */
160
161 public:
162         
163         LayerGroupTreeStore(etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface_);
164         ~LayerGroupTreeStore();
165
166         Gtk::TreeRow on_group_added(sinfg::String group);
167         etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
168         etl::loose_handle<const sinfgapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
169         etl::loose_handle<sinfgapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
170
171         bool find_layer_row(const sinfg::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
172
173         bool find_group_row(const sinfg::String &group, Gtk::TreeModel::Children::iterator &iter);
174
175         bool find_prev_layer_row(const sinfg::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
176
177         void rebuild();
178
179         void refresh();
180
181         void refresh_row(Gtk::TreeModel::Row &row);
182
183         void set_row_layer(Gtk::TreeRow &row,sinfg::Layer::Handle &handle);
184
185         static bool search_func(const Glib::RefPtr<TreeModel>&,int,const Glib::ustring&,const TreeModel::iterator&);
186
187         /*
188  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
189         */
190
191 public:
192         
193         static Glib::RefPtr<LayerGroupTreeStore> create(etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface_);
194
195 }; // END of class LayerGroupTreeStore
196
197 }; // END of namespace studio
198
199 /* === E N D =============================================================== */
200
201 #endif