remove incorrectly named
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcdialog.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdialog.h"
23 #include "bcsignals.h"
24 #include "condition.h"
25 #include "mutex.h"
26
27
28
29
30
31 BC_DialogThread::BC_DialogThread()
32  : Thread(0, 0, 0)
33 {
34         gui = 0;
35         startup_lock = new Condition(1, "BC_DialogThread::startup_lock");
36         window_lock = new Mutex("BC_DialogThread::window_lock");
37         active_lock = new Mutex("BC_DialogThread::active_lock");
38 }
39
40 BC_DialogThread::~BC_DialogThread()
41 {
42         startup_lock->lock("BC_DialogThread::~BC_DialogThread");
43         if(gui)
44         {
45                 gui->lock_window();
46                 gui->set_done(1);
47                 gui->unlock_window();
48         }
49         startup_lock->unlock();
50
51         delete startup_lock;
52         delete window_lock;
53         delete active_lock;
54 }
55
56 void BC_DialogThread::lock_dialog(const char *location)
57 {
58         window_lock->lock(location);
59 }
60
61 void BC_DialogThread::unlock_dialog()
62 {
63         window_lock->unlock();
64 }
65
66 int BC_DialogThread::is_running()
67 {
68         return Thread::running();
69 }
70
71 void BC_DialogThread::start()
72 {
73         if(Thread::running())
74         {
75                 window_lock->lock("BC_DialogThread::start");
76                 if(gui)
77                 {
78                         gui->lock_window("BC_DialogThread::start");
79                         gui->raise_window(1);
80                         gui->unlock_window();
81                 }
82                 window_lock->unlock();
83                 return;
84         }
85
86 // Don't allow anyone else to create the window
87         startup_lock->lock("BC_DialogThread::start");
88         Thread::start();
89
90 // Wait for startup
91         startup_lock->lock("BC_DialogThread::start");
92         startup_lock->unlock();
93         gui->init_wait();
94 }
95
96 void BC_DialogThread::run()
97 {
98         active_lock->lock("BC_DialogThread::run");
99         gui = new_gui();
100         startup_lock->unlock();
101         int result = gui->run_window();
102
103         handle_done_event(result);
104
105         window_lock->lock("BC_DialogThread::run");
106         delete gui;
107         gui = 0;
108         window_lock->unlock();
109
110         handle_close_event(result);
111         active_lock->unlock();
112 }
113
114 BC_Window* BC_DialogThread::new_gui()
115 {
116         printf("BC_DialogThread::new_gui called\n");
117         return 0;
118 }
119
120 BC_Window* BC_DialogThread::get_gui()
121 {
122         return gui;
123 }
124
125 void BC_DialogThread::handle_done_event(int result)
126 {
127 }
128
129 void BC_DialogThread::handle_close_event(int result)
130 {
131 }
132
133 void BC_DialogThread::close_window()
134 {
135         lock_dialog("BC_DialogThread::close_window");
136         if(gui)
137         {
138                 gui->lock_window("BC_DialogThread::close_window");
139                 gui->set_done(1);
140                 gui->unlock_window();
141         }
142         unlock_dialog();
143         join();
144 }
145
146 void BC_DialogThread::join()
147 {
148         if( !running() ) return;
149         active_lock->lock("BC_DialogThread::join");
150         active_lock->unlock();
151 }
152
153