indexing description: "[ Basic delegate of an EM_COMBOBOX. ]" date: "$Date$" revision: "$Revision$" class EM_BASIC_COMBOBOX_DELEGATE inherit EM_LIST_DELEGATE redefine install, optimal_width, optimal_height, draw_body end feature -- Initialisation install (combobox: EM_COMBOBOX [ANY]) is -- Install style on `combobox'. -- Set up all default values for background, border, font and colors. do Precursor {EM_LIST_DELEGATE} (combobox) combobox.set_background_color (theme_colors.standard_background) combobox.set_border (create {EM_LINE_BORDER}.make (theme_colors.list_border, 1)) end feature -- Measurement optimal_width (combobox: EM_COMBOBOX [ANY]): INTEGER is -- Optimal width of `combobox' local cursor: DS_LIST_CURSOR [ANY] do from cursor := combobox.elements_impl.new_cursor cursor.start until cursor.off loop combobox.to_string_agent.call ([cursor.item]) Result := Result.max (combobox.font.string_width (combobox.to_string_agent.last_result)) cursor.forth end Result := Result + combobox.border.left + combobox.border.right + 16 end optimal_height (combobox: EM_COMBOBOX [ANY]): INTEGER is -- Optimal height of `combobox' local cursor: DS_LIST_CURSOR [ANY] do if combobox.has_void_element then Result := combobox.font.string_height (default_string) end from cursor := combobox.elements_impl.new_cursor cursor.start until cursor.off loop combobox.to_string_agent.call ([cursor.item]) Result := Result.max (combobox.font.string_height (combobox.to_string_agent.last_result)) cursor.forth end Result := Result + combobox.border.top + combobox.border.bottom end feature -- Drawing draw_body (combobox: EM_COMBOBOX [ANY]) is -- Draw body of `combobox'. local x, y: INTEGER element_string: STRING do combobox.surface.set_drawing_color (combobox.foreground_color) x := combobox.border.left + 1 y := combobox.border.top if combobox.has_selected_element then combobox.to_string_agent.call ([combobox.selected_element]) element_string := combobox.to_string_agent.last_result combobox.font.draw_string (element_string, combobox.surface, x, y) end from y := 0 variant 6-y until y > 5 loop combobox.surface.put_pixel (combobox.width - combobox.border.right - 2 - y, combobox.border.top + 2 + y, combobox.foreground_color) from x := y variant 11-y-x until x > 10 - y loop combobox.surface.put_pixel (combobox.width - combobox.border.right - 3 - x, combobox.border.top + 2 + y, combobox.foreground_color) x := x + 1 end y := y + 1 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 end feature {NONE} -- Implementation default_string: STRING is "ATpq" -- String for default measurements end