Code: Alles auswählen
EnableExplicit
Procedure SCI_GetTextFormat(ID)
Protected result
Select ScintillaSendMessage(ID, #SCI_GETCODEPAGE)
Case #SC_CP_UTF8
result = #PB_UTF8
Default
result = #PB_Ascii
EndSelect
ProcedureReturn result
EndProcedure
Procedure SCI_SetGadgetText(ID, Text.s)
Protected Buffer.s
; Wir erzeugen einen Stringbuffer in der größte, wie das
; Scintilla in bei der momentan eingestellten Codepage benötigt!
Buffer = Space(StringByteLength(Text, SCI_GetTextFormat(ID)))
PokeS(@Buffer, Text, -1, SCI_GetTextFormat(ID))
ProcedureReturn ScintillaSendMessage(ID, #SCI_SETTEXT, 0, @Buffer)
EndProcedure
Procedure SCI_LoadFile(ID, FileName.s)
Protected FF, Format, length, *mem, Text.s
FF = ReadFile(#PB_Any, FileName)
If FF
Select ReadStringFormat(FF)
; hier wird das StringFormat ermittelt und entsprechend gleich die Codepage eingestellt
Case #PB_UTF8, #PB_Unicode
Format = #PB_UTF8
ScintillaSendMessage(ID, #SCI_SETCODEPAGE, #SC_CP_UTF8)
Default
Format = #PB_Ascii
ScintillaSendMessage(ID, #SCI_SETCODEPAGE, 0)
EndSelect
length = Lof(FF)
If length
*mem = AllocateMemory(length)
If *mem
ReadData(FF, *mem, length)
Text = PeekS(*mem, length, Format)
SCI_SetGadgetText(ID, Text.s)
FreeMemory(*mem)
CloseFile(FF)
ProcedureReturn #True
EndIf
EndIf
CloseFile(FF)
EndIf
EndProcedure
Procedure SCI_SaveFile(ID, FileName.s)
Protected length, *mem, FF
FF = CreateFile(#PB_Any, FileName.s)
If FF
; jetzt schreiben wir den BOM
WriteStringFormat(FF, SCI_GetTextFormat(ID))
length = ScintillaSendMessage(ID, #SCI_GETLENGTH) + 1
*mem = AllocateMemory(length)
; jetzt holen wir den Text in den Speicher,
; wo er auch in dem Format vorliegt, das wir schreiben wollen.
ScintillaSendMessage(ID, #SCI_GETTEXT, length, *mem)
WriteData(FF, *mem, length - 1); der Speicher mußte ein Byte größer sein, aber schreiben wollen wir das nicht ;)
CloseFile(FF)
FreeMemory(*mem)
ProcedureReturn #True
EndIf
EndProcedure
InitScintilla()
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "")
ScintillaGadget(0, 10, 10, 620, 460, 0)
Define myFile.s = #PB_Compiler_Home + "SDK\Readme.txt" ; hier anpassen
SCI_LoadFile(0, myFile)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Gruß
Thomas