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