Exciting new Alt/h help key provided by sge (Georgy) with many thanks!
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / remotecontrol.C
1
2 #include "bccolors.h"
3 #include "mainsession.h"
4 #include "mwindow.h"
5 #include "mwindowgui.h"
6 #include "record.h"
7 #include "remotecontrol.h"
8
9
10 RemoteWindow::RemoteWindow(RemoteControl *remote_control)
11  : BC_Window(_(PROGRAM_NAME ": RemoteWindow"),
12                 0, 0, xS(16), yS(16), -1, -1, 1, 0, 1)
13 {
14         this->remote_control = remote_control;
15 // *** CONTEXT_HELP ***
16         context_help_set_keyword("Remote Control for DVB");
17 }
18
19 RemoteWindow::~RemoteWindow()
20 {
21 }
22
23
24 RemoteControl::RemoteControl(MWindowGUI *mwindow_gui)
25  : Thread(1, 0, 0)
26 {
27         this->mwindow_gui = mwindow_gui;
28         this->handler = 0;
29         active_lock = new Mutex("RemoteControl::active_lock");
30
31         remote_window = new RemoteWindow(this);
32         Thread::start();
33         remote_window->init_wait();
34         gui = new RemoteGUI(remote_window, this);
35 }
36
37 void RemoteControl::run()
38 {
39         remote_window->run_window();
40 }
41
42 RemoteControl::~RemoteControl()
43 {
44         if( Thread::running() ) {
45                 remote_window->close(1);
46         }
47         Thread::join();
48         delete gui;
49         delete remote_window;
50         delete active_lock;
51 }
52
53
54
55 int RemoteControl::activate(RemoteHandler *handler)
56 {
57         int result = 0;
58         deactivate();
59         if( !handler )
60                 handler = !mwindow_gui->record->running() ?
61                         (RemoteHandler *)mwindow_gui->cwindow_remote_handler :
62                         (RemoteHandler *)mwindow_gui->record_remote_handler ;
63         active_lock->lock("RemoteControl::activate");
64         if( handler ) {
65                 gui->lock_window("RemoteControl::activate");
66                 gui->set_active(handler);
67                 gui->set_color(handler->color);
68                 gui->fill_color(handler->color);
69                 gui->unlock_window();
70                 result = 1;
71         }
72         active_lock->unlock();
73         return result;
74 }
75
76 int RemoteControl::deactivate()
77 {
78         int result = 0;
79         if( is_active() ) {
80                 active_lock->lock("RemoteControl::deactivate");
81                 if( is_active() ) {
82                         gui->set_inactive();
83                         result = 1;
84                 }
85                 active_lock->unlock();
86         }
87         return result;
88 }
89
90 int RemoteControl::remote_key(int key)
91 {
92         if( !is_active() ) return 0;
93         return handler->remote_key(key);
94 }
95
96 void RemoteControl::set_color(int color)
97 {
98         gui->lock_window("RemoteControl::fill_color");
99         gui->set_color(color);
100         gui->unlock_window();
101 }
102
103 void RemoteControl::fill_color(int color)
104 {
105         gui->lock_window("RemoteControl::fill_color");
106         gui->fill_color(color);
107         gui->unlock_window();
108 }
109
110 RemoteGUI::RemoteGUI(BC_WindowBase *wdw, RemoteControl *remote_control)
111  : BC_Popup(wdw, remote_control->mwindow_gui->mwindow->session->mwindow_x,0,
112                 xS(16),yS(16), -1, 1)
113 {
114         this->remote_control = remote_control;
115 }
116
117 RemoteGUI::~RemoteGUI()
118 {
119 }
120
121 void RemoteGUI::set_active(RemoteHandler *handler)
122 {
123         remote_control->handler = handler;
124         show_window();
125         grab_keyboard();
126 }
127
128 void RemoteGUI::set_inactive()
129 {
130         remote_control->handler = 0;
131         ungrab_keyboard();
132         hide_window();
133 }
134
135 void RemoteGUI::
136 fill_color(int color)
137 {
138         set_color(color);
139         draw_box(0, 0, get_w(), get_h());
140         flash();
141 }
142
143 void RemoteGUI::tile_windows(int config)
144 {
145         MWindow *mwindow = remote_control->mwindow_gui->mwindow;
146         if( config == mwindow->session->window_config ) return;
147         lock_window("RemoteGUI::tile_windows");
148         ungrab_keyboard();  hide_window();
149         mwindow->gui->lock_window("RemoteGUI::tile_windows 1");
150         int need_reload = mwindow->tile_windows(config);
151         mwindow->gui->unlock_window();
152         if( !need_reload ) {
153                 show_window();  raise_window();  grab_keyboard();
154                 reposition_window(mwindow->session->mwindow_x,0);
155                 unlock_window();
156         }
157         else {
158                 unlock_window();
159                 mwindow->restart_status = 1;
160                 mwindow->quit();
161         }
162 }
163
164 int RemoteGUI::button_press_event()
165 {
166         remote_control->deactivate();
167         return 1;
168 }
169
170 int RemoteGUI::keypress_event()
171 {
172         int key = get_keypress();
173         int result = remote_control->remote_key(key);
174         if( result < 0 ) {
175                 remote_control->deactivate();
176                 result = 0;
177         }
178         return result;
179 }
180
181 RemoteHandler::RemoteHandler(RemoteGUI *gui, int color)
182 {
183         this->gui = gui;
184         this->color = color;
185 }
186
187 RemoteHandler::~RemoteHandler()
188 {
189 }
190
191 int RemoteHandler::remote_key(int key)
192 {
193         gui->set_inactive();
194         return -1;
195 }
196
197 int RemoteHandler::process_key(int key)
198 {
199         return -1;
200 }
201