indexing description: "[ Basic delegate of an EM_CONTEXT_MENU. ]" date: "$Date$" revision: "$Revision$" class EM_BASIC_CONTEXT_MENU_DELEGATE inherit EM_LIST_DELEGATE redefine install, optimal_width, optimal_height, draw_body end feature -- Setup install (menu: EM_CONTEXT_MENU) is -- Install style on `menu'. -- Set up all default values for background, border, font and colors. do Precursor {EM_LIST_DELEGATE} (menu) menu.set_background_color (theme_colors.standard_background) menu.set_border (create {EM_LINE_BORDER}.make (theme_colors.list_border, 1)) menu.set_selection_background_color (theme_colors.selected_background) menu.set_selection_foreground_color (theme_colors.selected_text) end feature -- Layout optimal_width (menu: EM_CONTEXT_MENU): INTEGER is -- Optimal width of `list' local cursor: DS_LIST_CURSOR [EM_WIDGET] do from cursor := menu.elements_impl.new_cursor cursor.start until cursor.off loop Result := Result.max (cursor.item.width + cursor.item.x) cursor.forth end end optimal_height (menu: EM_CONTEXT_MENU): INTEGER is -- Optimal height `list' local cursor: DS_LIST_CURSOR [EM_WIDGET] do if menu.has_void_element then Result := menu.font.string_height (default_string) end from cursor := menu.elements_impl.new_cursor cursor.start until cursor.off loop Result := Result.max (cursor.item.y + cursor.item.height) cursor.forth end end feature -- Drawing draw_body (menu: EM_CONTEXT_MENU) is -- local cursor: DS_LIST_CURSOR [EM_WIDGET] element: EM_WIDGET do from cursor := menu.elements_impl.new_cursor cursor.start until cursor.after loop element := cursor.item if menu.selected_index = cursor.index then element.set_background_color (theme_colors.selected_background) else element.set_background_color (theme_colors.standard_background) end cursor.forth end end feature -- Basic operations position_to_text_index (menu: EM_CONTEXT_MENU; a_x, a_y: INTEGER): INTEGER is -- List index at position `a_x' `a_y' do Result := a_y // ((menu.height - menu.border.top - menu.border.bottom)// menu.widgets.count) if not menu.has_void_element then Result := Result + 1 end if Result > menu.count then Result := -1 end end feature {NONE} -- Implementation default_string: STRING is "ATpq" -- String for default measurements end