version update, Features5 update, proxy tweak
[goodguy/history.git] / cinelerra-5.1 / cinelerra / timebar.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 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 "bcsignals.h"
23 #include "clip.h"
24 #include "cplayback.h"
25 #include "cursors.h"
26 #include "cwindow.h"
27 #include "cwindowgui.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "filexml.h"
31 #include "fonts.h"
32 #include "labels.h"
33 #include "labeledit.h"
34 #include "localsession.h"
35 #include "maincursor.h"
36 #include "mainundo.h"
37 #include "mbuttons.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "patchbay.h"
41 #include "preferences.h"
42 #include "recordlabel.h"
43 #include "localsession.h"
44 #include "mainsession.h"
45 #include "theme.h"
46 #include "timebar.h"
47 #include "timelinepane.h"
48 #include "trackcanvas.h"
49 #include "tracks.h"
50 #include "transportque.h"
51 #include "units.h"
52 #include "vframe.h"
53 #include "vwindow.h"
54 #include "vwindowgui.h"
55 #include "zoombar.h"
56
57
58 LabelGUI::LabelGUI(MWindow *mwindow, TimeBar *timebar,
59         int64_t pixel, int y,
60         double position, VFrame **data)
61  : BC_Toggle(translate_pixel(mwindow, pixel), y,
62                 data ? data : mwindow->theme->label_toggle, 0)
63 {
64         this->mwindow = mwindow;
65         this->timebar = timebar;
66         this->gui = 0;
67         this->pixel = pixel;
68         this->position = position;
69         this->label = 0;
70 }
71
72 LabelGUI::~LabelGUI()
73 {
74 }
75
76 int LabelGUI::get_y(MWindow *mwindow, TimeBar *timebar)
77 {
78         return timebar->get_h() -
79                 mwindow->theme->label_toggle[0]->get_h();
80 }
81
82 int LabelGUI::translate_pixel(MWindow *mwindow, int pixel)
83 {
84         int result = pixel - mwindow->theme->label_toggle[0]->get_w() / 2;
85         return result;
86 }
87
88 void LabelGUI::reposition(int flush)
89 {
90         reposition_window(translate_pixel(mwindow, pixel),
91                 BC_Toggle::get_y());
92 }
93
94 int LabelGUI::button_press_event()
95 {
96         int result = 0;
97
98         if( this->is_event_win() && get_buttonpress() == 3 ) {
99                 if( label ) {
100                         int cur_x, cur_y;
101                         get_abs_cursor(cur_x, cur_y, 0);
102                         timebar->label_edit->start(label, cur_x, cur_y);
103                 }
104                 result = 1;
105         } else {
106                 result = BC_Toggle::button_press_event();
107         }
108         if( label )
109                 set_tooltip(this->label->textstr);
110         return result;
111 }
112
113 int LabelGUI::handle_event()
114 {
115         timebar->select_label(position);
116         return 1;
117 }
118
119
120 InPointGUI::InPointGUI(MWindow *mwindow, TimeBar *timebar,
121         int64_t pixel, double position)
122  : LabelGUI(mwindow, timebar,
123         pixel, get_y(mwindow, timebar),
124         position, mwindow->theme->in_point)
125 {
126 //printf("InPointGUI::InPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
127 }
128 InPointGUI::~InPointGUI()
129 {
130 }
131 int InPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
132 {
133         int result;
134         result = timebar->get_h() -
135                 mwindow->theme->in_point[0]->get_h();
136         return result;
137 }
138
139
140 OutPointGUI::OutPointGUI(MWindow *mwindow, TimeBar *timebar,
141         int64_t pixel, double position)
142  : LabelGUI(mwindow, timebar,
143         pixel, get_y(mwindow, timebar),
144         position, mwindow->theme->out_point)
145 {
146 //printf("OutPointGUI::OutPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
147 }
148 OutPointGUI::~OutPointGUI()
149 {
150 }
151 int OutPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
152 {
153         return timebar->get_h() -
154                 mwindow->theme->out_point[0]->get_h();
155 }
156
157
158 PresentationGUI::PresentationGUI(MWindow *mwindow, TimeBar *timebar,
159         int64_t pixel, double position)
160  : LabelGUI(mwindow, timebar, pixel, get_y(mwindow, timebar), position)
161 {
162 }
163 PresentationGUI::~PresentationGUI()
164 {
165 }
166
167 TimeBar::TimeBar(MWindow *mwindow, BC_WindowBase *gui,
168         int x, int y, int w, int h)
169  : BC_SubWindow(x, y, w, h)
170 {
171 //printf("TimeBar::TimeBar %d %d %d %d\n", x, y, w, h);
172         this->gui = gui;
173         this->mwindow = mwindow;
174         label_edit = new LabelEdit(mwindow, mwindow->awindow, 0);
175         pane = 0;
176         highlighted = 0;
177 }
178
179 TimeBar::~TimeBar()
180 {
181         delete in_point;
182         delete out_point;
183         delete label_edit;
184         labels.remove_all_objects();
185         presentations.remove_all_objects();
186 }
187
188 void TimeBar::create_objects()
189 {
190         in_point = 0;
191         out_point = 0;
192 //printf("TimeBar::create_objects %d\n", __LINE__);
193         current_operation = TIMEBAR_NONE;
194         set_cursor(UPRIGHT_ARROW_CURSOR, 0, 0);
195         update(0);
196 }
197
198
199 int64_t TimeBar::position_to_pixel(double position)
200 {
201         get_edl_length();
202         return (int64_t)(position / time_per_pixel);
203 }
204
205
206 double TimeBar::pixel_to_position(int pixel)
207 {
208         if( pane ) {
209                 pixel += get_edl()->local_session->view_start[pane->number];
210         }
211
212         return (double)pixel *
213                 get_edl()->local_session->zoom_sample /
214                 get_edl()->session->sample_rate;
215 }
216
217 void TimeBar::update_labels()
218 {
219         int output = 0;
220         EDL *edl = get_edl();
221
222         if( edl ) {
223                 for( Label *current=edl->labels->first; current; current=NEXT ) {
224                         int64_t pixel = position_to_pixel(current->position);
225                         if( pixel >= 0 && pixel < get_w()  ) {
226 // Create new label
227                                 if( output >= labels.total ) {
228                                         LabelGUI *new_label;
229                                         add_subwindow(new_label =
230                                                 new LabelGUI(mwindow,
231                                                         this,
232                                                         pixel,
233                                                         LabelGUI::get_y(mwindow, this),
234                                                         current->position));
235                                         new_label->set_cursor(INHERIT_CURSOR, 0, 0);
236                                         new_label->set_tooltip(current->textstr);
237                                         new_label->label = current;
238                                         labels.append(new_label);
239                                 }
240                                 else
241 // Reposition old label
242                                 {
243                                         LabelGUI *gui = labels.values[output];
244                                         if( gui->pixel != pixel ) {
245                                                 gui->pixel = pixel;
246                                                 gui->reposition(0);
247                                         }
248                                         else {
249                                                 gui->draw_face(1,0);
250                                         }
251
252                                         labels.values[output]->position = current->position;
253                                         labels.values[output]->set_tooltip(current->textstr);
254                                         labels.values[output]->label = current;
255                                 }
256
257                                 if( edl->local_session->get_selectionstart(1) <= current->position &&
258                                     edl->local_session->get_selectionend(1) >= current->position )
259                                         labels.values[output]->update(1);
260                                 else
261                                 if( labels.values[output]->get_value() )
262                                         labels.values[output]->update(0);
263
264                                 output++;
265                         }
266                 }
267         }
268
269 // Delete excess labels
270         while(labels.total > output)
271         {
272                 labels.remove_object();
273         }
274
275 // Get the labels to show
276         show_window(0);
277 }
278
279 void TimeBar::update_highlights()
280 {
281         EDL *edl = get_edl();
282         if( !edl ) return;
283         for( int i = 0; i < labels.total; i++ ) {
284                 LabelGUI *label = labels.values[i];
285                 if( edl->equivalent(label->position,
286                                 edl->local_session->get_selectionstart(1)) ||
287                     edl->equivalent(label->position,
288                                 edl->local_session->get_selectionend(1)) ) {
289                         if( !label->get_value() ) label->update(1);
290                 }
291                 else
292                         if( label->get_value() ) label->update(0);
293         }
294
295         if( edl->equivalent(edl->local_session->get_inpoint(),
296                         edl->local_session->get_selectionstart(1)) ||
297                 edl->equivalent(edl->local_session->get_inpoint(),
298                         edl->local_session->get_selectionend(1)) ) {
299                 if( in_point ) in_point->update(1);
300         }
301         else
302                 if( in_point ) in_point->update(0);
303
304         if( edl->equivalent(edl->local_session->get_outpoint(),
305                         edl->local_session->get_selectionstart(1)) ||
306                 edl->equivalent(edl->local_session->get_outpoint(),
307                         edl->local_session->get_selectionend(1)) ) {
308                 if( out_point ) out_point->update(1);
309         }
310         else
311                 if( out_point ) out_point->update(0);
312 }
313
314 void TimeBar::update_points()
315 {
316         EDL *edl = get_edl();
317         int64_t pixel = !edl ? 0 :
318                 position_to_pixel(edl->local_session->get_inpoint());
319
320         if( in_point ) {
321                 if( edl && edl->local_session->inpoint_valid() &&
322                     pixel >= 0 && pixel < get_w() ) {
323                         if( !EQUIV(edl->local_session->get_inpoint(), in_point->position) ||
324                             in_point->pixel != pixel ) {
325                                 in_point->pixel = pixel;
326                                 in_point->position = edl->local_session->get_inpoint();
327                                 in_point->reposition(0);
328                         }
329                         else {
330                                 in_point->draw_face(1, 0);
331                         }
332                 }
333                 else {
334                         delete in_point;
335                         in_point = 0;
336                 }
337         }
338         else
339         if( edl && edl->local_session->inpoint_valid() &&
340             pixel >= 0 && pixel < get_w() ) {
341                 add_subwindow(in_point = new InPointGUI(mwindow,
342                         this, pixel, edl->local_session->get_inpoint()));
343                 in_point->set_cursor(ARROW_CURSOR, 0, 0);
344         }
345
346         pixel = !edl ? 0 :
347                  position_to_pixel(edl->local_session->get_outpoint());
348
349         if( out_point ) {
350                 if( edl && edl->local_session->outpoint_valid() &&
351                     pixel >= 0 && pixel < get_w()) {
352                         if( !EQUIV(edl->local_session->get_outpoint(), out_point->position) ||
353                             out_point->pixel != pixel ) {
354                                 out_point->pixel = pixel;
355                                 out_point->position = edl->local_session->get_outpoint();
356                                 out_point->reposition(0);
357                         }
358                         else {
359                                 out_point->draw_face(1, 0);
360                         }
361                 }
362                 else {
363                         delete out_point;
364                         out_point = 0;
365                 }
366         }
367         else
368         if( edl && edl->local_session->outpoint_valid() &&
369             pixel >= 0 && pixel < get_w() ) {
370                 add_subwindow(out_point = new OutPointGUI(mwindow,
371                         this, pixel, edl->local_session->get_outpoint()));
372                 out_point->set_cursor(ARROW_CURSOR, 0, 0);
373         }
374
375 //      flush();
376 }
377
378 void TimeBar::update_clock(double position)
379 {
380 }
381
382 void TimeBar::update(int flush)
383 {
384         draw_time();
385 // Need to redo these when range is drawn to get the background updated.
386         update_labels();
387         update_points();
388
389
390         EDL *edl = get_edl();
391         int64_t pixel = -1;
392         int x = get_relative_cursor_x();
393 // Draw highlight position
394         if( edl && (highlighted || current_operation == TIMEBAR_DRAG) &&
395             x >= 0 && x < get_w() ) {
396 //printf("TimeBar::update %d %d\n", __LINE__, x);
397                 double position = pixel_to_position(x);
398
399                 position = mwindow->edl->align_to_frame(position, 0);
400                 pixel = position_to_pixel(position);
401                 update_clock(position);
402         }
403
404         if( pixel < 0 ) {
405                 double position = test_highlight();
406                 if( position >= 0 ) pixel = position_to_pixel(position);
407         }
408
409
410         if( pixel >= 0 && pixel < get_w() ) {
411                 set_color(mwindow->theme->timebar_cursor_color);
412                 set_line_dashes(1);
413 //printf("TimeBar::update %d pane=%d pixel=%jd\n", __LINE__, pane->number, pixel);
414                 draw_line(pixel, 0, pixel, get_h());
415                 set_line_dashes(0);
416         }
417
418
419         if( edl ) {
420                 double playback_start = edl->local_session->playback_start;
421                 if( playback_start >= 0 ) {
422                         int64_t pixel = position_to_pixel(playback_start);
423                         set_color(mwindow->theme->timebar_cursor_color ^ 0x0000ff);
424                         draw_line(pixel, 0, pixel, get_h());
425                         double playback_end = edl->local_session->playback_end;
426                         if( playback_end > playback_start ) {
427                                 pixel = position_to_pixel(playback_end);
428                                 set_color(mwindow->theme->timebar_cursor_color ^ 0x00ff00);
429                                 draw_line(pixel, 0, pixel, get_h());
430                         }
431                 }
432
433                 double position = edl->local_session->get_selectionstart(1);
434                 int64_t pixel = position_to_pixel(position);
435 // Draw insertion point position.
436                 int color = mwindow->theme->timebar_cursor_color;
437                 if( mwindow->preferences->forward_render_displacement )
438                         color ^= 0x00ffff;
439                 set_color(color);
440                 draw_line(pixel, 0, pixel, get_h());
441         }
442
443         update_highlights();
444
445 // Get the labels to show
446         show_window(0);
447         flash(flush);
448 //printf("TimeBar::update %d this=%p %d\n", __LINE__, this, current_operation);
449 }
450
451
452
453 int TimeBar::delete_project()
454 {
455 //      labels->delete_all();
456         return 0;
457 }
458
459 int TimeBar::save(FileXML *xml)
460 {
461 //      labels->save(xml);
462         return 0;
463 }
464
465
466
467
468 void TimeBar::draw_time()
469 {
470 }
471
472 EDL* TimeBar::get_edl()
473 {
474         return mwindow->edl;
475 }
476
477
478
479 void TimeBar::draw_range()
480 {
481
482
483 //printf("TimeBar::draw_range %d %p\n", __LINE__, get_edl());
484         if( has_preview() && get_edl() ) {
485                 int x1, x2;
486                 get_preview_pixels(x1, x2);
487
488 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
489                 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
490                 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
491                 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
492
493                 set_color(BLACK);
494                 draw_line(x1, 0, x1, get_h());
495                 draw_line(x2, 0, x2, get_h());
496
497
498                 EDL *edl = get_edl();
499                 if( edl ) {
500                         int64_t pixel = position_to_pixel(
501                                 edl->local_session->get_selectionstart(1));
502 // Draw insertion point position if this timebar belongs to a window which
503 // has something other than the master EDL.
504                         set_color(mwindow->theme->timebar_cursor_color);
505                         draw_line(pixel, 0, pixel, get_h());
506                 }
507         }
508         else
509                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
510 }
511
512 void TimeBar::select_label(double position)
513 {
514 }
515
516
517
518 int TimeBar::draw()
519 {
520         return 0;
521 }
522
523 double TimeBar::get_edl_length()
524 {
525         edl_length = get_edl() ? get_edl()->tracks->total_length() : 0;
526         int w1 = get_w()-1;
527         time_per_pixel = !EQUIV(edl_length, 0) ? edl_length/w1 : w1;
528         return edl_length;
529 }
530
531 int TimeBar::get_preview_pixels(int &x1, int &x2)
532 {
533         x1 = 0;  x2 = get_w();
534         get_edl_length();
535         EDL *edl = get_edl();
536         if( edl && !EQUIV(edl_length, 0) ) {
537                 double preview_start = edl->local_session->preview_start;
538                 double preview_end = edl->local_session->preview_end;
539                 if( preview_end < 0 || preview_end > edl_length )
540                         preview_end = edl_length;
541                 if( preview_end >= preview_start ) {
542                         x1 = (int)(preview_start / time_per_pixel);
543                         x2 = (int)(preview_end / time_per_pixel);
544                 }
545         }
546         return 0;
547 }
548
549
550 int TimeBar::test_preview(int buttonpress)
551 {
552         int result = 0;
553
554
555         if( get_edl() && cursor_inside() && buttonpress >= 0 ) {
556                 int x1, x2, x = get_relative_cursor_x();
557                 get_preview_pixels(x1, x2);
558 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, x);
559 // Inside left handle
560                 if( x >= x1 - HANDLE_W && x < x1 + HANDLE_W &&
561 // Ignore left handle if both handles are up against the left side
562                     x2 > HANDLE_W ) {
563                         if( buttonpress ) {
564                                 current_operation = TIMEBAR_DRAG_LEFT;
565                                 start_position = get_edl()->local_session->preview_start;
566                                 start_cursor_x = x;
567                         }
568                         else if( get_cursor() != LEFT_CURSOR )
569                                 set_cursor(LEFT_CURSOR, 0, 1);
570                         result = 1;
571                 }
572 // Inside right handle
573                 else if( x >= x2 - HANDLE_W && x < x2 + HANDLE_W &&
574 // Ignore right handle if both handles are up against the right side
575                     x1 < get_w() - HANDLE_W ) {
576                         if( buttonpress ) {
577                                 current_operation = TIMEBAR_DRAG_RIGHT;
578                                 start_position = get_edl()->local_session->preview_end;
579                                 if( start_position < 0 || start_position > edl_length )
580                                         start_position = edl_length;
581                                 start_cursor_x = x;
582                         }
583                         else if( get_cursor() != RIGHT_CURSOR )
584                                 set_cursor(RIGHT_CURSOR, 0, 1);
585                         result = 1;
586                 }
587 // Inside preview
588                 else if( get_button_down() && get_buttonpress() == 3 &&
589                     x >= x1 && x < x2 ) {
590                         if( buttonpress ) {
591                                 current_operation = TIMEBAR_DRAG_CENTER;
592                                 starting_start_position = get_edl()->local_session->preview_start;
593                                 starting_end_position = get_edl()->local_session->preview_end;
594                                 if( starting_end_position < 0 || starting_end_position > edl_length )
595                                         starting_end_position = edl_length;
596                                 start_cursor_x = x;
597                         }
598                         if( get_cursor() != HSEPARATE_CURSOR )
599                                 set_cursor(HSEPARATE_CURSOR, 0, 1);
600                         result = 1;
601                 }
602         }
603
604         if( !result && get_cursor() != ARROW_CURSOR )
605                 set_cursor(ARROW_CURSOR, 0, 1);
606
607
608         return result;
609 }
610
611 int TimeBar::move_preview(int &redraw)
612 {
613         int result = 0, x = get_relative_cursor_x();
614         switch( current_operation ) {
615         case TIMEBAR_DRAG_LEFT: {
616                 get_edl()->local_session->preview_start =
617                         start_position + time_per_pixel * (x - start_cursor_x);
618                 double preview_end = get_edl()->local_session->preview_end;
619                 if( preview_end < 0 || preview_end > edl_length )
620                         preview_end = get_edl()->local_session->preview_end = edl_length;
621                 CLAMP(get_edl()->local_session->preview_start, 0, preview_end);
622                 result = 1;
623                 break; }
624         case TIMEBAR_DRAG_RIGHT: {
625                 double preview_end = get_edl()->local_session->preview_end =
626                         start_position + time_per_pixel * (x - start_cursor_x);
627                 double preview_start = get_edl()->local_session->preview_start;
628                 if( preview_end >= edl_length && !preview_start ) {
629                         get_edl()->local_session->preview_end = -1;
630                         if( preview_start > preview_end )
631                                 preview_start = get_edl()->local_session->preview_start = preview_end;
632                 }
633                 else
634                         CLAMP(get_edl()->local_session->preview_end, preview_start, edl_length);
635                 result = 1;
636                 break; }
637         case TIMEBAR_DRAG_CENTER: {
638                 double dt = time_per_pixel * (x - start_cursor_x);
639                 get_edl()->local_session->preview_start = starting_start_position + dt;
640                 get_edl()->local_session->preview_end = starting_end_position + dt;
641                 if( get_edl()->local_session->preview_start < 0 ) {
642                         get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
643                         get_edl()->local_session->preview_start = 0;
644                 }
645                 else
646                 if( get_edl()->local_session->preview_end > edl_length ) {
647                         get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
648                         get_edl()->local_session->preview_end = edl_length;
649                 }
650                 result = 1;
651                 break; }
652         }
653
654 //printf("TimeBar::move_preview %d %d\n", __LINE__, current_operation);
655
656         if( result ) {
657                 update_preview();
658                 redraw = 1;
659         }
660 //printf("TimeBar::move_preview %d %d\n", __LINE__, current_operation);
661
662         return result;
663 }
664
665 void TimeBar::update_preview()
666 {
667 }
668
669 int TimeBar::samplemovement()
670 {
671         return 0;
672 }
673
674 void TimeBar::stop_playback()
675 {
676 }
677
678 int TimeBar::button_press_event()
679 {
680         int result = 0;
681         if( is_event_win() && cursor_above() ) {
682                 if( has_preview() && get_buttonpress() == 3 ) {
683                         result = test_preview(1);
684                 }
685 // Change time format
686                 else if( ctrl_down() ) {
687                         if( get_buttonpress() == 1 )
688                                 mwindow->next_time_format();
689                         else
690                         if( get_buttonpress() == 2 )
691                                 mwindow->prev_time_format();
692                         result = 1;
693                 }
694                 else if( get_buttonpress() == 1 ) {
695                         stop_playback();
696
697 // Select region between two labels
698                         if( !is_vwindow() && get_double_click() ) {
699                                 int x = get_relative_cursor_x();
700                                 double position = pixel_to_position(x);
701 // Test labels
702                                 select_region(position);
703                         }
704                         else {
705
706 // Reposition highlight cursor
707                                 update_cursor();
708                                 current_operation = TIMEBAR_DRAG;
709                                 activate_timeline();
710                         }
711                         result = 1;
712                 }
713         }
714         return result;
715 }
716
717 void TimeBar::activate_timeline()
718 {
719         mwindow->gui->activate_timeline();
720 }
721
722 int TimeBar::cursor_motion_event()
723 {
724         int result = 0;
725         int redraw = 0;
726
727 //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation);
728         switch( current_operation )
729         {
730                 case TIMEBAR_DRAG:
731                 {
732                         update_cursor();
733                         handle_mwindow_drag();
734                         result = 1;
735 //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation);
736                         break;
737                 }
738
739
740                 case TIMEBAR_DRAG_LEFT:
741                 case TIMEBAR_DRAG_RIGHT:
742                 case TIMEBAR_DRAG_CENTER:
743                         if( has_preview() )
744                                 result = move_preview(redraw);
745                         break;
746
747                 default:
748                         if( cursor_above() ) {
749                                 highlighted = 1;
750                                 redraw = 1;
751                         }
752
753 //printf("TimeBar::cursor_motion_event 20\n");
754                         if( has_preview() )
755                                 result = test_preview(0);
756 //printf("TimeBar::cursor_motion_event 30\n");
757                         break;
758         }
759
760
761 //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation);
762         if( redraw ) {
763                 update(1);
764         }
765 //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation);
766
767         return result;
768 }
769
770 int TimeBar::cursor_leave_event()
771 {
772         if( highlighted ) {
773                 highlighted = 0;
774                 update(1);
775         }
776         return 0;
777 }
778
779 int TimeBar::button_release_event()
780 {
781 //printf("TimeBar::button_release_event %d %d\n", __LINE__, current_operation);
782         int result = 0;
783         int need_redraw = 0;
784         switch( current_operation )
785         {
786                 case TIMEBAR_DRAG:
787                         mwindow->gui->get_focused_pane()->canvas->stop_dragscroll();
788                         current_operation = TIMEBAR_NONE;
789                         need_redraw = 1;
790                         result = 1;
791                         break;
792
793                 default:
794                         if( current_operation != TIMEBAR_NONE ) {
795                                 current_operation = TIMEBAR_NONE;
796                                 result = 1;
797                         }
798                         break;
799         }
800
801         if( (!cursor_above() && highlighted) || need_redraw ) {
802                 highlighted = 0;
803                 update(1);
804         }
805
806         return result;
807 }
808
809 // Update the selection cursor during a dragging operation
810 void TimeBar::update_cursor()
811 {
812 }
813
814 void TimeBar::handle_mwindow_drag()
815 {
816 }
817
818 int TimeBar::select_region(double position)
819 {
820         Label *start = 0, *end = 0, *current;
821         for( current = get_edl()->labels->first; current; current = NEXT ) {
822                 if( current->position > position ) {
823                         end = current;
824                         break;
825                 }
826         }
827
828         for( current = get_edl()->labels->last ; current; current = PREVIOUS ) {
829                 if( current->position <= position ) {
830                         start = current;
831                         break;
832                 }
833         }
834
835 // Select region
836         if( end != start ) {
837                 if( !start )
838                         get_edl()->local_session->set_selectionstart(0);
839                 else
840                         get_edl()->local_session->set_selectionstart(start->position);
841
842                 if( !end )
843                         get_edl()->local_session->set_selectionend(get_edl()->tracks->total_length());
844                 else
845                         get_edl()->local_session->set_selectionend(end->position);
846         }
847         else
848         if( end || start ) {
849                 get_edl()->local_session->set_selectionstart(start->position);
850                 get_edl()->local_session->set_selectionend(start->position);
851         }
852
853 // Que the CWindow
854         mwindow->cwindow->gui->lock_window("TimeBar::select_region");
855         mwindow->cwindow->update(1, 0, 0);
856         mwindow->cwindow->gui->unlock_window();
857         mwindow->gui->lock_window("TimeBar::select_region");
858         mwindow->gui->hide_cursor(0);
859         mwindow->gui->draw_cursor(1);
860         mwindow->gui->flash_canvas(0);
861         mwindow->gui->activate_timeline();
862         mwindow->gui->zoombar->update();
863         mwindow->gui->unlock_window();
864         update_highlights();
865         return 0;
866 }
867
868
869
870
871 int TimeBar::delete_arrows()
872 {
873         return 0;
874 }
875
876 double TimeBar::test_highlight()
877 {
878         return -1;
879 }
880
881