remove debug output
[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 "actions.h"
35 #include "ardour_ui.h"
36 #include "public_editor.h"
37 #include "meterbridge.h"
38 #include "mixer_ui.h"
39 #include "keyboard.h"
40 #include "splash.h"
41 #include "route_params_ui.h"
42 #include "opts.h"
43 #include "utils.h"
44
45 #include "i18n.h"
46
47 using namespace Gtk;
48 using namespace PBD;
49
50 namespace ARDOUR {
51         class Session;
52         class Route;
53 }
54
55 using namespace ARDOUR;
56
57 void
58 ARDOUR_UI::we_have_dependents ()
59 {
60         install_actions ();
61         ProcessorBox::register_actions ();
62         keyboard->setup_keybindings ();
63         editor->setup_tooltips ();
64         editor->UpdateAllTransportClocks.connect (sigc::mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
65
66         /* catch up on tabbable state */
67
68         tabbable_state_change (*editor);
69         tabbable_state_change (*mixer);
70         tabbable_state_change (*rc_option_editor);
71         
72         /* all actions are defined */
73
74         ActionManager::enable_accelerators ();
75         ActionManager::load_menus (ARDOUR_COMMAND_LINE::menus_file);
76
77         editor->track_mixer_selection ();
78         mixer->track_editor_selection ();
79
80         /* catch up on parameters */
81         
82         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
83         Config->map_parameters (pc);
84
85         ARDOUR_UI_UTILS::reset_dpi ();
86 }
87
88 void
89 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
90 {
91         DisplaySuspender ds;
92         BootMessage (_("Setup Editor"));
93         editor->set_session (s);
94         BootMessage (_("Setup Mixer"));
95         mixer->set_session (s);
96         meterbridge->set_session (s);
97
98         /* its safe to do this now */
99
100         BootMessage (_("Reload Session History"));
101         s->restore_history ("");
102 }
103
104 /** The main editor window has been closed */
105 gint
106 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
107 {
108 #ifdef TOP_MENUBAR
109         /* just hide the window, and return - the top menu stays up */
110         editor->hide ();
111         return TRUE;
112 #else
113         /* time to get out of here */
114         finish();
115         return TRUE;
116 #endif
117 }
118
119 GtkNotebook*
120 ARDOUR_UI::tab_window_root_drop (GtkNotebook* src,
121                                  GtkWidget* w,
122                                  gint x,
123                                  gint y,
124                                  gpointer)
125 {
126         using namespace std;
127         Gtk::Notebook* nb = 0;
128         Gtk::Window* win = 0;
129         Gtkmm2ext::Tabbable* tabbable = 0;
130
131
132         if (w == GTK_WIDGET(editor->contents().gobj())) {
133                 tabbable = editor;
134         } else if (w == GTK_WIDGET(mixer->contents().gobj())) {
135                 tabbable = mixer;
136         } else if (w == GTK_WIDGET(rc_option_editor->contents().gobj())) {
137                 tabbable = rc_option_editor;
138         } else {
139                 return 0;
140         }
141
142         nb = tabbable->tab_root_drop ();
143         win = tabbable->own_window ();
144
145         if (nb) {
146                 win->move (x, y);
147                 win->show_all ();
148                 win->present ();
149                 return nb->gobj();
150         }
151         
152         return 0; /* what was that? */
153 }
154
155 bool
156 ARDOUR_UI::idle_ask_about_quit ()
157 {
158         if (_session && _session->dirty()) {
159                 finish ();
160         } else {
161                 /* no session or session not dirty, but still ask anyway */
162
163                 Gtk::MessageDialog msg (string_compose ("Quit %1?", PROGRAM_NAME),
164                                         false, /* no markup */
165                                         Gtk::MESSAGE_INFO,
166                                         Gtk::BUTTONS_YES_NO,
167                                         true); /* modal */
168                 msg.set_default_response (Gtk::RESPONSE_YES);
169
170                 if (msg.run() == Gtk::RESPONSE_YES) {
171                         finish ();
172                 }
173         }
174
175         /* not reached but keep the compiler happy */
176
177         return false;
178 }
179
180 bool
181 ARDOUR_UI::main_window_delete_event (GdkEventAny* ev)
182 {
183         /* quit the application as soon as we go idle. If we call this here,
184          * the window manager/desktop can think we're taking too longer to
185          * handle the "delete" event
186          */
187         
188         Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_ask_about_quit));   
189         
190         return true;
191 }
192
193 static GtkNotebook*
194 tab_window_root_drop (GtkNotebook* src,
195                       GtkWidget* w,
196                       gint x,
197                       gint y,
198                       gpointer user_data)
199 {
200         return ARDOUR_UI::instance()->tab_window_root_drop (src, w, x, y, user_data);
201 }
202
203 int
204 ARDOUR_UI::setup_windows ()
205 {
206         /* we don't use a widget with its own window for the tab close button,
207            which makes it impossible to rely on GTK+ to generate signals for
208            events occuring "in" this widget. Instead, we pre-connect a
209            handler to the relevant events on the notebook and then check
210            to see if the event coordinates tell us that it occured "in"
211            the close button.
212         */
213         _tabs.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_button_event), false);
214         _tabs.signal_button_release_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_button_event), false);
215
216         rc_option_editor = new RCOptionEditor;
217         rc_option_editor->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change));
218
219         if (create_editor ()) {
220                 error << _("UI: cannot setup editor") << endmsg;
221                 return -1;
222         }
223
224         if (create_mixer ()) {
225                 error << _("UI: cannot setup mixer") << endmsg;
226                 return -1;
227         }
228
229         if (create_meterbridge ()) {
230                 error << _("UI: cannot setup meterbridge") << endmsg;
231                 return -1;
232         }
233
234         /* order of addition affects order seen in initial window display */
235         
236         rc_option_editor->add_to_notebook (_tabs, _("Preferences"));
237         mixer->add_to_notebook (_tabs, _("Mixer"));
238         editor->add_to_notebook (_tabs, _("Editor"));
239
240         /* all other dialogs are created conditionally */
241
242         we_have_dependents ();
243
244 #ifdef TOP_MENUBAR
245         EventBox* status_bar_event_box = manage (new EventBox);
246
247         status_bar_event_box->add (status_bar_label);
248         status_bar_event_box->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
249         status_bar_label.set_size_request (300, -1);
250
251         status_bar_label.show ();
252         status_bar_event_box->show ();
253
254         status_bar_event_box->signal_button_press_event().connect (mem_fun (*this, &ARDOUR_UI::status_bar_button_press));
255
256         status_bar_hpacker.pack_start (*status_bar_event_box, true, true, 6);
257         status_bar_hpacker.pack_start (menu_bar_base, false, false, 2);
258 #else
259         top_packer.pack_start (menu_bar_base, false, false);
260 #endif
261
262         main_vpacker.pack_start (top_packer, false, false);
263
264         /* now add the transport frame to the top of main window */
265         
266         main_vpacker.pack_start (transport_frame, false, false);
267         main_vpacker.pack_start (_tabs, true, true);
268
269 #ifdef TOP_MENUBAR
270         main_vpacker.pack_start (status_bar_hpacker, false, false);
271 #endif
272
273         setup_transport();
274         build_menu_bar ();
275         setup_tooltips ();
276
277         _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::main_window_delete_event));
278         
279         /* pack the main vpacker into the main window and show everything
280          */
281
282         _main_window.add (main_vpacker);
283         transport_frame.show_all ();
284
285         const XMLNode* mnode = main_window_settings ();
286
287         if (mnode) {
288                 const XMLProperty* prop;
289                 gint x = -1;
290                 gint y = -1;
291                 gint w = -1;
292                 gint h = -1;
293
294                 if ((prop = mnode->property (X_("x"))) != 0) {
295                         x = atoi (prop->value());
296                 }
297
298                 if ((prop = mnode->property (X_("y"))) != 0) {
299                         y = atoi (prop->value());
300                 } 
301
302                 if ((prop = mnode->property (X_("w"))) != 0) {
303                         w = atoi (prop->value());
304                 } 
305                 
306                 if ((prop = mnode->property (X_("h"))) != 0) {
307                         h = atoi (prop->value());
308                 }
309
310                 if (x >= 0 && y >= 0 && w >= 0 && h >= 0) {
311                         _main_window.set_position (Gtk::WIN_POS_NONE);
312                 }
313                 
314                 if (x >= 0 && y >= 0) {
315                         _main_window.move (x, y);
316                 }
317                 
318                 if (w > 0 && h > 0) {
319                         _main_window.set_default_size (w, h);
320                 }
321
322                 std::string current_tab;
323                 
324                 if ((prop = mnode->property (X_("current-tab"))) != 0) {
325                         current_tab = prop->value();
326                 } else {
327                         current_tab = "editor";
328                 }
329                 if (mixer && current_tab == "mixer") {
330                         _tabs.set_current_page (_tabs.page_num (mixer->contents()));
331                 } else if (rc_option_editor && current_tab == "preferences") {
332                         _tabs.set_current_page (_tabs.page_num (rc_option_editor->contents()));
333                 } else if (editor) {
334                         _tabs.set_current_page (_tabs.page_num (editor->contents()));
335                 }
336         }
337         
338         _main_window.show_all ();
339         setup_toplevel_window (_main_window, "", this);
340         
341         _tabs.signal_switch_page().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_switch));
342         _tabs.signal_page_removed().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_page_removed));
343         _tabs.signal_page_added().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_page_added));
344
345         /* It would be nice if Gtkmm had wrapped this rather than just
346          * deprecating the old set_window_creation_hook() method, but oh well...
347          */
348         g_signal_connect (_tabs.gobj(), "create-window", (GCallback) ::tab_window_root_drop, this);
349
350         return 0;
351 }