[PB 6.00] #PB_EventType_Focus doesn't seem to be working

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

[PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by marcoagpinto »

Hello!

Inside a Repeat Until loop, I have the following:

Code: Select all

      event=WaitWindowEvent()
      event_menu=EventMenu()
      event_gadget=EventGadget()
      event_type=EventType()
      event_window=EventWindow()
The event_type doesn't recognise clicking inside SpinGadgets (where we write the content), tested with numeric SpinGadgets.

Is it a bug, or am I doing something wrong?

Thanks!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by infratec »

In the german help for the Spingadget is only written:

Code: Select all

  #PB_EventType_Change
  #PB_EventType_Up
  #PB_EventType_Down  
and nothing more. So why should #PB_EventType_Focus should work?

Just checked:
also the english help does not mention it.
https://www.purebasic.com/documentation ... adget.html
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by BarryG »

Every clickable gadget should support #PB_EventType_Focus (and #PB_EventType_LostFocus), but that's a Feature Request.
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by marcoagpinto »

BarryG wrote: Sun Sep 25, 2022 10:50 am Every clickable gadget should support #PB_EventType_Focus (and #PB_EventType_LostFocus), but that's a Feature Request.
Ohhhhh… it is a feature request… I am so sad… I was trying hard to debug my code.

:cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by BarryG »

That's why I use GetActiveGadget() after a #PB_Event_Gadget trigger, so I can keep track of which gadget now has (or lost) the focus.
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by marcoagpinto »

BarryG wrote: Sun Sep 25, 2022 10:58 am That's why I use GetActiveGadget() after a #PB_Event_Gadget trigger, so I can keep track of which gadget now has (or lost) the focus.
Thank you very much!

It has worked this way.

8) 8) 8) 8) 8)
ozzie
Enthusiast
Enthusiast
Posts: 429
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by ozzie »

BarryG wrote: Sun Sep 25, 2022 10:58 am That's why I use GetActiveGadget() after a #PB_Event_Gadget trigger, so I can keep track of which gadget now has (or lost) the focus.
Thanks, BarryG. That's a useful tip.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB 6.00] #PB_EventType_Focus doesn't seem to be working

Post by mk-soft »

Small example with Custom Events. Window and Linux. MacOS not Events for Buttons because Buttons have not keyboard focus

Code: Select all

;-TOP

Enumeration CustomEvent #PB_Event_FirstCustomValue
  #MyEvent_GadgetFocus
  #MyEvent_GadgetLostFocus
EndEnumeration

Procedure UpdateGadgetFocus()
  Static LastGadget = -1
  Protected ActiveGadget = GetActiveGadget()
  
  If LastGadget <> ActiveGadget
    If LastGadget <> -1
      PostEvent(#MyEvent_GadgetLostFocus, GetActiveWindow(), LastGadget)
    EndIf
    If ActiveGadget <> -1
      PostEvent(#MyEvent_GadgetFocus, GetActiveWindow(), ActiveGadget)
    EndIf
    LastGadget = ActiveGadget
  EndIf
EndProcedure
    
Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Small Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy - WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    ButtonGadget(0, 10, 10, 120, 30, "Button 1")
    ButtonGadget(1, 140, 10, 120, 30, "Button 2")
    StringGadget(2, 10, 50, 250, 25, "String 3")
    EditorGadget(3, 10, 85, 250, 75)
    SetGadgetText(3, "Edit 4")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    SetActiveGadget(3)
    
    ; Main Loop
    Repeat
      UpdateGadgetFocus()
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
        Case #MyEvent_GadgetFocus
          Debug "Focus " + GetGadgetText(EventGadget())
          
        Case #MyEvent_GadgetLostFocus
          Debug "LostFocus " + GetGadgetText(EventGadget())
        
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
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
Post Reply