rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / menuattachtransition.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 "datatype.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "language.h"
26 #include "mainsession.h"
27 #include "menuattachtransition.h"
28 #include "mwindow.h"
29 #include "mwindowgui.h"
30 #include "plugindialog.h"
31 #include "pluginserver.h"
32
33
34
35 #include <string.h>
36
37
38
39 MenuAttachTransition::MenuAttachTransition(MWindow *mwindow, int data_type)
40  : BC_MenuItem(_("Attach Transition..."))
41 {
42         this->mwindow = mwindow;
43         this->data_type = data_type;
44         thread = new TransitionDialogThread(mwindow, data_type);
45 }
46
47 MenuAttachTransition::~MenuAttachTransition()
48 {
49         delete thread;
50 }
51
52 int MenuAttachTransition::handle_event()
53 {
54         thread->start();
55         return 1;
56 }
57
58
59 TransitionDialogThread::TransitionDialogThread(MWindow *mwindow, int data_type)
60  : BC_DialogThread()
61 {
62         this->mwindow = mwindow;
63         this->data_type = data_type;
64         this->number = -1;
65 }
66
67 TransitionDialogThread::~TransitionDialogThread()
68 {
69         close_window();
70 }
71
72 void TransitionDialogThread::start()
73 {
74         if(!transition_names.total)
75         {
76                 strcpy(transition_title, data_type == TRACK_AUDIO ?
77                         mwindow->edl->session->default_atransition :
78                         mwindow->edl->session->default_vtransition);
79
80 // Construct listbox names
81                 ArrayList<PluginServer*> plugindb;
82                 mwindow->search_plugindb(data_type == TRACK_AUDIO,
83                         data_type == TRACK_VIDEO, 0, 1, 0, plugindb);
84                 for(int i = 0; i < plugindb.total; i++) {
85                         const char *title = plugindb.values[i]->title;
86                         if( !strcmp(transition_title, title) ) number = i;
87                         transition_names.append(new BC_ListBoxItem(_(title)));
88                 }
89         }
90
91         mwindow->gui->unlock_window();
92         BC_DialogThread::start();
93         mwindow->gui->lock_window("TransitionDialogThread::start");
94 }
95
96
97
98 BC_Window* TransitionDialogThread::new_gui()
99 {
100         mwindow->gui->lock_window("TransitionDialogThread::new_gui");
101         int x = mwindow->gui->get_abs_cursor_x(0) -
102                 mwindow->session->transitiondialog_w / 2;
103         int y = mwindow->gui->get_abs_cursor_y(0) -
104                 mwindow->session->transitiondialog_h / 2;
105         TransitionDialog *window = new TransitionDialog(mwindow, this, x, y);
106         window->create_objects();
107         mwindow->gui->unlock_window();
108         return window;
109 }
110
111 void TransitionDialogThread::handle_close_event(int result)
112 {
113         if(!result)
114         {
115                 mwindow->paste_transitions(data_type, transition_title);
116         }
117 }
118
119
120
121 TransitionDialog::TransitionDialog(MWindow *mwindow,
122         TransitionDialogThread *thread, int x, int y)
123  : BC_Window(_("Attach Transition"), x, y,
124         mwindow->session->transitiondialog_w,
125         mwindow->session->transitiondialog_h,
126         320, 240, 1, 0, 1)
127 {
128         this->mwindow = mwindow;
129         this->thread = thread;
130 }
131
132 TransitionSetDefault::TransitionSetDefault(TransitionDialog *window, int x, int y)
133  : BC_GenericButton(x, y, _("Set Default Transition"))
134 {
135         this->window = window;
136 }
137
138 TransitionSetDefault::~TransitionSetDefault()
139 {
140 }
141
142 int TransitionSetDefault::handle_event()
143 {
144         TransitionDialogThread *thread = (TransitionDialogThread *)window->thread;
145         const char *transition_title = thread->transition_title;
146         EDL *edl = window->mwindow->edl;
147         switch( thread->data_type ) {
148         case TRACK_AUDIO:
149                 strcpy(edl->session->default_atransition, transition_title);
150                 break;
151         case TRACK_VIDEO:
152                 strcpy(edl->session->default_vtransition, transition_title);
153                 break;
154         }
155         window->set_default_text->update(transition_title);
156         return 1;
157 }
158
159 TransitionDefaultText::TransitionDefaultText(TransitionDialog *window,
160         int x, int y, int w, const char * text)
161  : BC_TextBox(x, y, w, 1, text)
162 {
163         this->window = window;
164 }
165
166 TransitionDefaultText::~TransitionDefaultText()
167 {
168 }
169
170
171 void TransitionDialog::create_objects()
172 {
173         int x = 10;
174         int y = 10;
175
176         lock_window("TransitionDialog::create_objects");
177         add_subwindow(name_title = new BC_Title(x, y, _("Select transition from list")));
178         y += name_title->get_h() + 5;
179         add_subwindow(name_list = new TransitionDialogName(thread,
180                 &thread->transition_names,
181                 x,
182                 y,
183                 get_w() - x - x,
184                 get_h() - y - BC_OKButton::calculate_h() - 100));
185         y += name_list->get_h() + 20;
186         add_subwindow(set_default = new TransitionSetDefault(this, x, y));
187         y += set_default->get_h() + 10;
188         const char *default_transition = "";
189         EDL *edl = mwindow->edl;
190         switch( thread->data_type ) {
191         case TRACK_AUDIO:
192                 default_transition = edl->session->default_atransition;
193                 break;
194         case TRACK_VIDEO:
195                 default_transition = edl->session->default_vtransition;
196                 break;
197         }
198         add_subwindow(set_default_text = new TransitionDefaultText(this, x, y,
199                         get_w()-x-20, default_transition));
200         if( thread->number >= 0 ) {
201                 name_list->update_selection(&thread->transition_names, thread->number, 0);
202                 name_list->draw_items(0);
203         }
204         add_subwindow(new BC_OKButton(this));
205         add_subwindow(new BC_CancelButton(this));
206         show_window();
207         unlock_window();
208 }
209
210
211 int TransitionDialog::resize_event(int w, int h)
212 {
213         int x = 10;
214         int y = 10;
215
216         name_title->reposition_window(x, y);
217         y += name_title->get_h() + 5;
218         name_list->reposition_window(x, y,
219                 w - x - x, h - y - BC_OKButton::calculate_h() - 100);
220         y += name_list->get_h() + 20;
221         set_default->reposition_window(x, y);
222         y += set_default->get_h() + 10;
223         set_default_text->reposition_window(x, y, get_w()-x-20);
224         return 1;
225 }
226
227
228
229 TransitionDialogName::TransitionDialogName(TransitionDialogThread *thread,
230         ArrayList<BC_ListBoxItem*> *standalone_data, int x, int y, int w, int h)
231  : BC_ListBox(x,
232         y,
233         w,
234         h,
235         LISTBOX_TEXT,
236         standalone_data)
237 {
238         this->thread = thread;
239 }
240
241 int TransitionDialogName::handle_event()
242 {
243         set_done(0);
244         return 1;
245 }
246
247 int TransitionDialogName::selection_changed()
248 {
249         thread->number = get_selection_number(0, 0);
250         strcpy(thread->transition_title,
251                 thread->transition_names.values[thread->number]->get_text());
252         return 1;
253 }
254
255
256
257