4 * Copyright (C) 2008 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 "bcmenuitem.h"
25 #include "bcmenupopup.h"
27 #include "bcresources.h"
28 #include "bcsignals.h"
33 // ==================================== Menu ===================================
35 BC_Menu::BC_Menu(const char *text)
37 strcpy(this->text, text);
48 int BC_Menu::initialize(BC_WindowBase *top_level,
59 this->menu_bar = menu_bar;
60 this->top_level = top_level;
61 menu_popup = new BC_MenuPopup;
62 menu_popup->initialize(top_level, menu_bar, this, 0, 0);
67 int BC_Menu::add_item(BC_MenuItem* menuitem)
69 menu_popup->add_item(menuitem);
73 int BC_Menu::remove_item(BC_MenuItem *item)
75 menu_popup->remove_item(item, 0);
79 int BC_Menu::total_menuitems()
81 return menu_popup->total_menuitems();
84 int BC_Menu::dispatch_button_press()
88 // Menu is down so dispatch to popup
91 result = menu_popup->dispatch_button_press();
97 if(top_level->event_win == menu_bar->win &&
98 top_level->cursor_x >= x && top_level->cursor_x < x + w &&
99 top_level->cursor_y >= y && top_level->cursor_y < y + h)
103 menu_bar->deactivate();
104 menu_bar->unhighlight();
105 menu_bar->button_releases = 0;
106 menu_bar->activate();
115 int BC_Menu::dispatch_button_release()
119 if(top_level->event_win == menu_bar->win &&
120 top_level->cursor_x >= x && top_level->cursor_y < x + w &&
121 top_level->cursor_y >= y && top_level->cursor_y < y + h)
123 if(menu_bar->button_releases >= 2)
126 menu_bar->deactivate();
132 result = menu_popup->dispatch_button_release();
136 int BC_Menu::dispatch_keypress()
138 return menu_popup->dispatch_key_press();
141 int BC_Menu::dispatch_motion_event()
144 int cursor_x = 0, cursor_y = 0;
149 result = menu_popup->dispatch_motion_event();
152 if(!result && top_level->match_window(top_level->event_win))
154 top_level->translate_coordinates(top_level->event_win,
161 // change focus from other menu
162 if(menu_bar->active && !active &&
163 cursor_x >= x && cursor_x < x + w &&
164 cursor_y >= y && cursor_y < y + h)
166 menu_bar->activate();
171 // control highlighting
174 if(cursor_x < x || cursor_x >= x + w ||
175 cursor_y < y || cursor_y >= y + h)
183 if(cursor_x >= x && cursor_x < x + w &&
184 cursor_y >= y && cursor_y < y + h)
186 menu_bar->unhighlight();
196 int BC_Menu::dispatch_cursor_leave()
200 menu_popup->dispatch_cursor_leave();
206 int BC_Menu::dispatch_translation_event()
210 menu_popup->dispatch_translation_event();
215 int BC_Menu::activate_menu()
221 XTranslateCoordinates(top_level->display,
229 menu_popup->activate_menu(new_x, new_y, w, h, 0, 1);
232 menu_popup->activate_menu(x, y, w, h, 1, 1);
239 void BC_Menu::draw_items()
241 if(active) menu_popup->draw_items();
244 int BC_Menu::set_text(char *text)
246 strcpy(this->text, text);
251 int BC_Menu::draw_title(int flash, int flush)
253 BC_Resources *resources = top_level->get_resources();
256 if(active && menu_popup)
258 // Menu is pulled down and title is recessed.
260 if(menu_bar->menu_title_bg[0])
263 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[2]);
267 menu_bar->draw_3d_box(x, y, w, h,
268 resources->menu_shadow,
270 resources->menu_down,
271 resources->menu_down,
272 resources->menu_light);
277 // Menu is not pulled down.
282 if(menu_bar->menu_title_bg[0])
285 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[1]);
289 menu_bar->set_color(resources->menu_highlighted);
290 menu_bar->draw_box(x, y, w, h);
296 if(menu_bar->menu_title_bg[0])
299 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[0]);
303 menu_bar->draw_background(x, y, w, h);
308 menu_bar->set_color(resources->menu_title_text);
309 menu_bar->set_font(MEDIUMFONT);
310 menu_bar->draw_text(x + 10 + text_offset,
311 h / 2 + menu_bar->get_text_ascent(MEDIUMFONT) / 2 + 1 + text_offset,
313 if(flash) menu_bar->flash(flush);
318 int BC_Menu::deactivate_menu()
322 menu_popup->deactivate_menu();
329 int BC_Menu::unhighlight()