(Source List) Source property signals (gtk2 part)
[ardour.git] / gtk2_ardour / editor_sources.h
1 /*
2     Copyright (C) 2000-2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19 #ifndef __gtk_ardour_editor_sources_h__
20 #define __gtk_ardour_editor_sources_h__
21
22 #include <boost/unordered_map.hpp>
23
24 #include <gtkmm/scrolledwindow.h>
25 #include <gtkmm/treemodel.h>
26 #include <gtkmm/treerowreference.h>
27 #include <gtkmm/treestore.h>
28
29 #include "editor_component.h"
30
31 #include "selection.h"
32
33 class EditorSources : public EditorComponent, public ARDOUR::SessionHandlePtr
34 {
35 public:
36         EditorSources (Editor *);
37
38         void set_session (ARDOUR::Session *);
39
40         void set_selection (Selection *sel) { _selection = sel; }
41
42         Gtk::Widget& widget () {
43                 return _scroller;
44         }
45
46         void clear ();
47
48         void reset_sort_direction (bool);
49         void reset_sort_type (Editing::RegionListSortType, bool);
50         void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
51
52         boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
53         boost::shared_ptr<ARDOUR::Region> get_single_selection ();
54
55         Editing::RegionListSortType sort_type () const {
56                 return _sort_type;
57         }
58
59         void block_change_connection (bool b) {
60                 _change_connection.block (b);
61         }
62
63         void unselect_all () {
64                 _display.get_selection()->unselect_all ();
65         }
66
67         void remove_unused_regions ();
68
69         XMLNode& get_state () const;
70         void set_state (const XMLNode &);
71
72 private:
73
74         struct Columns : public Gtk::TreeModel::ColumnRecord {
75                 Columns () {
76                         add (name);
77                         add (source);
78                         add (color_);
79                         add (natural_pos);
80                         add (path);
81                         add (take_id);
82                 }
83
84                 Gtk::TreeModelColumn<std::string> name;
85                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Source> > source;
86                 Gtk::TreeModelColumn<Gdk::Color> color_;
87                 Gtk::TreeModelColumn<std::string> natural_pos;
88                 Gtk::TreeModelColumn<std::string> path;
89                 Gtk::TreeModelColumn<std::string> take_id;
90         };
91
92         Columns _columns;
93
94         Gtk::TreeModel::RowReference last_row;
95
96         void freeze_tree_model ();
97         void thaw_tree_model ();
98         void source_changed (boost::shared_ptr<ARDOUR::Source>);
99         void populate_row (Gtk::TreeModel::Row row, boost::shared_ptr<ARDOUR::Source> source);
100         void selection_changed ();
101
102         sigc::connection _change_connection;
103
104         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
105
106         Gtk::Widget* old_focus;
107         Gtk::CellEditable* name_editable;
108         void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
109
110         void name_edit (const std::string&, const std::string&);
111
112         bool key_press (GdkEventKey *);
113         bool button_press (GdkEventButton *);
114
115         bool focus_in (GdkEventFocus*);
116         bool focus_out (GdkEventFocus*);
117         bool enter_notify (GdkEventCrossing*);
118         bool leave_notify (GdkEventCrossing*);
119
120         void show_context_menu (int button, int time);
121
122         int sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
123
124         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
125
126         void add_source (boost::shared_ptr<ARDOUR::Source>);
127         void remove_source (boost::shared_ptr<ARDOUR::Source>);
128
129         void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
130         void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
131         void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
132
133         void update_row (boost::shared_ptr<ARDOUR::Region>);
134         void update_all_rows ();
135
136         void insert_into_tmp_regionlist (boost::shared_ptr<ARDOUR::Region>);
137
138         void drag_data_received (
139                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
140                 );
141
142         Glib::RefPtr<Gtk::RadioAction> sort_type_action (Editing::RegionListSortType) const;
143
144         Glib::RefPtr<Gtk::Action> hide_action () const;
145         Glib::RefPtr<Gtk::Action> show_action () const;
146         Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
147
148         Gtk::Menu* _menu;
149         Gtk::ScrolledWindow _scroller;
150         Gtk::Frame _frame;
151
152         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
153
154         Glib::RefPtr<Gtk::TreeStore> _model;
155
156         bool ignore_region_list_selection_change;
157         bool ignore_selected_region_change;
158
159         Editing::RegionListSortType _sort_type;
160
161         std::list<boost::shared_ptr<ARDOUR::Region> > tmp_region_list;
162
163         typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::RowReference> RegionRowMap;
164         typedef boost::unordered_map<std::string, Gtk::TreeModel::RowReference > RegionSourceMap;
165
166         RegionRowMap region_row_map;
167         RegionSourceMap parent_regions_sources_map;
168
169         PBD::ScopedConnection source_property_connection;
170
171         PBD::ScopedConnection source_added_connection;
172         PBD::ScopedConnection source_removed_connection;
173
174         PBD::ScopedConnection editor_freeze_connection;
175         PBD::ScopedConnection editor_thaw_connection;
176
177         Selection* _selection;
178
179 };
180
181 #endif /* __gtk_ardour_editor_regions_h__ */