adjust h-size of color theme manager "Reset to Defaults" button
[ardour.git] / gtk2_ardour / visibility_group.h
1 /*
2     Copyright (C) 2011 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_visibility_group__
22 #define __ardour_visibility_group__
23
24 #include <gtkmm/liststore.h>
25 #include "pbd/signals.h"
26
27 class XMLNode;
28 class XMLProperty;
29
30 /** A class to manage a group of widgets where the visibility of each
31  *  can be configured by the user.  The class can generate a menu to
32  *  set up visibility, and save and restore visibility state to XML.
33  */
34
35 class VisibilityGroup
36 {
37 public:
38         VisibilityGroup (std::string const &);
39
40         void add (
41                 Gtk::Widget *,
42                 std::string const &,
43                 std::string const &,
44                 bool visible = false,
45                 boost::function<boost::optional<bool> ()> = 0
46                 );
47
48         Gtk::Widget* list_view ();
49         bool button_press_event (GdkEventButton *);
50         void update ();
51         void set_state (XMLNode const &);
52         void set_state (std::string);
53         std::string get_state_name () const;
54         std::string get_state_value () const;
55
56         PBD::Signal0<void> VisibilityChanged;
57
58         static std::string remove_element (std::string const& from, std::string const& element);
59         static std::string add_element (std::string const& from, std::string const& element);
60
61 private:
62
63         struct Member {
64                 Gtk::Widget* widget;
65                 std::string  id;
66                 std::string  name;
67                 bool         visible;
68                 boost::function<boost::optional<bool> ()> override;
69         };
70
71         class ModelColumns : public Gtk::TreeModelColumnRecord {
72         public:
73                 ModelColumns () {
74                         add (_visible);
75                         add (_name);
76                         add (_iterator);
77                 }
78
79                 Gtk::TreeModelColumn<bool> _visible;
80                 Gtk::TreeModelColumn<std::string> _name;
81                 Gtk::TreeModelColumn<std::vector<Member>::iterator> _iterator;
82         };
83
84         void toggle (std::vector<Member>::iterator);
85         void list_view_visible_changed (std::string const &);
86         void update_list_view ();
87         bool should_actually_be_visible (Member const &) const;
88
89         std::vector<Member> _members;
90         std::string _xml_property_name;
91         ModelColumns _model_columns;
92         Glib::RefPtr<Gtk::ListStore> _model;
93         bool _ignore_list_view_change;
94 };
95
96 #endif