handle main window delete events sensibly
[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         std::cerr << "Tab catch up\n";
69         
70         tabbable_state_change (*editor);
71         tabbable_state_change (*mixer);
72         tabbable_state_change (*rc_option_editor);
73         
74         std::cerr << "Tab catch done\n";
75         
76         /* all actions are defined */
77
78         ActionManager::enable_accelerators ();
79         ActionManager::load_menus (ARDOUR_COMMAND_LINE::menus_file);
80
81         editor->track_mixer_selection ();
82         mixer->track_editor_selection ();
83
84         /* catch up on parameters */
85         
86         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
87         Config->map_parameters (pc);
88
89         ARDOUR_UI_UTILS::reset_dpi ();
90 }
91
92 void
93 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
94 {
95         DisplaySuspender ds;
96         BootMessage (_("Setup Editor"));
97         editor->set_session (s);
98         BootMessage (_("Setup Mixer"));
99         mixer->set_session (s);
100         meterbridge->set_session (s);
101
102         /* its safe to do this now */
103
104         BootMessage (_("Reload Session History"));
105         s->restore_history ("");
106 }
107
108 /** The main editor window has been closed */
109 gint
110 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
111 {
112 #ifdef TOP_MENUBAR
113         /* just hide the window, and return - the top menu stays up */
114         editor->hide ();
115         return TRUE;
116 #else
117         /* time to get out of here */
118         finish();
119         return TRUE;
120 #endif
121 }
122
123 GtkNotebook*
124 ARDOUR_UI::tab_window_root_drop (GtkNotebook* src,
125                                  GtkWidget* w,
126                                  gint x,
127                                  gint y,
128                                  gpointer)
129 {
130         using namespace std;
131         Gtk::Notebook* nb = 0;
132         Gtk::Window* win = 0;
133         Gtkmm2ext::Tabbable* tabbable = 0;
134
135
136         if (w == GTK_WIDGET(editor->contents().gobj())) {
137                 tabbable = editor;
138         } else if (w == GTK_WIDGET(mixer->contents().gobj())) {
139                 tabbable = mixer;
140         } else if (w == GTK_WIDGET(rc_option_editor->contents().gobj())) {
141                 tabbable = rc_option_editor;
142         } else {
143                 return 0;
144         }
145
146         nb = tabbable->tab_root_drop ();
147         win = tabbable->own_window ();
148
149         if (nb) {
150                 win->move (x, y);
151                 win->show_all ();
152                 win->present ();
153                 return nb->gobj();
154         }
155         
156         return 0; /* what was that? */
157 }
158
159 bool
160 ARDOUR_UI::idle_ask_about_quit ()
161 {
162         if (_session && _session->dirty()) {
163                 finish ();
164         } else {
165                 /* no session or session not dirty, but still ask anyway */
166
167                 Gtk::MessageDialog msg (string_compose ("Quit %1?", PROGRAM_NAME),
168                                         false, /* no markup */
169                                         Gtk::MESSAGE_INFO,
170                                         Gtk::BUTTONS_YES_NO,
171                                         true); /* modal */
172                 msg.set_default_response (Gtk::RESPONSE_YES);
173
174                 if (msg.run() == Gtk::RESPONSE_YES) {
175                         finish ();
176                 }
177         }
178
179         /* not reached but keep the compiler happy */
180
181         return false;
182 }
183
184 bool
185 ARDOUR_UI::main_window_delete_event (GdkEventAny* ev)
186 {
187         /* quit the application as soon as we go idle. If we call this here,
188          * the window manager/desktop can think we're taking too longer to
189          * handle the "delete" event
190          */
191         
192         Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_ask_about_quit));   
193         
194         return true;
195 }