got ardour_dialog compiling
[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 <gtkmm2ext/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         : Dialog (name), 
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 bool
46 ArdourDialog::on_enter_notify_event (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 bool
55 ArdourDialog::on_leave_notify_event (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 void
64 ArdourDialog::on_unmap ()
65 {
66         _within_hiding = true;
67         Hiding (); /* EMIT_SIGNAL */
68         _within_hiding = false;
69         Dialog::on_unmap ();
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::set_hide_on_stop (bool yn)
81 {
82         hide_on_stop = yn;
83 }
84
85 void
86 ArdourDialog::close ()
87 {
88         hide_all ();
89
90         if (kbd_input) {
91                 ARDOUR_UI::instance()->allow_focus (false);
92         }
93 }
94
95 void
96 ArdourDialog::stop (int rr)
97 {
98         if (hide_on_stop) {
99                 Hiding (); /* EMIT_SIGNAL */
100                 hide_all ();
101
102                 if (kbd_input) {
103                         ARDOUR_UI::instance()->allow_focus (false);
104                 }
105         }
106
107         if (running) {
108                 if (rr == 0) {
109                         response (GTK_RESPONSE_ACCEPT);
110                 } else {
111                         response (GTK_RESPONSE_CANCEL);
112                 }
113                 running = false;
114         }
115 }
116
117 void
118 ArdourDialog::run ()
119 {
120         show_all ();
121
122         if (kbd_input) {
123                 ARDOUR_UI::instance()->allow_focus (true);
124         }
125
126         running = true;
127         switch (Dialog::run ()) {
128         case GTK_RESPONSE_ACCEPT:
129                 _run_status = 0;
130                 break;
131                 
132         case GTK_RESPONSE_DELETE_EVENT:
133                 _run_status = -1;
134                 break;
135
136         default:
137                 _run_status = -1;
138         }
139 }
140
141 void
142 ArdourDialog::set_keyboard_input (bool yn)
143 {
144         kbd_input = yn;
145 }
146
147 int
148 ArdourDialog::run_status ()
149 {
150         return _run_status;
151 }