Xojo Conferences
XDCMay2019MiamiUSA

[MBS] Handing MenuPopulate event on Cocoa (MBS Xojo Plugin Mailinglist archive)

Back to the thread list
Previous thread: [MBS] Floppy disk detection
Next thread: [MBS] [ANN] 14.2pr3


Re: [MBS] PortAudioStreamRecorderMBS issue   -   Garth Hjelte
  [MBS] Handing MenuPopulate event on Cocoa   -   Marnaud
   Re: [MBS] Handing MenuPopulate event on Cocoa   -   Marnaud
   Re: [MBS] Handing MenuPopulate event on Cocoa   -   Christian Schmitz
   Re: [MBS] Handing MenuPopulate event on Cocoa   -   Marnaud
   Re: [MBS] Handing MenuPopulate event on Cocoa   -   Christian Schmitz

[MBS] Handing MenuPopulate event on Cocoa
Date: 10.04.14 08:00 (Thu, 10 Apr 2014 09:00:03 +0200)
From: Marnaud
Greetings!

I need to handle the MenuPopulate event of the CarbonApplicationEventsMBS class in order to deactivate one row of a PopupMenu control. I use this kind of code:
dim i As Integer
dim m As MenuMBS

m=new MenuMBS
m.Handle=MenuHandle

if MenuHandle=PMCmdHandle then 'PMCmdHandle is a custom property of this class
for ito m.Count
m.Enabled(i)=m.Text(i)<>CstStrConcerningFileTrack
next
end if

and, in Carbon, I could define PMCmdHandle like this:
CAE1.PMCmdHandle=MyPopupMenu.MenuMBS.Handle

However, that last call produces an exception in Cocoa (only valid for Carbon 32 bits). This breaks the entire purpose of the MenuPopulate event, I guess. Which workaround can be done?
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Handing MenuPopulate event on Cocoa
Date: 10.04.14 13:22 (Thu, 10 Apr 2014 14:22:44 +0200)
From: Marnaud
Le 10 avr. 2014 à 13:40, Christian Schmitz a écrit:

> maybe like this:
>
> dim pb as NSPopUpButtonMBS = PopupMenu1.NSPopUpButtonMBS
> dim menu as NSMenuMBS = pb.menu
> dim handle as integer = menu.CarbonMenuRef

This gives me a handle of 0.

> Well, if you have a Menu, you could get the item and set enabled flag:
>
> dim item as NSMenuItemMBS = menu.Item(0)
> item.Enabled = false

I hope this would work. Currently, the code I'm using (with a MenuMBS) makes nothing with the enabled flag (but works with others like bold or underline); if the plugin function is not broken, I “expect” the NSMenuItemMBS.enabled flag to fail the same (it would be like an unsupported flag?).
Thank you.
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Handing MenuPopulate event on Cocoa
Date: 10.04.14 12:40 (Thu, 10 Apr 2014 13:40:17 +0200)
From: Christian Schmitz

Am 10.04.2014 um 12:11 schrieb Marnaud <<email address removed>>:

> How do I go from a PopupMenu to a NSMenuMBS? The NSMenuMBS has no constructor (that I found) with a PopupMenu parameter and the PopupMenu has nothing to get a NSMenuMBS (I also checked NSViewMBS, NSPopupButtonMBS and NSControlMBS properties of the PopupMenu).

maybe like this:

dim pb as NSPopUpButtonMBS = PopupMenu1.NSPopUpButtonMBS
dim menu as NSMenuMBS = pb.menu
dim handle as integer = menu.CarbonMenuRef

> In the meantime, I commented out the test (so all popup menus are processed); I've been able to set a PopupMenu's menu item to bold or underline, but enabledúlse doesn't disable the item (it did in Carbon); and disabling a menu item is exactly what I want to achieve. Do you happen to know that disabling a menu item in a PopupMenu is broken in Cocoa?

Well, if you have a Menu, you could get the item and set enabled flag:

dim item as NSMenuItemMBS = menu.Item(0)
item.Enabled = false

Sincerely
Christian

-

Re: [MBS] Handing MenuPopulate event on Cocoa
Date: 10.04.14 11:11 (Thu, 10 Apr 2014 12:11:15 +0200)
From: Marnaud
Le 10 avr. 2014 à 10:00, Christian Schmitz a écrit:

> I think in Cocoa you can get the NSMenuMBS and use CarbonMenuRef function there to get the handle.

How do I go from a PopupMenu to a NSMenuMBS? The NSMenuMBS has no constructor (that I found) with a PopupMenu parameter and the PopupMenu has nothing to get a NSMenuMBS (I also checked NSViewMBS, NSPopupButtonMBS and NSControlMBS properties of the PopupMenu).

In the meantime, I commented out the test (so all popup menus are processed); I've been able to set a PopupMenu's menu item to bold or underline, but enabled=false doesn't disable the item (it did in Carbon); and disabling a menu item is exactly what I want to achieve. Do you happen to know that disabling a menu item in a PopupMenu is broken in Cocoa?

Thanks
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Handing MenuPopulate event on Cocoa
Date: 10.04.14 09:00 (Thu, 10 Apr 2014 10:00:55 +0200)
From: Christian Schmitz

Am 10.04.2014 um 09:00 schrieb Marnaud <<email address removed>>:

> Greetings!
>
> However, that last call produces an exception in Cocoa (only valid for Carbon 32 bits). This breaks the entire purpose of the MenuPopulate event, I guess. Which workaround can be done?

I think in Cocoa you can get the NSMenuMBS and use CarbonMenuRef function there to get the handle.

Sincerely
Christian