Mouse LeftClick Scintilla

Just starting out? Need help? Post your questions and find answers here.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Dec 28, 2023 9:04 pm

Mouse LeftClick Scintilla

Post by rndrei »

Why doesn't the left mouse button not work? System: Linux Ubuntu

Code: Select all

OpenWindow(0,0,0,600,600,"") 
ScintillaGadget(1,0,0,600,500,#Null) 
Repeat 
  event=WaitWindowEvent() 
 Select Event   
         Case #PB_Event_Gadget
           Select EventGadget()
             Case 1
               Select EventType()
                 Case #PB_EventType_LeftClick        : Debug "Click with left mouse button"
                 Case #PB_EventType_RightClick       : Debug "Click with right mouse button"
               EndSelect
           EndSelect   
       EndSelect
 Until event=#PB_Event_CloseWindow 
End
Last edited by rndrei on Fri Sep 05, 2025 11:58 am, edited 2 times in total.
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Mouse LeftClick

Post by normeus »

Scintilla does not respond to left click?
PureBasic's help file is really a must read:

https://www.purebasic.com/documentation ... adget.html


Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Mouse LeftClick

Post by Blue »

rndrei is right.
Tested in Windows 11 X64 with PB 6.21 beta 7, PB 6.21 beta 6, PB 6.20

However, the PB Help file only mentions right-click as an event type for this gadget...
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Mouse LeftClick

Post by mk-soft »

Actually, you don't need that with a ScintillaGadget.
But you can query the buttons on all widgets.

Code: Select all

;-TOP by mk-soft

ProcedureC _signal_button_press_event_cb(*Widget, *Event.GdkEventButton, UserData)
  If *Event\button = 1
    PostEvent(#PB_Event_Gadget, GetActiveWindow(), UserData, #PB_EventType_LeftButtonDown)
  EndIf
  ProcedureReturn 0 ; Button process continue
EndProcedure

ProcedureC _signal_button_release_event_cb(*Widget, *Event.GdkEventButton, UserData)
  If *Event\button = 1
    PostEvent(#PB_Event_Gadget, GetActiveWindow(), UserData, #PB_EventType_LeftClick)
  EndIf
  ProcedureReturn 0 ; Button process continue
EndProcedure

OpenWindow(0,0,0,600,600,"") 
ScintillaGadget(1,0,0,600,500,#Null)

signal_button_press_event_1 = g_signal_connect_(GadgetID(1), "button-press-event", @_signal_button_press_event_cb(), 1) ; <- UserData = gadget number
signal_button_relase_event_1 = g_signal_connect_(GadgetID(1), "button-release-event", @_signal_button_release_event_cb(), 1) ; <- UserData = gadget number

Repeat 
  event=WaitWindowEvent() 
  Select Event   
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          Select EventType()
            Case #PB_EventType_LeftButtonDown   : Debug "Down with left mouse button"
            Case #PB_EventType_LeftClick        : Debug "Click with left mouse button"
            Case #PB_EventType_RightClick       : Debug "Click with right mouse button"
          EndSelect
      EndSelect   
  EndSelect
Until event=#PB_Event_CloseWindow 

If g_signal_handler_is_connected_(GadgetID(1), signal_button_press_event_1)
  g_signal_handler_disconnect_(GadgetID(1), signal_button_press_event_1)
EndIf

If g_signal_handler_is_connected_(GadgetID(1), signal_button_relase_event_1)
  g_signal_handler_disconnect_(GadgetID(1), signal_button_relase_event_1)
EndIf

End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Dec 28, 2023 9:04 pm

Re: Mouse LeftClick

Post by rndrei »

What about MacOS?
User avatar
Piero
Addict
Addict
Posts: 950
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Mouse LeftClick

Post by Piero »

rndrei wrote: Fri Sep 05, 2025 11:35 am What about MacOS?
+1
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Mouse LeftClick Scintilla

Post by mk-soft »

macOS ...

Code: Select all

#NSLeftMouseUp        = 2
#NSRightMouseUp       = 4
#NSMouseMoved         = 5
#NSKeyDown            = 10
#NSKeyUp              = 11
#NSScrollWheel        = 22

#NSAlphaShiftKeyMask = 1 << 16
#NSShiftKeyMask      = 1 << 17
#NSControlKeyMask    = 1 << 18
#NSAlternateKeyMask  = 1 << 19
#NSCommandKeyMask    = 1 << 20

EnableExplicit

Global sharedApplication = CocoaMessage(0, 0, "NSApplication sharedApplication")
Define currentEvent, type, modifierFlags, keyCode
Define clickCount, location.NSPoint, deltaX.CGFloat, deltaY.CGFloat
Define Event

If OpenWindow(0, 0, 0, 320, 170, "Events example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 10, 10, 300, 100, #PB_Editor_ReadOnly)
  Repeat
    
    Event = WaitWindowEvent()
    currentEvent = CocoaMessage(0, sharedApplication, "currentEvent")
    If currentEvent
      type = CocoaMessage(0, currentEvent, "type")
      modifierFlags = CocoaMessage(0, currentEvent, "modifierFlags")
      
      ClearGadgetItems(0)
      
      ; keyboard events
      
      If type = #NSKeyDown
        keyCode = CocoaMessage(0, currentEvent, "keyCode")
        SetGadgetText(0, "Key down with code : " + Str(keyCode))
      EndIf
      
      If type = #NSKeyUp
        keyCode = CocoaMessage(0, currentEvent, "keyCode")
        SetGadgetText(0, "Key up with code : " + Str(keyCode))
      EndIf
      
      ; key modifiers
      
      If modifierFlags & #NSAlphaShiftKeyMask  
        AddGadgetItem(0, -1, "Caps lock is on")
      Else
        AddGadgetItem(0, -1, "Caps lock is off")
      EndIf
      If modifierFlags & #NSShiftKeyMask
        AddGadgetItem(0, -1, "Shift key is pressed")
      EndIf
      If modifierFlags & #NSControlKeyMask
        AddGadgetItem(0, -1, "Ctrl key is pressed")
      EndIf
      If modifierFlags & #NSAlternateKeyMask
        AddGadgetItem(0, -1, "Alt key is pressed")
      EndIf
      If modifierFlags & #NSCommandKeyMask
        AddGadgetItem(0, -1, "Cmd key is pressed")
      EndIf
      
      ; mouse events
      
      If type = #NSLeftMouseUp
        clickCount = CocoaMessage(0, currentEvent, "clickCount")
        Debug ("Left mouse " + Str(clickCount) + "x clicked")
      EndIf
      
      If type = #NSRightMouseUp
        clickCount = CocoaMessage(0, currentEvent, "clickCount")
        Debug ("Right mouse " + Str(clickCount) + "x clicked")
      EndIf
      
      If type = #NSMouseMoved
        CocoaMessage(@location, currentEvent, "locationInWindow")
        AddGadgetItem(0, -1, "Mouse moved to (" + StrF(location\x, 1) + "," + StrF(WindowHeight(0)-location\y, 1) + ")"); use WindowHeight() to flip y coordinate
      EndIf
      
      If type = #NSScrollWheel
        CocoaMessage(@deltaX, currentEvent, "deltaX")
        CocoaMessage(@deltaY, currentEvent, "deltaY")
        AddGadgetItem(0, -1, "Mouse wheel delta (" + StrF(deltaX, 1) + "," + StrF(deltaY, 1) + ")")
      EndIf
      

    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf


; IDE Options = PureBasic 5.72 (MacOS X - x64)
; CursorPosition = 23
; FirstLine = 8
; EnableXP
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Dec 28, 2023 9:04 pm

Re: Mouse LeftClick Scintilla

Post by rndrei »

Everything works!
Thank's!
But when you right-click the menu comes out: cut, copy, paste, how can it be disabled in scintilla?
wombats
Enthusiast
Enthusiast
Posts: 718
Joined: Thu Dec 29, 2011 5:03 pm

Re: Mouse LeftClick Scintilla

Post by wombats »

To turn off the default editing menu, you can set #SCI_USEPOPUP to #SC_POPUP_NEVER (or 0): https://scintilla.org/ScintillaDoc.html#SCI_USEPOPUP.

Code: Select all

ScintillaSendMessage(Gadget, #SCI_USEPOPUP, #SC_POPUP_NEVER)
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Dec 28, 2023 9:04 pm

Re: Mouse LeftClick Scintilla

Post by rndrei »

Just what you need, thank you!
Post Reply