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