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