2 #include "bcmenuitem.h"
3 #include "bcmenupopup.h"
5 #include "bcpopupmenu.h"
6 #include "bcresources.h"
16 #define TOTAL_IMAGES 3
23 BC_PopupMenu::BC_PopupMenu(int x,
30 : BC_SubWindow(x, y, 0, 0, -1)
32 highlighted = popup_down = 0;
36 this->margin = margin;
38 this->margin = BC_WindowBase::get_resources()->popupmenu_margin;
40 this->use_title = use_title;
41 strcpy(this->text, text);
42 for(int i = 0; i < TOTAL_IMAGES; i++)
51 BC_PopupMenu::BC_PopupMenu(int x,
56 : BC_SubWindow(x, y, w, -1, -1)
58 highlighted = popup_down = 0;
61 this->use_title = use_title;
62 strcpy(this->text, text);
63 for(int i = 0; i < TOTAL_IMAGES; i++)
72 BC_PopupMenu::~BC_PopupMenu()
74 if(menu_popup) delete menu_popup;
75 for(int i = 0; i < TOTAL_IMAGES; i++)
77 if(images[i]) delete images[i];
81 char* BC_PopupMenu::get_text()
86 void BC_PopupMenu::set_text(char *text)
90 strcpy(this->text, text);
95 void BC_PopupMenu::set_icon(BC_Pixmap *icon)
100 if(menu_popup) draw_title();
104 int BC_PopupMenu::initialize()
111 if(BC_WindowBase::get_resources()->popupmenu_images)
112 set_images(BC_WindowBase::get_resources()->popupmenu_images);
114 set_images(BC_WindowBase::get_resources()->generic_button_images);
117 // Move outside window if no title
125 BC_SubWindow::initialize();
127 menu_popup = new BC_MenuPopup;
128 menu_popup->initialize(top_level,
134 if(use_title) draw_title();
139 int BC_PopupMenu::set_images(VFrame **data)
141 BC_Resources *resources = get_resources();
142 for(int i = 0; i < 3; i++)
144 if(images[i]) delete images[i];
145 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
151 resources->popupmenu_triangle_margin;
153 w = get_text_width(MEDIUMFONT, text) +
155 resources->popupmenu_triangle_margin;
157 h = images[BUTTON_UP]->get_h();
161 int BC_PopupMenu::calculate_h(VFrame **data)
166 if(BC_WindowBase::get_resources()->popupmenu_images)
167 data = BC_WindowBase::get_resources()->popupmenu_images;
169 data = BC_WindowBase::get_resources()->generic_button_images;
172 return data[BUTTON_UP]->get_h();
175 int BC_PopupMenu::add_item(BC_MenuItem *item)
177 menu_popup->add_item(item);
181 int BC_PopupMenu::remove_item(BC_MenuItem *item)
183 menu_popup->remove_item(item);
187 int BC_PopupMenu::total_items()
189 return menu_popup->total_menuitems();
193 BC_MenuItem* BC_PopupMenu::get_item(int i)
195 return menu_popup->menu_items.values[i];
198 int BC_PopupMenu::draw_title()
200 if(!use_title) return 0;
201 BC_Resources *resources = get_resources();
204 draw_top_background(parent_window, 0, 0, w, h);
205 draw_3segmenth(0, 0, w, images[status]);
208 set_color(get_resources()->popup_title_text);
210 if(status == BUTTON_DN)
214 set_font(MEDIUMFONT);
215 BC_WindowBase::draw_center_text(
216 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset,
217 (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2) + offset,
224 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset - icon->get_w() / 2 ,
225 get_h() / 2 - icon->get_h() / 2 + offset);
228 draw_triangle_down_flat(get_w() - margin - resources->popupmenu_triangle_margin,
229 get_h() / 2 - TRIANGLE_H / 2,
230 TRIANGLE_W, TRIANGLE_H);
236 int BC_PopupMenu::deactivate()
240 top_level->active_popup_menu = 0;
242 menu_popup->deactivate_menu();
244 if(use_title) draw_title(); // draw the title
249 int BC_PopupMenu::activate_menu()
256 top_level->deactivate();
257 top_level->active_popup_menu = this;
260 x = top_level->get_abs_cursor_x(0) - get_w();
261 y = top_level->get_abs_cursor_y(0) - get_h();
262 button_press_x = top_level->cursor_x;
263 button_press_y = top_level->cursor_y;
270 int new_x, new_y, top_w, top_h;
271 XTranslateCoordinates(top_level->display,
279 menu_popup->activate_menu(new_x,
287 menu_popup->activate_menu(x, y, w, h, 0, 1);
289 if(use_title) draw_title();
294 int BC_PopupMenu::deactivate_menu()
301 int BC_PopupMenu::reposition_window(int x, int y)
303 BC_WindowBase::reposition_window(x, y);
308 int BC_PopupMenu::focus_out_event()
315 int BC_PopupMenu::repeat_event(int64_t duration)
317 if(duration == top_level->get_resources()->tooltip_delay &&
318 tooltip_text[0] != 0 &&
319 status == BUTTON_HI &&
329 int BC_PopupMenu::button_press_event()
333 if(get_buttonpress() == 1 &&
337 top_level->hide_tooltip();
338 if(status == BUTTON_HI || status == BUTTON_UP) status = BUTTON_DN;
346 && (get_buttonpress() == 4 || get_buttonpress() == 5)
347 && menu_popup->total_menuitems() > 1
351 for (int i = 0; i < menu_popup->total_menuitems(); i++) {
352 if (!strcmp(menu_popup->menu_items.values[i]->get_text(),get_text())) {
358 if (theval == -1) theval=0;
359 else if (get_buttonpress() == 4) theval--;
360 else if (get_buttonpress() == 5) theval++;
364 if (theval >= menu_popup->total_menuitems())
365 theval = menu_popup->total_menuitems() - 1;
367 BC_MenuItem *tmp = menu_popup->menu_items.values[theval];
368 set_text(tmp->get_text());
369 if (!tmp->handle_event())
370 this->handle_event();
376 // Menu is down so dispatch to popup.
377 menu_popup->dispatch_button_press();
384 int BC_PopupMenu::button_release_event()
391 if(is_event_win() && use_title)
394 if(status == BUTTON_DN)
403 // Menu is down so dispatch to popup.
404 result = menu_popup->dispatch_button_release();
407 if(popup_down && button_releases >= 2)
412 if(!result && use_title && cursor_inside() && is_event_win())
418 if(!result && !use_title && popup_down && button_releases < 2)
424 if(!result && popup_down)
426 // Button was released outside any menu.
444 // Menu is down so dispatch to popup.
445 result = menu_popup->dispatch_button_release();
448 if(!result && use_title && cursor_inside() && top_level->event_win == win)
451 if(button_releases >= 2)
459 if(!result && !use_title && button_releases < 2)
461 // First release outside a floating menu
462 // Released outside a fictitious title area
463 // if(top_level->cursor_x < button_press_x - 5 ||
464 // top_level->cursor_y < button_press_y - 5 ||
465 // top_level->cursor_x > button_press_x + 5 ||
466 // top_level->cursor_y > button_press_y + 5)
474 int BC_PopupMenu::translation_event()
476 //printf("BC_PopupMenu::translation_event 1\n");
477 if(popup_down) menu_popup->dispatch_translation_event();
481 int BC_PopupMenu::cursor_leave_event()
484 if(status == BUTTON_HI && use_title)
494 menu_popup->dispatch_cursor_leave();
501 int BC_PopupMenu::cursor_enter_event()
503 if(is_event_win() && use_title)
506 if(top_level->button_down)
511 if(status == BUTTON_UP)
519 int BC_PopupMenu::cursor_motion_event()
523 // This menu is down.
526 result = menu_popup->dispatch_motion_event();
529 if(!result && use_title && top_level->event_win == win)
553 int BC_PopupMenu::drag_start_event()
555 //printf("BC_PopupMenu::drag_start_event %d\n", popup_down);
556 if(popup_down) return 1;
560 int BC_PopupMenu::drag_stop_event()
562 if(popup_down) return 1;
566 int BC_PopupMenu::drag_motion_event()
568 if(popup_down) return 1;