initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 }
38
39 BC_DialogThread::~BC_DialogThread()
40 {
41         startup_lock->lock("BC_DialogThread::~BC_DialogThread");
42         if(gui)
43         {
44                 gui->lock_window();
45                 gui->set_done(1);
46                 gui->unlock_window();
47         }
48         startup_lock->unlock();
49         join();
50
51         delete startup_lock;
52         delete window_lock;
53 }
54
55 void BC_DialogThread::lock_window(const char *location)
56 {
57         window_lock->lock(location);
58 }
59
60 void BC_DialogThread::unlock_window()
61 {
62         window_lock->unlock();
63 }
64
65 int BC_DialogThread::is_running()
66 {
67         return Thread::running();
68 }
69
70 void BC_DialogThread::start()
71 {
72         if(Thread::running())
73         {
74                 window_lock->lock("BC_DialogThread::start");
75                 if(gui)
76                 {
77                         gui->lock_window("BC_DialogThread::start");
78                         gui->raise_window(1);
79                         gui->unlock_window();
80                 }
81                 window_lock->unlock();
82                 return;
83         }
84
85 // Don't allow anyone else to create the window
86         startup_lock->lock("BC_DialogThread::start");
87         Thread::start();
88
89 // Wait for startup
90         startup_lock->lock("BC_DialogThread::start");
91         startup_lock->unlock();
92         gui->init_wait();
93 }
94
95 void BC_DialogThread::run()
96 {
97         gui = new_gui();
98         startup_lock->unlock();
99         int result = gui->run_window();
100
101         handle_done_event(result);
102
103         window_lock->lock("BC_DialogThread::run");
104         delete gui;
105         gui = 0;
106         window_lock->unlock();
107
108         handle_close_event(result);
109 }
110
111 void BC_DialogThread::lock_gui(const char *location)
112 {
113         window_lock->lock(location);
114 }
115
116 void BC_DialogThread::unlock_gui()
117 {
118         window_lock->unlock();
119 }
120
121
122 BC_Window* BC_DialogThread::new_gui()
123 {
124         printf("BC_DialogThread::new_gui called\n");
125         return 0;
126 }
127
128 BC_Window* BC_DialogThread::get_gui()
129 {
130         return gui;
131 }
132
133 void BC_DialogThread::handle_done_event(int result)
134 {
135 }
136
137 void BC_DialogThread::handle_close_event(int result)
138 {
139 }
140
141 void BC_DialogThread::close_window()
142 {
143         lock_window("BC_DialogThread::close_window");
144         if(gui)
145         {
146                 gui->lock_window("BC_DialogThread::close_window");
147                 gui->set_done(1);
148                 gui->unlock_window();
149         }
150         unlock_window();
151 }
152
153
154
155