initial commit
[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 "colormodels.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 }
683
684 BC_Window* AWindowRemovePlugin::new_gui()
685 {
686         int x = awindow->gui->get_abs_cursor_x(0);
687         int y = awindow->gui->get_abs_cursor_y(0);
688         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
689         gui->create_objects();
690         return gui;
691 }
692
693 int AWindowGUI::keypress_event()
694 {
695         switch(get_keypress()) {
696         case 'w': case 'W':
697                 if(ctrl_down()) {
698                         close_event();
699                         return 1;
700                 }
701                 break;
702         case DELETE:
703                 if(shift_down()) {
704                         PluginServer* plugin = selected_plugin();
705                         if( !plugin ) break;
706                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
707                         unlock_window();
708                         remove_plugin->start();
709                         lock_window();
710                 }
711         }
712         return 0;
713 }
714
715 void AWindowGUI::update_folder_list()
716 {
717 //printf("AWindowGUI::update_folder_list 1\n");
718         for(int i = 0; i < folders.total; i++)
719         {
720                 AssetPicon *picon = (AssetPicon*)folders.values[i];
721                 picon->in_use--;
722         }
723 //printf("AWindowGUI::update_folder_list 1\n");
724
725 // Search assets for folders
726         for(int i = 0; i < mwindow->edl->folders.total; i++)
727         {
728                 char *folder = mwindow->edl->folders.values[i];
729                 int exists = 0;
730 //printf("AWindowGUI::update_folder_list 1.1\n");
731
732                 for(int j = 0; j < folders.total; j++)
733                 {
734                         AssetPicon *picon = (AssetPicon*)folders.values[j];
735                         if(!strcasecmp(picon->get_text(), folder))
736                         {
737                                 exists = 1;
738                                 picon->in_use = 1;
739                                 break;
740                         }
741                 }
742
743                 if(!exists)
744                 {
745                         AssetPicon *picon = new AssetPicon(mwindow, this, folder);
746                         picon->create_objects();
747                         folders.append(picon);
748                 }
749 //printf("AWindowGUI::update_folder_list 1.3\n");
750         }
751 //printf("AWindowGUI::update_folder_list 1\n");
752 //for(int i = 0; i < folders.total; i++)
753 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
754
755 // Delete excess
756         for(int i = folders.total - 1; i >= 0; i--)
757         {
758                 AssetPicon *picon = (AssetPicon*)folders.values[i];
759                 if(!picon->in_use && !picon->persistent)
760                 {
761                         delete picon;
762                         folders.remove_number(i);
763                 }
764         }
765 //for(int i = 0; i < folders.total; i++)
766 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
767 //printf("AWindowGUI::update_folder_list 2\n");
768 }
769
770 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output, 
771         int do_audio, int do_video, int is_realtime, int is_transition)
772 {
773         ArrayList<PluginServer*> plugin_list;
774 // Get pointers to plugindb entries
775         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
776                         0, plugin_list);
777
778         for(int i = 0; i < plugin_list.total; i++) {
779                 PluginServer *server = plugin_list.values[i];
780                 int visible = plugin_visibility & (1<<server->dir_idx);
781                 if(!visible) continue;
782 // Create new listitem
783                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
784                 picon->create_objects();
785                 output->append(picon);
786         }
787 }
788
789 void AWindowGUI::update_asset_list()
790 {
791 //printf("AWindowGUI::update_asset_list 1\n");
792         for(int i = 0; i < assets.total; i++)
793         {
794                 AssetPicon *picon = (AssetPicon*)assets.values[i];
795                 picon->in_use--;
796         }
797
798
799
800
801
802 //printf("AWindowGUI::update_asset_list 2\n");
803
804
805 // Synchronize EDL clips
806         for(int i = 0; i < mwindow->edl->clips.total; i++)
807         {
808                 int exists = 0;
809                 
810 // Look for clip in existing listitems
811                 for(int j = 0; j < assets.total && !exists; j++)
812                 {
813                         AssetPicon *picon = (AssetPicon*)assets.values[j];
814                         
815                         if(picon->id == mwindow->edl->clips.values[i]->id)
816                         {
817                                 picon->edl = mwindow->edl->clips.values[i];
818                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
819                                 exists = 1;
820                                 picon->in_use = 1;
821                         }
822                 }
823
824 // Create new listitem
825                 if(!exists)
826                 {
827                         AssetPicon *picon = new AssetPicon(mwindow, 
828                                 this, 
829                                 mwindow->edl->clips.values[i]);
830                         picon->create_objects();
831                         assets.append(picon);
832                 }
833         }
834
835
836
837
838
839 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
840
841
842 // Synchronize EDL assets
843         for(Asset *current = mwindow->edl->assets->first; 
844                 current; 
845                 current = NEXT)
846         {
847                 int exists = 0;
848
849 // Look for asset in existing listitems
850                 for(int j = 0; j < assets.total && !exists; j++)
851                 {
852                         AssetPicon *picon = (AssetPicon*)assets.values[j];
853
854                         if(picon->id == current->id)
855                         {
856                                 picon->indexable = current;
857                                 exists = 1;
858                                 picon->in_use = 1;
859                                 break;
860                         }
861                 }
862
863 // Create new listitem
864                 if(!exists)
865                 {
866 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
867                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
868 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
869                         picon->create_objects();
870 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
871                         assets.append(picon);
872                 }
873         }
874
875
876
877 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
878
879
880 // Synchronize nested EDLs
881         for(int i = 0; i < mwindow->edl->nested_edls->size(); i++)
882         {
883                 int exists = 0;
884                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
885
886 // Look for asset in existing listitems
887                 for(int j = 0; j < assets.total && !exists; j++)
888                 {
889                         AssetPicon *picon = (AssetPicon*)assets.values[j];
890
891                         if(picon->id == indexable->id)
892                         {
893                                 picon->indexable = indexable;
894                                 exists = 1;
895                                 picon->in_use = 1;
896                                 break;
897                         }
898                 }
899
900 // Create new listitem
901                 if(!exists)
902                 {
903                         AssetPicon *picon = new AssetPicon(mwindow, 
904                                 this, 
905                                 indexable);
906                         picon->create_objects();
907                         assets.append(picon);
908                 }
909         }
910
911
912
913
914
915
916
917
918
919 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
920         for(int i = assets.size() - 1; i >= 0; i--)
921         {
922                 AssetPicon *picon = (AssetPicon*)assets.get(i);
923 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
924                 if(!picon->in_use)
925                 {
926                         delete picon;
927                         assets.remove_number(i);
928                 }
929         }
930 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
931 }
932
933
934
935
936
937 void AWindowGUI::sort_assets()
938 {
939 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
940         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
941                 sort_picons(&aeffects, 
942                         0);
943         else
944         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
945                 sort_picons(&veffects, 
946                         0);
947         else
948         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
949                 sort_picons(&atransitions, 
950                         0);
951         else
952         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
953                 sort_picons(&vtransitions, 
954                         0);
955         else
956                 sort_picons(&assets, 
957                         mwindow->edl->session->current_folder);
958
959         update_assets();
960 }
961
962
963
964
965
966
967
968
969
970
971
972 void AWindowGUI::collect_assets()
973 {
974         int i = 0;
975         mwindow->session->drag_assets->remove_all();
976         mwindow->session->drag_clips->remove_all();
977         while(1)
978         {
979                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
980                 if(!result) break;
981
982                 if(result->indexable) mwindow->session->drag_assets->append(result->indexable);
983                 if(result->edl) mwindow->session->drag_clips->append(result->edl);
984         }
985 }
986
987 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst, 
988         ArrayList<BC_ListBoxItem*> *src, 
989         char *folder)
990 {
991 // Remove current pointers
992         dst[0].remove_all();
993         dst[1].remove_all_objects();
994
995 // Create new pointers
996 //if(folder) printf("AWindowGUI::copy_picons 1 %s\n", folder);
997         for(int i = 0; i < src->total; i++)
998         {
999                 AssetPicon *picon = (AssetPicon*)src->values[i];
1000 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
1001                 if(!folder ||
1002                         (folder && picon->indexable && !strcasecmp(picon->indexable->folder, folder)) ||
1003                         (folder && picon->edl && !strcasecmp(picon->edl->local_session->folder, folder)))
1004                 {
1005                         BC_ListBoxItem *item2, *item1;
1006                         dst[0].append(item1 = picon);
1007                         if(picon->edl)
1008                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1009                         else
1010                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1011                         item1->set_autoplace_text(1);
1012                         item2->set_autoplace_text(1);
1013 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
1014                 }
1015         }
1016 }
1017
1018 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, 
1019                 char *folder)
1020 {
1021 //printf("AWindowGUI::sort_picons 1\n")
1022         int done = 0;
1023         while(!done)
1024         {
1025                 done = 1;
1026                 for(int i = 0; i < src->total - 1; i++)
1027                 {
1028                         BC_ListBoxItem *item1 = src->values[i];
1029                         BC_ListBoxItem *item2 = src->values[i + 1];
1030                         item1->set_autoplace_icon(1);
1031                         item2->set_autoplace_icon(1);
1032                         item1->set_autoplace_text(1);
1033                         item2->set_autoplace_text(1);
1034                         if(strcmp(item1->get_text(), item2->get_text()) > 0)
1035                         {
1036                                 src->values[i + 1] = item1;
1037                                 src->values[i] = item2;
1038                                 done = 0;
1039                         }
1040                 }
1041         }
1042 }
1043
1044
1045 void AWindowGUI::filter_displayed_assets()
1046 {
1047         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1048                 copy_picons(displayed_assets, 
1049                         &aeffects, 
1050                         0);
1051         else
1052         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1053                 copy_picons(displayed_assets, 
1054                         &veffects, 
1055                         0);
1056         else
1057         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1058                 copy_picons(displayed_assets, 
1059                         &atransitions, 
1060                         0);
1061         else
1062         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1063                 copy_picons(displayed_assets, 
1064                         &vtransitions, 
1065                         0);
1066         else
1067                 copy_picons(displayed_assets, 
1068                         &assets, 
1069                         mwindow->edl->session->current_folder);
1070 }
1071
1072
1073 void AWindowGUI::update_assets()
1074 {
1075 //printf("AWindowGUI::update_assets 1\n");
1076         update_folder_list();
1077 //printf("AWindowGUI::update_assets 2\n");
1078         update_asset_list();
1079 //printf("AWindowGUI::update_assets 3\n");
1080         filter_displayed_assets();
1081
1082 //for(int i = 0; i < folders.total; i++)
1083 //printf("AWindowGUI::update_assets 4\n");
1084 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
1085         if(mwindow->edl->session->folderlist_format != folder_list->get_format())
1086                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1087         folder_list->update(&folders,
1088                 0,
1089                 0,
1090                 1,
1091                 folder_list->get_xposition(),
1092                 folder_list->get_yposition(),
1093                 -1);
1094 //printf("AWindowGUI::update_assets 5\n");
1095
1096         if(mwindow->edl->session->assetlist_format != asset_list->get_format())
1097                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1098
1099
1100 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
1101         asset_list->update(displayed_assets,
1102                 asset_titles,
1103                 mwindow->edl->session->asset_columns,
1104                 ASSET_COLUMNS, 
1105                 asset_list->get_xposition(),
1106                 asset_list->get_yposition(),
1107                 -1,
1108                 0);
1109 //printf("AWindowGUI::update_assets 7\n");
1110
1111         flush();
1112 //printf("AWindowGUI::update_assets 8\n");
1113         return;
1114 }
1115
1116 void AWindowGUI::update_effects()
1117 {
1118         aeffects.remove_all_objects();
1119         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1120         veffects.remove_all_objects();
1121         create_persistent_folder(&veffects, 0, 1, 1, 0);
1122         atransitions.remove_all_objects();
1123         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1124         vtransitions.remove_all_objects();
1125         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1126 }
1127
1128 int AWindowGUI::current_folder_number()
1129 {
1130         int result = -1;
1131         for(int i = 0; i < folders.total; i++)
1132         {
1133                 if(!strcasecmp(folders.values[i]->get_text(), mwindow->edl->session->current_folder))
1134                 {
1135                         result = i;
1136                         break;
1137                 }
1138         }
1139         return result;
1140 }
1141
1142 int AWindowGUI::drag_motion()
1143 {
1144         if(get_hidden()) return 0;
1145
1146         int result = 0;
1147         return result;
1148 }
1149
1150 int AWindowGUI::drag_stop()
1151 {
1152         if(get_hidden()) return 0;
1153
1154         return 0;
1155 }
1156
1157 Indexable* AWindowGUI::selected_asset()
1158 {
1159         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1160         return picon ? picon->indexable : 0;
1161 }
1162
1163 PluginServer* AWindowGUI::selected_plugin()
1164 {
1165         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1166         return picon ? picon->plugin : 0;
1167 }
1168
1169 AssetPicon* AWindowGUI::selected_folder()
1170 {
1171         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1172         return picon;
1173 }
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1185  : BC_SubWindow(x, y, w, h)
1186 {
1187         this->mwindow = mwindow;
1188         this->gui = gui;
1189 }
1190 AWindowDivider::~AWindowDivider()
1191 {
1192 }
1193
1194 int AWindowDivider::button_press_event()
1195 {
1196         if(is_event_win() && cursor_inside())
1197         {
1198                 mwindow->session->current_operation = DRAG_PARTITION;
1199                 return 1;
1200         }
1201         return 0;
1202 }
1203
1204 int AWindowDivider::cursor_motion_event()
1205 {
1206         if(mwindow->session->current_operation == DRAG_PARTITION)
1207         {
1208                 mwindow->session->afolders_w = gui->get_relative_cursor_x();
1209                 gui->reposition_objects();
1210         }
1211         return 0;
1212 }
1213
1214 int AWindowDivider::button_release_event()
1215 {
1216         if(mwindow->session->current_operation == DRAG_PARTITION)
1217         {
1218                 mwindow->session->current_operation = NO_OPERATION;
1219                 return 1;
1220         }
1221         return 0;
1222 }
1223
1224
1225
1226
1227
1228
1229 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1230  : BC_ListBox(x, 
1231                 y, 
1232                 w, 
1233                 h,
1234                 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ? 
1235                         LISTBOX_ICONS : LISTBOX_TEXT, 
1236                 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
1237                 0,             // Titles for columns.  Set to 0 for no titles
1238                 0,                // width of each column
1239                 1,                      // Total columns.
1240                 0,                    // Pixel of top of window.
1241                 0,                        // If this listbox is a popup window
1242                 LISTBOX_SINGLE,  // Select one item or multiple items
1243                 ICON_TOP,        // Position of icon relative to text of each item
1244                 1)               // Allow drags
1245 {
1246         this->mwindow = mwindow;
1247         this->gui = gui;
1248         set_drag_scroll(0);
1249 }
1250
1251 AWindowFolders::~AWindowFolders()
1252 {
1253 }
1254         
1255 int AWindowFolders::selection_changed()
1256 {
1257         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1258         if(picon)
1259         {
1260                 if(get_button_down() && get_buttonpress() == 3)
1261                 {
1262                         gui->folderlist_menu->update_titles();
1263                         gui->folderlist_menu->activate_menu();
1264                 }
1265
1266                 strcpy(mwindow->edl->session->current_folder, picon->get_text());
1267 //printf("AWindowFolders::selection_changed 1\n");
1268                 gui->asset_list->draw_background();
1269                 gui->update_assets();
1270         }
1271         return 1;
1272 }
1273
1274 int AWindowFolders::button_press_event()
1275 {
1276         int result = 0;
1277
1278         result = BC_ListBox::button_press_event();
1279
1280         if(!result)
1281         {
1282                 if(get_buttonpress() == 3 && is_event_win() && cursor_inside())
1283                 {
1284                         gui->folderlist_menu->update_titles();
1285                         gui->folderlist_menu->activate_menu();
1286                         result = 1;
1287                 }
1288         }
1289
1290
1291         return result;
1292 }
1293
1294
1295
1296
1297
1298
1299
1300 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1301  : BC_ListBox(x, 
1302                 y, 
1303                 w, 
1304                 h,
1305                 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? 
1306                         LISTBOX_ICONS : LISTBOX_TEXT,
1307                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1308                 gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
1309                 mwindow->edl->session->asset_columns,                // width of each column
1310                 1,                      // Total columns.
1311                 0,                    // Pixel of top of window.
1312                 0,                        // If this listbox is a popup window
1313                 LISTBOX_MULTIPLE,  // Select one item or multiple items
1314                 ICON_TOP,        // Position of icon relative to text of each item
1315                 1)               // Allow drag
1316 {
1317         this->mwindow = mwindow;
1318         this->gui = gui;
1319         set_drag_scroll(0);
1320 }
1321
1322 AWindowAssets::~AWindowAssets()
1323 {
1324 }
1325
1326 int AWindowAssets::button_press_event()
1327 {
1328         int result = 0;
1329
1330         result = BC_ListBox::button_press_event();
1331
1332         if(!result && get_buttonpress() == 3 && is_event_win() && cursor_inside())
1333         {
1334                 BC_ListBox::deactivate_selection();
1335                 gui->assetlist_menu->update_titles();
1336                 gui->assetlist_menu->activate_menu();
1337                 result = 1;
1338         }
1339
1340
1341         return result;
1342 }
1343
1344
1345 int AWindowAssets::handle_event()
1346 {
1347 //printf("AWindowAssets::handle_event 1 %d %d\n", get_buttonpress(), get_selection(0, 0));
1348         if(get_selection(0, 0))
1349         {
1350                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1351                 {
1352                 }
1353                 else
1354                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1355                 {
1356                 }
1357                 else
1358                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1359                 {
1360                 }
1361                 else
1362                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1363                 {
1364                 }
1365                 else
1366                 if(mwindow->vwindows.size())
1367                 {
1368 //printf("AWindowAssets::handle_event 2 %d %d\n", get_buttonpress(), get_selection(0, 0));
1369                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->lock_window("AWindowAssets::handle_event");
1370                         
1371                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1372                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->indexable);
1373                         else
1374                         if(((AssetPicon*)get_selection(0, 0))->edl)
1375                                 mwindow->vwindows.get(DEFAULT_VWINDOW)->change_source(((AssetPicon*)get_selection(0, 0))->edl);
1376
1377                         mwindow->vwindows.get(DEFAULT_VWINDOW)->gui->unlock_window();
1378                 }
1379                 return 1;
1380         }
1381
1382         return 0;
1383 }
1384
1385 int AWindowAssets::selection_changed()
1386 {
1387 // Show popup window
1388         if(get_button_down() && get_buttonpress() == 3 && get_selection(0, 0))
1389         {
1390                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER) || 
1391                         !strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER) ||
1392                         !strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER) ||
1393                         !strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1394                 {
1395                         gui->assetlist_menu->update_titles();
1396                         gui->assetlist_menu->activate_menu();
1397                 }
1398                 else
1399                 {
1400                         if(((AssetPicon*)get_selection(0, 0))->indexable)
1401                                 gui->asset_menu->update();
1402                         else
1403                         if(((AssetPicon*)get_selection(0, 0))->edl)
1404                                 gui->asset_menu->update();
1405
1406
1407
1408                         gui->asset_menu->activate_menu();
1409                 }
1410
1411                 BC_ListBox::deactivate_selection();
1412                 return 1;
1413         }
1414         return 0;
1415 }
1416
1417 void AWindowAssets::draw_background()
1418 {
1419         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1420         set_color(RED);
1421         set_font(LARGEFONT);
1422         draw_text(get_w() - 
1423                         get_text_width(LARGEFONT, mwindow->edl->session->current_folder) - 4, 
1424                 30, 
1425                 mwindow->edl->session->current_folder, 
1426                 -1, 
1427                 get_bg_surface());
1428 }
1429
1430 int AWindowAssets::drag_start_event()
1431 {
1432         int collect_pluginservers = 0;
1433         int collect_assets = 0;
1434
1435         if(BC_ListBox::drag_start_event())
1436         {
1437                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1438                 {
1439                         mwindow->session->current_operation = DRAG_AEFFECT;
1440                         collect_pluginservers = 1;
1441                 }
1442                 else
1443                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1444                 {
1445                         mwindow->session->current_operation = DRAG_VEFFECT;
1446                         collect_pluginservers = 1;
1447                 }
1448                 else
1449                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1450                 {
1451                         mwindow->session->current_operation = DRAG_ATRANSITION;
1452                         collect_pluginservers = 1;
1453                 }
1454                 else
1455                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1456                 {
1457                         mwindow->session->current_operation = DRAG_VTRANSITION;
1458                         collect_pluginservers = 1;
1459                 }
1460                 else
1461                 {
1462                         mwindow->session->current_operation = DRAG_ASSET;
1463                         collect_assets = 1;
1464                 }
1465                 
1466                 
1467                 if(collect_pluginservers)
1468                 {
1469                         int i = 0;
1470                         mwindow->session->drag_pluginservers->remove_all();
1471                         while(1)
1472                         {
1473                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1474                                 if(!result) break;
1475                                 
1476                                 mwindow->session->drag_pluginservers->append(result->plugin);
1477                         }
1478                 }
1479                 
1480                 if(collect_assets)
1481                 {
1482                         gui->collect_assets();
1483                 }
1484
1485                 return 1;
1486         }
1487         return 0;
1488 }
1489
1490 int AWindowAssets::drag_motion_event()
1491 {
1492         BC_ListBox::drag_motion_event();
1493         unlock_window();
1494
1495         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1496         mwindow->gui->drag_motion();
1497         mwindow->gui->unlock_window();
1498
1499         for(int i = 0; i < mwindow->vwindows.size(); i++)
1500         {
1501                 VWindow *vwindow = mwindow->vwindows.get(i);
1502                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1503                 vwindow->gui->drag_motion();
1504                 vwindow->gui->unlock_window();
1505         }
1506
1507         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1508         mwindow->cwindow->gui->drag_motion();
1509         mwindow->cwindow->gui->unlock_window();
1510
1511         lock_window("AWindowAssets::drag_motion_event");
1512         return 0;
1513 }
1514
1515 int AWindowAssets::drag_stop_event()
1516 {
1517         int result = 0;
1518
1519         result = gui->drag_stop();
1520
1521         unlock_window();
1522
1523         if(!result)
1524         {
1525                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1526                 result = mwindow->gui->drag_stop();
1527                 mwindow->gui->unlock_window();
1528         }
1529
1530         if(!result) 
1531         {
1532                 for(int i = 0; i < mwindow->vwindows.size(); i++)
1533                 {
1534                         VWindow *vwindow = mwindow->vwindows.get(i);
1535                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1536                         result = vwindow->gui->drag_stop();
1537                         vwindow->gui->unlock_window();
1538                 }
1539         }
1540
1541         if(!result) 
1542         {
1543                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1544                 result = mwindow->cwindow->gui->drag_stop();
1545                 mwindow->cwindow->gui->unlock_window();
1546         }
1547
1548         lock_window("AWindowAssets::drag_stop_event");
1549
1550         if(result) get_drag_popup()->set_animation(0);
1551
1552         BC_ListBox::drag_stop_event();
1553         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1554         return 0;
1555 }
1556
1557 int AWindowAssets::column_resize_event()
1558 {
1559         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1560         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1561         return 1;
1562 }
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1576  : BC_Button(x, y, mwindow->theme->newbin_data)
1577 {
1578         this->mwindow = mwindow;
1579         this->gui = gui;
1580         set_tooltip(_("New bin"));
1581 }
1582
1583 int AWindowNewFolder::handle_event()
1584 {
1585         gui->newfolder_thread->start_new_folder();
1586         return 1;
1587 }
1588
1589 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1590  : BC_Button(x, y, mwindow->theme->deletebin_data)
1591 {
1592         this->mwindow = mwindow;
1593         this->gui = gui;
1594         set_tooltip(_("Delete bin"));
1595 }
1596
1597 int AWindowDeleteFolder::handle_event()
1598 {
1599         if(gui->folder_list->get_selection(0, 0))
1600         {
1601                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1602                 mwindow->delete_folder(folder->get_text());
1603         }
1604         return 1;
1605 }
1606
1607 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1608  : BC_Button(x, y, mwindow->theme->renamebin_data)
1609 {
1610         this->mwindow = mwindow;
1611         this->gui = gui;
1612         set_tooltip(_("Rename bin"));
1613 }
1614
1615 int AWindowRenameFolder::handle_event()
1616 {
1617         return 1;
1618 }
1619
1620 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1621  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1622 {
1623         this->mwindow = mwindow;
1624         this->gui = gui;
1625         set_tooltip(_("Delete asset from disk"));
1626 }
1627
1628 int AWindowDeleteDisk::handle_event()
1629 {
1630         return 1;
1631 }
1632
1633 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1634  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1635 {
1636         this->mwindow = mwindow;
1637         this->gui = gui;
1638         set_tooltip(_("Delete asset from project"));
1639 }
1640
1641 int AWindowDeleteProject::handle_event()
1642 {
1643         return 1;
1644 }
1645
1646 AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1647  : BC_Button(x, y, mwindow->theme->infoasset_data)
1648 {
1649         this->mwindow = mwindow;
1650         this->gui = gui;
1651         set_tooltip(_("Edit information on asset"));
1652 }
1653
1654 int AWindowInfo::handle_event()
1655 {
1656         gui->awindow->asset_edit->edit_asset(gui->selected_asset());
1657         return 1;
1658 }
1659
1660 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1661  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1662 {
1663         this->mwindow = mwindow;
1664         this->gui = gui;
1665         set_tooltip(_("Redraw index"));
1666 }
1667
1668 int AWindowRedrawIndex::handle_event()
1669 {
1670         return 1;
1671 }
1672
1673 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1674  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1675 {
1676         this->mwindow = mwindow;
1677         this->gui = gui;
1678         set_tooltip(_("Paste asset on recordable tracks"));
1679 }
1680
1681 int AWindowPaste::handle_event()
1682 {
1683         return 1;
1684 }
1685
1686 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1687  : BC_Button(x, y, mwindow->theme->appendasset_data)
1688 {
1689         this->mwindow = mwindow;
1690         this->gui = gui;
1691         set_tooltip(_("Append asset in new tracks"));
1692 }
1693
1694 int AWindowAppend::handle_event()
1695 {
1696         return 1;
1697 }
1698
1699 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1700  : BC_Button(x, y, mwindow->theme->viewasset_data)
1701 {
1702         this->mwindow = mwindow;
1703         this->gui = gui;
1704         set_tooltip(_("View asset"));
1705 }
1706
1707 int AWindowView::handle_event()
1708 {
1709         return 1;
1710 }
1711
1712 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w)
1713  : BC_MenuBar(x, y, w)
1714 {
1715         this->mwindow = mwindow;
1716         this->gui = gui;
1717 }
1718
1719 void AddTools::create_objects()
1720 {
1721         add_menu(add_plugins = new AddPluginsMenu(mwindow, gui));
1722         add_plugins->create_objects();
1723 }
1724
1725 AddPluginsMenu::AddPluginsMenu(MWindow *mwindow, AWindowGUI *gui)
1726  : BC_Menu("Add Tools")
1727 {
1728         this->mwindow = mwindow;
1729         this->gui = gui;
1730 }
1731
1732 void AddPluginsMenu::create_objects()
1733 {
1734         uint32_t vis = 0;
1735         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1736                 PluginServer *plugin = MWindow::plugindb->get(i);
1737                 if( !plugin->audio && !plugin->video ) continue;
1738                 int idx = plugin->dir_idx;
1739                 uint32_t msk = 1 << idx;
1740                 if( (msk & vis) != 0 ) continue;
1741                 vis |= msk;
1742                 char parent[BCTEXTLEN];
1743                 strcpy(parent, plugin->path);
1744                 char *cp = strrchr(parent, '/');
1745                 if( !cp ) continue;
1746                 *cp = 0;
1747                 char *bp = strrchr(parent, '/');
1748                 if( !bp ) bp = parent; else ++bp;
1749                 if( !strcmp(bp, "ladspa") )
1750                         gui->plugin_visibility &= ~(1 << idx);
1751                 add_item(new AddPluginItem(this, bp, idx));
1752         }
1753                 
1754 }
1755
1756 AddPluginItem::AddPluginItem(AddPluginsMenu *menu, char const *text, int idx)
1757  : BC_MenuItem(text)
1758 {
1759         this->menu = menu;
1760         this->idx = idx;
1761         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1762         int chk = (msk & vis) ? 1 : 0;
1763         set_checked(chk);
1764 }
1765
1766 int AddPluginItem::handle_event()
1767 {
1768         int chk = get_checked() ^ 1;
1769         set_checked(chk);
1770         uint32_t msk = 1 << idx, vis = menu->gui->plugin_visibility;
1771         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
1772         menu->gui->update_effects();
1773         menu->gui->update_assets();
1774         return 1;
1775 }
1776