64-bit replacement for [NSMenuItemCell menuView] and [NSMenuItemCell setMenuView] - macos

What are the 64-bit replacements for the two methods -[NSMenuItemCell menuView] and -[NSMenuItemCell setMenuView:] of the NSMenuItemCell class?
How can I obtain the same results?

The NSMenuItemCell and NSMenuView have never been used to draw menus in any release version of Mac OS X. The following is an excerpt from the Mac OS X Developer Release Notes:
Notes specific to MacOS X Developer Preview 3
Menu
The implementation of menus has changed drastically; NSMenuView and
NSMenuItemCell are no longer used, -[NSMenu menuRepresentation] now
returns nil, and tear off menus are no longer available. For Developer
Preview 3, there is no support for menu item images. If there is no
text in the menu item, a placeholder text consisting of "< image >" or
"< image name >" will be inserted instead. Menu item state images are
not supported either and in their place the standard checkbox or dash
for on and mixed states are used.
(I'm not sure of the exact timeline of pre-Public beta Mac OS X, but for "Developer Preview 3", I'd guess we're talking around the late 1990s here).
For more info on how menus are currently implemented, see Application Menu and Pop-up List Programming Topics: How Menus Work
As 一二三 alluded to, you use NSMenu along with NSMenuItem to implement menus. In OS X 10.5 and greater, you can use custom NSView instances in NSMenuItems using the -setView: method.

To customise menu item drawing, you need to supply a custom view to NSMenuItem.

Related

OS X NSStatusItem How to set the accessibility title for VoiceOver

There is no direct API (as far as I can see) but some applications seem to have it.
Although Apple's own icons (e.g. fast user switching, keyboard layout switching) do not have it.
Since OS X 10.10, NSStatusItem has button property, which is a regular NSView-based control that conforms to NSAccessibility protocol and which allows to change accessibilityTitle property directly.
On earlier versions of OS X, you can implement a custom button that looks and behaves exactly like vanilla NSStatusItem and assign it to the item via -[NSStatusItem setView:] method, then use -[NSView accessibilitySetOverrideValue:... forAttribute:NSAccessibilityTitleAttribute] on your custom control to provide a voiceover title.

NSStatusItem not keyboard navigable

I've created an NSStatusItem for my app, but would like it to be navigable, as the system items are, when using Control+F8 (Control+fn+f8).
The status item is inexplicably skipped in the navigation sequence. Is there a secret handshake of accepting first responder or something that needs to be done for this?
This is basically all the setup code I have for the item:
statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(28)
statusItem.menu = menu
statusItem.button?.image = NSImage(named: "menuIcon")
I found a a similar question asked on quoara.com: http://www.quora.com/Why-cant-I-focus-third-party-icons-in-the-status-menu-area-on-OS-X-with-a-keyboard-shortcut-like-Ctrl-F8-SOLVED.
Quoting Colin Barrett:
The third party items are implemented with a different API (NSStatusItem) than the built-in ones (NSMenuExtra). Note that you can drag to re-arrange the menu extras but not the status items (which always appear to the left of menu extras).
Unfortunately NSMenuExtra is private API and with the Mac App Store you're likely to see less and less apps using it.
Just as an example of third party apps which do support this, you can probably F8 to the MenuMeters icon / graph.
So if you really want to make your status menu items available via keyboard you'll have to dig within Apple's private frameworks, however that's an unstable territory, as they're subject to change at any time, without any notification.
As of at least macOS 10.12, it is possible to navigate to an NSStatusItem using the keyboard with Control+F8. This change presumably occurred between OS X 10.10 and macOS 10.12 (I haven’t tested this with any versions earlier than 10.12).
In order to enable keyboard navigation, the NSStatusItem’s menu property must be defined.

How to change the Mac OS X dock icon in a wxPython application

When a wx.App is launched through a script (i.e., not bundled with py2app) its icon in the dock is the standard Python rocket. Is it possible to customize that icon? It seems that in the past wx.TaskBarIcon did this (see http://wiki.wxpython.org/Custom%20Mac%20OsX%20Dock%20Bar%20Icon), but now it adds an icon to the menu bar.
I had the same issue and it seems there is a lack of documentation about this. I found several piece of information in different discussion threads.
You have to use the iconType argument of the wx.TaskBarIcon constructor. there are currently three possible values:
wx.TBI_CUSTOM_STATUSITEM: will create an icon in right part of the menu bar.
wx.TBI_DEFAULT_TYPE: default parameter, similar as TBI_DOCK for wxPython 3.0.
wx.TBI_DOCK: will replace the Python rocket with the selected icon
If you reuse the example from the wx official documentation, you just need to replace this line
wx.TaskBarIcon.__init__(self)
with this line
wx.TaskBarIcon.__init__(self, iconType=wx.TBI_DOCK)
The problem with this solution is that you have to choose to put the icon either in the menu bar either in the dock. It does not seem possible to put an icon in the both place while using only one instance of wx.TaskBarIcon.
Here are my current settings:
mac os X 10.11.5
wxPython 3.0.2.0
python 2.7.10

How to add Toolbar Button to Title Bar

I have created a toolbar via IB and have a simple View menu with the "Show Toolbar" and "Customize Toolbar" menu items. Both work exactly as I would like them to.
But, I cannot seem to get the Toolbar Button to show up in the title bar of the NSWindow.
I have tried setting the "Shows Toolbar Button" in IB... no luck.
I have tried calling setShowsToolbarButton in the window controller's awakeFromNib
NSLog(#"showsToolbarButton: %#\n",[[self window]showsToolbarButton]?#"YES":#"NO");
[[self window]setShowsToolbarButton:YES];
NSLog(#"showsToolbarButton: %#\n",[[self window]showsToolbarButton]?#"YES":#"NO");
Again, no luck. Both log entries show "NO" and there is no button.
Has this feature gone away?
If not, what is the proper way to get that button to show up?
I'm building for OSX 10.6 and newer using Xcode 5.0.2 on a machine running 10.9.
Thanks for any/all insights.
The button to hide and show the toolbar was commonly seen as a small capsule button in the upper right corner at least through 10.6 Snow Leopard.
It is no longer present in standard OS X windows.
Ostensibly this is still in Xcode for supporting projects targeting older versions of OS X.
You can probably still create your own button and set its action to the same selectors, but you would likely need to create a custom window using NSBorderlessWindowMask to get the button in the title bar where it used to be.
In its place for the last several OS X versions you will find the full screen button instead.

Customize the Apple Menu

How to customize the Apple menu? What SDKs should I study, etc.? I want to insert a menu item:
Apple Menu Specific
This AskDifferent question addresses removing an item from the Apple menu. Seems you could use the same technique to add an item. Just be sure to make a backup of any system files you edit.
The following posts recommend similar solutions but are a bit dated. The system file path appears to be the same, however.
Hide unwanted Apple menu items
Remove the 'Get Mac OS X Software' menu item
Also mentioned in the AskDifferent quesiton, FruitMenu allows for menu customization. However, there's no support for the more current versions of OS X.
Version 3.8.4 released Mar 3, 2011
Requires Mac OS X 10.5.8 or Mac OS X 10.6.x; Rosetta
Compatible with Mac OS X 10.6 Snow Leopard.
OS X Menu Item Tutorials
Creating a Standalone StatusItem Menu 1
This tutorial will show you how to create a StatusItem menu that will be available to all applications in the menu bar.
When you are done, you will have a simple menu that will appear on its own in the menubar as a "universal" background application, and will contain two menu items that let you enter a string into the Console and Quit itself. Note that you will need to code the functionality yourself for any menu item(s) you add or modify, but this will get you started.
Creating a Status Bar Application
This tutorial assumes you have a basic knowledge of Objective-C. In this tutorial, we will walk-through on how to create a status bar only application for the Mac OS X.
1 Mac Menu Bar Tutorial?
It is simply a folder named "Apple Menu Items" in the System Folder which you can manipulate in many ways. But don't rename it or move it out of the System Folder.
http://www.macoptions.com/os85/applemenu.html

Resources