3 #include "bcmenuitem.h"
4 #include "bcmenupopup.h"
6 #include "bcresources.h"
12 // ==================================== Menu ===================================
14 BC_Menu::BC_Menu(char *text)
16 strcpy(this->text, text);
27 int BC_Menu::initialize(BC_WindowBase *top_level,
38 this->menu_bar = menu_bar;
39 this->top_level = top_level;
40 menu_popup = new BC_MenuPopup;
41 menu_popup->initialize(top_level, menu_bar, this, 0, 0);
46 int BC_Menu::add_item(BC_MenuItem* menuitem)
48 menu_popup->add_item(menuitem);
52 int BC_Menu::remove_item(BC_MenuItem *item)
54 menu_popup->remove_item(item);
58 int BC_Menu::total_menuitems()
60 return menu_popup->total_menuitems();
63 int BC_Menu::dispatch_button_press()
67 // Menu is down so dispatch to popup
70 result = menu_popup->dispatch_button_press();
76 if(top_level->event_win == menu_bar->win &&
77 top_level->cursor_x >= x && top_level->cursor_x < x + w &&
78 top_level->cursor_y >= y && top_level->cursor_y < y + h)
82 menu_bar->deactivate();
83 menu_bar->unhighlight();
84 menu_bar->button_releases = 0;
94 int BC_Menu::dispatch_button_release()
98 if(top_level->event_win == menu_bar->win &&
99 top_level->cursor_x >= x && top_level->cursor_y < x + w &&
100 top_level->cursor_y >= y && top_level->cursor_y < y + h)
102 if(menu_bar->button_releases >= 2)
105 menu_bar->deactivate();
111 result = menu_popup->dispatch_button_release();
115 int BC_Menu::dispatch_keypress()
117 return menu_popup->dispatch_key_press();
120 int BC_Menu::dispatch_motion_event()
123 int cursor_x, cursor_y;
129 result = menu_popup->dispatch_motion_event();
134 top_level->translate_coordinates(top_level->event_win,
141 // change focus from other menu
142 if(menu_bar->active && !active &&
143 cursor_x >= x && cursor_x < x + w &&
144 cursor_y >= y && cursor_y < y + h)
146 menu_bar->activate();
151 // control highlighting
154 if(cursor_x < x || cursor_x >= x + w ||
155 cursor_y < y || cursor_y >= y + h)
163 if(cursor_x >= x && cursor_x < x + w &&
164 cursor_y >= y && cursor_y < y + h)
166 menu_bar->unhighlight();
176 int BC_Menu::dispatch_cursor_leave()
180 menu_popup->dispatch_cursor_leave();
186 int BC_Menu::dispatch_translation_event()
190 menu_popup->dispatch_translation_event();
195 int BC_Menu::activate_menu()
198 int new_x, new_y, top_w, top_h;
201 XTranslateCoordinates(top_level->display,
209 menu_popup->activate_menu(new_x, new_y, w, h, 0, 1);
212 menu_popup->activate_menu(x, y, w, h, 1, 1);
219 void BC_Menu::draw_items()
221 if(active) menu_popup->draw_items();
224 int BC_Menu::set_text(char *text)
226 strcpy(this->text, text);
231 int BC_Menu::draw_title()
233 BC_Resources *resources = top_level->get_resources();
236 if(active && menu_popup)
238 // Menu is pulled down and title is recessed.
240 if(menu_bar->menu_title_bg[0])
243 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[2]);
247 menu_bar->draw_3d_box(x, y, w, h,
248 resources->menu_shadow,
250 resources->menu_down,
251 resources->menu_down,
252 resources->menu_light);
257 // Menu is not pulled down.
262 if(menu_bar->menu_title_bg[0])
265 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[1]);
269 menu_bar->set_color(resources->menu_highlighted);
270 menu_bar->draw_box(x, y, w, h);
276 if(menu_bar->menu_title_bg[0])
279 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[0]);
283 menu_bar->draw_background(x, y, w, h);
288 menu_bar->set_color(resources->menu_title_text);
289 menu_bar->set_font(MEDIUMFONT);
290 menu_bar->draw_text(x + 10 + text_offset,
291 h - menu_bar->get_text_descent(MEDIUMFONT) + text_offset,
298 int BC_Menu::deactivate_menu()
302 menu_popup->deactivate_menu();
309 int BC_Menu::unhighlight()
321 // c-file-style: "linux"