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