Consultor Eletrônico



Kbase P106249: How to trap a double-click mouse event over a LABEL
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/11/2005
Status: Unverified

GOAL:

How to trap a double-click mouse event for a widget LABEL

GOAL:

How to know the position of a widget LABEL

GOAL:

How to change a widget LABEL at runtime

FIX:

The following example shows a fill-in over a LABEL if the user double-clicks over that label.
1- Define the following temp-table in the definitions block:
DEFINE TEMP-TABLE objectLabel NO-UNDO
FIELD objectHandle AS HANDLE
FIELD labelHandle AS HANDLE
FIELD xStart AS DECIMAL
FIELD xEnd AS DECIMAL
FIELD yStart AS DECIMAL
FIELD yEnd AS DECIMAL
INDEX pos xStart xEnd yStart yEnd.
2- In the MAIN-BLOCK walk the widget tree and store the widget and label values in the temp-table:
DEFINE VARIABLE hObject AS HANDLE NO-UNDO.
DEFINE VARIABLE hLabel AS HANDLE NO-UNDO.

ASSIGN hObject = FRAME {&FRAME-NAME}:FIRST-CHILD
hObject = hObject:FIRST-CHILD.
DO WHILE VALID-HANDLE(hObject):
ASSIGN hLabel = hObject:SIDE-LABEL-HANDLE NO-ERROR.
IF VALID-HANDLE(hLabel)
THEN DO:
CREATE objectLabel.
ASSIGN objectHandle = hObject
labelHandle = hLabel
xStart = hLabel:X + FRAME {&FRAME-NAME}:X
xEnd = hLabel:X + hLabel:WIDTH-PIXELS
yStart = hLabel:Y + FRAME {&FRAME-NAME}:Y
yEnd = hLabel:Y + hLabel:HEIGHT-PIXELS.
END.

ASSIGN hObject = hObject:NEXT-SIBLING.
END.

3- Create a dummy fill-in called 'fiLabel' and made it hidden.
4- In the LEFT-MOUSE-DBLCLICK trigger for the frame add the following code:
/*Finds if there is a label in the mouse position*/
FIND FIRST objectLabel NO-LOCK
WHERE objectLabel.xStart LE LAST-EVENT:X AND
objectLabel.xEnd GE LAST-EVENT:X AND
objectLabel.yStart LE LAST-EVENT:Y AND
objectLabel.yEnd GE LAST-EVENT:Y NO-ERROR.

/*If the user double-clicked over a label, sets the position and width for fiLabel over the label that was clicked*/
IF AVAILABLE objectLabel
THEN DO:
ASSIGN fiLabel:SCREEN-VALUE = ""
fiLabel:X = objectLabel.xStart
fiLabel:Y = objectLabel.yStart
fiLabel:WIDTH = objectLabel.labelHandle:WIDTH
&nbsp.; fiLabel:VISIBLE = TRUE.
fiLabel:MOVE-TO-TOP().
APPLY 'ENTRY':U TO fiLabel.
END.
5- In the RETURN trigger for fiLabel write the following code:
/*Assign the new LABEL and hidde the fill-in*/
ASSIGN objectLabel.objectHandle:LABEL = SELF:SCREEN-VALUE.
HIDE SELF.

APPLY 'ENTRY' TO objectLabel.objectHandle.
RETURN NO-APPLY..