Documentation for Win32lib v0.60.6
Table of Contents

RichEdit Control

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 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 )   
  • proc setIndent( id, start, right, offset )    Change indenting in a RichEdit Control
  • proc setIndex( atom list, object index )    Select characters in the control.
  • proc setSelection( atom list, object index )    An alias for setIndex
  • proc setTabs( id, tabs )    Change tab stops in a RichEdit Control.

    Documentation for Win32lib v0.60.6
    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 Control

    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. flags can be a combination of the folowing:

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

       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, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getRichText
    ( id, range )

    Get text from a RichEdit control

    Returns: Text in the given range.

    Category: RichEdit Control

    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 last index.
    To always retrieve all the text in the control, set the range to {0, 0}.

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


    Documentation for Win32lib v0.60.6
    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 Control

    Example:

              -- Find out what is selected
              sequence posn
    

    posn = getSelection( myRE )

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


    Documentation for Win32lib v0.60.6
    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 Control

    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, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    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 Control

    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, getStream, printRichTextPages, putStream, setAlignment, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

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

    Prints the contents of a RichText control.

    Category: RichEdit Control

    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./n

    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, getStream, printRichText, putStream, setAlignment, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

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

    Load text into a RichEdit control from a text sequence.

    Category: RichEdit Control

    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, getStream, printRichText, printRichTextPages, setAlignment, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setAlignment
    ( id, alignment )

    Align text in a RichEdit Control

    Category: RichEdit Control

    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, getStream, printRichText, printRichTextPages, putStream, setBullet, setIndent, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setBullet
    ( id )

    Category: RichEdit Control

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

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


    Documentation for Win32lib v0.60.6
    Table of Contents

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

    Change indenting in a RichEdit Control

    Category: RichEdit Control

    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, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setIndex, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setIndex
    ( atom list, object index )

    Select characters in the control.

    Category: RichEdit Control

    This is used for Edit and RichEdit controls.
    index is either a single integer of the position you are selecting, or a two-element sequence in the form : {low_posn, high_posn}. If the high_posn is zero, everything up to, and including, the last item is selected.

    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 set the current scroll position.

    Example:

              -- select characters 30 thru 43 inclusive
               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, getStream, printRichText, printRichTextPages, putStream, setAlignment, setBullet, setIndent, setSelection, setTabs


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setSelection
    ( atom list, object index )

    An alias for setIndex

    Category: RichEdit Control

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


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setTabs
    ( id, tabs )

    Change tab stops in a RichEdit Control.

    Category: RichEdit Control

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

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