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