How to detect double click on TextGadget()?

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to detect double click on TextGadget()?

Post by wilbert »

Here's another way of detecting the enter inside a StringGadget .
It's a more universal way you can use for every Target/Action .

Code: Select all

Prototype Proto_SendAction(Object, Selector, Action, Target, Sender)
DeclareC SendAction(Object, Selector, Action, Target, Sender)

Global SendAction_.Proto_SendAction = class_replaceMethod_(objc_getClass_("NSApplication"), 
                                                           sel_registerName_("sendAction:to:from:"), 
                                                           @SendAction(), "c@::@@")

Global StringGadgetClass

ProcedureC SendAction(Object, Selector, Action, Target, Sender)
  
  Select object_getClass_(Sender)
    Case StringGadgetClass
      Debug "Enter by StringGadget: " + Str(CocoaMessage(0, Sender, "tag"))
  EndSelect
    
  If SendAction_
    ProcedureReturn SendAction_(Object, Selector, Action, Target, Sender)
  EndIf
EndProcedure


OpenWindow(0, 270, 100, 200, 170, "Target/Action", #PB_Window_MinimizeGadget)
StringGadget(1, 10, 10, 100, 20, "Gadget 1")
StringGadget(2, 10, 40, 100, 20, "Gadget 2")
StringGadget(3, 10, 70, 100, 20, "Gadget 3")

StringGadgetClass = object_getClass_(GadgetID(1))

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply