merged hv7 mod
[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, PROGRAM_NAME ": %s Keyframe", 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 - 
483                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
484                         theme->widget_border,
485                 _("Keyframe parameters:"),
486                 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") - theme->widget_border,
503                 _("Edit value:")));
504         add_subwindow(value_text = new KeyFrameValue(thread,
505                 this,
506                 theme->keyframe_value_x,
507                 theme->keyframe_value_y,
508                 theme->keyframe_value_w));
509         add_subwindow(all_toggle = new KeyFrameAll(thread,
510                 this, 
511                 theme->keyframe_all_x,
512                 theme->keyframe_all_y));
513
514 #endif
515
516
517
518         add_subwindow(title4 = new BC_Title(theme->presets_list_x,
519                 theme->presets_list_y - 
520                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
521                         theme->widget_border,
522                 _("Presets:"),
523                 LARGEFONT));
524         add_subwindow(preset_list = new KeyFramePresetsList(thread,
525                 this,
526                 theme->presets_list_x,
527                 theme->presets_list_y,
528                 theme->presets_list_w, 
529                 theme->presets_list_h));
530         add_subwindow(title5 = new BC_Title(theme->presets_text_x,
531                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border,
532                 _("Preset title:")));
533         add_subwindow(preset_text = new KeyFramePresetsText(thread,
534                 this,
535                 theme->presets_text_x,
536                 theme->presets_text_y,
537                 theme->presets_text_w));
538         add_subwindow(delete_preset = new KeyFramePresetsDelete(thread,
539                 this,
540                 theme->presets_delete_x,
541                 theme->presets_delete_y));
542         add_subwindow(save_preset = new KeyFramePresetsSave(thread,
543                 this,
544                 theme->presets_save_x,
545                 theme->presets_save_y));
546         add_subwindow(apply_preset = new KeyFramePresetsApply(thread,
547                 this,
548                 theme->presets_apply_x,
549                 theme->presets_apply_y));
550
551
552
553
554         add_subwindow(new KeyFramePresetsOK(thread, this));
555         add_subwindow(new BC_CancelButton(this));
556
557         show_window();
558         unlock_window();
559 }
560
561 // called when going in & out of a factory preset
562 void KeyFrameWindow::update_editing()
563 {
564         if( thread->is_factory ) {
565                 delete_preset->disable();
566                 save_preset->disable();
567         }
568         else {
569                 delete_preset->enable();
570                 save_preset->enable();
571         }
572 }
573
574
575
576 int KeyFrameWindow::resize_event(int w, int h)
577 {
578         Theme *theme = mwindow->theme;
579         mwindow->session->keyframedialog_w = w;
580         mwindow->session->keyframedialog_h = h;
581         theme->get_keyframedialog_sizes(this);
582
583 #ifdef EDIT_KEYFRAME
584
585         title1->reposition_window(theme->keyframe_list_x,
586                 theme->keyframe_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
587 //      title2->reposition_window(theme->keyframe_text_x,
588 //              theme->keyframe_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
589         title3->reposition_window(theme->keyframe_value_x,
590                 theme->keyframe_value_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
591         keyframe_list->reposition_window(theme->keyframe_list_x,
592                 theme->keyframe_list_y,
593                 theme->keyframe_list_w, 
594                 theme->keyframe_list_h);
595 //      text->reposition_window(theme->keyframe_text_x,
596 //              theme->keyframe_text_y,
597 //              theme->keyframe_text_w);
598         value_text->reposition_window(theme->keyframe_value_x,
599                 theme->keyframe_value_y,
600                 theme->keyframe_value_w);
601         all_toggle->reposition_window(theme->keyframe_all_x,
602                 theme->keyframe_all_y);
603
604 #endif // EDIT_KEYFRAME
605
606
607
608
609         title4->reposition_window(theme->presets_list_x,
610                 theme->presets_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
611         title5->reposition_window(theme->presets_text_x,
612                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
613         preset_list->reposition_window(theme->presets_list_x,
614                 theme->presets_list_y,
615                 theme->presets_list_w, 
616                 theme->presets_list_h);
617         preset_text->reposition_window(theme->presets_text_x,
618                 theme->presets_text_y,
619                 theme->presets_text_w);
620         delete_preset->reposition_window(theme->presets_delete_x,
621                 theme->presets_delete_y);
622         save_preset->reposition_window(theme->presets_save_x,
623                 theme->presets_save_y);
624         apply_preset->reposition_window(theme->presets_apply_x,
625                 theme->presets_apply_y);
626
627         return 0;
628 }
629
630
631
632
633 #ifdef EDIT_KEYFRAME
634
635
636 KeyFrameList::KeyFrameList(KeyFrameThread *thread,
637         KeyFrameWindow *window,
638         int x,
639         int y,
640         int w, 
641         int h)
642  : BC_ListBox(x, 
643                 y, 
644                 w, 
645                 h,
646                 LISTBOX_TEXT,
647                 thread->keyframe_data,
648                 thread->column_titles,
649                 thread->column_width,
650                 KEYFRAME_COLUMNS)
651 {
652         this->thread = thread;
653         this->window = window;
654 }
655
656 int KeyFrameList::selection_changed()
657 {
658         window->value_text->update(
659                 thread->keyframe_data[1].get(get_selection_number(0, 0))->get_text());
660         return 0;
661 }
662
663 int KeyFrameList::handle_event()
664 {
665         window->set_done(0);
666         return 0;
667 }
668
669 int KeyFrameList::column_resize_event()
670 {
671         thread->mwindow->session->keyframedialog_column1 = get_column_width(0);
672         thread->mwindow->session->keyframedialog_column2 = get_column_width(1);
673         return 1;
674 }
675
676
677
678
679 // KeyFrameText::KeyFrameText(KeyFrameThread *thread,
680 //      KeyFrameWindow *window,
681 //      int x,
682 //      int y,
683 //      int w)
684 //  : BC_TextBox(x, 
685 //      y, 
686 //      w, 
687 //      1, 
688 //      "")
689 // {
690 //      this->thread = thread;
691 //      this->window = window;
692 // }
693 // 
694 // int KeyFrameText::handle_event()
695 // {
696 //      return 0;
697 // }
698
699
700
701 KeyFrameValue::KeyFrameValue(KeyFrameThread *thread,
702         KeyFrameWindow *window,
703         int x,
704         int y,
705         int w)
706  : BC_TextBox(x, 
707         y, 
708         w, 
709         1, 
710         (char*)"")
711 {
712         this->thread = thread;
713         this->window = window;
714 }
715
716 int KeyFrameValue::handle_event()
717 {
718         thread->apply_value();
719         return 0;
720 }
721
722
723
724
725
726 KeyFrameAll::KeyFrameAll(KeyFrameThread *thread,
727         KeyFrameWindow *window,
728         int x,
729         int y)
730  : BC_CheckBox(x, 
731         y, 
732         thread->mwindow->session->keyframedialog_all, 
733         _("Apply to all selected keyframes"))
734 {
735         this->thread = thread;
736         this->window = window;
737 }
738
739 int KeyFrameAll::handle_event()
740 {
741         thread->mwindow->session->keyframedialog_all = get_value();
742         return 1;
743 }
744
745 #endif // EDIT_KEYFRAME
746
747
748
749
750
751
752
753
754
755
756 KeyFramePresetsList::KeyFramePresetsList(KeyFrameThread *thread,
757         KeyFrameWindow *window,
758         int x,
759         int y,
760         int w, 
761         int h)
762  : BC_ListBox(x, 
763                 y, 
764                 w, 
765                 h,
766                 LISTBOX_TEXT,
767                 thread->presets_data)
768 {
769         this->thread = thread;
770         this->window = window;
771 }
772
773 int KeyFramePresetsList::selection_changed()
774 {
775         int number = get_selection_number(0, 0);
776         if( number >= 0 ) {
777                 strcpy(thread->preset_text, thread->preset_titles.get(number));
778                 thread->is_factory = thread->is_factories.get(number);
779 // show title without factory symbol in the textbox
780                 window->preset_text->update(
781                         thread->presets_data->get(number)->get_text());
782                 window->update_editing();
783         }
784         
785         return 0;
786 }
787
788 int KeyFramePresetsList::handle_event()
789 {
790         thread->apply_preset(thread->preset_text, thread->is_factory);
791         window->set_done(0);
792         return 0;
793 }
794
795
796 KeyFramePresetsText::KeyFramePresetsText(KeyFrameThread *thread,
797         KeyFrameWindow *window, int x, int y, int w)
798  : BC_TextBox(x, y, w, 1, thread->preset_text)
799 {
800         this->thread = thread;
801         this->window = window;
802 }
803
804 // user entered a title
805 int KeyFramePresetsText::handle_event()
806 {
807         strcpy(thread->preset_text, get_text());
808 // once changed, it's now not a factory preset
809         thread->is_factory = 0;
810         window->update_editing();
811         return 0;
812 }
813
814
815 KeyFramePresetsDelete::KeyFramePresetsDelete(KeyFrameThread *thread,
816         KeyFrameWindow *window,
817         int x,
818         int y)
819  : BC_GenericButton(x, y, _("Delete"))
820 {
821         this->thread = thread;
822         this->window = window;
823 }
824
825 int KeyFramePresetsDelete::handle_event()
826 {
827         if( !thread->is_factory ) {
828                 thread->delete_preset(thread->preset_text, thread->is_factory);
829         }
830         return 1;
831 }
832
833
834 KeyFramePresetsSave::KeyFramePresetsSave(KeyFrameThread *thread,
835         KeyFrameWindow *window,
836         int x,
837         int y)
838 : BC_GenericButton(x, y, _("Save"))
839 {
840         this->thread = thread;
841         this->window = window;
842 }
843
844 int KeyFramePresetsSave::handle_event()
845 {
846         if( !thread->is_factory ) {
847                 thread->save_preset(thread->preset_text, thread->is_factory);
848         }
849         return 1;
850 }
851
852
853
854
855
856
857
858
859 KeyFramePresetsApply::KeyFramePresetsApply(KeyFrameThread *thread,
860         KeyFrameWindow *window,
861         int x,
862         int y)
863  : BC_GenericButton(x, y, _("Apply"))
864 {
865         this->thread = thread;
866         this->window = window;
867 }
868
869 int KeyFramePresetsApply::handle_event()
870 {
871         thread->apply_preset(thread->preset_text, thread->is_factory);
872         return 1;
873 }
874
875
876 KeyFramePresetsOK::KeyFramePresetsOK(KeyFrameThread *thread,
877         KeyFrameWindow *window)
878  : BC_OKButton(window)
879 {
880         this->thread = thread;
881         this->window = window;
882 }
883
884 int KeyFramePresetsOK::keypress_event()
885 {
886         if( get_keypress() == RETURN ) {
887 // Apply the preset
888                 if( thread->presets_db->preset_exists(thread->plugin_title, 
889                         thread->preset_text, thread->is_factory) ) {
890                         window->set_done(0);
891                         return 1;
892                 }
893                 else {
894                         if( !thread->is_factory ) {
895                                 thread->save_preset(thread->preset_text, thread->is_factory);
896                                 return 1;
897                         }
898                 }
899         }
900         return 0;
901 }
902