indexing description: "[ A menu item that provides a submenu in a context menu. The submenu has to be added in the component scene with add_component (a_component: EM_COMPONENT). ]" date: "$Date$" revision: "$Revision$" class EM_MENU_ITEM inherit EM_LABEL redefine add_widget, make_from_text end create make_from_text feature -- Initialisation make_from_text (a_text: STRING_8) is -- create a menu item with name `a_text' do create menu.make_empty precursor (a_text) -- if mouse enters oder exits the item -- then show or hide the context menu mouse_entered_event.subscribe (agent show_menu) mouse_clicked_event.subscribe (agent wrap_show_menu) mouse_exited_event.subscribe (agent hide_menu) end feature -- Access add_from_menu (a_menu: EM_CONTEXT_MENU) is -- add a menu `a_menu' require a_menu_not_void: a_menu /= void do menu := a_menu menu.set_parent_menu_item (current) ensure menu = a_menu end add_widget (a_widget: EM_WIDGET) is -- add a single widget `a_widget' to the menu do menu.put (a_widget) end feature {EM_CONTEXT_MENU} -- Menu Management show_menu is -- to present the menu local x_, y_: INTEGER do -- build up menu -- standard position for submenu x_ := parent_widget.x + parent_widget.width -5 y_ := parent_widget.y + y +2 -- if the submenu reaches over boundaries -- swap side if screen_x + parent_widget.width + menu.width > video_subsystem.video_surface_width then x_ := x_ - parent_widget.width - menu.width +5 +7 end if screen_y + y + menu.height > video_subsystem.video_surface_height then y_ := y_ + height - menu.height +2 end -- and show menu.set_position (x_, y_) menu.show_menu ensure not_off_screen: screen_x + menu.width < video_subsystem.video_surface_width and screen_y + menu.height < video_subsystem.video_surface_height end hide_menu is -- hide the menu local a_context_menu: EM_CONTEXT_MENU do -- we got a hide command and our menu is visible, so hide it if menu.is_visible then menu.hide_menu end end feature -- Implementation menu: EM_CONTEXT_MENU feature {NONE} -- Wrapper wrap_show_menu (an_event: EM_MOUSEBUTTON_EVENT) is -- a dirty wrapper to call show_menu with mouse_clicked do show_menu end feature {EM_CONTEXT_MENU, EM_MENU_ITEM} -- Implementation cascaded_close is -- used to close all menues above and below current menu_item local a_context_menu: EM_CONTEXT_MENU do a_context_menu ?= parent_widget if a_context_menu /= void and a_context_menu.is_visible then a_context_menu.cascaded_close end end invariant menu_created: menu /= Void end