4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
29 static const char *mode_images[] =
41 static const char *mode_text[] =
44 N_("Replace current project"),
45 N_("Replace current project and concatenate tracks"),
46 N_("Append in new tracks"),
47 N_("Concatenate to existing tracks"),
48 N_("Paste over selection/at insertion point"),
49 N_("Create new resources only"),
54 LoadModeItem::LoadModeItem(const char *text, int value)
55 : BC_ListBoxItem(text)
61 LoadModeToggle::LoadModeToggle(int x, int y, LoadMode *window,
62 int value, const char *images, const char *tooltip)
63 : BC_Toggle(x, y, window->mwindow->theme->get_image_set(images),
64 *window->output == value)
66 this->window = window;
71 int LoadModeToggle::handle_event()
73 *window->output = value;
80 LoadMode::LoadMode(MWindow *mwindow,
81 BC_WindowBase *window, int x, int y, int *output,
82 int use_nothing, int use_nested, int line_wrap)
84 this->mwindow = mwindow;
85 this->window = window;
88 this->output = output;
89 this->use_nothing = use_nothing;
90 this->use_nested = use_nested;
91 this->line_wrap = line_wrap;
92 for( int i=0; i<TOTAL_LOADMODES; ++i ) mode[i] = 0;
100 load_modes.remove_all_objects();
101 for( int i=0; i<TOTAL_LOADMODES; ++i ) delete mode[i];
104 const char *LoadMode::mode_to_text()
106 for( int i=0; i<load_modes.total; ++i ) {
107 if( load_modes[i]->value == *output )
108 return load_modes[i]->get_text();
113 void LoadMode::load_mode_geometry(BC_WindowBase *gui, Theme *theme,
114 int use_nothing, int use_nested, int line_wrap,
118 const char *title_text = _("Insertion strategy:");
119 int mw = BC_Title::calculate_w(gui, title_text);
120 int mh = BC_Title::calculate_h(gui, title_text);
121 int ix = mw + 2*pad, iy = 0, x1 = ix;
122 int ww = theme->loadmode_w + 24;
123 if( mw < ww ) mw = ww;
125 for( int i=0; i<TOTAL_LOADMODES; ++i ) {
126 if( i == LOADMODE_NOTHING && !use_nothing) continue;
127 if( i == LOADMODE_NESTED && !use_nested) continue;
128 int text_line, w, h, toggle_x, toggle_y;
129 int text_x, text_y, text_w, text_h;
130 BC_Toggle::calculate_extents(gui,
131 theme->get_image_set(mode_images[i]), 0,
132 &text_line, &w, &h, &toggle_x, &toggle_y,
133 &text_x, &text_y, &text_w, &text_h, 0, MEDIUMFONT);
134 if( line_wrap && ix+w > ww ) { ix = x1; iy += h+pad; }
135 if( (ix+=w) > mw ) mw = ix;
136 if( (h+=iy) > mh ) mh = h;
141 mh = iy + BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
146 int LoadMode::calculate_w(BC_WindowBase *gui, Theme *theme,
147 int use_nothing, int use_nested, int line_wrap)
150 load_mode_geometry(gui, theme, use_nothing, use_nested, line_wrap,
155 int LoadMode::calculate_h(BC_WindowBase *gui, Theme *theme,
156 int use_nothing, int use_nested, int line_wrap)
159 load_mode_geometry(gui, theme, use_nothing, use_nested, line_wrap,
164 void LoadMode::create_objects()
167 const char *title_text = _("Insertion strategy:");
168 window->add_subwindow(title = new BC_Title(x, y, title_text));
169 int mw = title->get_w(), mh = title->get_h();
170 int ix = mw + 2*pad, iy = 0, x1 = ix;
171 int ww = mwindow->theme->loadmode_w + 24;
172 if( mw < ww ) mw = ww;
174 for( int i=0; i<TOTAL_LOADMODES; ++i ) {
175 if( i == LOADMODE_NOTHING && !use_nothing) continue;
176 if( i == LOADMODE_NESTED && !use_nested) continue;
177 load_modes.append(new LoadModeItem(_(mode_text[i]), i));
178 int text_line, w, h, toggle_x, toggle_y;
179 int text_x, text_y, text_w, text_h;
180 BC_Toggle::calculate_extents(window,
181 mwindow->theme->get_image_set(mode_images[i]), 0,
182 &text_line, &w, &h, &toggle_x, &toggle_y,
183 &text_x, &text_y, &text_w, &text_h, 0, MEDIUMFONT);
184 if( line_wrap && ix+w > ww ) { ix = x1; iy += h+pad; }
185 mode[i] = new LoadModeToggle(x+ix, y+iy, this,
186 i, mode_images[i], _(mode_text[i]));
187 window->add_subwindow(mode[i]);
188 if( (ix+=w) > mw ) mw = ix;
189 if( (h+=iy) > mh ) mh = h;
194 const char *mode_text = mode_to_text();
195 textbox = new BC_TextBox(x+ix, y+iy,
196 mwindow->theme->loadmode_w, 1, mode_text);
197 window->add_subwindow(textbox);
198 ix += textbox->get_w();
199 listbox = new LoadModeListBox(window, this, x+ix, y+iy);
200 window->add_subwindow(listbox);
201 mh = iy + textbox->get_h();
204 int LoadMode::reposition_window(int x, int y)
206 this->x = x; this->y = y;
207 title->reposition_window(x, y);
208 int mw = title->get_w(), mh = title->get_h();
210 int ix = mw + 2*pad, iy = 0, x1 = ix;
211 int ww = mwindow->theme->loadmode_w + 24;
212 if( mw < ww ) mw = ww;
214 for( int i=0; i<TOTAL_LOADMODES; ++i ) {
215 if( i == LOADMODE_NOTHING && !use_nothing) continue;
216 if( i == LOADMODE_NESTED && !use_nested) continue;
217 int text_line, w, h, toggle_x, toggle_y;
218 int text_x, text_y, text_w, text_h;
219 BC_Toggle::calculate_extents(window,
220 mwindow->theme->get_image_set(mode_images[i]), 0,
221 &text_line, &w, &h, &toggle_x, &toggle_y,
222 &text_x, &text_y, &text_w, &text_h, 0, MEDIUMFONT);
223 if( line_wrap && ix+w > ww ) { ix = x1; iy += h+pad; }
224 mode[i]->reposition_window(x+ix, y+iy);
225 if( (ix+=w) > mw ) mw = ix;
226 if( (h+=iy) > mh ) mh = h;
231 textbox->reposition_window(x+ix, y+iy);
232 ix += textbox->get_w();
233 listbox->reposition_window(x+ix, y+iy);
237 int LoadMode::get_h()
240 load_mode_geometry(window, mwindow->theme,
241 use_nothing, use_nested, line_wrap, 0, &result);
245 int LoadMode::get_x()
250 int LoadMode::get_y()
255 void LoadMode::update()
257 for( int i=0; i<TOTAL_LOADMODES; ++i ) {
258 if( !mode[i] ) continue;
259 mode[i]->set_value(*output == i);
261 textbox->update(mode_to_text());
264 int LoadMode::set_line_wrap(int v)
271 LoadModeListBox::LoadModeListBox(BC_WindowBase *window, LoadMode *loadmode,
273 : BC_ListBox(x, y, loadmode->mwindow->theme->loadmode_w, 150, LISTBOX_TEXT,
274 (ArrayList<BC_ListBoxItem *>*)&loadmode->load_modes, 0, 0, 1, 0, 1)
276 this->window = window;
277 this->loadmode = loadmode;
280 LoadModeListBox::~LoadModeListBox()
284 int LoadModeListBox::handle_event()
286 LoadModeItem *item = (LoadModeItem *)get_selection(0, 0);
288 *(loadmode->output) = item->value;