2101820515b7b522ac681048c0dfba332cdbf38d
[synfig.git] / synfig-studio / trunk / src / gtkmm / keyframetreestore.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file keyframetreestore.h
3 **      \brief Template Header
4 **
5 **      $Id$
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_KEYFRAMETREESTORE_H
26 #define __SYNFIG_STUDIO_KEYFRAMETREESTORE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <gtkmm/liststore.h>
31 #include <synfigapp/canvasinterface.h>
32 #include <gdkmm/pixbuf.h>
33 #include <synfig/keyframe.h>
34 #include <map>
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 //class TreeRowReferenceHack;
43 //#define TreeRowReferenceHack Gtk::TreeRowReference
44
45 namespace studio {
46
47 class KeyframeTreeStore_Class;
48
49 class KeyframeTreeStore :
50         public Glib::Object,
51         public Gtk::TreeModel,
52         public Gtk::TreeDragSource,
53         public Gtk::TreeDragDest
54 {
55         /*
56  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
57         */
58
59 public:
60
61         class Model : public Gtk::TreeModel::ColumnRecord
62         {
63         public:
64                 Gtk::TreeModelColumn<synfig::Time> time;
65                 Gtk::TreeModelColumn<Glib::ustring> description;
66                 Gtk::TreeModelColumn<synfig::Keyframe> keyframe;
67                 Gtk::TreeModelColumn<synfig::Time> time_delta;
68
69                 Model()
70                 {
71                         add(time);
72                         add(description);
73                         add(keyframe);
74                         add(time_delta);
75                 }
76         };
77
78         /*
79  -- ** -- P U B L I C  D A T A ------------------------------------------------
80         */
81
82 public:
83
84         const Model model;
85
86         /*
87  -- ** -- P R I V A T E   D A T A ---------------------------------------------
88         */
89
90 private:
91
92         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
93
94         //! Unique stamp for this TreeModel.
95         int stamp_;
96
97         static KeyframeTreeStore_Class keyframe_tree_store_class_;
98
99         //std::map<synfig::Keyframe,TreeRowReferenceHack> path_table_;
100
101         synfig::KeyframeList old_keyframe_list;
102
103         /*
104  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
105         */
106
107 private:
108
109         void add_keyframe(synfig::Keyframe);
110
111         void remove_keyframe(synfig::Keyframe);
112
113         void change_keyframe(synfig::Keyframe);
114
115         static int sorter(const Gtk::TreeModel::iterator &,const Gtk::TreeModel::iterator &);
116
117         bool iterator_sane(const GtkTreeIter* iter)const;
118
119         bool iterator_sane(const Gtk::TreeModel::iterator& iter)const;
120
121         void dump_iterator(const GtkTreeIter* iter, const Glib::ustring &name)const;
122
123         void dump_iterator(const Gtk::TreeModel::iterator& iter, const Glib::ustring &name)const;
124
125         //! Resets the iterator stamp for this model.
126         /*!     This should be called whenever the class is
127         **      constructed     or when large numbers of
128         **      iterators become invalid. */
129         void reset_stamp();
130
131         //void reset_path_table();
132
133         /*
134  -- ** -- V I R T U A L   F U N C T I O N S -----------------------------------
135         */
136
137 protected:
138
139         virtual void set_value_impl (const Gtk::TreeModel::iterator& row, int column, const Glib::ValueBase& value);
140         virtual Gtk::TreeModelFlags  get_flags_vfunc ();
141         virtual int  get_n_columns_vfunc ();
142         virtual GType  get_column_type_vfunc (int index);
143         virtual bool iter_next_vfunc (const iterator& iter, iterator& iter_next) const;
144         virtual bool  get_iter_vfunc (const Gtk::TreeModel::Path& path, iterator& iter_next)const;
145         virtual bool  iter_nth_root_child_vfunc (int n, iterator& iter)const;
146         virtual Gtk::TreeModel::Path  get_path_vfunc (const iterator& iter)const;
147         virtual void  ref_node_vfunc (iterator& iter)const;
148         virtual void  unref_node_vfunc (iterator& iter)const;
149         virtual void  get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const;
150         virtual bool    iter_is_valid (const iterator& iter) const;
151         virtual int     iter_n_root_children_vfunc () const;
152
153         //virtual bool  iter_nth_child_vfunc (GtkTreeIter* iter, const GtkTreeIter* parent, int n);
154         //virtual bool  iter_children_vfunc (GtkTreeIter* iter, const GtkTreeIter* parent);
155         //virtual bool  iter_has_child_vfunc (const GtkTreeIter* iter);
156         //virtual int  iter_n_children_vfunc (const GtkTreeIter* iter);
157         //virtual bool  iter_parent_vfunc (GtkTreeIter* iter, const GtkTreeIter* child);
158
159         /*
160         virtual bool  get_sort_column_id_vfunc (int* sort_column_id, Gtk::SortType* order);
161         virtual void  set_sort_column_id_vfunc (int sort_column_id, Gtk::SortType order);
162         virtual void  set_sort_func_vfunc (int sort_column_id, GtkTreeIterCompareFunc func, void* data, GtkDestroyNotify destroy);
163         virtual void  set_default_sort_func_vfunc (GtkTreeIterCompareFunc func, void* data, GtkDestroyNotify destroy);
164         virtual bool  has_default_sort_func_vfunc ();
165         */
166
167         /*
168  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
169         */
170
171 private:
172
173         /*
174  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
175         */
176
177 public:
178
179         KeyframeTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
180         ~KeyframeTreeStore();
181
182         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
183         etl::loose_handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
184
185         synfig::Canvas::Handle get_canvas() { return canvas_interface()->get_canvas(); }
186         synfig::Canvas::Handle get_canvas()const { return canvas_interface()->get_canvas(); }
187
188         Gtk::TreeModel::Row find_row(const synfig::Keyframe &keyframe);
189
190         /*
191  -- ** -- S T A T I C  M E T H O D S ------------------------------------------
192         */
193
194 public:
195
196         static Glib::RefPtr<KeyframeTreeStore> create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
197
198         static int time_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs);
199         static int description_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs);
200
201 }; // END of class KeyframeTreeStore
202
203 //! \internal
204 class KeyframeTreeStore_Class : public Glib::Class
205 {
206 public:
207         struct KeyframeTreeStoreClass
208         {
209                 GObjectClass parent_class;
210         };
211
212         friend class KeyframeTreeStore;
213
214         const Glib::Class& init();
215
216         static void class_init_function(gpointer g_blass, gpointer class_data);
217 }; // END of CustomTreeStore_Class
218
219 }; // END of namespace studio
220
221 /* === E N D =============================================================== */
222
223 #endif