indexing description: "[ A push button with a label and/or an image. Events: - `clicked_event': Triggered when clicked. Passes no arguments. ]" date: "$Date$" revision: "$Revision$" class EM_BUTTON inherit EM_WIDGET redefine make_void_surface, enable, disable end create make_void_surface, make_from_dimension, make_from_text, make_from_image, make_from_text_image, make_empty feature {NONE} -- Initialisation make_empty is -- Initialise `Current' with empty text do make_void_surface resize_to_optimal_dimension end make_from_text (a_text: like text) is -- Initialise `Current' with `a_text' as label. require a_text_not_void: a_text /= Void do make_void_surface text := a_text resize_to_optimal_dimension ensure text_set: text = a_text end make_from_image (an_image: like image) is -- Initialise `Current' with `an_image' as image. require an_image_not_void: an_image /= Void do make_void_surface image := an_image resize_to_optimal_dimension ensure image_set: image = an_image end make_from_text_image (a_text: like text; an_image: like image) is -- Initialise `Current' with `a_text' as label and `an_image' as image. require an_image_not_void: an_image /= Void do make_void_surface text := a_text image := an_image resize_to_optimal_dimension ensure text_set: text = a_text image_set: image = an_image end make_void_surface is -- Initialise default values. do create text.make_empty image := Void disabled_image := Void create clicked_event Precursor {EM_WIDGET} mouse_button_down_event.subscribe (agent handle_mouse_button_down) mouse_button_up_event.subscribe (agent handle_mouse_button_up) mouse_entered_event.subscribe (agent handle_mouse_entered) mouse_exited_event.subscribe (agent handle_mouse_exited) end delegate_factory: FUNCTION [ANY, TUPLE [], like delegate] is -- Factory to create default delegate do Result := theme_delegates.button_delegate_factory end feature -- Access text: STRING -- Text on `Current' image: EM_BITMAP -- Image on `Current' disabled_image: EM_BITMAP -- Disabled image on `Current' feature -- Status report is_mouse_over: BOOLEAN -- Is mouse over `Current'? is_pressed: BOOLEAN -- Is mouse down on `Current'? feature -- Status setting enable is -- Enable button. do Precursor {EM_WIDGET} set_mouse_over (False) set_pressed (False) end disable is -- Disable button. do Precursor {EM_WIDGET} set_mouse_over (False) set_pressed (False) end set_pressed (value: BOOLEAN) is -- Set `is_pressed' to `value'. do is_pressed := value set_changed ensure is_pressed_set: is_pressed = value changed: is_changed end set_mouse_over (value: BOOLEAN) is -- Set `is_mouse_over' to `value'. do is_mouse_over := value set_changed ensure is_mouse_over_set: is_mouse_over = value changed: is_changed end feature -- Element change set_text (a_text: like text) is -- Set `text' to `a_text'. require a_text_not_void: a_text /= Void do text := a_text set_changed ensure text_set: text = a_text changed: is_changed end set_image (an_image: like image) is -- Set `image' to `an_image'. require an_image_not_void: an_image /= Void do image := an_image set_changed ensure image_set: image = an_image end set_disabled_image (an_image: like disabled_image) is -- Set `disabled_image' to `an_image'. do disabled_image := an_image set_changed ensure image_set: disabled_image = an_image end feature -- Basic operations fire_clicked_event is -- File a clicked event. do Component_event_queue.add_event (clicked_event, []) end feature -- Events clicked_event: EM_EVENT_CHANNEL [TUPLE []] -- Clicked event feature {NONE} -- Mouse management handle_mouse_button_down (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button down event. do set_pressed (True) end handle_mouse_button_up (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button up event. do if is_pressed then fire_clicked_event end set_pressed (False) end handle_mouse_entered is -- Handle mouse entered event. do set_mouse_over (True) end handle_mouse_exited is -- Handle mouse exited event. do set_mouse_over (False) set_pressed (False) end invariant text_not_void: text /= Void clicked_event_not_void: clicked_event /= Void end