On 23/11/05 12:51 pm, "Rods" <[EMAIL PROTECTED]> wrote:
> I have some huge text members that I've implemented a search using preg
> xtra. Now I need to hilite the search result and when the user click "next"
> button the text will scroll to the position of the other result and so on,
> something like web browsers do.

Hi Rodrigo,

Are these text members editable?  If not, you cannot hilite the text
directly in the text member.  You can find two different workarounds at:

  <http://nonlinear.openspark.com/tips/text/hilitetext/>
  <http://nonlinear.openspark.com/tips/text/multiselect/>

Both these solution hilite complete lines: you would need to alter them to
hilite individual words.

What information do you get back from your PRegEx search?  If you get a
character number then you can use the handler below to make sure that the
given character is visible.

Cheers,

James

----------------------------------------------------------------------------


on ScrollToCharacter(aTextMember, aCharIndex) ------------------------
  -- INPUT: <aTextMember> should be a text member
  --        <aCharIndex> should be a positive integer
  -- ACTION: Scrolls aTextMember so that character aCharIndex is
  --         visible.  If the given character is already completely
  --         visible, no scrolling occurs.
  --------------------------------------------------------------------
  
  -- Error checking
  if ilk(aTextMember, #member) then
    case aTextMember.type of
      #text: -- continue
        
      otherwise:
        return #textMemberExpected
    end case
    
  else
    return #memberExpected
  end if
  
  if integerP(aCharIndex) then
    if aCharIndex < 0 then
      return #positiveIntegerExpected
    end if
    
  else
    return #integerExpected
  end if
  -- End of error checking
  
  -- How far down is the bottom of the given character?
  vLoc    = aTextMember.charPosToLoc(aCharIndex)
  vBottom = vLoc.locV
  
  -- What line is it on?
  vLine = aTextMember.locVToLinePos(vBottom)
  
  -- Where does the top of that line start?
  if vLine then
    vTop = aTextMember.linePosToLocV(vLine - 1)
  else
    vTop = 0
  end if
  
  vScroll = aTextMember.scrollTop
  
  if vScroll > vTop then
    -- The given character hidden above the top of the sprite.
    -- Scroll down to show it at the top of the sprite.
    aTextMember.scrollTop = vTop
    
  else
    vMaxScroll = vBottom - aTextMember.pageHeight
    
    if vScroll < vMaxScroll then
      -- The given character is hidden below the bottom of the
      -- sprite.  Scroll up to show it at the bottom of the sprite.
      aTextMember.scrollTop = vMaxScroll
    end if
  end if
  
  return 0 -- no error
end ScrollToCharacter

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to