5. Events : DragBox Event
 
Share this page                  
DragBox Event
The DragBox event is triggered when the user draws a drag box in a field that has a bias of FB_DRAGBOX.
This event has the following syntax:
on dragbox [fieldname]
fieldname is optional if you specify this event in a field script.
The following attributes of the FrameExec class can be used in the DragBox event block:
TriggerField
Specifies the field that is set to a bias of FB_DRAGBOX over which the user dragged a box
OriginatorField
Specifies the field specified in the initial on dragbox statement
XStart
Specifies the x coordinate of the upper left corner of the drag, relative to TriggerField
YStart
Specifies the y coordinate of the upper left corner of the drag, relative to TriggerField
XEnd
Specifies the x coordinate of the lower right corner of the drag, relative to TriggerField
YEnd
Specifies the y coordinate of the lower right corner of the drag, relative to TriggerField.
The coordinate values are expressed in 1000ths of an inch and are relative to the upper left corner of the TriggerField.
In the DragBox event, the XStart and YStart attributes always represent the upper left corner of the drag, even if the user started the drag from one of the other corners.
Use the CurFrame system variable to access these attributes. For more information, see FrameExec Class (see FrameExec Class).
Usage: The DragBox event is defined for all form fields. This event is not defined for menu fields.
When the user draws a box, you can use the DragBox event to determine the drag box coordinates. You can obtain the exact coordinates of the upper left corner and lower right corner of the drag box where the user drew it in the image or image trim field. Then you can use that information as needed in your program.
For example, assume that your application displays a large image field called graphfield that contains a graph. When the user drags a box on any part of the graph, you want the application to expand that area to show more detail. To accomplish this task, you could use a DragBox event:
initialize() =
declare
file_with_graph = varchar(100);
enddeclare
begin
...
file_with_graph = callproc
get_starting_graph(....);
graphfield.FileHandle = file_with_graph;
/* Starting */
field(graphfield).CurBias = FB_DRAGBOX;
/* ...or specify in the property sheet */
...
end
...
on dragbox graphfield =
begin
file_with_graph = callproc get_detail_graph
(starting_graph = file_with_graph,
x_start = CurFrame.XStart,
y_start = CurFrame.YStart,
x_end = CurFrame.XEnd,
y_end = CurFrame.YEnd);
graphfield.FileHandle = file_with_graph;
/* Reload detail */
end
The DragBox event calls a procedure, get_detail_graph, that expands the dragged area. The procedure uses the XStart, YStart, XEnd, and YEnd values to determine the area that the user dragged. (The program must expand the dragged area because OpenROAD does not automatically expand graphic images.)
You can also use this event in visual editor applications. By providing a DragBox event on a subform within a form, you can detect user drags and then create appropriate display objects at the point of the drag.
The following code demonstrates this behavior for creating rectangles and ellipses at the point of drags:
initialize() =
declare
rectangle = RectangleShape;
ellipse = EllipseShape;
shape = ShapeField;
enddeclare
begin
field(test_subform).CurBias = FB_DRAGBOX;
/* or in prop sheet */
...
on dragbox test_subform =
begin
/*  The CurFrame variable will have all of the
**  details of what the size of the drag was.
*/
if display_choice = 'Make Box' then
rectangle = RectangleShape.Create();
shape = rectangle;
else
ellipse = EllipseShape.Create();
shape = ellipse;
endif;
shape.FillColor = color;
shape.FillPattern = pattern;
shape.LineWidth = linewidth;
shape.XLeft = CurFrame.XStart;
shape.YTop = CurFrame.YStart;
shape.Width = CurFrame.XEnd - CurFrame.
XStart + 1;
shape.Height = CurFrame.YEnd - CurFrame.
YStart + 1;
shape.ParentField = field(test_subform);
/* Add to form */
end
If fields overlap or if you want to detect a drag box on a composite field, ignoring whether the drag started on a child field or on the composite field's background, you can do the following:
Set the bias of all the child fields to FB_VISIBLE.
Set the bias of the composite field to FB_DRAGBOX.
Then use the DragBox event block for the composite field.
You can use the FrameExec attributes XStart, YStart, XEnd, and YEnd to access the exact coordinates of the drag box.
For information about processing DragBox events for a set of fields, see ChildDragBox Event (see ChildDragBox Event).
More information:
OriginatorField Attribute (see page OriginatorField Attribute)
TriggerField Attribute (see page TriggerField Attribute)
XEnd Attribute (see page XEnd Attribute)
XStart Attribute (see page XStart Attribute)
YEnd Attribute (see page YEnd Attribute)
YStart Attribute (see page YStart Attribute)