Scintilla - Automatischer Zeileneinzug
Verfasst: 11.09.2009 19:46
Da ich das auch öfters selbst brauche und da soweit ich weiß kein automatischer Zeileneinzug vorab implementiert ist,
hier mal der Code für automatischen Zeileneinzug in einem Scintilla-Gadget.
hier mal der Code für automatischen Zeileneinzug in einem Scintilla-Gadget.
Code: Alles auswählen
; Implementation of autoindent in a scintilla gadget.
;
; Author: iostream
; Date: 11.9.2009
; Compiler: PB 4.40 Beta 2
; OS: Windows / Unix / MacOS
; String-Version: ASCII
EnableExplicit
; -----------------------------------------------
If Not InitScintilla()
MessageRequester("Error", "Can't initialize Scintilla.")
End
EndIf
; -----------------------------------------------
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
#NewlineChar = 13
CompilerElse
#NewlineChar = 10
CompilerEndIf
; -----------------------------------------------
Procedure.s GetLineIndent(ScintillaGadget, Line)
Protected Indent.s = ""
Protected Temp.s = ""
Protected *LineBuffer.Character = #Null
If Line >= 0
Temp = Space(ScintillaSendMessage(ScintillaGadget, #SCI_LINELENGTH, Line))
ScintillaSendMessage(ScintillaGadget, #SCI_GETLINE, Line, @Temp)
*LineBuffer = @Temp
While *LineBuffer\c = 9 Or *LineBuffer\c = 32
Indent + Chr(*LineBuffer\c)
*LineBuffer + SizeOf(Character)
Wend
EndIf
ProcedureReturn Indent
EndProcedure
Procedure ScintillaCallback(ScintillaGadget, *Notify.SCNotification)
Protected Line = 0
Protected Indent.s = ""
If *Notify\nmhdr\code = #SCN_CHARADDED
If *Notify\ch = #NewlineChar
Line = ScintillaSendMessage(ScintillaGadget, #SCI_LINEFROMPOSITION,ScintillaSendMessage(ScintillaGadget, #SCI_GETCURRENTPOS))
Indent = GetLineIndent(ScintillaGadget, Line - 1)
ScintillaSendMessage(ScintillaGadget, #SCI_REPLACESEL, 0, @Indent)
EndIf
EndIf
EndProcedure
; -----------------------------------------------
If OpenWindow(0, 0, 0, 500, 300, "Scintilla", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
ScintillaGadget(1, 10, 10, 480, 280, @ScintillaCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf