694c2d2a6101bfbbc148cf47514ddb52beefb9d2
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpopup.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 "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "editpopup.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "file.h"
31 #include "language.h"
32 #include "localsession.h"
33 #include "mainerror.h"
34 #include "mainsession.h"
35 #include "mwindow.h"
36 #include "mwindowgui.h"
37 #include "plugindialog.h"
38 #include "resizetrackthread.h"
39 #include "track.h"
40 #include "tracks.h"
41 #include "trackcanvas.h"
42
43 #include <string.h>
44
45 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
46  : BC_PopupMenu(0, 0, 0, "", 0)
47 {
48         this->mwindow = mwindow;
49         this->gui = gui;
50 }
51
52 EditPopup::~EditPopup()
53 {
54 }
55
56 void EditPopup::create_objects()
57 {
58         add_item(new EditAttachEffect(mwindow, this));
59         add_item(new EditMoveTrackUp(mwindow, this));
60         add_item(new EditMoveTrackDown(mwindow, this));
61         add_item(new EditPopupDeleteTrack(mwindow, this));
62         add_item(new EditPopupAddTrack(mwindow, this));
63 //      add_item(new EditPopupTitle(mwindow, this));
64         resize_option = 0;
65         matchsize_option = 0;
66 }
67
68 int EditPopup::update(Track *track, Edit *edit)
69 {
70         this->edit = edit;
71         this->track = track;
72
73         if(track->data_type == TRACK_VIDEO && !resize_option)
74         {
75                 add_item(resize_option = new EditPopupResize(mwindow, this));
76                 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
77         }
78         else
79         if(track->data_type == TRACK_AUDIO && resize_option)
80         {
81                 del_item(resize_option);     resize_option = 0;
82                 del_item(matchsize_option);  matchsize_option = 0;
83         }
84         return 0;
85 }
86
87
88
89
90
91
92
93
94
95 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
96  : BC_MenuItem(_("Attach effect..."))
97 {
98         this->mwindow = mwindow;
99         this->popup = popup;
100         dialog_thread = new PluginDialogThread(mwindow);
101 }
102
103 EditAttachEffect::~EditAttachEffect()
104 {
105         delete dialog_thread;
106 }
107
108 int EditAttachEffect::handle_event()
109 {
110         dialog_thread->start_window(popup->track,
111                 0, _(PROGRAM_NAME ": Attach Effect"),
112                 0, popup->track->data_type);
113         return 1;
114 }
115
116
117 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
118  : BC_MenuItem(_("Move up"))
119 {
120         this->mwindow = mwindow;
121         this->popup = popup;
122 }
123 EditMoveTrackUp::~EditMoveTrackUp()
124 {
125 }
126 int EditMoveTrackUp::handle_event()
127 {
128         mwindow->move_track_up(popup->track);
129         return 1;
130 }
131
132
133
134 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
135  : BC_MenuItem(_("Move down"))
136 {
137         this->mwindow = mwindow;
138         this->popup = popup;
139 }
140 EditMoveTrackDown::~EditMoveTrackDown()
141 {
142 }
143 int EditMoveTrackDown::handle_event()
144 {
145         mwindow->move_track_down(popup->track);
146         return 1;
147 }
148
149
150 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
151  : BC_MenuItem(_("Resize track..."))
152 {
153         this->mwindow = mwindow;
154         this->popup = popup;
155         dialog_thread = new ResizeTrackThread(mwindow);
156 }
157 EditPopupResize::~EditPopupResize()
158 {
159         delete dialog_thread;
160 }
161
162 int EditPopupResize::handle_event()
163 {
164         dialog_thread->start_window(popup->track);
165         return 1;
166 }
167
168
169 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
170  : BC_MenuItem(_("Match output size"))
171 {
172         this->mwindow = mwindow;
173         this->popup = popup;
174 }
175 EditPopupMatchSize::~EditPopupMatchSize()
176 {
177 }
178
179 int EditPopupMatchSize::handle_event()
180 {
181         mwindow->match_output_size(popup->track);
182         return 1;
183 }
184
185
186 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
187  : BC_MenuItem(_("Delete track"))
188 {
189         this->mwindow = mwindow;
190         this->popup = popup;
191 }
192 int EditPopupDeleteTrack::handle_event()
193 {
194         mwindow->delete_track(popup->track);
195         return 1;
196 }
197
198
199 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
200  : BC_MenuItem(_("Add track"))
201 {
202         this->mwindow = mwindow;
203         this->popup = popup;
204 }
205
206 int EditPopupAddTrack::handle_event()
207 {
208         switch( popup->track->data_type ) {
209         case TRACK_AUDIO:
210                 mwindow->add_audio_track_entry(1, popup->track);
211                 break;
212         case TRACK_VIDEO:
213                 mwindow->add_video_track_entry(popup->track);
214                 break;
215         case TRACK_SUBTITLE:
216                 mwindow->add_subttl_track_entry(popup->track);
217                 break;
218         }
219         return 1;
220 }
221
222
223 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
224  : BC_MenuItem(_("User title..."))
225 {
226         this->mwindow = mwindow;
227         this->popup = popup;
228         window = 0;
229 }
230
231 EditPopupTitle::~EditPopupTitle()
232 {
233         delete popup;
234 }
235
236 int EditPopupTitle::handle_event()
237 {
238         int result;
239
240         Track *trc = mwindow->session->track_highlighted;
241
242         if (trc && trc->record)
243         {
244                 Edit *edt = mwindow->session->edit_highlighted;
245                 if(!edt) return 1;
246
247                 window = new EditPopupTitleWindow (mwindow, popup);
248                 window->create_objects();
249                 result = window->run_window();
250
251
252                 if(!result && edt)
253                 {
254                         strcpy(edt->user_title, window->title_text->get_text());
255                 }
256
257                 delete window;
258                 window = 0;
259         }
260
261         return 1;
262 }
263
264
265 EditPopupTitleWindow::EditPopupTitleWindow (MWindow *mwindow, EditPopup *popup)
266  : BC_Window (_(PROGRAM_NAME ": Set edit title"),
267         mwindow->gui->get_abs_cursor_x(0) - 400 / 2,
268         mwindow->gui->get_abs_cursor_y(0) - 500 / 2,
269         300,
270         100,
271         300,
272         100,
273         0,
274         0,
275         1)
276 {
277         this->mwindow = mwindow;
278         this->popup = popup;
279         this->edt = this->mwindow->session->edit_highlighted;
280         if(this->edt)
281         {
282                 strcpy(new_text, this->edt->user_title);
283         }
284 }
285
286 EditPopupTitleWindow::~EditPopupTitleWindow()
287 {
288 }
289
290 int EditPopupTitleWindow::close_event()
291 {
292         set_done(1);
293         return 1;
294 }
295
296 void EditPopupTitleWindow::create_objects()
297 {
298         int x = 5;
299         int y = 10;
300
301         add_subwindow (new BC_Title (x, y, _("User title")));
302         add_subwindow (title_text = new EditPopupTitleText (this,
303                 mwindow, x, y + 20));
304         add_tool(new BC_OKButton(this));
305         add_tool(new BC_CancelButton(this));
306
307
308         show_window();
309         flush();
310 }
311
312
313 EditPopupTitleText::EditPopupTitleText (EditPopupTitleWindow *window,
314         MWindow *mwindow, int x, int y)
315  : BC_TextBox(x, y, 250, 1, (char*)(window->edt ? window->edt->user_title : ""))
316 {
317         this->window = window;
318         this->mwindow = mwindow;
319 }
320
321 EditPopupTitleText::~EditPopupTitleText()
322 {
323 }
324
325 int EditPopupTitleText::handle_event()
326 {
327         return 1;
328 }
329