inter-view tweaks, add clip preview, fix for dupl proxy vicon refs, fix track drag...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcmenubar.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2015 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 "bcmenu.h"
23 #include "bcmenubar.h"
24 #include "bcmenupopup.h"
25 #include "bcpixmap.h"
26 #include "bcpopup.h"
27 #include "bcpopupmenu.h"
28 #include "bcresources.h"
29 #include "bcsignals.h"
30 #include "bccolors.h"
31 #include "fonts.h"
32 #include "keys.h"
33 #include <string.h>
34 #include <unistd.h>
35 #include "vframe.h"
36
37
38 // ================================== Menu bar ==================================
39
40 BC_MenuBar::BC_MenuBar(int x, int y, int w)
41  : BC_SubWindow(x, y, w, 0, -1)
42 {
43 // Height is really determined by the font in create_tool_objects.
44         button_releases = 0;
45         active = 0;
46         menu_bar_bg = 0;
47         for(int i = 0; i < 3; i++)
48                 menu_title_bg[i] = 0;
49 }
50
51
52 BC_MenuBar::~BC_MenuBar()
53 {
54 // Delete all titles.
55         for(int i = 0; i < menu_titles.total; i++) delete menu_titles.values[i];
56         menu_titles.remove_all();
57         delete menu_bar_bg;
58         for(int i = 0; i < 3; i++)
59                 delete menu_title_bg[i];
60 }
61
62 int BC_MenuBar::initialize()
63 {
64         BC_Resources *resources = get_resources();
65 // Initialize dimensions
66         h = calculate_height(this);
67         bg_color = resources->menu_up;
68
69         if(resources->menu_bar_bg) menu_bar_bg = new BC_Pixmap(this,
70                 resources->menu_bar_bg);
71
72         if(resources->menu_title_bg)
73         {
74                 for(int i = 0; i < 3; i++)
75                         menu_title_bg[i] = new BC_Pixmap(this,
76                                 resources->menu_title_bg[i]);
77         }
78
79 // Create the subwindow
80         BC_SubWindow::initialize();
81
82         if(resources->menu_bg)
83                 set_background(resources->menu_bg);
84         draw_face(0, 0);
85         show_window(0);
86         return 0;
87 }
88
89 int BC_MenuBar::calculate_height(BC_WindowBase *window)
90 {
91         if(get_resources()->menu_bar_bg)
92                 return get_resources()->menu_bar_bg->get_h();
93         else
94                 return window->get_text_height(MEDIUMFONT) + 8;
95 }
96
97 void BC_MenuBar::draw_items()
98 {
99         for(int i = 0; i < menu_titles.total; i++)
100                 menu_titles.values[i]->draw_items();
101         flush();
102 }
103
104 int BC_MenuBar::add_menu(BC_Menu* menu)
105 {
106         int x, w;
107
108 // Get dimensions
109         if(menu_titles.total == 0)
110                 x = 2;
111         else
112                 x = menu_titles.values[menu_titles.total - 1]->x +
113                         menu_titles.values[menu_titles.total - 1]->w;
114
115         w = get_text_width(MEDIUMFONT, menu->text) + 20;
116 // get pointer
117         menu_titles.append(menu);
118 // initialize and draw
119         menu->initialize(top_level, this, x, 2, w, get_h() - 4);
120         return 0;
121 }
122
123 int BC_MenuBar::focus_out_event()
124 {
125         deactivate();
126         return 0;
127 }
128
129 int BC_MenuBar::button_press_event()
130 {
131         int result = 0;
132
133         for(int i = 0; i < menu_titles.total && !result; i++)
134         {
135                 result = menu_titles.values[i]->dispatch_button_press();
136         }
137
138         return result;
139 }
140
141 int BC_MenuBar::button_release_event()
142 {
143         int result = 0;
144
145         button_down = 0;
146         button_releases++;
147         for(int i = 0; i < menu_titles.total; i++)
148         {
149                 result += menu_titles.values[i]->dispatch_button_release();
150         }
151
152 // Button was released outside any menu.
153         if(!result)
154         {
155                 deactivate();
156         }
157 //printf("BC_MenuBar::button_release_event %d\n", result);
158
159         return result;
160 }
161
162 int BC_MenuBar::resize_event(int w, int h)
163 {
164         resize_window(w, get_h());
165         draw_face(0, 0);
166         for(int i = 0; i < menu_titles.total; i++)
167         {
168                 menu_titles.values[i]->draw_title(0, 0);
169         }
170         flash(0);
171         return 0;
172 }
173
174 int BC_MenuBar::keypress_event()
175 {
176         int result = 0;
177         switch( get_keypress() ) {
178         case ESC:
179                 deactivate();
180                 return 1;
181         }
182         if(!top_level->active_subwindow || !top_level->active_subwindow->uses_text())
183         {
184                 for(int i = 0; i < menu_titles.total && !result; i++)
185                 {
186                         result = menu_titles.values[i]->dispatch_keypress();
187                 }
188         }
189         return result;
190 }
191
192 int BC_MenuBar::cursor_motion_event()
193 {
194         int result = 0;
195         for(int i = 0; i < menu_titles.total && !result; i++)
196         {
197                 result = menu_titles.values[i]->dispatch_motion_event();
198         }
199         return result;
200 }
201
202 int BC_MenuBar::cursor_leave_event()
203 {
204         for(int i = 0; i < menu_titles.total; i++) {
205                 menu_titles.values[i]->dispatch_cursor_leave();
206         }
207         for(int i = 0; i < menu_titles.total; i++) {
208                 if( menu_titles.values[i]->active )
209                         return 0;
210         }
211         deactivate();
212         return 0;
213 }
214
215 int BC_MenuBar::cursor_enter_event()
216 {
217         if(active) return 1;
218         return 0;
219 }
220
221 int BC_MenuBar::translation_event()
222 {
223         if(active)
224         {
225                 for(int i = 0; i < menu_titles.total; i++)
226                 {
227                         menu_titles.values[i]->dispatch_translation_event();
228                 }
229         }
230         return 0;
231 }
232
233 int BC_MenuBar::activate()
234 {
235         top_level->deactivate();
236         top_level->active_menubar = this;
237         active = 1;
238         return 0;
239 }
240
241 int BC_MenuBar::deactivate()
242 {
243         for(int i = 0; i < menu_titles.total; i++)
244         {
245                 menu_titles.values[i]->deactivate_menu();
246         }
247         top_level->active_menubar = 0;
248         active = 0;
249         return 0;
250 }
251
252 int BC_MenuBar::unhighlight()
253 {
254         for(int i = 0; i < menu_titles.total; i++)
255         {
256                 menu_titles.values[i]->unhighlight();
257         }
258         return 0;
259 }
260
261 int BC_MenuBar::draw_face(int flash, int flush)
262 {
263         if(menu_bar_bg)
264         {
265                 draw_3segmenth(0,
266                         0,
267                         get_w(),
268                         menu_bar_bg);
269 // 9 segment doesn't draw properly
270 //              draw_9segment(0, 0, get_w(), get_h(), menu_bar_bg);
271         }
272         else
273         {
274                 int lx,ly,ux,uy;
275                 int h, w;
276                 h = get_h();
277                 w = get_w();
278                 h--;
279                 w--;
280
281                 lx = 1;  ly = 1;
282                 ux = w - 1;  uy = h - 1;
283
284                 set_color(top_level->get_resources()->menu_light);
285                 draw_line(0, 0, 0, uy);
286                 draw_line(0, 0, ux, 0);
287
288                 set_color(top_level->get_resources()->menu_shadow);
289                 draw_line(ux, ly, ux, uy);
290                 draw_line(lx, uy, ux, uy);
291                 set_color(BLACK);
292                 draw_line(w, 0, w, h);
293                 draw_line(0, h, w, h);
294         }
295
296         if(flash) this->flash(flush);
297         return 0;
298 }
299
300
301
302
303