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