Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / browsebutton.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "bcsignals.h"
24 #include "browsebutton.h"
25 #include "language.h"
26 #include "mutex.h"
27 #include "theme.h"
28
29
30 BrowseButton::BrowseButton(Theme *theme,
31         BC_WindowBase *parent_window,
32         BC_TextBox *textbox,
33         int x,
34         int y,
35         const char *init_directory,
36         const char *title,
37         const char *caption,
38         int want_directory)
39  : BC_Button(x, y, theme->get_image_set("magnify_button")),
40    Thread(1, 0, 0)
41 {
42         this->parent_window = parent_window;
43         this->want_directory = want_directory;
44         this->title = title;
45         this->caption = caption;
46         this->init_directory = init_directory;
47         this->textbox = textbox;
48         this->theme = theme;
49         set_tooltip(_("Look for file"));
50         gui = 0;
51         startup_lock = new Mutex("BrowseButton::startup_lock");
52 }
53
54 BrowseButton::~BrowseButton()
55 {
56         startup_lock->lock("BrowseButton::~BrowseButton");
57         if(gui)
58         {
59                 gui->lock_window();
60                 gui->set_done(1);
61                 gui->unlock_window();
62         }
63         startup_lock->unlock();
64         Thread::join();
65         delete startup_lock;
66 }
67
68 int BrowseButton::handle_event()
69 {
70         if(Thread::running())
71         {
72                 if(gui)
73                 {
74                         gui->lock_window("BrowseButton::handle_event");
75                         gui->raise_window();
76                         gui->unlock_window();
77                 }
78                 return 1;
79         }
80
81         x = parent_window->get_abs_cursor_x(0);
82         y = parent_window->get_abs_cursor_y(0);
83         startup_lock->lock("BrowseButton::handle_event 1");
84         Thread::start();
85
86         startup_lock->lock("BrowseButton::handle_event 2");
87         startup_lock->unlock();
88         return 1;
89 }
90
91 void BrowseButton::run()
92 {
93         BrowseButtonWindow browsewindow(theme,
94                 get_x() - BC_WindowBase::get_resources()->filebox_w / 2,
95                 get_y() - BC_WindowBase::get_resources()->filebox_h / 2,
96                 parent_window,
97                 textbox->get_text(),
98                 title,
99                 caption,
100                 want_directory);
101         gui = &browsewindow;
102         startup_lock->unlock();
103
104         browsewindow.lock_window("BrowseButton::run");
105         browsewindow.create_objects();
106         browsewindow.unlock_window();
107         int result2 = browsewindow.run_window();
108
109         if(!result2)
110         {
111 //              if(want_directory)
112 //              {
113 //                      textbox->update(browsewindow.get_directory());
114 //              }
115 //              else
116 //              {
117 //                      textbox->update(browsewindow.get_filename());
118 //              }
119
120                 parent_window->lock_window("BrowseButton::run");
121                 textbox->update(browsewindow.get_submitted_path());
122                 parent_window->flush();
123                 textbox->handle_event();
124                 parent_window->unlock_window();
125         }
126
127         startup_lock->lock("BrowseButton::run");
128         gui = 0;
129         startup_lock->unlock();
130 }
131
132 BrowseButtonWindow::BrowseButtonWindow(Theme *theme, int x, int y,
133         BC_WindowBase *parent_window, const char *init_directory,
134         const char *title, const char *caption, int want_directory)
135  : BC_FileBox(x, y, init_directory, title, caption,
136         want_directory, // Set to 1 to get hidden files.
137         want_directory, // Want only directories
138         0, theme->browse_pad)
139 {
140 // *** CONTEXT_HELP ***
141         context_help_set_keyword("Loading Files");
142 }
143
144 BrowseButtonWindow::~BrowseButtonWindow()
145 {
146 }