PureBasic Forum
https://www.purebasic.fr/english/

Open ComboBoxGadget?
https://www.purebasic.fr/english/viewtopic.php?f=19&t=72431
Page 1 of 1

Author:  wombats [ Mon Mar 11, 2019 2:56 am ]
Post subject:  Open ComboBoxGadget?

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.

Author:  wilbert [ Mon Mar 11, 2019 7:17 am ]
Post subject:  Re: Open ComboBoxGadget?

You can perform a click on the gadget itself put when I tried the gadget closed immediately after opening. :?
Code:
CocoaMessage(0, GadgetID(MyComboGadget), "performClick:", 0)

Author:  TI-994A [ Mon Mar 11, 2019 8:25 am ]
Post subject:  Re: Open ComboBoxGadget?

wilbert wrote:
You can perform a click on the gadget itself put when I tried the gadget closed immediately after opening. :?
Code:
CocoaMessage(0, GadgetID(MyComboGadget), "performClick:", 0)

It works perfectly on High Sierra.

Author:  Shardik [ Mon Mar 11, 2019 8:45 pm ]
Post subject:  Re: Open ComboBoxGadget?

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:
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

Author:  wombats [ Mon Mar 11, 2019 11:16 pm ]
Post subject:  Re: Open ComboBoxGadget?

Thank you, all.

I guess I was overthinking it. :oops:

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/