Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_03 / synfig-studio / src / gtkmm / instance.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file instance.h
3 **      \brief writeme
4 **
5 **      $Id: instance.h,v 1.2 2005/01/13 18:37:30 darco Exp $
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_INSTANCE_H
26 #define __SYNFIG_STUDIO_INSTANCE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <ETL/handle>
31 #include <gtkmm/treeview.h>
32 #include <gtkmm/treestore.h>
33 #include <synfigapp/instance.h>
34 #include <sigc++/object.h>
35 #include <synfigapp/value_desc.h>
36 #include "historytreestore.h"
37 #include <synfig/canvas.h>
38
39 /* === M A C R O S ========================================================= */
40
41 /* === T Y P E D E F S ===================================================== */
42
43 /* === C L A S S E S & S T R U C T S ======================================= */
44
45 namespace Gtk { class Menu; class ActionGroup; };
46
47 namespace studio {
48
49 class CanvasView;
50         
51
52 class Instance : public synfigapp::Instance
53 {
54 public:
55         typedef std::list< etl::handle<CanvasView> > CanvasViewList;
56
57         class CanvasTreeModel : public Gtk::TreeModel::ColumnRecord
58         {
59         public:
60                 Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
61                 Gtk::TreeModelColumn<Glib::ustring> label;
62                 Gtk::TreeModelColumn<Glib::ustring> name;
63                 Gtk::TreeModelColumn<Glib::ustring> id;
64
65                 Gtk::TreeModelColumn<synfig::Canvas::Handle> canvas;
66                 Gtk::TreeModelColumn<bool> is_canvas;
67
68                 Gtk::TreeModelColumn<synfig::ValueNode::Handle> value_node;
69                 Gtk::TreeModelColumn<bool> is_value_node;
70                 Gtk::TreeModelColumn<synfig::ValueBase> value;
71                 Gtk::TreeModelColumn<Glib::ustring> type;
72                 Gtk::TreeModelColumn<int> link_id;
73                 Gtk::TreeModelColumn<int> link_count;
74
75                 Gtk::TreeModelColumn<bool> is_editable;
76
77                 Gtk::TreeModelColumn<synfigapp::ValueDesc> value_desc;
78         
79                 CanvasTreeModel()
80                 {
81                         add(value);
82                         add(name);
83                         add(label);
84                         add(icon);
85                         add(type);
86                         add(id);
87                         add(canvas);
88                         add(value_node);
89                         add(is_canvas);
90                         add(is_value_node);
91
92                         add(is_editable);
93                         add(value_desc);
94                         add(link_count);
95                         add(link_id);
96                 }
97         } canvas_tree_model;
98         
99 private:
100
101         sigc::signal<void,CanvasView*> signal_canvas_view_created_;
102         sigc::signal<void,CanvasView*> signal_canvas_view_deleted_;
103         
104         sigc::signal<void> signal_undo_redo_status_changed_;
105
106         //! Tree containing the canvases -- used for the "canvas browser"
107         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store_;
108
109         //! Tree containing the actions -- used for the "canvas browser"
110         Glib::RefPtr<HistoryTreeStore> history_tree_store_;
111
112         //! Instance number
113         int     id_;
114
115         //! Used to calculate instance ID
116         static int instance_count_;
117
118         //! List of canvas view windows
119         CanvasViewList canvas_view_list_;
120         
121         bool undo_status_;
122         bool redo_status_;
123
124         void set_undo_status(bool x);
125         void set_redo_status(bool x);
126
127         static void _revert(Instance *);
128
129 protected:
130
131         Instance(synfig::Canvas::Handle);
132
133 public:
134
135         sigc::signal<void>& signal_undo_redo_status_changed() { return signal_undo_redo_status_changed_; }
136
137         ~Instance();
138
139         sigc::signal<void,CanvasView*>& signal_canvas_view_created() { return signal_canvas_view_created_; }
140         sigc::signal<void,CanvasView*>& signal_canvas_view_deleted() { return signal_canvas_view_deleted_; }
141
142         bool get_undo_status()const { return undo_status_; }
143
144         bool get_redo_status()const { return redo_status_; }
145
146         int get_visible_canvases()const;
147         
148         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store() { return canvas_tree_store_; }
149
150         Glib::RefPtr<const Gtk::TreeStore> canvas_tree_store()const { return canvas_tree_store_; }
151
152         Glib::RefPtr<HistoryTreeStore> history_tree_store() { return history_tree_store_; }
153
154         Glib::RefPtr<const HistoryTreeStore> history_tree_store()const { return history_tree_store_; }
155
156         //! Returns the number of instances that are currently open in the program
157         static int get_count() { return instance_count_; }
158
159         //etl::handle<synfig::Canvas> get_canvas()const { return synfigapp::Instance::get_canvas(); }
160         
161         etl::handle<CanvasView> find_canvas_view(etl::handle<synfig::Canvas> canvas);
162
163         //! Sets the focus to a specific canvas
164         void focus(etl::handle<synfig::Canvas> canvas);
165
166         CanvasViewList & canvas_view_list() { return canvas_view_list_; }
167         
168         const CanvasViewList & canvas_view_list()const { return canvas_view_list_; }
169
170         bool save_as(const synfig::String &filename)const;
171
172         bool save_as(const synfig::String &filename);
173
174         //! Opens a "Save As" dialog, and then saves the composition to that file
175         void dialog_save_as();
176
177         bool save();
178
179         void dialog_cvs_commit();
180
181         void dialog_cvs_add();
182
183         void dialog_cvs_update();
184
185         void dialog_cvs_revert();
186         
187         //! Closes the instance of this composition
188         void close();
189         
190         void revert();
191         
192         void update_all_titles();
193
194         void refresh_canvas_tree();
195         
196         bool safe_revert();
197         bool safe_close();
198
199         void add_actions_to_menu(Gtk::Menu *menu,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
200         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;
201
202         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;
203
204         void process_action(synfig::String name, synfigapp::Action::ParamList param_list);
205
206         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location=0.5f);
207
208         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas,const std::list<synfigapp::ValueDesc>& value_desc_list);
209
210
211         static void edit_waypoint(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
212
213 private:
214         void insert_canvas(Gtk::TreeRow row,synfig::Canvas::Handle canvas);
215
216 public:
217         static etl::handle<Instance> create(synfig::Canvas::Handle canvas);
218 }; // END class Instance
219
220 }; // END namespace studio
221
222 /* === E N D =============================================================== */
223
224 #endif