initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / keyframegui.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 "bchash.h"
23 #include "bcsignals.h"
24 #include "edl.h"
25 #include "keyframe.h"
26 #include "keyframes.h"
27 #include "keyframegui.h"
28 #include "keys.h"
29 #include "language.h"
30 #include "localsession.h"
31 #include "mainsession.h"
32 #include "mainundo.h"
33 #include "mwindow.h"
34 #include "mwindowgui.h"
35 #include "plugin.h"
36 #include "presets.h"
37 #include "theme.h"
38 #include "trackcanvas.h"
39 #include "tracks.h"
40
41
42
43
44 KeyFrameThread::KeyFrameThread(MWindow *mwindow)
45  : BC_DialogThread()
46 {
47         this->mwindow = mwindow;
48         plugin = 0;
49         keyframe = 0;
50         keyframe_data = new ArrayList<BC_ListBoxItem*>[KEYFRAME_COLUMNS];
51         plugin_title[0] = 0;
52         window_title[0] = 0;
53         column_titles[0] = (char*)"Parameter";
54         column_titles[1] = (char*)"Value";
55         column_width[0] = 0;
56         column_width[1] = 0;
57         presets_data = new ArrayList<BC_ListBoxItem*>;
58         presets_db = new PresetsDB;
59 }
60
61 KeyFrameThread::~KeyFrameThread()
62 {
63         for(int i = 0; i < KEYFRAME_COLUMNS; i++)
64                 keyframe_data[i].remove_all_objects();
65         delete [] keyframe_data;
66         presets_data->remove_all_objects();
67         delete presets_data;
68 }
69
70
71 #ifdef EDIT_KEYFRAME
72 void KeyFrameThread::update_values()
73 {
74 // Get the current selection before deleting the tables
75         int selection = -1;
76         for(int i = 0; i < keyframe_data[0].size(); i++)
77         {
78                 if(keyframe_data[0].get(i)->get_selected()) 
79                 {
80                         selection = i;
81                         break;
82                 }
83         }
84
85         for(int i = 0; i < KEYFRAME_COLUMNS; i++)
86                 keyframe_data[i].remove_all_objects();
87
88
89 // Must lock main window to read keyframe
90         mwindow->gui->lock_window("KeyFrameThread::update_values");
91         if(!plugin || !mwindow->edl->tracks->plugin_exists(plugin)) 
92         {
93                 mwindow->gui->unlock_window();
94                 return;
95         }
96
97         KeyFrame *keyframe = 0;
98         if(this->keyframe && plugin->keyframe_exists(this->keyframe))
99         {
100 // If user edited a specific keyframe, use it.
101                 keyframe = this->keyframe;
102         }
103         else
104         if(plugin->track)
105         {
106 // Use currently highlighted keyframe
107                 keyframe = plugin->get_prev_keyframe(
108                         plugin->track->to_units(
109                                 mwindow->edl->local_session->get_selectionstart(1), 0),
110                         PLAY_FORWARD);
111         }
112
113         if(keyframe)
114         {
115                 BC_Hash hash;
116                 char *text = 0, *extra = 0;
117                 keyframe->get_contents(&hash, &text, &extra);
118                 
119                 for(int i = 0; i < hash.size(); i++)
120                 {
121                         keyframe_data[0].append(new BC_ListBoxItem(hash.get_key(i)));
122                         keyframe_data[1].append(new BC_ListBoxItem(hash.get_value(i)));
123                 }
124                 keyframe_data[0].append(new BC_ListBoxItem((char*)"TEXT"));
125                 keyframe_data[1].append(new BC_ListBoxItem(text));
126                 
127                 delete [] text;
128                 delete [] extra;
129         }
130
131         column_width[0] = mwindow->session->keyframedialog_column1;
132         column_width[1] = mwindow->session->keyframedialog_column2;
133         if(selection >= 0 && selection < keyframe_data[0].size())
134         {
135                 for(int i = 0; i < KEYFRAME_COLUMNS; i++)
136                         keyframe_data[i].get(selection)->set_selected(1);
137         }
138         mwindow->gui->unlock_window();
139 }
140 #endif
141
142
143 void KeyFrameThread::start_window(Plugin *plugin, KeyFrame *keyframe)
144 {
145
146         if(!BC_DialogThread::is_running())
147         {
148                 if(!mwindow->edl->tracks->plugin_exists(plugin)) return;
149                 this->keyframe = keyframe;
150                 this->plugin = plugin;
151                 plugin->calculate_title(plugin_title, 0);
152                 sprintf(window_title, PROGRAM_NAME ": %s Keyframe", plugin_title);
153                 presets_db->load();
154                 calculate_preset_list();
155
156 #ifdef EDIT_KEYFRAME
157                 update_values();
158 #endif
159                 mwindow->gui->unlock_window();
160                 BC_DialogThread::start();
161                 mwindow->gui->lock_window("KeyFrameThread::start_window");
162         }
163         else
164         {
165                 BC_DialogThread::start();
166         }
167 }
168
169 BC_Window* KeyFrameThread::new_gui()
170 {
171         mwindow->gui->lock_window("KeyFrameThread::new_gui");
172         
173         int x = mwindow->gui->get_abs_cursor_x(0) - 
174                 mwindow->session->plugindialog_w / 2;
175         int y = mwindow->gui->get_abs_cursor_y(0) - 
176                 mwindow->session->plugindialog_h / 2;
177
178         KeyFrameWindow *window = new KeyFrameWindow(mwindow, 
179                 this, 
180                 x, 
181                 y,
182                 window_title);
183
184         window->create_objects();
185         
186         
187         mwindow->gui->unlock_window();
188
189         return window;
190 }
191
192 void KeyFrameThread::handle_done_event(int result)
193 {
194 // Apply the preset
195         if(!result)
196         {
197                 const char *title = ((KeyFrameWindow*)get_gui())->preset_text->get_text();
198                 apply_preset(title);
199                 apply_value();
200         }
201 }
202
203 void KeyFrameThread::handle_close_event(int result)
204 {
205         plugin = 0;
206         keyframe = 0;
207 }
208
209 void KeyFrameThread::close_window()
210 {
211         lock_window("KeyFrameThread::close_window");
212         if(get_gui())
213         {
214                 get_gui()->lock_window("KeyFrameThread::close_window");
215                 get_gui()->set_done(1);
216                 get_gui()->unlock_window();
217         }
218         unlock_window();
219 }
220
221
222
223 void KeyFrameThread::calculate_preset_list()
224 {
225         presets_data->remove_all_objects();
226         int total_presets = presets_db->get_total_presets(plugin_title);
227         for(int i = 0; i < total_presets; i++)
228         {
229                 presets_data->append(new BC_ListBoxItem(presets_db->get_preset_title(
230                         plugin_title,
231                         i)));
232         }
233 }
234
235
236 void KeyFrameThread::update_gui(int update_value_text)
237 {
238 #ifdef EDIT_KEYFRAME
239         if(BC_DialogThread::is_running())
240         {
241                 mwindow->gui->lock_window("KeyFrameThread::update_gui");
242                 update_values();
243                 mwindow->gui->unlock_window();
244
245                 lock_window("KeyFrameThread::update_gui");
246                 KeyFrameWindow *window = (KeyFrameWindow*)get_gui();
247                 if(window)
248                 {
249                         window->lock_window("KeyFrameThread::update_gui");
250                         window->keyframe_list->update(keyframe_data,
251                                 (const char **)column_titles,
252                                 column_width,
253                                 KEYFRAME_COLUMNS,
254                                 window->keyframe_list->get_xposition(),
255                                 window->keyframe_list->get_yposition(),
256                                 window->keyframe_list->get_highlighted_item());
257                         if( update_value_text )
258                         {
259                                 int selection_number = window->keyframe_list->get_selection_number(0, 0);
260                                 if( selection_number >= 0 && selection_number < keyframe_data[1].size())
261                                 {
262                                         char *edit_value = keyframe_data[1].get(selection_number)->get_text();
263                                         window->value_text->update(edit_value);
264                                 }
265                         }
266                         window->unlock_window();
267                 }
268                 unlock_window();
269         }
270 #endif
271 }
272
273 void KeyFrameThread::save_preset(const char *title)
274 {
275         get_gui()->unlock_window();
276         mwindow->gui->lock_window("KeyFrameThread::save_preset");
277         
278 // Test EDL for plugin existence
279         if(!mwindow->edl->tracks->plugin_exists(plugin))
280         {
281                 mwindow->gui->unlock_window();
282                 get_gui()->lock_window("KeyFrameThread::save_preset 2");
283                 return;
284         }
285
286
287 // Get current plugin keyframe
288         EDL *edl = mwindow->edl;
289         Track *track = plugin->track;
290         KeyFrame *keyframe = plugin->get_prev_keyframe(
291                         track->to_units(edl->local_session->get_selectionstart(1), 0), 
292                         PLAY_FORWARD);
293
294 // Send to database
295         presets_db->save_preset(plugin_title, title, keyframe->get_data());
296
297         mwindow->gui->unlock_window();
298         get_gui()->lock_window("KeyFrameThread::save_preset 2");
299
300
301 // Update list
302         calculate_preset_list();
303         ((KeyFrameWindow*)get_gui())->preset_list->update(presets_data,
304                 0,
305                 0,
306                 1);
307 }
308
309 void KeyFrameThread::delete_preset(const char *title)
310 {
311         get_gui()->unlock_window();
312         mwindow->gui->lock_window("KeyFrameThread::save_preset");
313         
314 // Test EDL for plugin existence
315         if(!mwindow->edl->tracks->plugin_exists(plugin))
316         {
317                 mwindow->gui->unlock_window();
318                 get_gui()->lock_window("KeyFrameThread::delete_preset 1");
319                 return;
320         }
321
322         presets_db->delete_preset(plugin_title, title);
323         
324         mwindow->gui->unlock_window();
325         get_gui()->lock_window("KeyFrameThread::delete_preset 2");
326
327
328 // Update list
329         calculate_preset_list();
330         ((KeyFrameWindow*)get_gui())->preset_list->update(presets_data,
331                 0,
332                 0,
333                 1);
334 }
335
336
337 void KeyFrameThread::apply_preset(const char *title)
338 {
339         if(presets_db->preset_exists(plugin_title, title))
340         {
341                 get_gui()->unlock_window();
342                 mwindow->gui->lock_window("KeyFrameThread::apply_preset");
343
344 // Test EDL for plugin existence
345                 if(!mwindow->edl->tracks->plugin_exists(plugin))
346                 {
347                         mwindow->gui->unlock_window();
348                         get_gui()->lock_window("KeyFrameThread::delete_preset 1");
349                         return;
350                 }
351
352                 mwindow->undo->update_undo_before();
353
354
355 #ifdef USE_KEYFRAME_SPANNING
356                 KeyFrame keyframe;
357                 presets_db->load_preset(plugin_title, title, &keyframe);
358                 plugin->keyframes->update_parameter(&keyframe);
359 #else
360                 KeyFrame *keyframe = plugin->get_keyframe();
361                 presets_db->load_preset(plugin_title, title, keyframe);
362 #endif
363                 mwindow->save_backup();
364                 mwindow->undo->update_undo_after(_("apply preset"), LOAD_AUTOMATION); 
365
366                 mwindow->update_plugin_guis(0);
367                 mwindow->gui->draw_overlays(1);
368                 mwindow->sync_parameters(CHANGE_PARAMS);
369
370
371                 update_gui(1);
372                 mwindow->gui->unlock_window();
373                 get_gui()->lock_window("KeyFrameThread::apply_preset");
374         }
375 }
376
377 #ifdef EDIT_KEYFRAME
378 void KeyFrameThread::apply_value()
379 {
380         const char *text = 0;
381         BC_Hash hash;
382         KeyFrameWindow *window = (KeyFrameWindow*)get_gui();
383         int selection = window->keyframe_list->get_selection_number(0, 0);
384 //printf("KeyFrameThread::apply_value %d %d\n", __LINE__, selection);
385         if(selection < 0) return;
386         
387         if(selection == keyframe_data[0].size() - 1)
388                 text = window->value_text->get_text();
389         else
390         {
391                 char *key = keyframe_data[0].get(selection)->get_text();
392                 const char *value = window->value_text->get_text();
393                 hash.update(key, value);
394         }
395
396         get_gui()->unlock_window();
397         mwindow->gui->lock_window("KeyFrameThread::apply_value");
398         if(plugin && mwindow->edl->tracks->plugin_exists(plugin))
399         {
400                 mwindow->undo->update_undo_before();
401                 if(mwindow->session->keyframedialog_all)
402                 {
403 // Search for all keyframes in selection but don't create a new one.
404                         Track *track = plugin->track;
405                         int64_t start = track->to_units(mwindow->edl->local_session->get_selectionstart(0), 0);
406                         int64_t end = track->to_units(mwindow->edl->local_session->get_selectionend(0), 0);
407                         int got_it = 0;
408                         for(KeyFrame *current = (KeyFrame*)plugin->keyframes->last;
409                                 current;
410                                 current = (KeyFrame*)PREVIOUS)
411                         {
412                                 got_it = 1;
413                                 if(current && current->position < end)
414                                 {
415                                         current->update_parameter(&hash, text, 0);
416 // Stop at beginning of range
417                                         if(current->position <= start) break;
418                                 }
419                         }
420
421                         if(!got_it)
422                         {
423                                 KeyFrame* keyframe = (KeyFrame*)plugin->keyframes->default_auto;
424                                 keyframe->update_parameter(&hash, text, 0);
425                         }
426                 }
427                 else
428                 {
429 // Create new keyframe if enabled
430                         KeyFrame *keyframe = plugin->get_keyframe();
431                         keyframe->update_parameter(&hash, text, 0);
432                 }
433         }
434         else
435         {
436 printf("KeyFrameThread::apply_value %d: plugin doesn't exist\n", __LINE__);
437         }
438
439         mwindow->save_backup();
440         mwindow->undo->update_undo_after(_("edit keyframe"), LOAD_AUTOMATION); 
441
442         mwindow->update_plugin_guis(0);
443         mwindow->gui->draw_overlays(1);
444         mwindow->sync_parameters(CHANGE_PARAMS);
445
446
447
448         mwindow->gui->unlock_window();
449
450         update_gui(0);
451
452         get_gui()->lock_window("KeyFrameThread::apply_value");
453 }
454 #endif
455
456
457
458 KeyFrameWindow::KeyFrameWindow(MWindow *mwindow,
459         KeyFrameThread *thread,
460         int x,
461         int y,
462         char *title_string)
463  : BC_Window(title_string, 
464         x,
465         y,
466         mwindow->session->keyframedialog_w, 
467         mwindow->session->keyframedialog_h, 
468         320, 
469         240,
470         1,
471         0,
472         1)
473 {
474         this->mwindow = mwindow;
475         this->thread = thread;
476 }
477
478 void KeyFrameWindow::create_objects()
479 {
480         Theme *theme = mwindow->theme;
481
482         theme->get_keyframedialog_sizes(this);
483         thread->column_width[0] = mwindow->session->keyframedialog_column1;
484         thread->column_width[1] = mwindow->session->keyframedialog_column2;
485         lock_window("KeyFrameWindow::create_objects");
486
487 #ifdef EDIT_KEYFRAME
488
489
490         add_subwindow(title1 = new BC_Title(theme->keyframe_list_x,
491                 theme->keyframe_list_y - 
492                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
493                         theme->widget_border,
494                 _("Keyframe parameters:"),
495                 LARGEFONT));
496         add_subwindow(keyframe_list = new KeyFrameList(thread,
497                 this,
498                 theme->keyframe_list_x,
499                 theme->keyframe_list_y,
500                 theme->keyframe_list_w, 
501                 theme->keyframe_list_h));
502 //      add_subwindow(title2 = new BC_Title(theme->keyframe_text_x,
503 //              theme->keyframe_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
504 //              _("Global Text:")));
505 //      add_subwindow(keyframe_text = new KeyFrameText(thread,
506 //              this,
507 //              theme->keyframe_text_x,
508 //              theme->keyframe_text_y,
509 //              theme->keyframe_text_w));
510         add_subwindow(title3 = new BC_Title(theme->keyframe_value_x,
511                 theme->keyframe_value_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border,
512                 _("Edit value:")));
513         add_subwindow(value_text = new KeyFrameValue(thread,
514                 this,
515                 theme->keyframe_value_x,
516                 theme->keyframe_value_y,
517                 theme->keyframe_value_w));
518         add_subwindow(all_toggle = new KeyFrameAll(thread,
519                 this, 
520                 theme->keyframe_all_x,
521                 theme->keyframe_all_y));
522
523 #endif
524
525
526
527         add_subwindow(title4 = new BC_Title(theme->presets_list_x,
528                 theme->presets_list_y - 
529                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
530                         theme->widget_border,
531                 _("Presets:"),
532                 LARGEFONT));
533         add_subwindow(preset_list = new KeyFramePresetsList(thread,
534                 this,
535                 theme->presets_list_x,
536                 theme->presets_list_y,
537                 theme->presets_list_w, 
538                 theme->presets_list_h));
539         add_subwindow(title5 = new BC_Title(theme->presets_text_x,
540                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border,
541                 _("Preset title:")));
542         add_subwindow(preset_text = new KeyFramePresetsText(thread,
543                 this,
544                 theme->presets_text_x,
545                 theme->presets_text_y,
546                 theme->presets_text_w));
547         add_subwindow(delete_preset = new KeyFramePresetsDelete(thread,
548                 this,
549                 theme->presets_delete_x,
550                 theme->presets_delete_y));
551         add_subwindow(save_preset = new KeyFramePresetsSave(thread,
552                 this,
553                 theme->presets_save_x,
554                 theme->presets_save_y));
555         add_subwindow(apply_preset = new KeyFramePresetsApply(thread,
556                 this,
557                 theme->presets_apply_x,
558                 theme->presets_apply_y));
559
560
561
562
563         add_subwindow(new KeyFramePresetsOK(thread, this));
564         add_subwindow(new BC_CancelButton(this));
565
566         show_window();
567         unlock_window();
568 }
569
570 int KeyFrameWindow::resize_event(int w, int h)
571 {
572         Theme *theme = mwindow->theme;
573         mwindow->session->keyframedialog_w = w;
574         mwindow->session->keyframedialog_h = h;
575         theme->get_keyframedialog_sizes(this);
576
577 #ifdef EDIT_KEYFRAME
578
579         title1->reposition_window(theme->keyframe_list_x,
580                 theme->keyframe_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
581 //      title2->reposition_window(theme->keyframe_text_x,
582 //              theme->keyframe_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
583         title3->reposition_window(theme->keyframe_value_x,
584                 theme->keyframe_value_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
585         keyframe_list->reposition_window(theme->keyframe_list_x,
586                 theme->keyframe_list_y,
587                 theme->keyframe_list_w, 
588                 theme->keyframe_list_h);
589 //      text->reposition_window(theme->keyframe_text_x,
590 //              theme->keyframe_text_y,
591 //              theme->keyframe_text_w);
592         value_text->reposition_window(theme->keyframe_value_x,
593                 theme->keyframe_value_y,
594                 theme->keyframe_value_w);
595         all_toggle->reposition_window(theme->keyframe_all_x,
596                 theme->keyframe_all_y);
597
598 #endif // EDIT_KEYFRAME
599
600
601
602
603         title4->reposition_window(theme->presets_list_x,
604                 theme->presets_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
605         title5->reposition_window(theme->presets_text_x,
606                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
607         preset_list->reposition_window(theme->presets_list_x,
608                 theme->presets_list_y,
609                 theme->presets_list_w, 
610                 theme->presets_list_h);
611         preset_text->reposition_window(theme->presets_text_x,
612                 theme->presets_text_y,
613                 theme->presets_text_w);
614         delete_preset->reposition_window(theme->presets_delete_x,
615                 theme->presets_delete_y);
616         save_preset->reposition_window(theme->presets_save_x,
617                 theme->presets_save_y);
618         apply_preset->reposition_window(theme->presets_apply_x,
619                 theme->presets_apply_y);
620
621         return 0;
622 }
623
624
625
626
627 #ifdef EDIT_KEYFRAME
628
629
630 KeyFrameList::KeyFrameList(KeyFrameThread *thread,
631         KeyFrameWindow *window,
632         int x,
633         int y,
634         int w, 
635         int h)
636  : BC_ListBox(x, 
637                 y, 
638                 w, 
639                 h,
640                 LISTBOX_TEXT,
641                 thread->keyframe_data,
642                 (const char **)thread->column_titles,
643                 thread->column_width,
644                 KEYFRAME_COLUMNS)
645 {
646         this->thread = thread;
647         this->window = window;
648 }
649
650 int KeyFrameList::selection_changed()
651 {
652         window->value_text->update(
653                 thread->keyframe_data[1].get(get_selection_number(0, 0))->get_text());
654         return 0;
655 }
656
657 int KeyFrameList::handle_event()
658 {
659         window->set_done(0);
660         return 0;
661 }
662
663 int KeyFrameList::column_resize_event()
664 {
665         thread->mwindow->session->keyframedialog_column1 = get_column_width(0);
666         thread->mwindow->session->keyframedialog_column2 = get_column_width(1);
667         return 1;
668 }
669
670
671
672
673 // KeyFrameText::KeyFrameText(KeyFrameThread *thread,
674 //      KeyFrameWindow *window,
675 //      int x,
676 //      int y,
677 //      int w)
678 //  : BC_TextBox(x, 
679 //      y, 
680 //      w, 
681 //      1, 
682 //      "")
683 // {
684 //      this->thread = thread;
685 //      this->window = window;
686 // }
687 // 
688 // int KeyFrameText::handle_event()
689 // {
690 //      return 0;
691 // }
692
693
694
695 KeyFrameValue::KeyFrameValue(KeyFrameThread *thread,
696         KeyFrameWindow *window,
697         int x,
698         int y,
699         int w)
700  : BC_TextBox(x, 
701         y, 
702         w, 
703         1, 
704         (char*)"")
705 {
706         this->thread = thread;
707         this->window = window;
708 }
709
710 int KeyFrameValue::handle_event()
711 {
712         thread->update_values();
713         return 0;
714 }
715
716
717
718
719
720 KeyFrameAll::KeyFrameAll(KeyFrameThread *thread,
721         KeyFrameWindow *window,
722         int x,
723         int y)
724  : BC_CheckBox(x, 
725         y, 
726         thread->mwindow->session->keyframedialog_all, 
727         _("Apply to all selected keyframes"))
728 {
729         this->thread = thread;
730         this->window = window;
731 }
732
733 int KeyFrameAll::handle_event()
734 {
735         thread->mwindow->session->keyframedialog_all = get_value();
736         return 1;
737 }
738
739 #endif // EDIT_KEYFRAME
740
741
742
743
744
745
746
747
748
749
750 KeyFramePresetsList::KeyFramePresetsList(KeyFrameThread *thread,
751         KeyFrameWindow *window,
752         int x,
753         int y,
754         int w, 
755         int h)
756  : BC_ListBox(x, 
757                 y, 
758                 w, 
759                 h,
760                 LISTBOX_TEXT,
761                 thread->presets_data)
762 {
763         this->thread = thread;
764         this->window = window;
765 }
766
767 int KeyFramePresetsList::selection_changed()
768 {
769         if(get_selection_number(0, 0) >= 0)
770                 window->preset_text->update(
771                         thread->presets_data->get(get_selection_number(0, 0))->get_text());
772         return 0;
773 }
774
775 int KeyFramePresetsList::handle_event()
776 {
777         thread->apply_preset(window->preset_text->get_text());
778         window->set_done(0);
779         return 0;
780 }
781
782
783
784
785
786
787
788
789
790
791 KeyFramePresetsText::KeyFramePresetsText(KeyFrameThread *thread,
792         KeyFrameWindow *window,
793         int x,
794         int y,
795         int w)
796  : BC_TextBox(x, 
797         y, 
798         w, 
799         1, 
800         (char*)"")
801 {
802         this->thread = thread;
803         this->window = window;
804 }
805
806 int KeyFramePresetsText::handle_event()
807 {
808         return 0;
809 }
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827 KeyFramePresetsDelete::KeyFramePresetsDelete(KeyFrameThread *thread,
828         KeyFrameWindow *window,
829         int x,
830         int y)
831  : BC_GenericButton(x, y, _("Delete"))
832 {
833         this->thread = thread;
834         this->window = window;
835 }
836
837 int KeyFramePresetsDelete::handle_event()
838 {
839         thread->delete_preset(window->preset_text->get_text());
840         return 1;
841 }
842
843
844
845
846
847
848
849 KeyFramePresetsSave::KeyFramePresetsSave(KeyFrameThread *thread,
850         KeyFrameWindow *window,
851         int x,
852         int y)
853 : BC_GenericButton(x, y, _("Save"))
854 {
855         this->thread = thread;
856         this->window = window;
857 }
858
859 int KeyFramePresetsSave::handle_event()
860 {
861         thread->save_preset(window->preset_text->get_text());
862         return 1;
863 }
864
865
866
867
868
869
870
871
872 KeyFramePresetsApply::KeyFramePresetsApply(KeyFrameThread *thread,
873         KeyFrameWindow *window,
874         int x,
875         int y)
876  : BC_GenericButton(x, y, _("Apply"))
877 {
878         this->thread = thread;
879         this->window = window;
880 }
881
882 int KeyFramePresetsApply::handle_event()
883 {
884         thread->apply_preset(window->preset_text->get_text());
885         return 1;
886 }
887
888
889 KeyFramePresetsOK::KeyFramePresetsOK(KeyFrameThread *thread,
890         KeyFrameWindow *window)
891  : BC_OKButton(window)
892 {
893         this->thread = thread;
894         this->window = window;
895 }
896
897 int KeyFramePresetsOK::keypress_event()
898 {
899         if(get_keypress() == RETURN)
900         {
901 // Apply the preset
902                 if(thread->presets_db->preset_exists(thread->plugin_title, 
903                         window->preset_text->get_text()))
904                 {
905                         window->set_done(0);
906                         return 1;
907                 }
908                 else
909 // Save the preset
910                 {
911                         thread->save_preset(window->preset_text->get_text());
912                         return 1;
913                 }
914         }
915         return 0;
916 }
917
918
919
920
921
922
923