r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / quit.C
blobe4adf1da9e308bba21310050cc771d317ef314f7
1 #include "assets.h"
2 #include "mbuttons.h"
3 #include "confirmquit.h"
4 #include "errorbox.h"
5 #include "language.h"
6 #include "levelwindow.h"
7 #include "levelwindowgui.h"
8 #include "mainmenu.h"
9 #include "mwindow.h"
10 #include "mwindowgui.h"
11 #include "playback3d.h"
12 #include "quit.h"
13 #include "record.h"
14 #include "render.h"
15 #include "savefile.h"
16 #include "mainsession.h"
17 #include "videowindow.h"
18 #include "videowindowgui.h"
21 Quit::Quit(MWindow *mwindow)
22  : BC_MenuItem(_("Quit"), "q", 'q'), Thread() 
23
24         this->mwindow = mwindow; 
26 int Quit::create_objects(Save *save)
27
28         this->save = save; 
29         return 0;
32 int Quit::handle_event() 
35 //printf("Quit::handle_event 1 %d\n", mwindow->session->changes_made);
36         if(mwindow->session->changes_made ||
37                 mwindow->gui->mainmenu->record->current_state ||
38                 mwindow->render->in_progress) 
39         {
40                 start();
41         }
42         else 
43         {        // quit
44                 mwindow->gui->unlock_window();
45                 mwindow->interrupt_indexes();
46 //              mwindow->gui->set_done(0);
47 //              BC_WindowBase::get_resources()->synchronous->quit();
48                 mwindow->playback_3d->quit();
49                 mwindow->gui->lock_window();
50         }
51         return 0;
54 void Quit::run()
56         int result = 0;
57 // Test execution conditions
58         if(mwindow->gui->mainmenu->record->current_state == RECORD_CAPTURING)
59         {
60                 ErrorBox error(PROGRAM_NAME ": Error", 
61                         mwindow->gui->get_abs_cursor_x(1), 
62                         mwindow->gui->get_abs_cursor_y(1));
63                 error.create_objects(_("Can't quit while a recording is in progress."));
64                 error.run_window();
65                 return;
66         }
67         else
68         if(mwindow->render->running())
69         {
70                 ErrorBox error(PROGRAM_NAME ": Error", 
71                         mwindow->gui->get_abs_cursor_x(1), 
72                         mwindow->gui->get_abs_cursor_y(1));
73                 error.create_objects(_("Can't quit while a render is in progress."));
74                 error.run_window();
75                 return;
76         }
79 //printf("Quit::run 1\n");
81 // Quit
82         {
83 //printf("Quit::run 2\n");
84                 ConfirmQuitWindow confirm(mwindow);
85 //printf("Quit::run 2\n");
86                 confirm.create_objects(_("Save edit list before exiting?"));
87 //printf("Quit::run 2\n");
88                 result = confirm.run_window();
89 //printf("Quit::run 2\n");
90         }
91 //printf("Quit::run 3\n");
93         switch(result)
94         {
95                 case 0:          // quit
96                         if(mwindow->gui)
97                         {
98                                 mwindow->interrupt_indexes();
99 // Last command in program
100 //                              mwindow->gui->set_done(0);
101 //                              BC_WindowBase::get_resources()->synchronous->quit();
102                                 mwindow->playback_3d->quit();
103                         }
104                         break;
106                 case 1:        // cancel
107                         return;
108                         break;
110                 case 2:           // save
111                         save->save_before_quit(); 
112                         return;
113                         break;
114         }