First let me say that I have zero experience with Scintilla and I got help from this post by akee...
I made a few changes to your code (look for the Sparkie was here comments) and it seems to work now. I had to change the lpstrText member of the SCTextRange structure from .b to .l to get this to work. Is that a PB bug or not, I don't know.
Code: Select all
;---- Initialize Scintilla DLL
If InitScintilla(#PB_Compiler_Home + "compilers\scintilla.dll") = #False
MessageRequester("Error","Scintilla.DLL Did not load",0)
End
EndIf
;
;InitScintillaStaticFull()
;.......................Sparkie was here ........................
Structure _SCTextRange
chrg.SCCharacterRange
lpstrText.l
EndStructure
;.................................................................
#SCI_INDICATORFILLRANGE = 2504
#SCI_INDICATORCLEARRANGE = 2505
#SCI_SETINDICATORVALUE = 2502
#SCI_SETINDICATORCURRENT = 2500
Enumeration
#SciID
#SrchID
EndEnumeration
Enumeration 0
#LexerState_Space
#LexerState_Click
EndEnumeration
Procedure Highlight(EditorGadget.l, startpos.l, endpos.l)
If startpos = -1
endstyled.l = ScintillaSendMessage (#SciID, #SCI_GETENDSTYLED)
linenumber.l = ScintillaSendMessage (#SciID, #SCI_LINEFROMPOSITION, endstyled)
Else
linenumber = ScintillaSendMessage (#SciID, #SCI_LINEFROMPOSITION, startpos)
EndIf
CurrentPos.l = ScintillaSendMessage (#SciID, #SCI_POSITIONFROMLINE, linenumber)
ScintillaSendMessage (#SciID, #SCI_STARTSTYLING, CurrentPos, $1F | #INDICS_MASK)
state = #LexerState_Space
startkeyword = CurrentPos
keyword.s = ""
prevChar.l=''
inClick.b=#False
While CurrentPos <= endpos
oldstate = state
Char.l = ScintillaSendMessage (#SciID, #SCI_GETCHARAT, CurrentPos)
If Char = '@' And prevChar = ' '
inClick=#True
state = #LexerState_Click
ElseIf Char = 10 Or Char = 13
inClick=#False
state = #LexerState_Space
ElseIf inClick=#True And Char <> ' '
state = #LexerState_Click
keyword+Chr(Char)
ElseIf Char = 9 Or Char = ' ' Or Char = '.'
state = #LexerState_Space
inClick=#False
Else
state = #LexerState_Space
inClick=#False
EndIf
If oldstate <> state Or CurrentPos = endpos
ScintillaSendMessage (#SciID, #SCI_SETSTYLING, CurrentPos - startkeyword, oldstate)
startkeyword = CurrentPos
EndIf
If Char = 10 Or CurrentPos = endpos
linenumber + 1
EndIf
CurrentPos + 1
prevChar=Char
Wend
EndProcedure
Procedure ScintillaCallBack(EditorGadget.l, *scinotify.SCNotification)
result.l = 0
Select *scinotify\nmhdr\code
;---- #SCN_HOTSPOTCLICK
Case #SCN_HOTSPOTCLICK
SCTxtRng._SCTextRange
;SCCharRng.SCCharacterRange ;CHANGED structure not used
Position = *scinotify\Position
linenumber = ScintillaSendMessage (#SciID, #SCI_LINEFROMPOSITION, Position)
WrdEnd.l = ScintillaSendMessage (#SciID,#SCI_WORDENDPOSITION, Position, 1)
WrdStart.l = ScintillaSendMessage (#SciID,#SCI_WORDSTARTPOSITION, Position, 1)
SCTxtRng\chrg\cpMax = WrdEnd.l ;CHANGED to point to correct structure
SCTxtRng\chrg\cpMin = WrdStart.l ;CHANGED to point to correct structure
ScintillaSendMessage (#SciID, #SCI_SETSEL, WrdStart, WrdEnd)
;.......................Sparkie was here ........................
SCTxtRng\chrg\cpMin = WrdStart
SCTxtRng\chrg\cpMax = WrdEnd
SCTxtRng\lpstrText = AllocateMemory(WrdEnd - WrdStart + 1)
txtLen.l = ScintillaSendMessage (#SciID,#SCI_GETTEXTRANGE,0, SCTxtRng)
Debug (Str(WrdStart) + " " + Str(WrdEnd) + " " + Str(txtLen))
clicked_text.s= PeekS(SCTxtRng\lpstrText, txtLen) ;CHANGED
SetGadgetText(#SrchID,clicked_text)
FreeMemory(SCTxtRng\lpstrText)
;.....................................................................
;---- #SCN_STYLENEEDED
Case #SCN_STYLENEEDED
Highlight(EditorGadget, -1, *scinotify\Position)
EndSelect
ProcedureReturn result
EndProcedure
;---- OpenWindow(0)
OpenWindow(0, 0, 0, 600, 400, "Task List", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
CreateMenu(0, WindowID(0))
MenuTitle("File")
MenuItem(1, "Quit")
CreateGadgetList(WindowID(0))
StringGadget(#SrchID, 5, 5, 570, 16, "Search",#PB_String_BorderLess)
ScintillaGadget(#SciID, 5, 27, 590, 348, @ScintillaCallBack())
SetGadgetColor(#SrchID, #PB_Gadget_FrontColor, $C0C0C0)
;---- Choose a lexer
ScintillaSendMessage (#SciID, #SCI_SETLEXER, #SCLEX_CONTAINER, 0)
;---- Set default font
ScintillaSendMessage (#SciID, #SCI_STYLESETFONT, #STYLE_DEFAULT, @"Courier New")
ScintillaSendMessage (#SciID, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 8)
ScintillaSendMessage (#SciID, #SCI_STYLECLEARALL)
;---- Set styles for custom lexer
ScintillaSendMessage (#SciID, #SCI_STYLESETFORE, #LexerState_Click, $EE0000)
ScintillaSendMessage (#SciID, #SCI_STYLESETFONT, #LexerState_Click, @"Tahoma")
ScintillaSendMessage (#SciID, #SCI_STYLESETSIZE, #LexerState_Click, 10)
ScintillaSendMessage (#SciID, #SCI_STYLESETHOTSPOT, #LexerState_Click, #True)
;---- Set some sample text
text.s = "The clickable text is blue" + #CRLF$
text + "Click these : @clickme or @clickmeinstead" + #CRLF$
ScintillaSendMessage (#SciID, #SCI_SETTEXT, 0, @text)
SetActiveGadget(#SciID)
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab | #PB_Shortcut_Shift)
;---- Event Loop
quit.l = #False
Repeat
event.l = WaitWindowEvent()
GadgetID = EventGadget()
Select event
Case #PB_Event_CloseWindow
quit = #True
Case #PB_Event_Menu
Select EventMenu()
Case 1 : quit = #True
EndSelect
EndSelect
Until quit
; IDE Options = PureBasic 4.10 (Windows - x86)
; CursorPosition = 239
; FirstLine = 214