Bug GeActiveGadget() in MacOS since PureBasic 6.00

Mac OSX specific forum
H-QueST
New User
New User
Posts: 4
Joined: Sat Mar 25, 2023 8:36 am

Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by H-QueST »

Hi Fred or Timo or an other expert,

there is a new bug in PureBasic 6.00 and 6.01:
GetActiveGadget() does not work on MacOS as in former versions.

Please try the following example on MacOS (result: -1) and on Windows (result: a number > 0):

Code: Select all

If OpenWindow(0, 0, 0, 230, 90, "Event-Handling Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   b1=ButtonGadget  (#PB_Any, 10, 10, 200, 20, "Klick on me")
   b2=CheckBoxGadget(#PB_Any, 10, 40, 200, 20, "Check me")
  If CreateMenu(0, WindowID(0))
     MenuTitle("Menu")
     MenuItem(1, "Item 1")
     MenuItem(2, "Item 2")
     MenuItem(3, "Item 3")
   EndIf
  Repeat
     Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case b1 : Debug "Button 1 klicked!" : Debug GetActiveGadget()
           Case b2 : Debug " Button 2 klicked!" : Debug GetActiveGadget()
         EndSelect
       Case #PB_Event_Menu
         Select EventMenu()
           Case m1 : Debug "Menu-Item 1 klicked!!"
           Case m2 : Debug "Menu-Item 2 klicked!"
           Case m3 : Debug "Menu-Item 3 klicked!"
         EndSelect
     EndSelect
   Until Event = #PB_Event_CloseWindow
EndIf
Is there a work arround for this bug?
Thank you for helping!


// Code Tags added (Kiffi)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by mk-soft »

Welcome ...
Please use code tags...

Has been like this since before v6.0
It's probably a feature of macOS. A button / checkbox does not keep or get a focus. A StringGadget keeps the focus, even if a button is pressed.

P.S.
Since Yosemite, buttons, etc. no longer have a focus ring.

Code: Select all

If OpenWindow(0, 0, 0, 230, 130, "Event-Handling Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  b1=ButtonGadget (#PB_Any, 10, 10, 200, 20, "Klick on me")
  b2=CheckBoxGadget(#PB_Any, 10, 40, 200, 20, "Check me")
  e1=StringGadget(#PB_Any, 10, 70, 200, 20, "Text")
  
  If CreateMenu(0, WindowID(0))
    MenuTitle("Menu")
    MenuItem(1, "Item 1")
    MenuItem(2, "Item 2")
    MenuItem(3, "Item 3")
  EndIf
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case b1 : Debug "Button 1 klicked!" : Debug GetActiveGadget()
          Case b2 : Debug " Button 2 klicked!" : Debug GetActiveGadget()
          Case e1 : Debug " String Event!" : Debug GetActiveGadget()
            
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1 : Debug "Menu-Item 1 klicked!!"
          Case 2 : Debug "Menu-Item 2 klicked!"
          Case 3 : Debug "Menu-Item 3 klicked!"
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
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
H-QueST
New User
New User
Posts: 4
Joined: Sat Mar 25, 2023 8:36 am

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by H-QueST »

Hello mk-soft,
Thank you very much.
It is true. A test with Purebasic 5.72 showed that it is due to the changed operating system since Yokosemite.
In the PureBasic help it is written that GetActiveGadget() works on all operating systems. So this statement is no longer valid for macOS.
How can I get the focus ring on buttons another way? Is there a CallCFunction() on MacOS?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by mk-soft »

As I have read in other forums for macOS, you have to create an NS button in an NSView yourself.
This is of course very time-consuming in PB. Or remember the last button yourself.

Other asked?
What do you need the GetActiveGadget for?
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
H-QueST
New User
New User
Posts: 4
Joined: Sat Mar 25, 2023 8:36 am

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by H-QueST »

It is about the fact that a program should react intelligently to the selection by the user from several buttons.
This is quite common and now works very well under PureBasic Windows, but unfortunately no longer under MacOS. However the function GetActiveButton() of my older MacOS compilate works also under the new MacOS versions. So it must be the library version from which a MacOS program is compiled in PureBasic. Maybe it is possible to include an older function in the current library.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by mk-soft »

This is due to the OS versions under Xcode version you are using.
Do it differently and write your own version with LastButtonGadget

Code: Select all

;-TOP

Global LastButtonGadget = -1

Procedure DoEventGadget()
  Protected gadget = EventGadget()
  Select GadgetType(gadget)
    Case #PB_GadgetType_Button, #PB_GadgetType_CheckBox, #PB_GadgetType_Option
      LastButtonGadget = gadget
  EndSelect
EndProcedure

BindEvent(#PB_Event_Gadget, @DoEventGadget())

Procedure GetLastButtonGadget()
  ProcedureReturn LastButtonGadget
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, "Test 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 0")
    ButtonGadget(1, 140, 10, 120, 30, "Button 1")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      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()
            Case 0, 1
              Debug GetLastButtonGadget()
          EndSelect
          
      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
H-QueST
New User
New User
Posts: 4
Joined: Sat Mar 25, 2023 8:36 am

Re: Bug GeActiveGadget() in MacOS since PureBasic 6.00

Post by H-QueST »

Hi mk-soft,
this works fine.
Thank you very much!
Post Reply