r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindowgui.C
blobecea0491c889c5246c342f90b167975a9e881ea2
1 #include "awindow.h"
2 #include "awindowgui.h"
3 #include "cwindow.h"
4 #include "cwindowgui.h"
5 #include "defaults.h"
6 #include "editpopup.h"
7 #include "edl.h"
8 #include "edlsession.h"
9 #include "filesystem.h"
10 #include "keys.h"
11 #include "localsession.h"
12 #include "mainclock.h"
13 #include "mainmenu.h"
14 #include "samplescroll.h"
15 #include "mainundo.h"
16 #include "maincursor.h"
17 #include "mbuttons.h"
18 #include "mtimebar.h"
19 #include "mwindow.h"
20 #include "mwindowgui.h"
21 #include "patchbay.h"
22 #include "pluginpopup.h"
23 #include "mainsession.h"
24 #include "statusbar.h"
25 #include "zoombar.h"
26 #include "theme.h"
27 #include "trackcanvas.h"
28 #include "tracks.h"
29 #include "trackscroll.h"
30 #include "transitionpopup.h"
31 #include "vwindow.h"
32 #include "vwindowgui.h"
34 #include <libintl.h>
35 #define _(String) gettext(String)
36 #define gettext_noop(String) String
37 #define N_(String) gettext_noop (String)
39 // the main window uses its own private colormap for video
40 MWindowGUI::MWindowGUI(MWindow *mwindow)
41  : BC_Window(PROGRAM_NAME ": Program", 
42                 mwindow->session->mwindow_x, 
43                 mwindow->session->mwindow_y, 
44                 mwindow->session->mwindow_w, 
45                 mwindow->session->mwindow_h, 
46                 100,
47                 100,
48                 1,
49                 1,
50                 1)
52         this->mwindow = mwindow;
53         samplescroll = 0;
54         trackscroll = 0;
55         cursor = 0;
56         canvas = 0;
60 MWindowGUI::~MWindowGUI()
62         delete mbuttons;
63         delete statusbar;
64         delete zoombar;
65         if(samplescroll) delete samplescroll;
66         if(trackscroll) delete trackscroll;
67         delete cursor;
68         delete patchbay;
69         delete timebar;
70         delete mainclock;
71         delete plugin_menu;
72         delete transition_menu;
75 void MWindowGUI::get_scrollbars()
77 //printf("MWindowGUI::get_scrollbars 1\n");
78         int64_t h_needed = mwindow->edl->get_tracks_height(mwindow->theme);
79         int64_t w_needed = mwindow->edl->get_tracks_width();
80         int need_xscroll = 0;
81         int need_yscroll = 0;
82         view_w = mwindow->theme->mcanvas_w;
83         view_h = mwindow->theme->mcanvas_h;
84 //printf("MWindowGUI::get_scrollbars 1\n");
86 // Scrollbars are constitutive
87         need_xscroll = need_yscroll = 1;
88         view_h = mwindow->theme->mcanvas_h - BC_ScrollBar::get_span(SCROLL_VERT);
89         view_w = mwindow->theme->mcanvas_w - BC_ScrollBar::get_span(SCROLL_HORIZ);
91 //      for(int i = 0; i < 2; i++)
92 //      {
93 //              if(w_needed > view_w)
94 //              {
95 //                      need_xscroll = 1;
96 //                      view_h = mwindow->theme->mcanvas_h - SCROLL_SPAN;
97 //              }
98 //              else
99 //                      need_xscroll = 0;
100 // 
101 //              if(h_needed > view_h)
102 //              {
103 //                      need_yscroll = 1;
104 //                      view_w = mwindow->theme->mcanvas_w - SCROLL_SPAN;
105 //              }
106 //              else
107 //                      need_yscroll = 0;
108 //      }
109 //printf("MWindowGUI::get_scrollbars 1\n");
111         if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
112         {
113                 canvas->reposition_window(mwindow->theme->mcanvas_x,
114                         mwindow->theme->mcanvas_y,
115                         view_w,
116                         view_h);
117         }
118 //printf("MWindowGUI::get_scrollbars 1\n");
120         if(need_xscroll)
121         {
122                 if(!samplescroll)
123                         add_subwindow(samplescroll = new SampleScroll(mwindow, 
124                                 this, 
125                                 view_w));
126                 else
127                         samplescroll->resize_event();
129                 samplescroll->set_position();
130         }
131         else
132         {
133                 if(samplescroll) delete samplescroll;
134                 samplescroll = 0;
135                 mwindow->edl->local_session->view_start = 0;
136         }
137 //printf("MWindowGUI::get_scrollbars 1\n");
139         if(need_yscroll)
140         {
141 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
142                 if(!trackscroll)
143                         add_subwindow(trackscroll = new TrackScroll(mwindow, 
144                                 this,
145                                 view_h));
146                 else
147                         trackscroll->resize_event();
150 //printf("MWindowGUI::get_scrollbars 1.2\n");
151                 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
152                         mwindow->edl->local_session->track_start,
153                         view_h);
154 //printf("MWindowGUI::get_scrollbars 1.3\n");
155         }
156         else
157         {
158                 if(trackscroll) delete trackscroll;
159                 trackscroll = 0;
160                 mwindow->edl->local_session->track_start = 0;
161         }
162 //printf("get_scrollbars 2 %d %d\n", need_xscroll, w_needed);
165 int MWindowGUI::create_objects()
167 //printf("MWindowGUI::create_objects 1\n");
168         set_icon(mwindow->theme->mwindow_icon);
169         
170 //printf("MWindowGUI::create_objects 1\n");
172         cursor = 0;
173         add_subwindow(mainmenu = new MainMenu(mwindow, this));
174 //printf("MWindowGUI::create_objects 1\n");
176         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
177         mwindow->theme->draw_mwindow_bg(this);
178         mainmenu->create_objects();
179 //printf("MWindowGUI::create_objects 1\n");
181         add_subwindow(mbuttons = new MButtons(mwindow, this));
182         mbuttons->create_objects();
183 //printf("MWindowGUI::create_objects 1\n");
185         add_subwindow(mwindow->timebar = timebar = new MTimeBar(mwindow, 
186                 this,
187                 mwindow->theme->mtimebar_x,
188                 mwindow->theme->mtimebar_y,
189                 mwindow->theme->mtimebar_w,
190                 mwindow->theme->mtimebar_h));
191         timebar->create_objects();
192 //printf("MWindowGUI::create_objects 2\n");
194         add_subwindow(mwindow->patches = patchbay = new PatchBay(mwindow, this));
195         patchbay->create_objects();
196 //printf("MWindowGUI::create_objects 1\n");
198         get_scrollbars();
200 //printf("MWindowGUI::create_objects 1\n");
201         mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
202         canvas->create_objects();
203 //printf("MWindowGUI::create_objects 1\n");
205         add_subwindow(zoombar = new ZoomBar(mwindow, this));
206         zoombar->create_objects();
207 //printf("MWindowGUI::create_objects 1\n");
209         add_subwindow(statusbar = new StatusBar(mwindow, this));
210         statusbar->create_objects();
211 //printf("MWindowGUI::create_objects 1\n");
213         add_subwindow(mainclock = new MainClock(mwindow, 
214                 mwindow->theme->mclock_x,
215                 mwindow->theme->mclock_y,
216                 mwindow->theme->mclock_w));
217         mainclock->update(0);
219 //printf("MWindowGUI::create_objects 1\n");
221         cursor = new MainCursor(mwindow, this);
222         cursor->create_objects();
223 //printf("MWindowGUI::create_objects 1\n");
225         add_subwindow(edit_menu = new EditPopup(mwindow, this));
226         edit_menu->create_objects();
227 //printf("MWindowGUI::create_objects 1\n");
229         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
230         plugin_menu->create_objects();
231 //printf("MWindowGUI::create_objects 1\n");
233         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
234         transition_menu->create_objects();
235 //printf("MWindowGUI::create_objects 1\n");
237         canvas->activate();
238 //printf("MWindowGUI::create_objects 1\n");
239         return 0;
242 void MWindowGUI::update_title(char *path)
244         FileSystem fs;
245         char filename[BCTEXTLEN], string[BCTEXTLEN];
246         fs.extract_name(filename, path);
247         sprintf(string, PROGRAM_NAME ": %s", filename);
248         set_title(string);
249 //printf("MWindowGUI::update_title %s\n", string);
250         flush();
253 void MWindowGUI::redraw_time_dependancies() 
255         zoombar->redraw_time_dependancies();
256         timebar->update();
257         mainclock->update(mwindow->edl->local_session->selectionstart);
260 int MWindowGUI::resize_event(int w, int h)
262         mwindow->session->mwindow_w = w;
263         mwindow->session->mwindow_h = h;
264         mwindow->theme->get_mwindow_sizes(this, w, h);
265         mwindow->theme->draw_mwindow_bg(this);
266         flash();
267         mainmenu->reposition_window(0, 0, w, mainmenu->get_h());
268         mbuttons->resize_event();
269         statusbar->resize_event();
270         timebar->resize_event();
271         patchbay->resize_event();
272         zoombar->resize_event();
273         get_scrollbars();
274         canvas->resize_event();
275         return 0;
279 void MWindowGUI::update(int scrollbars,
280         int canvas,
281         int timebar,
282         int zoombar,
283         int patchbay, 
284         int clock,
285         int buttonbar)
287         mwindow->edl->tracks->update_y_pixels(mwindow->theme);
288         if(scrollbars) this->get_scrollbars();
289         if(timebar) this->timebar->update();
290         if(zoombar) this->zoombar->update();
291         if(patchbay) this->patchbay->update();
292         if(clock) this->mainclock->update(mwindow->edl->local_session->selectionstart);
293         if(canvas)
294         {
295                 this->canvas->draw(canvas == 2);
296                 this->cursor->show();
297                 this->canvas->flash();
298                 this->canvas->activate();
299         }
300         if(buttonbar) mbuttons->update();
303 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
305         return (x1 >= view_x1 && x1 < view_x2) ||
306                 (x2 > view_x1 && x2 <= view_x2) ||
307                 (x1 <= view_x1 && x2 >= view_x2);
311 int MWindowGUI::show_message(char *message, int color)
313 //printf("MWindowGUI::show_message %s %d\n", message, color);
314         statusbar->status_text->set_color(color);
315         statusbar->status_text->update(message);
316         return 0;
319 // Drag motion called from other window
320 int MWindowGUI::drag_motion()
322         if(get_hidden()) return 0;
324         canvas->drag_motion();
325         return 0;
328 int MWindowGUI::drag_stop()
330         if(get_hidden()) return 0;
332         int result = canvas->drag_stop();
333         return result;
336 void MWindowGUI::default_positions()
338 //printf("MWindowGUI::default_positions 1\n");
339         mwindow->vwindow->gui->lock_window();
340         mwindow->cwindow->gui->lock_window();
341         mwindow->awindow->gui->lock_window();
343 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x, 
344 // mwindow->session->vwindow_y,
345 // mwindow->session->vwindow_w, 
346 // mwindow->session->vwindow_h);
347         reposition_window(mwindow->session->mwindow_x, 
348                 mwindow->session->mwindow_y,
349                 mwindow->session->mwindow_w, 
350                 mwindow->session->mwindow_h);
351         mwindow->vwindow->gui->reposition_window(mwindow->session->vwindow_x, 
352                 mwindow->session->vwindow_y,
353                 mwindow->session->vwindow_w, 
354                 mwindow->session->vwindow_h);
355         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x, 
356                 mwindow->session->cwindow_y,
357                 mwindow->session->cwindow_w, 
358                 mwindow->session->cwindow_h);
359         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x, 
360                 mwindow->session->awindow_y,
361                 mwindow->session->awindow_w, 
362                 mwindow->session->awindow_h);
363 //printf("MWindowGUI::default_positions 1\n");
365         resize_event(mwindow->session->mwindow_w, 
366                 mwindow->session->mwindow_h);
367 //printf("MWindowGUI::default_positions 1\n");
368         mwindow->vwindow->gui->resize_event(mwindow->session->vwindow_w, 
369                 mwindow->session->vwindow_h);
370 //printf("MWindowGUI::default_positions 1\n");
371         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w, 
372                 mwindow->session->cwindow_h);
373 //printf("MWindowGUI::default_positions 1\n");
374         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w, 
375                 mwindow->session->awindow_h);
377 //printf("MWindowGUI::default_positions 1\n");
379         flush();
380         mwindow->vwindow->gui->flush();
381         mwindow->cwindow->gui->flush();
382         mwindow->awindow->gui->flush();
384         mwindow->vwindow->gui->unlock_window();
385         mwindow->cwindow->gui->unlock_window();
386         mwindow->awindow->gui->unlock_window();
387 //printf("MWindowGUI::default_positions 2\n");
406 int MWindowGUI::repeat_event(int64_t duration)
408         return cursor->repeat_event(duration);
412 int MWindowGUI::translation_event()
414 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
415         mwindow->session->mwindow_x = get_x();
416         mwindow->session->mwindow_y = get_y();
417         return 0;
421 int MWindowGUI::save_defaults(Defaults *defaults)
423         defaults->update("MWINDOWWIDTH", get_w());
424         defaults->update("MWINDOWHEIGHT", get_h());
425         mainmenu->save_defaults(defaults);
426         BC_WindowBase::save_defaults(defaults);
429 int MWindowGUI::keypress_event()
431 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
432         int result = 0;
433         result = mbuttons->keypress_event();
434         return result;
438 int MWindowGUI::close_event() 
440         mainmenu->quit(); 
443 int MWindowGUI::menu_h()
445         return mainmenu->get_h();