rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[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 "browsebutton.h"
23 #include "language.h"
24 #include "mutex.h"
25 #include "mwindow.h"
26 #include "theme.h"
27
28
29
30
31 BrowseButton::BrowseButton(MWindow *mwindow,
32         BC_WindowBase *parent_window,
33         BC_TextBox *textbox,
34         int x,
35         int y,
36         const char *init_directory,
37         const char *title,
38         const char *caption,
39         int want_directory)
40  : BC_Button(x, y, mwindow->theme->get_image_set("magnify_button")),
41    Thread(1, 0, 0)
42 {
43         this->parent_window = parent_window;
44         this->want_directory = want_directory;
45         this->title = title;
46         this->caption = caption;
47         this->init_directory = init_directory;
48         this->textbox = textbox;
49         this->mwindow = mwindow;
50         set_tooltip(_("Look for file"));
51         gui = 0;
52         startup_lock = new Mutex("BrowseButton::startup_lock");
53 }
54
55 BrowseButton::~BrowseButton()
56 {
57         startup_lock->lock("BrowseButton::~BrowseButton");
58         if(gui)
59         {
60                 gui->lock_window();
61                 gui->set_done(1);
62                 gui->unlock_window();
63         }
64         startup_lock->unlock();
65         Thread::join();
66         delete startup_lock;
67 }
68
69 int BrowseButton::handle_event()
70 {
71         if(Thread::running())
72         {
73                 if(gui)
74                 {
75                         gui->lock_window("BrowseButton::handle_event");
76                         gui->raise_window();
77                         gui->unlock_window();
78                 }
79                 return 1;
80         }
81
82         x = parent_window->get_abs_cursor_x(0);
83         y = parent_window->get_abs_cursor_y(0);
84         startup_lock->lock("BrowseButton::handle_event 1");
85         Thread::start();
86
87         startup_lock->lock("BrowseButton::handle_event 2");
88         startup_lock->unlock();
89         return 1;
90 }
91
92 void BrowseButton::run()
93 {
94         BrowseButtonWindow browsewindow(mwindow,
95                 this,
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
133 BrowseButtonWindow::BrowseButtonWindow(MWindow *mwindow,
134         BrowseButton *button,
135         BC_WindowBase *parent_window,
136         const char *init_directory,
137         const char *title,
138         const char *caption,
139         int want_directory)
140  : BC_FileBox(button->x - BC_WindowBase::get_resources()->filebox_w / 2,
141         button->y - BC_WindowBase::get_resources()->filebox_h / 2,
142         init_directory, title, caption,
143         want_directory, // Set to 1 to get hidden files.
144         want_directory, // Want only directories
145         0, mwindow->theme->browse_pad)
146 {
147 }
148
149 BrowseButtonWindow::~BrowseButtonWindow()
150 {
151 }