Scintilla Readonly

Just starting out? Need help? Post your questions and find answers here.
Dano
User
User
Posts: 41
Joined: Fri Jul 16, 2004 4:20 am
Location: Edmonton, Ab, Canada

Scintilla Readonly

Post by Dano »

Hi everyone,

I quite like the Scintilla Gadget, and have been using it exclusively. Can someone tell me how to
make it readonly, so that one can't make changes to it? In reading the documentation there is
a SCI_SETREADONLY(bool readOnly), which I have enabled, but which still allows changes to be
made to the text, it sets an SCN_MODIFYATTEMPTRO, which I can only guess is a callback of
sorts which I have to check and then stop the changes being made. At this point my eyes are
glazing over as I have never used callbacks. I see in the Purebasic docs for Scintilla there is a
Callback parameter with a pointer to a structure in a Procedure to do this, but I am lost for
how to procede. Can anyone provide me with some sample code with which to learn from?

Dan
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Scintilla Readonly

Post by Danilo »

Code: Select all

ScintillaSendMessage(0, #SCI_SETREADONLY, #True, 0)
Works fine here. How is it possible to still modify the document? (Disable menus like "Cut"/"Paste" etc. within your program when setting Scintilla to read-only)

Here is an example (cut&paste from PB help) that shows the callback notification:

Code: Select all

ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
    ;
    ; The ProcedureDLL declaration is important for the callback to work correctly on MacOSX,
    ; on all other OS it has no effect.
    ;
    If *scinotify\nmhdr\code = #SCN_MODIFYATTEMPTRO ; search site http://www.scintilla.org/ScintillaDoc.html
        Debug "SCN_MODIFYATTEMPTRO"                 ; for 'SCN_MODIFYATTEMPTRO' to get info
    EndIf
EndProcedure

Procedure MakeScintillaText(text.s)
    Static sciText.s
    CompilerIf #PB_Compiler_Unicode
        sciText = Space(StringByteLength(text, #PB_UTF8))
        PokeS(@sciText, text, -1, #PB_UTF8)
    CompilerElse
        sciText = text
    CompilerEndIf
    ProcedureReturn @sciText
EndProcedure

If OpenWindow(0, 0, 0, 320, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    If InitScintilla()
        ScintillaGadget(0, 10, 10, 300, 70, @ScintillaCallBack())
        
        ; Output set to red color
        ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
        
        ; Set the initial text to the ScintillaGadget
        ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeScintillaText("This is a simple ScintillaGadget with text..."))
        
        ; Adding a second line of text with linebreak before
        Text$ = Chr(10) + "Second line"
        ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), MakeScintillaText(Text$))
        
        ; set read-only
        ScintillaSendMessage(0, #SCI_SETREADONLY, #True, 0)
    EndIf
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Scintilla Readonly

Post by IdeasVacuum »

You can use:

Code: Select all

DisableGadget(#MyScintilla, #True)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Dano
User
User
Posts: 41
Joined: Fri Jul 16, 2004 4:20 am
Location: Edmonton, Ab, Canada

Re: Scintilla Readonly

Post by Dano »

IdeasVacuum,

Yours is closest to what I want, I don't want to be able to change anything on the editor. I guess when I think about it what I thought of as read-only is different than what I needed. In a read-only document I think
it is still possible to make changes, you just can't save them. My need was for the text to be locked so no one could make any changes, at least at the beginning. Later on I have to be able to change stuff. So the DisableGadget
was perfect for me, aside from my own Popup menu which I used Purebasic commands with and it still changes text in there, but I can disable that when I need to. Sorry for the confusion Danilo, from what I infer
from your comments the native Scintilla menu does the right thing. I never used them, I use the Purebasic menu commands, which I will have to disable and enable when I need to.

Thanks to both of you for your help,
Dan
Post Reply