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) + 20;
117 menu_titles.append(menu);
118 // initialize and draw
119 menu->initialize(top_level, this, x, 2, w, get_h() - 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();
192 int BC_MenuBar::cursor_motion_event()
195 for(int i = 0; i < menu_titles.total && !result; i++)
197 result = menu_titles.values[i]->dispatch_motion_event();
202 int BC_MenuBar::cursor_leave_event()
204 for(int i = 0; i < menu_titles.total; i++) {
205 menu_titles.values[i]->dispatch_cursor_leave();
207 for(int i = 0; i < menu_titles.total; i++) {
208 if( menu_titles.values[i]->active )
215 int BC_MenuBar::cursor_enter_event()
221 int BC_MenuBar::translation_event()
225 for(int i = 0; i < menu_titles.total; i++)
227 menu_titles.values[i]->dispatch_translation_event();
233 int BC_MenuBar::activate()
235 top_level->deactivate();
236 top_level->active_menubar = this;
241 int BC_MenuBar::deactivate()
243 for(int i = 0; i < menu_titles.total; i++)
245 menu_titles.values[i]->deactivate_menu();
247 top_level->active_menubar = 0;
252 int BC_MenuBar::unhighlight()
254 for(int i = 0; i < menu_titles.total; i++)
256 menu_titles.values[i]->unhighlight();
261 int BC_MenuBar::draw_face(int flash, int flush)
269 // 9 segment doesn't draw properly
270 // draw_9segment(0, 0, get_w(), get_h(), menu_bar_bg);
282 ux = w - 1; uy = h - 1;
284 set_color(top_level->get_resources()->menu_light);
285 draw_line(0, 0, 0, uy);
286 draw_line(0, 0, ux, 0);
288 set_color(top_level->get_resources()->menu_shadow);
289 draw_line(ux, ly, ux, uy);
290 draw_line(lx, uy, ux, uy);
292 draw_line(w, 0, w, h);
293 draw_line(0, h, w, h);
296 if(flash) this->flash(flush);