Actions are an implementation of the design-by-contract approach to object orientation. Common activities such as showing and hiding an object on the display, or reading and writing data have been given a dedicated action interface. The 'contract' exists in the strict objectives of each action, as documented in this manual. For instance, calling `Show` and `Hide` actions on a UI object will change its visibility as one would expect. If an action isn't applicable to an object, calling it is legal but will do nothing. This document describes the available action interfaces, including the expectations of behaviour for the client, as well as implementation details of each contract. Where necessary, classes will often clarify the details of how they support their actions. These details are documented in the class manuals. # Action Interfaces The Core API provides multiple functions for action related tasks. `Action()` is used to make immediate calls, and requires an object pointer. `AsyncAction()` launches the action in a separate thread and returns immediately. `QueueAction()` is a pure messaging function, requiring only the object UID and delaying the call until the next message processing cycle. The aforementioned functions are documented completely in the Core API. For C++ users, additional macros are also provided. All actions listed in this document will have an associated stub function prefixed with `ac`. For example, `acShow(Object)` and `acSetKey(Object, Key, Value)`. Automated header generation also ensures that relevant methods are created at class level, meaning `Object->show()` and `Object->setKey(Key, Value)` are similarly valid. Tiri users can call actions with the `acName` template, in this case `object.acShow()` and `object.acSetKey(Key, Value)` would be equivalent to the C++ counterpart. Run-time inspection is supported with the Core API's `CheckAction()` function, which confirms if an object's class supports a given action. The `ActionList()` function provides insight into all known actions and their parameters. Finally, the `SubscribeAction()` function provides a monitoring feature that will call a custom function whenever a given action has been executed for a target object. # Action Index [`Activate`](#activate) | [`Clear`](#clear) | [`Clipboard`](#clipboard) | [`CopyData`](#copydata) | [`DataFeed`](#datafeed) | [`Deactivate`](#deactivate) | [`Disable`](#disable) | [`DragDrop`](#dragdrop) | [`Draw`](#draw) | [`Enable`](#enable) | [`Flush`](#flush) | [`Focus`](#focus) | [`Free`](#free) | [`GetKey`](#getkey) | [`Hide`](#hide) | [`Init`](#init) | [`Lock`](#lock) | [`Move`](#move) | [`MoveToBack`](#movetoback) | [`MoveToFront`](#movetofront) | [`MoveToPoint`](#movetopoint) | [`Next`](#next) | [`Prev`](#prev) | [`Query`](#query) | [`Read`](#read) | [`Redimension`](#redimension) | [`Redo`](#redo) | [`Refresh`](#refresh) | [`Rename`](#rename) | [`Reset`](#reset) | [`Resize`](#resize) | [`SaveImage`](#saveimage) | [`SaveSettings`](#savesettings) | [`SaveToObject`](#savetoobject) | [`Seek`](#seek) | [`SetField`](#setfield) | [`SetKey`](#setkey) | [`Show`](#show) | [`Signal`](#signal) | [`Undo`](#undo) | [`Unlock`](#unlock) | [`Write`](#write) # Internal Actions These actions are implemented for use internally, and must never be called from client code. [`FreeWarning`](#freewarning) | [`LostFocus`](#lostfocus) | [`NewChild`](#newchild) | [`NewObject`](#newobject) | [`NewOwner`](#newowner) | [`NewPlacement`](#newplacement) --- ## Activate `ERR acActivate(Object)` `Activate` causes an object to perform its "native activity". Although ambiguous, the activity should be relevant to the class in question. Here are a few examples of what some existing classes do when their objects are activated: |Class|Description| |:-|:-| |Sound|Plays audio data.| |Script|Runs a scripted program.| |Image|Loads a source image.| It is typical for most classes that support the loading and processing of data to do so in their `Activate` support. Some objects will continue to perform their native activity after they return back to the client - for example, activating a `Sound` object will cause it to play audio in the background. If background processing needs to be cancelled, this should be done with a [`Deactivate`](#Deactivate) call. ### Implementation Details The `Activate` action is intentionally ambiguous, giving free reign as to the nature of the implementation. Even so, it should be intuitively clear what the user would expect from the activation process. If that is not the case, the `Activate` action should probably go unsupported. Remember to support the `Deactivate` action if background activity can be cancelled. ## Clear `ERR acClear(Object)` This action will clear an object of all its data. Typical use cases are the clearing of graphics and data records. Here are some examples: |Class|Description| |:-|:-| |File|Clears file data by reducing the file length down to 0.| |Text|Deletes all lines of text.| |Bitmap|Clears the bitmap of graphics data.| The overall state of the object will normally remain intact - so clearing a file will not cause the file handle to be closed for instance. ## Clipboard `ERR acClipboard(Object, CLIPMODE Mode)` |Name|Type|Description| |:-|:-|:-| |Mode|CLIPMODE|The mode that will be used to shift data between the target object and clipboard system.| The `Clipboard` action is used on objects for the purpose of shifting data between them and the clipboard system. Generally, clients should only use this action when the user has done something that requires it to be called, for instance, holding the `CTRL+C` keys to make a copy operation. Three modes are currently available for performing clip operations, as illustrated in the following table: |CLIPMODE|Description| |:-|:-| |CUT|Cut (copy and delete) the currently selected data from the target object and copy it into the clipboard.| |COPY|Copy the currently selected data from the target object into the clipboard.| |PASTE|Paste the most recent data from the clipboard into the target object.| The specifics of how a target object interacts with a clipboard is down to the developer of the object's class. If you need more information on how an object might interface with the clipboard system, check its class documentation. ### Implementation Details Supporting the system-wide clipboard service requires code to be written for the `Clipboard` action. This action is closely related to the `Clipboard` class, which you will need to instantiate as necessary. The `Mode` reflects the type of action that needs to be performed. Copy and cut operations are identical, apart from the fact that cutting data will require you to delete the information after pasting it into the clipboard. To copy data to a clipboard, use any of the mechanisms supported by the `Clipboard` class, such as the `AddText()` method. Please refer to the documentation for the `Clipboard` class for more information. To paste data from a clipboard into one of your objects, call the `GetFiles()` method to retrieve the data from the file system. You may be 'selective' in the data that you retrieve from the clipboard, for instance, if the next clip is an image and your class only supports text data, you can ignore the image and extract the text data instead. The documentation for the `Clipboard` class has more information on how to scan the data store. ## CopyData `ERR acCopyData(Object, OBJECTPTR Dest)` |Name|Type|Description| |:-|:-|:-| |Dest|OBJECTPTR|The unique ID of the destination object.| The `CopyData` action is used to copy data between objects. To execute the copy process, call the `CopyData` action on the _source_ object, and set the `Dest` to the object that you are copying the data to. If the source object does not recognise the destination object type, it will make calls to the [`Write`](#Write) action to copy the data across. If it does understand the destination object type, it may make an 'intelligent' copy. For instance, when copying the data from one Bitmap to another, the image source will be _drawn_ to the destination. ### Implementation Details The `CopyData` action is provided so that data in one object can be copied across to another. This may or may not involve data conversion. For example, copying data between files is a straight forward process of copying a raw binary stream. However, copying data between two Bitmaps would be more complicated, because we need to consider clipping and colour conversion issues. Copying between different classes is also permitted, for example copying an `Image` to a `File` could output the image as raw data. If you wish to write your routine so that it only supports recognised classes, return `ERR::NoSupport` for those at are unsupported. To support all classes, include a fallback that uses the [`Write`](#Write) action to stream data to the destination object. ## DataFeed ``` ERR acDataFeed(Object, OBJECTPTR Object, DATA Datatype, APTR Buffer, INT Size) ``` |Name|Type|Description| |:-|:-|:-| |Object|OBJECTPTR|Must refer to the unique ID of the object that you represent. If you do not represent an object, set this parameter to the current task ID.| |Datatype|DATA|The type of data being sent.| |Buffer|APTR|The data being sent to the target object.| |Size|INT|The size of the data in `Buffer`.| The `DataFeed` action provides a mechanism for writing typed data to objects. The target `Object` will check the `Datatype` to determine if the `Buffer` content is supported, and if so, will process the data according to what is appropriate for the object's class. The following `Datatype` values are supported: #### DATA::CONTENT This is a special datatype used by the `Document` class to pass XML content to embedded objects. Although this duplicates the `DATA::XML` type, it may be desirable to parse such data differently to `DATA::XML` due to nature of the content. #### DATA::FILE This datatype is used to declare a file path that contains the data to be transferred. It is frequently used to speed up data transfers where loading file data into a buffer and passing it through the DataFeed system would be inefficient. Set the `Size` to the path's string length, including the null byte. #### DATA::RAW Sending raw binary data to an object is equivalent to calling the [`Write`](#Write) action. Set the `Size` to the byte length of the data. #### DATA::RECEIPT In response to a `DATA::REQUEST` from an object, a `RECEIPT` must be sent to the requesting object. The receipt will contain a null-terminated XML string with the data that has been requested. Please refer to the [`DragDrop`](#DragDrop) action for further information. #### DATA::REQUEST The `REQUEST` datatype is intended for supporting drag and drop operations, but theoretically can be used for any type of data transfer between objects where uniquely numbered items may be used. A request for data is achieved by passing an `Item` UID and indicating up to three types of data formats that would be accepted from the source. The `dcRequest` structure for managing the request is configured as follows: |Field|Type|Description| |:-|:-|:-| |Item|INT|Item to retrieve from the source.| |Preference|DATA [4]|Data preferences for the returned item(s).| The datatypes indicated by the Preference field can be any of the pure datatypes supported by the `DataFeed` action, for example `DATA::TEXT` or `DATA::XML`. Any unused elements of the `Preference` array must be set to zero. #### DATA::TEXT Use the `TEXT` datatype when sending UTF-8 text to an object. The `Size` of the string must include the null byte. #### DATA::XML The XML datatype shares the same qualities as `DATA::TEXT`, but explicitly declares the content as being XML formatted. How the information is interpreted by the receiving class is context dependent. It is recommended that you check the class' documentation to see the level of support that is offered. ## Deactivate `ERR acDeactivate(Object)` Deactivating an object that is still in an active state from the [`Activate`](#Activate) action will cause it to halt its activity. If the object is not in an active state, this action does nothing. ### Implementation Details A class that supports the `Activate` action should consider support for `Deactivate` if the object's active state persists beyond the original `Activate` call. If the target object is in an inactive state at the time of the `Deactivate` call, do nothing and return `ERR::Okay` to the client. ## Disable `ERR acDisable(Object)` The `Disable` action is used to put an object into a state where it cannot respond to user interaction. It is typically used to temporarily "turn off" objects in the interface. For instance, disabling a `Vector` object will cause it to drop incoming user events such as button clicks and cursor motion. An object will remain in a disabled state until enabled again with the [`Enable`](#Enable) action. Multiple calls to the `Disable` action will not nest unless the documentation for the object's class states otherwise. ### Implementation Details The Disable action is provided for the purposes of disabling the interactive elements of an object. It is typically supported by classes that have a presence in the UI, or have some other form of user interaction. It is important that only the user-interactive elements of the object are disabled. The object should not be disabled to the point of being useless, as non-interactive changes are still valid. If necessary, a class can nest multiple calls to the Disable action, although this would be considered to be an exception to the rule. If you are going to support nesting, document this fact in the class. Support for the `Disable` action should also be matched with support for the [`Enable`](#Enable) action. This will allow your disabled objects to return to a normal state, as disablement is usually only a temporary measure. ## DragDrop `ERR acDragDrop(Object, OBJECTPTR Source, INT Item, STRVIEW Datatype)` |Name|Type|Description| |:-|:-|:-| |Source|OBJECTPTR|Refers to the object containing the source data.| |Item|INT|An item ID, relevant to the source object.| |Datatype|STRVIEW|A sequence of DATA values indicating the types of data supported by the source item. Priority is given to the first.| The `DragDrop` action provides the core functionality of a universal drag and drop system. The process of drag and drop works as follows: 1. The user initiates a drag and drop operation by clicking and holding the mouse button on an interface item. 2. The owner of that item will monitor click and motion activity that could instigate a drag and drop operation. 3. On detecting the initial stages of the drag and drop operation, the object will create a new graphics `Surface` utilising the `COMPOSITE` and `STICK_TO_FRONT` flags. The Display API's `StartCursorDrag()` function is called to link this surface to the mouse pointer. No further action needs to be taken until the mouse button is released. When the item is dropped by releasing the mouse button over a `Surface`, the following occurs: 1. The mouse pointer will hide the draggable surface that was attached to it. 2. The `DragDrop` action will be called on the surface that is under the pointer's hot spot. The `Source`, `Item` number and datatype originally passed to `StartCursorDrag()` will be included in this action call. 3. If a listener is subscribed to the `DragDrop` action of the targeted surface, it will be able to respond to the drag and drop operation. The listener will need to send a `DATA::REQUEST` via the [`DataFeed`](#DataFeed) action to the object that is referenced in the `Source` parameter. The listener can indicate supported datatypes that it will accept from the source (see the `DataFeed` action for further information) and the Item number received from the `DragDrop` action. 4. The source object will respond by sending a `DATA::RECEIPT` message via the [`DataFeed`](#DataFeed) action. This contains the item data in one of the requested formats. Data for drag and drop activity is defined in XML format. The following template must be adhered to: ``` ` A choice can be made between defining a `path` or `object`. The `object` must belong to the `Sound` class. #### DATA::FILE `` #### DATA::IMAGE `