Initial import of gtk2_ardour.
[ardour.git] / gtk2_ardour / ardour_dialog.cc
1 /*
2     Copyright (C) 2002 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 #include <iostream>
21
22 #include <gtkmmext/doi.h>
23
24 #include "ardour_dialog.h"
25 #include "keyboard.h"
26 #include "ardour_ui.h"
27
28
29 ArdourDialog::ArdourDialog (string name)
30         : Gtk::Window (GTK_WINDOW_TOPLEVEL),
31           KeyboardTarget (*this, name)
32 {
33         session = 0;
34         kbd_input = false;
35         running = false;
36         _run_status = 0;
37         _within_hiding = false;
38         hide_on_stop = true;
39 }
40
41 ArdourDialog::~ArdourDialog ()
42 {
43 }
44
45 gint
46 ArdourDialog::enter_notify_event_impl (GdkEventCrossing *ev)
47 {
48         if (ev->detail != GDK_NOTIFY_INFERIOR) {
49                 Keyboard::the_keyboard().set_current_dialog (this);
50         }
51         return FALSE;
52 }
53
54 gint
55 ArdourDialog::leave_notify_event_impl (GdkEventCrossing *ev)
56 {
57         if (ev->detail != GDK_NOTIFY_INFERIOR) {
58                 Keyboard::the_keyboard().set_current_dialog (0);
59         }
60         return FALSE;
61 }
62
63 gint
64 ArdourDialog::unmap_event_impl (GdkEventAny *ev)
65 {
66         _within_hiding = true;
67          Hiding (); /* EMIT_SIGNAL */
68         _within_hiding = false;
69         return Gtk::Window::unmap_event_impl (ev);
70 }
71
72 void
73 ArdourDialog::wm_close()
74 {
75         stop (-1);
76         ARDOUR_UI::instance()->allow_focus(false);
77 }
78
79 void
80 ArdourDialog::wm_doi ()
81 {
82         if (!hide_on_stop) {
83                 Hiding (); /* EMIT_SIGNAL */
84         }
85         stop (-1);
86         delete_when_idle (this);
87 }
88
89 gint
90 ArdourDialog::wm_close_event (GdkEventAny* ev)
91 {
92         wm_close ();
93         return TRUE;
94 }
95
96 gint
97 ArdourDialog::wm_doi_event (GdkEventAny* ev)
98 {
99         wm_doi ();
100         return TRUE;
101 }
102
103 gint
104 ArdourDialog::wm_doi_event_stop (GdkEventAny* ev)
105 {
106         stop (-1);
107         return TRUE;
108 }
109
110 void
111 ArdourDialog::set_hide_on_stop (bool yn)
112 {
113         hide_on_stop = yn;
114 }
115
116 void
117 ArdourDialog::close ()
118 {
119         hide_all ();
120
121         if (kbd_input) {
122                 ARDOUR_UI::instance()->allow_focus (false);
123         }
124 }
125
126 void
127 ArdourDialog::stop (int rr)
128 {
129         _run_status = rr;
130
131         if (hide_on_stop) {
132                 Hiding (); /* EMIT_SIGNAL */
133                 hide_all ();
134
135                 if (kbd_input) {
136                         ARDOUR_UI::instance()->allow_focus (false);
137                 }
138         }
139
140         if (running) {
141                 Gtk::Main::quit ();
142                 running = false;
143         }
144 }
145
146 void
147 ArdourDialog::run ()
148 {
149         show_all ();
150
151         if (kbd_input) {
152                 ARDOUR_UI::instance()->allow_focus (true);
153         }
154
155         running = true;
156         Gtk::Main::run ();
157 }
158
159 void
160 ArdourDialog::set_keyboard_input (bool yn)
161 {
162         kbd_input = yn;
163 }
164
165 int
166 ArdourDialog::run_status ()
167 {
168         return _run_status;
169 }