Kbase P125542: How to limit number of lines that user can insert in an Editor widget?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/29/2009 |
|
Status: Unverified
GOAL:
How to limit number of lines that user can insert in an Editor widget?
GOAL:
Is it possible to limit the number of lines that can be inserted in an Editor widget?
GOAL:
Is there a way to impose a limit on the number of lines that are inserted in an Editor?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
The following example prevents the user from inserting more than 5 lines in an Editor. To achieve this, on VALUE-CHANGED trigger add the following example code:
DO:
DEFINE VARIABLE cEd AS CHARACTER NO-UNDO.
DEFINE VARIABLE iPos AS INTEGER NO-UNDO.
DEFINE VARIABLE iLine AS INTEGER NO-UNDO.
DEFINE VARIABLE iPoint AS INTEGER NO-UNDO init 1.
DEFINE VARIABLE iCurs AS INTEGER NO-UNDO.
/* save current values */
ASSIGN
iCurs = editor-1:CURSOR-OFFSET
cEd = editor-1:SCREEN-VALUE.
/* find how many 'new-lines' do we have in the editor */
GIN: 0in 0in 0pt; mso-pagination: none; mso-layout-grid-align: none"> DO WHILE TRUE:
iPos = index(cEd, chr(10), ipoint).
IF iPos > 0 THEN
ASSIGN
iLine = iLine + 1
iPoint = iPos + 1
.
ELSE LEAVE.
END.
/* more than 5 lines ('new-lines' or through word-wrap */
IF iLine >= 5 OR editor-1:NUM-LINES > 5 THEN DO:
ASSIGN
/* set the editor to previously saved value */
editor-1:SCREEN-VALUEle="mso-spacerun: yes"> = cOldEd.
/* place the cursor back where it was; Paste from context menu *is not handled*!!! */
editor-1:CURSOR-OFFSET = IF LAST-EVENT:LABEL = "ENTER" then ICURS - 2 else icurs - 1.
IF LAST-EVENT:LABEL = "CTRL-V" then editor-1:cursor-offset = icurs - length(clipboard:value).
/* informational message */
MESSAGE LAST-EVENT:LABEL + " " + LAST-EVENT:FUNCTION + " [" +
LAST-EVENT:EVENT-TYPE + "]-->" + SELF:TYPE + " " skip
"too many lines"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
/* save the editor for later */
ELSE cOldEd = editor-1:SCREEN-VALUE.
END.
On the Definitions Section, declare the variable cOldEd:
DEFINE VARIABLE cOldEd AS CHARACTER NO-UNDO..