Consultor Eletrônico



Kbase P37632: Dynamics: how to achieve Left Aligned Labels Boxes?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   18/08/2003
Status: Unverified

GOAL:

Dynamics: how to achieve Left Aligned Labels Boxes?

CAUSE:

Bug# 20030818-001

FIX:

The following has been logged as an enhancement request as Left Aligned Labels seems to be an important standard for Europe.  At the  moment the 4GL does not allow this feature.  However, the following has been  successfully achieved with Dynamics, so it would be interesting to implement  it in the Framework:


Rely on rectangles to define Left Aligned Labels Boxes:
1) These rectangles are visible only a design time, hidden at runtime
2) An additional button in the palette allows the drawing of a LALBox, with  a given color (not default) and a name of LALBox<number>
3) A LALBox around a group of fields defines a group of fields that you want  the labels to be left aligned on the left edge of the box.
4) In container/initializeObject after SUPER (the labels are already  translated including lookups and combos) we walk through the LALBox chain,  then through the widget tree.  For each widget, if located in the box and  has a VALID SIDE-LABEL-HANDLE, then align this label on the left edge of its  LALBox

Note that the weakness in the core -cannot draw a box around label to define  point to left align on, as in Delphi or VB- is transformed into a  significant strength because the box is defined for multiple fields instead of only one.

FURTHER COMMENTS:
Here is a piece of code used to achieve that.  This process is  very fast.  we shall would use 'LALBox' instead of 'LabelMarker'
PROCEDURE initializeObject.

RUN SUPER.

RUN leftAllignLabels.

END PROCEDURE.


---------------------------------------------------------------------------
PROCEDURE leftAllignLabels.

DEFINE VARIABLE cLabelMarkers AS CHARACTER NO-UNDO.
DEFINE VARIABLE cAllFieldHandles AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE hLabel AS HANDLE NO-UNDO.

{get allFieldHandles cAllFieldHandles}.

/* Get the handle of the label markers */
ASSIGN cLabelMarkers = DYNAMIC-FUNCTION('getAllLabelMarkers'
IN TARGET-PROCEDURE).

DO iCount = 1 TO NUM-ENTRIES (cAllFieldHandles):
hField = WIDGET-HANDLE (ENTRY(iCount, cAllFieldHandles)).

/* Find out if field is of type dynlookup */
IF CAN-QUERY(hField, 'FILE-NAME') THEN DO:
IF {fnarg InstanceOf 'DynLookup' hField} THEN
ASSIGN
hField = DYNAMIC-FUNCTION('getLabelHandle' IN hField )
hField:X = getLabelPosition(cLabelMarkers,hField).
END.

/* Reposition side labels of screen-widgets */
ELSE IF VALID-HANDLE (hField) AND
CAN-QUERY(hField, 'SIDE-LABEL-HANDLE') AND
hField:SIDE-LABEL-HANDLE <> ?
THEN hField:SIDE-LABEL-HANDLE:X =
getLabelPosition(cLabelMarkers,hField:SIDE-LABEL-HANDLE).
END.

/* Hide the markers */
DO iCount = 1 TO NUM-ENTRIES (cLabelMarkers):
hField = WIDGET-HANDLE ( ENTRY( iCount, cLabelMarkers) ).
IF VALID-HANDLE (hField) THEN ASSIGN hField:VISIBLE = FALSE.
END.

END PROCEDURE.

---------------------------------------------------------------------------
FUNCTION getAllLabelMarkers RETURNS CHARACTER

( /* parameter-definitions */ ) :
DEFINE VARIABLE cMarkerHandles AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFields AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldHandles AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE cMarker AS CHARACTER NO-UNDO.

{get allFieldNames cFields}.
{get allFieldHandles cFieldHandles}.

/* If more then 20 markers on one screen then kill the programmer! */
DO iCount = 1 TO 20:

ASSIGN cMarker = ''.
IF LOOKUP( 'MARKER-' + STRING(iCount), cFields ) <> 0 THEN DO:
cMarker =
ENTRY(LOOKUP('MARKER-' + STRING(iCount),cFields ),cFieldHandles ).
IF VALID-HANDLE( WIDGET-HANDLE (cMarker) ) THEN
ASSIGN cMarkerHandles = IF cMarkerHandles = ''
. THEN cMarker
ELSE cMarkerHandles + ',' + cMarker.
END.
END.

RETURN cMarkerHandles.

END FUNCTION.
---------------------------------------------------------------------------
FUNCTION getLabelPosition RETURNS INTEGER
( pcMarkerHandles AS CHARACTER,
phWidget AS HANDLE ) :

DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hMarker AS HANDLE NO-UNDO.
DEFINE VARIABLE iLabelX AS INTEGER NO-UNDO.

DO iCount = 1 TO NUM-ENTRIES (pcMarkerHandles):
hMarker = WIDGET-HANDLE( ENTRY( iCount, pcMarkerHandles) ).

IF NOT VALID-HANDLE (hMarker) THEN NEXT.

/* Check if marker is on same y position as the requested widget */
IF phWidget:Y < hMarker:Y OR
phWidget:Y > hMarker:Y + hMarker:HEIGHT-PIXELS
THEN NEXT.

IF hMarker:X > iLabelX AND
hMarker:X < phWidget:X
THEN ASSIGN iLabelX = hMarker:X.

END.

IF iLabelX > 0
THEN RETURN iLabelX.
ELSE RETURN phWidget:X.

END FUNCTION..