ff tooltip, shcmds doc, bld_prepare fix, edl load_xml fix
[goodguy/history.git] / cinelerra-5.1 / cinelerra / browsebutton.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 "bcsignals.h"
23 #include "browsebutton.h"
24 #include "language.h"
25 #include "mutex.h"
26 #include "theme.h"
27
28
29 BrowseButton::BrowseButton(Theme *theme,
30         BC_WindowBase *parent_window,
31         BC_TextBox *textbox,
32         int x,
33         int y,
34         const char *init_directory,
35         const char *title,
36         const char *caption,
37         int want_directory)
38  : BC_Button(x, y, theme->get_image_set("magnify_button")),
39    Thread(1, 0, 0)
40 {
41         this->parent_window = parent_window;
42         this->want_directory = want_directory;
43         this->title = title;
44         this->caption = caption;
45         this->init_directory = init_directory;
46         this->textbox = textbox;
47         this->theme = theme;
48         set_tooltip(_("Look for file"));
49         gui = 0;
50         startup_lock = new Mutex("BrowseButton::startup_lock");
51 }
52
53 BrowseButton::~BrowseButton()
54 {
55         startup_lock->lock("BrowseButton::~BrowseButton");
56         if(gui)
57         {
58                 gui->lock_window();
59                 gui->set_done(1);
60                 gui->unlock_window();
61         }
62         startup_lock->unlock();
63         Thread::join();
64         delete startup_lock;
65 }
66
67 int BrowseButton::handle_event()
68 {
69         if(Thread::running())
70         {
71                 if(gui)
72                 {
73                         gui->lock_window("BrowseButton::handle_event");
74                         gui->raise_window();
75                         gui->unlock_window();
76                 }
77                 return 1;
78         }
79
80         x = parent_window->get_abs_cursor_x(0);
81         y = parent_window->get_abs_cursor_y(0);
82         startup_lock->lock("BrowseButton::handle_event 1");
83         Thread::start();
84
85         startup_lock->lock("BrowseButton::handle_event 2");
86         startup_lock->unlock();
87         return 1;
88 }
89
90 void BrowseButton::run()
91 {
92         BrowseButtonWindow browsewindow(theme,
93                 get_x() - BC_WindowBase::get_resources()->filebox_w / 2,
94                 get_y() - BC_WindowBase::get_resources()->filebox_h / 2,
95                 parent_window,
96                 textbox->get_text(),
97                 title,
98                 caption,
99                 want_directory);
100         gui = &browsewindow;
101         startup_lock->unlock();
102
103         browsewindow.lock_window("BrowseButton::run");
104         browsewindow.create_objects();
105         browsewindow.unlock_window();
106         int result2 = browsewindow.run_window();
107
108         if(!result2)
109         {
110 //              if(want_directory)
111 //              {
112 //                      textbox->update(browsewindow.get_directory());
113 //              }
114 //              else
115 //              {
116 //                      textbox->update(browsewindow.get_filename());
117 //              }
118
119                 parent_window->lock_window("BrowseButton::run");
120                 textbox->update(browsewindow.get_submitted_path());
121                 parent_window->flush();
122                 textbox->handle_event();
123                 parent_window->unlock_window();
124         }
125
126         startup_lock->lock("BrowseButton::run");
127         gui = 0;
128         startup_lock->unlock();
129 }
130
131 BrowseButtonWindow::BrowseButtonWindow(Theme *theme, int x, int y,
132         BC_WindowBase *parent_window, const char *init_directory,
133         const char *title, const char *caption, int want_directory)
134  : BC_FileBox(x, y, init_directory, title, caption,
135         want_directory, // Set to 1 to get hidden files.
136         want_directory, // Want only directories
137         0, theme->browse_pad)
138 {
139 }
140
141 BrowseButtonWindow::~BrowseButtonWindow()
142 {
143 }