Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / ardour_dialog.cc
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2005-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2014-2018 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2015 Nick Mainsbridge <mainsbridge@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include <iostream>
24 #include <sigc++/bind.h>
25
26 #include <gtkmm2ext/doi.h>
27
28 #include "ardour_dialog.h"
29 #include "ardour_ui.h"
30 #include "keyboard.h"
31 #include "splash.h"
32 #include "utils.h"
33 #include "window_manager.h"
34
35 using namespace std;
36 using namespace Gtk;
37 using namespace Gtkmm2ext;
38 using namespace ARDOUR_UI_UTILS;
39
40 ArdourDialog::ArdourDialog (string title, bool modal, bool use_seperator)
41         : Dialog (title, modal, use_seperator)
42         , proxy (0)
43         , _splash_pushed (false)
44 {
45         init ();
46         set_position (Gtk::WIN_POS_MOUSE);
47 }
48
49 ArdourDialog::ArdourDialog (Gtk::Window& parent, string title, bool modal, bool use_seperator)
50         : Dialog (title, parent, modal, use_seperator)
51         , proxy (0)
52         , _splash_pushed (false)
53 {
54         init ();
55         set_position (Gtk::WIN_POS_CENTER_ON_PARENT);
56 }
57
58 ArdourDialog::~ArdourDialog ()
59 {
60         pop_splash ();
61         Keyboard::the_keyboard().focus_out_window (0, this);
62         WM::Manager::instance().remove (proxy);
63         proxy->explicit_delete ();
64 }
65
66 void
67 ArdourDialog::on_response (int response_id)
68 {
69         pop_splash ();
70         hide ();
71         ARDOUR::GUIIdle ();
72         Gtk::Dialog::on_response (response_id);
73 }
74
75 void
76 ArdourDialog::close_self ()
77 {
78         /* Don't call Idle, don't pop splash.
79          * This is used at exit and session-close and invoked
80          * via close_all_dialogs.
81          */
82         hide ();
83         Gtk::Dialog::on_response (RESPONSE_CANCEL);
84 }
85
86 void
87 ArdourDialog::pop_splash ()
88 {
89         if (_splash_pushed) {
90                 Splash* spl = Splash::instance();
91
92                 if (spl) {
93                         spl->pop_front();
94                 }
95                 _splash_pushed = false;
96         }
97 }
98
99 bool
100 ArdourDialog::on_focus_in_event (GdkEventFocus *ev)
101 {
102         Keyboard::the_keyboard().focus_in_window (ev, this);
103         return Dialog::on_focus_in_event (ev);
104 }
105
106 bool
107 ArdourDialog::on_focus_out_event (GdkEventFocus *ev)
108 {
109         if (!get_modal()) {
110                 Keyboard::the_keyboard().focus_out_window (ev, this);
111         }
112         return Dialog::on_focus_out_event (ev);
113 }
114
115 void
116 ArdourDialog::on_unmap ()
117 {
118         Keyboard::the_keyboard().leave_window (0, this);
119         Dialog::on_unmap ();
120 }
121
122 void
123 ArdourDialog::on_show ()
124 {
125         Dialog::on_show ();
126
127         // never allow the splash screen to obscure any dialog
128
129         if (Splash::exists()) {
130                 Splash* spl = Splash::instance();
131
132                 if (spl->is_visible()) {
133                         spl->pop_back_for (*this);
134                         _splash_pushed = true;
135                 }
136         }
137 }
138
139 bool
140 ArdourDialog::on_delete_event (GdkEventAny*)
141 {
142         hide ();
143         return false;
144 }
145
146 void
147 ArdourDialog::init ()
148 {
149         set_border_width (10);
150         add_events (Gdk::FOCUS_CHANGE_MASK);
151         set_type_hint (Gdk::WINDOW_TYPE_HINT_DIALOG);
152
153         Gtk::Window* parent = WM::Manager::instance().transient_parent();
154
155         if (parent) {
156                 set_transient_for (*parent);
157         }
158
159         ARDOUR_UI::CloseAllDialogs.connect (sigc::mem_fun (*this, &ArdourDialog::close_self)); /* send a RESPONSE_CANCEL to self */
160
161         proxy = new WM::ProxyTemporary (get_title(), this);
162         WM::Manager::instance().register_window (proxy);
163 }