The text of a manual · part 7 of 18
Qlarity-Based Terminal Programmer's Reference Manual: Chapter 3 Messages and Message Handler Prototypes, pages 33 to 39
Pages 33 to 39 of 134, from Qlarity-Based Terminal Programmer's Reference Manual
The original document is the PDF (1.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the QSI Corp QTERM-G70
Page 33
CHAPTER 3 MESSAGES AND MESSAGE HANDLER PROTOTYPES
In Qlarity, functions that handle messages must fit a specified format, or number and type of parameters, and the type of return value. The message handler formats may vary depending on whether the message is being handled by a global function, a function inside a container type object, or a function inside an area or non-drawable object. Message handler functions that return a boolean value can typically terminate the message (stop it from moving forward through the message handling system) by returning a value of “true.” Returning a value of “false” allows the message to continue on through the message handling system. Descriptions of all system messages are provided in this chapter. Included is the format (number and types of parameters and return type) used to declare a handler for each message.
3.1 Broadcast Messages Broadcast messages are sent to all objects (regardless of their enabled or disabled status) according to the Z-order. A message is first passed to the root container (where it is possibly handled by global functions), which then passes the message to each of its children, beginning with the frontmost object (highest Z-order). When the message is passed to a container object, the container object first handles the message then passes it to each of its children, beginning with the front-most object. In this manner, the message filters down through the object hierarchy until all objects have received the message. Broadcast message handlers do not have a return value and, therefore, cannot terminate the message. Message: MSG_INIT Description: This message is sent to all objects on system startup. It is the first message generated in the system. It allows each object to synchronize its system software attributes (enabled, parent, position, size, etc.) with its properties and to perform other startup functions. Do not rely on the order of reception for the init message (don’t assume others are already inited). Handler Format: func <name>( ) handles MSG_INIT [...] endfunc
MSG_INIT handlers take no parameters and do not have a return value.
3.2 Area Messages Area messages are associated with a given area, or point, (X,Y coordinate) on the terminal display. A message is first passed to the root container (where it is possibly handled by global functions), which then checks for any enabled children that contain or overlap the area of the message. This checking is done in Z-order, starting with the front-most object. If a child is eligible to receive the message, the message is passed to the child. When the message is passed to a container object (including the root container), it first handles the message then does a similar check for enabled children that contain or overlap the message area. After all of a container's children have received the message, the handler in the container (if any) is called a second time. In this manner, the message filters down through and back up the object hierarchy until all eligible objects have received it. Global area message handlers are considered to be methods of the root container. They are therefore eligible to receive a message twice (once before any of the root's children and once after all of root's children have received the message). Only area and container objects can receive area messages. Non-drawable objects are not eligible to handle them. The parameters of an area message handler indicate the location of the event on the screen. Area message handlers have a boolean return value used to terminate the message. Returning a value of “true” terminates the message, while returning a value of “false” allows the message to continue through the message handling system.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 34
22
QSI Qlarity-based Terminal Programmer’s Reference
The format for the handler is different for container and area objects. Containers have an additional boolean parameter. The value of this parameter is “false” when the container handler is called before the message passes to the container's children. When the handler is called after the container's children have received the message, the value of this parameter is “true.” A container, such as a form object, that doesn’t handle an area message directly (e.g., a screen press) generally returns “false” the first time the handler is called. This allows the container’s children to handle the message. However, “true” is returned on the second call to prevent objects behind the container (and therefore hidden) from receiving the message. Message: MSG_SCREEN_PRESS Description: This message indicates that a touch screen press event has occurred. Handler Format: (if handled by a container object/global) func <name>(<x> as integer, <y> as -> integer, pass as boolean) returns boolean handles MSG_SCREEN_PRESS [...] endfunc
(if handled by an area object) func <name> (<x> as integer, <y> as -> integer, returns boolean handles MSG_SCREEN_PRESS [...] endfunc
Parameters: <x> The x-location of press event (with respect to the parent's origin)
message, and true if the container's children have already received the message. Message: MSG_SCREEN_RELEASE Description: This message indicates that a touch screen release event has occurred. Handler Format: (if handled by a container object/global) func <name> (<x> as integer, <y> as -> integer, pass as boolean) returns boolean handles MSG_SCREEN_RELEASE [...] endfunc
(if handled by an area object) func <name> (<x> as integer, <y> as -> integer returns boolean handles MSG_SCREEN_RELEASE [...] endfunc
Parameters: <x> The x-location of press event (with respect to the parent's origin) <y> The y-location of the press event (with respect to the parent's origin) <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message. Message: MSG_SCREEN_MOVE
<y> The y-location of press event (with respect to the parent's origin) <pass> False if the container's children have not yet received the
Description: This message indicates that the user has moved his or her finger across the touch screen without lifting it. Objects whose area contains the starting or ending (or both) coordinates receive this message.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 35
QSI Qlarity-based Terminal Programmer’s Reference
Handler Format: (if handled by a container object) func <name> (<x_to> as integer, <y_to> as -> integer, <x_from> as integer, <y_from> as -> integer, <pass> as boolean) returns boolean handles MSG_SCREEN_MOVE [...] endfunc
(if handled by an area object) func <name> (<xto> as integer, <yto> as -> integer, <xfrom> as integer, <yfrom> as -> integer) returns boolean handles MSG_SCREEN_MOVE [...] endfunc
23 should just repaint the object entirely, and the system software clips the repainted region to the invalid region. Non-drawable objects are not eligible to receive this message. Draw messages are handled by the system as a low priority. Draw messages are placed in a separate message queue that is serviced when the regular message queue is empty. Also, the system software may combine multiple invalid regions into a single draw message to increase drawing efficiency. Message: MSG_DRAW Description:
Parameters:
This message indicates that the receiving object needs to paint itself on the screen.
<x_to> The final x-location after the move (with respect to the parent's origin).
Handler Format:
<y_to> The final y-location after the move (with respect to the parent's origin).
func <name> (<pass> as boolean) handles MSG_DRAW [...] endfunc
<x_from> The initial x-location before the move (with respect to the parent's origin). <y_from> The initial y-location before the move (with respect to the parent's origin). <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message.
3.3 Draw Messages A draw message cannot be terminated, and it is passed to containers (including the root container) twice, as described in section 3.2, “Area Messages.” This allows the container to draw borders around itself or perform other actions that should take place after the container’s children have finished handling the message. Unlike area messages, the actual invalid region is not passed to the handler as a set of parameters. Rather, the handler
(if handled by a container object)
(if handled by an area object) func <name>() handles MSG_DRAW [...] endfunc
Parameters: (if handled by a container object) <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message. A container should draw its background when “pass = false” and its borders when “pass = true.” (if handled by an area object) No parameters.
3.4 Registered Messages Registered messages are associated with system events such as a serial character receive, network packet receive, or
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 36
24
QSI Qlarity-based Terminal Programmer’s Reference timer tick. Event handlers that process these messages are registered with the system software using registration functions in the Qlarity API. Because these events are usually handled by a small number of functions, registration avoids the need to filter the message through the entire object hierarchy. If the handler in the registration list is an object method, the object owning the method is checked by the system software to ensure that it and every parent container (back to the root container) are enabled. If this condition is satisfied, the event handler is called. Because the root container cannot be disabled, global function event handlers are called without this check. If more than one object has registered for a given message, the objects receive the message in Z-order (as with area messages) with the root container (global handlers) receiving highest priority. Objects with handlers for registered messages may be registered to receive these messages by calling the RegisterMsgHandler() API function. This is typically done in the MSG_INIT handler for the object, but it can be done at any time. Each different type of message must be registered individually for a given object. Key handlers are registered using the RegisterKey() API function. Objects may be registered for a specific key or for all keys (using the parameter KEY_ALL). The actual keycode is passed to the handler as a parameter, so a handler registered for KEY_ALL can determine what key was pressed or released. A list of constants defining all keys for the keyboard or keypad is included in Appendix A, “Builtin Constants and Defined Types”. Registered objects may also be unregistered by calling the UnregisterMsgHandler() API function, after which the object will no longer receive the message. To unregister a key handler, register the object with the parameter KEY_NONE.
minates the message, while returning a value of “false” allows the message to continue on through the system. NOTE: The messages MSG_COMM_RECEIVE, MSG_COMM_RECEIVE_URGENT and MSG_COMM_RECEIVE_MULTICAST are all registered for at the same time. In other words, if an object registers for one of these messages, then it registers for all of them. Message: MSG_COMM_RECEIVE Description: This message indicates that one or more characters have been received from a communications interface (COM port or Ethernet port). You can register for multiple communications resources. As a result, you will receive this message each time data is received from any one of the resources for which you are registered. Use the GetComMessageSource API to determine the communications resource that resulted in the generation of this message. Handler Format: func <name> (<data>[] as byte) returns -> boolean handles MSG_COMM_RECEIVE [...] endfunc
Parameters: <data> A byte array containing the data that was received from the communications interface. Message: MSG_COMM_RECEIVE_URGENT
The key messages MSG_KEY_DOWN, MSG_KEY_ PRESS, and MSG_KEY_RELEASE are similar to area messages in that container objects receive the message twice: once before it is passed to the container’s children, and once after all of its children have received it. A boolean parameter is used to indicate which pass is taking place when the handler is called. The parameter value is false if the children have not yet received the message, and true if the children have already received it. Also similar to area message handlers, registered message handlers return a boolean value that is used to terminate the message. Returning a value of “true” from the handler ter-
Description: This message indicates that one or more characters have been received via the Transmission Control Protocol (TCP) urgent or out-of-band data channel. This message is only generated by a TCP communications resource. You can register for multiple communications resources. As a result, you will receive this message each time data is received from any one of the resources for which you are registered. Use the GetComMessageSource API to determine the communications resource that resulted in the generation of this message.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 37
QSI Qlarity-based Terminal Programmer’s Reference
Handler Format:
Message:
func <name> (<data>[] as byte) returns -> boolean handles MSG_COMM_RECEIVE_URGENT [...] endfunc
MSG_COMM_TRANSMIT
Parameters: <data> A byte array containing the data that was received via a TCP urgent data channel. Message: MSG_COMM_RECEIVE_MULTICAST Description: This message indicates that a packet has been received from a multicast communications interface. You can register for multiple communications resources. As a result, you will receive this message each time data is received from any one of the resources for which you are registered. Use the GetComMessageSource API to determine the communications resource that resulted in the generation of this message.
Description: This message indicates that one or more characters are to be transmitted by the communications interface. (EIA-232, 422, -485, Ethernet, etc.) This message is generated by calling the Send() API function, and it is useful for implementing a protocolizing function (adding a header, tail, checksum, etc.) for transmitted data in a single location. Handlers for this message should call the Transmit() API function to actually send the data. Handler Format: func <name> (<data>[] as byte) returns -> boolean handles MSG_COMM_TRANSMIT [...] endfunc
Parameters: <data> A byte array containing the data that is to be transmitted by the communications interface.
Handler Format:
Message:
func <name> (<data>[] as byte, <lport> as -> unibyte, <fport> as unibyte, <ip>[] as -> byte) returns boolean handles MSG_COMM_RECEIVE_MULTICAST [...] endfunc
MSG_TIMETICK
Parameters: <data> A byte array containing the information that was received from the communications interface.
25
Description: This message indicates that a system timer has expired. When registering for this message, an object specifies the interval between messages in 20 millisecond increments. The minimum interval is 40 milliseconds. A MSG_TIMETICK message is sent to the registered object at each time interval. Handler Format:
<lport> The local port number on the unit that the received data was destined for.
func <name> ( ) handles MSG_TIMETICK [...] endfunc
<fport> The foreign port number on the host that was the origin of the data.
Handlers for MSG_TIMETICK have no parameters and no return value.
<ip> The IP address of the host that was the origin of the data.
Message: MSG_KEY_DOWN
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 38
26
QSI Qlarity-based Terminal Programmer’s Reference
Description: This message indicates that a key has been pressed on the keyboard or keypad. The keyboard and keypad are distinguished by unique keycodes. If the key repeat feature is available on the keyboard or keypad and the key is held down, then the MSG_KEY_DOWN will only occur on the initial press (not as the key is repeated). Use this message to determine a key’s state (up or down); use MSG_KEY_ PRESS to determine the character typed (e.g., for a text editor). To be eligible to process this message, an object must register for it using the RegisterKey() API function (see section 4.2.3). Handler Format: (if handled by a container object/global) func <name> (<keycode> as unibyte, <pass> -> as boolean) handles MSG_KEY_DOWN [...] endfunc
(if handled by an area/non-drawable object) func <name> (<keycode> as unibyte) handles MSG_KEY_DOWN [...] endfunc this message, an object must register for it using the RegisterKey() API function (see section 4.2.3). Handler Format: (if handled by a container object/global) func <name> (<keycode> as unibyte, <pass> -> as boolean) handles MSG_KEY_PRESS [...] endfunc
(if handled by an area/non-drawable object) func <name> (<keycode> as unibyte) handles MSG_KEY_PRESS [...] endfunc
Parameters: <keycode> A unibyte containing the keycode for the key that was pressed. Most keycodes are defined as constants, which are listed in Appendix A. <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message.
Parameters: <keycode> A unibyte containing the keycode for the key that was pressed. Most keycodes are defined as constants, which are listed in Appendix A. <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message. Message: MSG_KEY_PRESS
Message: MSG_KEY_RELEASE Description: This message indicates that a key has been released on the keyboard or keypad. The keyboard and keypad are distinguished by unique keycodes. This message is unaffected by the key repeat feature. To be eligible to process this message, an object must register for it using the RegisterKey() API function (see section 4.2.3). Handler Format: (if handled by a container object/global)
Description: This message indicates that a key has been pressed on the keyboard or keypad. The keyboard and keypad are distinguished by unique keycodes. If the key repeat feature is available on the keyboard or keypad and the key is held down, then the MSG_KEY_PRESS will occur for the initial key (immediately after the MSG_KEY_DOWN message is sent) and for each key repeat event. To be eligible to process func <name> (<keycode> as unibyte, <pass> -> as boolean) handles MSG_KEY_RELEASE [...] endfunc
(if handled by an area/non-drawable object) func <name> (<keycode> as unibyte)
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 39
QSI Qlarity-based Terminal Programmer’s Reference handles MSG_KEY_RELEASE [...] endfunc
Parameters: <keycode> A unibyte containing the keycode for the key that was pressed. Most keycodes are defined as constants, which are listed in Appendix A. <pass> False if the container's children have not yet received the message, and true if the container's children have already received the message.
3.5 User Messages Although hardware events are generated by the system software, it is often desirable for the application to have the ability to send messages to indicate software events. Qlarity allows you to define user messages and a flexible set of Qlarity API functions to send these messages. 3.5.1
Defining User Messages
Syntax: constant message <msg_name>
27 order and may be terminated with a handler return value of “true.” Unlike area messages, these user messages are not sent to container objects twice. Container handlers are called before the message is passed to the container's children. A message sent with UserDirectMsg() goes to the object regardless of the object’s enabled status. UserBroadcastMsg(), UserSendMsg(), and UserDirectMsg() have a boolean parameter that determines whether the current message processing is suspended while the user message is handled by the messaging system. Passing a value of “true” will suspend the current processing until the user message has been processed. Processing of the suspended message then resumes at the statement following the API call to send the user message. Passing a value of “false” in this parameter causes the message to be enqueued as any other message. Any exceptions occurring during immediate handling filter up to where the message was initiated. All user messages carry a single integer parameter that can be used for any desired purpose. The integer is passed as a parameter to the particular API function and is received as a parameter in the handler function. 3.5.3
Handlers for User Messages
Description:
Description: This statement declares a user message named “<msg_name>.” The name can be any legal identifier; however, it is advisable to use a common convention for naming user messages, such as UMSG_XXXX.
This message indicates that a user message named “<msg_name>” has been sent. Handler Format:
Like other user-defined types, this declaration must appear in the global code area. Messages cannot be declared inside object definitions or instances.
func <name> (<intdata> as integer) -> returns boolean handles msg_name [...] endfunc
3.5.2
Parameters:
Sending User Messages
User messages are sent using the UserBroadcastMsg(), UserSendMsg(), and UserDirectMsg() API functions. These functions are described in detail in section 4.12, “User Message Functions” in this manual. Messages sent with UserBroadcastMsg() behave as broadcast messages. They go to all objects (enabled or disabled) in Z-order and cannot be terminated. Messages sent with UserSendMsg() behave as area messages. They are passed to eligible (enabled) objects in Z-
<intdata> An integer that can be used for any desired purpose. The meaning of the return value depends on how the message was sent, as follows: Broadcast The return value is ignored. User A return value of true = kill message; false = continue.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770