Remove cruft
[ardour.git] / gtk2_ardour / axis_view.cc
1 /*
2     Copyright (C) 2003 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
20 #include <cstdlib>
21 #include <cmath>
22
23 #include <algorithm>
24 #include <string>
25
26 #include <list>
27
28 #include "pbd/error.h"
29 #include "pbd/convert.h"
30 #include "pbd/i18n.h"
31
32 #include <gtkmm2ext/utils.h>
33 #include <gtkmm2ext/gtk_ui.h>
34
35 #include "ardour/selection.h"
36
37 #include "public_editor.h"
38 #include "ardour_ui.h"
39 #include "gui_object.h"
40 #include "axis_view.h"
41 #include "utils.h"
42
43 using namespace std;
44 using namespace Gtk;
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
47 using namespace ARDOUR_UI_UTILS;
48
49 list<Gdk::Color> AxisView::used_colors;
50
51 AxisView::AxisView ()
52 {
53 }
54
55 AxisView::~AxisView()
56 {
57 }
58
59 Gdk::Color
60 AxisView::unique_random_color()
61 {
62         return ::unique_random_color (used_colors);
63 }
64
65 string
66 AxisView::gui_property (const string& property_name) const
67 {
68         if (property_hashtable.count(property_name)) {
69                 return property_hashtable[property_name];
70         } else {
71                 string rv = gui_object_state().get_string (state_id(), property_name);
72                 property_hashtable.erase(property_name);
73                 property_hashtable.emplace(property_name, rv);
74                 return rv;
75         }
76 }
77
78 bool
79 AxisView::get_gui_property (const std::string& property_name, std::string& value) const
80 {
81         std::string str = gui_property(property_name);
82
83         if (!str.empty()) {
84                 value = str;
85                 return true;
86         }
87
88         return false;
89 }
90
91 void
92 AxisView::set_gui_property (const std::string& property_name, const std::string& value)
93 {
94         property_hashtable.erase (property_name);
95         property_hashtable.emplace (property_name, value);
96         gui_object_state ().set_property (state_id (), property_name, value);
97 }
98
99 bool
100 AxisView::marked_for_display () const
101 {
102         bool visible;
103         if (!get_gui_property ("visible", visible)) {
104                 return true;
105         }
106         return visible;
107 }
108
109 bool
110 AxisView::set_marked_for_display (bool yn)
111 {
112         bool visible;
113         if (get_gui_property ("visible", visible) && visible == yn) {
114                 return false; // nothing changed
115         }
116
117         set_gui_property ("visible", yn);
118         return true; // things changed
119 }
120
121 GUIObjectState&
122 AxisView::gui_object_state()
123 {
124         return *ARDOUR_UI::instance()->gui_object_state;
125 }
126
127 void
128 AxisView::set_selected (bool yn)
129 {
130         if (selected() == yn) {
131                 return;
132         }
133
134         Selectable::set_selected (yn);
135 }