1 /*
2  * Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __ardour_visibility_group__
21 #define __ardour_visibility_group__
22 
23 #include <gtkmm/liststore.h>
24 #include "pbd/signals.h"
25 
26 class XMLNode;
27 class XMLProperty;
28 
29 /** A class to manage a group of widgets where the visibility of each
30  *  can be configured by the user.  The class can generate a menu to
31  *  set up visibility, and save and restore visibility state to XML.
32  */
33 
34 class VisibilityGroup
35 {
36 public:
37 	VisibilityGroup (std::string const &);
38 
39 	void add (
40 		Gtk::Widget *,
41 		std::string const &,
42 		std::string const &,
43 		bool visible = false,
44 		boost::function<boost::optional<bool> ()> = 0
45 		);
46 
47 	Gtk::Widget* list_view ();
48 	bool button_press_event (GdkEventButton *);
49 	void update ();
50 	void set_state (XMLNode const &);
51 	void set_state (std::string);
52 	std::string get_state_name () const;
53 	std::string get_state_value () const;
54 
55 	PBD::Signal0<void> VisibilityChanged;
56 
57 	static std::string remove_element (std::string const& from, std::string const& element);
58 	static std::string add_element (std::string const& from, std::string const& element);
59 
60 private:
61 
62 	struct Member {
63 		Gtk::Widget* widget;
64 		std::string  id;
65 		std::string  name;
66 		bool         visible;
67 		boost::function<boost::optional<bool> ()> override;
68 	};
69 
70 	class ModelColumns : public Gtk::TreeModelColumnRecord {
71 	public:
ModelColumns()72 		ModelColumns () {
73 			add (_visible);
74 			add (_name);
75 			add (_iterator);
76 		}
77 
78 		Gtk::TreeModelColumn<bool> _visible;
79 		Gtk::TreeModelColumn<std::string> _name;
80 		Gtk::TreeModelColumn<std::vector<Member>::iterator> _iterator;
81 	};
82 
83 	void toggle (std::vector<Member>::iterator);
84 	void list_view_visible_changed (std::string const &);
85 	void update_list_view ();
86 	bool should_actually_be_visible (Member const &) const;
87 
88 	std::vector<Member> _members;
89 	std::string _xml_property_name;
90 	ModelColumns _model_columns;
91 	Glib::RefPtr<Gtk::ListStore> _model;
92 	bool _ignore_list_view_change;
93 };
94 
95 #endif
96