3d7703c2150ed09cf8c3f9ea7c504988f3d9ec19
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / editpanel.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "awindow.h"
23 #include "awindowgui.h"
24 #include "bcsignals.h"
25 #include "clipedit.h"
26 #include "cplayback.h"
27 #include "cwindow.h"
28 #include "cwindowgui.h"
29 #include "editpanel.h"
30 #include "edl.h"
31 #include "edlsession.h"
32 #include "filexml.h"
33 #include "keys.h"
34 #include "language.h"
35 #include "localsession.h"
36 #include "mainclock.h"
37 #include "mainundo.h"
38 #include "mbuttons.h"
39 #include "meterpanel.h"
40 #include "mwindow.h"
41 #include "mwindowgui.h"
42 #include "playbackengine.h"
43 #include "theme.h"
44 #include "timebar.h"
45 #include "trackcanvas.h"
46 #include "transportque.h"
47 #include "zoombar.h"
48 #include "manualgoto.h"
49
50
51
52 EditPanel::EditPanel(MWindow *mwindow,
53         BC_WindowBase *subwindow,
54         int window_id,
55         int x,
56         int y,
57         int editing_mode,
58         int use_editing_mode,
59         int use_keyframe,
60         int use_splice,   // Extra buttons
61         int use_overwrite,
62         int use_copy,
63         int use_paste,
64         int use_undo,
65         int use_fit,
66         int use_locklabels,
67         int use_labels,
68         int use_toclip,
69         int use_meters,
70         int use_cut,
71         int use_commercial,
72         int use_goto,
73         int use_clk2play)
74 {
75         this->window_id = window_id;
76         this->editing_mode = editing_mode;
77         this->use_editing_mode = use_editing_mode;
78         this->use_keyframe = use_keyframe;
79         this->use_splice = use_splice;
80         this->use_overwrite = use_overwrite;
81         this->use_copy = use_copy;
82         this->use_paste = use_paste;
83         this->use_undo = use_undo;
84         this->mwindow = mwindow;
85         this->subwindow = subwindow;
86         this->use_fit = use_fit;
87         this->use_labels = use_labels;
88         this->use_locklabels = use_locklabels;
89         this->use_toclip = use_toclip;
90         this->use_meters = use_meters;
91         this->use_cut = use_cut;
92         this->use_commercial = use_commercial;
93         this->use_goto = use_goto;
94         this->use_clk2play = use_clk2play;
95
96         this->x = x;
97         this->y = y;
98         this->fit = 0;
99         this->fit_autos = 0;
100         this->inpoint = 0;
101         this->outpoint = 0;
102         this->splice = 0;
103         this->overwrite = 0;
104         this->clip = 0;
105         this->cut = 0;
106         this->commercial = 0;
107         this->copy = 0;
108         this->paste = 0;
109         this->labelbutton = 0;
110         this->prevlabel = 0;
111         this->nextlabel = 0;
112         this->prevedit = 0;
113         this->nextedit = 0;
114         this->undo = 0;
115         this->redo = 0;
116         this->meter_panel = 0;
117         this->meters = 0;
118         this->arrow = 0;
119         this->ibeam = 0;
120         this->keyframe = 0;
121         this->span_keyframe = 0;
122         this->mangoto = 0;
123         this->click2play = 0;
124         locklabels = 0;
125 }
126
127 EditPanel::~EditPanel()
128 {
129 }
130
131 void EditPanel::set_meters(MeterPanel *meter_panel)
132 {
133         this->meter_panel = meter_panel;
134 }
135
136
137 void EditPanel::update()
138 {
139         int new_editing_mode = mwindow->edl->session->editing_mode;
140         if( arrow ) arrow->update(new_editing_mode == EDITING_ARROW);
141         if( ibeam ) ibeam->update(new_editing_mode == EDITING_IBEAM);
142         if( keyframe ) keyframe->update(mwindow->edl->session->auto_keyframes);
143         if( span_keyframe ) span_keyframe->update(mwindow->edl->session->span_keyframes);
144         if( locklabels ) locklabels->set_value(mwindow->edl->session->labels_follow_edits);
145         if( click2play ) {
146                 int value = !is_vwindow() ?
147                         mwindow->edl->session->cwindow_click2play :
148                         mwindow->edl->session->vwindow_click2play ;
149                 click2play->set_value(value);
150         }
151         if( meters ) {
152                 if( is_cwindow() ) {
153                         meters->update(mwindow->edl->session->cwindow_meter);
154                         mwindow->cwindow->gui->update_meters();
155                 }
156                 else {
157                         meters->update(mwindow->edl->session->vwindow_meter);
158                 }
159         }
160         subwindow->flush();
161 }
162
163 int EditPanel::calculate_w(MWindow *mwindow, int use_keyframe, int total_buttons)
164 {
165         int result = 0;
166         int button_w = mwindow->theme->get_image_set("ibeam")[0]->get_w();
167         if( use_keyframe ) {
168                 result += button_w + mwindow->theme->toggle_margin;
169         }
170
171         result += button_w * total_buttons;
172         return result;
173 }
174
175 int EditPanel::calculate_h(MWindow *mwindow)
176 {
177         return mwindow->theme->get_image_set("ibeam")[0]->get_h();
178 }
179
180 void EditPanel::create_buttons()
181 {
182         x1 = x, y1 = y;
183
184         if( use_editing_mode ) {
185                 arrow = new ArrowButton(mwindow, this, x1, y1);
186                 subwindow->add_subwindow(arrow);
187                 x1 += arrow->get_w();
188                 ibeam = new IBeamButton(mwindow, this, x1, y1);
189                 subwindow->add_subwindow(ibeam);
190                 x1 += ibeam->get_w();
191                 x1 += mwindow->theme->toggle_margin;
192         }
193
194         if( use_keyframe ) {
195                 keyframe = new KeyFrameButton(mwindow, this, x1, y1);
196                 subwindow->add_subwindow(keyframe);
197                 x1 += keyframe->get_w();
198                 span_keyframe = new SpanKeyFrameButton(mwindow, this, x1, y1);
199                 subwindow->add_subwindow(span_keyframe);
200                 x1 += span_keyframe->get_w();
201         }
202
203         if( use_locklabels ) {
204                 locklabels = new LockLabelsButton(mwindow, this, x1, y1);
205                 subwindow->add_subwindow(locklabels);
206                 x1 += locklabels->get_w();
207         }
208
209         if( use_keyframe || use_locklabels )
210                 x1 += mwindow->theme->toggle_margin;
211
212 // Mandatory
213         inpoint = new EditInPoint(mwindow, this, x1, y1);
214         subwindow->add_subwindow(inpoint);
215         x1 += inpoint->get_w();
216         outpoint = new EditOutPoint(mwindow, this, x1, y1);
217         subwindow->add_subwindow(outpoint);
218         x1 += outpoint->get_w();
219
220         if( use_splice ) {
221                 splice = new EditSplice(mwindow, this, x1, y1);
222                 subwindow->add_subwindow(splice);
223                 x1 += splice->get_w();
224         }
225
226         if( use_overwrite ) {
227                 overwrite = new EditOverwrite(mwindow, this, x1, y1);
228                 subwindow->add_subwindow(overwrite);
229                 x1 += overwrite->get_w();
230         }
231
232         if( use_toclip ) {
233                 clip = new EditToClip(mwindow, this, x1, y1);
234                 subwindow->add_subwindow(clip);
235                 x1 += clip->get_w();
236         }
237
238         if( use_cut ) {
239                 cut = new EditCut(mwindow, this, x1, y1);
240                 subwindow->add_subwindow(cut);
241                 x1 += cut->get_w();
242         }
243
244         if( use_copy ) {
245                 copy = new EditCopy(mwindow, this, x1, y1);
246                 subwindow->add_subwindow(copy);
247                 x1 += copy->get_w();
248         }
249
250         if( use_paste ) {
251                 paste = new EditPaste(mwindow, this, x1, y1);
252                 subwindow->add_subwindow(paste);
253                 x1 += paste->get_w();
254         }
255
256         if( use_meters ) {
257                 if( meter_panel ) {
258                         meters = new MeterShow(mwindow, meter_panel, x1, y1);
259                         subwindow->add_subwindow(meters);
260                         x1 += meters->get_w();
261                 }
262                 else
263                         printf("EditPanel::create_objects: meter_panel == 0\n");
264         }
265
266         if( use_labels ) {
267                 labelbutton = new EditLabelbutton(mwindow, this, x1, y1);
268                 subwindow->add_subwindow(labelbutton);
269                 x1 += labelbutton->get_w();
270                 prevlabel = new EditPrevLabel(mwindow, this, x1, y1);
271                 subwindow->add_subwindow(prevlabel);
272                 x1 += prevlabel->get_w();
273                 nextlabel = new EditNextLabel(mwindow, this, x1, y1);
274                 subwindow->add_subwindow(nextlabel);
275                 x1 += nextlabel->get_w();
276         }
277
278 // all windows except VWindow since it's only implemented in MWindow.
279         if( use_cut ) {
280                 prevedit = new EditPrevEdit(mwindow, this, x1, y1);
281                 subwindow->add_subwindow(prevedit);
282                 x1 += prevedit->get_w();
283                 nextedit = new EditNextEdit(mwindow, this, x1, y1);
284                 subwindow->add_subwindow(nextedit);
285                 x1 += nextedit->get_w();
286         }
287
288         if( use_fit ) {
289                 fit = new EditFit(mwindow, this, x1, y1);
290                 subwindow->add_subwindow(fit);
291                 x1 += fit->get_w();
292                 fit_autos = new EditFitAutos(mwindow, this, x1, y1);
293                 subwindow->add_subwindow(fit_autos);
294                 x1 += fit_autos->get_w();
295         }
296
297         if( use_undo ) {
298                 undo = new EditUndo(mwindow, this, x1, y1);
299                 subwindow->add_subwindow(undo);
300                 x1 += undo->get_w();
301                 redo = new EditRedo(mwindow, this, x1, y1);
302                 subwindow->add_subwindow(redo);
303                 x1 += redo->get_w();
304         }
305
306         if( use_goto ) {
307                 mangoto = new EditManualGoto(mwindow, this, x1, y1);
308                 subwindow->add_subwindow(mangoto);
309                 x1 += mangoto->get_w();
310         }
311
312         if( use_clk2play ) {
313                 click2play = new EditClick2Play(mwindow, this, x1, y1+5);
314                 subwindow->add_subwindow(click2play);
315                 x1 += click2play->get_w();
316         }
317
318         if( use_commercial ) {
319                 commercial = new EditCommercial(mwindow, this, x1, y1);
320                 subwindow->add_subwindow(commercial);
321                 x1 += commercial->get_w();
322         }
323 }
324
325 void EditPanel::reposition_buttons(int x, int y)
326 {
327         this->x = x;
328         this->y = y;
329         x1 = x, y1 = y;
330
331         if( use_editing_mode ) {
332                 arrow->reposition_window(x1, y1);
333                 x1 += arrow->get_w();
334                 ibeam->reposition_window(x1, y1);
335                 x1 += ibeam->get_w();
336                 x1 += mwindow->theme->toggle_margin;
337         }
338
339         if( use_keyframe ) {
340                 keyframe->reposition_window(x1, y1);
341                 x1 += keyframe->get_w();
342                 span_keyframe->reposition_window(x1, y1);
343                 x1 += span_keyframe->get_w();
344         }
345
346         if( use_locklabels ) {
347                 locklabels->reposition_window(x1,y1);
348                 x1 += locklabels->get_w();
349         }
350
351         if( use_keyframe || use_locklabels )
352                 x1 += mwindow->theme->toggle_margin;
353
354         inpoint->reposition_window(x1, y1);
355         x1 += inpoint->get_w();
356         outpoint->reposition_window(x1, y1);
357         x1 += outpoint->get_w();
358         if( use_splice ) {
359                 splice->reposition_window(x1, y1);
360                 x1 += splice->get_w();
361         }
362         if( use_overwrite ) {
363                 overwrite->reposition_window(x1, y1);
364                 x1 += overwrite->get_w();
365         }
366         if( use_toclip ) {
367                 clip->reposition_window(x1, y1);
368                 x1 += clip->get_w();
369         }
370         if( use_cut ) {
371                 cut->reposition_window(x1, y1);
372                 x1 += cut->get_w();
373         }
374         if( use_copy ) {
375                 copy->reposition_window(x1, y1);
376                 x1 += copy->get_w();
377         }
378         if( use_paste ) {
379                 paste->reposition_window(x1, y1);
380                 x1 += paste->get_w();
381         }
382
383         if( use_meters ) {
384                 meters->reposition_window(x1, y1);
385                 x1 += meters->get_w();
386         }
387
388         if( use_labels ) {
389                 labelbutton->reposition_window(x1, y1);
390                 x1 += labelbutton->get_w();
391                 prevlabel->reposition_window(x1, y1);
392                 x1 += prevlabel->get_w();
393                 nextlabel->reposition_window(x1, y1);
394                 x1 += nextlabel->get_w();
395         }
396
397         if( prevedit ) {
398                 prevedit->reposition_window(x1, y1);
399                 x1 += prevedit->get_w();
400         }
401
402         if( nextedit ) {
403                 nextedit->reposition_window(x1, y1);
404                 x1 += nextedit->get_w();
405         }
406
407         if( use_fit ) {
408                 fit->reposition_window(x1, y1);
409                 x1 += fit->get_w();
410                 fit_autos->reposition_window(x1, y1);
411                 x1 += fit_autos->get_w();
412         }
413
414         if( use_undo ) {
415                 undo->reposition_window(x1, y1);
416                 x1 += undo->get_w();
417                 redo->reposition_window(x1, y1);
418                 x1 += redo->get_w();
419         }
420
421         if( use_goto ) {
422                 mangoto->reposition_window(x1, y1);
423                 x1 += mangoto->get_w();
424         }
425         if( use_clk2play ) {
426                 click2play->reposition_window(x1, y1+5);
427                 x1 += click2play->get_w();
428         }
429 }
430
431 void EditPanel::create_objects()
432 {
433         create_buttons();
434 }
435
436 int EditPanel::get_w()
437 {
438         return x1 - x;
439 }
440
441 // toggle_label
442 EditLabelbutton::EditLabelbutton(MWindow *mwindow, EditPanel *panel, int x, int y)
443  : BC_Button(x, y, mwindow->theme->get_image_set("labelbutton"))
444 {
445         this->mwindow = mwindow;
446         this->panel = panel;
447         set_tooltip(_("Toggle label at current position ( l )"));
448 }
449
450 EditLabelbutton::~EditLabelbutton()
451 {
452 }
453 int EditLabelbutton::keypress_event()
454 {
455         if( get_keypress() == 'l' && !alt_down() )
456                 return handle_event();
457         return 0;
458 }
459 int EditLabelbutton::handle_event()
460 {
461         panel->panel_toggle_label();
462         return 1;
463 }
464
465 //next_label
466 EditNextLabel::EditNextLabel(MWindow *mwindow,
467         EditPanel *panel, int x, int y)
468  : BC_Button(x, y, mwindow->theme->get_image_set("nextlabel"))
469 {
470         this->mwindow = mwindow;
471         this->panel = panel;
472         set_tooltip(_("Next label ( ctrl -> )"));
473 }
474 EditNextLabel::~EditNextLabel()
475 {
476 }
477 int EditNextLabel::keypress_event()
478 {
479         if( ctrl_down() ) {
480                 int key = get_keypress();
481                 if( (key == RIGHT || key == '.') && !alt_down() ) {
482                         panel->panel_next_label(0);
483                         return 1;
484                 }
485                 if( key == '>' && alt_down() ) {
486                         panel->panel_next_label(1);
487                         return 1;
488                 }
489         }
490         return 0;
491 }
492 int EditNextLabel::handle_event()
493 {
494         int cut = ctrl_down() && alt_down();
495         panel->panel_next_label(cut);
496         return 1;
497 }
498
499 //prev_label
500 EditPrevLabel::EditPrevLabel(MWindow *mwindow,
501         EditPanel *panel, int x, int y)
502  : BC_Button(x, y, mwindow->theme->get_image_set("prevlabel"))
503 {
504         this->mwindow = mwindow;
505         this->panel = panel;
506         set_tooltip(_("Previous label ( ctrl <- )"));
507 }
508 EditPrevLabel::~EditPrevLabel()
509 {
510 }
511 int EditPrevLabel::keypress_event()
512 {
513         if( ctrl_down() ) {
514                 int key = get_keypress();
515                 if( (key == LEFT || key == ',') && !alt_down() ) {
516                         panel->panel_prev_label(0);
517                         return 1;
518                 }
519                 if( key == '<' && alt_down() ) {
520                         panel->panel_prev_label(1);
521                         return 1;
522                 }
523         }
524         return 0;
525 }
526 int EditPrevLabel::handle_event()
527 {
528         int cut = ctrl_down() && alt_down();
529         panel->panel_prev_label(cut);
530         return 1;
531 }
532
533 //prev_edit
534 EditPrevEdit::EditPrevEdit(MWindow *mwindow,
535         EditPanel *panel, int x, int y)
536  : BC_Button(x, y, mwindow->theme->get_image_set("prevedit"))
537 {
538         this->mwindow = mwindow;
539         this->panel = panel;
540         set_tooltip(_("Previous edit (alt <- )"));
541 }
542 EditPrevEdit::~EditPrevEdit()
543 {
544 }
545 int EditPrevEdit::keypress_event()
546 {
547         if( alt_down() ) {
548                 int key = get_keypress();
549                 if( (key == LEFT || key == ',') && !ctrl_down() ) {
550                         panel->panel_prev_edit(0);
551                         return 1;
552                 }
553                 if( key == ',' && ctrl_down() ) {
554                         panel->panel_prev_edit(1);
555                         return 1;
556                 }
557         }
558         return 0;
559 }
560 int EditPrevEdit::handle_event()
561 {
562         int cut = ctrl_down() && alt_down();
563         panel->panel_prev_edit(cut);
564         return 1;
565 }
566
567 //next_edit
568 EditNextEdit::EditNextEdit(MWindow *mwindow,
569         EditPanel *panel, int x, int y)
570  : BC_Button(x, y, mwindow->theme->get_image_set("nextedit"))
571 {
572         this->mwindow = mwindow;
573         this->panel = panel;
574         set_tooltip(_("Next edit ( alt -> )"));
575 }
576 EditNextEdit::~EditNextEdit()
577 {
578 }
579 int EditNextEdit::keypress_event()
580 {
581         if( alt_down() ) {
582                 int key = get_keypress();
583                 if( (key == RIGHT || key == '.') && !ctrl_down() ) {
584                         panel->panel_next_edit(0);
585                         return 1;
586                 }
587                 if( key == '.' && ctrl_down() ) {
588                         panel->panel_next_edit(1);
589                         return 1;
590                 }
591         }
592         return 0;
593 }
594 int EditNextEdit::handle_event()
595 {
596         int cut = ctrl_down() && alt_down();
597         panel->panel_next_edit(cut);
598         return 1;
599 }
600
601 //copy_selection
602 EditCopy::EditCopy(MWindow *mwindow, EditPanel *panel, int x, int y)
603  : BC_Button(x, y, mwindow->theme->get_image_set("copy"))
604 {
605         this->mwindow = mwindow;
606         this->panel = panel;
607         set_tooltip(_("Copy ( c )"));
608 }
609 EditCopy::~EditCopy()
610 {
611 }
612
613 int EditCopy::keypress_event()
614 {
615         if( alt_down() ) return 0;
616         if( (get_keypress() == 'c' && !ctrl_down()) ||
617             (panel->is_vwindow() && get_keypress() == 'C') ) {
618                 return handle_event();
619         }
620         return 0;
621 }
622 int EditCopy::handle_event()
623 {
624         panel->panel_copy_selection();
625         return 1;
626 }
627
628 //overwrite_selection
629 EditOverwrite::EditOverwrite(MWindow *mwindow, EditPanel *panel, int x, int y)
630  : BC_Button(x, y, mwindow->theme->overwrite_data)
631 {
632         this->mwindow = mwindow;
633         this->panel = panel;
634         set_tooltip(_("Overwrite ( b )"));
635 }
636 EditOverwrite::~EditOverwrite()
637 {
638 }
639 int EditOverwrite::handle_event()
640 {
641         panel->panel_overwrite_selection();
642         return 1;
643 }
644 int EditOverwrite::keypress_event()
645 {
646         if( alt_down() ) return 0;
647         if( get_keypress() == 'b' ||
648             (panel->is_vwindow() && get_keypress() == 'B') ) {
649                 handle_event();
650                 return 1;
651         }
652         return 0;
653 }
654
655 //set_inpoint
656 //unset_inoutpoint
657 EditInPoint::EditInPoint(MWindow *mwindow, EditPanel *panel, int x, int y)
658  : BC_Button(x, y, mwindow->theme->get_image_set("inbutton"))
659 {
660         this->mwindow = mwindow;
661         this->panel = panel;
662         set_tooltip(_("In point ( [ or < )"));
663 }
664 EditInPoint::~EditInPoint()
665 {
666 }
667 int EditInPoint::handle_event()
668 {
669         panel->panel_set_inpoint();
670         return 1;
671 }
672 int EditInPoint::keypress_event()
673 {
674         int key = get_keypress();
675         if( ctrl_down() ) {
676                 if( key == 't' ) {
677                         panel->panel_unset_inoutpoint();
678                         return 1;
679                 }
680         }
681         else if( !alt_down() ) {
682                 if( key == '[' || key == '<' ) {
683                         panel->panel_set_inpoint();
684                         return 1;
685                 }
686         }
687         return 0;
688 }
689
690 //set_outpoint
691 //unset_inoutpoint
692 EditOutPoint::EditOutPoint(MWindow *mwindow, EditPanel *panel, int x, int y)
693  : BC_Button(x, y, mwindow->theme->get_image_set("outbutton"))
694 {
695         this->mwindow = mwindow;
696         this->panel = panel;
697         set_tooltip(_("Out point ( ] or > )"));
698 }
699 EditOutPoint::~EditOutPoint()
700 {
701 }
702 int EditOutPoint::handle_event()
703 {
704         panel->panel_set_outpoint();
705         return 1;
706 }
707 int EditOutPoint::keypress_event()
708 {
709         int key = get_keypress();
710         if( ctrl_down() ) {
711                 if(  key == 't' ) {
712                         panel->panel_unset_inoutpoint();
713                         return 1;
714                 }
715         }
716         else if( !alt_down() ) {
717                 if( key == ']' || key == '>' ) {
718                         panel->panel_set_outpoint();
719                         return 1;
720                 }
721         }
722         return 0;
723 }
724
725 //splice_selection
726 EditSplice::EditSplice(MWindow *mwindow, EditPanel *panel, int x, int y)
727  : BC_Button(x, y, mwindow->theme->splice_data)
728 {
729         this->mwindow = mwindow;
730         this->panel = panel;
731         set_tooltip(_("Splice ( v )"));
732 }
733 EditSplice::~EditSplice()
734 {
735 }
736 int EditSplice::handle_event()
737 {
738         panel->panel_splice_selection();
739         return 1;
740 }
741 int EditSplice::keypress_event()
742 {
743         if( alt_down() ) return 0;
744         if( (get_keypress() == 'v' && !ctrl_down()) ||
745             (panel->is_vwindow() && get_keypress() == 'V') ) {
746                 handle_event();
747                 return 1;
748         }
749         return 0;
750 }
751
752 //to_clip
753 EditToClip::EditToClip(MWindow *mwindow, EditPanel *panel, int x, int y)
754  : BC_Button(x, y, mwindow->theme->get_image_set("toclip"))
755 {
756         this->mwindow = mwindow;
757         this->panel = panel;
758         set_tooltip(_("To clip ( i )"));
759 }
760 EditToClip::~EditToClip()
761 {
762 }
763 int EditToClip::handle_event()
764 {
765         panel->panel_to_clip();
766         return 1;
767 }
768
769 int EditToClip::keypress_event()
770 {
771         if( alt_down() ) return 0;
772         if( get_keypress() == 'i' ||
773             (panel->is_vwindow() && get_keypress() == 'I') ) {
774                 handle_event();
775                 return 1;
776         }
777         return 0;
778 }
779
780 //cut
781 EditCut::EditCut(MWindow *mwindow, EditPanel *panel, int x, int y)
782  : BC_Button(x, y, mwindow->theme->get_image_set("cut"))
783 {
784         this->mwindow = mwindow;
785         this->panel = panel;
786         set_tooltip(_("Split | Cut ( x )"));
787 }
788 EditCut::~EditCut()
789 {
790 }
791 int EditCut::keypress_event()
792 {
793         if( ctrl_down() || shift_down() || alt_down() )
794                 return 0;
795         if( get_keypress() == 'x' )
796                 return handle_event();
797         return 0;
798 }
799
800 int EditCut::handle_event()
801 {
802         panel->panel_cut();
803         return 1;
804 }
805
806 //paste
807 EditPaste::EditPaste(MWindow *mwindow, EditPanel *panel, int x, int y)
808  : BC_Button(x, y, mwindow->theme->get_image_set("paste"))
809 {
810         this->mwindow = mwindow;
811         this->panel = panel;
812         set_tooltip(_("Paste ( v )"));
813 }
814 EditPaste::~EditPaste()
815 {
816 }
817
818 int EditPaste::keypress_event()
819 {
820         if( get_keypress() == 'v' && !ctrl_down() )
821                 return handle_event();
822         return 0;
823 }
824 int EditPaste::handle_event()
825 {
826         panel->panel_paste();
827         return 1;
828 }
829
830 //fit_selection
831 EditFit::EditFit(MWindow *mwindow, EditPanel *panel, int x, int y)
832  : BC_Button(x, y, mwindow->theme->get_image_set("fit"))
833 {
834         this->mwindow = mwindow;
835         this->panel = panel;
836         set_tooltip(_("Fit selection to display ( f )"));
837 }
838 EditFit::~EditFit()
839 {
840 }
841 int EditFit::keypress_event()
842 {
843         if( !alt_down() && get_keypress() == 'f' ) {
844                 handle_event();
845                 return 1;
846         }
847         return 0;
848 }
849 int EditFit::handle_event()
850 {
851         panel->panel_fit_selection();
852         return 1;
853 }
854
855 //fit_autos
856 EditFitAutos::EditFitAutos(MWindow *mwindow, EditPanel *panel, int x, int y)
857  : BC_Button(x, y, mwindow->theme->get_image_set("fitautos"))
858 {
859         this->mwindow = mwindow;
860         this->panel = panel;
861         set_tooltip(_("Fit all autos to display ( Alt + f )"));
862 }
863 EditFitAutos::~EditFitAutos()
864 {
865 }
866 int EditFitAutos::keypress_event()
867 {
868         if( get_keypress() == 'f' && alt_down() ) {
869                 panel->panel_fit_autos(!ctrl_down() ? 1 : 0);
870                 return 1;
871         }
872         return 0;
873 }
874 int EditFitAutos::handle_event()
875 {
876         panel->panel_fit_autos(1);
877         return 1;
878 }
879
880 //set_editing_mode
881 ArrowButton::ArrowButton(MWindow *mwindow, EditPanel *panel, int x, int y)
882  : BC_Toggle(x, y,
883         mwindow->theme->get_image_set("arrow"),
884         mwindow->edl->session->editing_mode == EDITING_ARROW,
885         "", 0, 0, 0)
886 {
887         this->mwindow = mwindow;
888         this->panel = panel;
889         set_tooltip(_("Drag and drop editing mode"));
890 }
891
892 int ArrowButton::handle_event()
893 {
894         update(1);
895         panel->ibeam->update(0);
896         panel->panel_set_editing_mode(EDITING_ARROW);
897 // Nothing after this
898         return 1;
899 }
900
901 IBeamButton::IBeamButton(MWindow *mwindow, EditPanel *panel, int x, int y)
902  : BC_Toggle(x, y,
903         mwindow->theme->get_image_set("ibeam"),
904         mwindow->edl->session->editing_mode == EDITING_IBEAM,
905         "", 0, 0, 0)
906 {
907         this->mwindow = mwindow;
908         this->panel = panel;
909         set_tooltip(_("Cut and paste editing mode"));
910 }
911
912 int IBeamButton::handle_event()
913 {
914         update(1);
915         panel->arrow->update(0);
916         panel->panel_set_editing_mode(EDITING_IBEAM);
917 // Nothing after this
918         return 1;
919 }
920
921 //set_auto_keyframes
922 KeyFrameButton::KeyFrameButton(MWindow *mwindow, EditPanel *panel, int x, int y)
923  : BC_Toggle(x, y,
924         mwindow->theme->get_image_set("autokeyframe"),
925         mwindow->edl->session->auto_keyframes,
926         "", 0, 0, 0)
927 {
928         this->mwindow = mwindow;
929         this->panel = panel;
930         set_tooltip(_("Generate keyframes while tweeking (j)"));
931 }
932
933 int KeyFrameButton::handle_event()
934 {
935         panel->panel_set_auto_keyframes(get_value());
936         return 1;
937 }
938
939 int KeyFrameButton::keypress_event()
940 {
941         int key = get_keypress();
942         if( key == 'j' && !ctrl_down() && !shift_down() && !alt_down() ) {
943                 int value = get_value() ? 0 : 1;
944                 update(value);
945                 panel->panel_set_auto_keyframes(value);
946                 return 1;
947         }
948         return 0;
949 }
950
951 //set_span_keyframes
952 SpanKeyFrameButton::SpanKeyFrameButton(MWindow *mwindow, EditPanel *panel, int x, int y)
953  : BC_Toggle(x, y,
954         mwindow->theme->get_image_set("spankeyframe"),
955         mwindow->edl->session->span_keyframes,
956         "", 0, 0, 0)
957 {
958         this->mwindow = mwindow;
959         this->panel = panel;
960         set_tooltip(_("Allow keyframe spanning"));
961 }
962
963 int SpanKeyFrameButton::handle_event()
964 {
965         panel->panel_set_span_keyframes(get_value());
966         return 1;
967 }
968
969 //set_labels_follow_edits
970 LockLabelsButton::LockLabelsButton(MWindow *mwindow, EditPanel *panel, int x, int y)
971  : BC_Toggle(x, y,
972         mwindow->theme->get_image_set("locklabels"),
973         mwindow->edl->session->labels_follow_edits,
974         "", 0, 0, 0)
975 {
976         this->mwindow = mwindow;
977         this->panel = panel;
978         set_tooltip(_("Lock labels from moving with edits"));
979 }
980
981 int LockLabelsButton::handle_event()
982 {
983         panel->panel_set_labels_follow_edits(get_value());
984         return 1;
985 }
986
987
988
989 EditManualGoto::EditManualGoto(MWindow *mwindow, EditPanel *panel, int x, int y)
990  : BC_Button(x, y, mwindow->theme->get_image_set("goto"))
991 {
992         this->mwindow = mwindow;
993         this->panel = panel;
994         mangoto = new ManualGoto(mwindow, panel);
995         set_tooltip(_("Manual goto ( g )"));
996 }
997 EditManualGoto::~EditManualGoto()
998 {
999         delete mangoto;
1000 }
1001 int EditManualGoto::handle_event()
1002 {
1003         mangoto->start();
1004         return 1;
1005 }
1006
1007 int EditManualGoto::keypress_event()
1008 {
1009         if( get_keypress() == 'g' ) {
1010                 handle_event();
1011                 return 1;
1012         }
1013         return 0;
1014 }
1015
1016
1017 EditClick2Play::EditClick2Play(MWindow *mwindow, EditPanel *panel, int x, int y)
1018  : BC_Toggle(x, y, mwindow->theme->get_image_set("playpatch_data"),
1019     !panel->is_vwindow() ?
1020         mwindow->edl->session->cwindow_click2play :
1021         mwindow->edl->session->vwindow_click2play)
1022 {
1023         this->mwindow = mwindow;
1024         this->panel = panel;
1025         set_tooltip(_("Click to play (p)"));
1026 }
1027 int EditClick2Play::handle_event()
1028 {
1029         int value = get_value();
1030         panel->set_click_to_play(value);
1031         return 1;
1032 }
1033 int EditClick2Play::keypress_event()
1034 {
1035         int key = get_keypress();
1036         if( key == 'p' && !ctrl_down() && !shift_down() && !alt_down() ) {
1037                 int value = get_value() ? 0 : 1;
1038                 update(value);
1039                 panel->set_click_to_play(value);
1040                 return 1;
1041         }
1042         return 0;
1043 }
1044
1045
1046 EditCommercial::EditCommercial(MWindow *mwindow, EditPanel *panel, int x, int y)
1047  : BC_Button(x, y, mwindow->theme->get_image_set("commercial"))
1048 {
1049         this->mwindow = mwindow;
1050         this->panel = panel;
1051         set_tooltip(_("Commercial ( shift A )"));
1052 }
1053 EditCommercial::~EditCommercial()
1054 {
1055 }
1056 int EditCommercial::keypress_event()
1057 {
1058         if( ctrl_down() || !shift_down() || alt_down() )
1059                 return 0;
1060         if( get_keypress() == 'A' )
1061                 return handle_event();
1062         return 0;
1063 }
1064
1065 int EditCommercial::handle_event()
1066 {
1067         int have_mwindow_lock = mwindow->gui->get_window_lock();
1068         if( have_mwindow_lock )
1069                 mwindow->gui->unlock_window();
1070         mwindow->commit_commercial();
1071         if( !mwindow->put_commercial() ) {
1072                 mwindow->gui->lock_window("EditCommercial::handle_event 1");
1073                 mwindow->cut();
1074                 if( !have_mwindow_lock )
1075                         mwindow->gui->unlock_window();
1076                 mwindow->activate_commercial();
1077                 return 1;
1078         }
1079         mwindow->undo_commercial();
1080         if( have_mwindow_lock )
1081                 mwindow->gui->lock_window("EditCommercial::handle_event 2");
1082         return 1;
1083 }
1084
1085
1086 EditUndo::EditUndo(MWindow *mwindow, EditPanel *panel, int x, int y)
1087  : BC_Button(x, y, mwindow->theme->get_image_set("undo"))
1088 {
1089         this->mwindow = mwindow;
1090         this->panel = panel;
1091         set_tooltip(_("Undo ( z )"));
1092 }
1093 EditUndo::~EditUndo()
1094 {
1095 }
1096 int EditUndo::keypress_event()
1097 {
1098         if( ctrl_down() || shift_down() || alt_down() )
1099                 return 0;
1100         if( get_keypress() == 'z' )
1101                 return handle_event();
1102         return 0;
1103 }
1104 int EditUndo::handle_event()
1105 {
1106         mwindow->undo_entry(panel->subwindow);
1107         return 1;
1108 }
1109
1110 EditRedo::EditRedo(MWindow *mwindow, EditPanel *panel, int x, int y)
1111  : BC_Button(x, y, mwindow->theme->get_image_set("redo"))
1112 {
1113         this->mwindow = mwindow;
1114         this->panel = panel;
1115         set_tooltip(_("Redo ( shift Z )"));
1116 }
1117 EditRedo::~EditRedo()
1118 {
1119 }
1120 int EditRedo::keypress_event()
1121 {
1122         if( ctrl_down() || !shift_down() || alt_down() )
1123                 return 0;
1124         if( get_keypress() == 'Z' )
1125                 return handle_event();
1126         return 0;
1127 }
1128 int EditRedo::handle_event()
1129 {
1130         mwindow->redo_entry(panel->subwindow);
1131         return 1;
1132 }
1133