r632: Boost up the requirement for mjpegtools to 1.6.3
[cinelerra_cv/mob.git] / cinelerra / awindowgui.C
blobbceaecd4764b992d92da41f12ffbd079bbc86c21
1 #include "asset.h"
2 #include "assetedit.h"
3 #include "assetpopup.h"
4 #include "assets.h"
5 #include "awindowgui.h"
6 #include "awindowgui.inc"
7 #include "awindow.h"
8 #include "awindowmenu.h"
9 #include "cache.h"
10 #include "colormodels.h"
11 #include "cursors.h"
12 #include "cwindowgui.h"
13 #include "cwindow.h"
14 #include "edl.h"
15 #include "edlsession.h"
16 #include "file.h"
17 #include "filesystem.h"
18 #include "language.h"
19 #include "localsession.h"
20 #include "mainmenu.h"
21 #include "mainsession.h"
22 #include "mwindowgui.h"
23 #include "mwindow.h"
24 #include "newfolder.h"
25 #include "preferences.h"
26 #include "theme.h"
27 #include "vframe.h"
28 #include "vwindowgui.h"
29 #include "vwindow.h"
34 AssetPicon::AssetPicon(MWindow *mwindow, 
35         AWindowGUI *gui, 
36         Asset *asset)
37  : BC_ListBoxItem()
39         reset();
40         this->mwindow = mwindow;
41         this->gui = gui;
42         this->asset = asset;
43         this->id = asset->id;
46 AssetPicon::AssetPicon(MWindow *mwindow, 
47         AWindowGUI *gui, 
48         EDL *edl)
49  : BC_ListBoxItem()
51         reset();
52         this->mwindow = mwindow;
53         this->gui = gui;
54         this->edl = edl;
55         this->id = edl->id;
58 AssetPicon::AssetPicon(MWindow *mwindow, 
59         AWindowGUI *gui, 
60         char *folder)
61  : BC_ListBoxItem(folder, gui->folder_icon)
63         reset();
64         this->mwindow = mwindow;
65         this->gui = gui;
68 AssetPicon::AssetPicon(MWindow *mwindow, 
69         AWindowGUI *gui, 
70         PluginServer *plugin)
71  : BC_ListBoxItem()
73         reset();
74         this->mwindow = mwindow;
75         this->gui = gui;
76         this->plugin = plugin;
77         asset = 0;
78         icon = 0;
79         id = 0;
82 AssetPicon::~AssetPicon()
84         if(icon)
85         {
86                 if(icon != gui->file_icon &&
87                         icon != gui->audio_icon &&
88                         icon != gui->folder_icon &&
89                         icon != gui->clip_icon &&
90                         icon != gui->video_icon) 
91                 {
92                         delete icon;
93                         delete icon_vframe;
94                 }
95         }
98 void AssetPicon::reset()
100         plugin = 0;
101         asset = 0;
102         edl = 0;
103         icon = 0;
104         icon_vframe = 0;
105         in_use = 1;
106         id = 0;
107         persistent = 0;
110 void AssetPicon::create_objects()
112         FileSystem fs;
113         char name[BCTEXTLEN];
114         int pixmap_w, pixmap_h;
117         pixmap_h = 50;
119         if(asset)
120         {
121                 fs.extract_name(name, asset->path);
122                 set_text(name);
123                 if(asset->video_data)
124                 {
125                         if(mwindow->preferences->use_thumbnails)
126                         {
127                                 File *file = mwindow->video_cache->check_out(asset);
129                                 if(file)
130                                 {
131                                         pixmap_w = pixmap_h * asset->width / asset->height;
133                                         file->set_layer(0);
134                                         file->set_video_position(0, mwindow->edl->session->frame_rate);
136                                         if(gui->temp_picon && 
137                                                 (gui->temp_picon->get_w() != asset->width ||
138                                                 gui->temp_picon->get_h() != asset->height))
139                                         {
140                                                 delete gui->temp_picon;
141                                                 gui->temp_picon = 0;
142                                         }
144                                         if(!gui->temp_picon)
145                                         {
146                                                 gui->temp_picon = new VFrame(0, 
147                                                         asset->width, 
148                                                         asset->height, 
149                                                         BC_RGB888);
150                                         }
152                                         file->read_frame(gui->temp_picon);
154                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
155                                         icon->draw_vframe(gui->temp_picon,
156                                                 0, 
157                                                 0, 
158                                                 pixmap_w, 
159                                                 pixmap_h,
160                                                 0,
161                                                 0);
162 //printf("%d %d\n", gui->temp_picon->get_w(), gui->temp_picon->get_h());
163                                         icon_vframe = new VFrame(0, 
164                                                 pixmap_w, 
165                                                 pixmap_h, 
166                                                 BC_RGB888);
167                                         cmodel_transfer(icon_vframe->get_rows(), /* Leave NULL if non existent */
168                                                 gui->temp_picon->get_rows(),
169                                                 0, /* Leave NULL if non existent */
170                                                 0,
171                                                 0,
172                                                 0, /* Leave NULL if non existent */
173                                                 0,
174                                                 0,
175                                                 0,        /* Dimensions to capture from input frame */
176                                                 0, 
177                                                 gui->temp_picon->get_w(), 
178                                                 gui->temp_picon->get_h(),
179                                                 0,       /* Dimensions to project on output frame */
180                                                 0, 
181                                                 pixmap_w, 
182                                                 pixmap_h,
183                                                 BC_RGB888, 
184                                                 BC_RGB888,
185                                                 0,         /* When transfering BC_RGBA8888 to non-alpha this is the background color in 0xRRGGBB hex */
186                                                 0,       /* For planar use the luma rowspan */
187                                                 0);     /* For planar use the luma rowspan */
190                                         mwindow->video_cache->check_in(asset);
191                                 }
192                                 else
193                                 {
194                                         icon = gui->video_icon;
195                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
197                                 }
198                         }
199                         else
200                         {
201                                 icon = gui->video_icon;
202                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];                  
203                         }
204                 }
205                 else
206                 if(asset->audio_data)
207                 {
208                         icon = gui->audio_icon;
209                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
210                 }
211 //printf("AssetPicon::create_objects 2\n");
213                 set_icon(icon);
214                 set_icon_vframe(icon_vframe);
215 //printf("AssetPicon::create_objects 4\n");
216         }
217         else
218         if(edl)
219         {
220 //printf("AssetPicon::create_objects 4 %s\n", edl->local_session->clip_title);
221                 strcpy(name, edl->local_session->clip_title);
222                 set_text(name);
223                 set_icon(gui->clip_icon);
224                 set_icon_vframe(mwindow->theme->clip_icon);
225         }
226         else
227         if(plugin)
228         {
229                 strcpy(name, _(plugin->title));
230                 set_text(name);
231                 if(plugin->picon)
232                 {
233                         if(plugin->picon->get_color_model() == BC_RGB888)
234                         {
235                                 icon = new BC_Pixmap(gui, 
236                                         plugin->picon->get_w(), 
237                                         plugin->picon->get_h());
238                                 icon->draw_vframe(plugin->picon,
239                                         0,
240                                         0,
241                                         plugin->picon->get_w(), 
242                                         plugin->picon->get_h(),
243                                         0,
244                                         0);
245                         }
246                         else
247                         {
248                                 icon = new BC_Pixmap(gui, 
249                                         plugin->picon, 
250                                         PIXMAP_ALPHA);
251                         }
252                         icon_vframe = new VFrame (*plugin->picon);
253                 }
254                 else
255                 {
256                         icon = gui->file_icon;
257                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
258                 }
259                 set_icon(icon);
260                 set_icon_vframe(icon_vframe);
261         }
270 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
271  : BC_Window(PROGRAM_NAME ": Resources",
272         mwindow->session->awindow_x, 
273     mwindow->session->awindow_y, 
274     mwindow->session->awindow_w, 
275     mwindow->session->awindow_h,
276     100,
277     100,
278     1,
279     1,
280     1)
282 // printf("AWindowGUI::AWindowGUI %d %d %d %d\n",
283 // mwindow->session->awindow_x, 
284 // mwindow->session->awindow_y, 
285 // mwindow->session->awindow_w, 
286 // mwindow->session->awindow_h);
287         this->mwindow = mwindow;
288         this->awindow = awindow;
289         temp_picon = 0;
292 AWindowGUI::~AWindowGUI()
294         assets.remove_all_objects();
295         folders.remove_all_objects();
296         aeffects.remove_all_objects();
297         veffects.remove_all_objects();
298         atransitions.remove_all_objects();
299         vtransitions.remove_all_objects();
300         displayed_assets[1].remove_all_objects();
301         delete file_icon;
302         delete audio_icon;
303         delete folder_icon;
304         delete clip_icon;
305         delete newfolder_thread;
306         delete asset_menu;
307         delete assetlist_menu;
308         delete folderlist_menu;
309         if(temp_picon) delete temp_picon;
312 int AWindowGUI::create_objects()
314         int x, y;
315         AssetPicon *picon;
317 //printf("AWindowGUI::create_objects 1\n");
318         asset_titles[0] = _("Title");
319         asset_titles[1] = _("Comments");
321         set_icon(mwindow->theme->awindow_icon);
322         file_icon = new BC_Pixmap(this, 
323                 BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
324                 PIXMAP_ALPHA);
326         folder_icon = new BC_Pixmap(this, 
327                 BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
328                 PIXMAP_ALPHA);
330         audio_icon = new BC_Pixmap(this, 
331                 BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
332                 PIXMAP_ALPHA);
334         video_icon = new BC_Pixmap(this, 
335                 BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
336                 PIXMAP_ALPHA);
338         clip_icon = new BC_Pixmap(this, 
339                 mwindow->theme->clip_icon,
340                 PIXMAP_ALPHA);
342 // Mandatory folders
343         folders.append(picon = new AssetPicon(mwindow,
344                 this,
345                 AEFFECT_FOLDER));
346         picon->persistent = 1;
347         folders.append(picon = new AssetPicon(mwindow,
348                 this,
349                 VEFFECT_FOLDER));
350         picon->persistent = 1;
351         folders.append(picon = new AssetPicon(mwindow,
352                 this,
353                 ATRANSITION_FOLDER));
354         picon->persistent = 1;
355         folders.append(picon = new AssetPicon(mwindow,
356                 this,
357                 VTRANSITION_FOLDER));
358         picon->persistent = 1;
360         create_persistent_folder(&aeffects, 1, 0, 1, 0);
361         create_persistent_folder(&veffects, 0, 1, 1, 0);
362         create_persistent_folder(&atransitions, 1, 0, 0, 1);
363         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
365         mwindow->theme->get_awindow_sizes(this);
366         add_subwindow(asset_list = new AWindowAssets(mwindow,
367                 this,
368                 mwindow->theme->alist_x, 
369         mwindow->theme->alist_y, 
370         mwindow->theme->alist_w, 
371         mwindow->theme->alist_h));
372         add_subwindow(divider = new AWindowDivider(mwindow,
373                 this,
374                 mwindow->theme->adivider_x,
375                 mwindow->theme->adivider_y,
376                 mwindow->theme->adivider_w,
377                 mwindow->theme->adivider_h));
378         divider->set_cursor(HSEPARATE_CURSOR);
379         add_subwindow(folder_list = new AWindowFolders(mwindow,
380                 this,
381                 mwindow->theme->afolders_x, 
382         mwindow->theme->afolders_y, 
383         mwindow->theme->afolders_w, 
384         mwindow->theme->afolders_h));
385         
386         x = mwindow->theme->abuttons_x;
387         y = mwindow->theme->abuttons_y;
389         newfolder_thread = new NewFolderThread(mwindow, this);
391         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
392         asset_menu->create_objects();
394         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
395         assetlist_menu->create_objects();
397         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
398         folderlist_menu->create_objects();
399 //printf("AWindowGUI::create_objects 2\n");
401         return 0;
404 int AWindowGUI::resize_event(int w, int h)
406         mwindow->session->awindow_x = get_x();
407         mwindow->session->awindow_y = get_y();
408         mwindow->session->awindow_w = w;
409         mwindow->session->awindow_h = h;
411         mwindow->theme->get_awindow_sizes(this);
412         mwindow->theme->draw_awindow_bg(this);
414         asset_list->reposition_window(mwindow->theme->alist_x, 
415         mwindow->theme->alist_y, 
416         mwindow->theme->alist_w, 
417         mwindow->theme->alist_h);
418         divider->reposition_window(mwindow->theme->adivider_x,
419                 mwindow->theme->adivider_y,
420                 mwindow->theme->adivider_w,
421                 mwindow->theme->adivider_h);
422         folder_list->reposition_window(mwindow->theme->afolders_x, 
423         mwindow->theme->afolders_y, 
424         mwindow->theme->afolders_w, 
425         mwindow->theme->afolders_h);
426         
427         int x = mwindow->theme->abuttons_x;
428         int y = mwindow->theme->abuttons_y;
430 //      new_bin->reposition_window(x, y);
431 //      x += new_bin->get_w();
432 //      delete_bin->reposition_window(x, y);
433 //      x += delete_bin->get_w();
434 //      rename_bin->reposition_window(x, y);
435 //      x += rename_bin->get_w();
436 //      delete_disk->reposition_window(x, y);
437 //      x += delete_disk->get_w();
438 //      delete_project->reposition_window(x, y);
439 //      x += delete_project->get_w();
440 //      info->reposition_window(x, y);
441 //      x += info->get_w();
442 //      redraw_index->reposition_window(x, y);
443 //      x += redraw_index->get_w();
444 //      paste->reposition_window(x, y);
445 //      x += paste->get_w();
446 //      append->reposition_window(x, y);
447 //      x += append->get_w();
448 //      view->reposition_window(x, y);
450         BC_WindowBase::resize_event(w, h);
451         return 1;
454 int AWindowGUI::translation_event()
456         mwindow->session->awindow_x = get_x();
457         mwindow->session->awindow_y = get_y();
458         return 0;
461 void AWindowGUI::reposition_objects()
463         mwindow->theme->get_awindow_sizes(this);
464         asset_list->reposition_window(mwindow->theme->alist_x, 
465         mwindow->theme->alist_y, 
466         mwindow->theme->alist_w, 
467         mwindow->theme->alist_h);
468         divider->reposition_window(mwindow->theme->adivider_x,
469                 mwindow->theme->adivider_y,
470                 mwindow->theme->adivider_w,
471                 mwindow->theme->adivider_h);
472         folder_list->reposition_window(mwindow->theme->afolders_x, 
473         mwindow->theme->afolders_y, 
474         mwindow->theme->afolders_w, 
475         mwindow->theme->afolders_h);
476         flush();
479 int AWindowGUI::close_event()
481         hide_window();
482         mwindow->session->show_awindow = 0;
483         mwindow->gui->lock_window("AWindowGUI::close_event");
484         mwindow->gui->mainmenu->show_awindow->set_checked(0);
485         mwindow->gui->unlock_window();
486         mwindow->save_defaults();
487         return 1;
491 int AWindowGUI::keypress_event()
493         switch(get_keypress())
494         {
495                 case 'w':
496                 case 'W':
497                         if(ctrl_down())
498                         {
499                                 close_event();
500                                 return 1;
501                         }
502                         break;
503         }
504         return 0;
507 void AWindowGUI::update_folder_list()
509 //printf("AWindowGUI::update_folder_list 1\n");
510         for(int i = 0; i < folders.total; i++)
511         {
512                 AssetPicon *picon = (AssetPicon*)folders.values[i];
513                 picon->in_use--;
514         }
515 //printf("AWindowGUI::update_folder_list 1\n");
517 // Search assets for folders
518         for(int i = 0; i < mwindow->edl->folders.total; i++)
519         {
520                 char *folder = mwindow->edl->folders.values[i];
521                 int exists = 0;
522 //printf("AWindowGUI::update_folder_list 1.1\n");
524                 for(int j = 0; j < folders.total; j++)
525                 {
526                         AssetPicon *picon = (AssetPicon*)folders.values[j];
527                         if(!strcasecmp(picon->get_text(), folder))
528                         {
529                                 exists = 1;
530                                 picon->in_use = 1;
531                                 break;
532                         }
533                 }
535                 if(!exists)
536                 {
537                         AssetPicon *picon = new AssetPicon(mwindow, this, folder);
538                         picon->create_objects();
539                         folders.append(picon);
540                 }
541 //printf("AWindowGUI::update_folder_list 1.3\n");
542         }
543 //printf("AWindowGUI::update_folder_list 1\n");
544 //for(int i = 0; i < folders.total; i++)
545 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
547 // Delete excess
548         for(int i = folders.total - 1; i >= 0; i--)
549         {
550                 AssetPicon *picon = (AssetPicon*)folders.values[i];
551                 if(!picon->in_use && !picon->persistent)
552                 {
553                         delete picon;
554                         folders.remove_number(i);
555                 }
556         }
557 //for(int i = 0; i < folders.total; i++)
558 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
559 //printf("AWindowGUI::update_folder_list 2\n");
562 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output, 
563         int do_audio, 
564         int do_video, 
565         int is_realtime, 
566         int is_transition)
568         ArrayList<PluginServer*> plugindb;
570 // Get pointers to plugindb entries
571         mwindow->create_plugindb(do_audio, 
572                         do_video, 
573                         is_realtime, 
574                         is_transition,
575                         0,
576                         plugindb);
578         for(int i = 0; i < plugindb.total; i++)
579         {
580                 PluginServer *server = plugindb.values[i];
581                 int exists = 0;
583 // Create new listitem
584                 if(!exists)
585                 {
586                         AssetPicon *picon = new AssetPicon(mwindow, this, server);
587                         picon->create_objects();
588                         output->append(picon);
589                 }
590         }
593 void AWindowGUI::update_asset_list()
595 //printf("AWindowGUI::update_asset_list 1\n");
596         for(int i = 0; i < assets.total; i++)
597         {
598                 AssetPicon *picon = (AssetPicon*)assets.values[i];
599                 picon->in_use--;
600         }
606 //printf("AWindowGUI::update_asset_list 2\n");
609 // Synchronize EDL clips
610         for(int i = 0; i < mwindow->edl->clips.total; i++)
611         {
612                 int exists = 0;
613                 
614 // Look for clip in existing listitems
615                 for(int j = 0; j < assets.total && !exists; j++)
616                 {
617                         AssetPicon *picon = (AssetPicon*)assets.values[j];
618                         
619                         if(picon->id == mwindow->edl->clips.values[i]->id)
620                         {
621                                 picon->edl = mwindow->edl->clips.values[i];
622                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
623                                 exists = 1;
624                                 picon->in_use = 1;
625                         }
626                 }
628 // Create new listitem
629                 if(!exists)
630                 {
631                         AssetPicon *picon = new AssetPicon(mwindow, 
632                                 this, 
633                                 mwindow->edl->clips.values[i]);
634                         picon->create_objects();
635                         assets.append(picon);
636                 }
637         }
645 //printf("AWindowGUI::update_asset_list 3 %d\n", assets.total);
646 // Synchronize EDL assets
647         for(Asset *current = mwindow->edl->assets->first; 
648                 current; 
649                 current = NEXT)
650         {
651                 int exists = 0;
653 //printf("AWindowGUI::update_asset_list 3 %s\n", current->path);
654 // Look for asset in existing listitems
655                 for(int j = 0; j < assets.total && !exists; j++)
656                 {
657                         AssetPicon *picon = (AssetPicon*)assets.values[j];
659                         if(picon->id == current->id)
660                         {
661 //printf("AWindowGUI::update_asset_list 4 %p %d %d\n", picon->asset, picon->get_icon_x(), picon->get_icon_y());
662                                 picon->asset = current;
663                                 exists = 1;
664                                 picon->in_use = 1;
665                                 break;
666                         }
667                 }
669 //printf("AWindowGUI::update_asset_list 5\n");
670 // Create new listitem
671                 if(!exists)
672                 {
673 //printf("AWindowGUI::update_asset_list 4.1 %s\n", current->path);
674                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
675 //printf("AWindowGUI::update_asset_list 4.2 %s\n", current->path);
676                         picon->create_objects();
677 //printf("AWindowGUI::update_asset_list 4.3 %s\n", current->path);
678                         assets.append(picon);
679 //printf("AWindowGUI::update_asset_list 4.4 %s\n", current->path);
680                 }
681         }
691 //printf("AWindowGUI::update_asset_list 6\n");
692         for(int i = assets.total - 1; i >= 0; i--)
693         {
694                 AssetPicon *picon = (AssetPicon*)assets.values[i];
695 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
696                 if(!picon->in_use)
697                 {
698                         delete picon;
699                         assets.remove_number(i);
700                 }
701         }
702 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
709 void AWindowGUI::sort_assets()
711 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
712         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
713                 sort_picons(&aeffects, 
714                         0);
715         else
716         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
717                 sort_picons(&veffects, 
718                         0);
719         else
720         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
721                 sort_picons(&atransitions, 
722                         0);
723         else
724         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
725                 sort_picons(&vtransitions, 
726                         0);
727         else
728                 sort_picons(&assets, 
729                         mwindow->edl->session->current_folder);
731         update_assets();
744 void AWindowGUI::collect_assets()
746         int i = 0;
747         mwindow->session->drag_assets->remove_all();
748         mwindow->session->drag_clips->remove_all();
749         while(1)
750         {
751                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
752                 if(!result) break;
754                 if(result->asset) mwindow->session->drag_assets->append(result->asset);
755                 if(result->edl) mwindow->session->drag_clips->append(result->edl);
756         }
759 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst, 
760         ArrayList<BC_ListBoxItem*> *src, 
761         char *folder)
763 // Remove current pointers
764         dst[0].remove_all();
765         dst[1].remove_all_objects();
767 // Create new pointers
768 //if(folder) printf("AWindowGUI::copy_picons 1 %s\n", folder);
769         for(int i = 0; i < src->total; i++)
770         {
771                 AssetPicon *picon = (AssetPicon*)src->values[i];
772 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
773                 if(!folder ||
774                         (folder && picon->asset && !strcasecmp(picon->asset->folder, folder)) ||
775                         (folder && picon->edl && !strcasecmp(picon->edl->local_session->folder, folder)))
776                 {
777                         BC_ListBoxItem *item2, *item1;
778                         dst[0].append(item1 = picon);
779                         if(picon->edl)
780                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
781                         else
782                                 dst[1].append(item2 = new BC_ListBoxItem(""));
783                         item1->set_autoplace_text(1);
784                         item2->set_autoplace_text(1);
785 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
786                 }
787         }
790 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, 
791                 char *folder)
793 //printf("AWindowGUI::sort_picons 1\n")
794         int done = 0;
795         while(!done)
796         {
797                 done = 1;
798                 for(int i = 0; i < src->total - 1; i++)
799                 {
800                         BC_ListBoxItem *item1 = src->values[i];
801                         BC_ListBoxItem *item2 = src->values[i + 1];
802                         item1->set_autoplace_icon(1);
803                         item2->set_autoplace_icon(1);
804                         item1->set_autoplace_text(1);
805                         item2->set_autoplace_text(1);
806                         if(strcmp(item1->get_text(), item2->get_text()) > 0)
807                         {
808                                 src->values[i + 1] = item1;
809                                 src->values[i] = item2;
810                                 done = 0;
811                         }
812                 }
813         }
817 void AWindowGUI::filter_displayed_assets()
819         if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
820                 copy_picons(displayed_assets, 
821                         &aeffects, 
822                         0);
823         else
824         if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
825                 copy_picons(displayed_assets, 
826                         &veffects, 
827                         0);
828         else
829         if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
830                 copy_picons(displayed_assets, 
831                         &atransitions, 
832                         0);
833         else
834         if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
835                 copy_picons(displayed_assets, 
836                         &vtransitions, 
837                         0);
838         else
839                 copy_picons(displayed_assets, 
840                         &assets, 
841                         mwindow->edl->session->current_folder);
845 void AWindowGUI::update_assets()
847 //printf("AWindowGUI::update_assets 1\n");
848         update_folder_list();
849 //printf("AWindowGUI::update_assets 2\n");
850         update_asset_list();
851 //printf("AWindowGUI::update_assets 3\n");
852         filter_displayed_assets();
854 //for(int i = 0; i < folders.total; i++)
855 //printf("AWindowGUI::update_assets 4\n");
856 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
857         if(mwindow->edl->session->folderlist_format != folder_list->get_format())
858                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
859         folder_list->update(&folders,
860                 0,
861                 0,
862                 1,
863                 folder_list->get_xposition(),
864                 folder_list->get_yposition(),
865                 -1);
866 //printf("AWindowGUI::update_assets 5\n");
868         if(mwindow->edl->session->assetlist_format != asset_list->get_format())
869                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
872 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
873         asset_list->update(displayed_assets,
874                 asset_titles,
875                 mwindow->edl->session->asset_columns,
876                 ASSET_COLUMNS, 
877                 asset_list->get_xposition(),
878                 asset_list->get_yposition(),
879                 -1,
880                 0);
881 //printf("AWindowGUI::update_assets 7\n");
883         flush();
884 //printf("AWindowGUI::update_assets 8\n");
885         return;
888 int AWindowGUI::current_folder_number()
890         int result = -1;
891         for(int i = 0; i < folders.total; i++)
892         {
893                 if(!strcasecmp(folders.values[i]->get_text(), mwindow->edl->session->current_folder))
894                 {
895                         result = i;
896                         break;
897                 }
898         }
899         return result;
902 int AWindowGUI::drag_motion()
904         if(get_hidden()) return 0;
906         int result = 0;
907         return result;
910 int AWindowGUI::drag_stop()
912         if(get_hidden()) return 0;
914         return 0;
917 Asset* AWindowGUI::selected_asset()
919         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
920         if(picon) return picon->asset;
923 PluginServer* AWindowGUI::selected_plugin()
925         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
926         if(picon) return picon->plugin;
929 AssetPicon* AWindowGUI::selected_folder()
931         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
932     return picon;
944 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
945  : BC_SubWindow(x, y, w, h)
947         this->mwindow = mwindow;
948         this->gui = gui;
950 AWindowDivider::~AWindowDivider()
954 int AWindowDivider::button_press_event()
956         if(is_event_win() && cursor_inside())
957         {
958                 mwindow->session->current_operation = DRAG_PARTITION;
959                 return 1;
960         }
961         return 0;
964 int AWindowDivider::cursor_motion_event()
966         if(mwindow->session->current_operation == DRAG_PARTITION)
967         {
968                 mwindow->session->afolders_w = gui->get_relative_cursor_x();
969                 gui->reposition_objects();
970         }
971         return 0;
974 int AWindowDivider::button_release_event()
976         if(mwindow->session->current_operation == DRAG_PARTITION)
977         {
978                 mwindow->session->current_operation = NO_OPERATION;
979                 return 1;
980         }
981         return 0;
989 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
990  : BC_ListBox(x, 
991                 y, 
992                 w, 
993                 h,
994                 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ? 
995                         LISTBOX_ICONS : LISTBOX_TEXT, 
996                 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
997                 0,             // Titles for columns.  Set to 0 for no titles
998                 0,                // width of each column
999                 1,                      // Total columns.
1000                 0,                    // Pixel of top of window.
1001                 0,                        // If this listbox is a popup window
1002                 LISTBOX_SINGLE,  // Select one item or multiple items
1003                 ICON_TOP,        // Position of icon relative to text of each item
1004                 1)               // Allow drags
1006         this->mwindow = mwindow;
1007         this->gui = gui;
1008         set_drag_scroll(0);
1011 AWindowFolders::~AWindowFolders()
1014         
1015 int AWindowFolders::selection_changed()
1017         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1018         if(picon)
1019         {
1020                 strcpy(mwindow->edl->session->current_folder, picon->get_text());
1021 //printf("AWindowFolders::selection_changed 1\n");
1022                 gui->asset_list->draw_background();
1023                 gui->update_assets();
1024         }
1025         return 1;
1028 int AWindowFolders::button_press_event()
1030         int result = 0;
1032         result = BC_ListBox::button_press_event();
1034         if(!result)
1035         {
1036                 if(get_buttonpress() == 3 && is_event_win() && cursor_inside())
1037                 {
1038                         gui->folderlist_menu->update_titles();
1039                         gui->folderlist_menu->activate_menu();
1040                         result = 1;
1041                 }
1042         }
1045         return result;
1054 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1055  : BC_ListBox(x, 
1056                 y, 
1057                 w, 
1058                 h,
1059                 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? 
1060                         LISTBOX_ICONS : LISTBOX_TEXT,
1061                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1062                 gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
1063                 mwindow->edl->session->asset_columns,                // width of each column
1064                 1,                      // Total columns.
1065                 0,                    // Pixel of top of window.
1066                 0,                        // If this listbox is a popup window
1067                 LISTBOX_MULTIPLE,  // Select one item or multiple items
1068                 ICON_TOP,        // Position of icon relative to text of each item
1069                 1)               // Allow drag
1071         this->mwindow = mwindow;
1072         this->gui = gui;
1073         set_drag_scroll(0);
1076 AWindowAssets::~AWindowAssets()
1080 int AWindowAssets::button_press_event()
1082         int result = 0;
1084         result = BC_ListBox::button_press_event();
1086         if(!result && get_buttonpress() == 3 && is_event_win() && cursor_inside())
1087         {
1088                 BC_ListBox::deactivate_selection();
1089                 gui->assetlist_menu->update_titles();
1090                 gui->assetlist_menu->activate_menu();
1091                 result = 1;
1092         }
1095         return result;
1099 int AWindowAssets::handle_event()
1101 //printf("AWindowAssets::handle_event 1 %d %d\n", get_buttonpress(), get_selection(0, 0));
1102         if(get_selection(0, 0))
1103         {
1104                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1105                 {
1106                 }
1107                 else
1108                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1109                 {
1110                 }
1111                 else
1112                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1113                 {
1114                 }
1115                 else
1116                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1117                 {
1118                 }
1119                 else
1120                 {
1121 //printf("AWindowAssets::handle_event 2 %d %d\n", get_buttonpress(), get_selection(0, 0));
1122                         mwindow->vwindow->gui->lock_window("AWindowAssets::handle_event");
1123                         
1124                         if(((AssetPicon*)get_selection(0, 0))->asset)
1125                                 mwindow->vwindow->change_source(((AssetPicon*)get_selection(0, 0))->asset);
1126                         else
1127                         if(((AssetPicon*)get_selection(0, 0))->edl)
1128                                 mwindow->vwindow->change_source(((AssetPicon*)get_selection(0, 0))->edl);
1130                         mwindow->vwindow->gui->unlock_window();
1131                 }
1132                 return 1;
1133         }
1135         return 0;
1138 int AWindowAssets::selection_changed()
1140 // Show popup window
1141         if(get_button_down() && get_buttonpress() == 3 && get_selection(0, 0))
1142         {
1143                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER) || 
1144                         !strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER) ||
1145                         !strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER) ||
1146                         !strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1147                 {
1148                         gui->assetlist_menu->update_titles();
1149                         gui->assetlist_menu->activate_menu();
1150                 }
1151                 else
1152                 {
1153                         if(((AssetPicon*)get_selection(0, 0))->asset)
1154                                 gui->asset_menu->update();
1155                         else
1156                         if(((AssetPicon*)get_selection(0, 0))->edl)
1157                                 gui->asset_menu->update();
1161                         gui->asset_menu->activate_menu();
1162                 }
1164                 BC_ListBox::deactivate_selection();
1165                 return 1;
1166         }
1167         return 0;
1170 void AWindowAssets::draw_background()
1172         BC_ListBox::draw_background();
1173         set_color(BC_WindowBase::get_resources()->audiovideo_color);
1174         set_font(LARGEFONT);
1175         draw_text(get_w() - 
1176                         get_text_width(LARGEFONT, mwindow->edl->session->current_folder) - 4, 
1177                 30, 
1178                 mwindow->edl->session->current_folder, 
1179                 -1, 
1180                 get_bg_surface());
1183 int AWindowAssets::drag_start_event()
1185         int collect_pluginservers = 0;
1186         int collect_assets = 0;
1188         if(BC_ListBox::drag_start_event())
1189         {
1190                 if(!strcasecmp(mwindow->edl->session->current_folder, AEFFECT_FOLDER))
1191                 {
1192                         mwindow->session->current_operation = DRAG_AEFFECT;
1193                         collect_pluginservers = 1;
1194                 }
1195                 else
1196                 if(!strcasecmp(mwindow->edl->session->current_folder, VEFFECT_FOLDER))
1197                 {
1198                         mwindow->session->current_operation = DRAG_VEFFECT;
1199                         collect_pluginservers = 1;
1200                 }
1201                 else
1202                 if(!strcasecmp(mwindow->edl->session->current_folder, ATRANSITION_FOLDER))
1203                 {
1204                         mwindow->session->current_operation = DRAG_ATRANSITION;
1205                         collect_pluginservers = 1;
1206                 }
1207                 else
1208                 if(!strcasecmp(mwindow->edl->session->current_folder, VTRANSITION_FOLDER))
1209                 {
1210                         mwindow->session->current_operation = DRAG_VTRANSITION;
1211                         collect_pluginservers = 1;
1212                 }
1213                 else
1214                 {
1215                         mwindow->session->current_operation = DRAG_ASSET;
1216                         collect_assets = 1;
1217                 }
1218                 
1219                 
1220                 if(collect_pluginservers)
1221                 {
1222                         int i = 0;
1223                         mwindow->session->drag_pluginservers->remove_all();
1224                         while(1)
1225                         {
1226                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1227                                 if(!result) break;
1228                                 
1229                                 mwindow->session->drag_pluginservers->append(result->plugin);
1230                         }
1231                 }
1232                 
1233                 if(collect_assets)
1234                 {
1235                         gui->collect_assets();
1236                 }
1238                 return 1;
1239         }
1240         return 0;
1243 int AWindowAssets::drag_motion_event()
1245         BC_ListBox::drag_motion_event();
1247         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1248         mwindow->gui->drag_motion();
1249         mwindow->gui->unlock_window();
1251         mwindow->vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1252         mwindow->vwindow->gui->drag_motion();
1253         mwindow->vwindow->gui->unlock_window();
1255         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1256         mwindow->cwindow->gui->drag_motion();
1257         mwindow->cwindow->gui->unlock_window();
1258         return 0;
1261 int AWindowAssets::drag_stop_event()
1263         int result = 0;
1265         result = gui->drag_stop();
1268         if(!result)
1269         {
1270                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1271                 result = mwindow->gui->drag_stop();
1272                 mwindow->gui->unlock_window();
1273         }
1275         if(!result) 
1276         {
1277                 mwindow->vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1278                 result = mwindow->vwindow->gui->drag_stop();
1279                 mwindow->vwindow->gui->unlock_window();
1280         }
1282         if(!result) 
1283         {
1284                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1285                 result = mwindow->cwindow->gui->drag_stop();
1286                 mwindow->cwindow->gui->unlock_window();
1287         }
1291         if(result) get_drag_popup()->set_animation(0);
1293         BC_ListBox::drag_stop_event();
1294         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1295         return 0;
1298 int AWindowAssets::column_resize_event()
1300         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1301         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1302         return 1;
1316 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1317  : BC_Button(x, y, mwindow->theme->newbin_data)
1319         this->mwindow = mwindow;
1320         this->gui = gui;
1321         set_tooltip(_("New bin"));
1324 int AWindowNewFolder::handle_event()
1326         gui->newfolder_thread->start_new_folder();
1327         return 1;
1330 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1331  : BC_Button(x, y, mwindow->theme->deletebin_data)
1333         this->mwindow = mwindow;
1334         this->gui = gui;
1335         set_tooltip(_("Delete bin"));
1338 int AWindowDeleteFolder::handle_event()
1340         if(gui->folder_list->get_selection(0, 0))
1341         {
1342                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1343                 mwindow->delete_folder(folder->get_text());
1344         }
1345         return 1;
1348 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1349  : BC_Button(x, y, mwindow->theme->renamebin_data)
1351         this->mwindow = mwindow;
1352         this->gui = gui;
1353         set_tooltip(_("Rename bin"));
1356 int AWindowRenameFolder::handle_event()
1358         return 1;
1361 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1362  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1364         this->mwindow = mwindow;
1365         this->gui = gui;
1366         set_tooltip(_("Delete asset from disk"));
1369 int AWindowDeleteDisk::handle_event()
1371         return 1;
1374 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1375  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1377         this->mwindow = mwindow;
1378         this->gui = gui;
1379         set_tooltip(_("Delete asset from project"));
1382 int AWindowDeleteProject::handle_event()
1384         return 1;
1387 AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1388  : BC_Button(x, y, mwindow->theme->infoasset_data)
1390         this->mwindow = mwindow;
1391         this->gui = gui;
1392         set_tooltip(_("Edit information on asset"));
1395 int AWindowInfo::handle_event()
1397         gui->awindow->asset_edit->edit_asset(gui->selected_asset());
1398         return 1;
1401 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1402  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1404         this->mwindow = mwindow;
1405         this->gui = gui;
1406         set_tooltip(_("Redraw index"));
1409 int AWindowRedrawIndex::handle_event()
1411         return 1;
1414 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1415  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1417         this->mwindow = mwindow;
1418         this->gui = gui;
1419         set_tooltip(_("Paste asset on recordable tracks"));
1422 int AWindowPaste::handle_event()
1424         return 1;
1427 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1428  : BC_Button(x, y, mwindow->theme->appendasset_data)
1430         this->mwindow = mwindow;
1431         this->gui = gui;
1432         set_tooltip(_("Append asset in new tracks"));
1435 int AWindowAppend::handle_event()
1437         return 1;
1440 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1441  : BC_Button(x, y, mwindow->theme->viewasset_data)
1443         this->mwindow = mwindow;
1444         this->gui = gui;
1445         set_tooltip(_("View asset"));
1448 int AWindowView::handle_event()
1450         return 1;