1 /* === S Y N F I G ========================================================= */
2 /*!	\file trees/layergrouptreestore.h
3 **	\brief Layer set tree model
4 **
5 **	\legal
6 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **	Copyright (c) 2017 caryoscelus
8 **
9 **	This package is free software; you can redistribute it and/or
10 **	modify it under the terms of the GNU General Public License as
11 **	published by the Free Software Foundation; either version 2 of
12 **	the License, or (at your option) any later version.
13 **
14 **	This package is distributed in the hope that it will be useful,
15 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
16 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 **	General Public License for more details.
18 **	\endlegal
19 */
20 /* ========================================================================= */
21 
22 /* === S T A R T =========================================================== */
23 
24 #ifndef __SYNFIG_STUDIO_LAYERGROUPTREESTORE_H
25 #define __SYNFIG_STUDIO_LAYERGROUPTREESTORE_H
26 
27 /* === H E A D E R S ======================================================= */
28 
29 #include <gtkmm/treestore.h>
30 #include <synfigapp/canvasinterface.h>
31 #include <synfig/value.h>
32 #include <synfig/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<synfig::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<synfig::Canvas::Handle> canvas;
63 
64 		Gtk::TreeModelColumn<bool>						active;
65 		Gtk::TreeModelColumn<bool>						is_layer;
66 		Gtk::TreeModelColumn<bool>						is_group;
67 		Gtk::TreeModelColumn<synfig::Layer::Handle>		layer;
68 
69 		Gtk::TreeModelColumn<LayerList>		all_layers;
70 		Gtk::TreeModelColumn<LayerList>		child_layers;
71 
72 		Gtk::TreeModelColumn<float> z_depth;
73 
Model()74 		Model()
75 		{
76 			add(icon);
77 			add(label);
78 			add(group_name);
79 			add(parent_group_name);
80 			add(canvas);
81 			add(tooltip);
82 			add(active);
83 			add(layer);
84 			add(is_layer);
85 			add(is_group);
86 			add(all_layers);
87 			add(child_layers);
88 			add(z_depth);
89 		}
90 	};
91 
92 	/*
93  -- ** -- P U B L I C  D A T A ------------------------------------------------
94 	*/
95 
96 public:
97 
98 	//! TreeModel for the layers
99 	const Model model;
100 
101 	bool rebuilding;
102 
103 	/*
104  -- ** -- P R I V A T E   D A T A ---------------------------------------------
105 	*/
106 
107 private:
108 
109 	etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
110 
111 	Glib::RefPtr<Gdk::Pixbuf> layer_icon;
112 	Glib::RefPtr<Gdk::Pixbuf> group_icon;
113 
114 	/*
115  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
116 	*/
117 
118 private:
119 
120 	/*
121  -- ** -- P R O T E C T E D   M E T H O D S -----------------------------------
122 	*/
123 
124 private:
125 
126 	virtual void set_value_impl (const Gtk::TreeModel::iterator& row, int column, const Glib::ValueBase& value);
127 	virtual void  get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const;
128 
129 	virtual bool  row_draggable_vfunc (const TreeModel::Path& path)const;
130 	virtual bool  drag_data_get_vfunc (const TreeModel::Path& path, Gtk::SelectionData& selection_data)const;
131 	virtual bool  drag_data_delete_vfunc (const TreeModel::Path& path);
132 	virtual bool  drag_data_received_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data);
133 	virtual bool  row_drop_possible_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)const;
134 
135 
136 	void on_group_pair_added(synfig::String group, etl::handle<synfig::Layer> layer);
137 	void on_group_pair_removed(synfig::String group, etl::handle<synfig::Layer> layer);
138 
139 	void on_activity();
140 
141 	/*
142  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
143 	*/
144 
145 private:
146 
147 	bool on_layer_tree_event(GdkEvent *event);
148 
149 	void on_layer_new_description(synfig::Layer::Handle handle,synfig::String desc);
150 
151 	void on_layer_status_changed(synfig::Layer::Handle handle,bool);
152 
153 	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);
154 
155 	bool find_group_row_(const synfig::String &group, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter, Gtk::TreeModel::Children::iterator &prev);
156 
157 	bool on_group_removed(synfig::String group);
158 	bool on_group_changed(synfig::String group);
159 
160 	/*
161  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
162 	*/
163 
164 public:
165 
166 	LayerGroupTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
167 	~LayerGroupTreeStore();
168 
169 	Gtk::TreeRow on_group_added(synfig::String group);
canvas_interface()170 	etl::loose_handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
canvas_interface()171 	etl::loose_handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
get_canvas_interface()172 	etl::loose_handle<synfigapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
173 
174 	bool find_layer_row(const synfig::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
175 
176 	bool find_group_row(const synfig::String &group, Gtk::TreeModel::Children::iterator &iter);
177 
178 	bool find_prev_layer_row(const synfig::Layer::Handle &handle, Gtk::TreeModel::Children::iterator &iter);
179 
180 	void rebuild();
181 
182 	void refresh();
183 
184 	/// Re-apply current sorting
185 	void resort();
186 
187 	void refresh_row(Gtk::TreeModel::Row &row);
188 
189 	void set_row_layer(Gtk::TreeRow &row,synfig::Layer::Handle &handle);
190 
191 	static bool search_func(const Glib::RefPtr<TreeModel>&,int,const Glib::ustring&,const TreeModel::iterator&);
192 
193 	/*
194  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
195 	*/
196 
197 public:
198 
199 	static Glib::RefPtr<LayerGroupTreeStore> create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_);
200 
201 }; // END of class LayerGroupTreeStore
202 
203 }; // END of namespace studio
204 
205 /* === E N D =============================================================== */
206 
207 #endif
208