;///////////////////////////////////////////////////////////////////////////////// ;***Go-Scintilla 2*** ;*================= ;* ;*©nxSoftWare (www.nxSoftware.com) 2010. ;*====================================== ;* ;* Commented demo program. ;///////////////////////////////////////////////////////////////////////////////// XIncludeFile "GoScintilla.pbi" Procedure GOSCI_SetLineHighlightColor(id, color) #GOSCI_HIGHLIGHTERMARKERNUM=#GOSCI_BOOKMARKMARKERNUM+1 ScintillaSendMessage(1, #SCI_MARKERSETBACK, #GOSCI_HIGHLIGHTERMARKERNUM, color) ScintillaSendMessage(1, #SCI_MARKERDEFINE, #GOSCI_HIGHLIGHTERMARKERNUM, #SC_MARK_BACKGROUND) EndProcedure Procedure GOSCI_SetLineHighlighted(id, lineIndex, flag=#True) If IsGadget(id) And GadgetType(id)=#PB_GadgetType_Scintilla If flag ScintillaSendMessage(id, #SCI_MARKERADD, lineIndex, #GOSCI_HIGHLIGHTERMARKERNUM) Else ScintillaSendMessage(id, #SCI_MARKERDELETE, lineIndex, #GOSCI_HIGHLIGHTERMARKERNUM) EndIf EndIf EndProcedure Declare.i MyLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine) ;Initialise the Scintilla library for Windows. CompilerIf #PB_Compiler_OS=#PB_OS_Windows InitScintilla() CompilerEndIf If OpenWindow(0, 100, 200, 600, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered) ;Required for the tab key to function correctly when the Scintilla control has the focus. RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) RemoveKeyboardShortcut(0, #PB_Shortcut_Tab | #PB_Shortcut_Shift) ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla. GOSCI_Create(1, 10, 10, 580, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN) ;Set the padding added to the width of the line-number margin. GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10) ;Set folding symbols margin width. GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 12) ;Set font. GOSCI_SetFont(1, "Courier New", 10) ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs. GOSCI_SetTabs(1, 3) ;Set colors of text area GOSCI_SetColor(1, #GOSCI_FORECOLOR, $FFFFFF) GOSCI_SetColor(1, #GOSCI_BACKCOLOR, $9f5000) ;Set colors of caret (caret color and the back color of the line containing the caret) GOSCI_SetColor(1, #GOSCI_CARETFORECOLOR, $FFFFFF) GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $b35900) ;Set colors of selection GOSCI_SetColor(1, #GOSCI_SELECTIONBACKCOLOR, $8080ff) GOSCI_SetColor(1, #GOSCI_SELECTIONFORECOLOR, $000000) ;Set colors of line margin GOSCI_SetColor(1, #GOSCI_LINENUMBERFORECOLOR, $c0c0c0) GOSCI_SetColor(1, #GOSCI_LINENUMBERBACKCOLOR, $804000) ;Set colors of fold margin GOSCI_SetColor(1, #GOSCI_FOLDMARGINHIBACKCOLOR, $804000) GOSCI_SetColor(1, #GOSCI_FOLDMARGINLOBACKCOLOR, $804000) ;Set colors of fold markers GOSCI_SetColor(1, #GOSCI_FOLDMARKERSFORECOLOR, $804000) GOSCI_SetColor(1, #GOSCI_FOLDMARKERSBACKCOLOR, $c0c0c0) ;Highlighters ;========== ;Set colors of line highlighter. GOSCI_SetLineHighlightColor(1, $aa5500) ;Set styles for our syntax highlighting. ;======================================= ;First define some constants to identify our various styles. ;You can name these as we wish. Enumeration #STYLES_COMMANDS=1 #STYLES_COMMENTS #STYLES_LITERALSTRINGS #STYLES_NUMBERS #STYLES_CONSTANTS #STYLES_FUNCTIONS #STYLES_SEPARATORS #STYLES_OPERATORS #STYLES_TYPES EndEnumeration ;Set individual styles for commands. GOSCI_SetStyleFont(1, #STYLES_COMMANDS, "", -1, #PB_Font_Bold) GOSCI_SetStyleColors(1, #STYLES_COMMANDS, $ffff80) ;We have omitted the optional back color. ;Set individual styles for comments. GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $00ffff) ;We have omitted the optional back color. ;Set individual styles for literal strings. GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, $00ff00) ;We have omitted the optional back color. ;Set individual styles for numbers. GOSCI_SetStyleColors(1, #STYLES_NUMBERS, $ffff00) ;We have omitted the optional back color. ;Set individual styles for constants. GOSCI_SetStyleColors(1, #STYLES_CONSTANTS, $66b3ff) ;We have omitted the optional back color. ;Set individual styles for functions. GOSCI_SetStyleColors(1, #STYLES_FUNCTIONS, $fdb382) ;We have omitted the optional back color. ;Set individual styles for separators. GOSCI_SetStyleColors(1, #STYLES_SEPARATORS, $c0c0c0) ;We have omitted the optional back color. ;Set individual styles for operators. GOSCI_SetStyleColors(1, #STYLES_OPERATORS, $8080ff) ;We have omitted the optional back color. ;Set individual styles for types. GOSCI_SetStyleColors(1, #STYLES_TYPES, $ffccff) ;We have omitted the optional back color. ;Set delimiters and keywords for our syntax highlighting. ;======================================================== ;Delimiters. ;First set up a ; symbol to denote a comment. GOSCI_AddDelimiter(1, ";", "", #GOSCI_DELIMITTOENDOFLINE, #STYLES_COMMENTS) ;Now set up quotes to denote literal strings. GOSCI_AddDelimiter(1, Chr(34), Chr(34), #GOSCI_DELIMITBETWEEN, #STYLES_LITERALSTRINGS) ;Now set up a # symbol to denote a constant. GOSCI_AddDelimiter(1, "#", "", #GOSCI_LEFTDELIMITWITHOUTWHITESPACE, #STYLES_CONSTANTS) ;Now set up a \ symbol to denote a type. GOSCI_AddDelimiter(1, "\", "", #GOSCI_LEFTDELIMITWITHOUTWHITESPACE, #STYLES_TYPES) GOSCI_AddDelimiter(1, "\", "", #GOSCI_RIGHTDELIMITWITHOUTWHITESPACE, #STYLES_TYPES) ;Basic command keywords. GOSCI_AddKeywords(1, "Debug End If ElseIf Else EndIf For To Next Step Protected", #STYLES_COMMANDS) GOSCI_AddKeywords(1, "ProcedureReturn Select Case EndSelect Global", #STYLES_COMMANDS) GOSCI_AddKeywords(1, "Declare CompilerIf CompilerEndIf Dim And Or", #STYLES_COMMANDS) ;Add some folding keywords. GOSCI_AddKeywords(1, "Procedure ProcedureDll ProcedureCDll ProcedureC Macro", #STYLES_COMMANDS, #GOSCI_OPENFOLDKEYWORD) GOSCI_AddKeywords(1, "EndProcedure EndMacro", #STYLES_COMMANDS, #GOSCI_CLOSEFOLDKEYWORD) ;Add separator keywords GOSCI_AddKeywords(1, "( ) [ ] { } , :", #STYLES_SEPARATORS) ;Add operator keywords GOSCI_AddKeywords(1, "= + - * / % & | < >", #STYLES_OPERATORS) ;Additional lexer options. ;========================= ;The lexer needs to know what separator characters we are using. GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/%&|<>(){}[],.:") ;We can also set a style for numbers. GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS) ;Set our user-defined line styling function. ;=========================================== GOSCI_SetLineStylingFunction(1, @MyLineStyler()) ;Set some initial text. We load a PB source file from disc. ;====================== If ReadFile(1, "exampleSource.pb") While Eof(1)=#False text$=ReadString(1) GOSCI_InsertLineOfText(1, -1, text$) Wend CloseFile(1) EndIf Repeat eventID=WaitWindowEvent() Select eventID Case #PB_Event_Gadget Select EventGadget() EndSelect EndSelect Until eventID=#PB_Event_CloseWindow ;Free the Scintilla gadget. ;This needs explicitly calling in order to free resources used by GoScintilla. GOSCI_Free(1) EndIf ;///////////////////////////////////////////////////////////////////////////////// ;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines. Procedure.i MyLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine) Protected result=#GOSCI_STYLELINESASREQUIRED, numBytesStyled, symbolJustStyled$, *ptrAscii.ASCII Static regexHEX Static regexBIN Static regexFunc Static regexFuncName Static regexType If Not regexHEX ;{ Init search patterns Enumeration #Highlight_Remove=-1 #Highlight_None=0 #Highlight_Visible=1 #Highlight_End=2 EndEnumeration regexHEX=CreateRegularExpression(#PB_Any, "^[$][0-9A-Fa-f]+") regexBIN=CreateRegularExpression(#PB_Any, "^[%][0-1]+") regexFunc=CreateRegularExpression(#PB_Any, "^[\w]+[$]?([.][\w]+){0,1}[\s]*[(]") regexFuncName=CreateRegularExpression(#PB_Any, "^[\w]+[$]?") regexType=CreateRegularExpression(#PB_Any, "^[.][a-zA-Z_][\w]*") ;} EndIf lineHighlighting=GOSCI_GetLineData(id, currentLine-1) ;Need to loop through the UTF-8 buffer invoking GoScintilla's styling lexer as appropriate. While numUtf8Bytes Dim foundSymbol$(0) Select *utf8Buffer\a Case ';' ;{ search fold markers to update fold levels textToExamine$=LCase(PeekS(*utf8Buffer, numUtf8Bytes, #PB_UTF8)) Select Left(textToExamine$, 2) Case ";{" GOSCI_IncFoldLevel(id) Case ";}" GOSCI_DecFoldLevel(id) EndSelect ;} Case '.' ;{ search type textToExamine$=LCase(PeekS(*utf8Buffer, numUtf8Bytes, #PB_UTF8)) If ExtractRegularExpression(regexType, textToExamine$, foundSymbol$()) ;apply separator style numBytesStyled=GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes) numUtf8Bytes-numBytesStyled *utf8Buffer+numBytesStyled ;apply type style numBytesStyled=Len(foundSymbol$(0))-numBytesStyled Select LCase(foundSymbol$(0)) Case ".a", ".b", ".c", ".d", ".f", ".i", ".l", ".q", ".s", ".u", ".w" ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, 0) Default ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_TYPES) EndSelect numUtf8Bytes-numBytesStyled *utf8Buffer+numBytesStyled Continue EndIf ;} Case '$', '%' ;{ search BIN or HEX number textToExamine$=LCase(PeekS(*utf8Buffer, numUtf8Bytes, #PB_UTF8)) If ExtractRegularExpression(regexHEX, textToExamine$, foundSymbol$()) Or ExtractRegularExpression(regexBIN, textToExamine$, foundSymbol$()) ;apply number style numBytesStyled=Len(foundSymbol$(0)) ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_NUMBERS) numUtf8Bytes-numBytesStyled *utf8Buffer+numBytesStyled Continue EndIf ;} Case '_', 'a' To 'z', 'A' To 'Z' ;{ search function name textToExamine$=LCase(PeekS(*utf8Buffer, numUtf8Bytes, #PB_UTF8)) If MatchRegularExpression(regexFunc, textToExamine$) If ExtractRegularExpression(regexFuncName, textToExamine$, foundSymbol$()) ;apply function style numBytesStyled=Len(foundSymbol$(0)) ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_FUNCTIONS) numUtf8Bytes-numBytesStyled *utf8Buffer+numBytesStyled Continue EndIf EndIf ;} EndSelect numBytesStyled=GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes) symbolJustStyled$=LCase(PeekS(*utf8Buffer, numBytesStyled, #PB_UTF8)) If symbolJustStyled$="procedure" lineHighlighting=#Highlight_Visible ElseIf symbolJustStyled$="endprocedure" If lineHighlighting=#Highlight_Visible lineHighlighting=#Highlight_End Else lineHighlighting=#Highlight_Remove EndIf EndIf numUtf8Bytes-numBytesStyled *utf8Buffer+numBytesStyled Wend If GOSCI_GetLineData(id, currentLine)<>lineHighlighting Select lineHighlighting Case #Highlight_Visible GOSCI_SetLineData(id, currentLine, #Highlight_Visible) GOSCI_SetLineHighlighted(id,currentLine,1) Case #Highlight_End GOSCI_SetLineData(id, currentLine, #Highlight_None) GOSCI_SetLineHighlighted(id, currentLine, 1) Case #Highlight_None, #Highlight_Remove GOSCI_SetLineData(id, currentLine, #Highlight_None) GOSCI_SetLineHighlighted(id, currentLine, 0) EndSelect result=#GOSCI_STYLENEXTLINEREGARDLESS EndIf ProcedureReturn result EndProcedure ;///////////////////////////////////////////////////////////////////////////////// ; IDE Options = PureBasic 4.51 RC 1 (Windows - x86) ; CursorPosition = 286 ; FirstLine = 182 ; Folding = Qh ; Markers = 92,126 ; EnableXP ; Executable = t.exe ; EnableCompileCount = 435 ; EnableBuildCount = 0 ; EnableExeConstant