Documentation for Win32lib v0.70.18
Table of Contents

RichEdit controls

In addition to the specialized RichEdit control routines.


The Edit Control routines also work with RichEdit Controls:
  • clear( object )
  • copy( object )
  • cut( object )
  • paste( object )
  • undo( object )

  • func findText( id, text, range, flags )    Find text in a RichEdit Control.
  • func getRichText( id, range )    Get text from a RichEdit control
  • func getSelection( RE )   Gets the character range of any selected text.
  • func getSelectionFont(integer id)   Returns the address of a LOGFONT structure which describes the font used in the selection.
  • func getStream( integer id, integer flags )   Convert the data in a RichEdit control to a sequence.
  • proc printRichText(integer OutId, integer InId, integer Start, integer End, sequence Box, integer Render)   Prints some or all the contents of a rich edit control.
  • proc printRichTextPages(integer InId, integer pCallBack, object pUserData)   Prints the contents of a RichText control.
  • proc putStream( integer id, integer flag, sequence text )   Load text into a RichEdit control from a text sequence.
  • proc setAlignment( id, alignment )    Align text in a RichEdit Control
  • proc setBullet( id )   
  • func setFRData(integer id,object findWhat,object replaceWith,object flags,integer action)    Gets and possibly sets the "find what" and "replace with" strings used in a Find/Replace dialog box, as well as its control flags.
  • proc setIndent( id, start, right, offset )    Change indenting in a RichEdit Control
  • proc setIndex( atom id, object index )    Select characters in the control.
  • func setREChangeNotification(integer id,integer flag)   Gets, and possibly sets, the status of change notification for a RichEdit control.
  • proc setSelection( atom list, object index )    An alias for setIndex
  • func setTabEnabled( integer id, integer flag)   Possibly sets the flag which says whether a (Rich)Edit control uses Ctrl-Tab for tabbing
  • proc setTabs( id, tabs )    Change tab stops in a RichEdit Control.

    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    findText
    ( id, text, range, flags )

    Find text in a RichEdit Control.

    Returns: Index where text begins, or zero if not found

    Category: RichEdit controls

    range should be a sequence containing the range of text you'd like to search within the RichEdit, or an atom, if you want to search through all of the text. When specifying a range, the first index is included and the second index is excluded. flags can be a combination of the folowing:

  • findWholeWord
  • findMatchCase
  • findDown = Current to DocEnd, else Current to DocStart

    Example:

       atom fnd, frompoint
       integer cnt
       sequence word
          -- Count all occurances of a word.
          word = "procedure"
          cnt = 0
          frompoint = 0
          fnd = -1
          while fnd != 0 do
              fnd = findText(myRichFld, word, {frompoint,-1},
                                      findDown + findMatchCase + findWholeWord)
              if fnd then
                   cnt += 1
                   frompoint = fnd
              end if
          end while
    

    See Also: getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    getRichText
    ( id, range )

    Get text from a RichEdit control

    Returns: Text in the given range.

    Category: RichEdit controls

    If range is an atom, any selected text is returned. However if there is no selected text and range is -1 then all the text is returned.
    If range is a sequence, range should be a 2-element sequence with the first element the starting index to be retrieved, and the second element the first index NOT retrieved, like setIndex() does.
    To always retrieve all the text in the control, set the range to {0, 0}. Indexes are clipped so as to make sense. If they don't, "" is returned.

    See Also: findText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    getSelection
    ( RE )

    Gets the character range of any selected text.

    Returns: A sequence {first, last} of the characters selected.

    Category: RichEdit controls

    Example:

              -- Find out what is selected
              sequence posn
    

    posn = getSelection( myRE )

    See Also: findText, getRichText, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    getSelectionFont
    (integer id)

    Returns the address of a LOGFONT structure which describes the font used in the selection.

    Returns: (ATOM) 0 on failure, address of the LOGFONT structure on success.

    Category: RichEdit controls

    Failure will occur if the control is not a RichEdit, or if the character in the selected range don't have the same font. You must free the returned memory when done with it.

    See Also: findText, getRichText, getSelection, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    getStream
    ( integer id, integer flags )

    Convert the data in a RichEdit control to a sequence.

    Returns: SEQUENCE: The contents of the RichEdit control.

    Category: RichEdit controls

    Use flag StreamText to return plain text, or StreamRTF to return rich text. This can be combined to StreamSelection to only return any selected content from the RichEdit.

    Example:

               -- Create a RichEdit control
                RE = create( RichEdit, "", Win , 20, 20, 360, 200, ES_NOHIDESEL)
               . . .
               -- Save the text into a file from a RichEdit control
               richout = open("MyRich.txt", "w")
               -- Get the selected text from the control.
                printf(richout, "%s", { getStream( RE, StreamText + StreamSelection) } )
    

    close( richout )

    See Also: findText, getRichText, getSelection, getSelectionFont, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    printRichText
    (integer OutId, integer InId, integer Start, integer End, sequence Box, integer Render)

    Prints some or all the contents of a rich edit control.

    Category: RichEdit controls

    OutId is the control Id where the text is displayed. Usually 'Printer' but can be a Window or Pixmap. If not a printer, this can be used to do a print-preview display.
    InId is the RichText control
    Start is the first position in the RichEdit to start from.
    End is the last position in the RichEdit control. Use -1 to include all text up to the end of the control.
    Box is the area in the output control that will receive the formatted text. It is in the form {Left, Top, Right, Bottom, Scale}, where Scale is one of ...

  • w32InchScale : values are in inches
  • w32MillScale : values are in millimeters
  • w32PixelScale : values are in pixels
  • w32TwipsScale : values are in twips (1/1440th of an inch)

    Render is w32True if you wish to actually output the text, w32False to format it but not print it.

    Example:

        if length(getPrinter()) > 0 then
            VOID = startDoc("RichText Printer Test")
            VOID = startPage()
            printRichText(Printer, RE, 0, -1, {0.5, 0.5, 2.5, 3, w32InchScale}, w32True)
            VOID = endPage()
            VOID = endDoc()
    

    releasePrinter() repaintWindow(PPV) end if

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    printRichTextPages
    (integer InId, integer pCallBack, object pUserData)

    Prints the contents of a RichText control.

    Category: RichEdit controls

    InId is the RichText control
    pCallBack is a routine_id of a user defined function that is called before each page is built and again just before each page is output. If this is not a valid routine_id (eg. -1) then this routine will assume a 0.5 inch margin and print the entire RichText document, using multiple pages if required.

    The function will be passed a two parameters.

    When the function is called using w32RP_Build, the function must return one of ...
  • w32RP_SkipAll ==> Do not build this page, just end the document.
  • w32RP_Cancel ==> Do not build this page, just cancel the document.
  • {Left, Top, Right, Bottom, Scale} ==> the area in the page that will receive the formatted text.

    Left and Top indicate an offset from the left and top edges of the page, respectively.
    Right and Bottom, if positive values are also offsets from the left and top edges respectively, but if negative, they are offsets from the right and bottom edges.
    Scale is one of ...

    When the function is called using w32RP_Output, the function must return one of ...

  • w32RP_Print ==> Print the page
  • w32RP_LastPage ==> Print the page and then end the document.
  • w32RP_Skip ==> Skip this page and go on to the next page.
  • w32RP_SkipAll ==> Do not print this page or any others, just end the document.
  • w32RP_Cancel ==> Do not print this page but cancel the document.

    Note that you need to set the Printer device context before calling this. That can be done by calling getPrinter() or getPrintChoice().

    Example:

        function RTPager(integer pCode, sequence pParms)
          if pCode = w32RP_Build then
             -- Return the printable page area
             -- which is different for odd
             -- and even pages.
             if and_bits(pParms[1], 1) then
                return {0.25, 1, -0.75, -0.5, w32InchScale}
             else
                return {0.75, 1, -0.25, -0.5, w32InchScale}
             end if
          end if
    

    if pCode = w32RP_Output then -- The page has been built with text from the richedit control, so now -- I can add my own touches...

    -- Display the title text on the top left corner. wPuts( {Printer, 0, 0}, pParms[5] )

    -- Display the page number on the bottom-right of the page. lFooter = sprintf(" Page %d", pParms[1]) wPuts( {Printer, lParms[4][1] - getTextWidth(lFooter), lParms[4][2] - (getTextHeight(lFooter) * 2)}, lFooter )

    -- Tell win32lib to output the page now. return w32RP_Print end if end function

    . . .

    if length(getPrinter()) > 0 then printRichTextPages(RE, routine_id("RTPager"), "This Is The Title") releasePrinter() end if

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    putStream
    ( integer id, integer flag, sequence text )

    Load text into a RichEdit control from a text sequence.

    Category: RichEdit controls

    Use flag StreamText to indicate that contains plain text, or StreamRTF to indicate that text contains rich text. This can be combined with StreamSelection so that only any selected text in the control is replaced with text data.

    Example:

               sequence rich
               integer RE, fn, c
               . . .
               -- Create a RichEdit control
                RE = create( RichEdit, "", Win , 20, 20, 360, 200, ES_NOHIDESEL)
    

    -- Load the text into the RichEdit control fn = open("rich.rtf", "r") if fn != -1 then rich = {} c = getc( fn ) while c != -1 do rich &= c c = getc( fn ) end while

    putStream( RE, StreamRTF, rich )

    close( fn ) end if

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setAlignment
    ( id, alignment )

    Align text in a RichEdit Control

    Category: RichEdit controls

    Sets Alignment of the paragraph which includes the selection in a RichEdit control. alignment should be one of the following values:

  • AlignLeft
  • AlignRight
  • AlignCenter

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setBullet
    ( id )

    Category: RichEdit controls

    Toggles the bulleting of the paragraph which includes the selection in a RichEdit control.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    setFRData
    (integer id,object findWhat,object replaceWith,object flags,integer action)

    Gets and possibly sets the "find what" and "replace with" strings used in a Find/Replace dialog box, as well as its control flags.

    Returns: (SEQUENCE) "" if not applicable, else a triple of elements.

    Category: RichEdit controls

    If id is not the id of a RichEdit control for which getFindText() or getReplaceText() is being called, then "" is returned.
    Otherwise, a triple is returned. The first element is the string to be found. If getFindText() is being called, the second element is 0, else it is the replacement string.
    If findWhat is a string, the corresponding field in the dialog box will be updated. If getReplaceText() is being invoked and replaceWith is a string, that field is updated as well.
    If flags is a sequence, the current value of the dialog box flags is simply returned; otherwise, the dialog box flags are set to the new value and the former value is returned. In both cases, the value is returned as the third element of the returned sequence.
    If action is not w32False, thedialog box will perform as if a button had been clicked, depending on the value passed in flags or the current vlue of the dialog flags. Otherwise, no further action is taken and user must push a dialog button for next thing to happen.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setIndent
    ( id, start, right, offset )

    Change indenting in a RichEdit Control

    Category: RichEdit controls

    Sets indenting. If you don't want to change any of the indent modes, pass it's parameter as a sequence. All values should be in pixels.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndex, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setIndex
    ( atom id, object index )

    Select characters in the control.

    Category: RichEdit controls

    This is used for Edit and RichEdit controls.
    index is either

  • a single integer: the position you are setting the insertion point (caret) at, cancelling any current selection; If the value is 0 or less, the caret blinks at the end of the text.
  • a two-element sequence in the form {first selected char index, first NOT selected char index}: the range of characters to be selected. If the unselected index is zero, everything up to, and including, the last item is selected. If the two are equal, this is the same as passing the common value. If the unselected index is less than the selected index, then the pair is reversed. The insertion point is always set at the second index, whether reversing takes place or not. However, setIndex(id,{0,x}) is equivalent to setIndex(id,1). This is a Windows quirk.

    Use 0 to deselect the current selection.

    For ListView controls, index can be set to w32SelectAll to select all items.

    For Window, VScroll, HScroll, VTrackBar, HTrackBar, ProgressBar, UpDown: this sets the current scroll position.

    Example:

              -- select characters 30 thru 42 inclusive. Cursor blinks at character 43.
               setIndex( TheEdit, {30, 43} )
              -- select all characters
               setIndex( TheEdit, {1, 0} )
              -- select all characters from position 78
               setIndex( TheEdit, {78, 0} )
              -- move insertion point to char 50
               setIndex( TheEdit, 50 )
    

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setREChangeNotification, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    setREChangeNotification
    (integer id,integer flag)

    Gets, and possibly sets, the status of change notification for a RichEdit control.

    Returns: (INTEGER) The curent or former value for the flag.

    Category: RichEdit controls

    By default, RichEdit conrols do not notify their parent when a change in the data they hold takes place. Setting flag to a positive value will cause the RichEdit of id id to fire w32HChange on any change to its contents. Passing 0 wil disable this behaviour. Passing a negative -- value will simply return the current status.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setSelection, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setSelection
    ( atom list, object index )

    An alias for setIndex

    Category: RichEdit controls

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setTabEnabled, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [func]
    setTabEnabled
    ( integer id, integer flag)

    Possibly sets the flag which says whether a (Rich)Edit control uses Ctrl-Tab for tabbing

    Returns: The previous value of the flag, or -1 if the id was invalid.

    Category: RichEdit controls

    between controls. Pass 0 as flag to disable need for the Ctrl key, w32GetValue to just get the flag value, or anything else to enable it. For (Rich)Edit controls, the need for the Ctrl key is turned on by default, and disabled for other controls.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabs


    Documentation for Win32lib v0.70.18
    Table of Contents

    [proc]
    setTabs
    ( id, tabs )

    Change tab stops in a RichEdit Control.

    Category: RichEdit controls

    tabs should be a sequence of absolute positions for the tab stops in 1/1000 of an inch.

    See Also: findText, getRichText, getSelection, getSelectionFont, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setFRData, setIndent, setIndex, setREChangeNotification, setSelection, setTabEnabled