0862-0865

Previous Table of Contents Next

Page 862

Figure 35.19.
Creating block
relationships in a form.


Mouse Events, Timers, and Other Advanced Widgets

The standard Windows interface uses various graphical controls and other objects to control the operation of application components . Oracle Forms provides access to many of these features through the use of mouse triggers, timers, and VBX controls. Additionally, messaging in most Windows software is through an object called an alert box that has been implemented in Oracle Forms.

Working with the Mouse

The mouse pointer is the primary user -input device for navigation and selection in most
Windows applications. Oracle Forms provides triggers to detect and act on various mouse
activities.

Oracle Forms 4.5 uses the mouse for navigation and command input. Additionally, the mouse can be used to trigger specific events. An event can be triggered when the mouse passes over an item on the screen (WHEN-MOUSE-ENTER) or when it leaves the item (WHEN-MOUSE-LEAVE). A third mouse status event can occur if the mouse moves within an item (WHEN-MOUSE-MOVE).

Table 35.4 describes additional triggers that were added for mouse button activities.

Table 35.4. Mouse triggers.

Trigger Name
Event Description
WHEN-MOUSE-DOWN Operator presses and holds the mouse button.
WHEN-MOUSE-UP Operator releases the mouse button.
WHEN-MOUSE-CLICK Operator quickly presses and releases button.
WHEN-MOUSE-DOUBLECLICK Operator clicks mouse twice in succession.

Page 863

When these activities occur, several system variables retrieve status information for the mouse, as described in Table 35.5.

Table 35.5. Mouse system variables.


Variable
Value
MOUSE_BUTTON_PRESSED Returns 1 for left button; 2 for middle/right
MOUSE_BUTTON_SHIFT_STATE Returns null, Shift+, Ctrl+, or Shift+Ctrl+ depending on key pressed
MOUSE_ITEM Current item where mouse cursor is located
MOUSE_CANVAS Current canvas where mouse cursor is located
MOUSE_X_POS Current X position of mouse within item
MOUSE_Y_POS Current Y position of mouse within item
MOUSE_RECORD Record within block where mouse cursor is located
MOUSE_RECORD_OFFSET Record where mouse cursor is located relative to first displayed record
MOUSE_FORM Current form where mouse cursor is located

You can construct the sample form shown in Figure 35.20 to test and observe the operations of the mouse triggers and variables. To construct this form, create a block, b1, that is not associated with a table. In the Layout Editor, create four fields for TRIGGER_NAME, BUTTON_NUMBER, SHIFT_STATE, and MOUSE_ITEM1, and position these fields with the appropriate caption as shown in the figure. Set the Default value property for the MOUSE_ITEM1 field as WILL TURN RED ON MOUSE ENTRY. Also, create a button object, DRAG_BUTTON, on the canvas with a Label property of Drag This Button.

Figure 35.20.
Mouse observation form.


Next, select the Visual Attributes group in the Object Navigator and click the Add Objects button. In the property sheet for this object, set the font to Arial, size 8, and weight bold. Define the foreground color as BLACK and set the background to WHITE. Name this object BLACK_ON_WHITE. Create a second visual attribute, WHITE_ON_RED, with a white foreground and red background.

Page 864

You will use these visual attributes to define the display colors of the MOUSE_ITEM1 field using a WHEN-MOUSE-ENTER trigger as follows :

 begin    :b1.trigger_name := `MOUSE ENTER';    set_item_property (`B1.MOUSE_ITEM1', VISUAL_ATTRIBUTE,                                    `WHITE_ON_RED'); end; 

Similarly, create a WHEN-MOUSE-LEAVE trigger to use the BLACK_ON_WHITE attribute. Now, create WHEN-MOUSE-DOWN, WHEN-MOUSE-UP, WHEN-MOUSE-CLICK, and WHEN-MOUSE-DOUBLECLICK triggers at the form level to display the status of the mouse whenever a trigger event occurs:

 begin  -- WHEN-MOUSE-DOWN trigger    :b1.trigger_name := `MOUSE DOWN';    :b1.button_number := :system.mouse_button_pressed;    :b1.shift_state := :system.mouse_button_shift_state; end; 

The default installation of Oracle Forms includes several libraries and sample programs that you can use in your Forms development. One of these libraries, DRAG.PLL, provides functions that can be used for drag-and-drop functionality in Oracle Forms. To use this library, select the Attached Libraries group in the form and click the Add Object button. Select the DRAG.PLL file to attach to the form.

To implement drag-and-drop in this form, create two triggers on the DRAG BUTTON item as follows:

 begin -- WHEN-MOUSE-DOWN trigger    mouse.click; end; begin -- WHEN-MOUSE-MOVE trigger    if :system.mouse_button_pressed = 1 then       mouse.move;    end if; end; 

These triggers that reference procedures in the mouse package in the DRAG.PLL library are all that is needed to implement drag operations in a form. You should create a third trigger for the object to define the logic associated with the drop operation (WHEN-MOUSE-UP trigger).

This completes the design of the mouse control form. Run the form to observe how it operates. You should note a few important points at this time. First, observe the operation of passing the cursor over the MOUSE_ITEM1 field. The color of the field changes and the name of the trigger appears in the appropriate field. Now, click anywhere on the canvas. Three triggers actually fire with what appeared to be a single action. The WHEN-MOUSE-DOWN and WHEN-MOUSE-UP triggers fired before the WHEN-MOUSE-CLICK trigger. A double-click event fires all these triggers before firing the WHEN-MOUSE-DOUBLECLICK trigger. Therefore, when working with the mouse, you should take care when defining multiple triggers to prevent the execution of unwanted logic.

Page 865

Working with Alerts

Alerts are devices that can be included in a form to provide the user with information that requires a response. An alert can be one of three styles: Stop (usually fatal errors), Caution (warning messages), and Note (informational). Depending on the style you choose, a different icon appears in the alert box. Additionally, you can define up to three labeled buttons to determine the user response. The default setting is a two-button alert box with the captions OK and Cancel. To display the alert, a built-in function uses the following syntax:

 button_no := SHOW_ALERT (alert_name); 

button_no is defined as a numeric PL/SQL variable. Using the SET_ALERT_PROPERTY built-in, you can dynamically change the ALERT_MESSAGE_TEXT property at runtime. Using the standard trigger, ON-MESSAGE, you can create an alert box that presents all messages to the user in an alert box rather than on the status line, which is sometimes missed by a user. You can write an ON-MESSAGE that uses the MSG_ALERT dialog box (Stop, one button labeled OK) as follows:

 declare    msgtext     VARCHAR(80) := message_text;    bno            number; begin    set_alert_property (`MSG_ALERT', ALERT_MESSAGE_TEXT, msgtext);    bno := show_alert (`MSG_ALERT'); end; 

Whenever the built-in message is used, the message is displayed as shown in Figure 35.21. The form that contains this alert is described in the next section.

Figure 35.21.
Alert message.


Previous Table of Contents Next


Oracle Unleashed
Oracle Development Unleashed (3rd Edition)
ISBN: 0672315750
EAN: 2147483647
Year: 1997
Pages: 391

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net