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 
ArdourDialog(string title,bool modal,bool use_seperator)40 ArdourDialog::ArdourDialog (string title, bool modal, bool use_seperator)
41 	: Dialog (title, modal, use_seperator)
42 	, _sensitive (true)
43 	, proxy (0)
44 	, _splash_pushed (false)
45 {
46 	init ();
47 	set_position (Gtk::WIN_POS_MOUSE);
48 }
49 
ArdourDialog(Gtk::Window & parent,string title,bool modal,bool use_seperator)50 ArdourDialog::ArdourDialog (Gtk::Window& parent, string title, bool modal, bool use_seperator)
51 	: Dialog (title, parent, modal, use_seperator)
52 	, _sensitive (true)
53 	, proxy (0)
54 	, _splash_pushed (false)
55 {
56 	init ();
57 	set_position (Gtk::WIN_POS_CENTER_ON_PARENT);
58 }
59 
~ArdourDialog()60 ArdourDialog::~ArdourDialog ()
61 {
62 	pop_splash ();
63 	Keyboard::the_keyboard().focus_out_window (0, this);
64 	WM::Manager::instance().remove (proxy);
65 	proxy->explicit_delete ();
66 }
67 
68 void
on_response(int response_id)69 ArdourDialog::on_response (int response_id)
70 {
71 	pop_splash ();
72 	hide ();
73 	ARDOUR::GUIIdle ();
74 	Gtk::Dialog::on_response (response_id);
75 }
76 
77 void
close_self()78 ArdourDialog::close_self ()
79 {
80 	/* Don't call Idle, don't pop splash.
81 	 * This is used at exit and session-close and invoked
82 	 * via close_all_dialogs.
83 	 */
84 	hide ();
85 	Gtk::Dialog::on_response (RESPONSE_CANCEL);
86 }
87 
88 void
pop_splash()89 ArdourDialog::pop_splash ()
90 {
91 	if (_splash_pushed) {
92 		Splash* spl = Splash::exists () ? Splash::instance() : NULL;
93 
94 		if (spl) {
95 			spl->pop_front_for (*this);
96 		}
97 		_splash_pushed = false;
98 	}
99 }
100 
101 bool
on_focus_in_event(GdkEventFocus * ev)102 ArdourDialog::on_focus_in_event (GdkEventFocus *ev)
103 {
104 	Keyboard::the_keyboard().focus_in_window (ev, this);
105 	return Dialog::on_focus_in_event (ev);
106 }
107 
108 bool
on_focus_out_event(GdkEventFocus * ev)109 ArdourDialog::on_focus_out_event (GdkEventFocus *ev)
110 {
111 	if (!get_modal()) {
112 		Keyboard::the_keyboard().focus_out_window (ev, this);
113 	}
114 	return Dialog::on_focus_out_event (ev);
115 }
116 
117 void
on_unmap()118 ArdourDialog::on_unmap ()
119 {
120 	Keyboard::the_keyboard().leave_window (0, this);
121 	pop_splash ();
122 	Dialog::on_unmap ();
123 }
124 
125 void
on_show()126 ArdourDialog::on_show ()
127 {
128 	Dialog::on_show ();
129 
130 	// never allow the splash screen to obscure any dialog
131 
132 	if (Splash::exists()) {
133 		Splash* spl = Splash::instance();
134 
135 		spl->pop_back_for (*this);
136 		_splash_pushed = true;
137 	}
138 
139 	_sensitive = true;
140 }
141 
142 bool
on_delete_event(GdkEventAny *)143 ArdourDialog::on_delete_event (GdkEventAny*)
144 {
145 	hide ();
146 	return false;
147 }
148 
149 void
init()150 ArdourDialog::init ()
151 {
152 	set_border_width (10);
153 	add_events (Gdk::FOCUS_CHANGE_MASK);
154 	set_type_hint (Gdk::WINDOW_TYPE_HINT_DIALOG);
155 
156 	Gtk::Window* parent = WM::Manager::instance().transient_parent();
157 
158 	if (parent) {
159 		set_transient_for (*parent);
160 	}
161 
162 	ARDOUR_UI::CloseAllDialogs.connect (sigc::mem_fun (*this, &ArdourDialog::close_self)); /* send a RESPONSE_CANCEL to self */
163 
164 	proxy = new WM::ProxyTemporary (get_title(), this);
165 	WM::Manager::instance().register_window (proxy);
166 }
167 
168 void
set_ui_sensitive(bool yn)169 ArdourDialog::set_ui_sensitive (bool yn)
170 {
171 	_sensitive = yn;
172 }
173