indexing description: "[ A widget which displays a list of elements. The elements are displayd as strings and the conversion agent can be set using `set_to_string_agent'. By default the feature `out' from ANY will be used. See EM_LIST ]" date: "$Date$" revision: "$Revision$" class EM_TEXTLIST [G] inherit EM_LIST [G] create make_empty, make_from_list feature {NONE} -- Initialisation make_empty is -- Initialise empty list. do make_list make_void_surface set_keyboard_sensitive (True) resize_to_optimal_dimension key_down_event.subscribe (agent handle_key_down) mouse_button_down_event.subscribe (agent handle_mouse_button_down) to_string_agent := agent default_to_string_agent (?) end make_from_list (a_list: DS_LINEAR [G]) is -- Initialise list with elements from `a_list'. do make_empty elements_impl.extend_last (a_list) end delegate_factory: FUNCTION [ANY, TUPLE [], like delegate] is -- Factory to create default delegate do Result := theme_delegates.textlist_delegate_factory end feature -- Access to_string_agent: FUNCTION [ANY, TUPLE [G], STRING] -- Agent to convert elements to a string. selection_background_color: EM_COLOR -- Background on selected element selection_foreground_color: EM_COLOR -- Foreground on selected element feature -- Element change set_to_string_agent (an_agent: like to_string_agent) is -- Set `to_string_agent' to `an_agent'. require an_agent_not_void: an_agent /= Void do to_string_agent := an_agent set_changed ensure to_string_agent_set: to_string_agent = an_agent changed: is_changed end set_selection_background_color (a_color: like selection_background_color) is -- set the background color of the selected element to `a_color'. require a_color_not_void: a_color /= Void do selection_background_color := a_color set_changed ensure selection_background_color_set: selection_background_color = a_color changed: is_changed end set_selection_foreground_color (a_color: like selection_foreground_color) is -- set the foreground color of the selected element to `a_color'. require a_color_not_void: a_color /= Void do selection_foreground_color := a_color set_changed ensure selection_foreground_color_set: selection_foreground_color = a_color changed: is_changed end feature {NONE} -- Mouse management handle_mouse_button_down (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button down event. local clicked_index: INTEGER a_list: EM_LIST [ANY] do a_list ?= Current clicked_index := delegate.position_to_text_index (a_list, event.x, event.y) if clicked_index <= 0 then unselect else set_selected_index (clicked_index) end end feature {NONE} -- Keyboard management handle_key_down (event: EM_KEYBOARD_EVENT) is -- Handle key down event. do if count > 0 then if event.key = event.sdlk_up then if selected_index <= 1 and has_void_element then unselect elseif selected_index > 1 then set_selected_index (selected_index - 1) end elseif event.key = event.sdlk_down then if not has_selected_element then set_selected_index (1) elseif selected_index < count then set_selected_index (selected_index + 1) end end end end feature {NONE} -- Implementation default_to_string_agent (an_element: G): STRING is -- Default to string conversion. do Result := an_element.out end end