4 * Copyright (C) 2008-2015 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcmenubar.h"
24 #include "bcmenupopup.h"
27 #include "bcpopupmenu.h"
28 #include "bcresources.h"
29 #include "bcsignals.h"
38 // ================================== Menu bar ==================================
40 BC_MenuBar::BC_MenuBar(int x, int y, int w)
41 : BC_SubWindow(x, y, w, 0, -1)
43 // Height is really determined by the font in create_tool_objects.
47 for(int i = 0; i < 3; i++)
52 BC_MenuBar::~BC_MenuBar()
55 for(int i = 0; i < menu_titles.total; i++) delete menu_titles.values[i];
56 menu_titles.remove_all();
58 for(int i = 0; i < 3; i++)
59 delete menu_title_bg[i];
62 int BC_MenuBar::initialize()
64 BC_Resources *resources = get_resources();
65 // Initialize dimensions
66 h = calculate_height(this);
67 bg_color = resources->menu_up;
69 if(resources->menu_bar_bg) menu_bar_bg = new BC_Pixmap(this,
70 resources->menu_bar_bg);
72 if(resources->menu_title_bg)
74 for(int i = 0; i < 3; i++)
75 menu_title_bg[i] = new BC_Pixmap(this,
76 resources->menu_title_bg[i]);
79 // Create the subwindow
80 BC_SubWindow::initialize();
82 if(resources->menu_bg)
83 set_background(resources->menu_bg);
89 int BC_MenuBar::calculate_height(BC_WindowBase *window)
91 if(get_resources()->menu_bar_bg)
92 return get_resources()->menu_bar_bg->get_h();
94 return window->get_text_height(MEDIUMFONT) + 8;
97 void BC_MenuBar::draw_items()
99 for(int i = 0; i < menu_titles.total; i++)
100 menu_titles.values[i]->draw_items();
104 int BC_MenuBar::add_menu(BC_Menu* menu)
109 if(menu_titles.total == 0)
112 x = menu_titles.values[menu_titles.total - 1]->x +
113 menu_titles.values[menu_titles.total - 1]->w;
115 w = get_text_width(MEDIUMFONT, menu->text) + xS(20);
117 menu_titles.append(menu);
118 // initialize and draw
119 menu->initialize(top_level, this, x, yS(2), w, get_h() - yS(4));
123 int BC_MenuBar::focus_out_event()
129 int BC_MenuBar::button_press_event()
133 for(int i = 0; i < menu_titles.total && !result; i++)
135 result = menu_titles.values[i]->dispatch_button_press();
141 int BC_MenuBar::button_release_event()
147 for(int i = 0; i < menu_titles.total; i++)
149 result += menu_titles.values[i]->dispatch_button_release();
152 // Button was released outside any menu.
157 //printf("BC_MenuBar::button_release_event %d\n", result);
162 int BC_MenuBar::resize_event(int w, int h)
164 resize_window(w, get_h());
166 for(int i = 0; i < menu_titles.total; i++)
168 menu_titles.values[i]->draw_title(0, 0);
174 int BC_MenuBar::keypress_event()
177 switch( get_keypress() ) {
182 if(!top_level->active_subwindow || !top_level->active_subwindow->uses_text())
184 for(int i = 0; i < menu_titles.total && !result; i++)
186 result = menu_titles.values[i]->dispatch_keypress();
189 if (!result) result = context_help_check_and_show();
193 int BC_MenuBar::cursor_motion_event()
196 for(int i = 0; i < menu_titles.total && !result; i++)
198 result = menu_titles.values[i]->dispatch_motion_event();
203 int BC_MenuBar::cursor_leave_event()
205 for(int i = 0; i < menu_titles.total; i++) {
206 menu_titles.values[i]->dispatch_cursor_leave();
208 for(int i = 0; i < menu_titles.total; i++) {
209 if( menu_titles.values[i]->active )
216 int BC_MenuBar::cursor_enter_event()
222 int BC_MenuBar::translation_event()
226 for(int i = 0; i < menu_titles.total; i++)
228 menu_titles.values[i]->dispatch_translation_event();
234 int BC_MenuBar::activate()
236 top_level->deactivate();
237 top_level->active_menubar = this;
242 int BC_MenuBar::deactivate()
244 for(int i = 0; i < menu_titles.total; i++)
246 menu_titles.values[i]->deactivate_menu();
248 top_level->active_menubar = 0;
253 int BC_MenuBar::unhighlight()
255 for(int i = 0; i < menu_titles.total; i++)
257 menu_titles.values[i]->unhighlight();
262 int BC_MenuBar::draw_face(int flash, int flush)
270 // 9 segment doesn't draw properly
271 // draw_9segment(0, 0, get_w(), get_h(), menu_bar_bg);
283 ux = w - 1; uy = h - 1;
285 set_color(top_level->get_resources()->menu_light);
286 draw_line(0, 0, 0, uy);
287 draw_line(0, 0, ux, 0);
289 set_color(top_level->get_resources()->menu_shadow);
290 draw_line(ux, ly, ux, uy);
291 draw_line(lx, uy, ux, uy);
293 draw_line(w, 0, w, h);
294 draw_line(0, h, w, h);
297 if(flash) this->flash(flush);