initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / loadmode.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 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 static const char *tooltips[] = 
41 {
42         "Insert nothing",
43         "Replace current project",
44         "Replace current project and concatenate tracks",
45         "Append in new tracks",
46         "Concatenate to existing tracks",
47         "Paste at insertion point",
48         "Create new resources only",
49         "Nest sequence"
50 };
51
52
53
54
55 LoadMode::LoadMode(MWindow *mwindow,
56         BC_WindowBase *window, 
57         int x, 
58         int y, 
59         int *output, 
60         int use_nothing,
61         int use_nested)
62 {
63         this->mwindow = mwindow;
64         this->window = window;
65         this->x = x;
66         this->y = y;
67         this->output = output;
68         this->use_nothing = use_nothing;
69         this->use_nested = use_nested;
70         for(int i = 0; i < TOTAL_LOADMODES; i++)
71                 mode[i] = 0;
72 }
73
74 LoadMode::~LoadMode()
75 {
76         delete title;
77         for(int i = 0; i < TOTAL_LOADMODES; i++)
78                 if(mode[i]) delete mode[i];
79 }
80
81 int LoadMode::calculate_h(BC_WindowBase *gui, Theme *theme)
82 {
83         int text_line;
84         int w;
85         int h;
86         int toggle_x;
87         int toggle_y;
88         int text_x;
89         int text_y;
90         int text_w;
91         int text_h;
92         BC_Toggle::calculate_extents(gui, 
93                 theme->get_image_set(mode_images[0]),
94                 0,
95                 &text_line,
96                 &w,
97                 &h,
98                 &toggle_x,
99                 &toggle_y,
100                 &text_x,
101                 &text_y, 
102                 &text_w,
103                 &text_h, 
104                 0, MEDIUMFONT);
105         return h;
106 }
107
108 int LoadMode::calculate_w(BC_WindowBase *gui, 
109         Theme *theme, 
110         int use_none, 
111         int use_nested)
112 {
113         int total = gui->get_text_width(MEDIUMFONT, _("Insertion strategy:")) + 10;
114         for(int i = 0; i < TOTAL_LOADMODES; i++)
115         {
116                 if((i != LOADMODE_NOTHING || use_none) &&
117                         (i != LOADMODE_NESTED || use_nested))
118                 {
119                         int text_line;
120                         int w;
121                         int h;
122                         int toggle_x;
123                         int toggle_y;
124                         int text_x;
125                         int text_y;
126                         int text_w;
127                         int text_h;
128                         BC_Toggle::calculate_extents(gui, 
129                                 theme->get_image_set(mode_images[i]),
130                                 0,
131                                 &text_line,
132                                 &w,
133                                 &h,
134                                 &toggle_x,
135                                 &toggle_y,
136                                 &text_x,
137                                 &text_y, 
138                                 &text_w,
139                                 &text_h, 
140                                 0, MEDIUMFONT);
141                         total += w + 10;
142                 }
143         }
144         return total;
145 }
146
147 int LoadMode::get_h()
148 {
149         int result = 0;
150         result = MAX(result, title->get_h());
151         result = MAX(result, mode[1]->get_h());
152         return result;
153 }
154
155 void LoadMode::create_objects()
156 {
157         int x = this->x, y = this->y;
158
159         window->add_subwindow(title = new BC_Title(x, y, _("Insertion strategy:")));
160         x += title->get_w() + 10;
161         int x1 = x;
162         for(int i = 0; i < TOTAL_LOADMODES; i++)
163         {
164                 if((i != LOADMODE_NOTHING || use_nothing) &&
165                         (i != LOADMODE_NESTED || use_nested))
166                 {
167                         VFrame **images = mwindow->theme->get_image_set(mode_images[i]);
168                         if(x + images[0]->get_w() > window->get_w())
169                         {
170                                 x = x1;
171                                 y += images[0]->get_h() + 5;
172                         }
173                         window->add_subwindow(mode[i] = new LoadModeToggle(x, 
174                                 y, 
175                                 this, 
176                                 i, 
177                                 mode_images[i],
178                                 tooltips[i]));
179                         x += mode[i]->get_w() + 10;
180                 }
181         }
182
183
184 }
185
186 int LoadMode::get_x()
187 {
188         return x;
189 }
190
191 int LoadMode::get_y()
192 {
193         return y;
194 }
195
196 int LoadMode::reposition_window(int x, int y)
197 {
198         this->x = x;
199         this->y = y;
200         title->reposition_window(x, y);
201         x += title->get_w() + 10;
202         int x1 = x;
203         for(int i = 0; i < TOTAL_LOADMODES; i++)
204         {
205                 if(mode[i])
206                 {
207                         VFrame **images = mwindow->theme->get_image_set(mode_images[i]);
208                         if(x + images[0]->get_w() > window->get_w())
209                         {
210                                 x = x1;
211                                 y += images[0]->get_h() + 5;
212                         }
213                         mode[i]->reposition_window(x, y);
214                         x += mode[i]->get_w() + 10;
215                 }
216         }
217
218         return 0;
219 }
220
221 void LoadMode::update()
222 {
223         for(int i = 0; i < TOTAL_LOADMODES; i++)
224         {
225                 if(mode[i])
226                 {
227                         mode[i]->set_value(*output == i);
228                 }
229         }
230 }
231
232
233
234
235
236
237
238
239 LoadModeToggle::LoadModeToggle(int x, 
240         int y, 
241         LoadMode *window, 
242         int value, 
243         const char *images,
244         const char *tooltip)
245  : BC_Toggle(x, 
246         y, 
247         window->mwindow->theme->get_image_set(images),
248         *window->output == value)
249 {
250         this->window = window;
251         this->value = value;
252         set_tooltip(_(tooltip));
253 }
254
255 int LoadModeToggle::handle_event()
256 {
257         *window->output = value;
258         window->update();
259         return 1;
260 }
261
262