initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 }
65
66 void TransitionDialogThread::start()
67 {
68         if(!transition_names.total)
69         {
70 // Construct listbox names      
71                 ArrayList<PluginServer*> plugindb;
72                 mwindow->search_plugindb(data_type == TRACK_AUDIO, 
73                         data_type == TRACK_VIDEO, 
74                         0, 
75                         1,
76                         0,
77                         plugindb);
78                 for(int i = 0; i < plugindb.total; i++)
79                         transition_names.append(new BC_ListBoxItem(_(plugindb.values[i]->title)));
80         }
81
82         if(data_type == TRACK_AUDIO)
83                 strcpy(transition_title, mwindow->edl->session->default_atransition);
84         else
85                 strcpy(transition_title, mwindow->edl->session->default_vtransition);
86
87         mwindow->gui->unlock_window();
88         BC_DialogThread::start();
89         mwindow->gui->lock_window("TransitionDialogThread::start");
90 }
91
92
93
94 BC_Window* TransitionDialogThread::new_gui()
95 {
96         mwindow->gui->lock_window("TransitionDialogThread::new_gui");
97         int x = mwindow->gui->get_abs_cursor_x(0) -
98                 mwindow->session->transitiondialog_w / 2;
99         int y = mwindow->gui->get_abs_cursor_y(0) -
100                 mwindow->session->transitiondialog_h / 2;
101         TransitionDialog *window = new TransitionDialog(mwindow, 
102                 this,
103                 x, 
104                 y);
105         window->create_objects();
106         mwindow->gui->unlock_window();
107         return window;
108 }
109
110 void TransitionDialogThread::handle_close_event(int result)
111 {
112         if(!result)
113         {
114                 mwindow->paste_transitions(data_type, transition_title);
115         }
116 }
117
118
119
120 TransitionDialog::TransitionDialog(MWindow *mwindow, 
121         TransitionDialogThread *thread,
122         int x,
123         int y)
124  : BC_Window(_("Attach Transition"), 
125         x,
126         y,
127         mwindow->session->transitiondialog_w,
128         mwindow->session->transitiondialog_h, 
129         320, 
130         240,
131         1,
132         0,
133         1)
134 {
135         this->mwindow = mwindow;
136         this->thread = thread;
137 }
138
139 void TransitionDialog::create_objects()
140 {
141         int x = 10;
142         int y = 10;
143         
144         lock_window("TransitionDialog::create_objects");
145         add_subwindow(name_title = new BC_Title(x, y, _("Select transition from list")));
146         y += name_title->get_h() + 5;
147         add_subwindow(name_list = new TransitionDialogName(thread, 
148                 &thread->transition_names, 
149                 x, 
150                 y,
151                 get_w() - x - x,
152                 get_h() - y - BC_OKButton::calculate_h() - 10));
153         add_subwindow(new BC_OKButton(this));
154         add_subwindow(new BC_CancelButton(this));
155         show_window();
156         flush();
157         unlock_window();
158 }
159
160
161 int TransitionDialog::resize_event(int w, int h)
162 {
163         int x = 10;
164         int y = 10;
165
166         name_title->reposition_window(x, y);
167         y += name_title->get_h() + 5;
168         name_list->reposition_window(x, 
169                 y,
170                 w - x - x,
171                 h - y - BC_OKButton::calculate_h() - 10);
172
173         return 1;
174 }
175
176
177
178 TransitionDialogName::TransitionDialogName(TransitionDialogThread *thread, 
179         ArrayList<BC_ListBoxItem*> *standalone_data, 
180         int x,
181         int y, 
182         int w, 
183         int h)
184  : BC_ListBox(x, 
185         y, 
186         w, 
187         h, 
188         LISTBOX_TEXT,
189         standalone_data)
190 {
191         this->thread = thread;
192 }
193
194 int TransitionDialogName::handle_event()
195 {
196         set_done(0);
197         return 1;
198 }
199
200 int TransitionDialogName::selection_changed()
201 {
202         int number = get_selection_number(0, 0);
203         strcpy(thread->transition_title, 
204                 thread->transition_names.values[number]->get_text());
205         return 1;
206 }
207
208
209
210