remove dupl BC_ListBoxToggle friend decl
[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 }
453
454 AWindowGUI::~AWindowGUI()
455 {
456         assets.remove_all_objects();
457         folders.remove_all_objects();
458         aeffects.remove_all_objects();
459         veffects.remove_all_objects();
460         atransitions.remove_all_objects();
461         vtransitions.remove_all_objects();
462         labellist.remove_all_objects();
463         displayed_assets[1].remove_all_objects();
464
465         delete vicon_thread;
466         delete file_icon;
467         delete audio_icon;
468         delete video_icon;
469         delete folder_icon;
470         delete clip_icon;
471         delete label_icon;
472         delete atransition_icon;
473         delete vtransition_icon;
474         delete aeffect_icon;
475         delete ladspa_icon;
476         delete ladspa_vframe;
477         delete ff_aud_icon;
478         delete ff_aud_vframe;
479         delete ff_vid_icon;
480         delete ff_vid_vframe;
481         delete veffect_icon;
482         delete newfolder_thread;
483         delete asset_menu;
484         delete clip_menu;
485         delete label_menu;
486         delete effectlist_menu;
487         delete assetlist_menu;
488         delete cliplist_menu;
489         delete labellist_menu;
490         delete folderlist_menu;
491         if( temp_picon ) delete temp_picon;
492         delete remove_plugin;
493 }
494
495 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
496 {
497         return  icon == file_icon ||
498                 icon == folder_icon ||
499                 icon == audio_icon ||
500                 icon == video_icon ||
501                 icon == clip_icon ||
502                 icon == label_icon ||
503                 icon == vtransition_icon ||
504                 icon == atransition_icon ||
505                 icon == veffect_icon ||
506                 icon == aeffect_icon ||
507                 icon == ladspa_icon ||
508                 icon == ff_aud_icon ||
509                 icon == ff_vid_icon;
510 }
511
512 void AWindowGUI::create_objects()
513 {
514         AssetPicon *picon;
515
516         lock_window("AWindowGUI::create_objects");
517 SET_TRACE
518 //printf("AWindowGUI::create_objects 1\n");
519         asset_titles[0] = _("Title");
520         asset_titles[1] = _("Comments");
521
522 SET_TRACE
523
524         set_icon(mwindow->theme->get_image("awindow_icon"));
525         file_icon = new BC_Pixmap(this,
526                 BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
527                 PIXMAP_ALPHA);
528
529         folder_icon = new BC_Pixmap(this,
530                 BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
531                 PIXMAP_ALPHA);
532
533         audio_icon = new BC_Pixmap(this,
534                 BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
535                 PIXMAP_ALPHA);
536
537         video_icon = new BC_Pixmap(this,
538                 BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
539                 PIXMAP_ALPHA);
540
541         label_icon = new BC_Pixmap(this,
542                 BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL],
543                 PIXMAP_ALPHA);
544
545 SET_TRACE
546
547         clip_vframe = mwindow->theme->get_image("clip_icon");
548         clip_icon = new BC_Pixmap(this, clip_vframe, PIXMAP_ALPHA);
549         atransition_vframe = mwindow->theme->get_image("atransition_icon");
550         atransition_icon = new BC_Pixmap(this, atransition_vframe, PIXMAP_ALPHA);
551         vtransition_vframe = mwindow->theme->get_image("vtransition_icon");
552         vtransition_icon = new BC_Pixmap(this, vtransition_vframe, PIXMAP_ALPHA);
553         aeffect_vframe = mwindow->theme->get_image("aeffect_icon");
554         aeffect_icon = new BC_Pixmap(this, aeffect_vframe, PIXMAP_ALPHA);
555         ladspa_vframe = new VFramePng(lad_picon_png);
556         ladspa_icon = new BC_Pixmap(this, ladspa_vframe, PIXMAP_ALPHA);
557         ff_aud_vframe = new VFramePng(ff_audio_png);
558         ff_aud_icon = new BC_Pixmap(this, ff_aud_vframe, PIXMAP_ALPHA);
559         ff_vid_vframe = new VFramePng(ff_video_png);
560         ff_vid_icon = new BC_Pixmap(this, ff_vid_vframe, PIXMAP_ALPHA);
561         veffect_vframe = mwindow->theme->get_image("veffect_icon");
562         veffect_icon = new BC_Pixmap(this, veffect_vframe, PIXMAP_ALPHA);
563
564 SET_TRACE
565
566 // Mandatory folders
567         folders.append(picon = new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER));
568         picon->persistent = 1;
569         folders.append(picon = new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER));
570         picon->persistent = 1;
571         folders.append(picon = new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER));
572         picon->persistent = 1;
573         folders.append(picon = new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER));
574         picon->persistent = 1;
575         folders.append(picon = new AssetPicon(mwindow, this, AW_LABEL_FOLDER));
576         picon->persistent = 1;
577         folders.append(picon = new AssetPicon(mwindow, this, AW_CLIP_FOLDER));
578         picon->persistent = 1;
579         folders.append(picon = new AssetPicon(mwindow, this, AW_MEDIA_FOLDER));
580         picon->persistent = 1;
581
582         create_label_folder();
583 SET_TRACE
584
585         mwindow->theme->get_awindow_sizes(this);
586         load_defaults(mwindow->defaults);
587
588 SET_TRACE
589         add_subwindow(asset_list = new AWindowAssets(mwindow,
590                 this,
591                 mwindow->theme->alist_x,
592                 mwindow->theme->alist_y,
593                 mwindow->theme->alist_w,
594                 mwindow->theme->alist_h));
595
596         vicon_thread = new VIconThread(asset_list);
597         vicon_thread->start();
598
599 SET_TRACE
600         add_subwindow(divider = new AWindowDivider(mwindow,
601                 this,
602                 mwindow->theme->adivider_x,
603                 mwindow->theme->adivider_y,
604                 mwindow->theme->adivider_w,
605                 mwindow->theme->adivider_h));
606
607 SET_TRACE
608         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
609
610 SET_TRACE
611         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
612         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
613         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
614         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
615         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
616         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
617         add_tools->create_objects();
618         fy += add_tools->get_h();  fh -= add_tools->get_h();
619 SET_TRACE
620         add_subwindow(folder_list = new AWindowFolders(mwindow,
621                 this, fx, fy, fw, fh));
622 SET_TRACE
623         update_effects();
624 SET_TRACE
625
626         //int x = mwindow->theme->abuttons_x;
627         //int y = mwindow->theme->abuttons_y;
628
629 SET_TRACE
630
631         newfolder_thread = new NewFolderThread(mwindow, this);
632
633         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
634         asset_menu->create_objects();
635         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
636         clip_menu->create_objects();
637         add_subwindow(label_menu = new LabelPopup(mwindow, this));
638         label_menu->create_objects();
639
640         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
641         effectlist_menu->create_objects();
642         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
643         assetlist_menu->create_objects();
644         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
645         cliplist_menu->create_objects();
646         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
647         labellist_menu->create_objects();
648 SET_TRACE
649
650         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
651         folderlist_menu->create_objects();
652 SET_TRACE
653 //printf("AWindowGUI::create_objects 2\n");
654
655         create_custom_xatoms();
656         unlock_window();
657 }
658
659 int AWindowGUI::resize_event(int w, int h)
660 {
661         mwindow->session->awindow_x = get_x();
662         mwindow->session->awindow_y = get_y();
663         mwindow->session->awindow_w = w;
664         mwindow->session->awindow_h = h;
665
666         mwindow->theme->get_awindow_sizes(this);
667         mwindow->theme->draw_awindow_bg(this);
668         reposition_objects();
669
670 //      int x = mwindow->theme->abuttons_x;
671 //      int y = mwindow->theme->abuttons_y;
672 //      new_bin->reposition_window(x, y);
673 //      x += new_bin->get_w();
674 //      delete_bin->reposition_window(x, y);
675 //      x += delete_bin->get_w();
676 //      rename_bin->reposition_window(x, y);
677 //      x += rename_bin->get_w();
678 //      delete_disk->reposition_window(x, y);
679 //      x += delete_disk->get_w();
680 //      delete_project->reposition_window(x, y);
681 //      x += delete_project->get_w();
682 //      info->reposition_window(x, y);
683 //      x += info->get_w();
684 //      redraw_index->reposition_window(x, y);
685 //      x += redraw_index->get_w();
686 //      paste->reposition_window(x, y);
687 //      x += paste->get_w();
688 //      append->reposition_window(x, y);
689 //      x += append->get_w();
690 //      view->reposition_window(x, y);
691
692         BC_WindowBase::resize_event(w, h);
693         return 1;
694 }
695
696 int AWindowGUI::translation_event()
697 {
698         mwindow->session->awindow_x = get_x();
699         mwindow->session->awindow_y = get_y();
700         return 0;
701 }
702
703 void AWindowGUI::reposition_objects()
704 {
705         asset_list->reposition_window(
706                 mwindow->theme->alist_x, mwindow->theme->alist_y,
707                 mwindow->theme->alist_w, mwindow->theme->alist_h);
708         divider->reposition_window(
709                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
710                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
711         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
712         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
713         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
714         avicon_drawing->reposition_window(fw-avicon_w, fy);
715         fy += add_tools->get_h();  fh -= add_tools->get_h();
716         folder_list->reposition_window(fx, fy, fw, fh);
717 }
718
719 int AWindowGUI::save_defaults(BC_Hash *defaults)
720 {
721         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
722         defaults->update("VICON_DRAWING", vicon_drawing);
723         return 0;
724 }
725
726 int AWindowGUI::load_defaults(BC_Hash *defaults)
727 {
728         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
729         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
730         return 0;
731 }
732
733 int AWindowGUI::close_event()
734 {
735         hide_window();
736         mwindow->session->show_awindow = 0;
737         unlock_window();
738
739         mwindow->gui->lock_window("AWindowGUI::close_event");
740         mwindow->gui->mainmenu->show_awindow->set_checked(0);
741         mwindow->gui->unlock_window();
742
743         lock_window("AWindowGUI::close_event");
744         save_defaults(mwindow->defaults);
745         mwindow->save_defaults();
746         return 1;
747 }
748
749 void AWindowGUI::start_vicon_drawing()
750 {
751         if( !vicon_drawing ) return;
752         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
753         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
754         vicon_thread->start_drawing();
755 }
756
757 void AWindowGUI::stop_vicon_drawing()
758 {
759         vicon_thread->stop_drawing();
760 }
761
762 AWindowRemovePluginGUI::
763 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
764         int x, int y, PluginServer *plugin)
765  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
766 {
767         this->awindow = awindow;
768         this->thread = thread;
769         this->plugin = plugin;
770         VFrame *vframe = plugin->get_picon();
771         icon = vframe ? create_pixmap(vframe) : 0;
772         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
773 }
774
775 AWindowRemovePluginGUI::
776 ~AWindowRemovePluginGUI()
777 {
778         if( !awindow->gui->protected_pixmap(icon) )
779                 delete icon;
780         plugin_list.remove_all();
781 }
782
783 void AWindowRemovePluginGUI::create_objects()
784 {
785         BC_Button *ok_button = new BC_OKButton(this);
786         add_subwindow(ok_button);
787         BC_Button *cancel_button = new BC_CancelButton(this);
788         add_subwindow(cancel_button);
789         int x = 10, y = 10;
790         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
791         add_subwindow(title);
792         y += title->get_h() + 5;
793         list = new BC_ListBox(x, y,
794                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
795                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
796         add_subwindow(list);
797         show_window();
798 }
799
800 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
801 {
802         int ret = 0;
803         for( int i=0; i<folder.size(); ) {
804                 AssetPicon *picon = (AssetPicon *)folder[i];
805                 if( picon->plugin == plugin ) {
806                         folder.remove_object_number(i);
807                         ++ret;
808                         continue;
809                 }
810                 ++i;
811         }
812         return ret;
813 }
814
815 void AWindowRemovePlugin::handle_close_event(int result)
816 {
817         if( !result ) {
818                 printf(_("remove %s\n"), plugin->path);
819                 ArrayList<BC_ListBoxItem*> *folder =
820                         plugin->audio ? plugin->transition ?
821                                 &awindow->gui->atransitions :
822                                 &awindow->gui->aeffects :
823                         plugin->video ?  plugin->transition ?
824                                 &awindow->gui->vtransitions :
825                                 &awindow->gui->veffects :
826                         0;
827                 if( folder ) remove_plugin(plugin, *folder);
828                 char plugin_path[BCTEXTLEN];
829                 strcpy(plugin_path, plugin->path);
830                 MWindow *mwindow = awindow->mwindow;
831                 mwindow->plugindb->remove(plugin);
832                 remove(plugin_path);
833                 char index_path[BCTEXTLEN];
834                 snprintf(index_path, sizeof(index_path), "%s/%s",
835                         mwindow->preferences->plugin_dir, PLUGIN_FILE);
836                 remove(index_path);
837                 char png_path[BCTEXTLEN];
838                 if( plugin->get_plugin_png_path(png_path, mwindow->preferences->plugin_icons) )
839                         remove(png_path);
840                 if( plugin->get_plugin_png_path(png_path, DEFAULT_PICON) )
841                         remove(png_path);
842                 delete plugin;  plugin = 0;
843                 awindow->gui->async_update_assets();
844         }
845 }
846
847 AWindowRemovePlugin::
848 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
849  : BC_DialogThread()
850 {
851         this->awindow = awindow;
852         this->plugin = plugin;
853 }
854
855 AWindowRemovePlugin::
856 ~AWindowRemovePlugin()
857 {
858         close_window();
859 }
860
861 BC_Window* AWindowRemovePlugin::new_gui()
862 {
863         int x = awindow->gui->get_abs_cursor_x(0);
864         int y = awindow->gui->get_abs_cursor_y(0);
865         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
866         gui->create_objects();
867         return gui;
868 }
869
870 int AWindowGUI::keypress_event()
871 {
872         switch( get_keypress() ) {
873         case 'w': case 'W':
874                 if( ctrl_down() ) {
875                         close_event();
876                         return 1;
877                 }
878                 break;
879         case DELETE:
880                 if( shift_down() ) {
881                         PluginServer* plugin = selected_plugin();
882                         if( !plugin ) break;
883                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
884                         unlock_window();
885                         remove_plugin->start();
886                         lock_window();
887                 }
888         }
889         return 0;
890 }
891
892
893
894 int AWindowGUI::create_custom_xatoms()
895 {
896         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
897         return 0;
898 }
899 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
900 {
901         if( event->message_type == UpdateAssetsXAtom ) {
902                 update_assets();
903                 return 1;
904         }
905         return 0;
906 }
907
908 void AWindowGUI::async_update_assets()
909 {
910         xatom_event event;
911         event.message_type = UpdateAssetsXAtom;
912         send_custom_xatom(&event);
913 }
914
915
916
917
918
919
920
921 void AWindowGUI::update_folder_list()
922 {
923         stop_vicon_drawing();
924 //printf("AWindowGUI::update_folder_list 1\n");
925         for( int i = 0; i < folders.total; i++ ) {
926                 AssetPicon *picon = (AssetPicon*)folders.values[i];
927                 picon->in_use--;
928         }
929 //printf("AWindowGUI::update_folder_list 1\n");
930
931 // Search assets for folders
932         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
933                 const char *folder = mwindow->edl->folders.values[i];
934                 int exists = 0;
935 //printf("AWindowGUI::update_folder_list 1.1\n");
936
937                 for( int j = 0; j < folders.total; j++ ) {
938                         AssetPicon *picon = (AssetPicon*)folders.values[j];
939                         if( !strcasecmp(picon->get_text(), folder) ) {
940                                 exists = 1;
941                                 picon->in_use = 1;
942                                 break;
943                         }
944                 }
945
946                 if( !exists ) {
947                         int aw_folder = folder_number(folder);
948                         AssetPicon *picon = aw_folder >= 0 ?
949                                 new AssetPicon(mwindow, this, aw_folder) :
950                                 new AssetPicon(mwindow, this, folder, AW_USER_FOLDER);
951                         picon->create_objects();
952                         folders.append(picon);
953                 }
954 //printf("AWindowGUI::update_folder_list 1.3\n");
955         }
956 //printf("AWindowGUI::update_folder_list 1\n");
957 //for( int i = 0; i < folders.total; i++ )
958 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
959
960 // Delete excess
961         for( int i = folders.total - 1; i >= 0; i-- ) {
962                 AssetPicon *picon = (AssetPicon*)folders.values[i];
963                 if( !picon->in_use && !picon->persistent ) {
964                         delete picon;
965                         folders.remove_number(i);
966                 }
967         }
968 //for( int i = 0; i < folders.total; i++ )
969 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
970 //printf("AWindowGUI::update_folder_list 2\n");
971         start_vicon_drawing();
972 }
973
974 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
975         int do_audio, int do_video, int is_realtime, int is_transition)
976 {
977         ArrayList<PluginServer*> plugin_list;
978 // Get pointers to plugindb entries
979         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
980                         0, plugin_list);
981
982         for( int i = 0; i < plugin_list.total; i++ ) {
983                 PluginServer *server = plugin_list.values[i];
984                 int visible = plugin_visibility & (1<<server->dir_idx);
985                 if( !visible ) continue;
986 // Create new listitem
987                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
988                 picon->create_objects();
989                 output->append(picon);
990         }
991 }
992
993 void AWindowGUI::create_label_folder()
994 {
995         Label *current;
996         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
997                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
998                 picon->create_objects();
999                 labellist.append(picon);
1000         }
1001 }
1002
1003
1004 void AWindowGUI::update_asset_list()
1005 {
1006 //printf("AWindowGUI::update_asset_list 1\n");
1007         for( int i = 0; i < assets.total; i++ ) {
1008                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1009                 picon->in_use--;
1010         }
1011
1012
1013
1014
1015
1016 //printf("AWindowGUI::update_asset_list 2\n");
1017
1018
1019 // Synchronize EDL clips
1020         for( int i = 0; i < mwindow->edl->clips.total; i++ ) {
1021                 int exists = 0;
1022
1023 // Look for clip in existing listitems
1024                 for( int j = 0; j < assets.total && !exists; j++ ) {
1025                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1026
1027                         if( picon->id == mwindow->edl->clips.values[i]->id ) {
1028                                 picon->edl = mwindow->edl->clips.values[i];
1029                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
1030                                 exists = 1;
1031                                 picon->in_use = 1;
1032                         }
1033                 }
1034
1035 // Create new listitem
1036                 if( !exists ) {
1037                         AssetPicon *picon = new AssetPicon(mwindow,
1038                                 this,
1039                                 mwindow->edl->clips.values[i]);
1040                         picon->create_objects();
1041                         assets.append(picon);
1042                 }
1043         }
1044
1045
1046
1047
1048
1049 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1050
1051
1052 // Synchronize EDL assets
1053         for( Asset *current = mwindow->edl->assets->first;
1054                 current;
1055                 current = NEXT ) {
1056                 int exists = 0;
1057
1058 // Look for asset in existing listitems
1059                 for( int j = 0; j < assets.total && !exists; j++ ) {
1060                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1061
1062                         if( picon->id == current->id ) {
1063                                 picon->indexable = current;
1064                                 exists = 1;
1065                                 picon->in_use = 1;
1066                                 break;
1067                         }
1068                 }
1069
1070 // Create new listitem
1071                 if( !exists ) {
1072 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1073                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
1074 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1075                         picon->create_objects();
1076 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1077                         assets.append(picon);
1078                 }
1079         }
1080
1081         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1082         mwindow->gui->default_message();
1083         mwindow->gui->unlock_window();
1084
1085 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1086
1087
1088 // Synchronize nested EDLs
1089         for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) {
1090                 int exists = 0;
1091                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
1092
1093 // Look for asset in existing listitems
1094                 for( int j = 0; j < assets.total && !exists; j++ ) {
1095                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1096
1097                         if( picon->id == indexable->id ) {
1098                                 picon->indexable = indexable;
1099                                 exists = 1;
1100                                 picon->in_use = 1;
1101                                 break;
1102                         }
1103                 }
1104
1105 // Create new listitem
1106                 if( !exists ) {
1107                         AssetPicon *picon = new AssetPicon(mwindow,
1108                                 this,
1109                                 indexable);
1110                         picon->create_objects();
1111                         assets.append(picon);
1112                 }
1113         }
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1124         for( int i = assets.size() - 1; i >= 0; i-- ) {
1125                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1126 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
1127                 if( !picon->in_use ) {
1128                         delete picon;
1129                         assets.remove_number(i);
1130                 }
1131         }
1132 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
1133 }
1134
1135 void AWindowGUI::update_picon(Indexable *indexable)
1136 {
1137 //printf("AWindowGUI::update_asset_list 1\n");
1138         VIcon *vicon = 0;
1139         for( int i = 0; i < assets.total; i++ ) {
1140                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1141                 if( picon->indexable == indexable ||
1142                     picon->edl == (EDL *)indexable ) {
1143                         char name[BCTEXTLEN];
1144                         FileSystem fs;
1145                         fs.extract_name(name, indexable->path);
1146                         picon->set_text(name);
1147                         vicon = picon->vicon;
1148                         break;
1149                 }
1150         }
1151         if( vicon ) {
1152                 stop_vicon_drawing();
1153                 vicon->clear_images();
1154                 vicon->reset(indexable->get_frame_rate());
1155                 start_vicon_drawing();
1156         }
1157 }
1158
1159 void AWindowGUI::sort_assets()
1160 {
1161 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
1162         switch( mwindow->edl->session->awindow_folder ) {
1163         case AW_AEFFECT_FOLDER:
1164                 sort_picons(&aeffects);
1165                 break;
1166         case AW_VEFFECT_FOLDER:
1167                 sort_picons(&veffects);
1168                 break;
1169         case AW_ATRANSITION_FOLDER:
1170                 sort_picons(&atransitions);
1171                 break;
1172         case AW_VTRANSITION_FOLDER:
1173                 sort_picons(&vtransitions);
1174                 break;
1175         case AW_LABEL_FOLDER:
1176                 sort_picons(&labellist);
1177                 break;
1178         default:
1179                 sort_picons(&assets);
1180         }
1181
1182         update_assets();
1183 }
1184
1185 void AWindowGUI::collect_assets()
1186 {
1187         int i = 0;
1188         mwindow->session->drag_assets->remove_all();
1189         mwindow->session->drag_clips->remove_all();
1190         while(1)
1191         {
1192                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
1193                 if( !result ) break;
1194
1195                 if( result->indexable ) mwindow->session->drag_assets->append(result->indexable);
1196                 if( result->edl ) mwindow->session->drag_clips->append(result->edl);
1197         }
1198 }
1199
1200 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1201         ArrayList<BC_ListBoxItem*> *src, int folder)
1202 {
1203 // Remove current pointers
1204         dst[0].remove_all();
1205         dst[1].remove_all_objects();
1206
1207 // Create new pointers
1208 //if( folder ) printf("AWindowGUI::copy_picons 1 %s\n", folder);
1209         for( int i = 0; i < src->total; i++ ) {
1210                 AssetPicon *picon = (AssetPicon*)src->values[i];
1211 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
1212                 if( folder < 0 ||
1213                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1214                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1215                         BC_ListBoxItem *item2, *item1;
1216                         dst[0].append(item1 = picon);
1217                         if( picon->edl )
1218                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1219                         else
1220                         if( picon->label && picon->label->textstr )
1221                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1222                         else
1223                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1224                         item1->set_autoplace_text(1);
1225                         item2->set_autoplace_text(1);
1226 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
1227                 }
1228         }
1229 }
1230
1231 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1232 {
1233 //printf("AWindowGUI::sort_picons 1\n")
1234         int done = 0;
1235         while(!done)
1236         {
1237                 done = 1;
1238                 for( int i = 0; i < src->total - 1; i++ ) {
1239                         BC_ListBoxItem *item1 = src->values[i];
1240                         BC_ListBoxItem *item2 = src->values[i + 1];
1241                         item1->set_autoplace_icon(1);
1242                         item2->set_autoplace_icon(1);
1243                         item1->set_autoplace_text(1);
1244                         item2->set_autoplace_text(1);
1245                         if( strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1246                                 src->values[i + 1] = item1;
1247                                 src->values[i] = item2;
1248                                 done = 0;
1249                         }
1250                 }
1251         }
1252 }
1253
1254
1255 void AWindowGUI::filter_displayed_assets()
1256 {
1257         //allow_iconlisting = 1;
1258         asset_titles[0] = _("Title");
1259         asset_titles[1] = _("Comments");
1260
1261         switch( mwindow->edl->session->awindow_folder ) {
1262         case AW_AEFFECT_FOLDER:
1263                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1264                 break;
1265         case AW_VEFFECT_FOLDER:
1266                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1267                 break;
1268         case AW_ATRANSITION_FOLDER:
1269                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1270                 break;
1271         case AW_VTRANSITION_FOLDER:
1272                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1273                 break;
1274         case AW_LABEL_FOLDER:
1275                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1276                 asset_titles[0] = _("Time Stamps");
1277                 asset_titles[1] = _("Title");
1278                 //allow_iconlisting = 0;
1279                 break;
1280         default:
1281                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1282                 break;
1283         }
1284
1285         // Ensure the current folder icon is highlighted
1286         for( int i = 0; i < folders.total; i++ )
1287                 folders.values[i]->set_selected(0);
1288
1289         folders.values[mwindow->edl->session->awindow_folder]->set_selected(1);
1290 }
1291
1292
1293 void AWindowGUI::update_assets()
1294 {
1295 //printf("AWindowGUI::update_assets 1\n");
1296         update_folder_list();
1297 //printf("AWindowGUI::update_assets 2\n");
1298         update_asset_list();
1299         labellist.remove_all_objects();
1300         create_label_folder();
1301 //printf("AWindowGUI::update_assets 3\n");
1302         filter_displayed_assets();
1303
1304 //for( int i = 0; i < folders.total; i++ )
1305 //printf("AWindowGUI::update_assets 4\n");
1306 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
1307         if( mwindow->edl->session->folderlist_format != folder_list->get_format() )
1308                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1309         folder_list->update(&folders, 0, 0, 1,
1310                 folder_list->get_xposition(),
1311                 folder_list->get_yposition(),
1312                 -1);
1313 //printf("AWindowGUI::update_assets 5\n");
1314
1315         if( mwindow->edl->session->assetlist_format != asset_list->get_format() )
1316                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1317
1318
1319 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
1320         asset_list->update(displayed_assets, asset_titles,
1321                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1322                 asset_list->get_xposition(),
1323                 asset_list->get_yposition(),
1324                 -1, 0);
1325         asset_list->center_selection();
1326 //printf("AWindowGUI::update_assets 7\n");
1327
1328         flush();
1329 //printf("AWindowGUI::update_assets 8\n");
1330         return;
1331 }
1332
1333 void AWindowGUI::update_effects()
1334 {
1335         aeffects.remove_all_objects();
1336         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1337         veffects.remove_all_objects();
1338         create_persistent_folder(&veffects, 0, 1, 1, 0);
1339         atransitions.remove_all_objects();
1340         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1341         vtransitions.remove_all_objects();
1342         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1343 }
1344
1345 int AWindowGUI::folder_number(const char *name)
1346 {
1347         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1348                 if( !strcasecmp(name, folder_names[i]) ) return i;
1349         }
1350         return AW_NO_FOLDER;
1351 }
1352
1353 int AWindowGUI::drag_motion()
1354 {
1355         if( get_hidden() ) return 0;
1356
1357         int result = 0;
1358         return result;
1359 }
1360
1361 int AWindowGUI::drag_stop()
1362 {
1363         if( get_hidden() ) return 0;
1364
1365         return 0;
1366 }
1367
1368 Indexable* AWindowGUI::selected_asset()
1369 {
1370         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1371         return picon ? picon->indexable : 0;
1372 }
1373
1374 PluginServer* AWindowGUI::selected_plugin()
1375 {
1376         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1377         return picon ? picon->plugin : 0;
1378 }
1379
1380 AssetPicon* AWindowGUI::selected_folder()
1381 {
1382         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1383         return picon;
1384 }
1385
1386
1387
1388
1389
1390
1391
1392
1393 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1394  : BC_SubWindow(x, y, w, h)
1395 {
1396         this->mwindow = mwindow;
1397         this->gui = gui;
1398 }
1399 AWindowDivider::~AWindowDivider()
1400 {
1401 }
1402
1403 int AWindowDivider::button_press_event()
1404 {
1405         if( is_event_win() && cursor_inside() ) {
1406                 mwindow->session->current_operation = DRAG_PARTITION;
1407                 return 1;
1408         }
1409         return 0;
1410 }
1411
1412 int AWindowDivider::cursor_motion_event()
1413 {
1414         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1415                 int wmin = 25;
1416                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1417                 int fw = gui->get_relative_cursor_x();
1418                 if( fw > wmax ) fw = wmax;
1419                 if( fw < wmin ) fw = wmin;
1420                 mwindow->session->afolders_w = fw;
1421                 mwindow->theme->get_awindow_sizes(gui);
1422                 gui->reposition_objects();
1423                 gui->flush();
1424         }
1425         return 0;
1426 }
1427
1428 int AWindowDivider::button_release_event()
1429 {
1430         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1431                 mwindow->session->current_operation = NO_OPERATION;
1432                 return 1;
1433         }
1434         return 0;
1435 }
1436
1437
1438
1439
1440
1441
1442 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1443  : BC_ListBox(x, y, w, h,
1444                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1445                         LISTBOX_ICONS : LISTBOX_TEXT,
1446                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1447                 0,                // Titles for columns.  Set to 0 for no titles
1448                 0,                // width of each column
1449                 1,                // Total columns.
1450                 0,                // Pixel of top of window.
1451                 0,                // If this listbox is a popup window
1452                 LISTBOX_SINGLE,   // Select one item or multiple items
1453                 ICON_TOP,         // Position of icon relative to text of each item
1454                 1)                // Allow drags
1455 {
1456         this->mwindow = mwindow;
1457         this->gui = gui;
1458         set_drag_scroll(0);
1459 }
1460
1461 AWindowFolders::~AWindowFolders()
1462 {
1463 }
1464
1465 int AWindowFolders::selection_changed()
1466 {
1467         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1468         if( picon ) {
1469                 gui->stop_vicon_drawing();
1470
1471                 if( get_button_down() && get_buttonpress() == 3 ) {
1472                         gui->folderlist_menu->update_titles();
1473                         gui->folderlist_menu->activate_menu();
1474                 }
1475
1476                 mwindow->edl->session->awindow_folder =  picon->foldernum;
1477 //printf("AWindowFolders::selection_changed 1\n");
1478                 gui->asset_list->draw_background();
1479                 gui->async_update_assets();
1480
1481                 gui->start_vicon_drawing();
1482         }
1483         return 1;
1484 }
1485
1486 int AWindowFolders::button_press_event()
1487 {
1488         int result = 0;
1489
1490         result = BC_ListBox::button_press_event();
1491
1492         if( !result ) {
1493                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1494                         gui->folderlist_menu->update_titles();
1495                         gui->folderlist_menu->activate_menu();
1496                         result = 1;
1497                 }
1498         }
1499
1500
1501         return result;
1502 }
1503
1504
1505
1506
1507
1508
1509
1510 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1511  : BC_ListBox(x, y, w, h,
1512                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1513                         LISTBOX_ICONS : LISTBOX_TEXT,
1514                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1515                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1516                 mwindow->edl->session->asset_columns, // width of each column
1517                 1,                // Total columns.
1518                 0,                // Pixel of top of window.
1519                 0,                // If this listbox is a popup window
1520                 LISTBOX_MULTIPLE, // Select one item or multiple items
1521                 ICON_TOP,         // Position of icon relative to text of each item
1522                 1)                // Allow drag
1523 {
1524         this->mwindow = mwindow;
1525         this->gui = gui;
1526         set_drag_scroll(0);
1527         set_scroll_stretch(1, 1);
1528 }
1529
1530 AWindowAssets::~AWindowAssets()
1531 {
1532 }
1533
1534 int AWindowAssets::button_press_event()
1535 {
1536         int result = 0;
1537
1538         result = BC_ListBox::button_press_event();
1539
1540         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1541                 BC_ListBox::deactivate_selection();
1542                 int folder = mwindow->edl->session->awindow_folder;
1543                 switch( folder ) {
1544                 case AW_AEFFECT_FOLDER:
1545                 case AW_VEFFECT_FOLDER:
1546                 case AW_ATRANSITION_FOLDER:
1547                 case AW_VTRANSITION_FOLDER:
1548                         gui->effectlist_menu->update();
1549                         gui->effectlist_menu->activate_menu();
1550                         break;
1551                 case AW_LABEL_FOLDER:
1552                         gui->labellist_menu->update();
1553                         gui->labellist_menu->activate_menu();
1554                         break;
1555                 case AW_CLIP_FOLDER:
1556                         gui->cliplist_menu->update();
1557                         gui->cliplist_menu->activate_menu();
1558                         break;
1559                 case AW_MEDIA_FOLDER:
1560                         gui->assetlist_menu->update_titles();
1561                         gui->assetlist_menu->activate_menu();
1562                         break;
1563                 }
1564                 result = 1;
1565         }
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