add deselect to editpopup menu, drag edit select/deselect
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindowgui.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 "androidcontrol.h"
23 #include "awindowgui.h"
24 #include "awindow.h"
25 #include "bcdisplayinfo.h"
26 #include "bchash.h"
27 #include "bcsignals.h"
28 #include "clip.h"
29 #include "cwindowgui.h"
30 #include "cwindow.h"
31 #include "channelinfo.h"
32 #include "dbwindow.h"
33 #include "edit.h"
34 #include "editpopup.h"
35 #include "edits.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
39 #include "filexml.h"
40 #include "keyframepopup.h"
41 #include "keys.h"
42 #include "language.h"
43 #include "localsession.h"
44 #include "mainclock.h"
45 #include "maincursor.h"
46 #include "mainmenu.h"
47 #include "mainsession.h"
48 #include "mainundo.h"
49 #include "mbuttons.h"
50 #include "mtimebar.h"
51 #include "mwindowgui.h"
52 #include "mwindow.h"
53 #include "panedividers.h"
54 #include "patchbay.h"
55 #include "plugin.h"
56 #include "pluginpopup.h"
57 #include "pluginset.h"
58 #include "preferences.h"
59 #include "record.h"
60 #include "recordgui.h"
61 #include "renderengine.h"
62 #include "remotecontrol.h"
63 #include "resourcethread.h"
64 #include "samplescroll.h"
65 #include "shbtnprefs.h"
66 #include "statusbar.h"
67 #include "swindow.h"
68 #include "theme.h"
69 #include "trackcanvas.h"
70 #include "trackpopup.h"
71 #include "trackscroll.h"
72 #include "tracks.h"
73 #include "transitionpopup.h"
74 #include "vwindowgui.h"
75 #include "vwindow.h"
76 #include "wintv.h"
77 #include "x10tv.h"
78 #include "zoombar.h"
79
80 #define PANE_DRAG_MARGIN MAX(mwindow->theme->pane_w, mwindow->theme->pane_h)
81
82
83 // the main window uses its own private colormap for video
84 MWindowGUI::MWindowGUI(MWindow *mwindow)
85  : BC_Window(_(PROGRAM_NAME ": Program"),
86                 mwindow->session->mwindow_x, mwindow->session->mwindow_y,
87                 mwindow->session->mwindow_w, mwindow->session->mwindow_h,
88                 xS(100), yS(100), 1, 1, 1)
89 {
90         this->mwindow = mwindow;
91 //      samplescroll = 0;
92 //      trackscroll = 0;
93 //      cursor = 0;
94 //      patchbay = 0;
95 //      timebar = 0;
96 //      canvas = 0;
97         focused_pane = TOP_LEFT_PANE;
98         x_divider = 0;
99         y_divider = 0;
100         x_pane_drag = 0;
101         y_pane_drag = 0;
102         dragging_pane = 0;
103         drag_popup = 0;
104
105         render_engine = 0;
106         render_engine_id = -1;
107         for(int i = 0; i < TOTAL_PANES; i++)
108                 pane[i] = 0;
109
110         record = 0;
111         channel_info = 0;
112         swindow = 0;
113         db_window = 0;
114 // subwindows
115         mbuttons = 0;
116         statusbar = 0;
117         zoombar = 0;
118         mainclock = 0;
119         track_menu = 0;
120         edit_menu = 0;
121         plugin_menu = 0;
122         keyframe_menu = 0;
123         keyframe_hide = 0;
124         keyvalue_popup = 0;
125         transition_menu = 0;
126         remote_control = 0;
127         cwindow_remote_handler = 0;
128         record_remote_handler = 0;
129         android_control = 0;
130 }
131
132
133 MWindowGUI::~MWindowGUI()
134 {
135         delete android_control;
136         delete cwindow_remote_handler;
137         delete record_remote_handler;
138         delete remote_control;
139         delete keyvalue_popup;
140 //      delete samplescroll;
141 //      delete trackscroll;
142         for(int i = 0; i < TOTAL_PANES; i++)
143                 if(pane[i]) delete pane[i];
144 //      delete cursor;
145         delete render_engine;
146         delete resource_thread;
147         resource_pixmaps.remove_all_objects();
148         delete swindow;
149 #ifdef HAVE_DVB
150         delete channel_info;
151 #endif
152         delete db_window;
153         delete x_divider;
154         delete y_divider;
155 }
156
157 void MWindowGUI::create_objects()
158 {
159         lock_window("MWindowGUI::create_objects");
160         const int debug = 0;
161
162         resource_thread = new ResourceThread(mwindow);
163         resource_thread->create_objects();
164
165
166         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
167         set_icon(mwindow->theme->get_image("mwindow_icon"));
168         remote_control = new RemoteControl(this);
169         cwindow_remote_handler = 0;
170         record_remote_handler = 0;
171 #ifdef HAVE_X10TV
172 // should be first, use if plugged
173         if( !cwindow_remote_handler && mwindow->x10tv ) {
174                 cwindow_remote_handler = (RemoteHandler*)
175                         new X10TVCWindowHandler(mwindow->x10tv, remote_control);
176                 record_remote_handler = (RemoteHandler*)
177                         new X10TVRecordHandler(mwindow->x10tv, remote_control);
178         }
179 #endif
180 #ifdef HAVE_WINTV
181         if( !cwindow_remote_handler && mwindow->wintv ) {
182                 cwindow_remote_handler = (RemoteHandler*)
183                         new WinTVCWindowHandler(mwindow->wintv, remote_control);
184                 record_remote_handler = (RemoteHandler*)
185                         new WinTVRecordHandler(mwindow->wintv, remote_control);
186         }
187 #endif
188         mwindow->reset_android_remote();
189         if( !cwindow_remote_handler )
190                 cwindow_remote_handler = (RemoteHandler*)
191                         new CWindowKeyEvHandler(mwindow->gui->remote_control);
192         if( !record_remote_handler )
193                 record_remote_handler = (RemoteHandler*)
194                         new RecordKeyEvHandler(mwindow->gui->remote_control);
195         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
196
197         int x1 = get_w() - MainShBtns::calculate_w(-1, 0, -1) - xS(5);
198         add_subwindow(mainshbtns = new MainShBtns(mwindow, x1, -1));
199         mainshbtns->load(mwindow->preferences);
200         int x2 = x1 - mwindow->theme->stack_button_w - xS(5);
201         add_subwindow(stack_button = new StackButton(mwindow, x2, yS(2)));
202         add_subwindow(mainmenu = new MainMenu(mwindow, this, x2));
203         mainmenu->create_objects();
204         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
205         mwindow->theme->draw_mwindow_bg(this);
206         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
207
208         add_subwindow(mbuttons = new MButtons(mwindow, this));
209         mbuttons->create_objects();
210         int y1 = mbuttons->get_y()+yS(2);
211         add_subwindow(proxy_toggle = new ProxyToggle(mwindow, mbuttons, x2, y1));
212         add_subwindow(ffmpeg_toggle = new FFMpegToggle(mwindow, mbuttons, x1, y1));
213
214         pane[TOP_LEFT_PANE] = new TimelinePane(mwindow,
215                 TOP_LEFT_PANE,
216                 mwindow->theme->mcanvas_x,
217                 mwindow->theme->mcanvas_y,
218                 mwindow->theme->mcanvas_w,
219                 mwindow->theme->mcanvas_h);
220         pane[TOP_LEFT_PANE]->create_objects();
221
222         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
223         add_subwindow(zoombar = new ZoomBar(mwindow, this));
224         zoombar->create_objects();
225
226
227         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
228         add_subwindow(statusbar = new StatusBar(mwindow, this));
229         statusbar->create_objects();
230
231
232
233         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
234         add_subwindow(mainclock = new MainClock(mwindow,
235                 mwindow->theme->mclock_x, mwindow->theme->mclock_y,
236                 mwindow->theme->mclock_w));
237         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
238         mainclock->update(0);
239
240
241
242 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
243 //      cursor = new MainCursor(mwindow, this);
244 //      cursor->create_objects();
245
246
247         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
248         add_subwindow(track_menu = new TrackPopup(mwindow, this));
249         track_menu->create_objects();
250         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
251         add_subwindow(edit_menu = new EditPopup(mwindow, this));
252         edit_menu->create_objects();
253
254
255         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
256         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
257         plugin_menu->create_objects();
258
259
260         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
261         add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
262         keyframe_menu->create_objects();
263         add_subwindow(keyframe_hide = new KeyframeHidePopup(mwindow, this));
264         keyframe_hide->create_objects();
265
266
267         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
268         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
269         transition_menu->create_objects();
270
271 #ifdef HAVE_DVB
272         channel_info = new ChannelInfo(mwindow);
273 #endif
274 #ifdef HAVE_COMMERCIAL
275         db_window = new DbWindow(mwindow);
276 #endif
277         swindow = new SWindow(mwindow);
278
279         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
280
281         add_subwindow(pane_button = new PaneButton(mwindow,
282                 get_w() - mwindow->theme->get_image_set("pane")[0]->get_w(),
283                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h()));
284
285         pane[TOP_LEFT_PANE]->canvas->activate();
286
287         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
288         unlock_window();
289 }
290
291 void MWindowGUI::redraw_time_dependancies()
292 {
293         zoombar->redraw_time_dependancies();
294         for(int i = 0; i < TOTAL_PANES; i++)
295                 if(pane[i] && pane[i]->timebar) pane[i]->timebar->update(0);
296         mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
297 }
298
299 int MWindowGUI::focus_in_event()
300 {
301         for(int i = 0; i < TOTAL_PANES; i++)
302                 if(pane[i]) pane[i]->cursor->focus_in_event();
303         return 1;
304 }
305
306 int MWindowGUI::focus_out_event()
307 {
308         for(int i = 0; i < TOTAL_PANES; i++)
309                 if(pane[i]) pane[i]->cursor->focus_out_event();
310         return 1;
311 }
312
313
314 int MWindowGUI::resize_event(int w, int h)
315 {
316 //printf("MWindowGUI::resize_event %d\n", __LINE__);
317         mwindow->session->mwindow_w = w;
318         mwindow->session->mwindow_h = h;
319         int x1 = w - MainShBtns::calculate_w(-1, 0, -1) - xS(5);
320         mainshbtns->reposition_window(x1, -1);
321         int x2 = x1 - mwindow->theme->stack_button_w - xS(5);
322         stack_button->reposition_window(x2, stack_button->get_y());
323         mainmenu->resize_event(x2, mainmenu->get_h());
324         mwindow->theme->get_mwindow_sizes(this, w, h);
325         mwindow->theme->draw_mwindow_bg(this);
326         mbuttons->resize_event();
327         int y1 = mbuttons->get_y()+yS(2);
328         proxy_toggle->reposition_window(x2, y1);
329         ffmpeg_toggle->reposition_window(x1, y1);
330         statusbar->resize_event();
331         zoombar->resize_event();
332
333         resource_thread->stop_draw(1);
334
335         if(total_panes() > 1)
336         {
337                 if(horizontal_panes())
338                 {
339 //                      printf("MWindowGUI::resize_event %d %d %d\n",
340 //                              __LINE__,
341 //                              pane[TOP_RIGHT_PANE]->x,
342 //                              mwindow->theme->mcanvas_w -
343 //                                      BC_ScrollBar::get_span(SCROLL_VERT) -
344 //                                      PANE_DRAG_MARGIN);
345                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
346                                 BC_ScrollBar::get_span(SCROLL_VERT) -
347                                 PANE_DRAG_MARGIN)
348                         {
349                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
350                                 mwindow->edl->local_session->x_pane = -1;
351                         }
352                 }
353                 else
354                 if(vertical_panes())
355                 {
356                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
357                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
358                                 PANE_DRAG_MARGIN)
359                         {
360                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
361                                 mwindow->edl->local_session->y_pane = -1;
362                         }
363                 }
364                 else
365                 {
366                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
367                                         BC_ScrollBar::get_span(SCROLL_VERT) -
368                                         PANE_DRAG_MARGIN)
369                         {
370                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
371                                 mwindow->edl->local_session->x_pane = -1;
372                         }
373
374                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
375                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
376                                 PANE_DRAG_MARGIN)
377                         {
378                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
379                                 mwindow->edl->local_session->y_pane = -1;
380                         }
381                 }
382         }
383
384         if(total_panes() == 1)
385         {
386                 pane[TOP_LEFT_PANE]->resize_event(
387                         mwindow->theme->mcanvas_x,
388                         mwindow->theme->mcanvas_y,
389                         mwindow->theme->mcanvas_w,
390                         mwindow->theme->mcanvas_h);
391         }
392         else
393         if(horizontal_panes())
394         {
395                 pane[TOP_LEFT_PANE]->resize_event(
396                         pane[TOP_LEFT_PANE]->x,
397                         pane[TOP_LEFT_PANE]->y,
398                         pane[TOP_LEFT_PANE]->w,
399                         mwindow->theme->mcanvas_h);
400                 pane[TOP_RIGHT_PANE]->resize_event(
401                         pane[TOP_RIGHT_PANE]->x,
402                         pane[TOP_RIGHT_PANE]->y,
403                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
404                         mwindow->theme->mcanvas_h);
405         }
406         else
407         if(vertical_panes())
408         {
409                 pane[TOP_LEFT_PANE]->resize_event(
410                         pane[TOP_LEFT_PANE]->x,
411                         pane[TOP_LEFT_PANE]->y,
412                         mwindow->theme->mcanvas_w,
413                         pane[TOP_LEFT_PANE]->h);
414                 pane[BOTTOM_LEFT_PANE]->resize_event(
415                         pane[BOTTOM_LEFT_PANE]->x,
416                         pane[BOTTOM_LEFT_PANE]->y,
417                         mwindow->theme->mcanvas_w,
418                         mwindow->theme->mcanvas_y +
419                                 mwindow->theme->mcanvas_h -
420                                 pane[BOTTOM_LEFT_PANE]->y);
421         }
422         else
423         {
424                 pane[TOP_LEFT_PANE]->resize_event(
425                         pane[TOP_LEFT_PANE]->x,
426                         pane[TOP_LEFT_PANE]->y,
427                         pane[TOP_LEFT_PANE]->w,
428                         pane[TOP_LEFT_PANE]->h);
429                 pane[TOP_RIGHT_PANE]->resize_event(
430                         pane[TOP_RIGHT_PANE]->x,
431                         pane[TOP_RIGHT_PANE]->y,
432                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
433                         pane[TOP_RIGHT_PANE]->h);
434                 pane[BOTTOM_LEFT_PANE]->resize_event(
435                         pane[BOTTOM_LEFT_PANE]->x,
436                         pane[BOTTOM_LEFT_PANE]->y,
437                         pane[BOTTOM_LEFT_PANE]->w,
438                         mwindow->theme->mcanvas_y +
439                                 mwindow->theme->mcanvas_h -
440                                 pane[BOTTOM_LEFT_PANE]->y);
441                 pane[BOTTOM_RIGHT_PANE]->resize_event(
442                         pane[BOTTOM_RIGHT_PANE]->x,
443                         pane[BOTTOM_RIGHT_PANE]->y,
444                         mwindow->theme->mcanvas_w -
445                                 pane[BOTTOM_RIGHT_PANE]->x,
446                         mwindow->theme->mcanvas_y +
447                                 mwindow->theme->mcanvas_h -
448                                 pane[BOTTOM_RIGHT_PANE]->y);
449         }
450
451         update_pane_dividers();
452         pane_button->reposition_window(w - mwindow->theme->get_image_set("pane")[0]->get_w(),
453                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h());
454         resource_thread->start_draw();
455
456         flash(1);
457         return 0;
458 }
459
460 int MWindowGUI::total_panes()
461 {
462         int total = 0;
463         for(int i = 0; i < TOTAL_PANES; i++)
464                 if(pane[i]) total++;
465         return total;
466 }
467
468 int MWindowGUI::vertical_panes()
469 {
470         return total_panes() == 2 &&
471                 pane[TOP_LEFT_PANE] &&
472                 pane[BOTTOM_LEFT_PANE];
473 }
474
475 int MWindowGUI::horizontal_panes()
476 {
477         return total_panes() == 2 &&
478                 pane[TOP_LEFT_PANE] &&
479                 pane[TOP_RIGHT_PANE];
480 }
481
482 TimelinePane* MWindowGUI::get_focused_pane()
483 {
484         if(pane[focused_pane]) return pane[focused_pane];
485         for(int i = 0; i < TOTAL_PANES; i++)
486         {
487                 if(pane[i]) return pane[i];
488         }
489         return 0;
490 }
491
492 void MWindowGUI::activate_timeline()
493 {
494         if(pane[focused_pane])
495         {
496                 pane[focused_pane]->activate();
497         }
498         else
499         {
500                 for(int i = 0; i < TOTAL_PANES; i++)
501                 {
502                         if(pane[i])
503                         {
504                                 pane[i]->activate();
505                                 return;
506                         }
507                 }
508         }
509 }
510
511 void MWindowGUI::deactivate_timeline()
512 {
513         for(int i = 0; i < TOTAL_PANES; i++)
514         {
515                 if(pane[i])
516                 {
517                         pane[i]->canvas->deactivate();
518                 }
519         }
520 }
521
522 void MWindowGUI::update_title(char *path)
523 {
524         FileSystem fs;
525         char filename[BCTEXTLEN], string[BCTEXTLEN];
526         fs.extract_name(filename, path);
527         sprintf(string, _(PROGRAM_NAME ": %s"), filename);
528         set_title(string);
529 //printf("MWindowGUI::update_title %s\n", string);
530         flush();
531 }
532
533 void MWindowGUI::draw_overlays(int flash_it)
534 {
535         for(int i = 0; i < TOTAL_PANES; i++)
536         {
537                 if(pane[i])
538                 {
539                         pane[i]->canvas->draw_overlays();
540                         if(flash_it) pane[i]->canvas->flash();
541                 }
542         }
543 }
544
545 void MWindowGUI::update_timebar(int flush_it)
546 {
547         for(int i = 0; i < TOTAL_PANES; i++)
548         {
549                 if(pane[i] && pane[i]->timebar)
550                 {
551                         pane[i]->timebar->update(flush_it);
552                 }
553         }
554 }
555
556 void MWindowGUI::update_timebar_highlights()
557 {
558         for(int i = 0; i < TOTAL_PANES; i++)
559         {
560                 if(pane[i] && pane[i]->timebar)
561                 {
562                         pane[i]->timebar->update_highlights();
563                 }
564         }
565 }
566
567
568 void MWindowGUI::update_patchbay()
569 {
570         for(int i = 0; i < TOTAL_PANES; i++)
571         {
572                 if(pane[i] && pane[i]->patchbay)
573                 {
574                         pane[i]->patchbay->update();
575                 }
576         }
577 }
578
579 void MWindowGUI::update_proxy_toggle()
580 {
581         int value = mwindow->edl->session->proxy_scale == 1 ? 1 : 0;
582         proxy_toggle->set_value(value);
583         if( mwindow->edl->session->proxy_scale == 1 &&
584             mwindow->edl->session->proxy_disabled_scale == 1 )
585                 proxy_toggle->hide();
586         else
587                 proxy_toggle->show();
588 }
589
590 void MWindowGUI::update_plugintoggles()
591 {
592         for(int i = 0; i < TOTAL_PANES; i++)
593         {
594                 if(pane[i])
595                 {
596                         pane[i]->canvas->refresh_plugintoggles();
597                 }
598         }
599
600 }
601
602 void MWindowGUI::draw_indexes(Indexable *indexable)
603 {
604         for(int i = 0; i < TOTAL_PANES; i++)
605         {
606                 if(pane[i])
607                 {
608                         pane[i]->canvas->draw_indexes(indexable);
609                 }
610         }
611 }
612
613 void MWindowGUI::draw_canvas(int redraw, int hide_cursor)
614 {
615         resource_thread->stop_draw(0);
616
617         int mode = redraw ? FORCE_REDRAW : NORMAL_DRAW;
618         for(int i = 0; i < TOTAL_PANES; i++) {
619                 if( pane[i] )
620                         pane[i]->canvas->draw(mode, hide_cursor);
621         }
622
623         resource_thread->start_draw();
624 }
625
626 void MWindowGUI::flash_canvas(int flush)
627 {
628         for(int i = 0; i < TOTAL_PANES; i++)
629         {
630                 if(pane[i])
631                 {
632                         pane[i]->canvas->flash(flush);
633                 }
634         }
635 }
636
637 int MWindowGUI::show_window(int flush)
638 {
639         int ret = BC_WindowBase::show_window(flush);
640         stack_button->update();
641         update_proxy_toggle();
642         return ret;
643 }
644
645 void MWindowGUI::draw_cursor(int do_plugintoggles)
646 {
647         for(int i = 0; i < TOTAL_PANES; i++)
648         {
649                 if(pane[i])
650                 {
651                         pane[i]->cursor->draw(do_plugintoggles);
652                 }
653         }
654 }
655
656 void MWindowGUI::show_cursor(int do_plugintoggles)
657 {
658         for(int i = 0; i < TOTAL_PANES; i++)
659         {
660                 if(pane[i])
661                 {
662                         pane[i]->cursor->show(do_plugintoggles);
663                 }
664         }
665 }
666
667 void MWindowGUI::hide_cursor(int do_plugintoggles)
668 {
669         for(int i = 0; i < TOTAL_PANES; i++)
670         {
671                 if(pane[i])
672                 {
673                         pane[i]->cursor->hide(do_plugintoggles);
674                 }
675         }
676 }
677
678 void MWindowGUI::update_cursor()
679 {
680         for(int i = 0; i < TOTAL_PANES; i++)
681         {
682                 if(pane[i])
683                 {
684                         pane[i]->cursor->update();
685                 }
686         }
687 }
688
689 void MWindowGUI::set_playing_back(int value)
690 {
691         for(int i = 0; i < TOTAL_PANES; i++)
692         {
693                 if(pane[i])
694                 {
695                         pane[i]->cursor->playing_back = value;
696                 }
697         }
698 }
699
700 void MWindowGUI::update_scrollbars(int flush)
701 {
702         for(int i = 0; i < TOTAL_PANES; i++)
703         {
704                 if(pane[i])
705                 {
706                         pane[i]->update(1, NO_DRAW, 0, 0);
707                 }
708         }
709         if(flush) this->flush();
710 }
711
712 void MWindowGUI::reset_meters()
713 {
714         for(int i = 0; i < TOTAL_PANES; i++)
715         {
716                 if(pane[i] && pane[i]->patchbay)
717                 {
718                         pane[i]->patchbay->reset_meters();
719                 }
720         }
721 }
722
723 void MWindowGUI::stop_meters()
724 {
725         for(int i = 0; i < TOTAL_PANES; i++)
726         {
727                 if(pane[i] && pane[i]->patchbay)
728                 {
729                         pane[i]->patchbay->stop_meters();
730                 }
731         }
732 }
733
734 void MWindowGUI::update_meters(ArrayList<double> *module_levels)
735 {
736         for(int i = 0; i < TOTAL_PANES; i++)
737         {
738                 if(pane[i] && pane[i]->patchbay)
739                 {
740                         pane[i]->patchbay->update_meters(module_levels);
741                 }
742         }
743 }
744
745 void MWindowGUI::set_editing_mode(int flush)
746 {
747         for(int i = 0; i < TOTAL_PANES; i++)
748         {
749                 if(pane[i])
750                 {
751                         pane[i]->canvas->update_cursor(flush);
752                 }
753         }
754 }
755
756 void MWindowGUI::set_meter_format(int mode, int min, int max)
757 {
758         for(int i = 0; i < TOTAL_PANES; i++)
759         {
760                 if(pane[i] && pane[i]->patchbay)
761                 {
762                         pane[i]->patchbay->set_meter_format(mode, min, max);
763                 }
764         }
765 }
766
767 void MWindowGUI::update(int scrollbars,
768         int do_canvas,
769         int timebar,
770         int zoombar,
771         int patchbay,
772         int clock,
773         int buttonbar)
774 {
775         const int debug = 0;
776         if(debug) PRINT_TRACE
777
778
779
780         mwindow->edl->tracks->update_y_pixels(mwindow->theme);
781
782         if( do_canvas != NO_DRAW && do_canvas != IGNORE_THREAD )
783                 resource_thread->stop_draw(1);
784
785         for(int i = 0; i < TOTAL_PANES; i++)
786         {
787                 if(pane[i]) pane[i]->update(scrollbars,
788                         do_canvas,
789                         timebar,
790                         patchbay);
791         }
792
793         if( do_canvas != NO_DRAW && do_canvas != IGNORE_THREAD )
794                 resource_thread->start_draw();
795
796 //      if(scrollbars) this->get_scrollbars(0);
797 //      if(timebar) this->timebar->update(0);
798         if(zoombar) this->zoombar->update();
799 //      if(patchbay) this->patchbay->update();
800         if(clock) this->mainclock->update(
801                 mwindow->edl->local_session->get_selectionstart(1));
802         if(debug) PRINT_TRACE
803
804
805
806 //      if(do_canvas)
807 //      {
808 //              this->canvas->draw(do_canvas);
809 //              this->cursor->show();
810 //              this->canvas->flash(0);
811 // Activate causes the menubar to deactivate.  Don't want this for
812 // picon thread.
813 //              if(canvas != IGNORE_THREAD) this->canvas->activate();
814 //      }
815         if(debug) PRINT_TRACE
816
817
818
819         if(buttonbar) mbuttons->update();
820         if(debug) PRINT_TRACE
821
822 // Can't age if the cache called this to draw missing picons
823 // or the GUI is updating the status of the draw toggle.
824         if( do_canvas != FORCE_REDRAW && do_canvas != IGNORE_THREAD ) {
825                 unlock_window();
826                 mwindow->age_caches();
827                 lock_window("MWindowGUI::update");
828         }
829
830         flush();
831         if(debug) PRINT_TRACE
832 }
833
834 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
835 {
836         return (x1 >= view_x1 && x1 < view_x2) ||
837                 (x2 > view_x1 && x2 <= view_x2) ||
838                 (x1 <= view_x1 && x2 >= view_x2);
839 }
840
841
842 void MWindowGUI::show_message(const char *message, int msg_color, int bar_color)
843 {
844         statusbar->show_message(message, msg_color, bar_color);
845 }
846
847 void MWindowGUI::update_default_message()
848 {
849         statusbar->update_default_message();
850 }
851
852 void MWindowGUI::reset_default_message()
853 {
854         statusbar->reset_default_message();
855 }
856
857 void MWindowGUI::default_message()
858 {
859         statusbar->default_message();
860 }
861
862 // Drag motion called from other window
863 int MWindowGUI::drag_motion()
864 {
865         if(get_hidden()) return 0;
866
867         Track *over_track = 0;
868         Edit *over_edit = 0;
869         PluginSet *over_pluginset = 0;
870         Plugin *over_plugin = 0;
871         int redraw = 0;
872
873         if(drag_popup)
874         {
875                 drag_popup->cursor_motion_event();
876         }
877
878
879 // there's no point in drawing highlights has until drag operation has been set
880         if (!mwindow->session->current_operation)
881                 return 0;
882
883         for(int i = 0; i < TOTAL_PANES; i++)
884         {
885                 if(pane[i]) pane[i]->canvas->drag_motion(
886                         &over_track,
887                         &over_edit,
888                         &over_pluginset,
889                         &over_plugin);
890         }
891
892         if(mwindow->session->track_highlighted != over_track)
893         {
894                 mwindow->session->track_highlighted = over_track;
895                 redraw = 1;
896         }
897
898         if(mwindow->session->edit_highlighted != over_edit)
899         {
900                 mwindow->session->edit_highlighted = over_edit;
901                 redraw = 1;
902         }
903
904         if(mwindow->session->pluginset_highlighted != over_pluginset)
905         {
906                 mwindow->session->pluginset_highlighted = over_pluginset;
907                 redraw = 1;
908         }
909
910         if(mwindow->session->plugin_highlighted != over_plugin)
911         {
912                 mwindow->session->plugin_highlighted = over_plugin;
913                 redraw = 1;
914         }
915
916         if( mwindow->session->current_operation == DRAG_ASSET ||
917             mwindow->session->current_operation == DRAG_EDIT ||
918             mwindow->session->current_operation == DRAG_GROUP ||
919             mwindow->session->current_operation == DRAG_AEFFECT_COPY ||
920             mwindow->session->current_operation == DRAG_VEFFECT_COPY ) {
921                 redraw = 1;
922         }
923
924
925 // printf("drag_motion %d %d over_track=%p over_edit=%p\n",
926 // __LINE__,
927 // redraw,
928 // over_track,
929 // over_edit);
930         if(redraw)
931         {
932                 lock_window("MWindowGUI::drag_motion");
933                 draw_overlays(1);
934                 unlock_window();
935         }
936         return 0;
937 }
938
939 int MWindowGUI::drag_stop()
940 {
941         if(get_hidden()) return 0;
942         int result = 0, redraw = 0;
943
944         for(int i = 0; i < TOTAL_PANES; i++)
945         {
946                 if(pane[i]) result |= pane[i]->canvas->drag_stop(
947                         &redraw);
948         }
949         mwindow->edl->optimize();
950
951 // since we don't have subwindows we have to terminate any drag operation
952         if(result)
953         {
954                 if (mwindow->session->track_highlighted
955                         || mwindow->session->edit_highlighted
956                         || mwindow->session->plugin_highlighted
957                         || mwindow->session->pluginset_highlighted)
958                         redraw = 1;
959                 mwindow->session->track_highlighted = 0;
960                 mwindow->session->edit_highlighted = 0;
961                 mwindow->session->plugin_highlighted = 0;
962                 mwindow->session->pluginset_highlighted = 0;
963                 mwindow->session->current_operation = NO_OPERATION;
964         }
965
966
967 //printf("MWindowGUI::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
968         if(redraw)
969         {
970                 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
971                 update_scrollbars(0);
972                 update_patchbay();
973                 draw_canvas(1, 1);
974                 update_cursor();
975                 flash_canvas(1);
976         }
977
978         if(drag_popup)
979         {
980                 delete drag_popup;
981                 drag_popup = 0;
982         }
983         return result;
984 }
985
986 void MWindowGUI::default_positions()
987 {
988 //printf("MWindowGUI::default_positions 1\n");
989         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
990                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
991         if( vwindow && !vwindow->is_running() ) vwindow = 0;
992         if( vwindow ) vwindow->gui->lock_window("MWindowGUI::default_positions");
993         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
994         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
995
996 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x,
997 // mwindow->session->vwindow_y,
998 // mwindow->session->vwindow_w,
999 // mwindow->session->vwindow_h);
1000         reposition_window(mwindow->session->mwindow_x,
1001                 mwindow->session->mwindow_y,
1002                 mwindow->session->mwindow_w,
1003                 mwindow->session->mwindow_h);
1004         if( vwindow ) vwindow->gui->reposition_window(mwindow->session->vwindow_x,
1005                 mwindow->session->vwindow_y,
1006                 mwindow->session->vwindow_w,
1007                 mwindow->session->vwindow_h);
1008         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
1009                 mwindow->session->cwindow_y,
1010                 mwindow->session->cwindow_w,
1011                 mwindow->session->cwindow_h);
1012         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
1013                 mwindow->session->awindow_y,
1014                 mwindow->session->awindow_w,
1015                 mwindow->session->awindow_h);
1016 //printf("MWindowGUI::default_positions 1\n");
1017
1018         resize_event(mwindow->session->mwindow_w,
1019                 mwindow->session->mwindow_h);
1020 //printf("MWindowGUI::default_positions 1\n");
1021         if( vwindow ) vwindow->gui->resize_event(mwindow->session->vwindow_w,
1022                 mwindow->session->vwindow_h);
1023 //printf("MWindowGUI::default_positions 1\n");
1024         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
1025                 mwindow->session->cwindow_h);
1026 //printf("MWindowGUI::default_positions 1\n");
1027         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
1028                 mwindow->session->awindow_h);
1029
1030 //printf("MWindowGUI::default_positions 1\n");
1031
1032         flush();
1033         if( vwindow ) vwindow->gui->flush();
1034         mwindow->cwindow->gui->flush();
1035         mwindow->awindow->gui->flush();
1036
1037         if( vwindow ) vwindow->gui->unlock_window();
1038         mwindow->cwindow->gui->unlock_window();
1039         mwindow->awindow->gui->unlock_window();
1040 //printf("MWindowGUI::default_positions 2\n");
1041 }
1042
1043
1044 int MWindowGUI::repeat_event(int64_t duration)
1045 {
1046 // if(duration == 100)
1047 // mwindow->sync_parameters(CHANGE_ALL);
1048         int result = 0;
1049         for(int i = 0; i < TOTAL_PANES; i++)
1050         {
1051                 if(pane[i]) result = pane[i]->cursor->repeat_event(duration);
1052         }
1053         return result;
1054 }
1055
1056
1057 int MWindowGUI::translation_event()
1058 {
1059 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
1060         mwindow->session->mwindow_x = get_x();
1061         mwindow->session->mwindow_y = get_y();
1062         return 0;
1063 }
1064
1065
1066 int MWindowGUI::save_defaults(BC_Hash *defaults)
1067 {
1068         defaults->update("MWINDOWWIDTH", get_w());
1069         defaults->update("MWINDOWHEIGHT", get_h());
1070         mainmenu->save_defaults(defaults);
1071         BC_WindowBase::save_defaults(defaults);
1072         return 0;
1073 }
1074
1075 int MWindowGUI::keypress_event()
1076 {
1077 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
1078         int result = mbuttons->keypress_event();
1079         if( result ) return result;
1080
1081         Track *this_track = 0, *first_track = 0;
1082         int packed = 0, overwrite = 0, plugins = 0;
1083         double position = 0;
1084
1085         switch( get_keypress() ) {
1086         case 'A':
1087                 if( !alt_down() && ctrl_down() ) {
1088                         mwindow->edl->tracks->clear_selected_edits();
1089                         draw_overlays(1);
1090                         result = 1;
1091                 }
1092                 break;
1093         case 'a':
1094                 if( !ctrl_down() && alt_down() ) {
1095                         stop_transport("MWindowGUI::keypress_event 1");
1096                         mwindow->nearest_auto_keyframe(shift_down(),
1097                                 !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1098                         result = 1;
1099                 }
1100                 else if( ctrl_down() && alt_down() ) {
1101                         mwindow->select_edits(1);
1102                         result = 1;
1103                 }
1104                 break;
1105
1106         case 'e':
1107                 if( ctrl_down() || alt_down() ) break;
1108                 mwindow->toggle_editing_mode();
1109                 result = 1;
1110                 break;
1111
1112         case 'k': case 'K':
1113                 if( alt_down() ) break;
1114                 stop_transport("MWindowGUI::keypress_event 2");
1115                 mwindow->nearest_plugin_keyframe(shift_down(),
1116                         !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1117                 result = 1;
1118                 break;
1119
1120         case 'C':
1121                 packed = 1;
1122         case 'c':
1123                 if( !ctrl_down() || alt_down() ) break;
1124                 mwindow->selected_edits_to_clipboard(packed);
1125                 result = 1;
1126                 break;
1127         case 'P':
1128                 plugins = 1;
1129         case 'b':
1130                 overwrite = -1; // fall thru
1131         case 'v':
1132                 if( !ctrl_down() || alt_down() ) break;
1133                 if( mwindow->session->current_operation == DROP_TARGETING ) {
1134                         mwindow->session->current_operation = NO_OPERATION;
1135                         mwindow->gui->set_editing_mode(1);
1136                         int pane_no = 0;
1137                         for( ; pane_no<TOTAL_PANES; ++pane_no  ) {
1138                                 if( !pane[pane_no] ) continue;
1139                                 first_track = pane[pane_no]->over_track();
1140                                 if( first_track ) break;
1141                         }
1142                         if( first_track ) {
1143                                 int cursor_x = pane[pane_no]->canvas->get_relative_cursor_x();
1144                                 position = mwindow->edl->get_cursor_position(cursor_x, pane_no);
1145                         }
1146                 }
1147                 else
1148                         position = mwindow->edl->local_session->get_selectionstart();
1149                 if( !plugins )
1150                         mwindow->paste(position, first_track, 0, overwrite);
1151                 else
1152                         mwindow->paste_clipboard(first_track, position, 1, 0, 1, 1, 1);
1153                 mwindow->edl->tracks->clear_selected_edits();
1154                 draw_overlays(1);
1155                 result = 1;
1156                 break;
1157         case 'M':
1158                 mwindow->cut_selected_edits(0, 1);
1159                 result = 1;
1160                 break;
1161         case BACKSPACE:
1162         case 'm':
1163                 mwindow->cut_selected_edits(0, 0);
1164                 result = 1;
1165                 break;
1166         case 'z':
1167                 if( !alt_down() ) {
1168                         // z and ctrl-z both are undo, z mainmenu item
1169                         if( mwindow->session->current_operation == NO_OPERATION )
1170                                 mwindow->undo_entry(this);
1171                         result = 1;
1172                 }
1173                 else if( ctrl_down() ) {
1174                         mwindow->cut_selected_edits(1, 1);
1175                         result = 1;
1176                 }
1177                 break;
1178         case 'x':
1179                 if( !ctrl_down() || alt_down() ) break;
1180                 mwindow->cut_selected_edits(1, 0);
1181                 result = 1;
1182                 break;
1183
1184         case '1' ... '8':
1185                 if( !alt_down() || shift_down() ) break;
1186                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1187                         result = 1;
1188                 break;
1189
1190         case LEFT:
1191                 if( !ctrl_down() ) {
1192                         if( alt_down() ) {
1193                                 stop_transport("MWindowGUI::keypress_event 1");
1194                                 mwindow->prev_edit_handle(shift_down());
1195                         }
1196                         else
1197                                 mwindow->move_left();
1198                         result = 1;
1199                 }
1200                 break;
1201
1202         case ',':
1203                 if( !ctrl_down() && !alt_down() ) {
1204                         mwindow->move_left();
1205                         result = 1;
1206                 }
1207                 break;
1208
1209         case RIGHT:
1210                 if( !ctrl_down() ) {
1211                         if( alt_down() ) {
1212                                 stop_transport("MWindowGUI::keypress_event 2");
1213                                 mwindow->next_edit_handle(shift_down());
1214                         }
1215                         else
1216                                 mwindow->move_right();
1217                         result = 1;
1218                 }
1219                 break;
1220
1221         case '.':
1222                 if( !ctrl_down() && !alt_down() ) {
1223                         mwindow->move_right();
1224                         result = 1;
1225                 }
1226                 break;
1227
1228         case UP:
1229                 if( ctrl_down() && !alt_down() )
1230                         mwindow->expand_y();
1231                 else if( !ctrl_down() && alt_down() )
1232                         mwindow->expand_autos(0,1,1);
1233                 else if( ctrl_down() && alt_down() )
1234                         mwindow->expand_autos(1,1,1);
1235                 else
1236                         mwindow->expand_sample();
1237                 result = 1;
1238                 break;
1239
1240         case DOWN:
1241                 if( ctrl_down() && !alt_down() )
1242                         mwindow->zoom_in_y();
1243                 else if( !ctrl_down() && alt_down() )
1244                         mwindow->shrink_autos(0,1,1);
1245                 else if( ctrl_down() && alt_down() )
1246                         mwindow->shrink_autos(1,1,1);
1247                 else
1248                         mwindow->zoom_in_sample();
1249                 result = 1;
1250                 break;
1251
1252         case PGUP:
1253                 if( !ctrl_down() )
1254                         mwindow->move_up();
1255                 else
1256                         mwindow->expand_t();
1257                 result = 1;
1258                 break;
1259
1260         case PGDN:
1261                 if( !ctrl_down() )
1262                         mwindow->move_down();
1263                 else
1264                         mwindow->zoom_in_t();
1265                 result = 1;
1266                 break;
1267
1268         case TAB:
1269         case LEFTTAB:
1270                 for( int i=0; i<TOTAL_PANES; ++i ) {
1271                         if( !pane[i] ) continue;
1272                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1273                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1274                 }
1275
1276                 if( get_keypress() == TAB ) { // Switch the armed button
1277                         if( this_track )
1278                                 this_track->armed = !this_track->armed ? 1 : 0;
1279                 }
1280                 else {
1281                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1282                         // all selected if nothing previously selected or
1283                         // if this patch was previously the only one selected and armed
1284                         int selected = !total_selected || (total_selected == 1 &&
1285                                 this_track && this_track->armed ) ? 1 : 0;
1286                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1287                         if( !selected && this_track ) this_track->armed = 1;
1288                 }
1289
1290                 update(0, NORMAL_DRAW, 0, 0, 1, 0, 1);
1291                 unlock_window();
1292                 mwindow->cwindow->update(0, 1, 1);
1293                 lock_window("MWindowGUI::keypress_event 3");
1294
1295                 result = 1;
1296                 break;
1297
1298         case KEY_F1 ... KEY_F12:
1299                 resend_event(mwindow->cwindow->gui);
1300                 return 1;
1301         }
1302
1303 // since things under cursor have changed...
1304         if(result)
1305                 cursor_motion_event();
1306
1307         return result;
1308 }
1309
1310 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1311 {
1312         return key_listener(wp->get_keypress());
1313 }
1314
1315 int MWindowGUI::key_listener(int key)
1316 {
1317         int result = 1;
1318         switch( key ) {
1319         case KPTV:
1320                 if( !record->running() )
1321                         record->start();
1322                 else
1323                         record->record_gui->interrupt_thread->start(0);
1324                 break;
1325         case KPHAND:
1326                 mwindow->quit();
1327                 break;
1328 #ifdef HAVE_DVB
1329         case KPBOOK:
1330                 channel_info->toggle_scan();
1331                 break;
1332 #endif
1333         case KPMENU:
1334                 if( !remote_control->deactivate() )
1335                         remote_control->activate();
1336                 break;
1337         default:
1338                 result = 0;
1339                 break;
1340         }
1341         return result;
1342 }
1343
1344
1345 void MWindowGUI::use_android_remote(int on)
1346 {
1347         if( !on ) {
1348                 delete android_control;
1349                 android_control = 0;
1350                 return;
1351         }
1352         if( android_control ) return;
1353         android_control = new AndroidControl(this);
1354 }
1355 int MWindowGUI::keyev_grab_remote()
1356 {
1357         if( cwindow_remote_handler && cwindow_remote_handler->is_keytv() &&
1358             record_remote_handler  && record_remote_handler->is_keytv() )
1359                 return 0;
1360         delete cwindow_remote_handler;
1361         delete record_remote_handler;
1362         cwindow_remote_handler = (RemoteHandler*)
1363                 new CWindowKeyEvHandler(mwindow->gui->remote_control);
1364         record_remote_handler = (RemoteHandler*)
1365                 new RecordKeyEvHandler(mwindow->gui->remote_control);
1366         return 1;
1367 }
1368
1369 int MWindowGUI::close_event()
1370 {
1371         mainmenu->quit();
1372         return 0;
1373 }
1374
1375 void MWindowGUI::stop_drawing()
1376 {
1377         resource_thread->stop_draw(1);
1378 }
1379
1380 int MWindowGUI::menu_w()
1381 {
1382         return mainmenu->get_w();
1383 }
1384
1385 int MWindowGUI::menu_h()
1386 {
1387         return mainmenu->get_h();
1388 }
1389
1390 void MWindowGUI::start_x_pane_drag()
1391 {
1392         if(!x_pane_drag)
1393         {
1394                 x_pane_drag = new BC_Popup(this,
1395                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1396                         BC_DisplayInfo::get_top_border() +
1397                                 get_y() +
1398                                 mwindow->theme->mcanvas_y,
1399                         mwindow->theme->pane_w,
1400                         mwindow->theme->mcanvas_h,
1401                         mwindow->theme->drag_pane_color);
1402                 x_pane_drag->draw_3segmentv(0,
1403                         0,
1404                         x_pane_drag->get_h(),
1405                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1406                 x_pane_drag->flash(1);
1407         }
1408         dragging_pane = 1;
1409 }
1410
1411 void MWindowGUI::start_y_pane_drag()
1412 {
1413         if(!y_pane_drag)
1414         {
1415 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1416                 y_pane_drag = new BC_Popup(this,
1417                         BC_DisplayInfo::get_left_border() +
1418                                 get_x() +
1419                                 mwindow->theme->mcanvas_x,
1420                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1421                         mwindow->theme->mcanvas_w,
1422                         mwindow->theme->pane_h,
1423                         mwindow->theme->drag_pane_color);
1424                 y_pane_drag->draw_3segmenth(0,
1425                         0,
1426                         y_pane_drag->get_w(),
1427                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1428                 y_pane_drag->flash(1);
1429         }
1430         dragging_pane = 1;
1431 }
1432
1433 void MWindowGUI::handle_pane_drag()
1434 {
1435         if(dragging_pane)
1436         {
1437                 if(x_pane_drag)
1438                 {
1439                         x_pane_drag->reposition_window(
1440                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1441                                 x_pane_drag->get_y());
1442                 }
1443
1444                 if(y_pane_drag)
1445                 {
1446                         y_pane_drag->reposition_window(
1447                                 y_pane_drag->get_x(),
1448                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1449                 }
1450         }
1451 }
1452
1453
1454 void MWindowGUI::create_x_pane(int cursor_x)
1455 {
1456         if(total_panes() == 1)
1457         {
1458 // create a horizontal pane
1459 // do this 1st so the resize_event knows there are 2 panes
1460                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1461                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1462                         cursor_x -
1463                         mwindow->theme->patchbay_w;
1464                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1465                         TOP_RIGHT_PANE,
1466                         mwindow->theme->mcanvas_x +
1467                                 cursor_x,
1468                         mwindow->theme->mcanvas_y,
1469                         mwindow->theme->mcanvas_x +
1470                                 mwindow->theme->mcanvas_w -
1471                                 cursor_x,
1472                         mwindow->theme->mcanvas_h);
1473                 pane[TOP_LEFT_PANE]->resize_event(
1474                         mwindow->theme->mcanvas_x,
1475                         mwindow->theme->mcanvas_y,
1476                         cursor_x - mwindow->theme->pane_w,
1477                         mwindow->theme->mcanvas_h);
1478                 pane[TOP_RIGHT_PANE]->create_objects();
1479         }
1480         else
1481         if(vertical_panes())
1482         {
1483 // create 2 horizontal panes
1484                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1485                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1486                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1487                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1488                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1489                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1490                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1491                         cursor_x -
1492                         mwindow->theme->patchbay_w;
1493                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1494                         TOP_RIGHT_PANE,
1495                         mwindow->theme->mcanvas_x +
1496                                 cursor_x,
1497                         pane[TOP_LEFT_PANE]->y,
1498                         mwindow->theme->mcanvas_x +
1499                                 mwindow->theme->mcanvas_w -
1500                                 cursor_x,
1501                         pane[TOP_LEFT_PANE]->h);
1502                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1503                         BOTTOM_RIGHT_PANE,
1504                         mwindow->theme->mcanvas_x +
1505                                 cursor_x,
1506                         pane[BOTTOM_LEFT_PANE]->y,
1507                         mwindow->theme->mcanvas_x +
1508                                 mwindow->theme->mcanvas_w -
1509                                 cursor_x,
1510                         pane[BOTTOM_LEFT_PANE]->h);
1511                 pane[TOP_LEFT_PANE]->resize_event(
1512                         pane[TOP_LEFT_PANE]->x,
1513                         pane[TOP_LEFT_PANE]->y,
1514                         cursor_x - mwindow->theme->pane_w,
1515                         pane[TOP_LEFT_PANE]->h);
1516                 pane[BOTTOM_LEFT_PANE]->resize_event(
1517                         pane[BOTTOM_LEFT_PANE]->x,
1518                         pane[BOTTOM_LEFT_PANE]->y,
1519                         cursor_x - mwindow->theme->pane_w,
1520                         pane[BOTTOM_LEFT_PANE]->h);
1521                 pane[TOP_RIGHT_PANE]->create_objects();
1522                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1523         }
1524         else
1525         if(horizontal_panes())
1526         {
1527 // resize a horizontal pane
1528                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1529                         cursor_x -
1530                         pane[TOP_RIGHT_PANE]->x;
1531                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1532                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1533                 pane[TOP_LEFT_PANE]->resize_event(
1534                         mwindow->theme->mcanvas_x,
1535                         mwindow->theme->mcanvas_y,
1536                         cursor_x - mwindow->theme->pane_w,
1537                         mwindow->theme->mcanvas_h);
1538                 pane[TOP_RIGHT_PANE]->resize_event(
1539                         mwindow->theme->mcanvas_x +
1540                                 cursor_x,
1541                         pane[TOP_RIGHT_PANE]->y,
1542                         mwindow->theme->mcanvas_x +
1543                                 mwindow->theme->mcanvas_w -
1544                                 cursor_x,
1545                         mwindow->theme->mcanvas_h);
1546         }
1547         else
1548         {
1549 // resize 2 horizontal panes
1550                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1551                         cursor_x -
1552                         pane[TOP_RIGHT_PANE]->x;
1553                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1554                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1555                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1556                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1557
1558                 pane[TOP_LEFT_PANE]->resize_event(
1559                         mwindow->theme->mcanvas_x,
1560                         pane[TOP_LEFT_PANE]->y,
1561                         cursor_x - mwindow->theme->pane_w,
1562                         pane[TOP_LEFT_PANE]->h);
1563                 pane[TOP_RIGHT_PANE]->resize_event(
1564                         mwindow->theme->mcanvas_x +
1565                                 cursor_x,
1566                         pane[TOP_RIGHT_PANE]->y,
1567                         mwindow->theme->mcanvas_x +
1568                                 mwindow->theme->mcanvas_w -
1569                                 cursor_x,
1570                         pane[TOP_RIGHT_PANE]->h);
1571                 pane[BOTTOM_LEFT_PANE]->resize_event(
1572                         mwindow->theme->mcanvas_x,
1573                         pane[BOTTOM_LEFT_PANE]->y,
1574                         cursor_x - mwindow->theme->pane_w,
1575                         pane[BOTTOM_LEFT_PANE]->h);
1576                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1577                         mwindow->theme->mcanvas_x +
1578                                 cursor_x,
1579                         pane[BOTTOM_RIGHT_PANE]->y,
1580                         mwindow->theme->mcanvas_x +
1581                                 mwindow->theme->mcanvas_w -
1582                                 cursor_x,
1583                         pane[BOTTOM_RIGHT_PANE]->h);
1584
1585         }
1586 }
1587
1588
1589 void MWindowGUI::delete_x_pane(int cursor_x)
1590 {
1591 // give left panes coordinates of right pane
1592         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1593                 pane[TOP_RIGHT_PANE])
1594         {
1595                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1596                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1597                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1598                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1599                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1600                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1601                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1602         }
1603
1604         switch(total_panes())
1605         {
1606                 case 2:
1607                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1608                         {
1609 // delete right pane
1610                                 delete pane[TOP_RIGHT_PANE];
1611                                 pane[TOP_RIGHT_PANE] = 0;
1612                                 pane[TOP_LEFT_PANE]->resize_event(
1613                                         mwindow->theme->mcanvas_x,
1614                                         mwindow->theme->mcanvas_y,
1615                                         mwindow->theme->mcanvas_w,
1616                                         mwindow->theme->mcanvas_h);
1617
1618                         }
1619                         break;
1620
1621                 case 4:
1622 // delete right panes
1623                         delete pane[TOP_RIGHT_PANE];
1624                         pane[TOP_RIGHT_PANE] = 0;
1625                         delete pane[BOTTOM_RIGHT_PANE];
1626                         pane[BOTTOM_RIGHT_PANE] = 0;
1627                         pane[TOP_LEFT_PANE]->resize_event(
1628                                 mwindow->theme->mcanvas_x,
1629                                 pane[TOP_LEFT_PANE]->y,
1630                                 mwindow->theme->mcanvas_w,
1631                                 pane[TOP_LEFT_PANE]->h);
1632                         pane[BOTTOM_LEFT_PANE]->resize_event(
1633                                 mwindow->theme->mcanvas_x,
1634                                 pane[BOTTOM_LEFT_PANE]->y,
1635                                 mwindow->theme->mcanvas_w,
1636                                 pane[BOTTOM_LEFT_PANE]->h);
1637                         break;
1638         }
1639 }
1640
1641 void MWindowGUI::create_y_pane(int cursor_y)
1642 {
1643         if(total_panes() == 1)
1644         {
1645                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1646                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1647                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1648                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1649                         cursor_y -
1650                         mwindow->theme->mtimebar_h;
1651 // do this 1st so the resize_event knows there are 2 panes
1652                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1653                         BOTTOM_LEFT_PANE,
1654                         mwindow->theme->mcanvas_x,
1655                         mwindow->theme->mcanvas_y +
1656                                 cursor_y,
1657                         mwindow->theme->mcanvas_w,
1658                         mwindow->theme->mcanvas_h -
1659                                 cursor_y);
1660                 pane[TOP_LEFT_PANE]->resize_event(
1661                         mwindow->theme->mcanvas_x,
1662                         mwindow->theme->mcanvas_y,
1663                         mwindow->theme->mcanvas_w,
1664                         pane[BOTTOM_LEFT_PANE]->y -
1665                                 mwindow->theme->mcanvas_y -
1666                                 mwindow->theme->pane_h);
1667                 pane[BOTTOM_LEFT_PANE]->create_objects();
1668         }
1669         else
1670         if(horizontal_panes())
1671         {
1672 // create 2 panes
1673                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1674                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1675                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1676                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1677                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1678                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1679                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1680                         cursor_y -
1681                         mwindow->theme->mtimebar_h;
1682
1683                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1684                         BOTTOM_LEFT_PANE,
1685                         pane[TOP_LEFT_PANE]->x,
1686                         mwindow->theme->mcanvas_y +
1687                                 cursor_y,
1688                         pane[TOP_LEFT_PANE]->w,
1689                         mwindow->theme->mcanvas_h -
1690                                 cursor_y);
1691                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1692                         BOTTOM_RIGHT_PANE,
1693                         pane[TOP_RIGHT_PANE]->x,
1694                         mwindow->theme->mcanvas_y +
1695                                 cursor_y,
1696                         pane[TOP_RIGHT_PANE]->w,
1697                         mwindow->theme->mcanvas_h -
1698                                 cursor_y);
1699
1700                 pane[TOP_LEFT_PANE]->resize_event(
1701                         pane[TOP_LEFT_PANE]->x,
1702                         pane[TOP_LEFT_PANE]->y,
1703                         pane[TOP_LEFT_PANE]->w,
1704                         pane[BOTTOM_LEFT_PANE]->y -
1705                                 mwindow->theme->mcanvas_y -
1706                                 mwindow->theme->pane_h);
1707                 pane[TOP_RIGHT_PANE]->resize_event(
1708                         pane[TOP_RIGHT_PANE]->x,
1709                         pane[TOP_RIGHT_PANE]->y,
1710                         pane[TOP_RIGHT_PANE]->w,
1711                         pane[BOTTOM_RIGHT_PANE]->y -
1712                                 mwindow->theme->mcanvas_y -
1713                                 mwindow->theme->pane_h);
1714
1715                 pane[BOTTOM_LEFT_PANE]->create_objects();
1716                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1717         }
1718         else
1719         if(vertical_panes())
1720         {
1721 // resize a pane
1722                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1723                         cursor_y -
1724                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1725                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1726                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1727                 pane[TOP_LEFT_PANE]->resize_event(
1728                         mwindow->theme->mcanvas_x,
1729                         mwindow->theme->mcanvas_y,
1730                         mwindow->theme->mcanvas_w,
1731                         cursor_y - mwindow->theme->pane_h);
1732                 pane[BOTTOM_LEFT_PANE]->resize_event(
1733                         pane[BOTTOM_LEFT_PANE]->x,
1734                         cursor_y +
1735                                 mwindow->theme->mcanvas_y,
1736                         mwindow->theme->mcanvas_w,
1737                         mwindow->theme->mcanvas_h -
1738                                 cursor_y);
1739         }
1740         else
1741         {
1742 // resize 2 panes
1743                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1744                         cursor_y -
1745                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1746                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1747                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1748                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1749                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1750                 pane[TOP_LEFT_PANE]->resize_event(
1751                         pane[TOP_LEFT_PANE]->x,
1752                         pane[TOP_LEFT_PANE]->y,
1753                         pane[TOP_LEFT_PANE]->w,
1754                         cursor_y - mwindow->theme->pane_h);
1755                 pane[BOTTOM_LEFT_PANE]->resize_event(
1756                         pane[BOTTOM_LEFT_PANE]->x,
1757                         cursor_y +
1758                                 mwindow->theme->mcanvas_y,
1759                         pane[BOTTOM_LEFT_PANE]->w,
1760                         mwindow->theme->mcanvas_h -
1761                                         cursor_y);
1762                 pane[TOP_RIGHT_PANE]->resize_event(
1763                         pane[TOP_RIGHT_PANE]->x,
1764                         pane[TOP_RIGHT_PANE]->y,
1765                         pane[TOP_RIGHT_PANE]->w,
1766                         cursor_y - mwindow->theme->pane_h);
1767                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1768                         pane[BOTTOM_RIGHT_PANE]->x,
1769                         cursor_y +
1770                                 mwindow->theme->mcanvas_y,
1771                         pane[BOTTOM_RIGHT_PANE]->w,
1772                         mwindow->theme->mcanvas_h -
1773                                         cursor_y);
1774         }
1775 }
1776
1777 void MWindowGUI::delete_y_pane(int cursor_y)
1778 {
1779         if(cursor_y < mwindow->theme->mtimebar_h +
1780                 PANE_DRAG_MARGIN &&
1781                 pane[BOTTOM_LEFT_PANE])
1782         {
1783 // give top pane coordinates of bottom pane
1784                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1785                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1786                         pane[BOTTOM_LEFT_PANE]->y;
1787                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1788                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1789                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1790                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1791         }
1792
1793 // delete a pane
1794         switch(total_panes())
1795         {
1796                 case 2:
1797                         delete pane[BOTTOM_LEFT_PANE];
1798                         pane[BOTTOM_LEFT_PANE] = 0;
1799                         pane[TOP_LEFT_PANE]->resize_event(
1800                                 mwindow->theme->mcanvas_x,
1801                                 mwindow->theme->mcanvas_y,
1802                                 mwindow->theme->mcanvas_w,
1803                                 mwindow->theme->mcanvas_h);
1804                         break;
1805
1806                 case 4:
1807 // delete bottom 2 panes
1808
1809                         delete pane[BOTTOM_LEFT_PANE];
1810                         pane[BOTTOM_LEFT_PANE] = 0;
1811                         delete pane[BOTTOM_RIGHT_PANE];
1812                         pane[BOTTOM_RIGHT_PANE] = 0;
1813                         pane[TOP_LEFT_PANE]->resize_event(
1814                                 pane[TOP_LEFT_PANE]->x,
1815                                 mwindow->theme->mcanvas_y,
1816                                 pane[TOP_LEFT_PANE]->w,
1817                                 mwindow->theme->mcanvas_h);
1818                         pane[TOP_RIGHT_PANE]->resize_event(
1819                                 pane[TOP_RIGHT_PANE]->x,
1820                                 mwindow->theme->mcanvas_y,
1821                                 pane[TOP_RIGHT_PANE]->w,
1822                                 mwindow->theme->mcanvas_h);
1823                         break;
1824         }
1825 }
1826
1827 void MWindowGUI::stop_pane_drag()
1828 {
1829         if( !dragging_pane ) return;
1830         dragging_pane = 0;
1831         resource_thread->stop_draw(0);
1832
1833         if(x_pane_drag)
1834         {
1835 // cursor position relative to canvas
1836                 int cursor_x = x_pane_drag->get_x() -
1837                         get_x() -
1838                         BC_DisplayInfo::get_left_border() -
1839                         mwindow->theme->mcanvas_x +
1840                         mwindow->theme->pane_w;
1841                 delete x_pane_drag;
1842                 x_pane_drag = 0;
1843
1844
1845                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1846                         cursor_x < mwindow->theme->mcanvas_w -
1847                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1848                                 PANE_DRAG_MARGIN)
1849                 {
1850                         create_x_pane(cursor_x);
1851                         mwindow->edl->local_session->x_pane = cursor_x;
1852                 }
1853                 else
1854 // deleted a pane
1855                 {
1856                         delete_x_pane(cursor_x);
1857                         mwindow->edl->local_session->x_pane = -1;
1858                 }
1859
1860
1861         }
1862
1863         if(y_pane_drag)
1864         {
1865 // cursor position relative to canvas
1866                 int cursor_y = y_pane_drag->get_y() -
1867                         get_y() -
1868                         BC_DisplayInfo::get_top_border() -
1869                         mwindow->theme->mcanvas_y +
1870                         mwindow->theme->pane_h;
1871                 delete y_pane_drag;
1872                 y_pane_drag = 0;
1873
1874
1875
1876                 if(cursor_y >= mwindow->theme->mtimebar_h +
1877                                 PANE_DRAG_MARGIN &&
1878                         cursor_y < mwindow->theme->mcanvas_h -
1879                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1880                                 PANE_DRAG_MARGIN)
1881                 {
1882                         create_y_pane(cursor_y);
1883                         mwindow->edl->local_session->y_pane = cursor_y;
1884                 }
1885                 else
1886                 {
1887                         delete_y_pane(cursor_y);
1888                         mwindow->edl->local_session->y_pane = -1;
1889                 }
1890         }
1891
1892         update_pane_dividers();
1893         update_cursor();
1894 // required to get new widgets to appear
1895         show_window();
1896         resource_thread->start_draw();
1897 }
1898
1899 // create panes from EDL
1900 void MWindowGUI::load_panes()
1901 {
1902         int need_x_panes = 0;
1903         int need_y_panes = 0;
1904 // use names from create functions
1905         int cursor_x = mwindow->edl->local_session->x_pane;
1906         int cursor_y = mwindow->edl->local_session->y_pane;
1907
1908         resource_thread->stop_draw(1);
1909         if(cursor_x >=
1910                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1911                 cursor_x <
1912                 mwindow->theme->mcanvas_w -
1913                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1914                                 PANE_DRAG_MARGIN)
1915         {
1916                 need_x_panes = 1;
1917         }
1918
1919         if(cursor_y >=
1920                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1921                 cursor_y <
1922                 mwindow->theme->mcanvas_h -
1923                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1924                                 PANE_DRAG_MARGIN)
1925         {
1926                 need_y_panes = 1;
1927         }
1928
1929 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1930
1931
1932         if(need_x_panes)
1933         {
1934                 if(need_y_panes)
1935                 {
1936 // 4 panes
1937                         if(total_panes() == 1)
1938                         {
1939 // create 4 panes
1940 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1941                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1942                                         TOP_RIGHT_PANE,
1943                                         mwindow->theme->mcanvas_x +
1944                                                 cursor_x,
1945                                         mwindow->theme->mcanvas_y,
1946                                         mwindow->theme->mcanvas_x +
1947                                                 mwindow->theme->mcanvas_w -
1948                                                 cursor_x,
1949                                         cursor_y - mwindow->theme->pane_h);
1950                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1951                                         BOTTOM_LEFT_PANE,
1952                                         mwindow->theme->mcanvas_x,
1953                                         mwindow->theme->mcanvas_y +
1954                                                 cursor_y,
1955                                         cursor_x - mwindow->theme->pane_w,
1956                                         mwindow->theme->mcanvas_h -
1957                                                 cursor_y);
1958                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1959                                         BOTTOM_RIGHT_PANE,
1960                                         pane[TOP_RIGHT_PANE]->x,
1961                                         mwindow->theme->mcanvas_y +
1962                                                 cursor_y,
1963                                         pane[TOP_RIGHT_PANE]->w,
1964                                         mwindow->theme->mcanvas_h -
1965                                                 cursor_y);
1966                                 pane[TOP_LEFT_PANE]->resize_event(
1967                                         pane[TOP_LEFT_PANE]->x,
1968                                         pane[TOP_LEFT_PANE]->y,
1969                                         cursor_x - mwindow->theme->pane_w,
1970                                         cursor_y - mwindow->theme->pane_h);
1971                                 pane[TOP_RIGHT_PANE]->create_objects();
1972                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1973                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1974                         }
1975                         else
1976                         if(horizontal_panes())
1977                         {
1978 // create vertical panes
1979 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1980                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1981                                         BOTTOM_LEFT_PANE,
1982                                         mwindow->theme->mcanvas_x,
1983                                         mwindow->theme->mcanvas_y +
1984                                                 cursor_y,
1985                                         cursor_x - mwindow->theme->pane_w,
1986                                         mwindow->theme->mcanvas_h -
1987                                                 cursor_y);
1988                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1989                                         BOTTOM_RIGHT_PANE,
1990                                         pane[TOP_RIGHT_PANE]->x,
1991                                         mwindow->theme->mcanvas_y +
1992                                                 cursor_y,
1993                                         pane[TOP_RIGHT_PANE]->w,
1994                                         mwindow->theme->mcanvas_h -
1995                                                 cursor_y);
1996                                 pane[TOP_LEFT_PANE]->resize_event(
1997                                         pane[TOP_LEFT_PANE]->x,
1998                                         pane[TOP_LEFT_PANE]->y,
1999                                         cursor_x - mwindow->theme->pane_w,
2000                                         cursor_y - mwindow->theme->pane_h);
2001                                 pane[TOP_RIGHT_PANE]->resize_event(
2002                                         mwindow->theme->mcanvas_x +
2003                                                 cursor_x,
2004                                         mwindow->theme->mcanvas_y,
2005                                         mwindow->theme->mcanvas_x +
2006                                                 mwindow->theme->mcanvas_w -
2007                                                 cursor_x,
2008                                         cursor_y - mwindow->theme->pane_h);
2009                                 pane[BOTTOM_LEFT_PANE]->create_objects();
2010                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2011                         }
2012                         else
2013                         if(vertical_panes())
2014                         {
2015 // create horizontal panes
2016 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2017                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2018                                         TOP_RIGHT_PANE,
2019                                         mwindow->theme->mcanvas_x +
2020                                                 cursor_x,
2021                                         mwindow->theme->mcanvas_y,
2022                                         mwindow->theme->mcanvas_x +
2023                                                 mwindow->theme->mcanvas_w -
2024                                                 cursor_x,
2025                                         cursor_y - mwindow->theme->pane_h);
2026                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
2027                                         BOTTOM_RIGHT_PANE,
2028                                         pane[TOP_RIGHT_PANE]->x,
2029                                         mwindow->theme->mcanvas_y +
2030                                                 cursor_y,
2031                                         pane[TOP_RIGHT_PANE]->w,
2032                                         mwindow->theme->mcanvas_h -
2033                                                 cursor_y);
2034                                 pane[TOP_LEFT_PANE]->resize_event(
2035                                         pane[TOP_LEFT_PANE]->x,
2036                                         pane[TOP_LEFT_PANE]->y,
2037                                         cursor_x - mwindow->theme->pane_w,
2038                                         cursor_y - mwindow->theme->pane_h);
2039                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2040                                         pane[TOP_LEFT_PANE]->x,
2041                                         mwindow->theme->mcanvas_y +
2042                                                 cursor_y,
2043                                         mwindow->theme->mcanvas_x +
2044                                                 mwindow->theme->mcanvas_w -
2045                                                 cursor_x -  mwindow->theme->pane_w,
2046                                         mwindow->theme->mcanvas_h -
2047                                                 cursor_y);
2048                                 pane[TOP_RIGHT_PANE]->create_objects();
2049                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2050
2051
2052                         }
2053                         else
2054                         {
2055 // resize all panes
2056 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2057                                 pane[TOP_LEFT_PANE]->resize_event(
2058                                         pane[TOP_LEFT_PANE]->x,
2059                                         pane[TOP_LEFT_PANE]->y,
2060                                         cursor_x - mwindow->theme->pane_w,
2061                                         cursor_y - mwindow->theme->pane_h);
2062                                 pane[TOP_RIGHT_PANE]->resize_event(
2063                                         mwindow->theme->mcanvas_x +
2064                                                 cursor_x,
2065                                         mwindow->theme->mcanvas_y,
2066                                         mwindow->theme->mcanvas_x +
2067                                                 mwindow->theme->mcanvas_w -
2068                                                 cursor_x,
2069                                         cursor_y - mwindow->theme->pane_h);
2070                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2071                                         pane[TOP_LEFT_PANE]->x,
2072                                         mwindow->theme->mcanvas_y +
2073                                                 cursor_y,
2074                                         mwindow->theme->mcanvas_x +
2075                                                 mwindow->theme->mcanvas_w -
2076                                                 cursor_x - mwindow->theme->pane_w,
2077                                         mwindow->theme->mcanvas_h -
2078                                                 cursor_y);
2079                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2080                                         pane[TOP_RIGHT_PANE]->x,
2081                                         mwindow->theme->mcanvas_y +
2082                                                 cursor_y,
2083                                         pane[TOP_RIGHT_PANE]->w,
2084                                         mwindow->theme->mcanvas_h -
2085                                                 cursor_y);
2086
2087
2088                         }
2089                 }
2090                 else
2091                 {
2092 // 2 X panes
2093                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2094                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2095                         pane[BOTTOM_LEFT_PANE] = 0;
2096                         pane[BOTTOM_RIGHT_PANE] = 0;
2097
2098                         if(!pane[TOP_RIGHT_PANE])
2099                         {
2100                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2101                                         TOP_RIGHT_PANE,
2102                                         mwindow->theme->mcanvas_x +
2103                                                 cursor_x,
2104                                         mwindow->theme->mcanvas_y,
2105                                         mwindow->theme->mcanvas_x +
2106                                                 mwindow->theme->mcanvas_w -
2107                                                 cursor_x,
2108                                         mwindow->theme->mcanvas_h);
2109                                 pane[TOP_LEFT_PANE]->resize_event(
2110                                         mwindow->theme->mcanvas_x,
2111                                         mwindow->theme->mcanvas_y,
2112                                         cursor_x - mwindow->theme->pane_w,
2113                                         mwindow->theme->mcanvas_h);
2114                                 pane[TOP_RIGHT_PANE]->create_objects();
2115                         }
2116                         else
2117                         {
2118                                 pane[TOP_LEFT_PANE]->resize_event(
2119                                         mwindow->theme->mcanvas_x,
2120                                         mwindow->theme->mcanvas_y,
2121                                         cursor_x - mwindow->theme->pane_w,
2122                                         mwindow->theme->mcanvas_h);
2123                                 pane[TOP_RIGHT_PANE]->resize_event(
2124                                         mwindow->theme->mcanvas_x +
2125                                                 cursor_x,
2126                                         pane[TOP_RIGHT_PANE]->y,
2127                                         mwindow->theme->mcanvas_x +
2128                                                 mwindow->theme->mcanvas_w -
2129                                                 cursor_x,
2130                                         mwindow->theme->mcanvas_h);
2131                         }
2132                 }
2133         }
2134         else
2135         if(need_y_panes)
2136         {
2137 // 2 Y panes
2138                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2139                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2140                 pane[TOP_RIGHT_PANE] = 0;
2141                 pane[BOTTOM_RIGHT_PANE] = 0;
2142
2143                 if(!pane[BOTTOM_LEFT_PANE])
2144                 {
2145 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2146                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2147                                 BOTTOM_LEFT_PANE,
2148                                 mwindow->theme->mcanvas_x,
2149                                 mwindow->theme->mcanvas_y +
2150                                         cursor_y,
2151                                 mwindow->theme->mcanvas_w,
2152                                 mwindow->theme->mcanvas_h -
2153                                         cursor_y);
2154                         pane[TOP_LEFT_PANE]->resize_event(
2155                                 mwindow->theme->mcanvas_x,
2156                                 mwindow->theme->mcanvas_y,
2157                                 mwindow->theme->mcanvas_w,
2158                                 pane[BOTTOM_LEFT_PANE]->y -
2159                                         mwindow->theme->mcanvas_y -
2160                                         mwindow->theme->pane_h);
2161                         pane[BOTTOM_LEFT_PANE]->create_objects();
2162                 }
2163                 else
2164                 {
2165                         pane[TOP_LEFT_PANE]->resize_event(
2166                                 mwindow->theme->mcanvas_x,
2167                                 mwindow->theme->mcanvas_y,
2168                                 mwindow->theme->mcanvas_w,
2169                                 cursor_y - mwindow->theme->pane_h);
2170                         pane[BOTTOM_LEFT_PANE]->resize_event(
2171                                 pane[BOTTOM_LEFT_PANE]->x,
2172                                 cursor_y +
2173                                         mwindow->theme->mcanvas_y,
2174                                 mwindow->theme->mcanvas_w,
2175                                 mwindow->theme->mcanvas_h -
2176                                         cursor_y);
2177                 }
2178         }
2179         else
2180         {
2181 // 1 pane
2182                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2183                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2184                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2185                 pane[TOP_RIGHT_PANE] = 0;
2186                 pane[BOTTOM_RIGHT_PANE] = 0;
2187                 pane[BOTTOM_LEFT_PANE] = 0;
2188                 pane[TOP_LEFT_PANE]->resize_event(
2189                         mwindow->theme->mcanvas_x,
2190                         mwindow->theme->mcanvas_y,
2191                         mwindow->theme->mcanvas_w,
2192                         mwindow->theme->mcanvas_h);
2193         }
2194
2195         update_pane_dividers();
2196         show_window();
2197
2198         resource_thread->start_draw();
2199 }
2200
2201 void MWindowGUI::update_pane_dividers()
2202 {
2203
2204         if(horizontal_panes() || total_panes() == 4)
2205         {
2206                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2207                 int y = mwindow->theme->mcanvas_y;
2208                 int h = mwindow->theme->mcanvas_h;
2209
2210                 if(!x_divider)
2211                 {
2212                         add_subwindow(x_divider = new PaneDivider(
2213                                 mwindow, x, y, h, 1));
2214                         x_divider->create_objects();
2215                 }
2216                 else
2217                 {
2218                         x_divider->reposition_window(x, y, h);
2219                         x_divider->draw(0);
2220                 }
2221         }
2222         else
2223         {
2224                 if(x_divider)
2225                 {
2226                         delete x_divider;
2227                         x_divider = 0;
2228                 }
2229         }
2230
2231         if(vertical_panes() || total_panes() == 4)
2232         {
2233                 int x = mwindow->theme->mcanvas_x;
2234                 int y = pane[BOTTOM_LEFT_PANE]->y -
2235                         mwindow->theme->pane_h;
2236                 int w = mwindow->theme->mcanvas_w;
2237                 if(!y_divider)
2238                 {
2239                         add_subwindow(y_divider = new PaneDivider(
2240                                 mwindow, x, y, w, 0));
2241                         y_divider->create_objects();
2242                 }
2243                 else
2244                 {
2245                         y_divider->reposition_window(x, y, w);
2246                         y_divider->draw(0);
2247                 }
2248         }
2249         else
2250         {
2251                 if(y_divider)
2252                 {
2253                         delete y_divider;
2254                         y_divider = 0;
2255                 }
2256         }
2257 }
2258
2259 void MWindowGUI::draw_samplemovement()
2260 {
2261         draw_canvas(0, 1);
2262         show_cursor(1);
2263         flash_canvas(0);
2264         update_timebar(0);
2265         zoombar->update();
2266         update_scrollbars(1);
2267 }
2268
2269 void MWindowGUI::draw_trackmovement()
2270 {
2271         update_scrollbars(0);
2272         draw_canvas(0, 0);
2273         update_patchbay();
2274         flash_canvas(1);
2275 }
2276
2277
2278 void MWindowGUI::update_mixers(Track *track, int v)
2279 {
2280         for( int i=0; i<TOTAL_PANES;  ++i ) {
2281                 if( !pane[i] ) continue;
2282                 PatchBay *patchbay = pane[i]->patchbay;
2283                 if( !patchbay ) continue;
2284                 for( int j=0; j<patchbay->patches.total; ++j ) {
2285                         PatchGUI *patchgui = patchbay->patches.values[j];
2286                         if( !patchgui->mix ) continue;
2287                         if( !track || patchgui->track == track ) {
2288                                 patchgui->mix->update(v>=0 ? v :
2289                                         mwindow->mixer_track_active(patchgui->track));
2290                         }
2291                 }
2292         }
2293 }
2294
2295 void MWindowGUI::stop_transport(const char *lock_msg)
2296 {
2297         if( !mbuttons->transport->is_stopped() ) {
2298                 if( lock_msg ) unlock_window();
2299                 mbuttons->transport->handle_transport(STOP, 1);
2300                 if( lock_msg ) lock_window(lock_msg);
2301         }
2302 }
2303
2304 void MWindowGUI::close_keyvalue_popup()
2305 {
2306         if( !keyvalue_popup ) return;
2307         delete keyvalue_popup;
2308         keyvalue_popup = 0;
2309 }
2310
2311 void MWindowGUI::open_keyvalue_popup(BC_SubWindow *popup)
2312 {
2313         close_keyvalue_popup();
2314         keyvalue_popup = popup;
2315 }
2316
2317 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2318  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2319 {
2320         this->mwindow = mwindow;
2321 }
2322
2323 int PaneButton::cursor_motion_event()
2324 {
2325         if(get_top_level()->get_button_down() &&
2326                 is_event_win() &&
2327                 get_status() == BUTTON_DOWNHI &&
2328                 !cursor_inside())
2329         {
2330 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2331 // create drag bar
2332                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2333                 {
2334                         mwindow->gui->start_x_pane_drag();
2335                 }
2336                 else
2337                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2338                 {
2339                         mwindow->gui->start_y_pane_drag();
2340                 }
2341         }
2342
2343         mwindow->gui->handle_pane_drag();
2344
2345         int result = BC_Button::cursor_motion_event();
2346         return result;
2347 }
2348
2349 int PaneButton::button_release_event()
2350 {
2351         if( get_buttonpress() != WHEEL_DOWN && get_buttonpress() != WHEEL_UP )
2352                 mwindow->gui->stop_pane_drag();
2353         int result = BC_Button::button_release_event();
2354         return result;
2355 }
2356
2357
2358 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2359  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle,
2360          mwindow->preferences->get_file_probe_armed("FFMPEG_Early") > 0 ? 1 : 0)
2361 {
2362         this->mwindow = mwindow;
2363         this->mbuttons = mbuttons;
2364         set_tooltip(get_value() ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2365 }
2366
2367 FFMpegToggle::~FFMpegToggle()
2368 {
2369 }
2370
2371 int FFMpegToggle::handle_event()
2372 {
2373         int ffmpeg_early_probe = get_value();
2374         set_tooltip(ffmpeg_early_probe ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2375         mwindow->preferences->set_file_probe_armed("FFMPEG_Early", ffmpeg_early_probe);
2376         mwindow->preferences->set_file_probe_armed("FFMPEG_Late", !ffmpeg_early_probe);
2377         mwindow->update_preferences(mwindow->preferences);
2378         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2379                 _("Changing the base codecs may require rebuilding indexes."));
2380         return 1;
2381 }
2382
2383
2384 StackButton::StackButton(MWindow *mwindow, int x, int y)
2385  : BC_GenericButton(x, y, mwindow->theme->stack_button_w, "0")
2386 {
2387         this->mwindow = mwindow;
2388         set_tooltip(_("Close EDL"));
2389 }
2390
2391 int StackButton::handle_event()
2392 {
2393         mwindow->save_backup();
2394         mwindow->stack_pop();
2395         return 1;
2396 }
2397
2398 void StackButton::update()
2399 {
2400         char text[BCSTRLEN];
2401         int i = mwindow->stack.size();
2402         sprintf(text, "%d", i);
2403         set_text(text);
2404         draw_face();
2405 }
2406
2407
2408 ProxyToggle::ProxyToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2409  : BC_Toggle(x, y, ( !mwindow->edl->session->proxy_use_scaler ?
2410                         mwindow->theme->proxy_p_toggle :
2411                         mwindow->theme->proxy_s_toggle ),
2412                 mwindow->edl->session->proxy_disabled_scale != 1)
2413 {
2414         this->mwindow = mwindow;
2415         this->mbuttons = mbuttons;
2416         scaler_images = mwindow->edl->session->proxy_use_scaler;
2417         set_tooltip(mwindow->edl->session->proxy_disabled_scale==1 ?
2418                 _("Disable proxy") : _("Enable proxy"));
2419 }
2420
2421 void ProxyToggle::show()
2422 {
2423         int use_scaler = mwindow->edl->session->proxy_use_scaler;
2424         if( scaler_images != use_scaler )
2425                 set_images(!(scaler_images=use_scaler) ?
2426                         mwindow->theme->proxy_p_toggle :
2427                         mwindow->theme->proxy_s_toggle );
2428         draw_face(1, 0);
2429         if( is_hidden() )
2430                 show_window();
2431 }
2432
2433 void ProxyToggle::hide()
2434 {
2435         if( !is_hidden() )
2436                 hide_window();
2437 }
2438
2439 ProxyToggle::~ProxyToggle()
2440 {
2441 }
2442
2443 int ProxyToggle::handle_event()
2444 {
2445         int disabled = get_value();
2446         mwindow->gui->unlock_window();
2447         if( disabled )
2448                 mwindow->disable_proxy();
2449         else
2450                 mwindow->enable_proxy();
2451         mwindow->gui->lock_window("ProxyToggle::handle_event");
2452         set_tooltip(!disabled ? _("Disable proxy") : _("Enable proxy"));
2453         return 1;
2454 }
2455
2456 int ProxyToggle::keypress_event()
2457 {
2458         if( ctrl_down() && !shift_down() && !alt_down() ) {
2459                 int key = get_keypress();
2460                 if( key == 'r' ) {
2461                         int value = get_value() ? 0 : 1;
2462                         set_value(value);
2463                         return handle_event();
2464                 }
2465         }
2466         return 0;
2467 }
2468