2 #include "bcmenupopup.h"
4 #include "bcpopupmenu.h"
5 #include "bcresources.h"
15 #define TOTAL_IMAGES 3
22 BC_PopupMenu::BC_PopupMenu(int x,
29 : BC_SubWindow(x, y, 0, 0, -1)
31 highlighted = popup_down = 0;
35 this->margin = margin;
37 this->margin = BC_WindowBase::get_resources()->popupmenu_margin;
39 this->use_title = use_title;
40 strcpy(this->text, text);
41 for(int i = 0; i < TOTAL_IMAGES; i++)
50 BC_PopupMenu::BC_PopupMenu(int x,
55 : BC_SubWindow(x, y, w, -1, -1)
57 highlighted = popup_down = 0;
60 this->use_title = use_title;
61 strcpy(this->text, text);
62 for(int i = 0; i < TOTAL_IMAGES; i++)
71 BC_PopupMenu::~BC_PopupMenu()
73 if(menu_popup) delete menu_popup;
74 for(int i = 0; i < TOTAL_IMAGES; i++)
76 if(images[i]) delete images[i];
80 char* BC_PopupMenu::get_text()
85 void BC_PopupMenu::set_text(char *text)
89 strcpy(this->text, text);
94 void BC_PopupMenu::set_icon(BC_Pixmap *icon)
99 if(menu_popup) draw_title();
103 int BC_PopupMenu::initialize()
110 if(BC_WindowBase::get_resources()->popupmenu_images)
111 set_images(BC_WindowBase::get_resources()->popupmenu_images);
113 set_images(BC_WindowBase::get_resources()->generic_button_images);
116 // Move outside window if no title
124 BC_SubWindow::initialize();
126 menu_popup = new BC_MenuPopup;
127 menu_popup->initialize(top_level,
133 if(use_title) draw_title();
138 int BC_PopupMenu::set_images(VFrame **data)
140 BC_Resources *resources = get_resources();
141 for(int i = 0; i < 3; i++)
143 if(images[i]) delete images[i];
144 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
150 resources->popupmenu_triangle_margin;
152 w = get_text_width(MEDIUMFONT, text) +
154 resources->popupmenu_triangle_margin;
156 h = images[BUTTON_UP]->get_h();
160 int BC_PopupMenu::calculate_h(VFrame **data)
165 if(BC_WindowBase::get_resources()->popupmenu_images)
166 data = BC_WindowBase::get_resources()->popupmenu_images;
168 data = BC_WindowBase::get_resources()->generic_button_images;
171 return data[BUTTON_UP]->get_h();
174 int BC_PopupMenu::add_item(BC_MenuItem *item)
176 menu_popup->add_item(item);
180 int BC_PopupMenu::remove_item(BC_MenuItem *item)
182 menu_popup->remove_item(item);
186 int BC_PopupMenu::total_items()
188 return menu_popup->total_menuitems();
192 BC_MenuItem* BC_PopupMenu::get_item(int i)
194 return menu_popup->menu_items.values[i];
197 int BC_PopupMenu::draw_title()
199 if(!use_title) return 0;
200 BC_Resources *resources = get_resources();
203 draw_top_background(parent_window, 0, 0, w, h);
204 draw_3segmenth(0, 0, w, images[status]);
207 set_color(get_resources()->popup_title_text);
209 if(status == BUTTON_DN)
213 set_font(MEDIUMFONT);
214 BC_WindowBase::draw_center_text(
215 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset,
216 (int)((float)get_h() / 2 + get_text_ascent(MEDIUMFONT) / 2 - 2) + offset,
223 (get_w() - margin * 2 - resources->popupmenu_triangle_margin) / 2 + margin + offset - icon->get_w() / 2 ,
224 get_h() / 2 - icon->get_h() / 2 + offset);
227 draw_triangle_down_flat(get_w() - margin - resources->popupmenu_triangle_margin,
228 get_h() / 2 - TRIANGLE_H / 2,
229 TRIANGLE_W, TRIANGLE_H);
235 int BC_PopupMenu::deactivate()
239 top_level->active_popup_menu = 0;
241 menu_popup->deactivate_menu();
243 if(use_title) draw_title(); // draw the title
248 int BC_PopupMenu::activate_menu()
255 top_level->deactivate();
256 top_level->active_popup_menu = this;
259 x = top_level->get_abs_cursor_x(0) - get_w();
260 y = top_level->get_abs_cursor_y(0) - get_h();
261 button_press_x = top_level->cursor_x;
262 button_press_y = top_level->cursor_y;
269 int new_x, new_y, top_w, top_h;
270 XTranslateCoordinates(top_level->display,
278 menu_popup->activate_menu(new_x,
286 menu_popup->activate_menu(x, y, w, h, 0, 1);
288 if(use_title) draw_title();
293 int BC_PopupMenu::deactivate_menu()
300 int BC_PopupMenu::reposition_window(int x, int y)
302 BC_WindowBase::reposition_window(x, y);
307 int BC_PopupMenu::focus_out_event()
314 int BC_PopupMenu::repeat_event(int64_t duration)
316 if(duration == top_level->get_resources()->tooltip_delay &&
317 tooltip_text[0] != 0 &&
318 status == BUTTON_HI &&
328 int BC_PopupMenu::button_press_event()
332 if(get_buttonpress() == 1 &&
336 top_level->hide_tooltip();
337 if(status == BUTTON_HI || status == BUTTON_UP) status = BUTTON_DN;
345 // Menu is down so dispatch to popup.
346 menu_popup->dispatch_button_press();
353 int BC_PopupMenu::button_release_event()
360 if(is_event_win() && use_title)
363 if(status == BUTTON_DN)
372 // Menu is down so dispatch to popup.
373 result = menu_popup->dispatch_button_release();
376 if(popup_down && button_releases >= 2)
381 if(!result && use_title && cursor_inside() && is_event_win())
387 if(!result && !use_title && popup_down && button_releases < 2)
393 if(!result && popup_down)
395 // Button was released outside any menu.
413 // Menu is down so dispatch to popup.
414 result = menu_popup->dispatch_button_release();
417 if(!result && use_title && cursor_inside() && top_level->event_win == win)
420 if(button_releases >= 2)
428 if(!result && !use_title && button_releases < 2)
430 // First release outside a floating menu
431 // Released outside a fictitious title area
432 // if(top_level->cursor_x < button_press_x - 5 ||
433 // top_level->cursor_y < button_press_y - 5 ||
434 // top_level->cursor_x > button_press_x + 5 ||
435 // top_level->cursor_y > button_press_y + 5)
443 int BC_PopupMenu::translation_event()
445 //printf("BC_PopupMenu::translation_event 1\n");
446 if(popup_down) menu_popup->dispatch_translation_event();
450 int BC_PopupMenu::cursor_leave_event()
453 if(status == BUTTON_HI && use_title)
463 menu_popup->dispatch_cursor_leave();
470 int BC_PopupMenu::cursor_enter_event()
472 if(is_event_win() && use_title)
475 if(top_level->button_down)
480 if(status == BUTTON_UP)
488 int BC_PopupMenu::cursor_motion_event()
492 // This menu is down.
495 result = menu_popup->dispatch_motion_event();
498 if(!result && use_title && top_level->event_win == win)
522 int BC_PopupMenu::drag_start_event()
524 //printf("BC_PopupMenu::drag_start_event %d\n", popup_down);
525 if(popup_down) return 1;
529 int BC_PopupMenu::drag_stop_event()
531 if(popup_down) return 1;
535 int BC_PopupMenu::drag_motion_event()
537 if(popup_down) return 1;