LeftButtonDown, LeftButtonUp, get separated controle.

Linux specific forum
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

LeftButtonDown, LeftButtonUp, get separated controle.

Post by Joris »

How can I get controle over these LeftButtonDown, LeftButtonUp, on as many different gadgets, under linux ?
I would like to get these events used separated.

Code: Select all

Procedure Event_Window_Main(EventID) 
Select EventType():   ; (on a listview)
  Case #PB_EventType_LeftClick : this gives two signals one Down and one Up
.....
EndProcedure

Repeat
   EventID.i = WaitWindowEvent()

   Select EventWindow()
     Case Window_0 : Event_Window_Main(EventID)
     Case Window_1 : Event_Window_Voice(EventID)
   EndSelect
ForEver

P.s. Trying things to get there : ExamineMouse() gives a linker Error : id returned 1 exit status ???

Thanks
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: LeftButtonDown, LeftButtonUp, get separated controle.

Post by mk-soft »

No whole code to test :(

But I missed Select EventGadget()

Code: Select all

Procedure Event_Window_Main(EventID)
  Select EventID
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Listview_0
          Select EventType(): ; (on a listview)
            Case #PB_EventType_LeftClick
              ;TODO
          EndSelect
    EndSelect
    
EndSelect

EndProcedure
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
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: LeftButtonDown, LeftButtonUp, get separated controle.

Post by Shardik »

Joris wrote: Sat Jan 29, 2022 4:10 pm How can I get controle over these LeftButtonDown, LeftButtonUp, on as many different gadgets, under linux ?
The following example demonstrates how to detect a mouse button press or release in a StringGadget and in an EditorGadget. The mouse button action is displayed in a StatusBar. I have tested the example successfully on Linux Mint 19.3 'Tricia' x64 with Cinnamon and PB 5.73 x64.

Code: Select all

EnableExplicit

Enumeration 
  #StringGadget
  #EditorGadget
EndEnumeration

Define ButtonAction.S
Define LastButtonAction.S

ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventKey, *UserData)
  Shared ButtonAction.S

  If *Event\type = #GDK_BUTTON_PRESS
    ButtonAction = "button pressed"
  ElseIf *Event\type = #GDK_BUTTON_RELEASE
    ButtonAction = "button released"
  EndIf
EndProcedure   

OpenWindow(0, 100, 100, 300, 140, "Detect mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)

g_signal_connect_(GadgetID(#StringGadget), "button_press_event",
  @MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#StringGadget), "button_release_event",
  @MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#EditorGadget), "button_press_event",
  @MouseButtonCallback(), 0)
g_signal_connect_(GadgetID(#EditorGadget), "button_release_event",
  @MouseButtonCallback(), 0)

CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)

Repeat
  If ButtonAction <> LastButtonAction
    StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
      ": " + ButtonAction, #PB_StatusBar_Center)
    LastButtonAction = ButtonAction
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: LeftButtonDown, LeftButtonUp, get separated controle.

Post by Shardik »

This is another similar example which uses PostEvent() in the callback to generate a custom event for the main event loop. And the press and release event is connected in a For..Next loop for all Gadgets contained in "Enumeration Gadgets":

Code: Select all

EnableExplicit

Enumeration CustomEvents
  #Event_MouseLeftButtonDown = #PB_Event_FirstCustomValue
  #Event_MouseLeftButtonUp
EndEnumeration 

Enumeration Gadgets
  #StringGadget
  #EditorGadget
EndEnumeration

Define GadgetCount.I = #PB_Compiler_EnumerationValue
Define i.I

ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventButton,
  *UserData)
  If *Event\type = #GDK_BUTTON_PRESS And *Event\button = 1
    PostEvent(#Event_MouseLeftButtonDown)
  ElseIf *Event\type = #GDK_BUTTON_RELEASE And *Event\button = 1
    PostEvent(#Event_MouseLeftButtonUp)
  EndIf
EndProcedure   

OpenWindow(0, 100, 100, 300, 140, "Detect left mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)

; ----- Connect press and release event to each gadget in "Enumeration Gadgets"

For i = 1 To GadgetCount
  g_signal_connect_(GadgetID(i - 1), "button_press_event",
  @MouseButtonCallback(), 0)
  g_signal_connect_(GadgetID(i - 1), "button_release_event",
  @MouseButtonCallback(), 0)
Next i

CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #Event_MouseLeftButtonDown
      StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
        ": Left mouse button down", #PB_StatusBar_Center)
    Case #Event_MouseLeftButtonUp
      StatusBarText(0, 0, "GagdetID " + Str(GetActiveGadget()) +
        ": Left mouse button up", #PB_StatusBar_Center)
  EndSelect
ForEver
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: LeftButtonDown, LeftButtonUp, get separated controle.

Post by mk-soft »

@Shardik,
Very nice :D
but you can the gadget number send with PostEvent, therefore get pb_id with

Code: Select all

gadget = g_object_get_data_(*Widget, "pb_id" ) - 1
@Joris
If you bind a signal with a ProcedureC callback, you must pay attention to the parameters number and type. Otherwise the entire Linux GUI may hang up.
Link: https://docs.gtk.org/gtk3/


Update

Code: Select all

EnableExplicit

Enumeration CustomEvents
  #Event_MouseLeftButtonDown = #PB_Event_FirstCustomValue
  #Event_MouseLeftButtonUp
EndEnumeration 

Enumeration Gadgets
  #StringGadget
  #EditorGadget
EndEnumeration

Define GadgetCount.I = #PB_Compiler_EnumerationValue
Define i.I

ProcedureC MouseButtonCallback(*Widget.GtkWidget, *Event.GdkEventButton, *UserData)
  Protected gadget
  gadget = g_object_get_data_(*Widget, "pb_id" ) - 1
  If *Event\type = #GDK_BUTTON_PRESS And *Event\button = 1
    PostEvent(#Event_MouseLeftButtonDown, GetActiveWindow(), gadget)
  ElseIf *Event\type = #GDK_BUTTON_RELEASE And *Event\button = 1
    PostEvent(#Event_MouseLeftButtonUp, GetActiveWindow(), gadget)
  EndIf
EndProcedure   

OpenWindow(0, 100, 100, 300, 140, "Detect left mouse button down & up")
StringGadget(#StringGadget, 10, 10, 280, 25, "")
EditorGadget(#EditorGadget, 10, 45, 280, 60)

; ----- Connect press and release event to each gadget in "Enumeration Gadgets"

For i = 1 To GadgetCount
  g_signal_connect_(GadgetID(i - 1), "button_press_event",
  @MouseButtonCallback(), 0)
  g_signal_connect_(GadgetID(i - 1), "button_release_event",
  @MouseButtonCallback(), 0)
Next i

CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
SetActiveGadget(#StringGadget)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #Event_MouseLeftButtonDown
      StatusBarText(0, 0, "GagdetID " + Str(EventGadget()) +
        ": Left mouse button down", #PB_StatusBar_Center)
    Case #Event_MouseLeftButtonUp
      StatusBarText(0, 0, "GagdetID " + Str(EventGadget()) +
        ": Left mouse button up", #PB_StatusBar_Center)
  EndSelect
ForEver
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
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: LeftButtonDown, LeftButtonUp, get separated controle.

Post by Joris »

Shardik, mk-soft , that does the task.
I needed it on listview item selection, but that works too.
So nice made.

Thanks guys
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply