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