rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / probeprefs.C
1 #include "bcwindowbase.h"
2 #include "bcdisplayinfo.h"
3 #include "bcdialog.h"
4 #include "language.h"
5 #include "mainerror.h"
6 #include "mwindow.h"
7 #include "probeprefs.h"
8 #include "preferences.h"
9 #include "preferencesthread.h"
10 #include "theme.h"
11
12 #include <sys/wait.h>
13
14 ProbePref::ProbePref(const char *nm, int armed)
15 {
16         strncpy(name, nm, sizeof(name));
17         this->armed = armed;
18 }
19
20 ProbePref::~ProbePref()
21 {
22 }
23
24 FileProbeDialog::FileProbeDialog(PreferencesWindow *pwindow)
25  : BC_DialogThread()
26 {
27         this->pwindow = pwindow;
28 }
29
30 FileProbeDialog::~FileProbeDialog()
31 {
32         close_window();
33 }
34
35 BC_Window* FileProbeDialog::new_gui()
36 {
37         BC_DisplayInfo display_info;
38         int x = display_info.get_abs_cursor_x();
39         int y = display_info.get_abs_cursor_y();
40
41         pb_window = new ProbeEditWindow(this, x, y);
42         pb_window->create_objects();
43         return pb_window;
44 }
45
46 void FileProbeDialog::handle_close_event(int result)
47 {
48         pb_window = 0;
49 }
50
51
52 ProbeEditWindow::ProbeEditWindow(FileProbeDialog *pb_dialog, int x, int y)
53  : BC_Window(_(PROGRAM_NAME ": Probes"), x, y, 300, 200, 300, 200, 0, 0, 1)
54 {
55         this->pb_dialog = pb_dialog;
56         probe_list = 0;
57         probe_up_button = 0;
58         probe_down_button = 0;
59         probe_enabled = 0;
60         pb_enabled = 0;
61         pb_disabled = 0;
62 }
63
64 ProbeEditWindow::~ProbeEditWindow()
65 {
66         delete pb_enabled;
67         delete pb_disabled;
68 }
69
70 void ProbeEditWindow::create_objects()
71 {
72         pb_enabled = new BC_Pixmap(this,
73                 BC_WindowBase::get_resources()->listbox_up,
74                 PIXMAP_ALPHA);
75         pb_disabled = new BC_Pixmap(this,
76                 BC_WindowBase::get_resources()->listbox_dn,
77                 PIXMAP_ALPHA);
78         Preferences *preferences = pb_dialog->pwindow->thread->preferences;
79         for( int i=0; i<preferences->file_probes.size(); ++i ) {
80                 probe_items.append(new ProbePrefItem(this, preferences->file_probes[i]));
81         }
82         int x = 10, y = 10;
83         add_subwindow(probe_list = new ProbePrefList(this, x, y));
84         y += probe_list->get_h();
85         int x1 = x, y1 = y;
86         add_subwindow(probe_up_button = new ProbeUpButton(this, x1, y1));
87         x1 += probe_up_button->get_w() + 10;
88         add_subwindow(probe_down_button = new ProbeDownButton(this, x1, y1));
89         x1 += probe_down_button->get_w() + 10;
90         add_subwindow(probe_enabled = new ProbeEnabled(this, x1, y1));
91         probe_enabled->disable();
92
93         add_subwindow(new ProbeEditOK(this));
94         add_subwindow(new BC_CancelButton(this));
95
96         list_update();
97         show_window();
98 }
99
100 ProbeEditOK::ProbeEditOK(ProbeEditWindow *pb_window)
101  : BC_OKButton(pb_window)
102 {
103         this->pb_window = pb_window;
104 }
105
106 ProbeEditOK::~ProbeEditOK()
107 {
108 }
109
110 int ProbeEditOK::handle_event()
111 {
112         Preferences *preferences = pb_window->pb_dialog->pwindow->thread->preferences;
113         ArrayList<ProbePref *> &file_probes = preferences->file_probes;
114         file_probes.remove_all_objects();
115         ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
116         for( int i=0; i<probe_items.size(); ++i ) {
117                 ProbePrefItem *item = probe_items[i];
118                 file_probes.append(new ProbePref(item->get_text(), item->armed));
119         }
120         return BC_OKButton::handle_event();
121 }
122
123 int ProbeEditWindow::list_update()
124 {
125 //for( int i=0; i<probe_items.size(); ++i ) printf("%s, ",probe_items[i]->get_text()); printf("\n");
126         probe_list->update((ArrayList<BC_ListBoxItem*> *)&probe_items, 0, 0, 1,
127                 probe_list->get_xposition(), probe_list->get_yposition(),
128                 probe_list->get_highlighted_item(), 1, 0);
129         probe_list->center_selection();
130         return 1;
131 }
132
133 ProbeUpButton::ProbeUpButton(ProbeEditWindow *pb_window, int x, int y)
134  : BC_GenericButton(x, y, _("Up"))
135 {
136         this->pb_window = pb_window;
137 }
138
139 ProbeUpButton::~ProbeUpButton()
140 {
141 }
142
143 int ProbeUpButton::handle_event()
144 {
145         ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
146         int n = probe_items.size();
147         if( n > 1 ) {
148                 ProbePrefItem **pitem = &probe_items[0], *item0 = *pitem;
149                 for( int i=1; i<n; ++i ) {
150                         ProbePrefItem *&item = probe_items[i];
151                         if( item->get_selected() ) {
152                                 ProbePrefItem *t = item;  item = *pitem; *pitem = t;
153                         }
154                         pitem = &item;
155                 }
156                 if( item0->get_selected() ) {
157                         ProbePrefItem *t = *pitem;  *pitem = item0;  probe_items[0] = t;
158                 }
159         }
160         pb_window->list_update();
161         return 1;
162 }
163
164 ProbeDownButton::ProbeDownButton(ProbeEditWindow *pb_window, int x, int y)
165  : BC_GenericButton(x, y, _("Down"))
166 {
167         this->pb_window = pb_window;
168 }
169
170 ProbeDownButton::~ProbeDownButton()
171 {
172 }
173
174 ProbeEnabled::ProbeEnabled(ProbeEditWindow *pb_window, int x, int y)
175  : BC_CheckBox(x, y, 0, _("Enabled"))
176 {
177         this->pb_window = pb_window;
178 }
179 ProbeEnabled::~ProbeEnabled()
180 {
181 }
182
183 int ProbeEnabled::handle_event()
184 {
185         ProbePrefItem *item = (ProbePrefItem *)pb_window->probe_list->get_selection(0,0);
186         if( item ) {
187                 item->set_armed(get_value());
188                 pb_window->list_update();
189         }
190         return 1;
191 }
192
193 int ProbeDownButton::handle_event()
194 {
195         ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
196         int n = probe_items.size();
197         if( n > 1 ) {
198                 ProbePrefItem **pitem = &probe_items[n-1], *item1 = *pitem;
199                 for( int i=n-1; --i>=0; ) {
200                         ProbePrefItem *&item = probe_items[i];
201                         if( item->get_selected() ) {
202                                 ProbePrefItem *t = item;  item = *pitem; *pitem = t;
203                         }
204                         pitem = &item;
205                 }
206                 if( item1->get_selected() ) {
207                         ProbePrefItem *t = *pitem;  *pitem = item1;  probe_items[n-1] = t;
208                 }
209         }
210         pb_window->list_update();
211         return 1;
212 }
213
214 ProbePrefItem::ProbePrefItem(ProbeEditWindow *pb_window, ProbePref *pref)
215  : BC_ListBoxItem(pref->name, pref->armed ?
216                 pb_window->pb_enabled : pb_window->pb_disabled)
217 {
218         this->pb_window = pb_window;
219         this->armed = pref->armed;
220 }
221
222 ProbePrefItem::~ProbePrefItem()
223 {
224 }
225
226 void ProbePrefItem::set_armed(int armed)
227 {
228         this->armed = armed;
229         set_icon(armed ? pb_window->pb_enabled : pb_window->pb_disabled);
230 }
231
232 ProbePrefList::ProbePrefList(ProbeEditWindow *pb_window, int x, int y)
233  : BC_ListBox(x, y, pb_window->get_w()-x-10, pb_window->get_h()-y-80, LISTBOX_ICON_LIST,
234         (ArrayList<BC_ListBoxItem *>*) &pb_window->probe_items, 0, 0)
235 {
236         this->pb_window = pb_window;
237 }
238
239 ProbePrefList::~ProbePrefList()
240 {
241 }
242
243 int ProbePrefList::selection_changed()
244 {
245         ProbePrefItem *item = (ProbePrefItem *)pb_window->probe_list->get_selection(0,0);
246         if( item ) {
247                 pb_window->probe_enabled->set_value(item->armed);
248                 pb_window->probe_enabled->enable();
249         }
250         else {
251                 pb_window->probe_enabled->set_value(0);
252                 pb_window->probe_enabled->disable();
253         }
254         pb_window->list_update();
255         return 1;
256 }
257
258 int ProbePrefList::handle_event()
259 {
260         if( get_double_click() && get_buttonpress() == 1 ) {
261                 ProbePrefItem *item = (ProbePrefItem *)get_selection(0,0);
262                 int armed = item->armed ? 0 : 1;
263                 pb_window->probe_enabled->enable();
264                 pb_window->probe_enabled->set_value(armed);
265                 item->set_armed(armed);
266                 pb_window->list_update();
267         }
268         return 1;
269 }
270