Page 1 of 1

Open ComboBoxGadget?

Posted: Mon Mar 11, 2019 2:56 am
by wombats
Hi,

Is it possible to force a ComboBoxGadget to open using CocoaMessage?

I don't know if it's the right function, but I've found performClick in NSPopUpButtonCell. I don't know how to get access to it, nor what I would specify for "frame" and "controlView", however.

Thank you for any suggestions.

Re: Open ComboBoxGadget?

Posted: Mon Mar 11, 2019 7:17 am
by wilbert
You can perform a click on the gadget itself put when I tried the gadget closed immediately after opening. :?

Code: Select all

CocoaMessage(0, GadgetID(MyComboGadget), "performClick:", 0)

Re: Open ComboBoxGadget?

Posted: Mon Mar 11, 2019 8:25 am
by TI-994A
wilbert wrote:You can perform a click on the gadget itself put when I tried the gadget closed immediately after opening. :?

Code: Select all

CocoaMessage(0, GadgetID(MyComboGadget), "performClick:", 0)
It works perfectly on High Sierra.

Re: Open ComboBoxGadget?

Posted: Mon Mar 11, 2019 8:45 pm
by Shardik
You have to use two different methods to programmatically open a non-editable ComboBox (NSPopUpButton) or an editable ComboBox (NSComboBox). I have tested the following example successfully on these MacOS versions:
- MacOS 10.6.8 'Snow Leopard' with PB 5.46 x86 in ASCII and Unicode mode
- MacOS 10.9.5 'Mavericks' with PB 5.46 x86 in ASCII and Unicode mode
- MacOS 10.13.6 'High Sierra' with PB 5.46 x64 in ASCII and Unicode mode

Code: Select all

EnableExplicit

Define i.I
Define Selector.I = sel_registerName_("popUp:")

OpenWindow(0, 270, 100, 200, 200, "ComboBoxGadgets")
ComboBoxGadget(0, 10, 20, WindowWidth(0) - 20, 25)
ComboBoxGadget(1, 10, 70, WindowWidth(0) - 20, 25, #PB_ComboBox_Editable)
ButtonGadget(2, 10, 130, WindowWidth(0) - 20, 25, "Open 1st ComboBox")
ButtonGadget(3, 10, 160, WindowWidth(0) - 20, 25, "Open 2nd ComboBox")

For i = 1 To 3
  AddGadgetItem(0, -1, "Item " + Str(i))
  AddGadgetItem(1, -1, "Editable item " + Str(i))
Next

SetGadgetState(0, 0)
SetGadgetState(1, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          CocoaMessage(0, GadgetID(0), "performClick:", 0)
        Case 3
          CocoaMessage(0, CocoaMessage(0, GadgetID(1), "cell"),
            "performSelector:", Selector)
      EndSelect
  EndSelect
ForEver

Re: Open ComboBoxGadget?

Posted: Mon Mar 11, 2019 11:16 pm
by wombats
Thank you, all.

I guess I was overthinking it. :oops: