remove auto kfrm for gang, btn2 select kfrm pos
[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
29 // Must match macros
30 static const char *mode_text[] =
31 {
32         N_("Insert nothing"),
33         N_("Replace current project"),
34         N_("Replace current project and concatenate tracks"),
35         N_("Append in new tracks"),
36         N_("Concatenate to existing tracks"),
37         N_("Paste at insertion point"),
38         N_("Create new resources only"),
39         N_("Nest sequence")
40 };
41
42
43 LoadModeItem::LoadModeItem(const char *text, int value)
44  : BC_ListBoxItem(text)
45 {
46         this->value = value;
47 }
48
49
50 LoadMode::LoadMode(MWindow *mwindow, BC_WindowBase *window,
51         int x, int y, int *output, int use_nothing)
52 {
53         this->mwindow = mwindow;
54         this->window = window;
55         this->x = x;
56         this->y = y;
57         this->output = output;
58         this->use_nothing = use_nothing;
59         int mode = LOADMODE_NOTHING;
60         if(use_nothing)
61                 load_modes.append(new LoadModeItem(_(mode_text[mode]), mode));
62         while( ++mode < TOTAL_LOADMODES )
63                 load_modes.append(new LoadModeItem(_(mode_text[mode]), mode));
64 }
65
66 LoadMode::~LoadMode()
67 {
68         delete title;
69         delete textbox;
70         delete listbox;
71         for(int i = 0; i < load_modes.total; i++)
72                 delete load_modes.values[i];
73 }
74
75 int LoadMode::calculate_w(BC_WindowBase *gui, Theme *theme)
76 {
77         return theme->loadmode_w + 24;
78 }
79
80 int LoadMode::calculate_h(BC_WindowBase *gui, Theme *theme)
81 {
82         return BC_Title::calculate_h(gui, _("Insertion strategy:"), MEDIUMFONT) +
83                 BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
84 }
85
86 char* LoadMode::mode_to_text()
87 {
88         for(int i = 0; i < load_modes.total; i++)
89         {
90                 if(load_modes.values[i]->value == *output)
91                         return load_modes.values[i]->get_text();
92         }
93         return _("Unknown");
94 }
95
96 int LoadMode::create_objects()
97 {
98         int x = this->x, y = this->y;
99         char *default_text;
100         default_text = mode_to_text();
101
102         window->add_subwindow(title = new BC_Title(x, y, _("Insertion strategy:")));
103         y += title->get_h();
104         window->add_subwindow(textbox = new BC_TextBox(x, y,
105                 mwindow->theme->loadmode_w, 1, default_text));
106         x += textbox->get_w();
107         window->add_subwindow(listbox = new LoadModeListBox(window, this, x, y));
108
109         return 0;
110 }
111
112 int LoadMode::get_h()
113 {
114         int result = 0;
115         result = MAX(result, title->get_h());
116         result = MAX(result, textbox->get_h());
117         return result;
118 }
119
120 int LoadMode::get_x()
121 {
122         return x;
123 }
124
125 int LoadMode::get_y()
126 {
127         return y;
128 }
129
130 int LoadMode::reposition_window(int x, int y)
131 {
132         this->x = x;
133         this->y = y;
134         title->reposition_window(x, y);
135         y += 20;
136         textbox->reposition_window(x, y);
137         x += textbox->get_w();
138         listbox->reposition_window(x,
139                 y,
140                 mwindow->theme->loadmode_w);
141         return 0;
142 }
143
144
145 LoadModeListBox::LoadModeListBox(BC_WindowBase *window,
146         LoadMode *loadmode,
147         int x,
148         int y)
149  : BC_ListBox(x,
150         y,
151         loadmode->mwindow->theme->loadmode_w,
152         150,
153         LISTBOX_TEXT,
154         (ArrayList<BC_ListBoxItem *>*)&loadmode->load_modes,
155         0,
156         0,
157         1,
158         0,
159         1)
160 {
161         this->window = window;
162         this->loadmode = loadmode;
163 }
164
165 LoadModeListBox::~LoadModeListBox()
166 {
167 }
168
169 int LoadModeListBox::handle_event()
170 {
171         LoadModeItem *item = (LoadModeItem *)get_selection(0, 0);
172         if( item ) {
173                 loadmode->textbox->update(item->get_text());
174                 *(loadmode->output) = item->value;
175         }
176         return 1;
177 }
178
179
180
181
182