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