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