Code: Select all
EnableExplicit
Define Search.SCTextToFind
Define *Text, pos
If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla() ; 6.04
ScintillaGadget(0, 10, 10, 320, 70, 0)
*Text = UTF8("This is a simple ScintillaGadget with text... ")
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text)
*Text = UTF8("Sci")
Search\chrg\cpMin = 0
Search\chrg\cpMax = ScintillaSendMessage(0, #SCI_GETLENGTH)
Search\lpstrText = *Text
Search\chrgText\cpMin = 0
Search\chrgText\cpMax = MemorySize(*Text)
pos = ScintillaSendMessage(0, #SCI_FINDTEXT, 0, @Search)
FreeMemory(*Text)
ScintillaSendMessage(0, #SCI_SETSELECTIONSTART, pos, 0)
ScintillaSendMessage(0, #SCI_SETSELECTIONEND, pos + Len("Sci") , 0)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
And now the function
Code: Select all
EnableExplicit
#SciGt = 0
Define *Text
Procedure FindText(id, SearchText.s, flag = 0)
Protected *Text, pos
Protected Search.SCTextToFind
*Text = UTF8(SearchText)
Search\chrg\cpMin = 0
Search\chrg\cpMax = ScintillaSendMessage(id, #SCI_GETLENGTH)
Search\lpstrText = *Text
Search\chrgText\cpMin = 0
Search\chrgText\cpMax = MemorySize(*Text)
pos = ScintillaSendMessage(id, #SCI_FINDTEXT, flag, @Search)
FreeMemory(*Text)
If pos > - 1
ScintillaSendMessage(id, #SCI_SETSELECTIONSTART, pos, 0)
ScintillaSendMessage(id, #SCI_SETSELECTIONEND, pos + Len(SearchText) , 0)
EndIf
ProcedureReturn pos
EndProcedure
If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(#SciGt, 10, 10, 320, 70, 0)
*Text = UTF8("This is a simple ScintillaGadget with text... ")
ScintillaSendMessage(#SciGt, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text)
FindText(#SciGt, "th", #SCFIND_MATCHCASE) ; #SCFIND_WHOLEWORD, #SCFIND_WORDSTART, #SCFIND_REGEXP
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It turns out that the structure returns the positions of what was found. Then we can continue our search
Code: Select all
EnableExplicit
#Window = 0
Enumeration
#SciGt
#btnNext
#field
EndEnumeration
Define *Text, Search.SCTextToFind, SearchText.s, pos, Change
If Not InitScintilla()
End
EndIf
Procedure FindText(id, *Search.SCTextToFind, flag = 0)
Protected pos
pos = ScintillaSendMessage(id, #SCI_FINDTEXT, flag, *Search)
If pos > - 1
ScintillaSendMessage(id, #SCI_SETSELECTIONSTART, *Search\chrgText\cpMin, 0)
ScintillaSendMessage(id, #SCI_SETSELECTIONEND, *Search\chrgText\cpMax, 0)
EndIf
ProcedureReturn pos
EndProcedure
If OpenWindow(#Window, 0, 0, 530, 190, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScintillaGadget(#SciGt, 10, 10, 510, 130, 0)
ButtonGadget(#btnNext, 10, 150, 100, 30, "Start")
SearchText = "s"
StringGadget(#field, 120, 150, 60, 30, SearchText)
*Text = UTF8("This is a simple ScintillaGadget with text... ")
ScintillaSendMessage(#SciGt, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text)
*Text = UTF8(SearchText)
Search\chrg\cpMin = 0
Search\chrg\cpMax = ScintillaSendMessage(#SciGt, #SCI_GETLENGTH)
Search\lpstrText = *Text
; Search\chrgText\cpMin = 0
; Search\chrgText\cpMax = 0
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #field
If EventType() = #PB_EventType_Change
Change = 1
DisableGadget(#btnNext, #False)
SetGadgetText(#btnNext, "Start")
EndIf
Case #btnNext
If Change = 1
Change = 0
SearchText = GetGadgetText(#field)
If Asc(SearchText)
FreeMemory(*Text)
*Text = UTF8(SearchText)
Search\chrg\cpMin = 0
Search\chrg\cpMax = ScintillaSendMessage(#SciGt, #SCI_GETLENGTH)
Search\lpstrText = *Text
EndIf
EndIf
If Asc(SearchText)
pos = FindText(#SciGt, @Search, #SCFIND_MATCHCASE) ; #SCFIND_WHOLEWORD, #SCFIND_WORDSTART, #SCFIND_REGEXP
If pos > -1
Search\chrg\cpMin = Search\chrgText\cpMax
SetGadgetText(#btnNext, "Next")
Else
DisableGadget(#btnNext, #True)
EndIf
EndIf
EndSelect
Case #PB_Event_CloseWindow
FreeMemory(*Text)
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf