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