indexing description: "[ A window with a title and a close button. ]" date: "$Date$" revision: "$Revision$" class EM_DIALOG inherit EM_WINDOW redefine delegate_factory end EM_SHARED_WIDGET_OPTIONS export {NONE} all end create make_empty, make_from_title feature {NONE} -- Initialisation make_empty is -- Initialise dialog with empty title. do make_from_title ("") end make_from_title (a_title: like title) is -- Initialise dialog with `a_title'. require a_title_not_void: a_title /= Void do create close_button.make_from_text ("x") create title_label.make_from_text (a_title) create close_button_clicked_event make_from_dimension (20, 20) title := a_title is_draggable := True title_label.align_center title_label.mouse_dragged_event.subscribe (agent handle_mouse_dragged_on_title) add_widget (title_label) close_button.clicked_event.subscribe (agent hide) close_button.clicked_event.subscribe (agent close_button_clicked_event.publish ([])) add_widget (close_button) layout_header resize_event.subscribe (agent layout_header) ensure title_set: title = a_title end delegate_factory: FUNCTION [ANY, TUPLE [], like delegate] is -- Factory to create default delegate do Result := theme_delegates.dialog_delegate_factory end feature -- Access title: STRING -- Title of dialog feature -- Status report is_close_button_visible: BOOLEAN is -- Is close button visible? do Result := close_button.is_visible end is_draggable: BOOLEAN -- Is dialog draggable? feature -- Status setting show_close_button is -- Show close button. do close_button.show ensure close_button_visible: is_close_button_visible end hide_close_button is -- Hide close button. do close_button.hide ensure close_button_hidden: not is_close_button_visible end set_draggable (a_value: BOOLEAN) is -- Set `is_draggable' to `a_value'. do is_draggable := a_value ensure is_draggable_set: is_draggable = a_value end feature -- Element change set_title (a_title: like title) is -- Set `title' to `a_title'. require a_title_not_void: a_title /= Void do title := a_title title_label.set_text (title) ensure title_set: title = a_title end feature -- Events close_button_clicked_event: EM_EVENT_CHANNEL [TUPLE []] -- Close button clicked event feature {NONE} -- Mouse management handle_mouse_dragged_on_title (event: EM_MOUSEMOTION_EVENT) is -- Handle mouse dragging on title local new_x, new_y: INTEGER do if is_draggable then new_x := x+event.motion.x.floor new_y := y+event.motion.y.floor if Widget_options.is_dialog_dragging_restriction_enabled then new_x := new_x.max (0).min (Video_subsystem.video_surface_width-width) new_y := new_y.max (0).min (Video_subsystem.video_surface_height-height) end set_position (new_x, new_y) end end feature {EM_WIDGET_DELEGATE} -- Implementation close_button: EM_BUTTON -- Close button title_label: EM_LABEL -- Title label layout_header is -- Layout the header widgets. do close_button.set_dimension (16, 16) close_button.set_position (inner_width - close_button.width-2, -border.top + 2) title_label.set_position (-border.left, -border.top) title_label.set_dimension (width, 20) end end