Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc3 / src / gtkmm / instance.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file gtkmm/instance.h
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_STUDIO_INSTANCE_H
27 #define __SYNFIG_STUDIO_INSTANCE_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include <ETL/handle>
32 #include <gtkmm/treeview.h>
33 #include <gtkmm/treestore.h>
34 #include <synfigapp/instance.h>
35 #include <sigc++/object.h>
36 #include <synfigapp/value_desc.h>
37 #include "historytreestore.h"
38 #include <synfig/canvas.h>
39
40 /* === M A C R O S ========================================================= */
41 #define DEFAULT_FILENAME_PREFIX _("Synfig Animation ") // will be followed by a different number for each document
42
43 /* === T Y P E D E F S ===================================================== */
44
45 /* === C L A S S E S & S T R U C T S ======================================= */
46
47 namespace Gtk { class Menu; class ActionGroup; };
48
49 namespace studio {
50
51 class CanvasView;
52
53
54 class Instance : public synfigapp::Instance
55 {
56 public:
57         typedef std::list< etl::handle<CanvasView> > CanvasViewList;
58
59         enum Status
60         {
61                 STATUS_OK,
62                 STATUS_ERROR,
63                 STATUS_CANCEL
64         };
65
66         class CanvasTreeModel : public Gtk::TreeModel::ColumnRecord
67         {
68         public:
69                 Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
70                 Gtk::TreeModelColumn<Glib::ustring> label;
71                 Gtk::TreeModelColumn<Glib::ustring> name;
72                 Gtk::TreeModelColumn<Glib::ustring> id;
73
74                 Gtk::TreeModelColumn<synfig::Canvas::Handle> canvas;
75                 Gtk::TreeModelColumn<bool> is_canvas;
76
77                 Gtk::TreeModelColumn<synfig::ValueNode::Handle> value_node;
78                 Gtk::TreeModelColumn<bool> is_value_node;
79                 Gtk::TreeModelColumn<synfig::ValueBase> value;
80                 Gtk::TreeModelColumn<Glib::ustring> type;
81                 Gtk::TreeModelColumn<int> link_id;
82                 Gtk::TreeModelColumn<int> link_count;
83
84                 Gtk::TreeModelColumn<bool> is_editable;
85
86                 Gtk::TreeModelColumn<synfigapp::ValueDesc> value_desc;
87
88                 CanvasTreeModel()
89                 {
90                         add(value);
91                         add(name);
92                         add(label);
93                         add(icon);
94                         add(type);
95                         add(id);
96                         add(canvas);
97                         add(value_node);
98                         add(is_canvas);
99                         add(is_value_node);
100
101                         add(is_editable);
102                         add(value_desc);
103                         add(link_count);
104                         add(link_id);
105                 }
106         } canvas_tree_model;
107
108 private:
109
110         sigc::signal<void,CanvasView*> signal_canvas_view_created_;
111         sigc::signal<void,CanvasView*> signal_canvas_view_deleted_;
112
113         sigc::signal<void> signal_undo_redo_status_changed_;
114
115         //! Tree containing the canvases -- used for the "canvas browser"
116         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store_;
117
118         //! Tree containing the actions -- used for the "canvas browser"
119         Glib::RefPtr<HistoryTreeStore> history_tree_store_;
120
121         //! Instance number
122         int     id_;
123
124         //! Used to calculate instance ID
125         static int instance_count_;
126
127         //! List of canvas view windows
128         CanvasViewList canvas_view_list_;
129
130         bool undo_status_;
131         bool redo_status_;
132
133         void set_undo_status(bool x);
134         void set_redo_status(bool x);
135
136         static void _revert(Instance *);
137
138 protected:
139
140         Instance(synfig::Canvas::Handle);
141
142 public:
143
144         sigc::signal<void>& signal_undo_redo_status_changed() { return signal_undo_redo_status_changed_; }
145
146         ~Instance();
147
148         sigc::signal<void,CanvasView*>& signal_canvas_view_created() { return signal_canvas_view_created_; }
149         sigc::signal<void,CanvasView*>& signal_canvas_view_deleted() { return signal_canvas_view_deleted_; }
150
151         bool get_undo_status()const { return undo_status_; }
152
153         bool get_redo_status()const { return redo_status_; }
154
155         int get_visible_canvases()const;
156
157         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store() { return canvas_tree_store_; }
158
159         Glib::RefPtr<const Gtk::TreeStore> canvas_tree_store()const { return canvas_tree_store_; }
160
161         Glib::RefPtr<HistoryTreeStore> history_tree_store() { return history_tree_store_; }
162
163         Glib::RefPtr<const HistoryTreeStore> history_tree_store()const { return history_tree_store_; }
164
165         //! Returns the number of instances that are currently open in the program
166         static int get_count() { return instance_count_; }
167
168         //etl::handle<synfig::Canvas> get_canvas()const { return synfigapp::Instance::get_canvas(); }
169
170         etl::handle<CanvasView> find_canvas_view(etl::handle<synfig::Canvas> canvas);
171
172         //! Sets the focus to a specific canvas
173         void focus(etl::handle<synfig::Canvas> canvas);
174
175         CanvasViewList & canvas_view_list() { return canvas_view_list_; }
176
177         const CanvasViewList & canvas_view_list()const { return canvas_view_list_; }
178
179         bool save_as(const synfig::String &filename);
180
181         //! Opens a "Save As" dialog, and then saves the composition to that file
182         //! returns true if the save was successful
183         bool dialog_save_as();
184
185         Status save();
186
187         void dialog_cvs_commit();
188
189         void dialog_cvs_add();
190
191         void dialog_cvs_update();
192
193         void dialog_cvs_revert();
194
195         //! Closes the instance of this composition
196         void close();
197
198         void revert();
199
200         void update_all_titles();
201
202         void refresh_canvas_tree();
203
204         bool safe_revert();
205         bool safe_close();
206
207         void add_actions_to_menu(Gtk::Menu *menu,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
208         void add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList &param_list1,const synfigapp::Action::ParamList &param_list2, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
209
210         void add_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, synfig::String& ui_info,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
211
212         void process_action(synfig::String name, synfigapp::Action::ParamList param_list);
213
214         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location=0.5f);
215
216         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas,const std::list<synfigapp::ValueDesc>& value_desc_list);
217
218
219         static void edit_waypoint(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
220
221 private:
222         void insert_canvas(Gtk::TreeRow row,synfig::Canvas::Handle canvas);
223
224 public:
225         static etl::handle<Instance> create(synfig::Canvas::Handle canvas);
226 }; // END class Instance
227
228 }; // END namespace studio
229
230 /* === E N D =============================================================== */
231
232 #endif