; --------------------------------------------------------------------------------------------; Copyright (c) Fantaisie Software. All rights reserved.; Dual licensed under the GPL and Fantaisie Software licenses.; See LICENSE and LICENSE-FANTAISIE in the project root for license information.; --------------------------------------------------------------------------------------------;; Methods to create a readonly scintilla gadget for code display; With the configured IDE colors;Global HighlightCodeViewerProcedure CodeViewer_HighlightCallback(*StringStart.BYTE, Length, *Color, IsBold, TextChanged)ScintillaSendMessage(HighlightCodeViewer, #SCI_SETSTYLING, Length, *Color)EndProcedureProcedure CodeViewer_UpdateHighlight(Gadget)HighlightCodeViewer = Gadget; re-highlight the textSize = ScintillaSendMessage(Gadget, #SCI_GETTEXTLENGTH)*Buffer = AllocateMemory(Size+1)If *BufferScintillaSendMessage(Gadget, #SCI_GETTEXT, Size+1, *Buffer)ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, 0, $FFFFFF)HighlightingEngine(*Buffer, Size, 0, @CodeViewer_HighlightCallback(), 0)FreeMemory(*Buffer)EndIf; update line numbers size (if enabled)If ScintillaSendMessage(Gadget, #SCI_GETMARGINWIDTHN, 0) > 0NbLines = ScintillaSendMessage(Gadget, #SCI_GETLINECOUNT, 0, 0)If NbLines < 10 ; 2 digits minimum, as with the main code areaNbLines = 10EndIfLines$ = "_" + RSet("9", Len(Str(NbLines)), "9")ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, ScintillaSendMessage(Gadget, #SCI_TEXTWIDTH, #STYLE_LINENUMBER, ToAscii(Lines$)))EndIfEndProcedureProcedure UpdateCodeViewer(Gadget)If ScintillaSendMessage(Gadget, #SCI_GETMARGINWIDTHN, 0) > 0LineNumbers = #TrueElseLineNumbers = #FalseEndIf; Gtk2+ 'Pango' need an "!" before the font name (else it will use GDK font);CompilerIf #CompileLinuxGtkFontName$ = "!"+EditorFontName$ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, #STYLE_DEFAULT, ToAscii(FontName$))CompilerElseScintillaSendMessage(Gadget, #SCI_STYLESETFONT, #STYLE_DEFAULT, ToAscii(EditorFontName$))CompilerEndIfScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, EditorFontSize)If EditorFontStyle & #PB_Font_BoldScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, #STYLE_DEFAULT, 1)ElseScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, #STYLE_DEFAULT, 0)EndIfIf EditorFontStyle & #PB_Font_ItalicScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, #STYLE_DEFAULT, 1)ElseScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, #STYLE_DEFAULT, 0)EndIfIf EnableColoringScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, Colors(#COLOR_GlobalBackground)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL, 0, 0) ; to make the background & font change effective!ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 1, Colors(#COLOR_NormalText)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 2, Colors(#COLOR_BasicKeyword)\DisplayValue)If EnableKeywordBolding; Gtk2 'Pango' need an "!" before the font name (else it will use GDK font);CompilerIf #CompileLinuxGtkFontName$ = "!"+EditorBoldFontName$ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 2, ToAscii(FontName$))ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 14, ToAscii(FontName$))CompilerElseScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 2, ToAscii(EditorBoldFontName$))ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 14, ToAscii(EditorBoldFontName$))CompilerEndIfScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, EditorFontSize)ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, 2, 1) ; Bold (no effect on linux, but maybe on windows later)ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, 14, 1)If EditorFontStyle & #PB_Font_ItalicScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, 2, 1)ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, 14, 1)EndIfEndIfIf LineNumbersScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, Colors(#COLOR_LineNumberBack)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, Colors(#COLOR_LineNumber)\DisplayValue)EndIfScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 3, Colors(#COLOR_Comment)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 4, Colors(#COLOR_Constant)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 5, Colors(#COLOR_String)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 6, Colors(#COLOR_PureKeyword)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 7, Colors(#COLOR_ASMKeyword)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 8, Colors(#COLOR_Operator)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 9, Colors(#COLOR_Structure)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 10, Colors(#COLOR_Number)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 11, Colors(#COLOR_Pointer)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 12, Colors(#COLOR_Separator)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 13, Colors(#COLOR_Label)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 14, Colors(#COLOR_CustomKeyword)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 15, Colors(#COLOR_Module)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 16, Colors(#COLOR_BadBrace)\DisplayValue)CompilerIf #CompileWindowsIf Colors(#COLOR_Selection)\DisplayValue = -1 Or EnableAccessibility ; special accessibility schemeScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))ElseScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)EndIfIf Colors(#COLOR_SelectionFront)\DisplayValue = -1 Or EnableAccessibilityScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))ElseScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)EndIfCompilerElseScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)CompilerEndIfScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, Colors(#COLOR_CurrentLine)\DisplayValue, 0)ScintillaSendMessage(Gadget, #SCI_SETCARETFORE, Colors(#COLOR_Cursor)\DisplayValue, 0)If Colors(#COLOR_CurrentLine)\Enabled = 0 Or Colors(#COLOR_CurrentLine)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValueScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, 0, 0) ; disable the different color for the current lineElseScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, 1, 0) ; enable the different color for the current lineEndIfElse ; Coloring DisabledScintillaSendMessage(Gadget, #SCI_STYLERESETDEFAULT, 0, 0)ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, $FFFFFF)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, 000000ドル)ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL, 0, 0) ; to make the background & font change effective!ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, $FFFFFF, 0)ScintillaSendMessage(Gadget, #SCI_SETCARETFORE, 000000,ドル 0)CompilerIf #CompileWindowsScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))CompilerElseScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, $C0C0C0)ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, 000000ドル)CompilerEndIfIf LineNumbersScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, $FFFFFF)ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, 000000ドル)EndIfScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, 0, 0) ; disable the different color for the current lineEndIfScintillaSendMessage(Gadget, #SCI_SETTABWIDTH, TabLength)ScintillaSendMessage(Gadget, #SCI_SETUSETABS, RealTab)CodeViewer_UpdateHighlight(Gadget)EndProcedure; Note: *Buffer must be null-terminated!Procedure SetCodeViewer(Gadget, *Buffer, Encoding); set writable for the updateScintillaSendMessage(Gadget, #SCI_SETREADONLY, 0)If Encoding <> 0ScintillaSendMessage(Gadget, #SCI_SETCODEPAGE, #SC_CP_UTF8)ElseScintillaSendMessage(Gadget, #SCI_SETCODEPAGE, 0)EndIfScintillaSendMessage(Gadget, #SCI_SETTEXT, 0, *Buffer); back to readonlyScintillaSendMessage(Gadget, #SCI_SETREADONLY, 1)CodeViewer_UpdateHighlight(Gadget)EndProcedureProcedure CreateCodeViewer(Gadget, x, y, width, height, LineNumbers)GadgetID = ScintillaGadget(Gadget, x, y, width, height, @EmptyScintillaCallback())If Gadget = #PB_AnyGadget = GadgetIDEndIfInitCodeViewer(Gadget, LineNumbers)ProcedureReturn GadgetIDEndProcedureProcedure InitCodeViewer(Gadget, LineNumbers)ScintillaSendMessage(Gadget, #SCI_CLEARCMDKEY, #SCK_TAB) ; to enable the window shortcutsScintillaSendMessage(Gadget, #SCI_CLEARCMDKEY, #SCK_RETURN)ApplyWordChars(Gadget)ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 1, 0)If LineNumbers; set to something > 0 to indicate that they are enabled; see CodeViewer_UpdateHighlight()ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, 16)ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)EndIfScintillaSendMessage(Gadget, #SCI_SETREADONLY, 1)UpdateCodeViewer(Gadget)EndProcedure
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。