add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / plugindialog.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "condition.h"
23 #include "cstrdup.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "language.h"
27 #include "localsession.h"
28 #include "mainsession.h"
29 #include "mainundo.h"
30 #include "mwindow.h"
31 #include "mwindowgui.h"
32 #include "module.h"
33 #include "mutex.h"
34 #include "plugin.h"
35 #include "plugindialog.h"
36 #include "pluginserver.h"
37 #include "theme.h"
38 #include "track.h"
39 #include "tracks.h"
40 #include "transition.h"
41
42
43 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
44  : BC_DialogThread()
45 {
46         this->mwindow = mwindow;
47         this->plugin_id = -1;
48         this->plugin_type = PLUGIN_NONE;
49 }
50
51 PluginDialogThread::~PluginDialogThread()
52 {
53         close_window();
54 }
55
56 void PluginDialogThread::start_window(Track *track,
57         Plugin *plugin, const char *title, int is_mainmenu, int data_type)
58 {
59         if(!BC_DialogThread::is_running())
60         {
61 // At this point, the caller should hold the main window mutex.
62 //              mwindow->gui->lock_window("PluginDialogThread::start_window");
63                 this->track = track;
64                 this->data_type = data_type;
65                 this->is_mainmenu = is_mainmenu;
66                 single_standalone = mwindow->edl->session->single_standalone;
67
68                 if(plugin)
69                 {
70                         plugin->calculate_title(plugin_title, 0);
71                         this->shared_location = plugin->shared_location;
72                         this->plugin_type = plugin->plugin_type;
73                         this->plugin_id = plugin->orig_id;
74                 }
75                 else
76                 {
77                         this->plugin_title[0] = 0;
78                         this->shared_location.plugin = -1;
79                         this->shared_location.module = -1;
80                         this->plugin_type = PLUGIN_NONE;
81                         this->plugin_id = -1;
82                 }
83
84                 strcpy(this->window_title, title);
85                 mwindow->gui->unlock_window();
86
87                 BC_DialogThread::start();
88                 mwindow->gui->lock_window("PluginDialogThread::start_window");
89         }
90 }
91
92 BC_Window* PluginDialogThread::new_gui()
93 {
94         mwindow->gui->lock_window("PluginDialogThread::new_gui");
95         int x = mwindow->gui->get_abs_cursor_x(0) -
96                 mwindow->session->plugindialog_w / 2;
97         int y = mwindow->gui->get_abs_cursor_y(0) -
98                 mwindow->session->plugindialog_h / 2;
99         plugin_type = PLUGIN_NONE;
100         PluginDialog *window = new PluginDialog(mwindow,
101                 this,
102                 window_title,
103                 x,
104                 y);
105         window->create_objects();
106         mwindow->gui->unlock_window();
107         return window;
108 }
109
110 void PluginDialogThread::handle_done_event(int result)
111 {
112         if( !result ) {
113                 PluginDialog *dialog = (PluginDialog *)get_gui();
114                 dialog->apply();
115         }
116 }
117
118
119 void PluginDialogThread::handle_close_event(int result)
120 {
121 }
122
123
124
125
126
127 PluginDialog::PluginDialog(MWindow *mwindow,
128         PluginDialogThread *thread,
129         const char *window_title,
130         int x,
131         int y)
132  : BC_Window(window_title, x, y,
133         mwindow->session->plugindialog_w,
134         mwindow->session->plugindialog_h,
135         xS(510), yS(415), 1, 0, 1)
136 {
137         this->mwindow = mwindow;
138         this->thread = thread;
139         single_standalone = 0;
140 // *** CONTEXT_HELP ***
141         switch( thread->data_type ) {
142         case TRACK_AUDIO:
143                 context_help_set_keyword("Audio Effects");
144                 break;
145         case TRACK_VIDEO:
146                 context_help_set_keyword("Video Effects");
147                 break;
148         default:
149                 context_help_set_keyword("How to Use Plugins");
150                 break;
151         }
152 }
153
154 PluginDialog::~PluginDialog()
155 {
156         lock_window("PluginDialog::~PluginDialog");
157         standalone_data.remove_all_objects();
158
159         shared_data.remove_all_objects();
160
161         module_data.remove_all_objects();
162
163         plugin_locations.remove_all_objects();
164
165         module_locations.remove_all_objects();
166
167         delete standalone_list;
168         delete shared_list;
169         delete module_list;
170         unlock_window();
171 }
172
173 void PluginDialog::create_objects()
174 {
175         int xs10 = xS(10);
176         int ys10 = yS(10), ys20 = yS(20);
177 //      int use_default = 1;
178         mwindow->theme->get_plugindialog_sizes();
179         lock_window("PluginDialog::create_objects");
180
181 // GET A LIST OF ALL THE PLUGINS AVAILABLE
182         mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
183                 thread->data_type == TRACK_VIDEO,
184                 1, 0, 0, plugindb);
185
186         mwindow->edl->get_shared_plugins(thread->track,
187                 &plugin_locations,
188                 thread->is_mainmenu,
189                 thread->data_type);
190         mwindow->edl->get_shared_tracks(thread->track,
191                 &module_locations,
192                 thread->is_mainmenu,
193                 thread->data_type);
194
195 // Construct listbox items
196         for(int i = 0; i < plugin_locations.total; )
197         {
198                 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
199                 char *track_title = track->title;
200                 int number = plugin_locations.values[i]->plugin;
201                 double start = mwindow->edl->local_session->get_selectionstart(1);
202                 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
203                 if( !plugin ) { plugin_locations.remove_object_number(i);  continue; }
204                 char string[BCTEXTLEN];
205                 const char *plugin_title = _(plugin->title);
206                 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
207                 shared_data.append(new BC_ListBoxItem(string));
208                 ++i;
209         }
210         for(int i = 0; i < module_locations.total; i++)
211         {
212                 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
213                 module_data.append(new BC_ListBoxItem(track->title));
214         }
215
216 // Create widgets
217         add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
218                 mwindow->theme->plugindialog_new_y - ys20,
219                 _("Plugins:")));
220         int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
221         int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
222         add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
223         int dy = search_text->get_h() + ys10;
224         y1 += dy;  h1 -= dy;
225         load_plugin_list(0);
226
227         add_subwindow(standalone_list = new PluginDialogNew(this,
228                 &standalone_data, x1, y1, w1, h1));
229 //
230 //      if(thread->plugin)
231 //              add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
232 //                      this,
233 //                      mwindow->theme->plugindialog_newattach_x,
234 //                      mwindow->theme->plugindialog_newattach_y));
235 //      else
236 //              add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
237 //                      this,
238 //                      mwindow->theme->plugindialog_newattach_x,
239 //                      mwindow->theme->plugindialog_newattach_y));
240 //
241
242         add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
243                 mwindow->theme->plugindialog_shared_y - ys20,
244                 _("Shared effects:")));
245         add_subwindow(shared_list = new PluginDialogShared(this,
246                 &shared_data,
247                 mwindow->theme->plugindialog_shared_x,
248                 mwindow->theme->plugindialog_shared_y,
249                 mwindow->theme->plugindialog_shared_w,
250                 mwindow->theme->plugindialog_shared_h));
251 //      if(thread->plugin)
252 //       add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
253 //          this,
254 //          mwindow->theme->plugindialog_sharedattach_x,
255 //          mwindow->theme->plugindialog_sharedattach_y));
256 //    else
257 //              add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
258 //                      this,
259 //                      mwindow->theme->plugindialog_sharedattach_x,
260 //                      mwindow->theme->plugindialog_sharedattach_y));
261 //
262
263         add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
264                 mwindow->theme->plugindialog_module_y - ys20,
265                 _("Shared tracks:")));
266         add_subwindow(module_list = new PluginDialogModules(this,
267                 &module_data,
268                 mwindow->theme->plugindialog_module_x,
269                 mwindow->theme->plugindialog_module_y,
270                 mwindow->theme->plugindialog_module_w,
271                 mwindow->theme->plugindialog_module_h));
272 //      if(thread->plugin)
273 //       add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
274 //          this,
275 //          mwindow->theme->plugindialog_moduleattach_x,
276 //          mwindow->theme->plugindialog_moduleattach_y));
277 //    else
278 //              add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
279 //                      this,
280 //                      mwindow->theme->plugindialog_moduleattach_x,
281 //                      mwindow->theme->plugindialog_moduleattach_y));
282 //
283
284
285 // Add option for the menu invocation
286 //      add_subwindow(file_title = new BC_Title(
287 //              mwindow->theme->menueffect_file_x,
288 //              mwindow->theme->menueffect_file_y,
289 //              _("One standalone effect is attached to the first track.\n"
290 //              "Shared effects are attached to the remaining tracks.")));
291
292         if(thread->is_mainmenu)
293                 add_subwindow(single_standalone = new PluginDialogSingle(this,
294                         mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + xs10,
295                         mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
296                                 get_text_height(MEDIUMFONT)));
297
298         add_subwindow(ok_btn = new BC_OKButton(this));
299         add_subwindow(can_btn = new BC_CancelButton(this));
300         int aw = PluginDialogApply::calculate_w(this, _("Apply"));
301         int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
302         int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
303         add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
304         selected_available = -1;
305         selected_shared = -1;
306         selected_modules = -1;
307
308         show_window();
309         flush();
310         unlock_window();
311 }
312
313 int PluginDialog::resize_event(int w, int h)
314 {
315         int ys10 = yS(10), ys20 = yS(20);
316         mwindow->session->plugindialog_w = w;
317         mwindow->session->plugindialog_h = h;
318         mwindow->theme->get_plugindialog_sizes();
319
320         standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
321                 mwindow->theme->plugindialog_new_y - ys20);
322         int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
323         int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
324         search_text->reposition_window(x1, y1, w1);
325         int dy = search_text->get_h() + ys10;
326         y1 += dy;  h1 -= dy;
327         standalone_list->reposition_window(x1, y1, w1, h1);
328
329 //      if(standalone_attach)
330 //              standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
331 //                      mwindow->theme->plugindialog_newattach_y);
332 //      else
333 //              standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
334 //                      mwindow->theme->plugindialog_newattach_y);
335
336         shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
337                 mwindow->theme->plugindialog_shared_y - ys20);
338         shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
339                 mwindow->theme->plugindialog_shared_y,
340                 mwindow->theme->plugindialog_shared_w,
341                 mwindow->theme->plugindialog_shared_h);
342 //      if(shared_attach)
343 //              shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
344 //                      mwindow->theme->plugindialog_sharedattach_y);
345 //      else
346 //              shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
347 //                      mwindow->theme->plugindialog_sharedattach_y);
348 //
349
350
351
352
353         module_title->reposition_window(mwindow->theme->plugindialog_module_x,
354                 mwindow->theme->plugindialog_module_y - ys20);
355         module_list->reposition_window(mwindow->theme->plugindialog_module_x,
356                 mwindow->theme->plugindialog_module_y,
357                 mwindow->theme->plugindialog_module_w,
358                 mwindow->theme->plugindialog_module_h);
359 //      if(module_attach)
360 //              module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
361 //                      mwindow->theme->plugindialog_moduleattach_y);
362 //      else
363 //              module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
364 //                      mwindow->theme->plugindialog_moduleattach_y);
365
366
367         if(single_standalone)
368                 single_standalone->reposition_window(
369                         mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + ys10,
370                         mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
371                                 get_text_height(MEDIUMFONT));
372
373         int aw = PluginDialogApply::calculate_w(this, _("Apply"));
374         int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
375         int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
376         apy_btn->reposition_window(ax, ay);
377
378         flush();
379         return 0;
380 }
381
382 int PluginDialog::attach_new(int number)
383 {
384         if(number >= 0 && number < plugindb.size())
385         {
386                 strcpy(thread->plugin_title, plugindb.values[number]->title);
387                 thread->plugin_type = PLUGIN_STANDALONE;         // type is plugin
388         }
389         return 0;
390 }
391
392 int PluginDialog::attach_shared(int number)
393 {
394         if(number >= 0 && number < plugin_locations.size())
395         {
396                 thread->plugin_type = PLUGIN_SHAREDPLUGIN;         // type is shared plugin
397                 thread->shared_location = *(plugin_locations.values[number]); // copy location
398         }
399         return 0;
400 }
401
402 int PluginDialog::attach_module(int number)
403 {
404         if(number >= 0 && number < module_locations.size())
405         {
406 //              title->update(module_data.values[number]->get_text());
407                 thread->plugin_type = PLUGIN_SHAREDMODULE;         // type is module
408                 thread->shared_location = *(module_locations.values[number]); // copy location
409         }
410         return 0;
411 }
412
413 void PluginDialog::save_settings()
414 {
415 }
416
417
418 void PluginDialog::clear_selection()
419 {
420         standalone_list->set_all_selected(&standalone_data, 0);
421         standalone_list->draw_items(1);
422         shared_list->set_all_selected(&shared_data, 0);
423         shared_list->draw_items(1);
424         module_list->set_all_selected(&module_data, 0);
425         module_list->draw_items(1);
426         selected_available = -1;
427         selected_shared = -1;
428         selected_modules = -1;
429         thread->plugin_id = -1;
430         thread->plugin_type = PLUGIN_NONE;
431 }
432
433 void PluginDialog::apply()
434 {
435         if( selected_available >= 0 ) {
436                 attach_new(selected_available);
437         }
438         else if( selected_shared >= 0 ) {
439                 attach_shared(selected_shared);
440         }
441         else if( selected_modules >= 0 ) {
442                 attach_module(selected_modules);
443         }
444
445         thread->apply();
446 }
447
448 void PluginDialogThread::apply()
449 {
450         Plugin *plugin = 0;
451         EDL *edl = mwindow->edl;
452         if( edl )
453                 edl->session->single_standalone = single_standalone;
454         if(plugin_type) {
455                 mwindow->gui->lock_window("PluginDialogThread::run 3");
456                 mwindow->undo->update_undo_before();
457                 if( is_mainmenu ) {
458                         mwindow->insert_effect(plugin_title, &shared_location,
459                                 data_type, plugin_type, single_standalone);
460                 }
461                 else if( (plugin=edl->tracks->plugin_exists(plugin_id)) != 0 ) {
462                         plugin->change_plugin(plugin_title,
463                                         &shared_location, plugin_type);
464                 }
465                 else if( edl->tracks->track_exists(track) ) {
466                         double start = edl->local_session->get_selectionstart();
467                         double end = edl->local_session->get_selectionend();
468                         if( start >= end ) {
469                                 start = 0;
470                                 end = track->get_length();
471                         }
472                         double length = end - start;
473                         mwindow->insert_effect(plugin_title, &shared_location,
474                                         track, 0, start, length, plugin_type);
475                 }
476
477                 mwindow->save_backup();
478                 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
479                 mwindow->restart_brender();
480                 mwindow->update_plugin_states();
481                 mwindow->sync_parameters(CHANGE_EDL);
482                 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
483                 mwindow->gui->unlock_window();
484         }
485         plugin_id = -1;
486 }
487
488 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
489  : BC_GenericButton(x, y, _("Apply"))
490 {
491         this->dialog = dialog;
492 }
493
494 int PluginDialogApply::handle_event()
495 {
496         dialog->apply();
497         dialog->clear_selection();
498         return 1;
499 }
500
501
502
503
504
505
506 //
507 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
508 //  : BC_TextBox(x, y, xS(200), 1, text)
509 // {
510 //      this->dialog = dialog;
511 // }
512 // PluginDialogTextBox::~PluginDialogTextBox()
513 // { }
514 // int PluginDialogTextBox::handle_event()
515 // { }
516 //
517 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
518 //  : BC_GenericButton(x, y, _("Detach"))
519 // {
520 //      this->dialog = dialog;
521 // }
522 // PluginDialogDetach::~PluginDialogDetach()
523 // { }
524 // int PluginDialogDetach::handle_event()
525 // {
526 // //   dialog->title->update(_("None"));
527 //      dialog->thread->plugin_type = 0;         // type is none
528 //      dialog->thread->plugin_title[0] = 0;
529 //      return 1;
530 // }
531 //
532
533
534
535 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
536         ArrayList<BC_ListBoxItem*> *standalone_data,
537         int x, int y, int w, int h)
538  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
539 {
540         this->dialog = dialog;
541 }
542
543 PluginDialogNew::~PluginDialogNew() { }
544 int PluginDialogNew::handle_event()
545 {
546 //      dialog->attach_new(get_selection_number(0, 0));
547 //      deactivate();
548
549         set_done(0);
550         return 1;
551 }
552 int PluginDialogNew::selection_changed()
553 {
554         int no = get_selection_number(0, 0);
555         dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
556                 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
557         dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
558         dialog->shared_list->draw_items(1);
559         dialog->selected_shared = -1;
560         dialog->module_list->set_all_selected(&dialog->module_data, 0);
561         dialog->module_list->draw_items(1);
562         dialog->selected_modules = -1;
563         return 1;
564 }
565
566 // *** CONTEXT_HELP ***
567 int PluginDialogNew::keypress_event()
568 {
569         int item, plugin_no;
570         char title[BCTEXTLEN];
571         PluginServer *plugin = 0;
572
573 //      printf("PluginDialogNew::keypress_event: %d\n", get_keypress());
574
575         // If not our context help keystroke, redispatch it
576         // to the event handler of the base class
577         if (get_keypress() != 'h' || ! alt_down() ||
578             ! is_tooltip_event_win() || ! cursor_inside())
579                 return BC_ListBox::keypress_event();
580
581         // Try to show help for the plugin currently under mouse
582         item = get_highlighted_item();
583         if (item >= 0 && item < dialog->standalone_data.size()) {
584                 plugin_no = ((PluginDialogListItem *)dialog->standalone_data[item])->item_no;
585                 if (plugin_no >= 0 && plugin_no < dialog->plugindb.total)
586                         plugin = dialog->plugindb.values[plugin_no];
587         }
588
589         // If some plugin is highlighted, show its help
590         // Otherwise show more general help
591         if (plugin) {
592                 strcpy(title, plugin->title);
593                 if (! strcmp(title, "Overlay")) {
594                         // "Overlay" plugin title is ambiguous
595                         if (plugin->audio) strcat(title, " \\(Audio\\)");
596                         if (plugin->video) strcat(title, " \\(Video\\)");
597                 }
598                 if (plugin->is_ffmpeg()) {
599                         // FFmpeg plugins can be audio or video
600                         if (plugin->audio)
601                                 strcpy(title, "FFmpeg Audio Plugins");
602                         if (plugin->video)
603                                 strcpy(title, "FFmpeg Video Plugins");
604                 }
605                 context_help_show(title);
606                 return 1;
607         }
608         else {
609                 switch (dialog->thread->data_type) {
610                 case TRACK_AUDIO:
611                         context_help_show("Audio Effects");
612                         return 1;
613                 case TRACK_VIDEO:
614                         context_help_show("Video Effects");
615                         return 1;
616                 default:
617                         context_help_show("How to Use Plugins");
618                         return 1;
619                 }
620                 context_help_show("How to Use Plugins");
621                 return 1;
622         }
623         context_help_show("How to Use Plugins");
624         return 1;
625 }
626
627 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
628 //  : BC_GenericButton(x, y, _("Attach"))
629 // {
630 //      this->dialog = dialog;
631 // }
632 // PluginDialogAttachNew::~PluginDialogAttachNew()
633 // {
634 // }
635 // int PluginDialogAttachNew::handle_event()
636 // {
637 //      dialog->attach_new(dialog->selected_available);
638 //      set_done(0);
639 //      return 1;
640 // }
641 //
642 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
643 //  : BC_GenericButton(x, y, _("Change"))
644 // {
645 //    this->dialog = dialog;
646 // }
647 // PluginDialogChangeNew::~PluginDialogChangeNew()
648 // {
649 // }
650 // int PluginDialogChangeNew::handle_event()
651 // {
652 //    dialog->attach_new(dialog->selected_available);
653 //    set_done(0);
654 //    return 1;
655 // }
656
657
658 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
659         ArrayList<BC_ListBoxItem*> *shared_data,
660         int x, int y, int w, int h)
661  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, shared_data)
662 {
663         this->dialog = dialog;
664         context_help_set_keyword("Shared Effects and Shared Tracks");
665 }
666 PluginDialogShared::~PluginDialogShared() { }
667 int PluginDialogShared::handle_event()
668 {
669 //      dialog->attach_shared(get_selection_number(0, 0));
670 //      deactivate();
671         set_done(0);
672         return 1;
673 }
674 int PluginDialogShared::selection_changed()
675 {
676         dialog->selected_shared = get_selection_number(0, 0);
677
678
679         dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
680         dialog->standalone_list->draw_items(1);
681         dialog->module_list->set_all_selected(&dialog->module_data, 0);
682         dialog->module_list->draw_items(1);
683         dialog->selected_available = -1;
684         dialog->selected_modules = -1;
685         return 1;
686 }
687
688 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
689 //      PluginDialog *dialog,
690 //      int x,
691 //      int y)
692 //  : BC_GenericButton(x, y, _("Attach"))
693 // {
694 //      this->dialog = dialog;
695 // }
696 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
697 // int PluginDialogAttachShared::handle_event()
698 // {
699 //      dialog->attach_shared(dialog->selected_shared);
700 //      set_done(0);
701 //      return 1;
702 // }
703 //
704 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
705 //    PluginDialog *dialog,
706 //    int x,
707 //    int y)
708 //  : BC_GenericButton(x, y, _("Change"))
709 // {
710 //    this->dialog = dialog;
711 // }
712 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
713 // int PluginDialogChangeShared::handle_event()
714 // {
715 //    dialog->attach_shared(dialog->selected_shared);
716 //    set_done(0);
717 //    return 1;
718 // }
719 //
720
721
722
723
724
725
726
727
728
729
730
731
732 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
733         ArrayList<BC_ListBoxItem*> *module_data,
734         int x, int y, int w, int h)
735  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, module_data)
736 {
737         this->dialog = dialog;
738         context_help_set_keyword("Shared Effects and Shared Tracks");
739 }
740 PluginDialogModules::~PluginDialogModules() { }
741 int PluginDialogModules::handle_event()
742 {
743 //      dialog->attach_module(get_selection_number(0, 0));
744 //      deactivate();
745
746         set_done(0);
747         return 1;
748 }
749 int PluginDialogModules::selection_changed()
750 {
751         dialog->selected_modules = get_selection_number(0, 0);
752
753
754         dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
755         dialog->standalone_list->draw_items(1);
756         dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
757         dialog->shared_list->draw_items(1);
758         dialog->selected_available = -1;
759         dialog->selected_shared = -1;
760         return 1;
761 }
762
763 void PluginDialog::load_plugin_list(int redraw)
764 {
765         standalone_data.remove_all_objects();
766         const char *text = search_text->get_text();
767
768         for( int i=0; i<plugindb.total; ++i ) {
769                 const char *title = _(plugindb.values[i]->title);
770                 if( text && text[0] && !bstrcasestr(title, text) ) continue;
771                 standalone_data.append(new PluginDialogListItem(title, i));
772         }
773
774         if( redraw )
775                 standalone_list->draw_items(1);
776 }
777
778 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
779  : BC_TextBox(x, y, w, 1, "")
780 {
781         this->dialog = dialog;
782 }
783
784 int PluginDialogSearchText::handle_event()
785 {
786         dialog->load_plugin_list(1);
787         return 1;
788 }
789
790 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
791  : BC_CheckBox(x, y, dialog->thread->single_standalone,
792         _("Attach single standalone and share others"))
793 {
794         this->dialog = dialog;
795         context_help_set_keyword("Shared Effects and Shared Tracks");
796 }
797
798 int PluginDialogSingle::handle_event()
799 {
800         dialog->thread->single_standalone = get_value();
801         return 1;
802 }
803
804
805 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
806 //      PluginDialog *dialog,
807 //      int x,
808 //      int y)
809 //  : BC_GenericButton(x, y, _("Attach"))
810 // {
811 //      this->dialog = dialog;
812 // }
813 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
814 // int PluginDialogAttachModule::handle_event()
815 // {
816 //      dialog->attach_module(dialog->selected_modules);
817 //      set_done(0);
818 //      return 1;
819 // }
820 //
821 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
822 //    PluginDialog *dialog,
823 //    int x,
824 //    int y)
825 //  : BC_GenericButton(x, y, _("Change"))
826 // {
827 //    this->dialog = dialog;
828 // }
829 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
830 // int PluginDialogChangeModule::handle_event()
831 // {
832 //    dialog->attach_module(dialog->selected_modules);
833 //    set_done(0);
834 //    return 1;
835 // }
836 //
837