Page 1 of 1

Scintilla Gadget Functions

Posted: Wed Jul 07, 2021 1:19 am
by matty47
I am working through some Scintilla tutorials and have come across a stumbling block. My current code is

Code: Select all

 Procedure zoomIn()
      ScintillaSendMessage(0,#SCI_ZOOMIN,0,0) ;make larger one point per click
      SetActiveGadget(0)
    EndProcedure
    
    Procedure zoomOut()
      ScintillaSendMessage(0,#SCI_ZOOMOUT,0,0) ;make smaller one point per click
      SetActiveGadget(0)
    EndProcedure
    
    Procedure zoom20()
      ScintillaSendMessage(0,#SCI_SETZOOM,20,0) ;set zoom to +20 points
      SetActiveGadget(0)
    EndProcedure
    
    Procedure zoomReset()
      ScintillaSendMessage(0,#SCI_SETZOOM,0,0) ;remove zoom ie. zoom=0
      SetActiveGadget(0)
    EndProcedure
    

If OpenWindow(0, 0, 0, 400, 200, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    If InitScintilla()
      ScintillaGadget(0, 10, 10, 250, 180, 0)
      
      ScintillaSendMessage(0,#SCI_USEPOPUP,1,0) ;this turns on the default popup menu
      zi=ButtonGadget(#PB_Any,280,10,100,25,"Zoom In")
      zo=ButtonGadget(#PB_Any,280,50,100,25,"Zoom Out")
      z20=ButtonGadget(#PB_Any,280,90,100,25,"Zoom x 20")
      zr=ButtonGadget(#PB_Any,280,130,100,25,"Reset Zoom")
      SetActiveGadget(0)
      
      ; Set the initial text to the ScintillaGadget
      *Text=UTF8("This is a simple ScintillaGadget")
      ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
      FreeMemory(*Text) ; The buffer made by UTF8() has to be freed, to avoid memory leak
      
      ; Adding a second line of text with linebreak before
      Text$ = Chr(10) + "This is a second line"
      *Text=UTF8(Text$)
      ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), *Text)
      FreeMemory(*Text)
      
      ;Set a margin with line numbers
      ScintillaSendMessage(0,#SCI_SETMARGINWIDTHN,0,20)
    EndIf
    
Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case zi
            zoomIn()
          Case zo
            zoomOut()
          Case z20
            zoom20()
          Case zr
            zoomReset()
        EndSelect
    EndSelect
    
  Until EventID=#PB_Event_CloseWindow
EndIf
The line "ScintillaSendMessage(0,#SCI_USEPOPUP,1,0)" should enable a popup context menu but it does not work when compiled. If the line is left out there is still no popup context menu (which I thought should be enabled by default). Any help on this greatly appreciated. Thanks

Re: Scintilla Gadget Functions

Posted: Wed Jul 07, 2021 5:20 pm
by juergenkulow
Hello matty47,

Code: Select all

Procedure zoomIn()
  ScintillaSendMessage(0,#SCI_ZOOMIN,0,0) ;make larger one point per click
  SetActiveGadget(0)
EndProcedure

Procedure zoomOut()
  ScintillaSendMessage(0,#SCI_ZOOMOUT,0,0) ;make smaller one point per click
  SetActiveGadget(0)
EndProcedure

Procedure zoom20()
  ScintillaSendMessage(0,#SCI_SETZOOM,20,0) ;set zoom to +20 points
  SetActiveGadget(0)
EndProcedure

Procedure zoomReset()
  ScintillaSendMessage(0,#SCI_SETZOOM,0,0) ;remove zoom ie. zoom=0
  SetActiveGadget(0)
EndProcedure


If OpenWindow(0, 0, 0, 400, 200, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreatePopupMenu(0) 
    MenuItem(1, "Zoom In")     
    MenuItem(2, "Zoom Out") 
    MenuItem(3, "Zoom x 20")
    MenuItem(4, "Reset Zoom")
    CloseSubMenu()
  EndIf
  If InitScintilla()
    
    ScintillaGadget(0, 10, 10, 250, 180, 0)
    ; see https://www.scintilla.org/ScintillaDoc.html#SCI_USEPOPUP
    #SC_POPUP_NEVER=0 ;	Never show Default editing menu.
    #SC_POPUP_ALL=1   ; Show Default editing menu If clicking on scintilla.
    #SC_POPUP_TEXT=2  ; Show Default editing menu only If clicking on text area.
    ScintillaSendMessage(0,#SCI_USEPOPUP,#SC_POPUP_TEXT) ; $943 do not work?!
    ; see https://github.com/aluedke/renderdoc/blob/master/qrenderdoc/3rdparty/scintilla/src/ScintillaBase.cxx Line 67 and 482
    zi=ButtonGadget(#PB_Any,280,10,100,25,"Zoom In")
    zo=ButtonGadget(#PB_Any,280,50,100,25,"Zoom Out")
    z20=ButtonGadget(#PB_Any,280,90,100,25,"Zoom x 20")
    zr=ButtonGadget(#PB_Any,280,130,100,25,"Reset Zoom")
    SetActiveGadget(0)
    
    ; Set the initial text to the ScintillaGadget
    *Text=UTF8("This is a simple ScintillaGadget")
    ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
    FreeMemory(*Text) ; The buffer made by UTF8() has to be freed, to avoid memory leak
    
    ; Adding a second line of text with linebreak before
    Text$ = Chr(10) + "This is a second line"
    *Text=UTF8(Text$)
    ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), *Text)
    FreeMemory(*Text)
    
    ;Set a margin with line numbers
    ScintillaSendMessage(0,#SCI_SETMARGINWIDTHN,0,20)
  EndIf
  
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
      Case #PB_Event_RightClick       ; Right mouse shows popup menu.
        DisplayPopupMenu(0, WindowID(0))     
      Case #PB_Event_Menu        
        Select EventMenu()      
          Case 1 : zoomIn()
          Case 2 : zoomOut()
          Case 3 : zoom20()
          Case 4 : zoomReset()
        EndSelect
      Case #PB_Event_Gadget
        Select EventGadget()
          Case zi
            zoomIn()
          Case zo
            zoomOut()
          Case z20
            zoom20()
          Case zr
            zoomReset()
        EndSelect
    EndSelect
    
  Until EventID=#PB_Event_CloseWindow
EndIf

Re: Scintilla Gadget Functions

Posted: Thu Jul 08, 2021 7:00 am
by matty47
Thanks for the reply. I tried your code. The new popup menu did not show when clicking on the text in the Scintilla gadget but did show when clicking outside the gadget - on the window near the buttons. Oddly, while clicking the right mouse button, I found that the default popup (with Undo, Redo, Cut Paste etc) showed when right clicking on the horizontal scroll bar portion of the Scintilla gadget.
I will keep trying.
Thanks for your input
I am working on Windows 10 Home 64bit

Re: Scintilla Gadget Functions

Posted: Fri Jul 09, 2021 9:05 am
by juergenkulow