2 #include "bcmenupopup.h"
4 #include "bcpopupmenu.h"
5 #include "bcresources.h"
14 #define TOTAL_IMAGES 3
21 BC_PopupMenu::BC_PopupMenu(int x,
28 : BC_SubWindow(x, y, 0, 0, -1)
30 highlighted = popup_down = 0;
34 this->margin = margin;
36 this->margin = BC_WindowBase::get_resources()->popupmenu_margin;
38 this->use_title = use_title;
39 strcpy(this->text, text);
40 for(int i = 0; i < TOTAL_IMAGES; i++)
49 BC_PopupMenu::BC_PopupMenu(int x,
54 : BC_SubWindow(x, y, w, -1, -1)
56 highlighted = popup_down = 0;
59 this->use_title = use_title;
60 strcpy(this->text, text);
61 for(int i = 0; i < TOTAL_IMAGES; i++)
70 BC_PopupMenu::~BC_PopupMenu()
72 if(menu_popup) delete menu_popup;
73 for(int i = 0; i < TOTAL_IMAGES; i++)
75 if(images[i]) delete images[i];
79 char* BC_PopupMenu::get_text()
84 void BC_PopupMenu::set_text(char *text)
88 strcpy(this->text, text);
93 void BC_PopupMenu::set_icon(BC_Pixmap *icon)
98 if(menu_popup) draw_title();
102 int BC_PopupMenu::initialize()
109 if(BC_WindowBase::get_resources()->popupmenu_images)
110 set_images(BC_WindowBase::get_resources()->popupmenu_images);
112 set_images(BC_WindowBase::get_resources()->generic_button_images);
115 // Move outside window if no title
123 BC_SubWindow::initialize();
125 menu_popup = new BC_MenuPopup;
126 menu_popup->initialize(top_level,
132 if(use_title) draw_title();
137 int BC_PopupMenu::set_images(VFrame **data)
139 BC_Resources *resources = get_resources();
140 for(int i = 0; i < 3; i++)
142 if(images[i]) delete images[i];
143 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
149 resources->popupmenu_triangle_margin;
151 w = get_text_width(MEDIUMFONT, text) +
153 resources->popupmenu_triangle_margin;
155 h = images[BUTTON_UP]->get_h();
159 int BC_PopupMenu::calculate_h(VFrame **data)
164 if(BC_WindowBase::get_resources()->popupmenu_images)
165 data = BC_WindowBase::get_resources()->popupmenu_images;
167 data = BC_WindowBase::get_resources()->generic_button_images;
170 return data[BUTTON_UP]->get_h();
173 int BC_PopupMenu::add_item(BC_MenuItem *item)
175 menu_popup->add_item(item);
179 int BC_PopupMenu::remove_item(BC_MenuItem *item)
181 menu_popup->remove_item(item);
185 int BC_PopupMenu::total_items()
187 return menu_popup->total_menuitems();
191 BC_MenuItem* BC_PopupMenu::get_item(int i)
193 return menu_popup->menu_items.values[i];
196 int BC_PopupMenu::draw_title()
198 if(!use_title) return 0;
199 BC_Resources *resources = get_resources();
202 draw_top_background(parent_window, 0, 0, w, h);
203 draw_3segmenth(0, 0, w, images[status]);
206 set_color(get_resources()->popup_title_text);
208 if(status == BUTTON_DN)
212 set_font(MEDIUMFONT);
213 BC_WindowBase::draw_center_text(
214 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset,
215 (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2) + offset,
222 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset - icon->get_w() / 2 ,
223 get_h() / 2 - icon->get_h() / 2 + offset);
226 draw_triangle_down_flat(get_w() - margin - resources->popupmenu_triangle_margin,
227 get_h() / 2 - TRIANGLE_H / 2,
228 TRIANGLE_W, TRIANGLE_H);
234 int BC_PopupMenu::deactivate()
238 top_level->active_popup_menu = 0;
240 menu_popup->deactivate_menu();
242 if(use_title) draw_title(); // draw the title
247 int BC_PopupMenu::activate_menu()
254 top_level->deactivate();
255 top_level->active_popup_menu = this;
258 x = top_level->get_abs_cursor_x(0) - get_w();
259 y = top_level->get_abs_cursor_y(0) - get_h();
260 button_press_x = top_level->cursor_x;
261 button_press_y = top_level->cursor_y;
268 int new_x, new_y, top_w, top_h;
269 XTranslateCoordinates(top_level->display,
277 menu_popup->activate_menu(new_x,
285 menu_popup->activate_menu(x, y, w, h, 0, 1);
287 if(use_title) draw_title();
292 int BC_PopupMenu::deactivate_menu()
299 int BC_PopupMenu::reposition_window(int x, int y)
301 BC_WindowBase::reposition_window(x, y);
306 int BC_PopupMenu::focus_out_event()
313 int BC_PopupMenu::repeat_event(int64_t duration)
315 if(duration == top_level->get_resources()->tooltip_delay &&
316 tooltip_text[0] != 0 &&
317 status == BUTTON_HI &&
327 int BC_PopupMenu::button_press_event()
331 if(get_buttonpress() == 1 &&
335 top_level->hide_tooltip();
336 if(status == BUTTON_HI || status == BUTTON_UP) status = BUTTON_DN;
344 // Menu is down so dispatch to popup.
345 menu_popup->dispatch_button_press();
352 int BC_PopupMenu::button_release_event()
358 //printf("BC_PopupMenu::button_release_event 1 %d\n", result);
360 if(is_event_win() && use_title)
363 if(status == BUTTON_DN)
369 //printf("BC_PopupMenu::button_release_event 2 %d\n", result);
373 // Menu is down so dispatch to popup.
374 result = menu_popup->dispatch_button_release();
377 if(popup_down && button_releases >= 2)
381 //printf("BC_PopupMenu::button_release_event 3 %d\n", result);
383 if(!result && use_title && cursor_inside() && is_event_win())
385 //printf("BC_PopupMenu::button_release_event 4 %d\n", result);
390 if(!result && !use_title && popup_down && button_releases < 2)
392 //printf("BC_PopupMenu::button_release_event 5 %d\n", result);
395 //printf("BC_PopupMenu::button_release_event 6 %d\n", result);
398 if(!result && popup_down)
400 // Button was released outside any menu.
404 //printf("BC_PopupMenu::button_release_event 5 %d\n", result);
419 // Menu is down so dispatch to popup.
420 result = menu_popup->dispatch_button_release();
423 if(!result && use_title && cursor_inside() && top_level->event_win == win)
426 if(button_releases >= 2)
434 if(!result && !use_title && button_releases < 2)
436 // First release outside a floating menu
437 // Released outside a fictitious title area
438 // if(top_level->cursor_x < button_press_x - 5 ||
439 // top_level->cursor_y < button_press_y - 5 ||
440 // top_level->cursor_x > button_press_x + 5 ||
441 // top_level->cursor_y > button_press_y + 5)
449 int BC_PopupMenu::translation_event()
451 //printf("BC_PopupMenu::translation_event 1\n");
452 if(popup_down) menu_popup->dispatch_translation_event();
456 int BC_PopupMenu::cursor_leave_event()
459 if(status == BUTTON_HI && use_title)
469 menu_popup->dispatch_cursor_leave();
476 int BC_PopupMenu::cursor_enter_event()
478 if(is_event_win() && use_title)
481 if(top_level->button_down)
486 if(status == BUTTON_UP)
494 int BC_PopupMenu::cursor_motion_event()
498 // This menu is down.
501 result = menu_popup->dispatch_motion_event();
504 if(!result && use_title && top_level->event_win == win)
528 int BC_PopupMenu::drag_start_event()
530 //printf("BC_PopupMenu::drag_start_event %d\n", popup_down);
531 if(popup_down) return 1;
535 int BC_PopupMenu::drag_stop_event()
537 if(popup_down) return 1;
541 int BC_PopupMenu::drag_motion_event()
543 if(popup_down) return 1;