hi everyone !
i try find some function in Scintilla Docs , but i dont found a way to get "full words" without get char by char ...
someone know a simple way to get full words and set color in this words ?
how can i get full word in Scintilla without use much "if"
- skinkairewalker
- Enthusiast
- Posts: 625
- Joined: Fri Dec 04, 2015 9:26 pm
Re: how can i get full word in Scintilla without use much "i
Not sure but maybe this helps you out:
Code: Select all
Procedure MakeScintillaText(text.s)
Static sciText.s
CompilerIf #PB_Compiler_Unicode
sciText = Space(StringByteLength(text, #PB_UTF8))
PokeS(@sciText, text, -1, #PB_UTF8)
CompilerElse
sciText = text
CompilerEndIf
ProcedureReturn @sciText
EndProcedure
Enumeration Highlight
#Style_KeyWord_Green
#Style_KeyWord_Red
#Style_NonKeyWord
EndEnumeration
;Your KeyWords
Global KeyWordGreen.s = "Procedure|EndProcedure|Goto|For|Next|Repeat|Until|While|Wend"
Global KeyWordRed.s = "Select|EndSelect|Case|Newlist"
Global KeyWordSep.s = "|"
;Scintilla Properties
Procedure ScintillaProperties(Gadget)
BackColor=RGB(80,80,80)
;Character between each word in the KeyWord list
ScintillaSendMessage(Gadget, #SCI_AUTOCSETSEPARATOR, Asc(KeyWordSep))
;Style KeyWord Green
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_KeyWord_Green, RGB(7, 79,7))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #Style_KeyWord_Green, BackColor)
;ScintillaSendMessage(Gadget,#SCE_LUA_COMMENT, @"Courier New") ; Coment Font
;ScintillaSendMessage(Gadget,#SCE_LUA_COMMENT, 9) ; Coment Size
;ScintillaSendMessage(Gadget,#SCI_STYLESETBOLD,#Style_KeyWord_Green, #True ); set number Bold
;Style KeyWord Red
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_KeyWord_Red, RGB(79, 7, 7))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #Style_KeyWord_Red, BackColor)
;Style NonKeyWord
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_NonKeyWord, RGB(0, 0, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #Style_NonKeyWord, BackColor)
;ScintillaSendMessage(Gadget, #SCI_SETSELFORE,#True,RGB(255,255,255))
ScintillaSendMessage(Gadget, #SCI_SETSELBACK,#True,RGB(120,120,120))
txt.s="Procedure.l Test(x.l)"+Chr(10)
txt + " Select Case x"+Chr(10)
txt + " Case 1 : y = 3"+Chr(10)
txt + " Case 2 : y = 4"+Chr(10)
txt + " EndSelect"+Chr(10)
txt + "EndProcedure"+Chr(10)
txt + "Procedure TestB(x.l)"+Chr(10)
txt + " Select Case x"+Chr(10)
txt + " Case 1 : y = 3"+Chr(10)
txt + " Case 2 : y = 4"+Chr(10)
txt + " EndSelect"+Chr(10)
txt + "EndProcedure" + Chr(0)
ScintillaSendMessage(Gadget, #SCI_SETTEXT, 0, MakeScintillaText(txt))
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN,0,30)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(0,0,0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(100,100,100))
;Main background color
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, BackColor)
;Caretline backcolor
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK , RGB ( 100 , 100, 100 ) )
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE , #True )
;Fold margin:
;fold color
ScintillaSendMessage(Gadget, #SCI_SETFOLDMARGINCOLOUR, 1,RGB(95,95,95))
ScintillaSendMessage(Gadget, #SCI_SETFOLDMARGINHICOLOUR, 1,RGB(95,95,95))
;fold symbols
ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, RGB(160,160,160))
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, $0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, RGB(160,160,160))
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, $0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPENMID, RGB(160,160,160))
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, $0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERSUB, $0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERTAIL, $0)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND, #SC_MARK_EMPTY);
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID, #SC_MARK_EMPTY);
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_BOXMINUS)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER , #SC_MARK_BOXPLUS)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB , #SC_MARK_VLINE)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL, #SC_MARK_LCORNER)
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN,2,12)
ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) ;margin 2 set to hold folder symbols
;fold sensitivity for clicks
ScintillaSendMessage(Gadget, #SCI_SETMARGINSENSITIVEN, 2, 1) ;margin 2 set as sensitive to clicks
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 0, 1 | #SC_FOLDLEVELHEADERFLAG); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 1, 2 | #SC_FOLDLEVELHEADERFLAG); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 2, 3); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 3, 3); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 4, 3 | #SC_FOLDLEVELNUMBERMASK); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 5, 2); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 6, 1 | #SC_FOLDLEVELHEADERFLAG); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 7, 2); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 8, 2); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 9, 2); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 10,2); 'fold point
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, 11,2); 'fold point
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 0, #SC_MARKNUM_FOLDEROPEN)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 1, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 2, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 3, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 4, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 5, #SC_MARKNUM_FOLDERTAIL)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 6, #SC_MARKNUM_FOLDEROPEN)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 7, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 8, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 9, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 10, #SC_MARKNUM_FOLDERSUB)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, 11, #SC_MARKNUM_FOLDERTAIL)
EndProcedure
Procedure KeyWord(Key.s)
Protected n
If Key=""
ProcedureReturn -1
EndIf
;KeyWordGreen
For n=1 To CountString(KeyWordGreen, KeyWordSep) + 1
If LCase(StringField(KeyWordGreen, n, KeyWordSep)) = LCase(Key)
ProcedureReturn #Style_KeyWord_Green
EndIf
Next
;KeyWordRed
For n=1 To CountString(KeyWordRed, KeyWordSep) + 1
If LCase(StringField(KeyWordRed, n, KeyWordSep)) = LCase(Key)
ProcedureReturn #Style_KeyWord_Red
EndIf
Next
ProcedureReturn #Style_NonKeyWord
EndProcedure
Procedure ScintillaGetLineEndPosition(Gadget, Line)
ProcedureReturn ScintillaSendMessage(Gadget, #SCI_GETLINEENDPOSITION, Line)
EndProcedure
Procedure ScintillaLineFromPosition(gadget, Pos)
ProcedureReturn ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, Pos)
EndProcedure
Procedure Highlight(Gadget.l, EndPos.l)
Protected Char.i, KeyWord.s, StyleID.i
Protected CurrentPos.i = 0, EndLinePos.i
EndPos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, EndPos))
ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, CurrentPos, $1F | #INDICS_MASK)
While CurrentPos <= EndPos
Char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, CurrentPos)
Select Char
Case 'a' To 'z', 'A' To 'Z'
EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, CurrentPos))
KeyWord = Chr(Char)
While CurrentPos < EndLinePos
CurrentPos + 1
Char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, CurrentPos)
If Not ((Char >= 'a' And Char <= 'z') Or (Char >= 'A' And Char <= 'Z') Or Char = '_'Or (Char >= '0' And Char <= '9'))
CurrentPos-1
Break
EndIf
KeyWord + Chr(Char)
Wend
;-KeyWord or not KeyWord ?
Select KeyWord(KeyWord)
Case #Style_KeyWord_Green
StyleID = #Style_KeyWord_Green
Case #Style_KeyWord_Red
StyleID = #Style_KeyWord_Red
Default
StyleID = #Style_NonKeyWord
EndSelect
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, Len(KeyWord), StyleID)
Default
ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_NonKeyWord)
EndSelect
CurrentPos+1
Wend
EndProcedure
Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
Case #SCN_STYLENEEDED
Highlight(Gadget, *scinotify\position)
Case #SCN_MARGINCLICK
iLine = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, *scinotify\position, 0)
ScintillaSendMessage(Gadget, #SCI_TOGGLEFOLD, iLine, 0)
iExpanded = ScintillaSendMessage(hSci, #SCI_GETFOLDEXPANDED, iLine, 0)
If iExpanded
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, iLine, #SC_MARKNUM_FOLDER)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, iLine, #SC_MARKNUM_FOLDEROPEN)
Else
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, iLine, #SC_MARKNUM_FOLDEROPEN)
ScintillaSendMessage(Gadget, #SCI_MARKERADD, iLine, #SC_MARKNUM_FOLDER)
EndIf
EndSelect
EndProcedure
Procedure ScintillaSyntax(PBID,x,y,width,height)
If InitScintilla()
result=ScintillaGadget(PBID, x, y, width, height, @ScintillaCallBack())
ScintillaProperties(0)
EndIf
If PBID=#PB_Any
ScintillaProperties(result) : ProcedureReturn result
Else
ScintillaProperties(PBID) : ProcedureReturn GadgetID(result)
EndIf
EndProcedure
OpenWindow(0, 0, 0, 1000, 700, "Scintilla Highlight",#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ScintillaSyntax(#PB_Any,0,0,1000,700)
Repeat
ev=WaitWindowEvent()
Until ev=#PB_Event_CloseWindow
End
- skinkairewalker
- Enthusiast
- Posts: 625
- Joined: Fri Dec 04, 2015 9:26 pm
Re: how can i get full word in Scintilla without use much "i
thanks by you answer !
this working fine
but have a simple way to understand how it works ? xD
this working fine
but have a simple way to understand how it works ? xD