3 #include "bcmenupopup.h"
6 #include "bcpopupmenu.h"
7 #include "bcresources.h"
15 // ================================== Menu bar ==================================
17 BC_MenuBar::BC_MenuBar(int x, int y, int w)
18 : BC_SubWindow(x, y, w, 0, -1)
20 // Height is really determined by the font in create_tool_objects.
24 for(int i = 0; i < 3; i++)
29 BC_MenuBar::~BC_MenuBar()
32 for(int i = 0; i < menu_titles.total; i++) delete menu_titles.values[i];
33 menu_titles.remove_all();
35 for(int i = 0; i < 3; i++)
36 delete menu_title_bg[i];
39 int BC_MenuBar::initialize()
41 BC_Resources *resources = get_resources();
42 // Initialize dimensions
43 h = calculate_height(this);
44 bg_color = resources->menu_up;
46 if(resources->menu_bar_bg) menu_bar_bg = new BC_Pixmap(this,
47 resources->menu_bar_bg);
49 if(resources->menu_title_bg)
51 for(int i = 0; i < 3; i++)
52 menu_title_bg[i] = new BC_Pixmap(this,
53 resources->menu_title_bg[i]);
56 // Create the subwindow
57 BC_SubWindow::initialize();
59 if(resources->menu_bg)
60 set_background(resources->menu_bg);
65 int BC_MenuBar::calculate_height(BC_WindowBase *window)
67 if(get_resources()->menu_bar_bg)
68 return get_resources()->menu_bar_bg->get_h();
70 return window->get_text_height(MEDIUMFONT) + 8;
73 void BC_MenuBar::draw_items()
75 for(int i = 0; i < menu_titles.total; i++)
76 menu_titles.values[i]->draw_items();
80 int BC_MenuBar::add_menu(BC_Menu* menu)
85 if(menu_titles.total == 0)
88 x = menu_titles.values[menu_titles.total - 1]->x +
89 menu_titles.values[menu_titles.total - 1]->w;
91 w = get_text_width(MEDIUMFONT, menu->text) + 20;
93 menu_titles.append(menu);
94 // initialize and draw
95 menu->initialize(top_level, this, x, 2, w, get_h() - 4);
99 int BC_MenuBar::focus_out_event()
105 int BC_MenuBar::button_press_event()
109 for(int i = 0; i < menu_titles.total && !result; i++)
111 result = menu_titles.values[i]->dispatch_button_press();
117 int BC_MenuBar::button_release_event()
123 for(int i = 0; i < menu_titles.total; i++)
125 result += menu_titles.values[i]->dispatch_button_release();
128 // Button was released outside any menu.
133 //printf("BC_MenuBar::button_release_event %d\n", result);
138 int BC_MenuBar::resize_event(int w, int h)
140 resize_window(w, get_h());
142 for(int i = 0; i < menu_titles.total; i++)
144 menu_titles.values[i]->draw_title();
149 int BC_MenuBar::keypress_event()
152 if(!top_level->active_subwindow || !top_level->active_subwindow->uses_text())
154 for(int i = 0; i < menu_titles.total && !result; i++)
156 result = menu_titles.values[i]->dispatch_keypress();
162 int BC_MenuBar::cursor_motion_event()
165 for(int i = 0; i < menu_titles.total && !result; i++)
167 result = menu_titles.values[i]->dispatch_motion_event();
172 int BC_MenuBar::cursor_leave_event()
174 for(int i = 0; i < menu_titles.total; i++)
176 menu_titles.values[i]->dispatch_cursor_leave();
181 int BC_MenuBar::cursor_enter_event()
187 int BC_MenuBar::translation_event()
191 for(int i = 0; i < menu_titles.total; i++)
193 menu_titles.values[i]->dispatch_translation_event();
199 int BC_MenuBar::activate()
201 top_level->deactivate();
202 top_level->active_menubar = this;
207 int BC_MenuBar::deactivate()
209 for(int i = 0; i < menu_titles.total; i++)
211 menu_titles.values[i]->deactivate_menu();
213 top_level->active_menubar = 0;
218 int BC_MenuBar::unhighlight()
220 for(int i = 0; i < menu_titles.total; i++)
222 menu_titles.values[i]->unhighlight();
227 int BC_MenuBar::draw_face()
231 draw_9segment(0, 0, get_w(), get_h(), menu_bar_bg);
243 ux = w - 1; uy = h - 1;
245 set_color(top_level->get_resources()->menu_light);
246 draw_line(0, 0, 0, uy);
247 draw_line(0, 0, ux, 0);
249 set_color(top_level->get_resources()->menu_shadow);
250 draw_line(ux, ly, ux, uy);
251 draw_line(lx, uy, ux, uy);
253 draw_line(w, 0, w, h);
254 draw_line(0, h, w, h);