Initscintilla function deprecated

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4224
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Initscintilla function deprecated

Post by skywalk »

Hi Fred,
Why did you not use lexilla for the PB IDE code?
Is it easier to hardcode within the scintilla code directly?
Or it was already coded before lexilla appeared?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18274
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Initscintilla function deprecated

Post by Fred »

We have our own parser because we need much more than just coloring/case correction
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 782
Joined: Fri Dec 04, 2015 9:26 pm

Re: Initscintilla function deprecated

Post by skinkairewalker »

infratec wrote: Fri Oct 25, 2024 10:05 am Hm ... your code works here without problems.
I only changed the OpenfileRequester() part, removed InitScintilla() and modified the window stuff

Code: Select all

EnableExplicit



Procedure.s ReadFileToVar(Path$)
  Protected id_file, Format, Text$
  
  id_file = ReadFile(#PB_Any, Path$)
  If id_file
    Format = ReadStringFormat(id_file)
    Text$ = ReadString(id_file, Format | #PB_File_IgnoreEOL)
    CloseFile(id_file)
  EndIf
  
  ProcedureReturn Text$
EndProcedure


Define NbLexers, *Buffer, i, k, *Text, File$, *Lexer, w, h

Prototype.i CreateLexerProto(name.p - utf8)
Prototype.i GetLexerCountProto()
Prototype GetLexerNameProto(index.i, *BufferName, *BufferNameLength)


If OpenLibrary(0, "Lexilla.dll")
  Define CreateLexer.CreateLexerProto = GetFunction(0, "CreateLexer")
  Define GetLexerCount.GetLexerCountProto = GetFunction(0, "GetLexerCount")
  Define GetLexerName.GetLexerNameProto = GetFunction(0, "GetLexerName")
  
  If CreateLexer = #Null Or GetLexerCount = #Null Or GetLexerName = #Null
    Debug "Invalid Lexilla lib"
    End
  EndIf
EndIf

File$ = OpenFileRequester("Choose a html file", #PB_Compiler_Home + "Examples\Sources\Data\WebView\", "HTML|*.htm;*.html", 0)
If File$
  If FileSize(File$) < 0
    End
  EndIf
Else
  End
EndIf

; ; List all available lexers
; ;
; NbLexers = GetLexerCount()
; Debug "NbLexers: "+NbLexers
; 
; *Buffer = AllocateMemory(128)
; If *Buffer
;   For k = 0 To NbLexers - 1
;     GetLexerName(k, *Buffer, MemorySize(*Buffer))
;     Debug PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8)
;   Next
;   FreeMemory(*Buffer)
; EndIf

ExamineDesktops()
w = DesktopWidth(0)
h = DesktopHeight(0)


If OpenWindow(0, 0, 0, w - 40, h - 200, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ScintillaGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, 0)
  
  ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12) ; font size
  ScintillaSendMessage(0, #SCI_STYLECLEARALL)
  ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, $3f3f3f)
  ScintillaSendMessage(0, #SCI_SETSELBACK, 1, $a0a0a0) ; the background color of the selection
  ScintillaSendMessage(0, #SCI_SETSELALPHA, 100)       ; transparency of the selection
  For i = 0 To 32
    ScintillaSendMessage(0, #SCI_STYLESETBACK, i, $3f3f3f)
    ScintillaSendMessage(0, #SCI_STYLESETFORE, i, $999999) ; default text color
  Next
  
  *Lexer = CreateLexer("hypertext")
  ScintillaSendMessage(0, #SCI_SETILEXER, 0, *Lexer)
  
  ; HTML
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 1, $FF9F00) ; Comments
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 2, $9CCBEB) ; Numbers
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 3, $8080FF) ; Keyword1
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 4, $999999) ; Lines
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 6, $72ADC0) ; Operators
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 7, $F78865) ; Keyword Identifier
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 10, $72ADC0); Keyword2
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 11, $FF8000); Keyword3
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 12, $71AE71); Keyword4
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 13, $DE98D9); Constants
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 15, $00FFFF); Label
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 16, $8080FF); Error
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 17, $D3D08C); Hexnumber
  ScintillaSendMessage(0, #SCI_STYLESETFORE, 18, $D3D08C); Binnumber
  
  
  ; Set the text to the ScintillaGadget
  *Text = UTF8(ReadFileToVar(File$))
  ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
  FreeMemory(*Text) ; The buffer made by UTF8() has to be freed, to avoid memory leak
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
You need the lexilla.dll in the same directory as your exe.
And set 'Create temporay executable in source directory' for running from the IDE

I'm trying to change the lexer to vb or lua, but apparently it didn't work, is there something I'm forgetting to do???
Post Reply