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