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