remove old quicktime, replaced with current ffmpeg
[goodguy/history.git] / cinelerra-5.0 / cinelerra / awindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 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 "assetedit.h"
24 #include "assetpopup.h"
25 #include "assets.h"
26 #include "awindowgui.h"
27 #include "awindowgui.inc"
28 #include "awindow.h"
29 #include "awindowmenu.h"
30 #include "bcsignals.h"
31 #include "cache.h"
32 #include "bccmodels.h"
33 #include "cursors.h"
34 #include "cwindowgui.h"
35 #include "cwindow.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "file.h"
39 #include "filesystem.h"
40 #include "indexable.h"
41 #include "keys.h"
42 #include "language.h"
43 #include "localsession.h"
44 #include "mainmenu.h"
45 #include "mainsession.h"
46 #include "mwindowgui.h"
47 #include "mwindow.h"
48 #include "nestededls.h"
49 #include "newfolder.h"
50 #include "preferences.h"
51 #include "theme.h"
52 #include "vframe.h"
53 #include "vwindowgui.h"
54 #include "vwindow.h"
55
56 #include "data/lad_picon_png.h"
57
58 #include<stdio.h>
59 #include<unistd.h>
60 #include<fcntl.h>
61
62 AssetPicon::AssetPicon(MWindow *mwindow, 
63         AWindowGUI *gui, 
64         Indexable *indexable)
65  : BC_ListBoxItem()
66 {
67         reset();
68         this->mwindow = mwindow;
69         this->gui = gui;
70         this->indexable = indexable;
71         indexable->add_user();
72         this->id = indexable->id;
73 }
74
75 AssetPicon::AssetPicon(MWindow *mwindow, 
76         AWindowGUI *gui, 
77         EDL *edl)
78  : BC_ListBoxItem()
79 {
80         reset();
81         this->mwindow = mwindow;
82         this->gui = gui;
83         this->edl = edl;
84         edl->add_user();
85         this->id = edl->id;
86 }
87
88 AssetPicon::AssetPicon(MWindow *mwindow, 
89         AWindowGUI *gui, 
90         const char *folder)
91  : BC_ListBoxItem(folder, gui->folder_icon)
92 {
93         reset();
94         this->mwindow = mwindow;
95         this->gui = gui;
96 }
97
98 AssetPicon::AssetPicon(MWindow *mwindow, 
99         AWindowGUI *gui, 
100         PluginServer *plugin)
101  : BC_ListBoxItem()
102 {
103         reset();
104         this->mwindow = mwindow;
105         this->gui = gui;
106         this->plugin = plugin;
107 }
108
109
110 AssetPicon::~AssetPicon()
111 {
112         if(indexable) indexable->remove_user();
113         if(edl) edl->remove_user();
114         if( icon && !gui->protected_pixmap(icon) ) {
115                 delete icon;
116         }
117 }
118
119 void AssetPicon::reset()
120 {
121         plugin = 0;
122         indexable = 0;
123         edl = 0;
124         icon = 0;
125         icon_vframe = 0;
126         in_use = 1;
127         id = 0;
128         persistent = 0;
129 }
130
131 void AssetPicon::create_objects()
132 {
133         FileSystem fs;
134         char name[BCTEXTLEN];
135         int pixmap_w, pixmap_h;
136         const int debug = 0;
137
138         pixmap_h = 50;
139
140         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
141         if(indexable)
142         {
143                 fs.extract_name(name, indexable->path);
144                 set_text(name);
145         }
146         
147         if(indexable && indexable->is_asset)
148         {
149                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
150                 Asset *asset = (Asset*)indexable;
151                 if(asset->video_data)
152                 {
153                         if(mwindow->preferences->use_thumbnails)
154                         {
155                                 gui->unlock_window();
156                                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
157                                 File *file = mwindow->video_cache->check_out(asset, 
158                                         mwindow->edl,
159                                         1);
160                                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
161
162                                 if(file)
163                                 {
164                                         int height = asset->height > 0 ? asset->height : 1;
165                                         pixmap_w = pixmap_h * asset->width / height;
166
167                                         file->set_layer(0);
168                                         file->set_video_position(0, 0);
169
170                                         if(gui->temp_picon && 
171                                                 (gui->temp_picon->get_w() != asset->width ||
172                                                 gui->temp_picon->get_h() != asset->height))
173                                         {
174                                                 delete gui->temp_picon;
175                                                 gui->temp_picon = 0;
176                                         }
177
178                                         if(!gui->temp_picon)
179                                         {
180                                                 gui->temp_picon = new VFrame(0, -1,
181                                                         asset->width, asset->height, 
182                                                         BC_RGB888, -1);
183                                         }
184
185                                         file->read_frame(gui->temp_picon);
186                                         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
187                                         mwindow->video_cache->check_in(asset);
188
189                                         gui->lock_window("AssetPicon::create_objects 1");
190                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
191                                         icon->draw_vframe(gui->temp_picon,
192                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
193 //printf("%d %d\n", gui->temp_picon->get_w(), gui->temp_picon->get_h());
194                                         icon_vframe = new VFrame(0,
195                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
196                                         BC_CModels::transfer(
197                                                 icon_vframe->get_rows(),
198                                                 gui->temp_picon->get_rows(),
199                                                 0, 0, 0, 0, 0, 0, 0, 0, 
200                                                 gui->temp_picon->get_w(), 
201                                                 gui->temp_picon->get_h(),
202                                                 0, 0, pixmap_w, pixmap_h,
203                                                 BC_RGB888, BC_RGB888,
204                                                 0, 0, 0);
205
206                                         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
207
208                                 }
209                                 else
210                                 {
211                                         gui->lock_window("AssetPicon::create_objects 2");
212                                         icon = gui->video_icon;
213                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
214                                 }
215                         }
216                         else
217                         {
218                                 icon = gui->video_icon;
219                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];                  
220                         }
221                 }
222                 else
223                 if(asset->audio_data)
224                 {
225                         icon = gui->audio_icon;
226                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
227                 }
228 //printf("AssetPicon::create_objects 2\n");
229
230                 if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
231         }
232         else
233         if(indexable && !indexable->is_asset)
234         {
235                 icon = gui->video_icon;
236                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
237         }
238         else
239         if(edl)
240         {
241 //printf("AssetPicon::create_objects 4 %s\n", edl->local_session->clip_title);
242                 set_text(strcpy(name, edl->local_session->clip_title));
243                 icon = gui->clip_icon;
244                 icon_vframe = mwindow->theme->get_image("clip_icon");
245         }
246         else
247         if(plugin)
248         {
249                 strcpy(name, _(plugin->title));
250                 set_text(name);
251                 icon_vframe = plugin->get_picon();
252                 if( icon_vframe )
253                         icon = gui->create_pixmap(icon_vframe);
254                 else if( plugin->audio ) {
255                         if( plugin->transition ) {
256                                 icon = gui->atransition_icon;
257                                 icon_vframe = gui->atransition_vframe;
258                         }
259                         else if( !plugin->is_ladspa() ) {
260                                 icon = gui->aeffect_icon;
261                                 icon_vframe = gui->aeffect_vframe;
262                         }
263                         else {
264                                 icon = gui->ladspa_icon;
265                                 icon_vframe = gui->ladspa_vframe;
266                         }
267                 }
268                 else if( plugin->video ) {
269                         if( plugin->transition ) {
270                                 icon = gui->vtransition_icon;
271                                 icon_vframe = gui->vtransition_vframe;
272                         }
273                         else {
274                                 icon = gui->veffect_icon;
275                                 icon_vframe = gui->veffect_vframe;
276                         }
277                 }
278         }
279         if( !icon ) {
280                 icon = gui->file_icon;
281                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
282         }
283         set_icon(icon);
284         set_icon_vframe(icon_vframe);
285
286         if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
287 }
288
289
290
291
292
293
294 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
295  : BC_Window(PROGRAM_NAME ": Resources",
296         mwindow->session->awindow_x, 
297     mwindow->session->awindow_y, 
298     mwindow->session->awindow_w, 
299     mwindow->session->awindow_h,
300     100,
301     100,
302     1,
303     1,
304     1)
305 {
306 // printf("AWindowGUI::AWindowGUI %d %d %d %d\n",
307 // mwindow->session->awindow_x, 
308 // mwindow->session->awindow_y, 
309 // mwindow->session->awindow_w, 
310 // mwindow->session->awindow_h);
311         this->mwindow = mwindow;
312         this->awindow = awindow;
313         file_icon = 0;
314         audio_icon = 0;
315         video_icon = 0;
316         folder_icon = 0;
317         clip_icon = 0;
318         atransition_icon = 0;  atransition_vframe = 0;
319         vtransition_icon = 0;  vtransition_vframe = 0;
320         aeffect_icon = 0;      aeffect_vframe = 0;
321         ladspa_icon = 0;       ladspa_vframe = 0;
322         veffect_icon = 0;      veffect_vframe = 0;
323         newfolder_thread = 0;
324         asset_menu = 0;
325         assetlist_menu = 0;
326         folderlist_menu = 0;
327         temp_picon = 0;
328         remove_plugin = 0;
329         plugin_visibility = ~0;
330 }
331
332 AWindowGUI::~AWindowGUI()
333 {
334         assets.remove_all_objects();
335         folders.remove_all_objects();
336         aeffects.remove_all_objects();
337         veffects.remove_all_objects();
338         atransitions.remove_all_objects();
339         vtransitions.remove_all_objects();
340         displayed_assets[1].remove_all_objects();
341         delete file_icon;
342         delete audio_icon;
343         delete video_icon;
344         delete folder_icon;
345         delete clip_icon;
346         delete atransition_icon;
347         delete vtransition_icon;
348         delete aeffect_icon;
349         delete ladspa_icon;
350         delete ladspa_vframe;
351         delete veffect_icon;
352         delete newfolder_thread;
353         delete asset_menu;
354         delete assetlist_menu;
355         delete folderlist_menu;
356         if(temp_picon) delete temp_picon;
357         delete remove_plugin;
358 }
359
360 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
361 {
362         return  icon == file_icon ||
363                 icon == audio_icon ||
364                 icon == folder_icon ||
365                 icon == clip_icon ||
366                 icon == video_icon ||
367                 icon == veffect_icon ||
368                 icon == vtransition_icon ||
369                 icon == aeffect_icon ||
370                 icon == ladspa_icon ||
371                 icon == atransition_icon; 
372 }
373
374 void AWindowGUI::create_objects()
375 {
376         AssetPicon *picon;
377
378         lock_window("AWindowGUI::create_objects");
379 SET_TRACE
380 //printf("AWindowGUI::create_objects 1\n");
381         asset_titles[0] = _("Title");
382         asset_titles[1] = _("Comments");
383
384 SET_TRACE
385
386         set_icon(mwindow->theme->get_image("awindow_icon"));
387         file_icon = new BC_Pixmap(this, 
388                 BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
389                 PIXMAP_ALPHA);
390
391         folder_icon = new BC_Pixmap(this, 
392                 BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
393                 PIXMAP_ALPHA);
394
395         audio_icon = new BC_Pixmap(this, 
396                 BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
397                 PIXMAP_ALPHA);
398
399         video_icon = new BC_Pixmap(this, 
400                 BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
401                 PIXMAP_ALPHA);
402
403 SET_TRACE
404
405         clip_vframe = mwindow->theme->get_image("clip_icon");
406         clip_icon = new BC_Pixmap(this, clip_vframe, PIXMAP_ALPHA);
407         atransition_vframe = mwindow->theme->get_image("atransition_icon");
408         atransition_icon = new BC_Pixmap(this, atransition_vframe, PIXMAP_ALPHA);
409         vtransition_vframe = mwindow->theme->get_image("vtransition_icon");
410         vtransition_icon = new BC_Pixmap(this, vtransition_vframe, PIXMAP_ALPHA);
411         aeffect_vframe = mwindow->theme->get_image("aeffect_icon");
412         aeffect_icon = new BC_Pixmap(this, aeffect_vframe, PIXMAP_ALPHA);
413         ladspa_vframe = new VFrame(lad_picon_png);
414         ladspa_icon = new BC_Pixmap(this, ladspa_vframe, PIXMAP_ALPHA);
415         veffect_vframe = mwindow->theme->get_image("veffect_icon");
416         veffect_icon = new BC_Pixmap(this, veffect_vframe, PIXMAP_ALPHA);
417
418 SET_TRACE
419
420 // Mandatory folders
421         folders.append(picon = new AssetPicon(mwindow,
422                 this,
423                 AEFFECT_FOLDER));
424         picon->persistent = 1;
425         folders.append(picon = new AssetPicon(mwindow,
426                 this,
427                 VEFFECT_FOLDER));
428         picon->persistent = 1;
429         folders.append(picon = new AssetPicon(mwindow,
430                 this,
431                 ATRANSITION_FOLDER));
432         picon->persistent = 1;
433         folders.append(picon = new AssetPicon(mwindow,
434                 this,
435                 VTRANSITION_FOLDER));
436         picon->persistent = 1;
437 SET_TRACE
438
439         mwindow->theme->get_awindow_sizes(this);
440
441 SET_TRACE
442         add_subwindow(asset_list = new AWindowAssets(mwindow,
443                 this,
444                 mwindow->theme->alist_x, 
445                 mwindow->theme->alist_y, 
446                 mwindow->theme->alist_w, 
447                 mwindow->theme->alist_h));
448
449 SET_TRACE
450         add_subwindow(divider = new AWindowDivider(mwindow,
451                 this,
452                 mwindow->theme->adivider_x,
453                 mwindow->theme->adivider_y,
454                 mwindow->theme->adivider_w,
455                 mwindow->theme->adivider_h));
456
457 SET_TRACE
458         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
459
460 SET_TRACE
461         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y; 
462         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h; 
463         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, fw));
464         add_tools->create_objects();
465         fy += add_tools->get_h();  fh -= add_tools->get_h();
466 SET_TRACE
467         add_subwindow(folder_list = new AWindowFolders(mwindow,
468                 this, fx, fy, fw, fh));
469 SET_TRACE
470         update_effects();
471 SET_TRACE
472
473         //int x = mwindow->theme->abuttons_x;
474         //int y = mwindow->theme->abuttons_y;
475
476 SET_TRACE
477
478         newfolder_thread = new NewFolderThread(mwindow, this);
479
480         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
481         asset_menu->create_objects();
482
483 SET_TRACE
484
485         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
486
487 SET_TRACE
488         assetlist_menu->create_objects();
489
490 SET_TRACE
491
492         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
493         folderlist_menu->create_objects();
494 //printf("AWindowGUI::create_objects 2\n");
495
496 SET_TRACE
497         unlock_window();
498 }
499
500 int AWindowGUI::resize_event(int w, int h)
501 {
502         mwindow->session->awindow_x = get_x();
503         mwindow->session->awindow_y = get_y();
504         mwindow->session->awindow_w = w;
505         mwindow->session->awindow_h = h;
506
507         mwindow->theme->get_awindow_sizes(this);
508         mwindow->theme->draw_awindow_bg(this);
509
510         asset_list->reposition_window(mwindow->theme->alist_x, 
511         mwindow->theme->alist_y, 
512         mwindow->theme->alist_w, 
513         mwindow->theme->alist_h);
514         divider->reposition_window(mwindow->theme->adivider_x,
515                 mwindow->theme->adivider_y,
516                 mwindow->theme->adivider_w,
517                 mwindow->theme->adivider_h);
518
519         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y; 
520         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h; 
521         add_tools->reposition_window(fx, fy, fw, add_tools->get_h());
522         fy += add_tools->get_h();  fh -= add_tools->get_h();
523         folder_list->reposition_window(fx, fy, fw, fh);
524         
525 //      int x = mwindow->theme->abuttons_x;
526 //      int y = mwindow->theme->abuttons_y;
527 //      new_bin->reposition_window(x, y);
528 //      x += new_bin->get_w();
529 //      delete_bin->reposition_window(x, y);
530 //      x += delete_bin->get_w();
531 //      rename_bin->reposition_window(x, y);
532 //      x += rename_bin->get_w();
533 //      delete_disk->reposition_window(x, y);
534 //      x += delete_disk->get_w();
535 //      delete_project->reposition_window(x, y);
536 //      x += delete_project->get_w();
537 //      info->reposition_window(x, y);
538 //      x += info->get_w();
539 //      redraw_index->reposition_window(x, y);
540 //      x += redraw_index->get_w();
541 //      paste->reposition_window(x, y);
542 //      x += paste->get_w();
543 //      append->reposition_window(x, y);
544 //      x += append->get_w();
545 //      view->reposition_window(x, y);
546
547         BC_WindowBase::resize_event(w, h);
548         return 1;
549 }
550
551 int AWindowGUI::translation_event()
552 {
553         mwindow->session->awindow_x = get_x();
554         mwindow->session->awindow_y = get_y();
555         return 0;
556 }
557
558 void AWindowGUI::reposition_objects()
559 {
560         mwindow->theme->get_awindow_sizes(this);
561         asset_list->reposition_window(mwindow->theme->alist_x, 
562         mwindow->theme->alist_y, 
563         mwindow->theme->alist_w, 
564         mwindow->theme->alist_h);
565         divider->reposition_window(mwindow->theme->adivider_x,
566                 mwindow->theme->adivider_y,
567                 mwindow->theme->adivider_w,
568                 mwindow->theme->adivider_h);
569         folder_list->reposition_window(mwindow->theme->afolders_x, 
570         mwindow->theme->afolders_y, 
571         mwindow->theme->afolders_w, 
572         mwindow->theme->afolders_h);
573         flush();
574 }
575
576 int AWindowGUI::close_event()
577 {
578         hide_window();
579         mwindow->session->show_awindow = 0;
580         unlock_window();
581
582         mwindow->gui->lock_window("AWindowGUI::close_event");
583         mwindow->gui->mainmenu->show_awindow->set_checked(0);
584         mwindow->gui->unlock_window();
585
586         lock_window("AWindowGUI::close_event");
587         mwindow->save_defaults();
588         return 1;
589 }
590
591 AWindowRemovePluginGUI::
592 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
593         int x, int y, PluginServer *plugin)
594  : BC_Window(PROGRAM_NAME ": Remove plugin", x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
595 {
596         this->awindow = awindow;
597         this->thread = thread;
598         this->plugin = plugin;
599         VFrame *vframe = plugin->get_picon();
600         icon = vframe ? create_pixmap(vframe) : 0;
601         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
602 }
603
604 AWindowRemovePluginGUI::
605 ~AWindowRemovePluginGUI()
606 {
607         if( !awindow->gui->protected_pixmap(icon) )
608                 delete icon;
609         plugin_list.remove_all();
610 }
611
612 void AWindowRemovePluginGUI::create_objects()
613 {
614         BC_Button *ok_button = new BC_OKButton(this);
615         add_subwindow(ok_button);
616         BC_Button *cancel_button = new BC_CancelButton(this);
617         add_subwindow(cancel_button);
618         int x = 10, y = 10;
619         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
620         add_subwindow(title);
621         y += title->get_h() + 5;
622         list = new BC_ListBox(x, y,
623                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
624                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
625         add_subwindow(list);
626         show_window();
627 }
628
629 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
630 {
631         int ret = 0;
632         for( int i=0; i<folder.size(); ) {
633                 AssetPicon *picon = (AssetPicon *)folder[i];
634                 if( picon->plugin == plugin ) {
635                         folder.remove_object_number(i);
636                         ++ret;
637                         continue;
638                 }
639                 ++i;
640         }
641         return ret;
642 }
643
644 void AWindowRemovePlugin::handle_close_event(int result)
645 {
646         if( !result ) {
647                 printf("remove %s\n", plugin->path);
648                 ArrayList<BC_ListBoxItem*> *folder = 
649                         plugin->audio ? plugin->transition ?
650                                 &awindow->gui->atransitions :
651                                 &awindow->gui->aeffects :
652                         plugin->video ?  plugin->transition ?
653                                 &awindow->gui->vtransitions :
654                                 &awindow->gui->veffects :
655                         0;
656                 if( folder ) remove_plugin(plugin, *folder);
657                 awindow->gui->update_assets();
658                 char png_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_path[BCTEXTLEN];
659                 strcpy(plugin_path, plugin->path);
660                 if( !plugin->get_plugin_png_path(png_path) ) png_path[0] = 0;
661                 MWindow *mwindow = awindow->mwindow;
662                 sprintf(index_path, "%s/%s", mwindow->preferences->plugin_dir, PLUGIN_FILE);
663                 mwindow->plugindb->remove(plugin);
664                 plugin->delete_this();
665                 remove(plugin_path);
666                 if( png_path[0] ) remove(png_path);
667                 remove(index_path);
668         }
669 }
670
671 AWindowRemovePlugin::
672 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
673  : BC_DialogThread()
674 {
675         this->awindow = awindow;
676         this->plugin = plugin;
677 }
678
679 AWindowRemovePlugin::
680 ~AWindowRemovePlugin()
681 {
682         close_window();
683 }
684
685 BC_Window* AWindowRemovePlugin::new_gui()
686 {
687         int x = awindow->gui->get_abs_cursor_x(0);
688         int y = awindow->gui->get_abs_cursor_y(0);
689         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
690         gui->create_objects();
691         return gui;
692 }
693
694 int AWindowGUI::keypress_event()
695 {
696         switch(get_keypress()) {
697         case 'w': case 'W':
698                 if(ctrl_down()) {
699                         close_event();
700                         return 1;
701                 }
702                 break;
703         case DELETE:
704                 if(shift_down()) {
705                         PluginServer* plugin = selected_plugin();
706                         if( !plugin ) break;
707                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
708                         unlock_window();
709                         remove_plugin->start();
710                         lock_window();
711                 }
712         }
713         return 0;
714 }
715
716 void AWindowGUI::update_folder_list()
717 {
718 //printf("AWindowGUI::update_folder_list 1\n");
719         for(int i = 0; i < folders.total; i++)
720         {
721                 AssetPicon *picon = (AssetPicon*)folders.values[i];
722                 picon->in_use--;
723         }
724 //printf("AWindowGUI::update_folder_list 1\n");
725
726 // Search assets for folders
727         for(int i = 0; i < mwindow->edl->folders.total; i++)
728         {
729                 char *folder = mwindow->edl->folders.values[i];
730                 int exists = 0;
731 //printf("AWindowGUI::update_folder_list 1.1\n");
732
733                 for(int j = 0; j < folders.total; j++)
734                 {
735                         AssetPicon *picon = (AssetPicon*)folders.values[j];
736                         if(!strcasecmp(picon->get_text(), folder))
737                         {
738                                 exists = 1;
739                                 picon->in_use = 1;
740                                 break;
741                         }
742                 }
743
744                 if(!exists)
745                 {
746                         AssetPicon *picon = new AssetPicon(mwindow, this, folder);
747                         picon->create_objects();
748                         folders.append(picon);
749                 }
750 //printf("AWindowGUI::update_folder_list 1.3\n");
751         }
752 //printf("AWindowGUI::update_folder_list 1\n");
753 //for(int i = 0; i < folders.total; i++)
754 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
755
756 // Delete excess
757         for(int i = folders.total - 1; i >= 0; i--)
758         {
759                 AssetPicon *picon = (AssetPicon*)folders.values[i];
760                 if(!picon->in_use && !picon->persistent)
761                 {
762                         delete picon;
763                         folders.remove_number(i);
764                 }
765         }
766 //for(int i = 0; i < folders.total; i++)
767 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
768 //printf("AWindowGUI::update_folder_list 2\n");
769 }
770
771 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output, 
772         int do_audio, int do_video, int is_realtime, int is_transition)
773 {
774         ArrayList<PluginServer*> plugin_list;
775 // Get pointers to plugindb entries
776         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
777                         0, plugin_list);
778
779         for(int i = 0; i < plugin_list.total; i++) {
780                 PluginServer *server = plugin_list.values[i];
781                 int visible = plugin_visibility & (1<<server->dir_idx);
782                 if(!visible) continue;
783 // Create new listitem
784                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
785                 picon->create_objects();
786                 output->append(picon);
787         }
788 }
789
790 void AWindowGUI::update_asset_list()
791 {
792 //printf("AWindowGUI::update_asset_list 1\n");
793         for(int i = 0; i < assets.total; i++)
794         {
795                 AssetPicon *picon = (AssetPicon*)assets.values[i];
796                 picon->in_use--;
797         }
798
799
800
801
802
803 //printf("AWindowGUI::update_asset_list 2\n");
804
805
806 // Synchronize EDL clips
807         for(int i = 0; i < mwindow->edl->clips.total; i++)
808         {
809                 int exists = 0;
810                 
811 // Look for clip in existing listitems
812                 for(int j = 0; j < assets.total && !exists; j++)
813                 {
814                         AssetPicon *picon = (AssetPicon*)assets.values[j];
815                         
816                         if(picon->id == mwindow->edl->clips.values[i]->id)
817                         {
818                                 picon->edl = mwindow->edl->clips.values[i];
819                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
820                                 exists = 1;
821                                 picon->in_use = 1;
822                         }
823                 }
824
825 // Create new listitem
826                 if(!exists)
827                 {
828                         AssetPicon *picon = new AssetPicon(mwindow, 
829                                 this, 
830                                 mwindow->edl->clips.values[i]);
831                         picon->create_objects();
832                         assets.append(picon);
833                 }
834         }
835
836
837
838
839
840 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
841
842
843 // Synchronize EDL assets
844         for(Asset *current = mwindow->edl->assets->first; 
845                 current; 
846                 current = NEXT)
847         {
848                 int exists = 0;
849
850 // Look for asset in existing listitems
851                 for(int j = 0; j < assets.total && !exists; j++)
852                 {
853                         AssetPicon *picon = (AssetPicon*)assets.values[j];
854
855                         if(picon->id == current->id)
856                         {
857                                 picon->indexable = current;
858                                 exists = 1;
859                                 picon->in_use = 1;
860                                 break;
861                         }
862                 }
863
864 // Create new listitem
865                 if(!exists)
866                 {
867 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
868                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
869 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
870                         picon->create_objects();
871 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
872                         assets.append(picon);
873                 }
874         }
875
876
877
878 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
879
880
881 // Synchronize nested EDLs
882         for(int i = 0; i < mwindow->edl->nested_edls->size(); i++)
883         {
884                 int exists = 0;
885                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
886
887 // Look for asset in existing listitems
888                 for(int j = 0; j < assets.total && !exists; j++)
889                 {
890                         AssetPicon *picon = (AssetPicon*)assets.values[j];
891
892                         if(picon->id == indexable->id)
893                         {
894                                 picon->indexable = indexable;
895                                 exists = 1;
896                                 picon->in_use = 1;
897                                 break;
898                         }
899                 }
900
901 // Create new listitem
902                 if(!exists)
903                 {
904                         AssetPicon *picon = new AssetPicon(mwindow, 
905                                 this, 
906                                 indexable);
907                         picon->create_objects();
908                         assets.append(picon);
909                 }
910         }
911
912
913
914
915
916
917
918
919
920 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
921         for(int i = assets.size() - 1; i >= 0; i--)
922         {
923                 AssetPicon *picon = (AssetPicon*)assets.get(i);
924 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
925                 if(!picon->in_use)
926                 {
927                         delete picon;
928                         assets.remove_number(i);
929                 }
930         }
931 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
932 }
933
934
935
936
937
938 void AWindowGUI::sort_assets()
939 {
940 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
941         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
942                 sort_picons(&aeffects, 
943                         0);
944         else
945         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
946                 sort_picons(&veffects, 
947                         0);
948         else
949         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
950                 sort_picons(&atransitions, 
951                         0);
952         else
953         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
954                 sort_picons(&vtransitions, 
955                         0);
956         else
957                 sort_picons(&assets, 
958                         mwindow->edl->session->current_folder);
959
960         update_assets();
961 }
962
963
964
965
966
967
968
969
970
971
972
973 void AWindowGUI::collect_assets()
974 {
975         int i = 0;
976         mwindow->session->drag_assets->remove_all();
977         mwindow->session->drag_clips->remove_all();
978         while(1)
979         {
980                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
981                 if(!result) break;
982
983                 if(result->indexable) mwindow->session->drag_assets->append(result->indexable);
984                 if(result->edl) mwindow->session->drag_clips->append(result->edl);
985         }
986 }
987
988 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst, 
989         ArrayList<BC_ListBoxItem*> *src, 
990         char *folder)
991 {
992 // Remove current pointers
993         dst[0].remove_all();
994         dst[1].remove_all_objects();
995
996 // Create new pointers
997 //if(folder) printf("AWindowGUI::copy_picons 1 %s\n", folder);
998         for(int i = 0; i < src->total; i++)
999         {
1000                 AssetPicon *picon = (AssetPicon*)src->values[i];
1001 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
1002                 if(!folder ||
1003                         (folder && picon->indexable && !strcasecmp(picon->indexable->folder, folder)) ||
1004                         (folder && picon->edl && !strcasecmp(picon->edl->local_session->folder, folder)))
1005                 {
1006                         BC_ListBoxItem *item2, *item1;
1007                         dst[0].append(item1 = picon);
1008                         if(picon->edl)
1009                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1010                         else
1011                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1012                         item1->set_autoplace_text(1);
1013                         item2->set_autoplace_text(1);
1014 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
1015                 }
1016         }
1017 }
1018
1019 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, 
1020                 char *folder)
1021 {
1022 //printf("AWindowGUI::sort_picons 1\n")
1023         int done = 0;
1024         while(!done)
1025         {
1026                 done = 1;
1027                 for(int i = 0; i < src->total - 1; i++)
1028                 {
1029                         BC_ListBoxItem *item1 = src->values[i];
1030                         BC_ListBoxItem *item2 = src->values[i + 1];
1031                         item1->set_autoplace_icon(1);
1032                         item2->set_autoplace_icon(1);
1033                         item1->set_autoplace_text(1);
1034                         item2->set_autoplace_text(1);
1035                         if(strcmp(item1->get_text(), item2->get_text()) > 0)
1036                         {
1037                                 src->values[i + 1] = item1;
1038                                 src->values[i] = item2;
1039                                 done = 0;
1040                         }
1041                 }
1042         }
1043 }
1044
1045
1046 void AWindowGUI::filter_displayed_assets()
1047 {
1048         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1049                 copy_picons(displayed_assets, 
1050                         &aeffects, 
1051                         0);
1052         else
1053         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1054                 copy_picons(displayed_assets, 
1055                         &veffects, 
1056                         0);
1057         else
1058         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1059                 copy_picons(displayed_assets, 
1060                         &atransitions, 
1061                         0);
1062         else
1063         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1064                 copy_picons(displayed_assets, 
1065                         &vtransitions, 
1066                         0);
1067         else
1068                 copy_picons(displayed_assets, 
1069                         &assets, 
1070                         mwindow->edl->session->current_folder);
1071 }
1072
1073
1074 void AWindowGUI::update_assets()
1075 {
1076 //printf("AWindowGUI::update_assets 1\n");
1077         update_folder_list();
1078 //printf("AWindowGUI::update_assets 2\n");
1079         update_asset_list();
1080 //printf("AWindowGUI::update_assets 3\n");
1081         filter_displayed_assets();
1082
1083 //for(int i = 0; i < folders.total; i++)
1084 //printf("AWindowGUI::update_assets 4\n");
1085 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
1086         if(mwindow->edl->session->folderlist_format != folder_list->get_format())
1087                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1088         folder_list->update(&folders,
1089                 0,
1090                 0,
1091                 1,
1092                 folder_list->get_xposition(),
1093                 folder_list->get_yposition(),
1094                 -1);
1095 //printf("AWindowGUI::update_assets 5\n");
1096
1097         if(mwindow->edl->session->assetlist_format != asset_list->get_format())
1098                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1099
1100
1101 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
1102         asset_list->update(displayed_assets,
1103                 asset_titles,
1104                 mwindow->edl->session->asset_columns,
1105                 ASSET_COLUMNS, 
1106                 asset_list->get_xposition(),
1107                 asset_list->get_yposition(),
1108                 -1,
1109                 0);
1110 //printf("AWindowGUI::update_assets 7\n");
1111
1112         flush();
1113 //printf("AWindowGUI::update_assets 8\n");
1114         return;
1115 }
1116
1117 void AWindowGUI::update_effects()
1118 {
1119         aeffects.remove_all_objects();
1120         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1121         veffects.remove_all_objects();
1122         create_persistent_folder(&veffects, 0, 1, 1, 0);
1123         atransitions.remove_all_objects();
1124         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1125         vtransitions.remove_all_objects();
1126         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1127 }
1128
1129 int AWindowGUI::current_folder_number()
1130 {
1131         int result = -1;
1132         for(int i = 0; i < folders.total; i++)
1133         {
1134                 if(!strcasecmp(folders.values[i]->get_text(), mwindow->edl->session->current_folder))
1135                 {
1136                         result = i;
1137                         break;
1138                 }
1139         }
1140         return result;
1141 }
1142
1143 int AWindowGUI::drag_motion()
1144 {
1145         if(get_hidden()) return 0;
1146
1147         int result = 0;
1148         return result;
1149 }
1150
1151 int AWindowGUI::drag_stop()
1152 {
1153         if(get_hidden()) return 0;
1154
1155         return 0;
1156 }
1157
1158 Indexable* AWindowGUI::selected_asset()
1159 {
1160         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1161         return picon ? picon->indexable : 0;
1162 }
1163
1164 PluginServer* AWindowGUI::selected_plugin()
1165 {
1166         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1167         return picon ? picon->plugin : 0;
1168 }
1169
1170 AssetPicon* AWindowGUI::selected_folder()
1171 {
1172         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1173         return picon;
1174 }
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1186  : BC_SubWindow(x, y, w, h)
1187 {
1188         this->mwindow = mwindow;
1189         this->gui = gui;
1190 }
1191 AWindowDivider::~AWindowDivider()
1192 {
1193 }
1194
1195 int AWindowDivider::button_press_event()
1196 {
1197         if(is_event_win() && cursor_inside())
1198         {
1199                 mwindow->session->current_operation = DRAG_PARTITION;
1200                 return 1;
1201         }
1202         return 0;
1203 }
1204
1205 int AWindowDivider::cursor_motion_event()
1206 {
1207         if(mwindow->session->current_operation == DRAG_PARTITION)
1208         {
1209                 mwindow->session->afolders_w = gui->get_relative_cursor_x();
1210                 gui->reposition_objects();
1211         }
1212         return 0;
1213 }
1214
1215 int AWindowDivider::button_release_event()
1216 {
1217         if(mwindow->session->current_operation == DRAG_PARTITION)
1218         {
1219                 mwindow->session->current_operation = NO_OPERATION;
1220                 return 1;
1221         }
1222         return 0;
1223 }
1224
1225
1226
1227
1228
1229
1230 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1231  : BC_ListBox(x, 
1232                 y, 
1233                 w, 
1234                 h,
1235                 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ? 
1236                         LISTBOX_ICONS : LISTBOX_TEXT, 
1237                 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
1238                 0,             // Titles for columns.  Set to 0 for no titles
1239                 0,                // width of each column
1240                 1,                      // Total columns.
1241                 0,                    // Pixel of top of window.
1242                 0,                        // If this listbox is a popup window
1243                 LISTBOX_SINGLE,  // Select one item or multiple items
1244                 ICON_TOP,        // Position of icon relative to text of each item
1245                 1)               // Allow drags
1246 {
1247         this->mwindow = mwindow;
1248         this->gui = gui;
1249         set_drag_scroll(0);
1250 }
1251
1252 AWindowFolders::~AWindowFolders()
1253 {
1254 }
1255         
1256 int AWindowFolders::selection_changed()
1257 {
1258         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1259         if(picon)
1260         {
1261                 if(get_button_down() && get_buttonpress() == 3)
1262                 {
1263                         gui->folderlist_menu->update_titles();
1264                         gui->folderlist_menu->activate_menu();
1265                 }
1266
1267                 strcpy(mwindow->edl->session->current_folder, picon->get_text());
1268 //printf("AWindowFolders::selection_changed 1\n");
1269                 gui->asset_list->draw_background();
1270                 gui->update_assets();
1271         }
1272         return 1;
1273 }
1274
1275 int AWindowFolders::button_press_event()
1276 {
1277         int result = 0;
1278
1279         result = BC_ListBox::button_press_event();
1280
1281         if(!result)
1282         {
1283                 if(get_buttonpress() == 3 && is_event_win() && cursor_inside())
1284                 {
1285                         gui->folderlist_menu->update_titles();
1286                         gui->folderlist_menu->activate_menu();
1287                         result = 1;
1288                 }
1289         }
1290
1291
1292         return result;
1293 }
1294
1295
1296
1297
1298
1299
1300
1301 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1302  : BC_ListBox(x, 
1303                 y, 
1304                 w, 
1305                 h,
1306                 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? 
1307                         LISTBOX_ICONS : LISTBOX_TEXT,
1308                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1309                 gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
1310                 mwindow->edl->session->asset_columns,                // width of each column
1311                 1,                      // Total columns.
1312                 0,                    // Pixel of top of window.
1313                 0,                        // If this listbox is a popup window
1314                 LISTBOX_MULTIPLE,  // Select one item or multiple items
1315                 ICON_TOP,        // Position of icon relative to text of each item
1316                 1)               // Allow drag
1317 {
1318         this->mwindow = mwindow;
1319         this->gui = gui;
1320         set_drag_scroll(0);
1321 }
1322
1323 AWindowAssets::~AWindowAssets()
1324 {
1325 }
1326
1327 int AWindowAssets::button_press_event()
1328 {
1329         int result = 0;
1330
1331         result = BC_ListBox::button_press_event();
1332
1333         if(!result && get_buttonpress() == 3 && is_event_win() && cursor_inside())
1334         {
1335                 BC_ListBox::deactivate_selection();
1336                 gui->assetlist_menu->update_titles();
1337                 gui->assetlist_menu->activate_menu();
1338                 result = 1;
1339         }
1340
1341
1342         return result;
1343 }
1344
1345
1346 int AWindowAssets::handle_event()
1347 {
1348 //printf("AWindowAssets::handle_event 1 %d %d\n", get_buttonpress(), get_selection(0, 0));
1349         if(get_selection(0, 0))
1350         {
1351                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1352                 {
1353                 }
1354                 else
1355                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1356                 {
1357                 }
1358                 else
1359                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1360                 {
1361                 }
1362                 else
1363                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1364                 {
1365                 }
1366                 else
1367                 if(mwindow->vwindows.size())
1368                 {
1369 //printf("AWindowAssets::handle_event 2 %d %d\n", get_buttonpress(), get_selection(0, 0));
1370                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->lock_window("AWindowAssets::handle_event");
1371                         
1372                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1373                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->indexable);
1374                         else
1375                         if(((AssetPicon*)get_selection(0, 0))->edl)
1376                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->edl);
1377
1378                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->unlock_window();
1379                 }
1380                 return 1;
1381         }
1382
1383         return 0;
1384 }
1385
1386 int AWindowAssets::selection_changed()
1387 {
1388 // Show popup window
1389         if(get_button_down() && get_buttonpress() == 3 && get_selection(0, 0))
1390         {
1391                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER) || 
1392                         !strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER) ||
1393                         !strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER) ||
1394                         !strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1395                 {
1396                         gui->assetlist_menu->update_titles();
1397                         gui->assetlist_menu->activate_menu();
1398                 }
1399                 else
1400                 {
1401                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1402                                 gui->asset_menu->update();
1403                         else
1404                         if(((AssetPicon*)get_selection(0, 0))->edl)
1405                                 gui->asset_menu->update();
1406
1407
1408
1409                         gui->asset_menu->activate_menu();
1410                 }
1411
1412                 BC_ListBox::deactivate_selection();
1413                 return 1;
1414         }
1415         return 0;
1416 }
1417
1418 void AWindowAssets::draw_background()
1419 {
1420         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1421         set_color(RED);
1422         set_font(LARGEFONT);
1423         draw_text(get_w() - 
1424                         get_text_width(LARGEFONT, mwindow->edl->session->current_folder) - 4, 
1425                 30, 
1426                 mwindow->edl->session->current_folder, 
1427                 -1, 
1428                 get_bg_surface());
1429 }
1430
1431 int AWindowAssets::drag_start_event()
1432 {
1433         int collect_pluginservers = 0;
1434         int collect_assets = 0;
1435
1436         if(BC_ListBox::drag_start_event())
1437         {
1438                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1439                 {
1440                         mwindow->session->current_operation = DRAG_AEFFECT;
1441                         collect_pluginservers = 1;
1442                 }
1443                 else
1444                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1445                 {
1446                         mwindow->session->current_operation = DRAG_VEFFECT;
1447                         collect_pluginservers = 1;
1448                 }
1449                 else
1450                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1451                 {
1452                         mwindow->session->current_operation = DRAG_ATRANSITION;
1453                         collect_pluginservers = 1;
1454                 }
1455                 else
1456                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1457                 {
1458                         mwindow->session->current_operation = DRAG_VTRANSITION;
1459                         collect_pluginservers = 1;
1460                 }
1461                 else
1462                 {
1463                         mwindow->session->current_operation = DRAG_ASSET;
1464                         collect_assets = 1;
1465                 }
1466                 
1467                 
1468                 if(collect_pluginservers)
1469                 {
1470                         int i = 0;
1471                         mwindow->session->drag_pluginservers->remove_all();
1472                         while(1)
1473                         {
1474                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1475                                 if(!result) break;
1476                                 
1477                                 mwindow->session->drag_pluginservers->append(result->plugin);
1478                         }
1479                 }
1480                 
1481                 if(collect_assets)
1482                 {
1483                         gui->collect_assets();
1484                 }
1485
1486                 return 1;
1487         }
1488         return 0;
1489 }
1490
1491 int AWindowAssets::drag_motion_event()
1492 {
1493         BC_ListBox::drag_motion_event();
1494         unlock_window();
1495
1496         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1497         mwindow->gui->drag_motion();
1498         mwindow->gui->unlock_window();
1499
1500         for(int i = 0; i < mwindow->vwindows.size(); i++)
1501         {
1502                 VWindow *vwindow = mwindow->vwindows.get(i);
1503                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1504                 vwindow->gui->drag_motion();
1505                 vwindow->gui->unlock_window();
1506         }
1507
1508         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1509         mwindow->cwindow->gui->drag_motion();
1510         mwindow->cwindow->gui->unlock_window();
1511
1512         lock_window("AWindowAssets::drag_motion_event");
1513         return 0;
1514 }
1515
1516 int AWindowAssets::drag_stop_event()
1517 {
1518         int result = 0;
1519
1520         result = gui->drag_stop();
1521
1522         unlock_window();
1523
1524         if(!result)
1525         {
1526                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1527                 result = mwindow->gui->drag_stop();
1528                 mwindow->gui->unlock_window();
1529         }
1530
1531         if(!result) 
1532         {
1533                 for(int i = 0; i < mwindow->vwindows.size(); i++)
1534                 {
1535                         VWindow *vwindow = mwindow->vwindows.get(i);
1536                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1537                         result = vwindow->gui->drag_stop();
1538                         vwindow->gui->unlock_window();
1539                 }
1540         }
1541
1542         if(!result) 
1543         {
1544                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1545                 result = mwindow->cwindow->gui->drag_stop();
1546                 mwindow->cwindow->gui->unlock_window();
1547         }
1548
1549         lock_window("AWindowAssets::drag_stop_event");
1550
1551         if(result) get_drag_popup()->set_animation(0);
1552
1553         BC_ListBox::drag_stop_event();
1554         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1555         return 0;
1556 }
1557
1558 int AWindowAssets::column_resize_event()
1559 {
1560         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1561         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1562         return 1;
1563 }
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1577  : BC_Button(x, y, mwindow->theme->newbin_data)
1578 {
1579         this->mwindow = mwindow;
1580         this->gui = gui;
1581         set_tooltip(_("New bin"));
1582 }
1583
1584 int AWindowNewFolder::handle_event()
1585 {
1586         gui->newfolder_thread->start_new_folder();
1587         return 1;
1588 }
1589
1590 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1591  : BC_Button(x, y, mwindow->theme->deletebin_data)
1592 {
1593         this->mwindow = mwindow;
1594         this->gui = gui;
1595         set_tooltip(_("Delete bin"));
1596 }
1597
1598 int AWindowDeleteFolder::handle_event()
1599 {
1600         if(gui->folder_list->get_selection(0, 0))
1601         {
1602                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1603                 mwindow->delete_folder(folder->get_text());
1604         }
1605         return 1;
1606 }
1607
1608 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1609  : BC_Button(x, y, mwindow->theme->renamebin_data)
1610 {
1611         this->mwindow = mwindow;
1612         this->gui = gui;
1613         set_tooltip(_("Rename bin"));
1614 }
1615
1616 int AWindowRenameFolder::handle_event()
1617 {
1618         return 1;
1619 }
1620
1621 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1622  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1623 {
1624         this->mwindow = mwindow;
1625         this->gui = gui;
1626         set_tooltip(_("Delete asset from disk"));
1627 }
1628
1629 int AWindowDeleteDisk::handle_event()
1630 {
1631         return 1;
1632 }
1633
1634 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1635  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1636 {
1637         this->mwindow = mwindow;
1638         this->gui = gui;
1639         set_tooltip(_("Delete asset from project"));
1640 }
1641
1642 int AWindowDeleteProject::handle_event()
1643 {
1644         return 1;
1645 }
1646
1647 AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1648  : BC_Button(x, y, mwindow->theme->infoasset_data)
1649 {
1650         this->mwindow = mwindow;
1651         this->gui = gui;
1652         set_tooltip(_("Edit information on asset"));
1653 }
1654
1655 int AWindowInfo::handle_event()
1656 {
1657         gui->awindow->asset_edit->edit_asset(gui->selected_asset());
1658         return 1;
1659 }
1660
1661 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1662  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1663 {
1664         this->mwindow = mwindow;
1665         this->gui = gui;
1666         set_tooltip(_("Redraw index"));
1667 }
1668
1669 int AWindowRedrawIndex::handle_event()
1670 {
1671         return 1;
1672 }
1673
1674 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1675  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1676 {
1677         this->mwindow = mwindow;
1678         this->gui = gui;
1679         set_tooltip(_("Paste asset on recordable tracks"));
1680 }
1681
1682 int AWindowPaste::handle_event()
1683 {
1684         return 1;
1685 }
1686
1687 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1688  : BC_Button(x, y, mwindow->theme->appendasset_data)
1689 {
1690         this->mwindow = mwindow;
1691         this->gui = gui;
1692         set_tooltip(_("Append asset in new tracks"));
1693 }
1694
1695 int AWindowAppend::handle_event()
1696 {
1697         return 1;
1698 }
1699
1700 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1701  : BC_Button(x, y, mwindow->theme->viewasset_data)
1702 {
1703         this->mwindow = mwindow;
1704         this->gui = gui;
1705         set_tooltip(_("View asset"));
1706 }
1707
1708 int AWindowView::handle_event()
1709 {
1710         return 1;
1711 }
1712
1713 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w)
1714  : BC_MenuBar(x, y, w)
1715 {
1716         this->mwindow = mwindow;
1717         this->gui = gui;
1718 }
1719
1720 void AddTools::create_objects()
1721 {
1722         add_menu(add_plugins = new AddPluginsMenu(mwindow, gui));
1723         add_plugins->create_objects();
1724 }
1725
1726 AddPluginsMenu::AddPluginsMenu(MWindow *mwindow, AWindowGUI *gui)
1727  : BC_Menu("Add Tools")
1728 {
1729         this->mwindow = mwindow;
1730         this->gui = gui;
1731 }
1732
1733 void AddPluginsMenu::create_objects()
1734 {
1735         uint32_t vis = 0;
1736         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1737                 PluginServer *plugin = MWindow::plugindb->get(i);
1738                 if( !plugin->audio && !plugin->video ) continue;
1739                 int idx = plugin->dir_idx;
1740                 uint32_t msk = 1 << idx;
1741                 if( (msk & vis) != 0 ) continue;
1742                 vis |= msk;
1743                 char parent[BCTEXTLEN];
1744                 strcpy(parent, plugin->path);
1745                 char *cp = strrchr(parent, '/');
1746                 if( !cp ) continue;
1747                 *cp = 0;
1748                 char *bp = strrchr(parent, '/');
1749                 if( !bp ) bp = parent; else ++bp;
1750                 if( !strcmp(bp, "ladspa") )
1751                         gui->plugin_visibility &= ~(1 << idx);
1752                 add_item(new AddPluginItem(this, bp, idx));
1753         }
1754                 
1755 }
1756
1757 AddPluginItem::AddPluginItem(AddPluginsMenu *menu, char const *text, int idx)
1758  : BC_MenuItem(text)
1759 {
1760         this->menu = menu;
1761         this->idx = idx;
1762         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1763         int chk = (msk & vis) ? 1 : 0;
1764         set_checked(chk);
1765 }
1766
1767 int AddPluginItem::handle_event()
1768 {
1769         int chk = get_checked() ^ 1;
1770         set_checked(chk);
1771         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1772         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
1773         menu->gui->update_effects();
1774         menu->gui->update_assets();
1775         return 1;
1776 }
1777