rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.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 "colors.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         for(int i = 0; i < menu_titles.total; i++) {
126                 if( menu_titles.values[i]->active )
127                         return 0;
128         }
129         deactivate();
130         return 0;
131 }
132
133 int BC_MenuBar::button_press_event()
134 {
135         int result = 0;
136
137         for(int i = 0; i < menu_titles.total && !result; i++)
138         {
139                 result = menu_titles.values[i]->dispatch_button_press();
140         }
141
142         return result;
143 }
144
145 int BC_MenuBar::button_release_event()
146 {
147         int result = 0;
148
149         button_down = 0;
150         button_releases++;
151         for(int i = 0; i < menu_titles.total; i++)
152         {
153                 result += menu_titles.values[i]->dispatch_button_release();
154         }
155
156 // Button was released outside any menu.
157         if(!result)
158         {
159                 deactivate();
160         }
161 //printf("BC_MenuBar::button_release_event %d\n", result);
162
163         return result;
164 }
165
166 int BC_MenuBar::resize_event(int w, int h)
167 {
168         resize_window(w, get_h());
169         draw_face(0, 0);
170         for(int i = 0; i < menu_titles.total; i++)
171         {
172                 menu_titles.values[i]->draw_title(0, 0);
173         }
174         flash(0);
175         return 0;
176 }
177
178 int BC_MenuBar::keypress_event()
179 {
180         int result = 0;
181         switch( get_keypress() ) {
182         case ESC:
183                 deactivate();
184                 return 1;
185         }
186         if(!top_level->active_subwindow || !top_level->active_subwindow->uses_text())
187         {
188                 for(int i = 0; i < menu_titles.total && !result; i++)
189                 {
190                         result = menu_titles.values[i]->dispatch_keypress();
191                 }
192         }
193         return result;
194 }
195
196 int BC_MenuBar::cursor_motion_event()
197 {
198         int result = 0;
199         for(int i = 0; i < menu_titles.total && !result; i++)
200         {
201                 result = menu_titles.values[i]->dispatch_motion_event();
202         }
203         return result;
204 }
205
206 int BC_MenuBar::cursor_leave_event()
207 {
208         for(int i = 0; i < menu_titles.total; i++)
209         {
210                 menu_titles.values[i]->dispatch_cursor_leave();
211         }
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