3 * Copyright (C) 2016-2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #include "bcwindowbase.h"
22 #include "bcdisplayinfo.h"
25 #include "mainerror.h"
27 #include "probeprefs.h"
28 #include "preferences.h"
29 #include "preferencesthread.h"
34 ProbePref::ProbePref(const char *nm, int armed)
36 strncpy(name, nm, sizeof(name));
40 ProbePref::~ProbePref()
44 FileProbeDialog::FileProbeDialog(PreferencesWindow *pwindow)
47 this->pwindow = pwindow;
50 FileProbeDialog::~FileProbeDialog()
55 BC_Window* FileProbeDialog::new_gui()
57 BC_DisplayInfo display_info;
58 int x = display_info.get_abs_cursor_x();
59 int y = display_info.get_abs_cursor_y();
61 pb_window = new ProbeEditWindow(this, x, y);
62 pb_window->create_objects();
66 void FileProbeDialog::handle_close_event(int result)
72 ProbeEditWindow::ProbeEditWindow(FileProbeDialog *pb_dialog, int x, int y)
73 : BC_Window(_(PROGRAM_NAME ": Probes"), x, y, xS(300), yS(200), xS(300), yS(200), 0, 0, 1)
75 this->pb_dialog = pb_dialog;
78 probe_down_button = 0;
82 // *** CONTEXT_HELP ***
83 context_help_set_keyword("Probe Order when Loading Media");
86 ProbeEditWindow::~ProbeEditWindow()
92 void ProbeEditWindow::create_objects()
94 int xs10 = xS(10), ys10 = yS(10);
95 lock_window("ProbeEditWindow::create_objects");
96 pb_enabled = new BC_Pixmap(this,
97 BC_WindowBase::get_resources()->listbox_up,
99 pb_disabled = new BC_Pixmap(this,
100 BC_WindowBase::get_resources()->listbox_dn,
102 Preferences *preferences = pb_dialog->pwindow->thread->preferences;
103 for( int i=0; i<preferences->file_probes.size(); ++i ) {
104 probe_items.append(new ProbePrefItem(this, preferences->file_probes[i]));
106 int x = xs10, y = ys10;
107 add_subwindow(probe_list = new ProbePrefList(this, x, y));
108 y += probe_list->get_h();
110 add_subwindow(probe_up_button = new ProbeUpButton(this, x1, y1));
111 x1 += probe_up_button->get_w() + xs10;
112 add_subwindow(probe_down_button = new ProbeDownButton(this, x1, y1));
113 x1 += probe_down_button->get_w() + xs10;
114 add_subwindow(probe_enabled = new ProbeEnabled(this, x1, y1));
115 probe_enabled->disable();
117 add_subwindow(new ProbeEditOK(this));
118 add_subwindow(new BC_CancelButton(this));
125 ProbeEditOK::ProbeEditOK(ProbeEditWindow *pb_window)
126 : BC_OKButton(pb_window)
128 this->pb_window = pb_window;
131 ProbeEditOK::~ProbeEditOK()
135 int ProbeEditOK::handle_event()
137 Preferences *preferences = pb_window->pb_dialog->pwindow->thread->preferences;
138 ArrayList<ProbePref *> &file_probes = preferences->file_probes;
139 file_probes.remove_all_objects();
140 ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
141 for( int i=0; i<probe_items.size(); ++i ) {
142 ProbePrefItem *item = probe_items[i];
143 file_probes.append(new ProbePref(item->get_text(), item->armed));
145 return BC_OKButton::handle_event();
148 int ProbeEditWindow::list_update()
150 //for( int i=0; i<probe_items.size(); ++i ) printf("%s, ",probe_items[i]->get_text()); printf("\n");
151 probe_list->update((ArrayList<BC_ListBoxItem*> *)&probe_items, 0, 0, 1,
152 probe_list->get_xposition(), probe_list->get_yposition(),
153 probe_list->get_highlighted_item(), 1, 0);
154 probe_list->center_selection();
158 ProbeUpButton::ProbeUpButton(ProbeEditWindow *pb_window, int x, int y)
159 : BC_GenericButton(x, y, _("Up"))
161 this->pb_window = pb_window;
164 ProbeUpButton::~ProbeUpButton()
168 int ProbeUpButton::handle_event()
170 ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
171 int n = probe_items.size();
173 ProbePrefItem **pitem = &probe_items[0], *item0 = *pitem;
174 for( int i=1; i<n; ++i ) {
175 ProbePrefItem *&item = probe_items[i];
176 if( item->get_selected() ) {
177 ProbePrefItem *t = item; item = *pitem; *pitem = t;
181 if( item0->get_selected() ) {
182 ProbePrefItem *t = *pitem; *pitem = item0; probe_items[0] = t;
185 pb_window->list_update();
189 ProbeDownButton::ProbeDownButton(ProbeEditWindow *pb_window, int x, int y)
190 : BC_GenericButton(x, y, _("Down"))
192 this->pb_window = pb_window;
195 ProbeDownButton::~ProbeDownButton()
199 ProbeEnabled::ProbeEnabled(ProbeEditWindow *pb_window, int x, int y)
200 : BC_CheckBox(x, y, 0, _("Enabled"))
202 this->pb_window = pb_window;
204 ProbeEnabled::~ProbeEnabled()
208 int ProbeEnabled::handle_event()
210 ProbePrefItem *item = (ProbePrefItem *)pb_window->probe_list->get_selection(0,0);
212 item->set_armed(get_value());
213 pb_window->list_update();
218 int ProbeDownButton::handle_event()
220 ArrayList<ProbePrefItem *> &probe_items = pb_window->probe_items;
221 int n = probe_items.size();
223 ProbePrefItem **pitem = &probe_items[n-1], *item1 = *pitem;
224 for( int i=n-1; --i>=0; ) {
225 ProbePrefItem *&item = probe_items[i];
226 if( item->get_selected() ) {
227 ProbePrefItem *t = item; item = *pitem; *pitem = t;
231 if( item1->get_selected() ) {
232 ProbePrefItem *t = *pitem; *pitem = item1; probe_items[n-1] = t;
235 pb_window->list_update();
239 ProbePrefItem::ProbePrefItem(ProbeEditWindow *pb_window, ProbePref *pref)
240 : BC_ListBoxItem(pref->name, pref->armed ?
241 pb_window->pb_enabled : pb_window->pb_disabled)
243 this->pb_window = pb_window;
244 this->armed = pref->armed;
247 ProbePrefItem::~ProbePrefItem()
251 void ProbePrefItem::set_armed(int armed)
254 set_icon(armed ? pb_window->pb_enabled : pb_window->pb_disabled);
257 ProbePrefList::ProbePrefList(ProbeEditWindow *pb_window, int x, int y)
258 : BC_ListBox(x, y, pb_window->get_w()-x-xS(10), pb_window->get_h()-y-yS(80),
259 LISTBOX_ICON_LIST, (ArrayList<BC_ListBoxItem *>*) &pb_window->probe_items,
262 this->pb_window = pb_window;
265 ProbePrefList::~ProbePrefList()
269 int ProbePrefList::selection_changed()
271 ProbePrefItem *item = (ProbePrefItem *)pb_window->probe_list->get_selection(0,0);
273 pb_window->probe_enabled->set_value(item->armed);
274 pb_window->probe_enabled->enable();
277 pb_window->probe_enabled->set_value(0);
278 pb_window->probe_enabled->disable();
280 pb_window->list_update();
284 int ProbePrefList::handle_event()
286 if( get_double_click() && get_buttonpress() == 1 ) {
287 ProbePrefItem *item = (ProbePrefItem *)get_selection(0,0);
288 int armed = item->armed ? 0 : 1;
289 pb_window->probe_enabled->enable();
290 pb_window->probe_enabled->set_value(armed);
291 item->set_armed(armed);
292 pb_window->list_update();