DisableGadget() ImageGadget()

Mac OSX specific forum
BlindMan
User
User
Posts: 32
Joined: Thu Aug 30, 2018 11:34 am

DisableGadget() ImageGadget()

Post by BlindMan »

Hi

This code works as expected on Windows 10 but not on Catalina.

On macOS Catalina 10.15.4 using PB572, left and right mouse clicks are sometimes detected on a disabled image gadget. No mouse clicks detected on Windows 10.

Code: Select all


  OpenWindow(0, 0, 0, 200, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  TextGadget(0, 10, 1, 180, 20, "", #PB_Text_Center) 

  BoxSize=40
  
  CreateImage(0, BoxSize, BoxSize)
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(0,255,0))
  StopDrawing()
 
  CreateImage(1, BoxSize, BoxSize)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(255,0,0))
  StopDrawing()
  
  ImageGadget(1, 40, 40, BoxSize, BoxSize, ImageID(0))
  ImageGadget(2,120, 40, BoxSize, BoxSize, ImageID(0))

  Global LClicks = 0
  Global RClicks = 0
  Global BIG = 0
  Global EVT = 0

  Procedure OffOn()
    If BIG = 1
      DisableGadget(1, 1)
      DisableGadget(2, 0)
      SetGadgetState(1, ImageID(1))
      SetGadgetState(2, ImageID(0))
    Else
      DisableGadget(1, 0)
      DisableGadget(2, 1)
      SetGadgetState(1, ImageID(0))
      SetGadgetState(2, ImageID(1))
    EndIf
    SetGadgetText(0, "BIG " + Str(BIG) + "  L " + Str(LClicks) + "  R " + Str(RClicks))   
  EndProcedure
  
  
  Repeat
    Event = WaitWindowEvent(100)
       
    If Event = #PB_Event_Gadget
      
      BIG = EventGadget()
      EVT = EventType()

      If EVT = #PB_EventType_LeftClick
        LClicks = LClicks + 1
        OffOn()
      EndIf
      
      If EVT = #PB_EventType_RightClick
        RClicks = RClicks + 1
        OffOn()
      EndIf          
      
    EndIf
    
  Until Event = #PB_Event_CloseWindow
    
  End
    


Using GetGadgetState() instead of DisableGadget() as a workaround.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: DisableGadget() ImageGadget()

Post by mk-soft »

Must be a bug in macOS.

Although the object NSImageView (NSControl) is locked "isEnabled = 0" the events are processed differently.

Solution: Query isEnabled

Code: Select all

Procedure IsEnabled(Gadget)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn #True ; TODO
    CompilerCase #PB_OS_Linux
      ProcedureReturn #True ; TODO
    CompilerCase #PB_OS_MacOS
      ProcedureReturn CocoaMessage(0, GadgetID(Gadget), "isEnabled")
    CompilerEndSelect
EndProcedure

OpenWindow(0, 0, 0, 200, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  TextGadget(0, 10, 1, 180, 20, "", #PB_Text_Center) 

  BoxSize=40
  
  CreateImage(0, BoxSize, BoxSize)
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(0,255,0))
  StopDrawing()
 
  CreateImage(1, BoxSize, BoxSize)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(255,0,0))
  StopDrawing()
  
  ImageGadget(1, 40, 40, BoxSize, BoxSize, ImageID(0))
  ImageGadget(2,120, 40, BoxSize, BoxSize, ImageID(0))
  
  DisableGadget(2, 1)
  ;CocoaMessage(0, GadgetID(2), "setEnabled:", #False)
  
  Debug CocoaMessage(0, GadgetID(2), "isEnabled")
  
  
  Debug DumpObjectMethods(GadgetID(1), 1)
  
  Repeat
    Event = WaitWindowEvent()
       
    If Event = #PB_Event_Gadget
      
      Select EventType()
        Case #PB_EventType_LeftClick
          
          If IsEnabled(EventGadget())
            Debug "Left " + EventGadget()
          EndIf
          
        Case #PB_EventType_RightClick
          If IsEnabled(EventGadget())
            Debug "Right " + EventGadget()
          EndIf
          
      EndSelect          
      
    EndIf
    
  Until Event = #PB_Event_CloseWindow
    
  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
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: DisableGadget() ImageGadget()

Post by Wolfram »

The problem ist if you click to fast it will be detected as double or triple click.

This seams logical to me.

Code: Select all

  Repeat
    Event = WaitWindowEvent(100)
       
    If Event = #PB_Event_Gadget
      
      BIG = EventGadget()
      EVT = EventType()

      If EVT = #PB_EventType_LeftClick Or EVT = #PB_EventType_LeftDoubleClick
        LClicks = LClicks + 1
        OffOn()
      EndIf
      
      If EVT = #PB_EventType_RightClick Or EVT = #PB_EventType_RightDoubleClick
        RClicks = RClicks + 1
        OffOn()
      EndIf          
      
    EndIf
    
  Until Event = #PB_Event_CloseWindow
macOS Catalina 10.15.7
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: DisableGadget() ImageGadget()

Post by mk-soft »

Disable ImageGadget on macOS not work...
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