prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / clipedit.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "awindow.h"
23 #include "awindowgui.h"
24 #include "bcsignals.h"
25 #include "clipedit.h"
26 #include "edl.h"
27 #include "fonts.h"
28 #include "language.h"
29 #include "localsession.h"
30 #include "mainsession.h"
31 #include "mwindow.h"
32 #include "mwindowgui.h"
33 #include "vwindow.h"
34 #include "vwindowgui.h"
35
36
37
38
39 ClipEdit::ClipEdit(MWindow *mwindow, AWindow *awindow, VWindow *vwindow)
40  : BC_DialogThread()
41 {
42         this->mwindow = mwindow;
43         this->awindow = awindow;
44         this->vwindow = vwindow;
45         this->clip = 0;
46         this->create_it = 0;
47 }
48
49 ClipEdit::~ClipEdit()
50 {
51         close_window();
52 }
53
54 // After the window is closed and deleted, this is called.
55 void ClipEdit::handle_close_event(int result)
56 {
57         if(!result)
58         {
59 // Add to EDL
60                 //EDL *new_edl = 0;
61                 if(create_it) // new_edl =
62                         mwindow->edl->add_clip(clip);
63
64 // Copy clip to existing clip in EDL
65                 if(!create_it)
66                         original->copy_session(clip);
67
68
69 //                      mwindow->vwindow->gui->update_sources(mwindow->vwindow->gui->source->get_text());
70
71
72                 mwindow->awindow->gui->lock_window();
73                 mwindow->awindow->gui->update_assets();
74                 mwindow->awindow->gui->flush();
75                 mwindow->awindow->gui->unlock_window();
76
77 // Change VWindow to it if vwindow was called
78 // But this doesn't let you easily create a lot of clips.
79                 if(vwindow && create_it)
80                 {
81 //                              vwindow->change_source(new_edl);
82                 }
83         }
84         else
85         {
86                 mwindow->session->clip_number--;
87         }
88
89
90
91 // For creating new clips, the original was copied in add_clip.
92 // For editing old clips, the original was transferred to another variable.
93         if(!create_it) clip->remove_user();
94         original = 0;
95         clip = 0;
96         create_it = 0;
97 }
98
99
100 // User creates the window and initializes it here.
101 BC_Window* ClipEdit::new_gui()
102 {
103         original = clip;
104
105         if(!create_it)
106         {
107                 this->clip = new EDL(mwindow->edl);
108                 clip->create_objects();
109                 clip->copy_all(original);
110         }
111
112
113         window = new ClipEditWindow(mwindow, this);
114         window->create_objects();
115         return window;
116 }
117
118
119
120 void ClipEdit::edit_clip(EDL *clip)
121 {
122 // Allow more than one window so we don't have to delete the clip in handle_event
123         if(!this->clip)
124         {
125                 this->clip = clip;
126                 this->create_it = 0;
127                 start();
128         }
129 }
130
131 void ClipEdit::create_clip(EDL *clip)
132 {
133 // Allow more than one window so we don't have to delete the clip in handle_event
134         if(!this->clip)
135         {
136                 this->clip = clip;
137                 this->create_it = 1;
138                 start();
139         }
140 }
141
142
143
144
145
146
147
148
149 ClipEditWindow::ClipEditWindow(MWindow *mwindow, ClipEdit *thread)
150  : BC_Window(_(PROGRAM_NAME ": Clip Info"), 
151         mwindow->gui->get_abs_cursor_x(1) - 400 / 2,
152         mwindow->gui->get_abs_cursor_y(1) - 350 / 2,
153         400, 
154         350,
155         400,
156         430,
157         0,
158         0,
159         1)
160 {
161         this->mwindow = mwindow;
162         this->thread = thread;
163 }
164
165 ClipEditWindow::~ClipEditWindow()
166 {
167 }
168
169         
170 void ClipEditWindow::create_objects()
171 {
172         lock_window("ClipEditWindow::create_objects");
173         this->create_it = thread->create_it;
174
175         int x = 10, y = 10;
176         int x1 = x;
177         BC_TextBox *textbox;
178         BC_TextBox *titlebox;
179         BC_Title *title;
180
181         add_subwindow(title = new BC_Title(x1, y, _("Title:")));
182         y += title->get_h() + 5;
183         add_subwindow(titlebox = new ClipEditTitle(this, x1, y, get_w() - x1 * 2));
184         y += titlebox->get_h() + 10;
185         add_subwindow(title = new BC_Title(x1, y, _("Comments:")));
186         y += title->get_h() + 5;
187         add_subwindow(textbox = new ClipEditComments(this, 
188                 x1, 
189                 y, 
190                 get_w() - x1 * 2, 
191                 BC_TextBox::pixels_to_rows(this, 
192                         MEDIUMFONT, 
193                         get_h() - 10 - BC_OKButton::calculate_h() - y)));
194
195
196
197         add_subwindow(new BC_OKButton(this));
198         add_subwindow(new BC_CancelButton(this));
199         show_window();
200         titlebox->activate();
201         unlock_window();
202 }
203
204
205
206
207
208 ClipEditTitle::ClipEditTitle(ClipEditWindow *window, int x, int y, int w)
209  : BC_TextBox(x, y, w, 1, window->thread->clip->local_session->clip_title)
210 {
211         this->window = window;
212 }
213
214 int ClipEditTitle::handle_event()
215 {
216         strcpy(window->thread->clip->local_session->clip_title, get_text());
217         return 1;
218 }
219
220
221
222
223
224 ClipEditComments::ClipEditComments(ClipEditWindow *window, int x, int y, int w, int rows)
225  : BC_TextBox(x, y, w, rows, window->thread->clip->local_session->clip_notes)
226 {
227         this->window = window;
228 }
229
230 int ClipEditComments::handle_event()
231 {
232         strcpy(window->thread->clip->local_session->clip_notes, get_text());
233         return 1;
234 }