User Interface Event Handlers: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page lifting)
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOEDITSECTION__
<div style="float: right; margin-left: 1.5em; max-width: 25%;">__TOC__</div>
User Interface Event handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.
User Interface Event handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.


==Reference List==
{{Important|When using the event names listed below with the [[ctrlAddEventHandler]], [[ctrlSetEventHandler]], [[displayAddEventHandler]] or [[displaySetEventHandler]] commands, the prefix "on" in the name must be removed. (e.g. ''''ButtonDown'''' instead of ''''onButtonDown'''')}}


{| class="sortable bikitable"
== Reference List ==
! Priority
<div style="max-width: 72%;">{{Important|When using the event names listed below with the [[ctrlAddEventHandler]], [[ctrlSetEventHandler]], [[displayAddEventHandler]] or [[displaySetEventHandler]] commands, the prefix "on" in the name must be removed (e.g. ''''ButtonDown'''' instead of ''''onButtonDown'''').}}</div>
! Event
! Fired
! Notes and Parameters
! Scope
|-
|  class="priority" | 1
|  class="event" | onButtonClick
|  class="fired" | The attached button action is performed. When returned value is [[true]], button's display remains opened.
|  class="notes" | Returns control.
|  class="scope" | Button
|-
|  class="priority" | ?
|  class="event" | onButtonDblClick
|  class="fired" | ?
|  class="notes" | Arma 3
|  class="scope" | Button
|- <span idonButtonDown"/>
|  class="priority" | 1
|  class="event" | onButtonDown
|  class="fired" | The left mouse button is pressed over the button area or a key on the keyboard is pressed.
|  class="notes" | Returns control.
|  class="scope" | Button
|- <span idonButtonUp"/>
|  class="priority" | 1
|  class="event" | onButtonUp
|  class="fired" | The left mouse buttons is released outside the button area and the attached button action is not performed.
|  class="notes" | Returns control.
|  class="scope" | Button
|-
|  class="priority" | 3
|  class="event" | onCanDestroy
|  class="fired" | Ask this control if dialog can be closed (used for validation of contained data).
|  class="notes" | Returns the control and exit code.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onChar
|  class="fired" | When some readable characters is recognised.
|  class="notes" | Returns the control and the char code.
|  class="scope" | Control
|-
|  class="priority" | ?
|  class="event" | onChecked
|  class="fired" | CheckBox checked
|  class="notes" | Arma 3
|  class="scope" | Checkbox
|-
|  class="priority" | ?
|  class="event" | onCheckedChanged
|  class="fired" | Checked state of CheckBox changed.
|  class="notes" | Arma 3. Returns control and the checked state (0 or 1, not boolean).
|  class="scope" | Checkbox
|-
|  class="priority" | 2
|  class="event" | onCheckBoxesSelChanged
|  class="fired" | Changed the selection in a checkbox.
|  class="notes" | Returns the control, the selected element index and the current state.
|  class="scope" | Checkbox
|-
|  class="priority" | 1
|  class="event" | onChildDestroyed
|  class="fired" | Child display is closed.
|  class="notes" | Returns the display, which child display was closed and exit code.
|  class="scope" | Display
|-
|  class="priority" | 3
|  class="event" | onDestroy
|  class="fired" | Destroying control
|  class="notes" | Returns the control and exit code.
|  class="scope" | Control
|-
|  class="priority" | ?
|  class="event" | onDraw
|  class="fired" | Fires when the map is drawn (can occur more than once per second).
|  class="notes" | Returns the map control.
|  class="scope" | Map
|-
|  class="priority" | 2
|  class="event" | onHTMLLink
|  class="fired" | Pressing and releasing a HTML link.
|  class="notes" | Returns the control and href.
|  class="scope" | HTML
|-
|  class="priority" | 2
|  class="event" | onIMEChar
|  class="fired" | When IME character is recognized (used in Korean and other eastern languages).
|  class="notes" | Returns the control and the char code.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onIMEComposition
|  class="fired" | When partial IME character is recognized (used in Korean and other eastern languages).
|  class="notes" | Returns the control and the char code.
|  class="scope" | Control
|-
|  class="priority" | 3
|  class="event" | onJoystickButton
|  class="fired" | Pressing and releasing any joystick button.
|  class="notes" | '''Not in Arma 2 or Arma 3''' Returns the control and the the pressed button.
|  class="scope" | Control
|- <span idonKeyDown"/>
|  class="priority" | 2
|  class="event" | onKeyDown
|  class="fired" | Pressing any keyboard key. Fired before the [[#onKeyUp|onKeyUp]] event.
|  class="notes" | Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
|  class="scope" | Display, Control
|- <span idonKeyUp"/>
|  class="priority" | 2
|  class="event" | onKeyUp
|  class="fired" | Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
|  class="notes" | Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
|  class="scope" | Display, Control
|-
|  class="priority" | 2
|  class="event" | onKillFocus
|  class="fired" | Input focus is no longer on control. It no longer accepts keyboard input.
|  class="notes" | Returns control.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onLBSelChanged
|  class="fired" | The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
|  class="notes" | Returns the control and the selected element index.
|  class="scope" | Listbox,Combobox
|-
|  class="priority" | 2
|  class="event" | onLBListSelChanged
|  class="fired" | Selection in XCombo box changed (but value is not stored yet).
|  class="notes" | Returns the control and the selected element index.
|  class="scope" | Listbox
|-
|  class="priority" | 2
|  class="event" | onLBDblClick
|  class="fired" | Double click on some row in listbox.
|  class="notes" | Returns the control and the selected element index.
|  class="scope" | Listbox
|-
|  class="priority" | 2
|  class="event" | onLBDrag
|  class="fired" | Drag & drop operation started.
|  class="notes" | Returns the control and the selected element index.
|  class="scope" | Listbox
|-
|  class="priority" | 2
|  class="event" | onLBDragging
|  class="fired" | Drag & drop operation is in progress.
|  class="notes" | Returns the control and the x and y coordinates.
|  class="scope" | Listbox
|-
|  class="priority" | 2
|  class="event" | onLBDrop
|  class="fired" | Drag & drop operation finished.
|  class="notes" | Returns the control and the x and y coordinates.When the Listbox is inside a ctrlGroup the eventhandler need to be added to the ctrlGroup
|  class="scope" | Listbox, Combobox, Textbox, ActiveText, Button
|-
|  class="priority" | 1
|  class="event" | onLoad
|  class="fired" | Fires when UI container is created, but no action is taken. onLoad event for display fires '''after''' onLoad events for all controls it contains are fired.
|  class="notes" | Returns the display or control.
|  class="scope" | Display, Control
|-
|  class="priority" | 2
|  class="event" | onMenuSelected
|  class="fired" | Some item in context menu (used now only in new mission editor) was selected.
|  class="notes" | Returns the control and the command id.
|  class="scope" | Context menu
|- <span idonMouseButtonDown"/>
|  class="priority" | 2
|  class="event" | onMouseButtonDown
|  class="fired" | Pressing a mouse button. Followed by the [[#onMouseButtonUp|onMouseButtonUp]] event.
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
|  class="scope" | Control
|- <span idonMouseButtonUp"/>
|  class="priority" | 2
|  class="event" | onMouseButtonUp
|  class="fired" | Releasing a mouse button. Follows the [[#onMouseButtonDown|onMouseButtonDown]] event.
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onMouseButtonClick
|  class="fired" | Pressing and releasing a mouse button.
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
|  class="scope" | ListBox, ComboBox, TextBox, Button, ActiveText
|-
|  class="priority" | 2
|  class="event" | onMouseButtonDblClick
|  class="fired" | Pressing and releasing a mouse button twice within very short time.
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
|  class="scope" | Control
|-
|  class="priority" rowspan=2| 2
|  class="event" rowspan=2 | onMouseMoving
|  class="fired" rowspan=2 | Fires continuously while moving the mouse with a certain interval.
|  class="notes" | Returns the control, the <u> x and y coordinates relative to control</u> and mouseOver.
|  class="scope" | Control
|-
| class="notes" | Returns the display, the <u>some kind of x and y delta position</u>.
| class="scope" | Display
|-
|  class="priority" | 1
|  class="event" | onMouseEnter
|  class="fired" | The mouse pointer enters the control area.
|  class="notes" | Returns control.
|  class="scope" | Control
|-
|  class="priority" | 1
|  class="event" | onMouseExit
|  class="fired" | The mouse pointer exits the control area.
|  class="notes" | Returns control.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onMouseHolding
|  class="fired" | Fires continuously while mouse is not moving with a certain interval.
|  class="notes" | Returns the control, the x and y coordinates and mouseOver. If used with a display, the mouseOver parameter is excluded.
|  class="scope" | Control
|-
|  class="priority" | 2
|  class="event" | onMouseZChanged
|  class="fired" | Fires when mouse wheel position is changed. Does not fire on disabled control. Checked with CT_EDIT type in v1.50.
|  class="notes" | Returns the control and the change of the scrollbar.
|  class="scope" | Control only
|-
|  class="priority" | 2
|  class="event" | onObjectMoved
|  class="fired" | Moving an object.
|  class="notes" | Returns the control and the offset on the x, y and z axes.
|  class="scope" | Object
|-
|  class="priority" | 2
|  class="event" | onSetFocus
|  class="fired" | Input focus is on control. It now begins to accept keyboard input.
|  class="notes" | Returns control.
|  class="scope" | Control
|-
|  class="priority" | 3
|  class="event" | onTimer
|  class="fired" | After amount of time given by setTimer function.
|  class="notes" | Returns control.
|  class="scope" | Control
|-
|  class="priority" | 1
|  class="event" | onUnload
|  class="fired" | Display is closed, but no controls are destroyed yet. '''NOTE:''' onUnload event doesn't fire for RscTitles displays started with [[cutRsc]]
|  class="notes" | Returns the display and exit code.
|  class="scope" | Display
|-
|  class="priority" | 2
|  class="event" | onSliderPosChanged
|  class="fired" | Changing the position of a slider.
|  class="notes" | Returns the control and the change.
|  class="scope" | Slider
|-
|  class="priority" | 2
|  class="event" | onToolBoxSelChanged
|  class="fired" | Changed the selection in a toolbox.
|  class="notes" | Returns the control and the selected element index.
|  class="scope" | Toolbox
|-
|  class="priority" | 2
|  class="event" | onTreeLButtonDown
|  class="fired" | Pressing and releasing left mouse button on a tree.
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 3
|  class="event" | onTreeCollapsed
|  class="fired" | The tree folder structure has been collapsed.
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onTreeDblClick
|  class="fired" | Pressing and releasing twice on a tree entry.
|  class="notes" | Returns the control and the current selection path.
|  class="scope" | Tree
|-
|  class="priority" | 3
|  class="event" | onTreeExpanded
|  class="fired" | The tree folder structure has been expanded.
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onTreeMouseExit
|  class="fired" | The mouse pointer exits the tree control area
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onTreeMouseHold
|  class="fired" | Fires continuously while mouse is not moving with a certain interval.
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onTreeMouseMove
|  class="fired" | Fires continuously while moving the mouse with a certain interval.
|  class="notes" | Returns the control.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onTreeSelChanged
|  class="fired" | Changing the selection in a tree.
|  class="notes" | Returns the control and the new selection path.
|  class="scope" | Tree
|-
|  class="priority" | 2
|  class="event" | onVideoStopped
|  class="fired" | {{GVI|arma2oa|1.56}}<br />Activated every time video ends (when looped, handler is executed after every finished loop).
|  class="notes" | Returns the control
|  class="scope" | Control
|}


==Event parameters==
The events handlers receive parameters in the ''[[_this]]'' variable. Each event passes a different set of parameters (listed in the table above) in an array. The control or display that the event was assigned to is always found in {{Inline code|[[_this]] [[select]] 0}}.


==Scope==
=== Generic events ===
In ArmA, most control-specific events work for controls and do not work for displays. The 2 exceptions being: '''''onKeyDown''''' and '''''onKeyUp'''''.
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onLoad ====
* '''Priority:''' 1
* '''Use on:''' Display, Control
* '''Fired on:''' Fires when UI container is created, but no action is taken. onLoad event for display fires '''after''' onLoad events for all controls it contains are fired.
* '''Returns:''' Returns the display or control in format [[Array]].


Since Arma 2, most control-specific events now work for both displays and controls.


==Defining events==
==== onUnload ====
User Interface Event Handlers can be assigned in two ways: via class property definitions or via [[:Category:Scripting Commands|scripting commands]].
* '''Priority:''' 1
* '''Use on:''' Display
* '''Fired on:''' Display is closed, but no controls are destroyed yet.
* '''Returns:''' Returns the display and exit code.
{{note|onUnload event doesn't fire for RscTitles displays started with [[cutRsc]]}}
 
 
==== onChildDestroyed ====
* '''Priority:''' 1
* '''Use on:''' Display
* '''Fired on:''' Child display is closed.
* '''Returns:''' Returns the display, which child display was closed and exit code.
<syntaxhighlight lang="cpp">params ["_display", "_closedChildDisplay", "_exitCode"];</syntaxhighlight>
 
 
==== onMouseEnter ====
* '''Priority:''' 1
* '''Use on:''' Control
* '''Fired on:''' The mouse pointer enters the control area.
* '''Returns:''' Returns control.
 
 
==== onMouseExit ====
* '''Priority:''' 1
* '''Use on:''' Control
* '''Fired on:''' The mouse pointer exits the control area.
* '''Returns:''' Returns control.
 
 
==== onSetFocus ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Input focus is on control. It now begins to accept keyboard input.
* '''Returns:''' Returns control.
 
 
==== onKillFocus ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Input focus is no longer on control. It no longer accepts keyboard input.
* '''Returns:''' Returns control.
 
 
==== onTimer ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Fired on:''' After amount of time given by setTimer function.
* '''Returns:''' Returns control.
 
 
==== onKeyDown ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Fired on:''' Pressing any keyboard key. Fired before the [[#onKeyUp|onKeyUp]] event.
* '''Returns:''' Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
 
 
==== onKeyUp ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Fired on:''' Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
* '''Returns:''' Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
 
 
==== onChar ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' When some readable characters is recognised.
* '''Returns:''' Returns the control and the char code.
 
 
==== onIMEChar ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' When IME character is recognized (used in Korean and other eastern languages).
* '''Returns:''' Returns the control and the char code.
 
 
==== onIMEComposition ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' When partial IME character is recognized (used in Korean and other eastern languages).
* '''Returns:''' Returns the control and the char code.
 
 
==== onJoystickButton ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Fired on:''' Pressing and releasing any joystick button.
* '''Returns:''' Returns the control and the the pressed button.<br />{{note|Not present in Arma 2 or Arma 3}}
 
 
==== onMouseButtonDown ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Pressing a mouse button. Followed by the [[#onMouseButtonUp|onMouseButtonUp]] event.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
 
 
==== onMouseButtonUp ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Releasing a mouse button. Follows the [[#onMouseButtonDown|onMouseButtonDown]] event.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
 
 
==== onMouseButtonClick ====
* '''Priority:''' 2
* '''Use on:''' ListBox, ComboBox, TextBox, Button, ActiveText
* '''Fired on:''' Pressing and releasing a mouse button.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
 
 
==== onMouseButtonDblClick ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Pressing and releasing a mouse button twice within very short time.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
 
 
==== onMouseMoving ====
* '''Priority:''' 2
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
<hr />
* '''Use on:''' Control
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br />
If the controls parent is its display then x and y will be the same as [[getMousePosition]] else it will be relative to its parent control for instance if inside a [[DialogControls-ControlsGroup|controlsGroup]]
<hr />
* '''Use on:''' Display
* '''Returns:''' Returns the display, and ''some kind of'' x and y delta position.
 
 
==== onMouseHolding ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Returns:''' Returns the control, the x and y coordinates and mouseOver. If used with a display, the mouseOver parameter is excluded.
 
 
==== onMouseZChanged ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Fired on:''' Fires when mouse wheel position is changed. Does not fire on disabled control.
* '''Returns:''' Returns the display or control and the change of the scrollwheel.
 
 
==== onCanDestroy ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Fired on:''' Ask this control if dialog can be closed (used for validation of contained data).
* '''Returns:''' Returns the control and exit code.
 
 
==== onDestroy ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Fired on:''' Destroying control
* '''Returns:''' Returns the control and exit code.
{{Cfg ref|end}}
 
 
=== Button events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onButtonClick ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Fired on:''' The attached button action is performed. When returned value is [[true]], button's display remains opened.
* '''Returns:''' Returns control.
 
 
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
==== onButtonDblClick ====
</div>
* '''Priority:''' ?
* '''Use on:''' Button
* '''Fired on:''' button double click?
* '''Returns:''' ?
 
 
==== onButtonDown ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Fired on:''' The left mouse button is pressed over the button area or a key on the keyboard is pressed.
* '''Returns:''' Returns control.
 
 
==== onButtonUp ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Fired on:''' The left mouse buttons is released outside the button area and the attached button action is not performed.
* '''Returns:''' Returns control.
{{Cfg ref|end}}
 
 
=== Listbox events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onLBSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Listbox, Combobox
* '''Fired on:''' The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
* '''Returns:''' Returns the control and the selected element index.
 
 
==== onLBListSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Fired on:''' Selection in XCombo box changed (but value is not stored yet).
* '''Returns:''' Returns the control and the selected element index.
 
 
==== onLBDblClick ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Fired on:''' Double click on some row in listbox.
* '''Returns:''' Returns the control and the selected element index.
 
 
==== onLBDrag ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Fired on:''' Drag & drop operation started.
* '''Returns:''' Returns the control and the selected element index.
 
 
==== onLBDragging ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Fired on:''' Drag & drop operation is in progress.
* '''Returns:''' Returns the control and the x and y coordinates.
 
 
==== onLBDrop ====
* '''Priority:''' 2
* '''Use on:''' Listbox, Combobox, Textbox, ActiveText, Button
* '''Fired on:''' Drag & drop operation finished.
* '''Returns:''' Returns the control and the x and y coordinates.<br />When the Listbox is inside a ctrlGroup the eventhandler need to be added to the ctrlGroup.
{{Cfg ref|end}}
 
 
=== Tree events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onTreeSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' Changing the selection in a tree.
* '''Returns:''' Returns the control and the new selection path.
 
==== onTreeLButtonDown ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing left mouse button on a tree.
* '''Returns:''' Returns the control.
 
==== onTreeDblClick ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing twice on a tree entry.
* '''Returns:''' Returns the control and the current selection path.
 
==== onTreeExpanded ====
* '''Priority:''' 3
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been expanded.
* '''Returns:''' Returns the control.
 
==== onTreeCollapsed ====
* '''Priority:''' 3
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been collapsed.
* '''Returns:''' Returns the control.
 
==== onTreeMouseMove ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
* '''Returns:''' Returns the control.
 
==== onTreeMouseHold ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Returns:''' Returns the control.
 
 
==== onTreeMouseExit ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Fired on:''' The mouse pointer exits the tree control area
* '''Returns:''' Returns the control.
{{Cfg ref|end}}
 
 
=== Checkbox events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
==== onChecked ====
</div>
* '''Use on:''' Checkbox
* '''Priority:''' ?
* '''Fired on:''' CheckBox checked
 
 
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
==== onCheckedChanged ====
</div>
* '''Priority:''' ?
* '''Use on:''' Checkbox
* '''Fired on:''' Checked state of CheckBox changed.
* '''Returns:''' Returns control and the checked state (0 or 1, not boolean).
 
 
==== onCheckBoxesSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Checkbox
* '''Fired on:''' Changed the selection in a checkbox.
* '''Returns:''' Returns the control, the selected element index and the current state.
{{Cfg ref|end}}
 
 
=== Misc. events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onToolBoxSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Toolbox
* '''Fired on:''' Changed the selection in a toolbox.
* '''Returns:''' Returns the control and the selected element index.
 
 
==== onHTMLLink ====
* '''Priority:''' 2
* '''Use on:''' HTML
* '''Fired on:''' Pressing and releasing a HTML link.
* '''Returns:''' Returns the control and href.
 
 
==== onSliderPosChanged ====
* '''Priority:''' 2
* '''Use on:''' Slider
* '''Fired on:''' Changing the position of a slider.
* '''Returns:''' Returns the control and the change.
 
 
==== onObjectMoved ====
* '''Priority:''' 2
* '''Use on:''' Object
* '''Fired on:''' Moving an object.
* '''Returns:''' Returns the control and the offset on the x, y and z axes.
 
 
==== onMenuSelected ====
* '''Priority:''' 2
* '''Use on:''' Context menu
* '''Fired on:''' Some item in context menu (used now only in new mission editor) was selected.
* '''Returns:''' Returns the control and the command id.
 
 
==== onDraw ====
* '''Priority:''' ?
* '''Use on:''' Map
* '''Fired on:''' Fires when the map is drawn (can occur more than once per second).
* '''Returns:''' Returns the map control.
 
 
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma2oa|1.56}}</div>
==== onVideoStopped ====
</div>
* '''Priority:''' 2
* '''Use on:''' Control
* '''Fired on:''' Activated every time the video ends (when looped, handler is executed after every finished loop).
* '''Returns:''' Returns the control
{{Cfg ref|end}}
 
 
== Event parameters ==
The events handlers receive parameters in the ''[[_this]]'' variable.
Each event passes a different set of parameters (listed in the table above) in an array.
The control or display that the event was assigned to is always found in {{Inline code|[[_this]] [[select]] 0}}.
 
 
== Scope ==
{{GVI|arma1|1.00}} In ArmA, most control-specific events work for controls and do not work for displays. The two exceptions being: '''''onKeyDown''''' and '''''onKeyUp'''''.<br />
{{GVI|arma2|1.00}} Since Arma 2, most control-specific events now work for both displays and controls.


===Class defined events===
Events can be defined in the Dialog (display) or Control classes (in [[Config.cpp|config.cpp]] or [[description.ext]]). The event property value (string) is executed as a line of code. An example line (this would be put within a control or dialog class):


<syntaxhighlight lang="c">onMouseDown = "hint str _this";</syntaxhighlight>
== Defining events ==
User Interface Event Handlers can be assigned in two ways: via class property definitions or via [[:Category:Scripting Commands|scripting commands]].


Example:
<syntaxhighlight lang="c">class RscControlsGroup {
    type = 15;
    idc = -1;
    style = 0;
    x = 0;
    y = 0;
    w = 1;
    h = 1;
   
    class VScrollbar {
        color[] = {1,1,1,1};
        width = 0.021000;
        autoScrollSpeed = -1;
        autoScrollDelay = 5;
        autoScrollRewind = 0;
    };
   
    class HScrollbar {
        color[] = {1, 1, 1, 1};
        height = 0.028;
    };


    class ScrollBar { //for ARMA 2
=== Class defined events ===
        color[] = {1,1,1,0.600000};
Events can be defined in the Dialog (display) or Control classes (in [[Config.cpp|config.cpp]] or [[description.ext]]).
        colorActive[] = {1,1,1,1};
The event property value (string) is executed as a line of code.
        colorDisabled[] = {1,1,1,0.300000};
        thumb = "#(argb,8,8,3)color(1,1,1,1)";
        arrowEmpty = "#(argb,8,8,3)color(1,1,1,1)";
        arrowFull = "#(argb,8,8,3)color(1,1,1,1)";
        border = "#(argb,8,8,3)color(1,1,1,1)";
    };
   
    class Controls {};
};


class mouseHandler: RscControlsGroup {         
An example line (this would be put within a control or dialog class):
    onMouseHolding = "[0,_this] call Axx";
<syntaxhighlight lang="cpp">onMouseDown = "hint str _this";</syntaxhighlight>
    onMouseButtonDown = "[1,_this] call Axx";
    onMouseButtonUp = "[2,_this] call Axx";
    onMouseZChanged = "[3,_this] call Axx";   
    onMouseEnter = "[4,_this] call Axx";  
    idc = 123;
    x = 0.0;
    y = 0.0;
    w = 1.0;
    h = 1.0;           
    colorBackground[] = {0.2, 0.0, 0.0, 0.0};
};
</syntaxhighlight>


===Script defined events===
Full Example:
These events can also be given to dialogs/controls using the [[ctrlSetEventHandler]] scripting command.  For the event handler to be called enable the control using the [[ctrlEnable]] scripting command.
<syntaxhighlight lang="cpp">class RscControlsGroup {
type = 15;
idc = -1;
style = 0;
x = 0;
y = 0;
w = 1;
h = 1;


<code>([[findDisplay]] 46) [[displayAddEventHandler]] ["keyDown", "[[_this]] [[call]] functionName_keyDown"];</code>
class VScrollbar {
color[] = { 1, 1, 1, 1 };
width = 0.021;
autoScrollSpeed = -1;
autoScrollDelay = 5;
autoScrollRewind = 0;
};


<code>functionName_keyDown = {
class HScrollbar {
&nbsp;  [[params]] ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
color[] = { 1, 1, 1, 1 };
&nbsp;
height = 0.028;
&nbsp;  [[private]] _handled = [[false]];
};
&nbsp;
&nbsp;  [[if]] (!_shift && !_ctrlKey && !_alt) [[then]] {
&nbsp;      [[if]] (_dikCode [[in]] ([[actionKeys]] "NetworkStats")) [[then]] {
&nbsp;          [] [[execVM]] "path\script.sqf";
&nbsp;          _handled = [[true]];
&nbsp;      };
&nbsp;  };
&nbsp;
&nbsp;  _handled;
};</code><!--


Or
class ScrollBar { // >= Arma 2
color[] = { 1, 1, 1, 0.6 };
colorActive[] = { 1, 1, 1, 1 };
colorDisabled[] = { 1, 1, 1, 0.3 };
thumb = "#(argb,8,8,3)color(1,1,1,1)";
arrowEmpty = "#(argb,8,8,3)color(1,1,1,1)";
arrowFull = "#(argb,8,8,3)color(1,1,1,1)";
border = "#(argb,8,8,3)color(1,1,1,1)";
};


<code>functionName_keyDown = {<nowiki>
class Controls {};
    </nowiki>[[params]] ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];<nowiki>
};


    </nowiki>private _handled = [[false]];<nowiki>
class mouseHandler: RscControlsGroup {
onMouseHolding = "[0,_this] call myEventFunction";
onMouseButtonDown = "[1,_this] call myEventFunction";
onMouseButtonUp = "[2,_this] call myEventFunction";
onMouseZChanged = "[3,_this] call myEventFunction";
onMouseEnter = "[4,_this] call myEventFunction";
idc = 123;
x = 0.0;
y = 0.0;
w = 1.0;
h = 1.0;
colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
};</syntaxhighlight>


    </nowiki>[[if]] (!_shift && !_ctrlKey && !_alt) [[then]] {<nowiki>
        </nowiki>[[if]] (_dikCode [[in]] ([[actionKeys]] "NetworkStats")) [[then]] {<nowiki>
            </nowiki>[] [[execVM]] "path\script.sqf";<nowiki>
            </nowiki>_handled = [[true]];<nowiki>
        </nowiki>};<nowiki>
    </nowiki>};<nowiki>


    </nowiki>_handled;<nowiki>
=== Script defined events ===
</nowiki>};</code>
These events can also be given to dialogs/controls using the [[ctrlSetEventHandler]] scripting command.
For the event handler to be called enable the control using the [[ctrlEnable]] scripting command.


Take your pick :-/ -->
{{codecomment|// adding event handler}}
([[findDisplay]] 46) [[displayAddEventHandler]] ["keyDown", "[[_this]] [[call]] functionName_keyDown"];
{{codecomment|// function definition}}
functionName_keyDown = {
[[params]] ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
[[private]] _handled = [[false]];
[[if]] (!_shift && !_ctrlKey && !_alt) [[then]] {
[[if]] (_dikCode [[in]] ([[actionKeys]] "NetworkStats")) [[then]] {
[] [[execVM]] "path\script.sqf";
_handled = [[true]];
};
};
_handled;
};


==Demo mission==
For VBS2 users, [https://forums.bisimulations.com/viewtopic.php?p=21235#p21235 a demo mission is available here].


[[Category:ArmA: Mission Editing]]
[[Category:ArmA: Mission Editing]]
[[Category:Event Handlers]]
[[Category:Event Handlers]]
[[Category: Dialogs]]
[[Category: Dialogs]]

Revision as of 16:35, 20 April 2018

User Interface Event handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.


Reference List

When using the event names listed below with the ctrlAddEventHandler, ctrlSetEventHandler, displayAddEventHandler or displaySetEventHandler commands, the prefix "on" in the name must be removed (e.g. 'ButtonDown' instead of 'onButtonDown').


Generic events

Template:Cfg ref Template:Cfg ref

onLoad

  • Priority: 1
  • Use on: Display, Control
  • Fired on: Fires when UI container is created, but no action is taken. onLoad event for display fires after onLoad events for all controls it contains are fired.
  • Returns: Returns the display or control in format Array.


onUnload

  • Priority: 1
  • Use on: Display
  • Fired on: Display is closed, but no controls are destroyed yet.
  • Returns: Returns the display and exit code.

Template:note


onChildDestroyed

  • Priority: 1
  • Use on: Display
  • Fired on: Child display is closed.
  • Returns: Returns the display, which child display was closed and exit code.
params ["_display", "_closedChildDisplay", "_exitCode"];


onMouseEnter

  • Priority: 1
  • Use on: Control
  • Fired on: The mouse pointer enters the control area.
  • Returns: Returns control.


onMouseExit

  • Priority: 1
  • Use on: Control
  • Fired on: The mouse pointer exits the control area.
  • Returns: Returns control.


onSetFocus

  • Priority: 2
  • Use on: Control
  • Fired on: Input focus is on control. It now begins to accept keyboard input.
  • Returns: Returns control.


onKillFocus

  • Priority: 2
  • Use on: Control
  • Fired on: Input focus is no longer on control. It no longer accepts keyboard input.
  • Returns: Returns control.


onTimer

  • Priority: 3
  • Use on: Control
  • Fired on: After amount of time given by setTimer function.
  • Returns: Returns control.


onKeyDown

  • Priority: 2
  • Use on: Display, Control
  • Fired on: Pressing any keyboard key. Fired before the onKeyUp event.
  • Returns: Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.


onKeyUp

  • Priority: 2
  • Use on: Display, Control
  • Fired on: Releasing any keyboard key. Fired after the onKeyDown event.
  • Returns: Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.


onChar

  • Priority: 2
  • Use on: Control
  • Fired on: When some readable characters is recognised.
  • Returns: Returns the control and the char code.


onIMEChar

  • Priority: 2
  • Use on: Control
  • Fired on: When IME character is recognized (used in Korean and other eastern languages).
  • Returns: Returns the control and the char code.


onIMEComposition

  • Priority: 2
  • Use on: Control
  • Fired on: When partial IME character is recognized (used in Korean and other eastern languages).
  • Returns: Returns the control and the char code.


onJoystickButton

  • Priority: 3
  • Use on: Control
  • Fired on: Pressing and releasing any joystick button.
  • Returns: Returns the control and the the pressed button.
    Template:note


onMouseButtonDown

  • Priority: 2
  • Use on: Control
  • Fired on: Pressing a mouse button. Followed by the onMouseButtonUp event.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.


onMouseButtonUp

  • Priority: 2
  • Use on: Control
  • Fired on: Releasing a mouse button. Follows the onMouseButtonDown event.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.


onMouseButtonClick

  • Priority: 2
  • Use on: ListBox, ComboBox, TextBox, Button, ActiveText
  • Fired on: Pressing and releasing a mouse button.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.


onMouseButtonDblClick

  • Priority: 2
  • Use on: Control
  • Fired on: Pressing and releasing a mouse button twice within very short time.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.


onMouseMoving

  • Priority: 2
  • Fired on: Fires continuously while moving the mouse with a certain interval.

  • Use on: Control
  • Returns: Returns the control, the x and y coordinates relative to the controls parent and mouseOver.

If the controls parent is its display then x and y will be the same as getMousePosition else it will be relative to its parent control for instance if inside a controlsGroup


  • Use on: Display
  • Returns: Returns the display, and some kind of x and y delta position.


onMouseHolding

  • Priority: 2
  • Use on: Control
  • Fired on: Fires continuously while mouse is not moving with a certain interval.
  • Returns: Returns the control, the x and y coordinates and mouseOver. If used with a display, the mouseOver parameter is excluded.


onMouseZChanged

  • Priority: 2
  • Use on: Display, Control
  • Fired on: Fires when mouse wheel position is changed. Does not fire on disabled control.
  • Returns: Returns the display or control and the change of the scrollwheel.


onCanDestroy

  • Priority: 3
  • Use on: Control
  • Fired on: Ask this control if dialog can be closed (used for validation of contained data).
  • Returns: Returns the control and exit code.


onDestroy

  • Priority: 3
  • Use on: Control
  • Fired on: Destroying control
  • Returns: Returns the control and exit code.

Template:Cfg ref


Button events

Template:Cfg ref Template:Cfg ref

onButtonClick

  • Priority: 1
  • Use on: Button
  • Fired on: The attached button action is performed. When returned value is true, button's display remains opened.
  • Returns: Returns control.


onButtonDblClick

  • Priority: ?
  • Use on: Button
  • Fired on: button double click?
  • Returns: ?


onButtonDown

  • Priority: 1
  • Use on: Button
  • Fired on: The left mouse button is pressed over the button area or a key on the keyboard is pressed.
  • Returns: Returns control.


onButtonUp

  • Priority: 1
  • Use on: Button
  • Fired on: The left mouse buttons is released outside the button area and the attached button action is not performed.
  • Returns: Returns control.

Template:Cfg ref


Listbox events

Template:Cfg ref Template:Cfg ref

onLBSelChanged

  • Priority: 2
  • Use on: Listbox, Combobox
  • Fired on: The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
  • Returns: Returns the control and the selected element index.


onLBListSelChanged

  • Priority: 2
  • Use on: Listbox
  • Fired on: Selection in XCombo box changed (but value is not stored yet).
  • Returns: Returns the control and the selected element index.


onLBDblClick

  • Priority: 2
  • Use on: Listbox
  • Fired on: Double click on some row in listbox.
  • Returns: Returns the control and the selected element index.


onLBDrag

  • Priority: 2
  • Use on: Listbox
  • Fired on: Drag & drop operation started.
  • Returns: Returns the control and the selected element index.


onLBDragging

  • Priority: 2
  • Use on: Listbox
  • Fired on: Drag & drop operation is in progress.
  • Returns: Returns the control and the x and y coordinates.


onLBDrop

  • Priority: 2
  • Use on: Listbox, Combobox, Textbox, ActiveText, Button
  • Fired on: Drag & drop operation finished.
  • Returns: Returns the control and the x and y coordinates.
    When the Listbox is inside a ctrlGroup the eventhandler need to be added to the ctrlGroup.

Template:Cfg ref


Tree events

Template:Cfg ref Template:Cfg ref

onTreeSelChanged

  • Priority: 2
  • Use on: Tree
  • Fired on: Changing the selection in a tree.
  • Returns: Returns the control and the new selection path.

onTreeLButtonDown

  • Priority: 2
  • Use on: Tree
  • Fired on: Pressing and releasing left mouse button on a tree.
  • Returns: Returns the control.

onTreeDblClick

  • Priority: 2
  • Use on: Tree
  • Fired on: Pressing and releasing twice on a tree entry.
  • Returns: Returns the control and the current selection path.

onTreeExpanded

  • Priority: 3
  • Use on: Tree
  • Fired on: The tree folder structure has been expanded.
  • Returns: Returns the control.

onTreeCollapsed

  • Priority: 3
  • Use on: Tree
  • Fired on: The tree folder structure has been collapsed.
  • Returns: Returns the control.

onTreeMouseMove

  • Priority: 2
  • Use on: Tree
  • Fired on: Fires continuously while moving the mouse with a certain interval.
  • Returns: Returns the control.

onTreeMouseHold

  • Priority: 2
  • Use on: Tree
  • Fired on: Fires continuously while mouse is not moving with a certain interval.
  • Returns: Returns the control.


onTreeMouseExit

  • Priority: 2
  • Use on: Tree
  • Fired on: The mouse pointer exits the tree control area
  • Returns: Returns the control.

Template:Cfg ref


Checkbox events

Template:Cfg ref Template:Cfg ref

onChecked

  • Use on: Checkbox
  • Priority: ?
  • Fired on: CheckBox checked


onCheckedChanged

  • Priority: ?
  • Use on: Checkbox
  • Fired on: Checked state of CheckBox changed.
  • Returns: Returns control and the checked state (0 or 1, not boolean).


onCheckBoxesSelChanged

  • Priority: 2
  • Use on: Checkbox
  • Fired on: Changed the selection in a checkbox.
  • Returns: Returns the control, the selected element index and the current state.

Template:Cfg ref


Misc. events

Template:Cfg ref Template:Cfg ref

onToolBoxSelChanged

  • Priority: 2
  • Use on: Toolbox
  • Fired on: Changed the selection in a toolbox.
  • Returns: Returns the control and the selected element index.


onHTMLLink

  • Priority: 2
  • Use on: HTML
  • Fired on: Pressing and releasing a HTML link.
  • Returns: Returns the control and href.


onSliderPosChanged

  • Priority: 2
  • Use on: Slider
  • Fired on: Changing the position of a slider.
  • Returns: Returns the control and the change.


onObjectMoved

  • Priority: 2
  • Use on: Object
  • Fired on: Moving an object.
  • Returns: Returns the control and the offset on the x, y and z axes.


onMenuSelected

  • Priority: 2
  • Use on: Context menu
  • Fired on: Some item in context menu (used now only in new mission editor) was selected.
  • Returns: Returns the control and the command id.


onDraw

  • Priority: ?
  • Use on: Map
  • Fired on: Fires when the map is drawn (can occur more than once per second).
  • Returns: Returns the map control.


onVideoStopped

  • Priority: 2
  • Use on: Control
  • Fired on: Activated every time the video ends (when looped, handler is executed after every finished loop).
  • Returns: Returns the control

Template:Cfg ref


Event parameters

The events handlers receive parameters in the _this variable. Each event passes a different set of parameters (listed in the table above) in an array. The control or display that the event was assigned to is always found in _this select 0.


Scope

Logo A1 black.png1.00 In ArmA, most control-specific events work for controls and do not work for displays. The two exceptions being: onKeyDown and onKeyUp.
Logo A2.png1.00 Since Arma 2, most control-specific events now work for both displays and controls.


Defining events

User Interface Event Handlers can be assigned in two ways: via class property definitions or via scripting commands.


Class defined events

Events can be defined in the Dialog (display) or Control classes (in config.cpp or description.ext). The event property value (string) is executed as a line of code.

An example line (this would be put within a control or dialog class):

onMouseDown = "hint str _this";

Full Example:

class RscControlsGroup {
	type	= 15;
	idc		= -1;
	style	=  0;
	x = 0;
	y = 0;
	w = 1;
	h = 1;

	class VScrollbar {
		color[]				= { 1, 1, 1, 1 };
		width				= 0.021;
		autoScrollSpeed		= -1;
		autoScrollDelay		= 5;
		autoScrollRewind	= 0;
	};

	class HScrollbar {
		color[]	= { 1, 1, 1, 1 };
		height	= 0.028;
	};

	
	class ScrollBar {	// >= Arma 2
		color[]			= { 1, 1, 1, 0.6 };
		colorActive[]	= { 1, 1, 1, 1 };
		colorDisabled[]	= { 1, 1, 1, 0.3 };
		thumb			= "#(argb,8,8,3)color(1,1,1,1)";
		arrowEmpty		= "#(argb,8,8,3)color(1,1,1,1)";
		arrowFull		= "#(argb,8,8,3)color(1,1,1,1)";
		border			= "#(argb,8,8,3)color(1,1,1,1)";
	};

	class Controls {};
};

class mouseHandler: RscControlsGroup {
	onMouseHolding		= "[0,_this] call myEventFunction";
	onMouseButtonDown	= "[1,_this] call myEventFunction";
	onMouseButtonUp		= "[2,_this] call myEventFunction";
	onMouseZChanged		= "[3,_this] call myEventFunction";
	onMouseEnter		= "[4,_this] call myEventFunction";
	idc = 123;
	x = 0.0;
	y = 0.0;
	w = 1.0;
	h = 1.0;
	colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
};


Script defined events

These events can also be given to dialogs/controls using the ctrlSetEventHandler scripting command. For the event handler to be called enable the control using the ctrlEnable scripting command.

// adding event handler
(findDisplay 46) displayAddEventHandler ["keyDown", "_this call functionName_keyDown"];

// function definition
functionName_keyDown = {
	params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
	private _handled = false;

	if (!_shift && !_ctrlKey && !_alt) then {
		if (_dikCode in (actionKeys "NetworkStats")) then {
			[] execVM "path\script.sqf";
			_handled = true;
		};
	};
	_handled;
};