search fixes, preset fixes, ladspa icon logging, igor pref theme, drag btn rollover
[goodguy/history.git] / cinelerra-5.1 / 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 "awindow.h"
28 #include "bccmodels.h"
29 #include "bcsignals.h"
30 #include "bchash.h"
31 #include "cache.h"
32 #include "clip.h"
33 #include "clippopup.h"
34 #include "cursors.h"
35 #include "cwindowgui.h"
36 #include "cwindow.h"
37 #include "edl.h"
38 #include "edlsession.h"
39 #include "effectlist.h"
40 #include "file.h"
41 #include "filesystem.h"
42 #include "folderlistmenu.h"
43 #include "indexable.h"
44 #include "keys.h"
45 #include "language.h"
46 #include "labels.h"
47 #include "labelpopup.h"
48 #include "localsession.h"
49 #include "mainmenu.h"
50 #include "mainsession.h"
51 #include "mwindowgui.h"
52 #include "mwindow.h"
53 #include "nestededls.h"
54 #include "newfolder.h"
55 #include "preferences.h"
56 #include "theme.h"
57 #include "vframe.h"
58 #include "vicon.h"
59 #include "vwindowgui.h"
60 #include "vwindow.h"
61
62 #include "data/lad_picon_png.h"
63 #include "data/ff_audio_png.h"
64 #include "data/ff_video_png.h"
65
66 #include<stdio.h>
67 #include<unistd.h>
68 #include<fcntl.h>
69
70
71 const char *AWindowGUI::folder_names[] =
72 {
73         N_("Audio Effects"),
74         N_("Video Effects"),
75         N_("Audio Transitions"),
76         N_("Video Transitions"),
77         N_("Labels"),
78         N_("Clips"),
79         N_("Media"),
80         N_("Proxy"),
81 };
82
83
84 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
85  : VIcon(w, h, framerate)
86 {
87         this->picon = picon;
88         this->length = length;
89         temp = 0;
90 }
91
92 AssetVIcon::~AssetVIcon()
93 {
94         delete temp;
95 }
96
97 VFrame *AssetVIcon::frame()
98 {
99         if( seq_no >= images.size() ) {
100                 MWindow *mwindow = picon->mwindow;
101                 Asset *asset = (Asset *)picon->indexable;
102                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
103                 if( !file ) return 0;
104                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
105                         delete temp;  temp = 0;
106                 }
107                 if( !temp )
108                         temp = new VFrame(asset->width, asset->height, BC_RGB888);
109                 int ww = picon->gui->vicon_thread->view_w;
110                 int hh = picon->gui->vicon_thread->view_h;
111                 while( seq_no >= images.size() ) {
112                         file->set_layer(0);
113                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
114                         file->set_video_position(pos,0);
115                         file->read_frame(temp);
116                         add_image(temp, ww, hh, BC_RGB8);
117                 }
118                 mwindow->video_cache->check_in(asset);
119         }
120         return *images[seq_no];
121 }
122
123 int64_t AssetVIcon::set_seq_no(int64_t no)
124 {
125         if( no >= length ) no = 0;
126         return seq_no = no;
127 }
128
129 int AssetVIcon::get_vx()
130 {
131         BC_ListBox *lbox = picon->gui->asset_list;
132         return lbox->get_item_x(picon);
133 }
134 int AssetVIcon::get_vy()
135 {
136         BC_ListBox *lbox = picon->gui->asset_list;
137         return lbox->get_item_y(picon) + lbox->get_title_h();
138 }
139
140
141 AssetPicon::AssetPicon(MWindow *mwindow,
142         AWindowGUI *gui, Indexable *indexable)
143  : BC_ListBoxItem()
144 {
145         reset();
146         this->mwindow = mwindow;
147         this->gui = gui;
148         this->indexable = indexable;
149         indexable->add_user();
150         this->id = indexable->id;
151 }
152
153 AssetPicon::AssetPicon(MWindow *mwindow,
154         AWindowGUI *gui, EDL *edl)
155  : BC_ListBoxItem()
156 {
157         reset();
158         this->mwindow = mwindow;
159         this->gui = gui;
160         this->edl = edl;
161         edl->add_user();
162         this->id = edl->id;
163 }
164
165 AssetPicon::AssetPicon(MWindow *mwindow,
166         AWindowGUI *gui, int folder, int persist)
167  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]),
168         folder>=0 && folder<AWINDOW_FOLDERS ?
169                 gui->folder_icons[folder]: gui->folder_icon)
170 {
171         reset();
172         foldernum = folder;
173         this->mwindow = mwindow;
174         this->gui = gui;
175         persistent = persist;
176 }
177
178 AssetPicon::AssetPicon(MWindow *mwindow,
179         AWindowGUI *gui, PluginServer *plugin)
180  : BC_ListBoxItem()
181 {
182         reset();
183         this->mwindow = mwindow;
184         this->gui = gui;
185         this->plugin = plugin;
186 }
187
188 AssetPicon::AssetPicon(MWindow *mwindow,
189         AWindowGUI *gui, Label *label)
190  : BC_ListBoxItem()
191 {
192         reset();
193         this->mwindow = mwindow;
194         this->gui = gui;
195         this->label = label;
196         indexable = 0;
197         icon = 0;
198         id = 0;
199 }
200
201 AssetPicon::~AssetPicon()
202 {
203         if( vicon )
204                 gui->vicon_thread->del_vicon(vicon);
205         if( indexable ) indexable->remove_user();
206         if( edl ) edl->remove_user();
207         if( icon && !gui->protected_pixmap(icon) ) {
208                 delete icon;
209                 if( !plugin ) delete icon_vframe;
210         }
211 }
212
213 void AssetPicon::reset()
214 {
215         plugin = 0;
216         label = 0;
217         indexable = 0;
218         edl = 0;
219         foldernum = AW_NO_FOLDER;
220         icon = 0;
221         icon_vframe = 0;
222         vicon = 0;
223         in_use = 1;
224         id = 0;
225         persistent = 0;
226 }
227
228 void AssetPicon::create_objects()
229 {
230         FileSystem fs;
231         char name[BCTEXTLEN];
232         int pixmap_w, pixmap_h;
233
234         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
235
236         if( indexable ) {
237                 fs.extract_name(name, indexable->path);
238                 set_text(name);
239         }
240
241         if( indexable && indexable->is_asset ) {
242                 Asset *asset = (Asset*)indexable;
243                 if( asset->video_data ) {
244                         if( mwindow->preferences->use_thumbnails ) {
245                                 gui->unlock_window();
246                                 File *file = mwindow->video_cache->check_out(asset,
247                                         mwindow->edl,
248                                         1);
249
250                                 if( file ) {
251                                         int height = asset->height > 0 ? asset->height : 1;
252                                         pixmap_w = pixmap_h * asset->width / height;
253
254                                         file->set_layer(0);
255                                         file->set_video_position(0, 0);
256
257                                         if( gui->temp_picon &&
258                                                 (gui->temp_picon->get_w() != asset->width ||
259                                                 gui->temp_picon->get_h() != asset->height) ) {
260                                                 delete gui->temp_picon;
261                                                 gui->temp_picon = 0;
262                                         }
263
264                                         if( !gui->temp_picon ) {
265                                                 gui->temp_picon = new VFrame(0, -1,
266                                                         asset->width, asset->height,
267                                                         BC_RGB888, -1);
268                                         }
269                                         { char string[BCTEXTLEN];
270                                         sprintf(string, _("Reading %s"), name);
271                                         mwindow->gui->lock_window("AssetPicon::create_objects");
272                                         mwindow->gui->show_message(string);
273                                         mwindow->gui->unlock_window(); }
274                                         file->read_frame(gui->temp_picon);
275                                         mwindow->video_cache->check_in(asset);
276
277                                         gui->lock_window("AssetPicon::create_objects 1");
278                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
279                                         icon->draw_vframe(gui->temp_picon,
280                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
281                                         icon_vframe = new VFrame(0,
282                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
283                                         icon_vframe->transfer_from(gui->temp_picon);
284                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
285 // vicon images
286                                                 double framerate = asset->get_frame_rate();
287                                                 if( !framerate ) framerate = VICON_RATE;
288                                                 int64_t frames = asset->get_video_frames();
289                                                 double secs = frames / framerate;
290                                                 if( secs > 5 ) secs = 5;
291                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
292                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
293                                                 gui->vicon_thread->add_vicon(vicon);
294                                         }
295
296                                 }
297                                 else {
298                                         gui->lock_window("AssetPicon::create_objects 2");
299                                         icon = gui->video_icon;
300                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
301                                 }
302                         }
303                         else {
304                                 icon = gui->video_icon;
305                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
306                         }
307                 }
308                 else
309                 if( asset->audio_data ) {
310                         icon = gui->audio_icon;
311                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
312                 }
313
314         }
315         else
316         if( indexable && !indexable->is_asset ) {
317                 icon = gui->video_icon;
318                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
319         }
320         else
321         if( edl ) {
322                 set_text(strcpy(name, edl->local_session->clip_title));
323                 icon = gui->clip_icon;
324                 icon_vframe = mwindow->theme->get_image("clip_icon");
325         }
326         else
327         if( plugin ) {
328                 strcpy(name,  plugin->title);
329                 set_text(name);
330                 icon_vframe = plugin->get_picon();
331                 if( icon_vframe )
332                         icon = gui->create_pixmap(icon_vframe);
333                 else if( plugin->audio ) {
334                         if( plugin->transition ) {
335                                 icon = gui->atransition_icon;
336                                 icon_vframe = gui->atransition_vframe;
337                         }
338                         else if( plugin->is_ffmpeg() ) {
339                                 icon = gui->ff_aud_icon;
340                                 icon_vframe = gui->ff_aud_vframe;
341                         }
342                         else if( plugin->is_ladspa() ) {
343                                 icon = gui->ladspa_icon;
344                                 icon_vframe = gui->ladspa_vframe;
345                         }
346                         else {
347                                 icon = gui->aeffect_icon;
348                                 icon_vframe = gui->aeffect_vframe;
349                         }
350                 }
351                 else if( plugin->video ) {
352                         if( plugin->transition ) {
353                                 icon = gui->vtransition_icon;
354                                 icon_vframe = gui->vtransition_vframe;
355                         }
356                         else if( plugin->is_ffmpeg() ) {
357                                 icon = gui->ff_vid_icon;
358                                 icon_vframe = gui->ff_vid_vframe;
359                         }
360                         else {
361                                 icon = gui->veffect_icon;
362                                 icon_vframe = gui->veffect_vframe;
363                         }
364                 }
365         }
366         else
367         if( label ) {
368                 Units::totext(name,
369                               label->position,
370                               mwindow->edl->session->time_format,
371                               mwindow->edl->session->sample_rate,
372                               mwindow->edl->session->frame_rate,
373                               mwindow->edl->session->frames_per_foot);
374                 set_text(name);
375                 icon = gui->label_icon;
376                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL];
377                 set_icon(icon);
378                 set_icon_vframe(icon_vframe);
379         }
380         if( !icon ) {
381                 icon = gui->file_icon;
382                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
383         }
384         set_icon(icon);
385         set_icon_vframe(icon_vframe);
386 }
387
388 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
389  : BC_Window(_(PROGRAM_NAME ": Resources"),
390         mwindow->session->awindow_x, mwindow->session->awindow_y,
391         mwindow->session->awindow_w, mwindow->session->awindow_h,
392         100, 100, 1, 1, 1)
393 {
394         this->mwindow = mwindow;
395         this->awindow = awindow;
396
397         file_vframe = 0;                file_icon = 0;
398         folder_vframe = 0;              folder_icon = 0;
399         audio_vframe = 0;               audio_icon = 0;
400         video_vframe = 0;               video_icon = 0;
401         label_vframe = 0;               label_icon = 0;
402
403         atransition_vframe = 0;         atransition_icon = 0;
404         vtransition_vframe = 0;         vtransition_icon = 0;
405         aeffect_vframe = 0;             aeffect_icon = 0;
406         ladspa_vframe = 0;              ladspa_icon = 0;
407         veffect_vframe = 0;             veffect_icon = 0;
408         ff_aud_vframe = 0;              ff_aud_icon = 0;
409         ff_vid_vframe = 0;              ff_vid_icon = 0;
410
411         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
412         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
413         clip_folder_vframe = 0;         clip_folder_icon = 0;
414         label_folder_vframe = 0;        label_folder_icon = 0;
415         media_folder_vframe = 0;        media_folder_icon = 0;
416         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
417         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
418         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
419
420         ladspa_vframe = 0;              ladspa_icon = 0;
421         ff_aud_vframe = 0;              ff_aud_icon = 0;
422         ff_vid_vframe = 0;              ff_vid_icon = 0;
423
424         clip_vframe = 0;                clip_icon = 0;
425         atransition_vframe = 0;         atransition_icon = 0;
426         vtransition_vframe = 0;         vtransition_icon = 0;
427         aeffect_vframe = 0;             aeffect_icon = 0;
428         veffect_vframe = 0;             veffect_icon = 0;
429
430         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
431         newfolder_thread = 0;
432         asset_menu = 0;
433         effectlist_menu = 0;
434         assetlist_menu = 0;
435         cliplist_menu = 0;
436         labellist_menu = 0;
437         folderlist_menu = 0;
438         temp_picon = 0;
439         search_text = 0;
440         allow_iconlisting = 1;
441         remove_plugin = 0;
442         vicon_thread = 0;
443         vicon_drawing = 1;
444         displayed_folder = AW_NO_FOLDER;
445 }
446
447 AWindowGUI::~AWindowGUI()
448 {
449         assets.remove_all_objects();
450         folders.remove_all_objects();
451         aeffects.remove_all_objects();
452         veffects.remove_all_objects();
453         atransitions.remove_all_objects();
454         vtransitions.remove_all_objects();
455         labellist.remove_all_objects();
456         displayed_assets[1].remove_all_objects();
457
458         delete vicon_thread;
459         delete newfolder_thread;
460
461         delete asset_menu;
462         delete clip_menu;
463         delete label_menu;
464         delete effectlist_menu;
465         delete assetlist_menu;
466         delete cliplist_menu;
467         delete labellist_menu;
468         delete folderlist_menu;
469         delete search_text;
470         delete temp_picon;
471         delete remove_plugin;
472
473         delete file_vframe;             delete file_icon;
474         delete folder_vframe;           delete folder_icon;
475         delete audio_vframe;            delete audio_icon;
476         delete video_vframe;            delete video_icon;
477         delete label_vframe;            delete label_icon;
478         delete clip_vframe;             delete clip_icon;
479         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
480         delete atransition_folder_vframe; delete atransition_folder_icon;
481         delete veffect_folder_vframe;   delete veffect_folder_icon;
482         delete vtransition_folder_vframe; delete vtransition_folder_icon;
483         delete clip_folder_vframe;      delete clip_folder_icon;
484         delete label_folder_vframe;     delete label_folder_icon;
485         delete media_folder_vframe;     delete media_folder_icon;
486         delete proxy_folder_vframe;     delete proxy_folder_icon;
487         delete ladspa_vframe;           delete ladspa_icon;
488         delete ff_aud_vframe;           delete ff_aud_icon;
489         delete ff_vid_vframe;           delete ff_vid_icon;
490         delete atransition_vframe;      delete atransition_icon;
491         delete vtransition_vframe;      delete vtransition_icon;
492         delete aeffect_vframe;          delete aeffect_icon;
493         delete veffect_vframe;          delete veffect_icon;
494 }
495
496 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
497 {
498         return  icon == file_icon ||
499                 icon == folder_icon ||
500                 icon == audio_icon ||
501                 icon == video_icon ||
502                 icon == clip_icon ||
503                 icon == label_icon ||
504                 icon == vtransition_icon ||
505                 icon == atransition_icon ||
506                 icon == veffect_icon ||
507                 icon == aeffect_icon ||
508                 icon == ladspa_icon ||
509                 icon == ff_aud_icon ||
510                 icon == ff_vid_icon ||
511                 icon == aeffect_folder_icon ||
512                 icon == veffect_folder_icon ||
513                 icon == atransition_folder_icon ||
514                 icon == vtransition_folder_icon ||
515                 icon == label_folder_icon ||
516                 icon == clip_folder_icon ||
517                 icon == media_folder_icon ||
518                 icon == proxy_folder_icon;
519 }
520
521 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
522 {
523         char png_path[BCTEXTLEN];
524         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
525         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
526                 File::get_plugin_path(), plugin_icons, name);
527         if( access(png_path, R_OK) ) return 0;
528         return VFramePng::vframe_png(png_path,0,0);
529 }
530
531 VFrame *AWindowGUI::get_picon(const char *name)
532 {
533         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
534         if( !vframe ) {
535                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
536                 snprintf(pp, ep-pp, "%s.png", name);
537                 unsigned char *data = mwindow->theme->get_image_data(png_name);
538                 if( data ) vframe = new VFramePng(data, 0.);
539         }
540         return vframe;
541 }
542
543 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
544 {
545         vfrm = get_picon(fn);
546         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
547         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
548 }
549 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
550 {
551         vfrm = get_picon(fn);
552         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
553         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
554 }
555 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
556 {
557         vfrm = get_picon(fn);
558         if( !vfrm ) vfrm = new VFramePng(png);
559         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
560 }
561
562 void AWindowGUI::create_objects()
563 {
564         lock_window("AWindowGUI::create_objects");
565         asset_titles[0] = C_("Title");
566         asset_titles[1] = _("Comments");
567
568         set_icon(mwindow->theme->get_image("awindow_icon"));
569
570         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
571         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
572         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
573         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
574         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
575
576         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
577         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
578         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
579         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
580         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
581         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
582         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
583         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
584
585         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
586         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
587         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
588         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
589         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
590         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
591         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
592         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
593
594         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
595         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
596         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
597         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
598         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
599
600         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
601         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
602         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
603
604 // Mandatory folders
605         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
606         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
607         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
608         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
609         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
610         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
611         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
612         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
613
614         create_label_folder();
615
616         mwindow->theme->get_awindow_sizes(this);
617         load_defaults(mwindow->defaults);
618
619         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y + 5;
620         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
621         search_text = new AWindowSearchText(mwindow, this, x1, y1);
622         search_text->create_objects();
623         int dy = search_text->get_h() + 10;
624         y1 += dy;  h1 -= dy;
625         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
626
627         vicon_thread = new VIconThread(asset_list);
628         vicon_thread->start();
629
630         add_subwindow(divider = new AWindowDivider(mwindow, this,
631                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
632                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
633
634         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
635
636         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
637         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
638         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
639         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
640         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
641         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
642         add_tools->create_objects();
643         fy += add_tools->get_h();  fh -= add_tools->get_h();
644         add_subwindow(folder_list = new AWindowFolders(mwindow,
645                 this, fx, fy, fw, fh));
646         update_effects();
647
648         //int x = mwindow->theme->abuttons_x;
649         //int y = mwindow->theme->abuttons_y;
650
651
652         newfolder_thread = new NewFolderThread(mwindow, this);
653
654         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
655         asset_menu->create_objects();
656         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
657         clip_menu->create_objects();
658         add_subwindow(label_menu = new LabelPopup(mwindow, this));
659         label_menu->create_objects();
660
661         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
662         effectlist_menu->create_objects();
663         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
664         assetlist_menu->create_objects();
665         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
666         cliplist_menu->create_objects();
667         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
668         labellist_menu->create_objects();
669
670         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
671         folderlist_menu->create_objects();
672
673         create_custom_xatoms();
674         unlock_window();
675 }
676
677 int AWindowGUI::resize_event(int w, int h)
678 {
679         mwindow->session->awindow_x = get_x();
680         mwindow->session->awindow_y = get_y();
681         mwindow->session->awindow_w = w;
682         mwindow->session->awindow_h = h;
683
684         mwindow->theme->get_awindow_sizes(this);
685         mwindow->theme->draw_awindow_bg(this);
686         reposition_objects();
687
688 //      int x = mwindow->theme->abuttons_x;
689 //      int y = mwindow->theme->abuttons_y;
690 //      new_bin->reposition_window(x, y);
691 //      x += new_bin->get_w();
692 //      delete_bin->reposition_window(x, y);
693 //      x += delete_bin->get_w();
694 //      rename_bin->reposition_window(x, y);
695 //      x += rename_bin->get_w();
696 //      delete_disk->reposition_window(x, y);
697 //      x += delete_disk->get_w();
698 //      delete_project->reposition_window(x, y);
699 //      x += delete_project->get_w();
700 //      info->reposition_window(x, y);
701 //      x += info->get_w();
702 //      redraw_index->reposition_window(x, y);
703 //      x += redraw_index->get_w();
704 //      paste->reposition_window(x, y);
705 //      x += paste->get_w();
706 //      append->reposition_window(x, y);
707 //      x += append->get_w();
708 //      view->reposition_window(x, y);
709
710         BC_WindowBase::resize_event(w, h);
711         return 1;
712 }
713
714 int AWindowGUI::translation_event()
715 {
716         mwindow->session->awindow_x = get_x();
717         mwindow->session->awindow_y = get_y();
718         return 0;
719 }
720
721 void AWindowGUI::reposition_objects()
722 {
723         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y + 5;
724         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
725         search_text->reposition_window(x1, y1, w1);
726         int dy = search_text->get_h() + 10;
727         y1 += dy;  h1 -= dy;
728         asset_list->reposition_window(x1, y1, w1, h1);
729         divider->reposition_window(
730                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
731                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
732         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
733         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
734         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
735         avicon_drawing->reposition_window(fw-avicon_w, fy);
736         fy += add_tools->get_h();  fh -= add_tools->get_h();
737         folder_list->reposition_window(fx, fy, fw, fh);
738 }
739
740 int AWindowGUI::save_defaults(BC_Hash *defaults)
741 {
742         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
743         defaults->update("VICON_DRAWING", vicon_drawing);
744         return 0;
745 }
746
747 int AWindowGUI::load_defaults(BC_Hash *defaults)
748 {
749         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
750         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
751         return 0;
752 }
753
754 int AWindowGUI::close_event()
755 {
756         hide_window();
757         mwindow->session->show_awindow = 0;
758         unlock_window();
759
760         mwindow->gui->lock_window("AWindowGUI::close_event");
761         mwindow->gui->mainmenu->show_awindow->set_checked(0);
762         mwindow->gui->unlock_window();
763
764         lock_window("AWindowGUI::close_event");
765         save_defaults(mwindow->defaults);
766         mwindow->save_defaults();
767         return 1;
768 }
769
770 void AWindowGUI::start_vicon_drawing()
771 {
772         if( !vicon_drawing ) return;
773         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
774         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
775         vicon_thread->start_drawing();
776 }
777
778 void AWindowGUI::stop_vicon_drawing()
779 {
780         vicon_thread->stop_drawing();
781 }
782
783 AWindowRemovePluginGUI::
784 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
785         int x, int y, PluginServer *plugin)
786  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
787 {
788         this->awindow = awindow;
789         this->thread = thread;
790         this->plugin = plugin;
791         VFrame *vframe = plugin->get_picon();
792         icon = vframe ? create_pixmap(vframe) : 0;
793         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
794 }
795
796 AWindowRemovePluginGUI::
797 ~AWindowRemovePluginGUI()
798 {
799         if( !awindow->gui->protected_pixmap(icon) )
800                 delete icon;
801         plugin_list.remove_all();
802 }
803
804 void AWindowRemovePluginGUI::create_objects()
805 {
806         BC_Button *ok_button = new BC_OKButton(this);
807         add_subwindow(ok_button);
808         BC_Button *cancel_button = new BC_CancelButton(this);
809         add_subwindow(cancel_button);
810         int x = 10, y = 10;
811         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
812         add_subwindow(title);
813         y += title->get_h() + 5;
814         list = new BC_ListBox(x, y,
815                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
816                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
817         add_subwindow(list);
818         show_window();
819 }
820
821 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
822 {
823         int ret = 0;
824         for( int i=0; i<folder.size(); ) {
825                 AssetPicon *picon = (AssetPicon *)folder[i];
826                 if( picon->plugin == plugin ) {
827                         folder.remove_object_number(i);
828                         ++ret;
829                         continue;
830                 }
831                 ++i;
832         }
833         return ret;
834 }
835
836 void AWindowRemovePlugin::handle_close_event(int result)
837 {
838         if( !result ) {
839                 printf(_("remove %s\n"), plugin->path);
840                 ArrayList<BC_ListBoxItem*> *folder =
841                         plugin->audio ? plugin->transition ?
842                                 &awindow->gui->atransitions :
843                                 &awindow->gui->aeffects :
844                         plugin->video ?  plugin->transition ?
845                                 &awindow->gui->vtransitions :
846                                 &awindow->gui->veffects :
847                         0;
848                 if( folder ) remove_plugin(plugin, *folder);
849                 char plugin_path[BCTEXTLEN];
850                 strcpy(plugin_path, plugin->path);
851                 MWindow *mwindow = awindow->mwindow;
852                 mwindow->plugindb->remove(plugin);
853                 remove(plugin_path);
854                 char index_path[BCTEXTLEN];
855                 snprintf(index_path, sizeof(index_path), "%s/%s",
856                         mwindow->preferences->plugin_dir, PLUGIN_FILE);
857                 remove(index_path);
858                 char picon_path[BCTEXTLEN];
859                 FileSystem fs;
860                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
861                         File::get_plugin_path());
862                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
863                 plugin->get_plugin_png_name(png_name);
864                 fs.update(picon_path);
865                 for( int i=0; i<fs.dir_list.total; ++i ) {
866                         char *fs_path = fs.dir_list[i]->path;
867                         if( !fs.is_dir(fs_path) ) continue;
868                         snprintf(png_path, sizeof(picon_path), "%s/%s",
869                                 fs_path, png_name);
870                         remove(png_path);
871                 }
872                 delete plugin;  plugin = 0;
873                 awindow->gui->async_update_assets();
874         }
875 }
876
877 AWindowRemovePlugin::
878 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
879  : BC_DialogThread()
880 {
881         this->awindow = awindow;
882         this->plugin = plugin;
883 }
884
885 AWindowRemovePlugin::
886 ~AWindowRemovePlugin()
887 {
888         close_window();
889 }
890
891 BC_Window* AWindowRemovePlugin::new_gui()
892 {
893         int x = awindow->gui->get_abs_cursor_x(0);
894         int y = awindow->gui->get_abs_cursor_y(0);
895         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
896         gui->create_objects();
897         return gui;
898 }
899
900 int AWindowGUI::keypress_event()
901 {
902         switch( get_keypress() ) {
903         case 'w': case 'W':
904                 if( ctrl_down() ) {
905                         close_event();
906                         return 1;
907                 }
908                 break;
909         case DELETE:
910                 if( shift_down() ) {
911                         PluginServer* plugin = selected_plugin();
912                         if( !plugin ) break;
913                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
914                         unlock_window();
915                         remove_plugin->start();
916                         lock_window();
917                 }
918         }
919         return 0;
920 }
921
922
923
924 int AWindowGUI::create_custom_xatoms()
925 {
926         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
927         return 0;
928 }
929 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
930 {
931         if( event->message_type == UpdateAssetsXAtom ) {
932                 update_assets();
933                 return 1;
934         }
935         return 0;
936 }
937
938 void AWindowGUI::async_update_assets()
939 {
940         xatom_event event;
941         event.message_type = UpdateAssetsXAtom;
942         send_custom_xatom(&event);
943 }
944
945
946 void AWindowGUI::update_folder_list()
947 {
948         for( int i = 0; i < folders.total; i++ ) {
949                 AssetPicon *picon = (AssetPicon*)folders.values[i];
950                 picon->in_use = 0;
951         }
952
953 // Search assets for folders
954         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
955                 const char *folder = mwindow->edl->folders.values[i];
956                 int exists = 0;
957
958                 for( int j = 0; j < folders.total; j++ ) {
959                         AssetPicon *picon = (AssetPicon*)folders.values[j];
960                         if( !strcasecmp(picon->get_text(), folder) ) {
961                                 exists = 1;
962                                 picon->in_use = 1;
963                                 break;
964                         }
965                 }
966
967                 if( !exists ) {
968                         int aw_folder = folder_number(folder);
969                         if( aw_folder >= 0 ) {
970                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
971                                 picon->create_objects();
972                                 folders.append(picon);
973                         }
974                 }
975         }
976
977 // Delete unused non-persistent folders
978         for( int i=folders.total; --i>=0; ) {
979                 AssetPicon *picon = (AssetPicon*)folders.values[i];
980                 if( !picon->in_use && !picon->persistent ) {
981                         delete picon;
982                         folders.remove_number(i);
983                 }
984         }
985 }
986
987 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
988         int do_audio, int do_video, int is_realtime, int is_transition)
989 {
990         ArrayList<PluginServer*> plugin_list;
991 // Get pointers to plugindb entries
992         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
993                         0, plugin_list);
994
995         for( int i = 0; i < plugin_list.total; i++ ) {
996                 PluginServer *server = plugin_list.values[i];
997                 int visible = plugin_visibility & (1<<server->dir_idx);
998                 if( !visible ) continue;
999 // Create new listitem
1000                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1001                 picon->create_objects();
1002                 output->append(picon);
1003         }
1004 }
1005
1006 void AWindowGUI::create_label_folder()
1007 {
1008         Label *current;
1009         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1010                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1011                 picon->create_objects();
1012                 labellist.append(picon);
1013         }
1014 }
1015
1016
1017 void AWindowGUI::update_asset_list()
1018 {
1019         for( int i = 0; i < assets.total; i++ ) {
1020                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1021                 picon->in_use = 0;
1022         }
1023
1024 // Synchronize EDL clips
1025         for( int i = 0; i < mwindow->edl->clips.total; i++ ) {
1026                 int exists = 0;
1027
1028 // Look for clip in existing listitems
1029                 for( int j = 0; j < assets.total && !exists; j++ ) {
1030                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1031
1032                         if( picon->id == mwindow->edl->clips.values[i]->id ) {
1033                                 picon->edl = mwindow->edl->clips.values[i];
1034                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
1035                                 exists = 1;
1036                                 picon->in_use = 1;
1037                         }
1038                 }
1039
1040 // Create new listitem
1041                 if( !exists ) {
1042                         AssetPicon *picon = new AssetPicon(mwindow,
1043                                 this, mwindow->edl->clips.values[i]);
1044                         picon->create_objects();
1045                         assets.append(picon);
1046                 }
1047         }
1048
1049 // Synchronize EDL assets
1050         for( Asset *current = mwindow->edl->assets->first;
1051                 current;
1052                 current = NEXT ) {
1053                 int exists = 0;
1054
1055 // Look for asset in existing listitems
1056                 for( int j = 0; j < assets.total && !exists; j++ ) {
1057                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1058
1059                         if( picon->id == current->id ) {
1060                                 picon->indexable = current;
1061                                 exists = 1;
1062                                 picon->in_use = 1;
1063                                 break;
1064                         }
1065                 }
1066
1067 // Create new listitem
1068                 if( !exists ) {
1069                         AssetPicon *picon = new AssetPicon(mwindow,
1070                                 this, current);
1071                         picon->create_objects();
1072                         assets.append(picon);
1073                 }
1074         }
1075
1076         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1077         mwindow->gui->default_message();
1078         mwindow->gui->unlock_window();
1079
1080 // Synchronize nested EDLs
1081         for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) {
1082                 int exists = 0;
1083                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
1084
1085 // Look for asset in existing listitems
1086                 for( int j = 0; j < assets.total && !exists; j++ ) {
1087                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1088
1089                         if( picon->id == indexable->id ) {
1090                                 picon->indexable = indexable;
1091                                 exists = 1;
1092                                 picon->in_use = 1;
1093                                 break;
1094                         }
1095                 }
1096
1097 // Create new listitem
1098                 if( !exists ) {
1099                         AssetPicon *picon = new AssetPicon(mwindow,
1100                                 this, indexable);
1101                         picon->create_objects();
1102                         assets.append(picon);
1103                 }
1104         }
1105
1106         for( int i = assets.size() - 1; i >= 0; i-- ) {
1107                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1108                 if( !picon->in_use ) {
1109                         delete picon;
1110                         assets.remove_number(i);
1111                 }
1112         }
1113 }
1114
1115 void AWindowGUI::update_picon(Indexable *indexable)
1116 {
1117         VIcon *vicon = 0;
1118         for( int i = 0; i < assets.total; i++ ) {
1119                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1120                 if( picon->indexable == indexable ||
1121                     picon->edl == (EDL *)indexable ) {
1122                         char name[BCTEXTLEN];
1123                         FileSystem fs;
1124                         fs.extract_name(name, indexable->path);
1125                         picon->set_text(name);
1126                         vicon = picon->vicon;
1127                         break;
1128                 }
1129         }
1130         if( vicon ) {
1131                 stop_vicon_drawing();
1132                 vicon->clear_images();
1133                 vicon->reset(indexable->get_frame_rate());
1134                 start_vicon_drawing();
1135         }
1136 }
1137
1138 void AWindowGUI::sort_assets()
1139 {
1140         switch( mwindow->edl->session->awindow_folder ) {
1141         case AW_AEFFECT_FOLDER:
1142                 sort_picons(&aeffects);
1143                 break;
1144         case AW_VEFFECT_FOLDER:
1145                 sort_picons(&veffects);
1146                 break;
1147         case AW_ATRANSITION_FOLDER:
1148                 sort_picons(&atransitions);
1149                 break;
1150         case AW_VTRANSITION_FOLDER:
1151                 sort_picons(&vtransitions);
1152                 break;
1153         case AW_LABEL_FOLDER:
1154                 sort_picons(&labellist);
1155                 break;
1156         default:
1157                 sort_picons(&assets);
1158         }
1159 // reset xyposition
1160         asset_list->update_format(asset_list->get_format(), 0);
1161         update_assets();
1162 }
1163
1164 void AWindowGUI::sort_folders()
1165 {
1166         sort_picons(&folders);
1167         folder_list->update_format(folder_list->get_format(), 0);
1168         update_assets();
1169 }
1170
1171 void AWindowGUI::collect_assets()
1172 {
1173         int i = 0;
1174         mwindow->session->drag_assets->remove_all();
1175         mwindow->session->drag_clips->remove_all();
1176         while(1)
1177         {
1178                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
1179                 if( !result ) break;
1180
1181                 if( result->indexable ) mwindow->session->drag_assets->append(result->indexable);
1182                 if( result->edl ) mwindow->session->drag_clips->append(result->edl);
1183         }
1184 }
1185
1186 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1187         ArrayList<BC_ListBoxItem*> *src, int folder)
1188 {
1189 // Remove current pointers
1190         dst[0].remove_all();
1191         dst[1].remove_all_objects();
1192
1193 // Create new pointers
1194         for( int i = 0; i < src->total; i++ ) {
1195                 AssetPicon *picon = (AssetPicon*)src->values[i];
1196                 if( folder < 0 ||
1197                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1198                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1199                         const char *text = search_text->get_text();
1200                         int hidden = text && text[0] && !strcasestr(picon->get_text(), text);
1201                         if( picon->vicon ) picon->vicon->hidden = hidden;
1202                         if( hidden ) continue;
1203                         BC_ListBoxItem *item2, *item1;
1204                         dst[0].append(item1 = picon);
1205                         if( picon->edl )
1206                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1207                         else
1208                         if( picon->label && picon->label->textstr )
1209                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1210                         else
1211                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1212                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
1213                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
1214                 }
1215         }
1216 }
1217
1218 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1219 {
1220         int done = 0;
1221         while(!done)
1222         {
1223                 done = 1;
1224                 for( int i = 0; i < src->total - 1; i++ ) {
1225                         BC_ListBoxItem *item1 = src->values[i];
1226                         BC_ListBoxItem *item2 = src->values[i + 1];
1227                         item1->set_autoplace_icon(1);
1228                         item2->set_autoplace_icon(1);
1229                         item1->set_autoplace_text(1);
1230                         item2->set_autoplace_text(1);
1231                         if( strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1232                                 src->values[i + 1] = item1;
1233                                 src->values[i] = item2;
1234                                 done = 0;
1235                         }
1236                 }
1237         }
1238 }
1239
1240
1241 void AWindowGUI::filter_displayed_assets()
1242 {
1243         //allow_iconlisting = 1;
1244         asset_titles[0] = C_("Title");
1245         asset_titles[1] = _("Comments");
1246
1247         switch( mwindow->edl->session->awindow_folder ) {
1248         case AW_AEFFECT_FOLDER:
1249                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1250                 break;
1251         case AW_VEFFECT_FOLDER:
1252                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1253                 break;
1254         case AW_ATRANSITION_FOLDER:
1255                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1256                 break;
1257         case AW_VTRANSITION_FOLDER:
1258                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1259                 break;
1260         case AW_LABEL_FOLDER:
1261                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1262                 asset_titles[0] = _("Time Stamps");
1263                 asset_titles[1] = C_("Title");
1264                 //allow_iconlisting = 0;
1265                 break;
1266         default:
1267                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1268                 break;
1269         }
1270
1271         // Ensure the current folder icon is highlighted
1272         int selected_folder = mwindow->edl->session->awindow_folder;
1273         for( int i = 0; i < folders.total; i++ ) {
1274                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1275                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1276                 folder_item->set_selected(selected);
1277         }
1278 }
1279
1280
1281 void AWindowGUI::update_assets()
1282 {
1283         stop_vicon_drawing();
1284         update_folder_list();
1285         update_asset_list();
1286         labellist.remove_all_objects();
1287         create_label_folder();
1288
1289         if( displayed_folder != mwindow->edl->session->awindow_folder )
1290                 search_text->clear();
1291         filter_displayed_assets();
1292
1293         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1294                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1295         }
1296         int folder_xposition = folder_list->get_xposition();
1297         int folder_yposition = folder_list->get_yposition();
1298         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1299
1300         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1301                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1302         }
1303         int asset_xposition = asset_list->get_xposition();
1304         int asset_yposition = asset_list->get_yposition();
1305         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1306                 displayed_folder = mwindow->edl->session->awindow_folder;
1307                 asset_xposition = asset_yposition = 0;
1308         }
1309         asset_list->update(displayed_assets, asset_titles,
1310                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1311                 asset_xposition, asset_yposition, -1, 0);
1312         asset_list->center_selection();
1313
1314         flush();
1315         start_vicon_drawing();
1316         return;
1317 }
1318
1319 void AWindowGUI::update_effects()
1320 {
1321         aeffects.remove_all_objects();
1322         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1323         veffects.remove_all_objects();
1324         create_persistent_folder(&veffects, 0, 1, 1, 0);
1325         atransitions.remove_all_objects();
1326         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1327         vtransitions.remove_all_objects();
1328         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1329 }
1330
1331 int AWindowGUI::folder_number(const char *name)
1332 {
1333         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1334                 if( !strcasecmp(name, folder_names[i]) ) return i;
1335         }
1336         return AW_NO_FOLDER;
1337 }
1338
1339 int AWindowGUI::drag_motion()
1340 {
1341         if( get_hidden() ) return 0;
1342
1343         int result = 0;
1344         return result;
1345 }
1346
1347 int AWindowGUI::drag_stop()
1348 {
1349         if( get_hidden() ) return 0;
1350
1351         return 0;
1352 }
1353
1354 Indexable* AWindowGUI::selected_asset()
1355 {
1356         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1357         return picon ? picon->indexable : 0;
1358 }
1359
1360 PluginServer* AWindowGUI::selected_plugin()
1361 {
1362         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1363         return picon ? picon->plugin : 0;
1364 }
1365
1366 AssetPicon* AWindowGUI::selected_folder()
1367 {
1368         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1369         return picon;
1370 }
1371
1372
1373
1374
1375
1376
1377
1378
1379 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1380  : BC_SubWindow(x, y, w, h)
1381 {
1382         this->mwindow = mwindow;
1383         this->gui = gui;
1384 }
1385 AWindowDivider::~AWindowDivider()
1386 {
1387 }
1388
1389 int AWindowDivider::button_press_event()
1390 {
1391         if( is_event_win() && cursor_inside() ) {
1392                 mwindow->session->current_operation = DRAG_PARTITION;
1393                 return 1;
1394         }
1395         return 0;
1396 }
1397
1398 int AWindowDivider::cursor_motion_event()
1399 {
1400         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1401                 int wmin = 25;
1402                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1403                 int fw = gui->get_relative_cursor_x();
1404                 if( fw > wmax ) fw = wmax;
1405                 if( fw < wmin ) fw = wmin;
1406                 mwindow->session->afolders_w = fw;
1407                 mwindow->theme->get_awindow_sizes(gui);
1408                 gui->reposition_objects();
1409                 gui->flush();
1410         }
1411         return 0;
1412 }
1413
1414 int AWindowDivider::button_release_event()
1415 {
1416         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1417                 mwindow->session->current_operation = NO_OPERATION;
1418                 return 1;
1419         }
1420         return 0;
1421 }
1422
1423
1424
1425
1426
1427
1428 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1429  : BC_ListBox(x, y, w, h,
1430                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1431                         LISTBOX_ICONS : LISTBOX_TEXT,
1432                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1433                 0,                // Titles for columns.  Set to 0 for no titles
1434                 0,                // width of each column
1435                 1,                // Total columns.
1436                 0,                // Pixel of top of window.
1437                 0,                // If this listbox is a popup window
1438                 LISTBOX_SINGLE,   // Select one item or multiple items
1439                 ICON_TOP,         // Position of icon relative to text of each item
1440                 1)                // Allow drags
1441 {
1442         this->mwindow = mwindow;
1443         this->gui = gui;
1444         set_drag_scroll(0);
1445 }
1446
1447 AWindowFolders::~AWindowFolders()
1448 {
1449 }
1450
1451 int AWindowFolders::selection_changed()
1452 {
1453         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1454         if( picon ) {
1455                 gui->stop_vicon_drawing();
1456
1457                 if( get_button_down() && get_buttonpress() == 3 ) {
1458                         gui->folderlist_menu->update_titles();
1459                         gui->folderlist_menu->activate_menu();
1460                 }
1461
1462                 mwindow->edl->session->awindow_folder = picon->foldernum;
1463                 gui->asset_list->draw_background();
1464                 gui->async_update_assets();
1465
1466                 gui->start_vicon_drawing();
1467         }
1468         return 1;
1469 }
1470
1471 int AWindowFolders::button_press_event()
1472 {
1473         int result = 0;
1474
1475         result = BC_ListBox::button_press_event();
1476
1477         if( !result ) {
1478                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1479                         gui->folderlist_menu->update_titles();
1480                         gui->folderlist_menu->activate_menu();
1481                         result = 1;
1482                 }
1483         }
1484
1485
1486         return result;
1487 }
1488
1489
1490
1491
1492
1493
1494
1495 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1496  : BC_ListBox(x, y, w, h,
1497                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1498                         LISTBOX_ICONS : LISTBOX_TEXT,
1499                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1500                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1501                 mwindow->edl->session->asset_columns, // width of each column
1502                 1,                // Total columns.
1503                 0,                // Pixel of top of window.
1504                 0,                // If this listbox is a popup window
1505                 LISTBOX_MULTIPLE, // Select one item or multiple items
1506                 ICON_TOP,         // Position of icon relative to text of each item
1507                 -1)               // Allow drags, require shift for scrolling
1508 {
1509         this->mwindow = mwindow;
1510         this->gui = gui;
1511         set_drag_scroll(0);
1512         set_scroll_stretch(1, 1);
1513 }
1514
1515 AWindowAssets::~AWindowAssets()
1516 {
1517 }
1518
1519 int AWindowAssets::button_press_event()
1520 {
1521         int result = 0;
1522
1523         result = BC_ListBox::button_press_event();
1524
1525         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1526                 BC_ListBox::deactivate_selection();
1527                 int folder = mwindow->edl->session->awindow_folder;
1528                 switch( folder ) {
1529                 case AW_AEFFECT_FOLDER:
1530                 case AW_VEFFECT_FOLDER:
1531                 case AW_ATRANSITION_FOLDER:
1532                 case AW_VTRANSITION_FOLDER:
1533                         gui->effectlist_menu->update();
1534                         gui->effectlist_menu->activate_menu();
1535                         break;
1536                 case AW_LABEL_FOLDER:
1537                         gui->labellist_menu->update();
1538                         gui->labellist_menu->activate_menu();
1539                         break;
1540                 case AW_CLIP_FOLDER:
1541                         gui->cliplist_menu->update();
1542                         gui->cliplist_menu->activate_menu();
1543                         break;
1544                 case AW_MEDIA_FOLDER:
1545                 case AW_PROXY_FOLDER:
1546                         gui->assetlist_menu->update_titles();
1547                         gui->assetlist_menu->activate_menu();
1548                         break;
1549                 }
1550                 result = 1;
1551         }
1552
1553         return result;
1554 }
1555
1556
1557 int AWindowAssets::handle_event()
1558 {
1559         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
1560         if( !asset_picon ) return 0;
1561         switch( mwindow->edl->session->awindow_folder ) {
1562         case AW_AEFFECT_FOLDER:
1563         case AW_VEFFECT_FOLDER:
1564         case AW_ATRANSITION_FOLDER:
1565         case AW_VTRANSITION_FOLDER: return 1;
1566         }
1567         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1568                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1569         if( !vwindow || !vwindow->is_running() ) return 1;
1570
1571         vwindow->gui->lock_window("AWindowAssets::handle_event");
1572         if( asset_picon->indexable )
1573                 vwindow->change_source(asset_picon->indexable);
1574         else if( asset_picon->edl )
1575                 vwindow->change_source(asset_picon->edl);
1576         vwindow->gui->unlock_window();
1577         return 1;
1578 }
1579
1580 int AWindowAssets::selection_changed()
1581 {
1582 // Show popup window
1583         AssetPicon *item;
1584         if( get_button_down() && get_buttonpress() == 3 &&
1585             (item = (AssetPicon*)get_selection(0, 0)) ) {
1586                 int folder = mwindow->edl->session->awindow_folder;
1587                 switch( folder ) {
1588                 case AW_AEFFECT_FOLDER:
1589                 case AW_VEFFECT_FOLDER:
1590                 case AW_ATRANSITION_FOLDER:
1591                 case AW_VTRANSITION_FOLDER:
1592                         gui->effectlist_menu->update();
1593                         gui->effectlist_menu->activate_menu();
1594                         break;
1595                 case AW_LABEL_FOLDER:
1596                         if( !item->label ) break;
1597                         gui->label_menu->activate_menu();
1598                         break;
1599                 case AW_CLIP_FOLDER:
1600                         if( !item->indexable && !item->edl ) break;
1601                         gui->clip_menu->update();
1602                         gui->clip_menu->activate_menu();
1603                         break;
1604                 default:
1605                         if( !item->indexable && !item->edl ) break;
1606                         gui->asset_menu->update();
1607                         gui->asset_menu->activate_menu();
1608                         break;
1609                 }
1610
1611                 BC_ListBox::deactivate_selection();
1612                 return 1;
1613         }
1614         else if( get_button_down() && get_buttonpress() == 1 &&
1615                  (item = (AssetPicon*)get_selection(0, 0)) ) {
1616                 VIcon *vicon = 0;
1617                 if( !gui->vicon_thread->viewing ) {
1618                         vicon = item->vicon;
1619                 }
1620                 gui->vicon_thread->set_view_popup(vicon);
1621
1622         }
1623         return 0;
1624 }
1625
1626 void AWindowAssets::draw_background()
1627 {
1628         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1629         set_color(BC_WindowBase::get_resources()->audiovideo_color);
1630         set_font(LARGEFONT);
1631         int aw_folder = mwindow->edl->session->awindow_folder;
1632         if( aw_folder < 0 ) return;
1633         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
1634         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
1635                 aw_name, -1, get_bg_surface());
1636 }
1637
1638 int AWindowAssets::drag_start_event()
1639 {
1640         int collect_pluginservers = 0;
1641         int collect_assets = 0;
1642
1643         if( BC_ListBox::drag_start_event() ) {
1644                 switch( mwindow->edl->session->awindow_folder ) {
1645                 case AW_AEFFECT_FOLDER:
1646                         mwindow->session->current_operation = DRAG_AEFFECT;
1647                         collect_pluginservers = 1;
1648                         break;
1649                 case AW_VEFFECT_FOLDER:
1650                         mwindow->session->current_operation = DRAG_VEFFECT;
1651                         collect_pluginservers = 1;
1652                         break;
1653                 case AW_ATRANSITION_FOLDER:
1654                         mwindow->session->current_operation = DRAG_ATRANSITION;
1655                         collect_pluginservers = 1;
1656                         break;
1657                 case AW_VTRANSITION_FOLDER:
1658                         mwindow->session->current_operation = DRAG_VTRANSITION;
1659                         collect_pluginservers = 1;
1660                         break;
1661                 case AW_LABEL_FOLDER:
1662                         // do nothing!
1663                         break;
1664                 default:
1665                         mwindow->session->current_operation = DRAG_ASSET;
1666                         collect_assets = 1;
1667                         break;
1668                 }
1669
1670                 if( collect_pluginservers ) {
1671                         int i = 0;
1672                         mwindow->session->drag_pluginservers->remove_all();
1673                         while(1)
1674                         {
1675                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1676                                 if( !result ) break;
1677
1678                                 mwindow->session->drag_pluginservers->append(result->plugin);
1679                         }
1680                 }
1681
1682                 if( collect_assets ) {
1683                         gui->collect_assets();
1684                 }
1685
1686                 return 1;
1687         }
1688         return 0;
1689 }
1690
1691 int AWindowAssets::drag_motion_event()
1692 {
1693         BC_ListBox::drag_motion_event();
1694         unlock_window();
1695
1696         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1697         mwindow->gui->drag_motion();
1698         mwindow->gui->unlock_window();
1699
1700         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
1701                 VWindow *vwindow = mwindow->vwindows.get(i);
1702                 if( !vwindow->is_running() ) continue;
1703                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1704                 vwindow->gui->drag_motion();
1705                 vwindow->gui->unlock_window();
1706         }
1707
1708         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1709         mwindow->cwindow->gui->drag_motion();
1710         mwindow->cwindow->gui->unlock_window();
1711
1712         lock_window("AWindowAssets::drag_motion_event");
1713         return 0;
1714 }
1715
1716 int AWindowAssets::drag_stop_event()
1717 {
1718         int result = 0;
1719
1720         result = gui->drag_stop();
1721
1722         unlock_window();
1723
1724         if( !result ) {
1725                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1726                 result = mwindow->gui->drag_stop();
1727                 mwindow->gui->unlock_window();
1728         }
1729
1730         if( !result ) {
1731                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
1732                         VWindow *vwindow = mwindow->vwindows.get(i);
1733                         if( !vwindow ) continue;
1734                         if( !vwindow->is_running() ) continue;
1735                         if( vwindow->gui->is_hidden() ) continue;
1736                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1737                         if( vwindow->gui->cursor_above() &&
1738                             vwindow->gui->get_cursor_over_window() ) {
1739                                 result = vwindow->gui->drag_stop();
1740                         }
1741                         vwindow->gui->unlock_window();
1742                 }
1743         }
1744
1745         if( !result ) {
1746                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1747                 result = mwindow->cwindow->gui->drag_stop();
1748                 mwindow->cwindow->gui->unlock_window();
1749         }
1750
1751         lock_window("AWindowAssets::drag_stop_event");
1752
1753         if( result )
1754                 get_drag_popup()->set_animation(0);
1755
1756         BC_ListBox::drag_stop_event();
1757 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1758         mwindow->session->current_operation = ::NO_OPERATION;
1759         return 1;
1760 }
1761
1762 int AWindowAssets::column_resize_event()
1763 {
1764         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1765         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1766         return 1;
1767 }
1768
1769 int AWindowAssets::focus_in_event()
1770 {
1771         gui->start_vicon_drawing();
1772         return 0;
1773 }
1774
1775 int AWindowAssets::focus_out_event()
1776 {
1777         gui->stop_vicon_drawing();
1778         return BC_ListBox::focus_out_event();
1779 }
1780
1781 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
1782  : BC_TextBox(x, y, w, 1, "")
1783 {
1784         this->search_text = search_text;
1785 }
1786
1787 int AWindowSearchTextBox::handle_event()
1788 {
1789         return search_text->handle_event();
1790 }
1791
1792 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1793 {
1794         this->mwindow = mwindow;
1795         this->gui = gui;
1796         this->x = x;
1797         this->y = y;
1798 }
1799
1800 void AWindowSearchText::create_objects()
1801 {
1802         int x1 = x, y1 = y, margin = 10;
1803         gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
1804         x1 += text_title->get_w() + margin;
1805         int w1 = gui->get_w() - x1 - 2*margin;
1806         gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
1807 }
1808
1809 int AWindowSearchText::handle_event()
1810 {
1811         gui->async_update_assets();
1812         return 1;
1813 }
1814
1815 int AWindowSearchText::get_w()
1816 {
1817         return text_box->get_w() + text_title->get_w() + 10;
1818 }
1819
1820 int AWindowSearchText::get_h()
1821 {
1822         return bmax(text_box->get_h(),text_title->get_h());
1823 }
1824
1825 void AWindowSearchText::reposition_window(int x, int y, int w)
1826 {
1827         int x1 = x, y1 = y, margin = 10;
1828         text_title->reposition_window(x1, y1);
1829         x1 += text_title->get_w() + margin;
1830         int w1 = gui->get_w() - x1 - 2*margin;
1831         text_box->reposition_window(x1, y1, w1);
1832 }
1833
1834 const char *AWindowSearchText::get_text()
1835 {
1836         return text_box->get_text();
1837 }
1838
1839 void AWindowSearchText::clear()
1840 {
1841         text_box->update("");
1842 }
1843
1844 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1845  : BC_Button(x, y, mwindow->theme->newbin_data)
1846 {
1847         this->mwindow = mwindow;
1848         this->gui = gui;
1849         set_tooltip(_("New bin"));
1850 }
1851
1852 int AWindowNewFolder::handle_event()
1853 {
1854         gui->newfolder_thread->start_new_folder();
1855         return 1;
1856 }
1857
1858 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1859  : BC_Button(x, y, mwindow->theme->deletebin_data)
1860 {
1861         this->mwindow = mwindow;
1862         this->gui = gui;
1863         set_tooltip(_("Delete bin"));
1864 }
1865
1866 int AWindowDeleteFolder::handle_event()
1867 {
1868         if( gui->folder_list->get_selection(0, 0) ) {
1869                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1870                 mwindow->delete_folder(folder->get_text());
1871         }
1872         return 1;
1873 }
1874
1875 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1876  : BC_Button(x, y, mwindow->theme->renamebin_data)
1877 {
1878         this->mwindow = mwindow;
1879         this->gui = gui;
1880         set_tooltip(_("Rename bin"));
1881 }
1882
1883 int AWindowRenameFolder::handle_event()
1884 {
1885         return 1;
1886 }
1887
1888 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1889  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1890 {
1891         this->mwindow = mwindow;
1892         this->gui = gui;
1893         set_tooltip(_("Delete asset from disk"));
1894 }
1895
1896 int AWindowDeleteDisk::handle_event()
1897 {
1898         return 1;
1899 }
1900
1901 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1902  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1903 {
1904         this->mwindow = mwindow;
1905         this->gui = gui;
1906         set_tooltip(_("Delete asset from project"));
1907 }
1908
1909 int AWindowDeleteProject::handle_event()
1910 {
1911         return 1;
1912 }
1913
1914 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1915 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
1916 // {
1917 //      this->mwindow = mwindow;
1918 //      this->gui = gui;
1919 //      set_tooltip(_("Edit information on asset"));
1920 // }
1921 // 
1922 // int AWindowInfo::handle_event()
1923 // {
1924 //      int cur_x, cur_y;
1925 //      gui->get_abs_cursor(cur_x, cur_y, 0);
1926 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
1927 //      return 1;
1928 // }
1929
1930 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1931  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1932 {
1933         this->mwindow = mwindow;
1934         this->gui = gui;
1935         set_tooltip(_("Redraw index"));
1936 }
1937
1938 int AWindowRedrawIndex::handle_event()
1939 {
1940         return 1;
1941 }
1942
1943 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1944  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1945 {
1946         this->mwindow = mwindow;
1947         this->gui = gui;
1948         set_tooltip(_("Paste asset on recordable tracks"));
1949 }
1950
1951 int AWindowPaste::handle_event()
1952 {
1953         return 1;
1954 }
1955
1956 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1957  : BC_Button(x, y, mwindow->theme->appendasset_data)
1958 {
1959         this->mwindow = mwindow;
1960         this->gui = gui;
1961         set_tooltip(_("Append asset in new tracks"));
1962 }
1963
1964 int AWindowAppend::handle_event()
1965 {
1966         return 1;
1967 }
1968
1969 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1970  : BC_Button(x, y, mwindow->theme->viewasset_data)
1971 {
1972         this->mwindow = mwindow;
1973         this->gui = gui;
1974         set_tooltip(_("View asset"));
1975 }
1976
1977 int AWindowView::handle_event()
1978 {
1979         return 1;
1980 }
1981
1982 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
1983  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
1984 {
1985         this->mwindow = mwindow;
1986         this->gui = gui;
1987 }
1988
1989 void AddTools::create_objects()
1990 {
1991         uint64_t vis = 0;
1992         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
1993         vis |= 1 << PLUGIN_LADSPA_ID;
1994         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
1995         vis |= 1 << PLUGIN_FFMPEG_ID;
1996         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1997                 PluginServer *plugin = MWindow::plugindb->get(i);
1998                 if( !plugin->audio && !plugin->video ) continue;
1999                 int idx = plugin->dir_idx;
2000                 uint32_t msk = 1 << idx;
2001                 if( (msk & vis) != 0 ) continue;
2002                 vis |= msk;
2003                 char parent[BCTEXTLEN];
2004                 strcpy(parent, plugin->path);
2005                 char *bp = strrchr(parent, '/');
2006                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
2007                 if( !bp ) bp = parent; else ++bp;
2008                 add_item(new AddPluginItem(this, bp, idx));
2009         }
2010 }
2011
2012 #if 0
2013 // plugin_dirs list from toplevel makefile include plugin_defs
2014 N_("ladspa")
2015 N_("ffmpeg")
2016 N_("audio_tools")
2017 N_("audio_transitions")
2018 N_("blending")
2019 N_("colors")
2020 N_("exotic")
2021 N_("transforms")
2022 N_("tv_effects")
2023 N_("video_tools")
2024 N_("video_transitions")
2025 #endif
2026
2027 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2028  : BC_MenuItem(_(text))
2029 {
2030         this->menu = menu;
2031         this->idx = idx;
2032         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2033         int chk = (msk & vis) ? 1 : 0;
2034         set_checked(chk);
2035 }
2036
2037 int AddPluginItem::handle_event()
2038 {
2039         int chk = get_checked() ^ 1;
2040         set_checked(chk);
2041         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2042         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2043         menu->gui->update_effects();
2044         menu->gui->save_defaults(menu->mwindow->defaults);
2045         menu->gui->async_update_assets();
2046         return 1;
2047 }
2048
2049 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2050  : BC_Toggle(x, y, images, agui->vicon_drawing)
2051 {
2052         this->agui = agui;
2053         set_tooltip(_("draw vicons"));
2054 }
2055
2056 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2057 {
2058         int text_line = -1, toggle_x = -1, toggle_y = -1;
2059         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2060         BC_Toggle::calculate_extents(agui, images, 1,
2061                 &text_line, ww, hh, &toggle_x, &toggle_y,
2062                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2063 }
2064
2065 AVIconDrawing::~AVIconDrawing()
2066 {
2067 }
2068
2069 int AVIconDrawing::handle_event()
2070 {
2071         agui->vicon_drawing = get_value();
2072         if( agui->vicon_drawing )
2073                 agui->start_vicon_drawing();
2074         else
2075                 agui->stop_vicon_drawing();
2076         return 1;
2077 }
2078
2079
2080 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2081  : BC_MenuItem("")
2082 {
2083         this->mwindow = mwindow;
2084         this->gui = gui;
2085 }
2086
2087 int AWindowListFormat::handle_event()
2088 {
2089         gui->stop_vicon_drawing();
2090
2091         EDLSession *session = mwindow->edl->session;
2092         switch( session->assetlist_format ) {
2093         case ASSETS_TEXT:
2094                 session->assetlist_format = ASSETS_ICONS;
2095                 break;
2096         case ASSETS_ICONS:
2097                 session->assetlist_format = ASSETS_TEXT;
2098                 break;
2099         }
2100
2101         gui->asset_list->update_format(session->assetlist_format, 1);
2102         if( !mwindow->awindow->gui->allow_iconlisting ) {
2103                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2104         }
2105
2106         gui->start_vicon_drawing();
2107         return 1;
2108 }
2109
2110 void AWindowListFormat::update()
2111 {
2112         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2113                 (char*)_("Display icons") : (char*)_("Display text"));
2114 }
2115
2116 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2117  : BC_MenuItem(_("Sort items"))
2118 {
2119         this->mwindow = mwindow;
2120         this->gui = gui;
2121 }
2122
2123 int AWindowListSort::handle_event()
2124 {
2125         gui->sort_assets();
2126         return 1;
2127 }
2128