So I needed Scintilla to let me insert a read-only section at the start of text and lock it in place. This area would be filled later, progammatically. Maybe I could use this in a self-documenting feature or something. Or not.
Anyway, I took a peek at the #SCI_STYLESETCHANGEABLE message. In ScintillaDocs it is said that it is an "experimental and incompletely implemented style attribute". Caveat emptor. Ok, I understand that. But maybe it could still be usefull as it is. So I wrote this simple tester code:
Code: Select all
EnableExplicit
InitScintilla()
#STYLE_PROTECTED = 30
Define sciFont.s, hdr$, hdrLen, memBuffer
Procedure MakeUTF8Text(text.s)
Static buffer.s
buffer = Space(StringByteLength(text, #PB_UTF8))
PokeS(@buffer, text, -1, #PB_UTF8)
ProcedureReturn @buffer
EndProcedure
Procedure DoSciEvent()
Shared hdrLen
Protected posNow
If EventType() = #PB_EventType_RightClick
posNow = ScintillaSendMessage(0, #SCI_GETCURRENTPOS)
If ScintillaSendMessage(0, #SCI_GETSTYLEAT, posNow) = #STYLE_PROTECTED
ScintillaSendMessage(0, #SCI_GOTOPOS, hdrLen)
MessageRequester("WARNING!", "Restricted area. Trespassers will be shot.")
EndIf
EndIf
EndProcedure
hdr$ = ""
hdr$ + "----------------------------------------" + #CR$
hdr$ + "---- ----" + #CR$
hdr$ + "---- This is a protected area ----" + #CR$
hdr$ + "---- (ma non troppo) ----" + #CR$
hdr$ + "---- ----" + #CR$
hdr$ + "----------------------------------------" + #CR$
hdrLen = StringByteLength(hdr$,#PB_UTF8)
sciFont = "Courier New"
memBuffer = AllocateMemory(Len(sciFont) + 1)
PokeS(memBuffer, sciFont, -1, #PB_Ascii)
OpenWindow(0, 0, 0, 600, 700, "Block me lines!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScintillaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0)
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, memBuffer)
ScintillaSendMessage(0, #SCI_SETWRAPMODE, #SC_WRAP_WHITESPACE)
ScintillaSendMessage(0, #SCI_SETCODEPAGE, #SC_CP_UTF8)
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_PROTECTED, RGB($EE, $EE, $EE))
ScintillaSendMessage(0, #SCI_STYLESETCHANGEABLE, #STYLE_PROTECTED, 0)
ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeUTF8Text(hdr$))
ScintillaSendMessage(0, #SCI_STARTSTYLING, 0, $1F)
ScintillaSendMessage(0, #SCI_SETSTYLING, hdrLen, #STYLE_PROTECTED)
ScintillaSendMessage(0, #SCI_GOTOPOS, hdrLen)
SetActiveGadget(0)
BindGadgetEvent(0, @DoSciEvent())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
But the caret could still be positioned right before the protected area (either by arrow keys, as it jumped past it, or by leftclicking there) and then I was able to insert text again, pushing the following text forward. Not cool. Not cool at all. My protected area must remain there, at the start of the text, always. Then I realized I was out of beer. And ideas.
Any thoughts?
Ricardo