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