3 #include "bcmenuitem.h"
4 #include "bcmenupopup.h"
5 #include "bcresources.h"
11 // ==================================== Menu ===================================
13 BC_Menu::BC_Menu(char *text)
15 strcpy(this->text, text);
26 int BC_Menu::initialize(BC_WindowBase *top_level,
37 this->menu_bar = menu_bar;
38 this->top_level = top_level;
39 menu_popup = new BC_MenuPopup;
40 menu_popup->initialize(top_level, menu_bar, this, 0, 0);
45 int BC_Menu::add_item(BC_MenuItem* menuitem)
47 menu_popup->add_item(menuitem);
51 int BC_Menu::remove_item(BC_MenuItem *item)
53 menu_popup->remove_item(item);
57 int BC_Menu::total_menuitems()
59 return menu_popup->total_menuitems();
62 int BC_Menu::dispatch_button_press()
66 // Menu is down so dispatch to popup
69 result = menu_popup->dispatch_button_press();
75 if(top_level->event_win == menu_bar->win &&
76 top_level->cursor_x >= x && top_level->cursor_x < x + w &&
77 top_level->cursor_y >= y && top_level->cursor_y < y + h)
81 menu_bar->deactivate();
82 menu_bar->unhighlight();
83 menu_bar->button_releases = 0;
93 int BC_Menu::dispatch_button_release()
97 if(top_level->event_win == menu_bar->win &&
98 top_level->cursor_x >= x && top_level->cursor_y < x + w &&
99 top_level->cursor_y >= y && top_level->cursor_y < y + h)
101 if(menu_bar->button_releases >= 2)
104 menu_bar->deactivate();
110 result = menu_popup->dispatch_button_release();
114 int BC_Menu::dispatch_keypress()
116 return menu_popup->dispatch_key_press();
119 int BC_Menu::dispatch_motion_event()
122 int cursor_x, cursor_y;
128 result = menu_popup->dispatch_motion_event();
133 top_level->translate_coordinates(top_level->event_win,
140 // change focus from other menu
141 if(menu_bar->active && !active &&
142 cursor_x >= x && cursor_x < x + w &&
143 cursor_y >= y && cursor_y < y + h)
145 menu_bar->activate();
150 // control highlighting
153 if(cursor_x < x || cursor_x >= x + w ||
154 cursor_y < y || cursor_y >= y + h)
162 if(cursor_x >= x && cursor_x < x + w &&
163 cursor_y >= y && cursor_y < y + h)
165 menu_bar->unhighlight();
175 int BC_Menu::dispatch_cursor_leave()
179 menu_popup->dispatch_cursor_leave();
185 int BC_Menu::dispatch_translation_event()
189 menu_popup->dispatch_translation_event();
194 int BC_Menu::activate_menu()
197 int new_x, new_y, top_w, top_h;
200 XTranslateCoordinates(top_level->display,
208 menu_popup->activate_menu(new_x, new_y, w, h, 0, 1);
211 menu_popup->activate_menu(x, y, w, h, 1, 1);
218 void BC_Menu::draw_items()
220 if(active) menu_popup->draw_items();
223 int BC_Menu::set_text(char *text)
225 strcpy(this->text, text);
230 int BC_Menu::draw_title()
232 if(active && menu_popup)
234 // Menu is pulled down and title is recessed.
235 menu_bar->draw_3d_box(x, y, w, h,
236 top_level->get_resources()->menu_shadow,
238 top_level->get_resources()->menu_down,
239 top_level->get_resources()->menu_down,
240 top_level->get_resources()->menu_light);
241 menu_bar->set_color(top_level->get_resources()->menu_item_text);
244 // Menu is not pulled down.
248 menu_bar->set_color(top_level->get_resources()->menu_highlighted);
249 menu_bar->draw_box(x, y, w, h);
250 menu_bar->set_color(top_level->get_resources()->menu_highlighted_fontcolor);
254 menu_bar->draw_background(x, y, w, h);
255 menu_bar->set_color(top_level->get_resources()->menu_item_text);
258 menu_bar->set_font(MEDIUMFONT);
259 menu_bar->draw_text(x + 10, h - menu_bar->get_text_descent(MEDIUMFONT), text);
265 int BC_Menu::deactivate_menu()
269 menu_popup->deactivate_menu();
276 int BC_Menu::unhighlight()