tweak zoom/fullscr to remember cwdw scale after fullscr
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / loadmode.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 "clip.h"
23 #include "language.h"
24 #include "loadmode.h"
25 #include "mwindow.h"
26 #include "theme.h"
27
28 // Must match macros
29 static const char *mode_images[] =
30 {
31         "loadmode_none",
32         "loadmode_new",
33         "loadmode_newcat",
34         "loadmode_newtracks",
35         "loadmode_cat",
36         "loadmode_paste",
37         "loadmode_resource",
38         "loadmode_nested"
39 };
40
41 static const char *mode_text[] =
42 {
43         N_("Insert nothing"),
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"),
50         N_("Nest sequence")
51 };
52
53
54 LoadModeItem::LoadModeItem(const char *text, int value)
55  : BC_ListBoxItem(text)
56 {
57         this->value = value;
58 }
59
60
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)
65 {
66         this->window = window;
67         this->value = value;
68         set_tooltip(tooltip);
69 }
70
71 int LoadModeToggle::handle_event()
72 {
73         *window->output = value;
74         window->update();
75         return 1;
76 }
77
78
79
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)
83 {
84         this->mwindow = mwindow;
85         this->window = window;
86         this->x = x;
87         this->y = y;
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;
93 }
94
95 LoadMode::~LoadMode()
96 {
97         delete title;
98         delete textbox;
99         delete listbox;
100         load_modes.remove_all_objects();
101         for( int i=0; i<TOTAL_LOADMODES; ++i ) delete mode[i];
102 }
103
104 const char *LoadMode::mode_to_text()
105 {
106         for( int i=0; i<load_modes.total; ++i ) {
107                 if( load_modes[i]->value == *output )
108                         return load_modes[i]->get_text();
109         }
110         return _("Unknown");
111 }
112
113 void LoadMode::load_mode_geometry(BC_WindowBase *gui, Theme *theme,
114                 int use_nothing, int use_nested, int line_wrap,
115                 int *pw, int *ph)
116 {
117         int pad = 5;
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;
124
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;
137                 ix += pad;
138         }
139
140         ix = 0;  iy = mh+pad;
141         mh = iy + BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
142         if( pw ) *pw = mw;
143         if( ph ) *ph = mh;
144 }
145
146 int LoadMode::calculate_w(BC_WindowBase *gui, Theme *theme,
147                 int use_nothing, int use_nested, int line_wrap)
148 {
149         int result = 0;
150         load_mode_geometry(gui, theme, use_nothing, use_nested, line_wrap,
151                         &result, 0);
152         return result;
153 }
154
155 int LoadMode::calculate_h(BC_WindowBase *gui, Theme *theme,
156                 int use_nothing, int use_nested, int line_wrap)
157 {
158         int result = 0;
159         load_mode_geometry(gui, theme, use_nothing, use_nested, line_wrap,
160                         0, &result);
161         return result;
162 }
163
164 void LoadMode::create_objects()
165 {
166         int pad = 5;
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;
173
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;
190                 ix += pad;
191         }
192
193         ix = 0;  iy = mh+pad;
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();
202 }
203
204 int LoadMode::reposition_window(int x, int y)
205 {
206         this->x = x;  this->y = y;
207         title->reposition_window(x, y);
208         int mw = title->get_w(), mh = title->get_h();
209         int pad = 5;
210         int ix = mw + 2*pad, iy = 0, x1 = ix;
211         int ww = mwindow->theme->loadmode_w + 24;
212         if( mw < ww ) mw = ww;
213
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;
227                 ix += pad;
228         }
229
230         ix = 0;  iy = mh+pad;
231         textbox->reposition_window(x+ix, y+iy);
232         ix += textbox->get_w();
233         listbox->reposition_window(x+ix, y+iy);
234         return 0;
235 }
236
237 int LoadMode::get_h()
238 {
239         int result = 0;
240         load_mode_geometry(window, mwindow->theme,
241                         use_nothing, use_nested, line_wrap, 0, &result);
242         return result;
243 }
244
245 int LoadMode::get_x()
246 {
247         return x;
248 }
249
250 int LoadMode::get_y()
251 {
252         return y;
253 }
254
255 void LoadMode::update()
256 {
257         for( int i=0; i<TOTAL_LOADMODES; ++i ) {
258                 if( !mode[i] ) continue;
259                 mode[i]->set_value(*output == i);
260         }
261         textbox->update(mode_to_text());
262 }
263
264 int LoadMode::set_line_wrap(int v)
265 {
266         int ret = line_wrap;
267         line_wrap = v;
268         return ret;
269 }
270
271 LoadModeListBox::LoadModeListBox(BC_WindowBase *window, LoadMode *loadmode,
272                 int x, int y)
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)
275 {
276         this->window = window;
277         this->loadmode = loadmode;
278 }
279
280 LoadModeListBox::~LoadModeListBox()
281 {
282 }
283
284 int LoadModeListBox::handle_event()
285 {
286         LoadModeItem *item = (LoadModeItem *)get_selection(0, 0);
287         if( item ) {
288                 *(loadmode->output) = item->value;
289                 loadmode->update();
290         }
291         return 1;
292 }
293