Speed up AFL/PFL changes for large sessions
[ardour.git] / gtk2_ardour / color_theme_manager.h
1 /*
2     Copyright (C) 2000-2016 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 #ifndef __ardour_gtk_color_manager_h__
21 #define __ardour_gtk_color_manager_h__
22
23 #include <gtkmm/treeview.h>
24 #include <gtkmm/treestore.h>
25 #include <gtkmm/scrolledwindow.h>
26 #include <gtkmm/colorselection.h>
27 #include <gtkmm/button.h>
28
29 #include "canvas/types.h"
30 #include "canvas/canvas.h"
31
32 #include "option_editor.h"
33 #include "ui_config.h"
34
35 namespace ArdourCanvas {
36         class Container;
37         class ScrollGroup;
38 }
39
40 class ArdourDialog;
41
42 class ColorThemeManager : public Gtk::VBox, public OptionEditorComponent
43 {
44   public:
45         ColorThemeManager();
46         ~ColorThemeManager();
47
48         void reset_canvas_colors();
49         void on_color_theme_changed ();
50
51         /** Called when a configuration parameter's value has changed.
52          *  @param p parameter name
53          */
54         void parameter_changed (std::string const & p);
55
56         /** Called to instruct the object to set its UI state from the configuration */
57         void set_state_from_config ();
58
59         /** Called to instruct the object to add itself to an OptionEditorPage */
60         void add_to_page (OptionEditorPage *);
61
62         void set_note (std::string const &);
63
64         Gtk::Widget& tip_widget();
65
66   private:
67         Gtk::Button reset_button;
68         Gtk::Notebook notebook;
69
70         /* handls response from color dialog when it is used to
71            edit a derived color.
72         */
73         void palette_color_response (int, std::string);
74
75         Gtk::ScrolledWindow palette_scroller;
76         ArdourCanvas::GtkCanvasViewport palette_viewport;
77         ArdourCanvas::Container* palette_group;
78
79         /* these methods create and manage a canvas for use in either the
80            palette tab or in a separate dialog. Different behaviour is
81            accomplished by changing the event handler passed into the
82            allocation handler. We do it there because we have to rebuild
83            the canvas on allocation events, and during the rebuild, connect
84            each rectangle to the event handler.
85
86            the alternative is one event handler for the canvas and a map
87            of where each color rectangle is. nothing wrong with this
88            but the per-rect event setup is simpler and avoids building
89            and looking up the map information.
90         */
91         ArdourCanvas::Container* initialize_palette_canvas (ArdourCanvas::Canvas& canvas);
92         void build_palette_canvas (ArdourCanvas::Canvas&, ArdourCanvas::Container&, sigc::slot<bool,GdkEvent*,std::string> event_handler);
93         void palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, ArdourCanvas::Canvas* canvas, sigc::slot<bool,GdkEvent*,std::string> event_handler);
94         void palette_size_request (Gtk::Requisition*);
95
96         /* handles events from a palette canvas inside the palette (derived
97            colors) tab
98         */
99         bool palette_event (GdkEvent*, std::string name);
100         /* allows user to edit a named color (e.g. "color 3") after clicking
101            on it inside the palette tab.
102         */
103         void edit_palette_color (std::string);
104
105         struct ColorAliasModelColumns : public Gtk::TreeModel::ColumnRecord {
106                 ColorAliasModelColumns() {
107                         add (name);
108                         add (alias);
109                         add (color);
110                         add (key);
111                 }
112
113                 Gtk::TreeModelColumn<std::string>  name;
114                 Gtk::TreeModelColumn<std::string>  alias;
115                 Gtk::TreeModelColumn<Gdk::Color>   color;
116                 Gtk::TreeModelColumn<std::string>  key;
117         };
118
119         ColorAliasModelColumns       alias_columns;
120         Gtk::TreeView                alias_display;
121         Glib::RefPtr<Gtk::TreeStore> alias_list;
122         Gtk::ScrolledWindow          alias_scroller;
123
124         bool alias_button_press_event (GdkEventButton*);
125
126         ArdourDialog* palette_window;
127         sigc::connection palette_response_connection;
128
129         void choose_color_from_palette (std::string const &target_name);
130
131         bool alias_palette_event (GdkEvent*, std::string, std::string);
132         void alias_palette_response (int, std::string, std::string);
133
134         void setup_aliases ();
135         void setup_palette ();
136
137         Gtk::ScrolledWindow modifier_scroller;
138         Gtk::VBox modifier_vbox;
139
140         void setup_modifiers ();
141         void modifier_edited (Gtk::Range*, std::string);
142
143         Gtk::ColorSelectionDialog color_dialog;
144         sigc::connection color_dialog_connection;
145
146         void colors_changed ();
147         void set_ui_to_state ();
148
149
150         struct ColorThemeModelColumns : public Gtk::TreeModel::ColumnRecord {
151                 ColorThemeModelColumns() {
152                         add (name);
153                         add (path);
154                 }
155
156                 Gtk::TreeModelColumn<std::string>  name;
157                 Gtk::TreeModelColumn<std::string>  path;
158         };
159
160         ColorThemeModelColumns color_theme_columns;
161         Glib::RefPtr<Gtk::TreeStore> theme_list;
162
163         Gtk::Label color_theme_label;
164         Gtk::ComboBox color_theme_dropdown;
165
166 };
167
168 #endif /* __ardour_gtk_color_manager_h__ */