Merge branch 'license-fix' of https://github.com/adiknoth/ardour
[ardour.git] / gtk2_ardour / ardour_ui_dependents.cc
1 /*
2     Copyright (C) 2000 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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 /* this file exists solely to break compilation dependencies that
25    would connect changes to the mixer or editor objects.
26 */
27
28 #include <cstdio>
29
30 #include "pbd/error.h"
31
32 #include "ardour/session.h"
33
34 #include "ardour_ui.h"
35 #include "public_editor.h"
36 #include "mixer_ui.h"
37 #include "keyboard.h"
38 #include "splash.h"
39 #include "route_params_ui.h"
40 #include "opts.h"
41 #include "i18n.h"
42
43 using namespace Gtk;
44 using namespace PBD;
45
46 namespace ARDOUR {
47         class Session;
48         class Route;
49 }
50
51 using namespace ARDOUR;
52
53 void
54 ARDOUR_UI::shutdown ()
55 {
56         if (ui_config->dirty()) {
57                 ui_config->save_state();
58         }
59 }
60
61 void
62 ARDOUR_UI::we_have_dependents ()
63 {
64         install_actions ();
65         ProcessorBox::register_actions ();
66         keyboard->setup_keybindings ();
67         editor->setup_tooltips ();
68         editor->UpdateAllTransportClocks.connect (sigc::mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
69
70         editor->track_mixer_selection ();
71         mixer->track_editor_selection ();
72 }
73
74 void
75 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
76 {
77         BootMessage (_("Setup Editor"));
78         editor->set_session (s);
79         BootMessage (_("Setup Mixer"));
80         mixer->set_session (s);
81
82         /* its safe to do this now */
83
84         BootMessage (_("Reload Session History"));
85         s->restore_history ("");
86 }
87
88 static bool
89 _hide_splash (gpointer arg)
90 {
91         ((ARDOUR_UI*)arg)->hide_splash();
92         return false;
93 }
94
95 void
96 ARDOUR_UI::goto_editor_window ()
97 {
98         if (splash && splash->is_visible()) {
99                 // in 2 seconds, hide the splash screen
100                 Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (_hide_splash), this), 2000);
101         }
102
103         editor->show_window ();
104         editor->present ();
105         flush_pending ();
106 }
107
108 void
109 ARDOUR_UI::goto_mixer_window ()
110 {
111         if (!editor) {
112                 return;
113         }
114
115         Glib::RefPtr<Gdk::Window> win = editor->get_window ();
116         Glib::RefPtr<Gdk::Screen> screen;
117         
118         if (win) {
119                 screen = win->get_screen();
120         } else {
121                 screen = Gdk::Screen::get_default();
122         }
123         
124         if (screen && screen->get_height() < 700) {
125                 Gtk::MessageDialog msg (_("This screen is not tall enough to display the mixer window"));
126                 msg.run ();
127                 return;
128         }
129
130         mixer->show_window ();
131         mixer->present ();
132         flush_pending ();
133 }
134
135 void
136 ARDOUR_UI::toggle_mixer_window ()
137 {
138         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-mixer"));
139         if (!act) {
140                 return;
141         }
142
143         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
144
145         if (tact->get_active()) {
146                 goto_mixer_window ();
147         } else {
148                 mixer->hide ();
149         }
150 }
151
152 void
153 ARDOUR_UI::toggle_editor_mixer ()
154 {
155         if (editor && mixer) {
156
157                 if (editor->get_screen() != mixer->get_screen()) {
158                         // different screens, so don't do anything
159                         return;
160                 }
161
162                 /* See if they are obscuring each other */
163                 
164                 gint ex, ey, ew, eh;
165                 gint mx, my, mw, mh;
166
167                 editor->get_position (ex, ey);
168                 editor->get_size (ew, eh);
169
170                 mixer->get_position (mx, my);
171                 mixer->get_size (mw, mh);
172
173                 GdkRectangle e;
174                 GdkRectangle m;
175                 GdkRectangle r;
176
177                 e.x = ex;
178                 e.y = ey;
179                 e.width = ew;
180                 e.height = eh;
181
182                 m.x = mx;
183                 m.y = my;
184                 m.width = mw;
185                 m.height = mh;
186                 
187                 if (!gdk_rectangle_intersect (&e, &m, &r)) {
188                         /* they do not intersect so do not toggle */
189                         return;
190                 }
191         }
192                 
193         if (mixer && mixer->fully_visible()) {
194                 goto_editor_window ();
195         } else {
196                 goto_mixer_window ();
197         }
198 }
199
200 /** The main editor window has been closed */
201 gint
202 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
203 {
204 #ifdef TOP_MENUBAR
205         /* just hide the window, and return - the top menu stays up */
206         editor->hide ();
207         return TRUE;
208 #else
209         /* time to get out of here */
210         finish();
211         return TRUE;
212 #endif
213 }
214