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