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