Scintilla SCI_MARGINSETTEXT issue(s)

Everything else that doesn't fall into one of the other PB categories.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Scintilla SCI_MARGINSETTEXT issue(s)

Post by bbanelli »

Greetings,

I want to add text to margin, but when I try to do so, only first character appears instead of whole text?

Code: Select all

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, 240, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    If InitScintilla()
      ScintillaGadget(0, 10, 10, 300, 220, #Null)
      
      ScintillaSendMessage(0, #SCI_GETEDGEMODE, 1)
      
      ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, 16)
      ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 1, 0)
      ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 2, 0)
      ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 3, 0)
      ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 4, 50)
      
      ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE, 1)
      ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLEALWAYS, 1)      
      ScintillaSendMessage(0, #SCI_SETCARETLINEBACKALPHA, 50)
      ScintillaSendMessage(0, #SCI_SETCARETLINEBACK, RGB(100, 252, 195)) 
      
      ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 4, #SC_MARGIN_TEXT)
      
      ; Generate random numbers and sort them
      NewMap UniqueRandomMap()
      NewList UniqueRandomList.i()
      Text$ = ""
      For i = 0 To 35
        While MapSize(UniqueRandomMap()) < 7
          AddMapElement(UniqueRandomMap(),Str(Random(90,1)))
        Wend
        ResetMap(UniqueRandomMap())
        ForEach UniqueRandomMap()
          AddElement(UniqueRandomList())
          UniqueRandomList() = Val(MapKey(UniqueRandomMap()))
        Next
        SortList(UniqueRandomList(),#PB_Sort_Ascending)
        ResetList(UniqueRandomList())
        ForEach UniqueRandomList()
          Text$ + UniqueRandomList() + "  "
        Next
        Text$ = RTrim(Text$)
        Text$ = RTrim(Text$)
        If i <> 35 ; skip last line break
          Text$ + #CRLF$
        EndIf
        ClearMap(UniqueRandomMap())
        ClearList(UniqueRandomList())
      Next

      ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeScintillaText(Text$))
      
      ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 0, MakeScintillaText(":Batch 1"))
      ScintillaSendMessage(0, #SCI_MARGINSETTEXT, 5, MakeScintillaText(":End"))
      For i = 1 To 6
        BatchBegin$ = ":Batch " + Str(i+1)
        BatchEnd$ = ":End"
        ScintillaSendMessage(0, #SCI_MARGINSETTEXT, i*6-1, MakeScintillaText(BatchEnd$))
        ScintillaSendMessage(0, #SCI_MARGINSETTEXT, i*6, MakeScintillaText(BatchBegin$))
      Next

    EndIf
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
Image

Stupid me - I've sorted it out, I had to use MakeScintillaText(), naturally! The other question below still remains!

Also, I would like to make those margins permanent. Now, when I delete a line, marker (well, only first character, but hopefully this is correctable :)) gets removed. How can I keep those permanent? I can preset length (number of lines) of this gadget, so it would have 36, 72 or whatever lines necessary, but without deleting those margins if possible.
Last edited by bbanelli on Mon Nov 10, 2014 1:53 am, edited 2 times in total.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Scintilla SCI_MARGINSETTEXT issue(s)

Post by Danilo »

Hint: The full text is added in ASCII mode. ;)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Scintilla SCI_MARGINSETTEXT issue(s)

Post by IdeasVacuum »

Not really sure what you mean, but instead of deleting the line, why not replace the text with nothing, or a space?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Scintilla SCI_MARGINSETTEXT issue(s)

Post by bbanelli »

Danilo wrote:Hint: The full text is added in ASCII mode. ;)
Well, that's what I get for coding on Sunday night/Monday early morning. :)
IdeasVacuum wrote:Not really sure what you mean, but instead of deleting the line, why not replace the text with nothing, or a space?
This is my problem:

http://youtu.be/ZbNkEFKUJMs?hd=1

So basically, you are correct, when I "delete" the line by selecting row and removing it, it remains. However, when I select multiple rows and press "Delete" on keyboard, you can see what happens. Is there a way to prevent that? I guess I could have callback that traps keys and when it detects either backspace or delete pressed, finds highlighted rows and replace them with new text? But both backspace or delete doesn't seem to be "trapped" by SCN_CHARADDED and *scinotify\ch.

Maybe going this way?

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification) 
  If *scinotify\nmhdr\code = #SCN_MODIFIED
    Debug *scinotify\line
    ;TODO
  EndIf
EndProcedure
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Scintilla SCI_MARGINSETTEXT issue(s)

Post by Danilo »

bbanelli wrote:Maybe going this way?

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification) 
  If *scinotify\nmhdr\code = #SCN_MODIFIED
    Debug *scinotify\line
    ;TODO
  EndIf
EndProcedure
Yes, and there is even more detailed info available.

Code: Select all

Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification) 
    If *scinotify\nmhdr\code = #SCN_MODIFIED
        
        Debug *scinotify\line
        Debug *scinotify\position
        Debug *scinotify\length
        
        ; (Before)Delete, (Before)Insert
        If *scinotify\modificationType & #SC_MOD_BEFOREDELETE
            Debug "#SC_MOD_BEFOREDELETE"
        EndIf
        If *scinotify\modificationType & #SC_MOD_DELETETEXT
            Debug "#SC_MOD_DELETETEXT"
            Debug "Lines added: "+*scinotify\linesAdded
        EndIf
        If *scinotify\modificationType & #SC_MOD_BEFOREINSERT
            Debug "#SC_MOD_BEFOREINSERT"
        EndIf
        If *scinotify\modificationType & #SC_MOD_INSERTTEXT
            Debug "#SC_MOD_INSERTTEXT"
            Debug "Lines added: "+*scinotify\linesAdded
        EndIf
        
        ; Undo, Redo, User
        If *scinotify\modificationType & #SC_PERFORMED_USER
            Debug "#SC_PERFORMED_USER"
        EndIf
        If *scinotify\modificationType & #SC_PERFORMED_UNDO
            Debug "#SC_PERFORMED_UNDO"
        EndIf
        If *scinotify\modificationType & #SC_PERFORMED_REDO
            Debug "#SC_PERFORMED_REDO"
        EndIf
        ;TODO
    EndIf
EndProcedure
All notifications are listed at http://scintilla.org/ScintillaDoc.html#Notifications
Post Reply