folder icon move segv, resources drag scroll bug, memory leaks, global msgqual, po...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / appearanceprefs.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 "appearanceprefs.h"
23 #include "deleteallindexes.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "file.h"
27 #include "filesystem.h"
28 #include "language.h"
29 #include "mwindow.h"
30 #include "preferences.h"
31 #include "preferencesthread.h"
32 #include "shbtnprefs.h"
33 #include "theme.h"
34
35
36 AppearancePrefs::AppearancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
37  : PreferencesDialog(mwindow, pwindow)
38 {
39         hms = 0;
40         hmsf = 0;
41         samples = 0;
42         frames = 0;
43         hex = 0;
44         feet = 0;
45         thumbnails = 0;
46 }
47
48 AppearancePrefs::~AppearancePrefs()
49 {
50         delete hms;
51         delete hmsf;
52         delete samples;
53         delete frames;
54         delete hex;
55         delete feet;
56         delete thumbnails;
57 }
58
59
60 void AppearancePrefs::create_objects()
61 {
62         BC_Resources *resources = BC_WindowBase::get_resources();
63         int margin = mwindow->theme->widget_border;
64         char string[BCTEXTLEN];
65         int x0 = mwindow->theme->preferencesoptions_x;
66         int y0 = mwindow->theme->preferencesoptions_y;
67         int x = x0, y = y0, x1 = x + 100;
68
69         add_subwindow(new BC_Title(x, y, _("Layout:"), LARGEFONT,
70                 resources->text_default));
71         y += 35;
72
73         ViewTheme *theme;
74         add_subwindow(new BC_Title(x, y, _("Theme:")));
75         add_subwindow(theme = new ViewTheme(x1, y, pwindow));
76         theme->create_objects();
77         y += theme->get_h() + 5;
78
79         x = x0;
80         ViewPluginIcons *plugin_icons;
81         add_subwindow(new BC_Title(x, y, _("Plugin Icons:")));
82         add_subwindow(plugin_icons = new ViewPluginIcons(x1, y, pwindow));
83         plugin_icons->create_objects();
84         y += plugin_icons->get_h() + 5;
85
86         y += 10;
87         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
88         y += 15;
89
90         add_subwindow(new BC_Title(x, y, _("Time Format:"), LARGEFONT,
91                 resources->text_default));
92
93         x1 = get_w()/2;
94         add_subwindow(new BC_Title(x1, y, _("Flags:"), LARGEFONT,
95                 resources->text_default));
96
97         y += get_text_height(LARGEFONT) + 5;
98         y += 10;
99         int y1 = y;
100
101         add_subwindow(hms = new TimeFormatHMS(pwindow, this,
102                 pwindow->thread->edl->session->time_format == TIME_HMS,
103                 x, y));
104         y += 20;
105         add_subwindow(hmsf = new TimeFormatHMSF(pwindow, this,
106                 pwindow->thread->edl->session->time_format == TIME_HMSF,
107                 x, y));
108         y += 20;
109         add_subwindow(samples = new TimeFormatSamples(pwindow, this,
110                 pwindow->thread->edl->session->time_format == TIME_SAMPLES,
111                 x, y));
112         y += 20;
113         add_subwindow(hex = new TimeFormatHex(pwindow, this,
114                 pwindow->thread->edl->session->time_format == TIME_SAMPLES_HEX,
115                 x, y));
116         y += 20;
117         add_subwindow(frames = new TimeFormatFrames(pwindow, this,
118                 pwindow->thread->edl->session->time_format == TIME_FRAMES,
119                 x, y));
120         y += 20;
121         add_subwindow(feet = new TimeFormatFeet(pwindow, this,
122                 pwindow->thread->edl->session->time_format == TIME_FEET_FRAMES,
123                 x, y));
124         x += feet->get_w() + 15;
125         BC_Title *title;
126         add_subwindow(title = new BC_Title(x, y, _("Frames per foot:")));
127         x += title->get_w() + margin;
128         sprintf(string, "%0.2f", pwindow->thread->edl->session->frames_per_foot);
129         add_subwindow(new TimeFormatFeetSetting(pwindow,
130                 x, y - 5,       string));
131         x = x0;
132         y += 20;
133         add_subwindow(seconds = new TimeFormatSeconds(pwindow, this,
134                 pwindow->thread->edl->session->time_format == TIME_SECONDS,
135                 x, y));
136         x = x0;
137         y += 35;
138         add_subwindow(title = new BC_Title(x, y, _("Highlighting Inversion color:")));
139         x += title->get_w() + margin;
140         char hex_color[BCSTRLEN];
141         sprintf(hex_color, "%06x", preferences->highlight_inverse);
142         add_subwindow(new HighlightInverseColor(pwindow, x, y, hex_color));
143         y += 35;
144
145         UseTipWindow *tip_win = new UseTipWindow(pwindow, x1, y1);
146         add_subwindow(tip_win);
147         y1 += tip_win->get_h() + 5;
148         UseWarnIndecies *idx_win = new UseWarnIndecies(pwindow, x1, y1);
149         add_subwindow(idx_win);
150         y1 += idx_win->get_h() + 5;
151         UseWarnVersion *ver_win = new UseWarnVersion(pwindow, x1, y1);
152         add_subwindow(ver_win);
153         y1 += ver_win->get_h() + 5;
154         BD_WarnRoot *bdwr_win = new BD_WarnRoot(pwindow, x1, y1);
155         add_subwindow(bdwr_win);
156         y1 += bdwr_win->get_h() + 5;
157         PopupMenuBtnup *pop_win = new PopupMenuBtnup(pwindow, x1, y1);
158         add_subwindow(pop_win);
159         y1 += pop_win->get_h() + 5;
160         GrabFocusPolicy *grab_input_focus = new GrabFocusPolicy(pwindow, x1, y1);
161         add_subwindow(grab_input_focus);
162         y1 += grab_input_focus->get_h() + 5;
163         ActivateFocusPolicy *focus_activate = new ActivateFocusPolicy(pwindow, x1, y1);
164         add_subwindow(focus_activate);
165         y1 += focus_activate->get_h() + 5;
166         DeactivateFocusPolicy *focus_deactivate = new DeactivateFocusPolicy(pwindow, x1, y1);
167         add_subwindow(focus_deactivate);
168         y1 += focus_deactivate->get_h() + 5;
169         ForwardRenderDisplacement *displacement = new ForwardRenderDisplacement(pwindow, x1, y1);
170         add_subwindow(displacement);
171         y1 += displacement->get_h() + 5;
172         add_subwindow(thumbnails = new ViewThumbnails(x1, y1, pwindow));
173         if( y < y1 ) y = y1;
174 }
175
176 int AppearancePrefs::update(int new_value)
177 {
178         pwindow->thread->redraw_times = 1;
179         pwindow->thread->edl->session->time_format = new_value;
180         hms->update(new_value == TIME_HMS);
181         hmsf->update(new_value == TIME_HMSF);
182         samples->update(new_value == TIME_SAMPLES);
183         hex->update(new_value == TIME_SAMPLES_HEX);
184         frames->update(new_value == TIME_FRAMES);
185         feet->update(new_value == TIME_FEET_FRAMES);
186         seconds->update(new_value == TIME_SECONDS);
187         return 0;
188 }
189
190
191 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
192  : BC_Radial(x, y, value, TIME_HMS_TEXT)
193 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
194
195 int TimeFormatHMS::handle_event()
196 {
197         tfwindow->update(TIME_HMS);
198         return 1;
199 }
200
201 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
202  : BC_Radial(x, y, value, TIME_HMSF_TEXT)
203 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
204
205 int TimeFormatHMSF::handle_event()
206 {
207         tfwindow->update(TIME_HMSF);
208         return 1;
209 }
210
211 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
212  : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
213 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
214
215 int TimeFormatSamples::handle_event()
216 {
217         tfwindow->update(TIME_SAMPLES);
218         return 1;
219 }
220
221 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
222  : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
223 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
224
225 int TimeFormatFrames::handle_event()
226 {
227         tfwindow->update(TIME_FRAMES);
228         return 1;
229 }
230
231 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
232  : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
233 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
234
235 int TimeFormatHex::handle_event()
236 {
237         tfwindow->update(TIME_SAMPLES_HEX);
238         return 1;
239 }
240
241 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
242  : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
243 {
244         this->pwindow = pwindow;
245         this->tfwindow = tfwindow;
246 }
247
248 int TimeFormatSeconds::handle_event()
249 {
250         tfwindow->update(TIME_SECONDS);
251         return 1;
252 }
253
254 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
255  : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
256 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
257
258 int TimeFormatFeet::handle_event()
259 {
260         tfwindow->update(TIME_FEET_FRAMES);
261         return 1;
262 }
263
264 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
265  : BC_TextBox(x, y, 90, 1, string)
266 { this->pwindow = pwindow; }
267
268 int TimeFormatFeetSetting::handle_event()
269 {
270         pwindow->thread->edl->session->frames_per_foot = atof(get_text());
271         if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
272         return 0;
273 }
274
275
276 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
277  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
278 {
279         this->pwindow = pwindow;
280 }
281 ViewTheme::~ViewTheme()
282 {
283 }
284
285 void ViewTheme::create_objects()
286 {
287         ArrayList<PluginServer*> themes;
288         MWindow::search_plugindb(0, 0, 0, 0, 1, themes);
289
290         for(int i = 0; i < themes.total; i++) {
291                 add_item(new ViewThemeItem(this, themes.values[i]->title));
292         }
293 }
294
295 int ViewTheme::handle_event()
296 {
297         return 1;
298 }
299
300 ViewThemeItem::ViewThemeItem(ViewTheme *popup, const char *text)
301  : BC_MenuItem(text)
302 {
303         this->popup = popup;
304 }
305
306 int ViewThemeItem::handle_event()
307 {
308         popup->set_text(get_text());
309         strcpy(popup->pwindow->thread->preferences->theme, get_text());
310         popup->handle_event();
311         return 1;
312 }
313
314
315 ViewPluginIcons::ViewPluginIcons(int x, int y, PreferencesWindow *pwindow)
316  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->plugin_icons, 1)
317 {
318         this->pwindow = pwindow;
319 }
320 ViewPluginIcons::~ViewPluginIcons()
321 {
322 }
323
324 void ViewPluginIcons::create_objects()
325 {
326         add_item(new ViewPluginIconItem(this, DEFAULT_PICON));
327         FileSystem fs;
328         const char *plugin_path = File::get_plugin_path();
329         if( fs.update(plugin_path) ) return;
330         for( int i=0; i<fs.dir_list.total; ++i ) {
331                 char *fs_path = fs.dir_list[i]->path;
332                 if( !fs.is_dir(fs_path) ) continue;
333                 char *cp = strrchr(fs_path,'/');
334                 cp = !cp ? fs_path : cp+1;
335                 if( strncmp("picon_", cp, 6) ) continue;
336                 if( !strcmp(cp += 6,DEFAULT_PICON) ) continue;
337                 add_item(new ViewPluginIconItem(this, cp));
338         }
339 }
340
341 int ViewPluginIcons::handle_event()
342 {
343         return 1;
344 }
345
346 ViewPluginIconItem::ViewPluginIconItem(ViewPluginIcons *popup, const char *text)
347  : BC_MenuItem(text)
348 {
349         this->popup = popup;
350 }
351
352 int ViewPluginIconItem::handle_event()
353 {
354         popup->set_text(get_text());
355         strcpy(popup->pwindow->thread->preferences->plugin_icons, get_text());
356         popup->handle_event();
357         return 1;
358 }
359
360
361 ViewThumbnails::ViewThumbnails(int x,
362         int y,
363         PreferencesWindow *pwindow)
364  : BC_CheckBox(x,
365         y,
366         pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
367 {
368         this->pwindow = pwindow;
369 }
370
371 int ViewThumbnails::handle_event()
372 {
373         pwindow->thread->preferences->use_thumbnails = get_value();
374         return 1;
375 }
376
377
378
379 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
380  : BC_CheckBox(x,
381         y,
382         pwindow->thread->preferences->use_tipwindow,
383         _("Show tip of the day"))
384 {
385         this->pwindow = pwindow;
386 }
387 int UseTipWindow::handle_event()
388 {
389         pwindow->thread->preferences->use_tipwindow = get_value();
390         return 1;
391 }
392
393
394 UseWarnIndecies::UseWarnIndecies(PreferencesWindow *pwindow, int x, int y)
395  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_indexes,
396         _("ffmpeg probe warns rebuild indexes"))
397 {
398         this->pwindow = pwindow;
399 }
400
401 int UseWarnIndecies::handle_event()
402 {
403         pwindow->thread->preferences->warn_indexes = get_value();
404         return 1;
405 }
406
407 UseWarnVersion::UseWarnVersion(PreferencesWindow *pwindow, int x, int y)
408  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_version,
409         _("EDL version warns if mismatched"))
410 {
411         this->pwindow = pwindow;
412 }
413
414 int UseWarnVersion::handle_event()
415 {
416         pwindow->thread->preferences->warn_version = get_value();
417         return 1;
418 }
419
420 BD_WarnRoot::BD_WarnRoot(PreferencesWindow *pwindow, int x, int y)
421  : BC_CheckBox(x, y, pwindow->thread->preferences->bd_warn_root,
422         _("Create Bluray warns if not root"))
423 {
424         this->pwindow = pwindow;
425 }
426
427 int BD_WarnRoot::handle_event()
428 {
429         pwindow->thread->preferences->bd_warn_root = get_value();
430         return 1;
431 }
432
433 PopupMenuBtnup::PopupMenuBtnup(PreferencesWindow *pwindow, int x, int y)
434  : BC_CheckBox(x, y, pwindow->thread->preferences->popupmenu_btnup,
435         _("Popups activate on button up"))
436 {
437         this->pwindow = pwindow;
438 }
439
440 int PopupMenuBtnup::handle_event()
441 {
442         pwindow->thread->preferences->popupmenu_btnup = get_value();
443         return 1;
444 }
445
446 GrabFocusPolicy::GrabFocusPolicy(PreferencesWindow *pwindow, int x, int y)
447  : BC_CheckBox(x, y, (pwindow->thread->preferences->grab_input_focus) != 0,
448         _("Set Input Focus when window entered"))
449 {
450         this->pwindow = pwindow;
451 }
452
453 int GrabFocusPolicy::handle_event()
454 {
455         pwindow->thread->preferences->grab_input_focus = get_value();
456         return 1;
457 }
458
459 ActivateFocusPolicy::ActivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
460  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_ACTIVATE) != 0,
461         _("Click to activate text focus"))
462 {
463         this->pwindow = pwindow;
464 }
465
466 int ActivateFocusPolicy::handle_event()
467 {
468         if( get_value() )
469                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_ACTIVATE;
470         else
471                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_ACTIVATE;
472         return 1;
473 }
474
475 DeactivateFocusPolicy::DeactivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
476  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_DEACTIVATE) != 0,
477         _("Click to deactivate text focus"))
478 {
479         this->pwindow = pwindow;
480 }
481
482 int DeactivateFocusPolicy::handle_event()
483 {
484         if( get_value() )
485                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_DEACTIVATE;
486         else
487                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_DEACTIVATE;
488         return 1;
489 }
490
491 ForwardRenderDisplacement::ForwardRenderDisplacement(PreferencesWindow *pwindow, int x, int y)
492  : BC_CheckBox(x, y, pwindow->thread->preferences->forward_render_displacement,
493         _("Always show next frame"))
494 {
495         this->pwindow = pwindow;
496 }
497
498 int ForwardRenderDisplacement::handle_event()
499 {
500         pwindow->thread->preferences->forward_render_displacement = get_value();
501         return 1;
502 }
503
504 HighlightInverseColor::HighlightInverseColor(PreferencesWindow *pwindow, int x, int y, const char *hex)
505  : BC_TextBox(x, y, 80, 1, hex)
506 {
507         this->pwindow = pwindow;
508 }
509
510 int HighlightInverseColor::handle_event()
511 {
512         int inverse_color = strtoul(get_text(),0,16);
513         if( (inverse_color &= 0xffffff) == 0 ) {
514                 inverse_color = 0xffffff;
515                 char string[BCSTRLEN];
516                 sprintf(string,"%06x", inverse_color);
517                 update(string);
518         }
519         pwindow->thread->preferences->highlight_inverse = inverse_color;
520         return 1;
521 }
522